diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/PrivateName/proxy-ccw.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/PrivateName/proxy-ccw.js')
-rw-r--r-- | js/src/tests/non262/PrivateName/proxy-ccw.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/js/src/tests/non262/PrivateName/proxy-ccw.js b/js/src/tests/non262/PrivateName/proxy-ccw.js new file mode 100644 index 0000000000..94778489b6 --- /dev/null +++ b/js/src/tests/non262/PrivateName/proxy-ccw.js @@ -0,0 +1,66 @@ +// |reftest| + +// Validate CCWs and proxies +class Base { + constructor(o) { + return o; + } +} + +class A extends Base { + x1 = 12; + #x = 10; + static gx(o) { + return o.#x; + } + static sx(o, x) { + o.#x = x; + } + static hasx(o) { + try { + o.#x; + return true; + } catch { + return false; + } + } +} + + +var g = newGlobal({newCompartment: true}); +g.A = A; + +// cross_compartment_target is a cross compartment wrapper to an empty object. +var cross_compartment_target = g.eval('this.x = {}; this.x'); + +// #x gets stamped into the target of the CCW. +new A(cross_compartment_target); +assertEq(A.hasx(cross_compartment_target), true); + +// Can we update and read from this compartment? +assertEq(A.gx(cross_compartment_target), 10); +var o = {test: 12}; +A.sx(cross_compartment_target, o); +assertEq(A.gx(cross_compartment_target), o); + +// Can we read and update from the other compartment? +assertEq(g.eval('this.A.gx(this.x)'), o); +var y = g.eval('this.y = {test: 13}; this.A.sx(this.x, this.y); this.y'); +assertEq(g.eval('this.A.gx(this.x)'), y); +assertEq(A.gx(cross_compartment_target), y); + + +if (typeof nukeCCW === 'function') { + // Nuke the CCW. Now things should throw. + nukeCCW(cross_compartment_target); + var threw = true; + try { + A.gx(cross_compartment_target); + threw = false; + } catch (e) { + } + assertEq(threw, true); +} + + +if (typeof reportCompare === 'function') reportCompare(0, 0);
\ No newline at end of file |