tor-browser

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

test_bug267645.js (3263B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 function run_test() {
      6  let sb = new Cu.Sandbox("https://example.com",
      7                          { wantGlobalProperties: ["DOMException"] });
      8  Cu.exportFunction(function() {
      9    undefined.foo();
     10  }, sb, { defineAs: "func" });
     11  // By default, the stacks of things running in a sandbox will contain the
     12  // actual evalInSandbox() call location.  To override that, we have to pass an
     13  // explicit filename.
     14  let threw = Cu.evalInSandbox("var threw; try { func(); threw = false; } catch (e) { globalThis.exn = e; threw = true } threw",
     15                                sb, "", "FakeFile");
     16  Assert.ok(threw);
     17 
     18  // Check what the sandbox could see from this exception.
     19  Assert.ok(!Cu.evalInSandbox("exn.filename", sb).includes("/unit/"));
     20  Assert.equal(Cu.evalInSandbox("exn.fileName", sb), undefined);
     21  Assert.ok(!Cu.evalInSandbox("exn.stack", sb).includes("/unit/"));
     22  Assert.equal(Cu.evalInSandbox("exn.message", sb), "An exception was thrown");
     23  Assert.equal(Cu.evalInSandbox("exn.name", sb), "InvalidStateError");
     24 
     25  Cu.exportFunction(function() {
     26    throw new Error("Hello");
     27  }, sb, { defineAs: "func2" });
     28  threw = Cu.evalInSandbox("var threw; try { func2(); threw = false; } catch (e) { globalThis.exn = e; threw = true } threw",
     29                                sb, "", "FakeFile");
     30  Assert.ok(threw);
     31  Assert.ok(!Cu.evalInSandbox("exn.filename", sb).includes("/unit/"));
     32  Assert.equal(Cu.evalInSandbox("exn.fileName", sb), undefined);
     33  Assert.ok(!Cu.evalInSandbox("exn.stack", sb).includes("/unit/"));
     34  Assert.equal(Cu.evalInSandbox("exn.message", sb), "An exception was thrown");
     35  Assert.equal(Cu.evalInSandbox("exn.name", sb), "InvalidStateError");
     36 
     37  let ctor = Cu.evalInSandbox("TypeError", sb);
     38  Cu.exportFunction(function() {
     39    throw new ctor("Hello");
     40  }, sb, { defineAs: "func3" });
     41  threw = Cu.evalInSandbox("var threw; try { func3(); threw = false; } catch (e) { globalThis.exn = e; threw = true } threw",
     42                                sb, "", "FakeFile");
     43  Assert.ok(threw);
     44  Assert.ok(!Cu.evalInSandbox("exn.fileName", sb).includes("/unit/"));
     45  Assert.equal(Cu.evalInSandbox("exn.filename", sb), undefined);
     46  Assert.ok(!Cu.evalInSandbox("exn.stack", sb).includes("/unit/"));
     47  Assert.equal(Cu.evalInSandbox("exn.message", sb), "Hello");
     48  Assert.equal(Cu.evalInSandbox("exn.name", sb), "TypeError");
     49 
     50  ctor = Cu.evalInSandbox("DOMException", sb);
     51  Cu.exportFunction(function() {
     52    throw new ctor("Goodbye", "InvalidAccessError");
     53  }, sb, { defineAs: "func4" });
     54  threw = Cu.evalInSandbox("var threw; try { func4(); threw = false; } catch (e) { globalThis.exn = e; threw = true } threw",
     55                                sb, "", "FakeFile");
     56  Assert.ok(threw);
     57  Assert.ok(!Cu.evalInSandbox("exn.filename", sb).includes("/unit/"));
     58  Assert.equal(Cu.evalInSandbox("exn.fileName", sb), undefined);
     59  Assert.ok(!Cu.evalInSandbox("exn.stack", sb).includes("/unit/"));
     60  Assert.equal(Cu.evalInSandbox("exn.message", sb), "Goodbye");
     61  Assert.equal(Cu.evalInSandbox("exn.name", sb), "InvalidAccessError");
     62 }