~ubuntu-branches/ubuntu/saucy/mozjs17/saucy

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2013-05-25 12:24:23 UTC
  • Revision ID: package-import@ubuntu.com-20130525122423-zmxucrhtensw90xy
Tags: upstream-17.0.0
ImportĀ upstreamĀ versionĀ 17.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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('new-compartment');
 
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);