tor-browser

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

test_source-04.js (2738B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const SOURCE_URL = getFileUrl("source-03.js");
      7 
      8 add_task(
      9  threadFrontTest(
     10    async ({ threadFront, server }) => {
     11      const promise = waitForNewSource(threadFront, SOURCE_URL);
     12 
     13      // Create two globals in the default junk sandbox compartment so that
     14      // both globals are part of the same compartment.
     15      server.allowNewThreadGlobals();
     16      const debuggee1 = Cu.Sandbox("http://example.com");
     17      debuggee1.__name = "debuggee2.js";
     18      const debuggee2 = Cu.Sandbox("http://example.com");
     19      debuggee2.__name = "debuggee2.js";
     20      server.disallowNewThreadGlobals();
     21 
     22      // Load first copy of the source file. The first call to "loadSubScript" will
     23      // create a ScriptSourceObject and a JSScript which references it.
     24      loadSubScript(SOURCE_URL, debuggee1);
     25 
     26      await promise;
     27 
     28      // We want to set a breakpoint and make sure that the breakpoint is properly
     29      // set on _both_ files backed
     30      await setBreakpoint(threadFront, {
     31        sourceUrl: SOURCE_URL,
     32        line: 4,
     33      });
     34 
     35      const { sources } = await getSources(threadFront);
     36      Assert.equal(sources.length, 1);
     37 
     38      // Ensure that the breakpoint was properly applied to the JSScipt loaded
     39      // in the first global.
     40      let pausedOne = false;
     41      let onResumed = null;
     42      threadFront.once("paused", function () {
     43        pausedOne = true;
     44        onResumed = resume(threadFront);
     45      });
     46      Cu.evalInSandbox("init()", debuggee1, "1.8", "test.js", 1);
     47      await onResumed;
     48      Assert.equal(pausedOne, true);
     49 
     50      // Load second copy of the source file. The second call will attempt to
     51      // re-use JSScript objects because that is what loadSubScript does for
     52      // instances of the same file that are loaded in the system principal in
     53      // the same compartment.
     54      //
     55      // We explicitly want this because it is an edge case of the server. Most
     56      // of the time a Debugger.Source will only have a single Debugger.Script
     57      // associated with a given function, but in the context of explicitly
     58      // cloned JSScripts, this is not the case, and we need to handle that.
     59      loadSubScript(SOURCE_URL, debuggee2);
     60 
     61      // Ensure that the breakpoint was properly applied to the JSScipt loaded
     62      // in the second global.
     63      let pausedTwo = false;
     64      threadFront.once("paused", function () {
     65        pausedTwo = true;
     66        onResumed = resume(threadFront);
     67      });
     68      Cu.evalInSandbox("init()", debuggee2, "1.8", "test.js", 1);
     69      await onResumed;
     70      Assert.equal(pausedTwo, true);
     71    },
     72    { doNotRunWorker: true }
     73  )
     74 );