tor-browser

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

Debugger-findScripts-uncompleted-01.js (1570B)


      1 // |jit-test| skip-if: isLcovEnabled()
      2 
      3 // Uncompleted scripts and their inner scripts shouldn't be found in
      4 // findScripts.
      5 
      6 let g = newGlobal({newCompartment: true});
      7 let dbg = new Debugger(g);
      8 
      9 let message = "";
     10 try {
     11  g.eval(`
     12 (function nonLazyOuter() {
     13  (function nonLazyInner() {
     14    function lazy1() {
     15      function lazy2() {
     16      }
     17    }
     18  })();
     19 })();
     20 
     21 (function uncompletedNonLazy() {
     22  function lazyInUncompleted1() {
     23    function lazyInUncompleted2() {
     24    }
     25  }
     26  // LazyScripts for above 2 functions are created when parsing,
     27  // and JSScript for uncompletedNonLazy is created at the beginning of
     28  // compiling it, but it doesn't get code() since the following switch-case
     29  // throws error while emitting bytecode.
     30  switch (1) {
     31    ${"case 1:".repeat(2**16+1)}
     32  }
     33 })();
     34 `);
     35 } catch (e) {
     36  message = e.message;
     37 }
     38 
     39 assertEq(message.includes("too many switch cases"), true,
     40         "Error for switch-case should be thrown," +
     41         "in order to test the case that uncompleted script is created");
     42 
     43 for (var script of dbg.findScripts()) {
     44  // Since all of above scripts can be GCed, we cannot check the set of
     45  // found scripts.
     46  if (script.displayName) {
     47    assertEq(script.displayName != "uncompletedNonLazy", true,
     48             "Uncompiled script shouldn't be found");
     49    assertEq(script.displayName != "lazyInUncompleted1", true,
     50             "Scripts inside uncompiled script shouldn't be found");
     51    assertEq(script.displayName != "lazyInUncompleted2", true,
     52             "Scripts inside uncompiled script shouldn't be found");
     53  }
     54 }