tor-browser

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

Frame-evalWithBindings-01.js (767B)


      1 // evalWithBindings basics
      2 
      3 var g = newGlobal({newCompartment: true});
      4 var dbg = new Debugger(g);
      5 var hits = 0;
      6 dbg.onDebuggerStatement = function (frame) {
      7    assertEq(frame.evalWithBindings("x", {x: 2}).return, 2);
      8    assertEq(frame.evalWithBindings("x + y", {x: 2}).return, 5);
      9    hits++;
     10 };
     11 
     12 // in global code
     13 g.y = 3;
     14 g.eval("debugger;");
     15 
     16 // in function code
     17 g.y = "fail";
     18 g.eval("function f(y) { debugger; }");
     19 g.f(3);
     20 
     21 // in direct eval code
     22 g.eval("function f() { var y = 3; eval('debugger;'); }");
     23 g.f();
     24 
     25 // in strict eval code with var
     26 g.eval("function f() { 'use strict'; eval('var y = 3; debugger;'); }");
     27 g.f();
     28 
     29 // in a with block
     30 g.eval("with ({y: 3}) { debugger; }");
     31 
     32 // shadowing
     33 g.eval("{ let x = 50, y = 3; debugger; }");
     34 
     35 assertEq(hits, 6);