summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/unit/test_bug267645.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /js/xpconnect/tests/unit/test_bug267645.js
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/xpconnect/tests/unit/test_bug267645.js')
-rw-r--r--js/xpconnect/tests/unit/test_bug267645.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/js/xpconnect/tests/unit/test_bug267645.js b/js/xpconnect/tests/unit/test_bug267645.js
new file mode 100644
index 0000000000..6196a2165c
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_bug267645.js
@@ -0,0 +1,62 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+function run_test() {
+ let sb = new Cu.Sandbox("https://example.com",
+ { wantGlobalProperties: ["DOMException"] });
+ Cu.exportFunction(function() {
+ undefined.foo();
+ }, sb, { defineAs: "func" });
+ // By default, the stacks of things running in a sandbox will contain the
+ // actual evalInSandbox() call location. To override that, we have to pass an
+ // explicit filename.
+ let threw = Cu.evalInSandbox("var threw; try { func(); threw = false; } catch (e) { globalThis.exn = e; threw = true } threw",
+ sb, "", "FakeFile");
+ Assert.ok(threw);
+
+ // Check what the sandbox could see from this exception.
+ Assert.ok(!Cu.evalInSandbox("exn.filename", sb).includes("/unit/"));
+ Assert.equal(Cu.evalInSandbox("exn.fileName", sb), undefined);
+ Assert.ok(!Cu.evalInSandbox("exn.stack", sb).includes("/unit/"));
+ Assert.equal(Cu.evalInSandbox("exn.message", sb), "An exception was thrown");
+ Assert.equal(Cu.evalInSandbox("exn.name", sb), "InvalidStateError");
+
+ Cu.exportFunction(function() {
+ throw new Error("Hello");
+ }, sb, { defineAs: "func2" });
+ threw = Cu.evalInSandbox("var threw; try { func2(); threw = false; } catch (e) { globalThis.exn = e; threw = true } threw",
+ sb, "", "FakeFile");
+ Assert.ok(threw);
+ Assert.ok(!Cu.evalInSandbox("exn.filename", sb).includes("/unit/"));
+ Assert.equal(Cu.evalInSandbox("exn.fileName", sb), undefined);
+ Assert.ok(!Cu.evalInSandbox("exn.stack", sb).includes("/unit/"));
+ Assert.equal(Cu.evalInSandbox("exn.message", sb), "An exception was thrown");
+ Assert.equal(Cu.evalInSandbox("exn.name", sb), "InvalidStateError");
+
+ let ctor = Cu.evalInSandbox("TypeError", sb);
+ Cu.exportFunction(function() {
+ throw new ctor("Hello");
+ }, sb, { defineAs: "func3" });
+ threw = Cu.evalInSandbox("var threw; try { func3(); threw = false; } catch (e) { globalThis.exn = e; threw = true } threw",
+ sb, "", "FakeFile");
+ Assert.ok(threw);
+ Assert.ok(!Cu.evalInSandbox("exn.fileName", sb).includes("/unit/"));
+ Assert.equal(Cu.evalInSandbox("exn.filename", sb), undefined);
+ Assert.ok(!Cu.evalInSandbox("exn.stack", sb).includes("/unit/"));
+ Assert.equal(Cu.evalInSandbox("exn.message", sb), "Hello");
+ Assert.equal(Cu.evalInSandbox("exn.name", sb), "TypeError");
+
+ ctor = Cu.evalInSandbox("DOMException", sb);
+ Cu.exportFunction(function() {
+ throw new ctor("Goodbye", "InvalidAccessError");
+ }, sb, { defineAs: "func4" });
+ threw = Cu.evalInSandbox("var threw; try { func4(); threw = false; } catch (e) { globalThis.exn = e; threw = true } threw",
+ sb, "", "FakeFile");
+ Assert.ok(threw);
+ Assert.ok(!Cu.evalInSandbox("exn.filename", sb).includes("/unit/"));
+ Assert.equal(Cu.evalInSandbox("exn.fileName", sb), undefined);
+ Assert.ok(!Cu.evalInSandbox("exn.stack", sb).includes("/unit/"));
+ Assert.equal(Cu.evalInSandbox("exn.message", sb), "Goodbye");
+ Assert.equal(Cu.evalInSandbox("exn.name", sb), "InvalidAccessError");
+}