michael@0: // Debugger.Object.prototype.evalInGlobal: nested evals michael@0: michael@0: var g = newGlobal(); michael@0: var dbg = new Debugger; michael@0: var gw = dbg.addDebuggee(g); michael@0: michael@0: assertEq(gw.evalInGlobal("eval('\"Awake\"');").return, "Awake"); michael@0: michael@0: // Evaluating non-strict-mode code uses the given global as its variable michael@0: // environment. michael@0: g.x = "Swing Lo Magellan"; michael@0: g.y = "The Milk-Eyed Mender"; michael@0: assertEq(gw.evalInGlobal("eval('var x = \"A Brief History of Love\"');\n" michael@0: + "var y = 'Merriweather Post Pavilion';" michael@0: + "x;").return, michael@0: "A Brief History of Love"); michael@0: assertEq(g.x, "A Brief History of Love"); michael@0: assertEq(g.y, "Merriweather Post Pavilion"); michael@0: michael@0: // As above, but notice that we still create bindings on the global, even michael@0: // when we've interposed a new environment via 'withBindings'. michael@0: g.x = "Swing Lo Magellan"; michael@0: g.y = "The Milk-Eyed Mender"; michael@0: assertEq(gw.evalInGlobalWithBindings("eval('var x = d1;'); var y = d2; x;", michael@0: { d1: "A Brief History of Love", michael@0: d2: "Merriweather Post Pavilion" }).return, michael@0: "A Brief History of Love"); michael@0: assertEq(g.x, "A Brief History of Love"); michael@0: assertEq(g.y, "Merriweather Post Pavilion"); michael@0: michael@0: michael@0: // Strict mode code variants of the above: michael@0: michael@0: // Evaluating strict-mode code uses a fresh call object as its variable environment. michael@0: // Also, calls to eval from strict-mode code run the eval code in a fresh michael@0: // call object. michael@0: g.x = "Swing Lo Magellan"; michael@0: g.y = "The Milk-Eyed Mender"; michael@0: assertEq(gw.evalInGlobal("\'use strict\';\n" michael@0: + "eval('var x = \"A Brief History of Love\"');\n" michael@0: + "var y = \"Merriweather Post Pavilion\";" michael@0: + "x;").return, michael@0: "Swing Lo Magellan"); michael@0: assertEq(g.x, "Swing Lo Magellan"); michael@0: assertEq(g.y, "The Milk-Eyed Mender"); michael@0: michael@0: // Introducing a bindings object shouldn't change this behavior. michael@0: g.x = "Swing Lo Magellan"; michael@0: g.y = "The Milk-Eyed Mender"; michael@0: assertEq(gw.evalInGlobalWithBindings("'use strict'; eval('var x = d1;'); var y = d2; x;", michael@0: { d1: "A Brief History of Love", michael@0: d2: "Merriweather Post Pavilion" }).return, michael@0: "Swing Lo Magellan"); michael@0: assertEq(g.x, "Swing Lo Magellan"); michael@0: assertEq(g.y, "The Milk-Eyed Mender");