1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/debug/Environment-setVariable-10.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,32 @@ 1.4 +// setVariable works on non-innermost environments. 1.5 + 1.6 +// (The debuggee code here is a bit convoluted to defeat optimizations that 1.7 +// could make obj.b a null closure or obj.i a flat closure--that is, a function 1.8 +// that gets a frozen copy of i instead of a reference to the runtime 1.9 +// environment that contains it. setVariable does not currently detect this 1.10 +// flat closure case.) 1.11 + 1.12 +var g = newGlobal(); 1.13 +g.eval("function d() { debugger; }\n" + 1.14 + "var i = 'FAIL';\n" + 1.15 + "function a() {\n" + 1.16 + " var obj = {b: function (i) { d(obj); return i; },\n" + 1.17 + " i: function () { return i; }};\n" + 1.18 + " var i = 'FAIL2';\n" + 1.19 + " return obj;\n" + 1.20 + "}\n"); 1.21 + 1.22 +var dbg = Debugger(g); 1.23 +dbg.onDebuggerStatement = function (frame) { 1.24 + var x = 0; 1.25 + for (var env = frame.older.environment; env; env = env.parent) { 1.26 + if (env.getVariable("i") !== undefined) 1.27 + env.setVariable("i", x++); 1.28 + } 1.29 +}; 1.30 + 1.31 +var obj = g.a(); 1.32 +var r = obj.b('FAIL3'); 1.33 +assertEq(r, 0); 1.34 +assertEq(obj.i(), 1); 1.35 +assertEq(g.i, 2);