summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/unit/test_private_field_xrays.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /js/xpconnect/tests/unit/test_private_field_xrays.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/xpconnect/tests/unit/test_private_field_xrays.js')
-rw-r--r--js/xpconnect/tests/unit/test_private_field_xrays.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/js/xpconnect/tests/unit/test_private_field_xrays.js b/js/xpconnect/tests/unit/test_private_field_xrays.js
new file mode 100644
index 0000000000..bd37eb44c7
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_private_field_xrays.js
@@ -0,0 +1,58 @@
+'use strict'
+
+ChromeUtils.importESModule("resource://gre/modules/Preferences.sys.mjs");
+
+add_task(async function () {
+ let webnav = Services.appShell.createWindowlessBrowser(false);
+
+ let docShell = webnav.docShell;
+
+ docShell.createAboutBlankContentViewer(null, null);
+
+ let window = webnav.document.defaultView;
+
+ let iframe = window.eval(`
+ iframe = document.createElement("iframe");
+ iframe.id = "iframe"
+ document.body.appendChild(iframe)
+ iframe`);
+
+
+ let unwrapped = Cu.waiveXrays(iframe);
+
+
+ class Base {
+ constructor(o) {
+ return o;
+ }
+ };
+
+
+ class A extends Base {
+ #x = 12;
+ static gx(o) {
+ return o.#x;
+ }
+
+ static sx(o, v) {
+ o.#x = v;
+ }
+ };
+
+ new A(iframe);
+ Assert.equal(A.gx(iframe), 12);
+ A.sx(iframe, 'wrapped');
+
+ // Shouldn't tunnel past xray.
+ Assert.throws(() => A.gx(unwrapped), TypeError);
+ Assert.throws(() => A.sx(unwrapped, 'unwrapped'), TypeError);
+
+ new A(unwrapped);
+ Assert.equal(A.gx(unwrapped), 12);
+ Assert.equal(A.gx(iframe), 'wrapped');
+
+ A.sx(iframe, 'modified');
+ Assert.equal(A.gx(unwrapped), 12);
+ A.sx(unwrapped, 16);
+ Assert.equal(A.gx(iframe), 'modified');
+});