tor-browser

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

Source-text-02.js (856B)


      1 // Nested compilation units (say, an eval with in an eval) should have the
      2 // correct sources attributed to them.
      3 let g = newGlobal({newCompartment: true});
      4 let dbg = new Debugger(g);
      5 
      6 var text;
      7 var count = 0;
      8 dbg.onNewScript = function (script) {
      9    ++count;
     10    if (count % 2 == 0)
     11        assertEq(script.source.text, text);
     12 }
     13 
     14 g.eval("eval('" + (text = "") + "')");
     15 g.eval("eval('" + (text = "2 * 3") + "')");
     16 
     17 // `new Function(${string})` generates source wrapped with `function anonymous(args) {${string}}`
     18 text = "function anonymous(\n) {\n\n}";
     19 g.eval("new Function('')");
     20 
     21 text = "function anonymous(a,b\n) {\nc\n}";
     22 g.eval("new Function('a', 'b', 'c')");
     23 
     24 text = "function anonymous(d\n,e\n) {\nf\n}";
     25 g.eval("new Function('d\\n', 'e', 'f')");
     26 
     27 evaluate("", { global: g });
     28 text = "2 * 3";
     29 evaluate("2 * 3", { global: g });
     30 assertEq(count, 12);