js/src/jit-test/tests/debug/Environment-setVariable-10.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:7ecab750921a
1 // setVariable works on non-innermost environments.
2
3 // (The debuggee code here is a bit convoluted to defeat optimizations that
4 // could make obj.b a null closure or obj.i a flat closure--that is, a function
5 // that gets a frozen copy of i instead of a reference to the runtime
6 // environment that contains it. setVariable does not currently detect this
7 // flat closure case.)
8
9 var g = newGlobal();
10 g.eval("function d() { debugger; }\n" +
11 "var i = 'FAIL';\n" +
12 "function a() {\n" +
13 " var obj = {b: function (i) { d(obj); return i; },\n" +
14 " i: function () { return i; }};\n" +
15 " var i = 'FAIL2';\n" +
16 " return obj;\n" +
17 "}\n");
18
19 var dbg = Debugger(g);
20 dbg.onDebuggerStatement = function (frame) {
21 var x = 0;
22 for (var env = frame.older.environment; env; env = env.parent) {
23 if (env.getVariable("i") !== undefined)
24 env.setVariable("i", x++);
25 }
26 };
27
28 var obj = g.a();
29 var r = obj.b('FAIL3');
30 assertEq(r, 0);
31 assertEq(obj.i(), 1);
32 assertEq(g.i, 2);

mercurial