blob: 2577e922b40a6febd991a182aef90212834721be (
plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
name = "info";
group = "status";
shortDescription = "Display information about something";
longDescription = "info scripts : Names of scripts being debugged";
longDescription += "\ninfo breakpoints : Status of breakpoints currently set";
longDescription += "\ninfo locals : Local variables of current stack frame";
argumentTypes = [ "subcommand-name" ];
subCommands = [ "breakpoints", "locals", "scripts" ];
function execute() {
var arg = arguments[0];
if (arg == undefined) {
message("\"info\" must be followed by the name of an info command.");
return;
} else if (arg == "scripts") {
scheduleGetScripts();
state = 1;
} else if (arg == "breakpoints") {
if (arguments.length > 1) {
var id = parseInt(arguments[1]);
if (isNaN(id)) {
message("Breakpoint id expected.");
return;
}
scheduleGetBreakpointData(id);
breakpointId = id;
state = 3;
} else {
scheduleGetBreakpoints();
state = 2;
}
} else if (arg == "locals") {
scheduleGetActivationObject(getCurrentFrameIndex());
state = 4;
} else {
warning("Undefined info command \"" + arg + "\". Try \"help info\".");
}
}
function breakpointString(id, data) {
var fn = data.fileName;
if (fn.length == 0)
fn = "<anonymous script, id=" + data.scriptId + ">";
var ret = id + "\t" + (data.enabled ? "yes" : "no")
+ "\t" + fn + ":" + data.lineNumber;
if (data.condition.length != 0) {
ret += "\n\tstop only if " + data.condition;
}
return ret;
}
function handleResponse(resp) {
if (state == 1) {
// info scripts
var scripts = resp.result;
if (scripts == undefined) {
message("No scripts loaded.");
return;
}
for (var id in scripts) {
var fn = scripts[id].fileName;
if (fn.length == 0)
fn = "<anonymous script, id=" + id + ">";
message("\t" + fn);
}
}
else if (state == 2) {
// info breakpoints
var breakpoints = resp.result;
if (breakpoints == undefined) {
message("No breakpoints set.");
return;
}
message("Id\tEnabled\tWhere");
for (var id in breakpoints) {
var data = breakpoints[id];
message(breakpointString(id, data));
}
} else if (state == 3) {
// info breakpoints N
var data = resp.result;
if (data == undefined) {
message("No breakpoint number " + breakpointId + ".");
return;
}
message("Id\tEnabled\tWhere");
message(breakpointString(breakpointId, data));
}
else if (state == 4) {
// info locals
var act = resp.result;
scheduleNewScriptValueIterator(act);
state = 5;
} else if (state == 5) {
var id = resp.result;
scheduleGetPropertiesByIterator(id, 100);
iteratorId = id;
state = 6;
} else if (state == 6) {
var props = resp.result;
if (props.length == 0) {
scheduleDeleteScriptValueIterator(iteratorId);
state = 7;
return;
}
var maxLength = 0;
for (var i = 0; i < props.length; ++i)
maxLength = Math.max(props[i].name.length, maxLength);
for (var i = 0; i < props.length; ++i) {
var prop = props[i];
var msg = prop.name;
var pad = maxLength - prop.name.length;
for (var j = 0; j < pad; ++j)
msg += ' ';
message(msg + " : " + prop.valueAsString);
}
scheduleGetPropertiesByIterator(iteratorId, 100);
} else if (state == 7) {
// done
}
}
|