js/src/jit-test/tests/debug/Object-evalInGlobal-04.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Debugger.Object.prototype.evalInGlobal: nested evals
     3 var g = newGlobal();
     4 var dbg = new Debugger;
     5 var gw = dbg.addDebuggee(g);
     7 assertEq(gw.evalInGlobal("eval('\"Awake\"');").return, "Awake");
     9 // Evaluating non-strict-mode code uses the given global as its variable
    10 // environment.
    11 g.x = "Swing Lo Magellan";
    12 g.y = "The Milk-Eyed Mender";
    13 assertEq(gw.evalInGlobal("eval('var x = \"A Brief History of Love\"');\n"
    14                          + "var y = 'Merriweather Post Pavilion';"
    15                          + "x;").return,
    16          "A Brief History of Love");
    17 assertEq(g.x, "A Brief History of Love");
    18 assertEq(g.y, "Merriweather Post Pavilion");
    20 // As above, but notice that we still create bindings on the global, even
    21 // when we've interposed a new environment via 'withBindings'.
    22 g.x = "Swing Lo Magellan";
    23 g.y = "The Milk-Eyed Mender";
    24 assertEq(gw.evalInGlobalWithBindings("eval('var x = d1;'); var y = d2; x;",
    25                                      { d1: "A Brief History of Love",
    26                                        d2: "Merriweather Post Pavilion" }).return,
    27          "A Brief History of Love");
    28 assertEq(g.x, "A Brief History of Love");
    29 assertEq(g.y, "Merriweather Post Pavilion");
    32 // Strict mode code variants of the above:
    34 // Evaluating strict-mode code uses a fresh call object as its variable environment.
    35 // Also, calls to eval from strict-mode code run the eval code in a fresh
    36 // call object.
    37 g.x = "Swing Lo Magellan";
    38 g.y = "The Milk-Eyed Mender";
    39 assertEq(gw.evalInGlobal("\'use strict\';\n"
    40                          + "eval('var x = \"A Brief History of Love\"');\n"
    41                          + "var y = \"Merriweather Post Pavilion\";"
    42                          + "x;").return,
    43          "Swing Lo Magellan");
    44 assertEq(g.x, "Swing Lo Magellan");
    45 assertEq(g.y, "The Milk-Eyed Mender");
    47 // Introducing a bindings object shouldn't change this behavior.
    48 g.x = "Swing Lo Magellan";
    49 g.y = "The Milk-Eyed Mender";
    50 assertEq(gw.evalInGlobalWithBindings("'use strict'; eval('var x = d1;'); var y = d2; x;",
    51                                      { d1: "A Brief History of Love",
    52                                        d2: "Merriweather Post Pavilion" }).return,
    53          "Swing Lo Magellan");
    54 assertEq(g.x, "Swing Lo Magellan");
    55 assertEq(g.y, "The Milk-Eyed Mender");

mercurial