tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Object-executeInGlobal-04.js (2407B)


      1 // Debugger.Object.prototype.executeInGlobal: nested evals
      2 
      3 var g = newGlobal({newCompartment: true});
      4 var dbg = new Debugger;
      5 var gw = dbg.addDebuggee(g);
      6 
      7 assertEq(gw.executeInGlobal("eval('\"Awake\"');").return, "Awake");
      8 
      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.executeInGlobal("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");
     19 
     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.executeInGlobalWithBindings("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");
     30 
     31 
     32 // Strict mode code variants of the above:
     33 
     34 // Strict mode still lets us create bindings on the global as this is
     35 // equivalent to executing statements at the global level. But note that
     36 // setting strict mode means that nested evals get their own call objects.
     37 g.x = "Swing Lo Magellan";
     38 g.y = "The Milk-Eyed Mender";
     39 assertEq(gw.executeInGlobal("\'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, "Merriweather Post Pavilion");
     46 
     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.executeInGlobalWithBindings("'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, "Merriweather Post Pavilion");