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.

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

mercurial