summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/xpcshell/test_nativewrappers.js
blob: ae247fb1543e0300f5b5de0f90d12ddeaacc1b1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* eslint-disable strict */
function run_test() {
  Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
  registerCleanupFunction(() => {
    Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
  });
  const { addDebuggerToGlobal } = ChromeUtils.importESModule(
    "resource://gre/modules/jsdebugger.sys.mjs"
  );
  addDebuggerToGlobal(globalThis);
  const g = createTestGlobal("test1");

  const dbg = makeDebugger();
  dbg.addDebuggee(g);
  dbg.onDebuggerStatement = function(frame) {
    const args = frame.arguments;
    try {
      args[0];
      Assert.ok(true);
    } catch (ex) {
      Assert.ok(false);
    }
  };

  g.eval("function stopMe(arg) {debugger;}");

  const g2 = createTestGlobal("test2");
  g2.g = g;
  // Not using the "stringify a function" trick because that runs afoul of the
  // Cu.importGlobalProperties lint and we don't need it here anyway.
  g2.eval(`(function createBadEvent() {
    Cu.importGlobalProperties(["DOMParser"]);
    let parser = new DOMParser();
    let doc = parser.parseFromString("<foo></foo>", "text/xml");
    g.stopMe(doc.createEvent("MouseEvent"));
  } )()`);

  dbg.disable();
}