tor-browser

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

test_source-03.js (2821B)


      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 a 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 two copies of the source file. The first call to "loadSubScript" will
     23      // create a ScriptSourceObject and a JSScript which references it.
     24      // The second call will attempt to re-use JSScript objects because that is
     25      // what loadSubScript does for instances of the same file that are loaded
     26      // in the system principal in the same compartment.
     27      //
     28      // We explicitly want this because it is an edge case of the server. Most
     29      // of the time a Debugger.Source will only have a single Debugger.Script
     30      // associated with a given function, but in the context of explicitly
     31      // cloned JSScripts, this is not the case, and we need to handle that.
     32      loadSubScript(SOURCE_URL, debuggee1);
     33      loadSubScript(SOURCE_URL, debuggee2);
     34 
     35      await promise;
     36 
     37      // We want to set a breakpoint and make sure that the breakpoint is properly
     38      // set on _both_ files backed
     39      await setBreakpoint(threadFront, {
     40        sourceUrl: SOURCE_URL,
     41        line: 4,
     42      });
     43 
     44      const { sources } = await getSources(threadFront);
     45 
     46      // Note: Since we load the file twice, we end up with two copies of the
     47      // source object, and so two sources here.
     48      Assert.equal(sources.length, 2);
     49 
     50      // Ensure that the breakpoint was properly applied to the JSScipt loaded
     51      // in the first global.
     52      let pausedOne = false;
     53      let onResumed = null;
     54      threadFront.once("paused", function () {
     55        pausedOne = true;
     56        onResumed = resume(threadFront);
     57      });
     58      Cu.evalInSandbox("init()", debuggee1, "1.8", "test.js", 1);
     59      await onResumed;
     60      Assert.equal(pausedOne, true);
     61 
     62      // Ensure that the breakpoint was properly applied to the JSScipt loaded
     63      // in the second global.
     64      let pausedTwo = false;
     65      threadFront.once("paused", function () {
     66        pausedTwo = true;
     67        onResumed = resume(threadFront);
     68      });
     69      Cu.evalInSandbox("init()", debuggee2, "1.8", "test.js", 1);
     70      await onResumed;
     71      Assert.equal(pausedTwo, true);
     72    },
     73    { doNotRunWorker: true }
     74  )
     75 );