Skip to content

Instantly share code, notes, and snippets.

@fitzgen
Created September 25, 2012 12:19
Show Gist options
  • Save fitzgen/3781446 to your computer and use it in GitHub Desktop.
Save fitzgen/3781446 to your computer and use it in GitHub Desktop.
// Load the actor definition.
DebuggerServer.addActors("chrome://global/content/devtools/dbg-profiler-actors.js");
// Define a global-scoped actor
function ProfilerActor(aConnection, aRootActor)
{
this._conn = aConnection;
this._profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
this._started = false;
}
ProfilerActor.prototype = {
actorPrefix: "profiler",
disconnect: function() {
if (this._profiler && this._started) {
this._profiler.StopProfiler();
}
this._profiler = null;
},
onStartProfiler: function(aRequest) {
this._profiler.StartProfiler(aRequest.entries, aRequest.interval,
aRequest.features, aRequest.features.length);
this._started = true;
return { "msg": "profiler started" }
},
onStopProfiler: function(aRequest) {
this._profiler.StopProfiler();
this._started = false;
return { "msg": "profiler stopped" }
},
};
// Define the request types this actor can handle.
ProfilerActor.prototype.requestTypes = {
"startProfiler": ProfilerActor.prototype.onStartProfiler,
"stopProfiler": ProfilerActor.prototype.onStopProfiler,
};
// Register the actor.
DebuggerServer.addGlobalActor(ProfilerActor, "profilerActor");
// Define a tab-scoped actor
function ConsoleActor(aConnection, aTabActor)
{
this._conn = aConnection;
this._browser = aTabActor.browser;
this.consoleAPIListener = new ConsoleAPIListener();
}
ConsoleActor.prototype = {
actorPrefix: "console",
disconnect: function() {
if (this.consoleAPIListener) {
this.consoleAPIListener.destroy();
this.consoleAPIListener = null;
}
},
onEvaluateJS: function(aRequest) {
let input = aRequest.text;
let result, error = null;
let timestamp;
this.helperResult = null;
this.evalInput = input;
try {
timestamp = Date.now();
result = this.evalInSandbox(input);
}
catch (ex) {
error = ex;
}
let helperResult = this.helperResult;
delete this.helperResult;
delete this.evalInput;
return {
from: this.actorID,
input: input,
result: this.createValueGrip(result),
timestamp: timestamp,
error: error,
errorMessage: error ? String(error) : null,
helperResult: helperResult,
};
},
onAutocomplete: function WCA_onAutocomplete(aRequest) {
let result = JSPropertyProvider(this.window, aRequest.text) || {};
return {
from: this.actorID,
matches: result.matches || [],
matchProp: result.matchProp,
};
},
};
// Define the request types this actor can handle.
ConsoleActor.prototype.requestTypes = {
"evaluateJS": ConsoleActor.prototype.onEvaluateJS,
"autocomplete": ConsoleActor.prototype.onAutocomplete,
};
// Register the actor.
DebuggerServer.addTabActor(ConsoleActor, "consoleActor");
// Client
function ConsoleClient(aDebuggerClient, aActor) {
this._actor = aActor;
this._client = aDebuggerClient;
}
ConsoleClient.prototype = {
evaluateJS: function WCC_evaluateJS(aString, aOnResponse) {
let packet = {
to: this._actor,
type: "evaluateJS",
text: aString,
};
this._client.request(packet, aOnResponse);
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment