-
Notifications
You must be signed in to change notification settings - Fork 9
/
calllog.mozcmd
75 lines (69 loc) · 2.61 KB
/
calllog.mozcmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
[{
name: "calllog",
description: "Commands to manipulate function call logging"
}, {
name: "calllog record",
description: "Start logging function calls to the console",
exec: function(args, context) {
let global = Components.utils.getGlobalForObject(this);
if (typeof global.Debugger == "undefined") {
let JSDebug = {};
Components.utils.import("resource://gre/modules/jsdebugger.jsm", JSDebug);
JSDebug.addDebuggerToGlobal(global);
}
let Debugger = global.Debugger;
let contentWin = context.environment.contentDocument.defaultView;
let dbg = new Debugger(contentWin);
if (!Array.isArray(global.callLogDebuggers))
global.callLogDebuggers = [];
global.callLogDebuggers.push(dbg);
dbg.onEnterFrame = this.onEnterFrame.bind(this);
return "Call logging started.";
},
valueToString: function(value) {
if (typeof value !== "object" || value === null)
return uneval(value);
return "[object " + value.class + "]";
},
framePosition: function(frame) {
if (!frame.script)
return frame.type + " code";
let line = frame.script.getOffsetLine(frame.offset);
let source = frame.script.url || (frame.type + " code");
return source + ":" + line;
},
callDescription: function(frame) {
let name = frame.callee.name || "<anonymous>";
let args = frame.arguments.map(this.valueToString).join(", ");
return name + "(" + args + ")";
},
onEnterFrame: function(frame) {
try {
let msg = Components.classes["@mozilla.org/scripterror;1"]
.createInstance(Components.interfaces.nsIScriptError);
msg.init("Method call: " + this.callDescription(frame),
frame.script ? frame.script.url : (frame.type + " code"),
"",
frame.script.getOffsetLine(frame.offset),
0,
Components.interfaces.nsIScriptError.warningFlag,
"component javascript");
Services.console.logMessage(msg);
} catch(e) {}
}
}, {
name: "calllog stop",
description: "Stop function call logging",
exec: function(args, context) {
let global = Components.utils.getGlobalForObject(this);
let numDebuggers = 0
if (Array.isArray(global.callLogDebuggers))
numDebuggers = global.callLogDebuggers.length;
if (numDebuggers == 0)
return "No call logging is currently active";
for (let dbg of global.callLogDebuggers)
dbg.onEnterFrame = undefined;
global.callLogDebuggers = [];
return "Stopped call logging for " + numDebuggers + " contexts";
}
}]