tor-browser

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

Script-getEffectfulOffsets.js (1428B)


      1 // Check that Script.getEffectfulOffsets behaves sensibly.
      2 
      3 var g = newGlobal({newCompartment: true});
      4 var dbg = Debugger(g);
      5 var numEffectfulOperations;
      6 
      7 function onNewScript(script) {
      8  script.getChildScripts().forEach(onNewScript);
      9  numEffectfulOperations += script.getEffectfulOffsets().length;
     10 }
     11 dbg.onNewScript = onNewScript;
     12 
     13 function test(code, expected) {
     14  numEffectfulOperations = 0;
     15  g.eval(`
     16 function f(a, b, c) {
     17 ${code}
     18 }
     19 `);
     20  assertEq(numEffectfulOperations, expected);
     21 }
     22 
     23 const base = 1;
     24 test("", base);
     25 
     26 test("a.f = 0", base + 1);
     27 test("a.f++", base + 1);
     28 test("return a.f", base + 0);
     29 test("a[b] = 0", base + 1);
     30 test("a[b]++", base + 1);
     31 test("return a[b]", base + 0);
     32 test("a = 0", base + 0);
     33 test("d = 0", base + 1);
     34 test("with (a) { b = 0; }", base + 7);
     35 test("let o = {}; ({x: o.x} = { x: 10 })", base + 1);
     36 test("var x", base + 0);
     37 
     38 // d is not closed over, and "let d = 0;" uses InitLexical,
     39 // which is non-effectful.
     40 test(`
     41 let d = 10;
     42 `, base + 0);
     43 
     44 // d is closed over, and "let d = 0;" uses InitAliasedLexical with hops == 0,
     45 // which is non-effectful.
     46 test(`
     47 let d = 10;
     48 function g() {
     49  d;
     50 }
     51 `, base + 0);
     52 
     53 // Private accessor uses InitAliasedLexical with hops == 1,
     54 // which is currently marked as effectful.
     55 // Please fix this test if it's marked as non-effectful in the future.
     56 test(`
     57 class B {
     58  set #x(x) {}
     59 }
     60 `, base + 1);
     61 
     62 test(`
     63 class B {
     64  get #x() {}
     65  set #x(x) {}
     66 }
     67 `, base + 2);