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-init-set.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/PrivateName/proxy-init-set.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/js/src/tests/non262/PrivateName/proxy-init-set.js b/js/src/tests/non262/PrivateName/proxy-init-set.js new file mode 100644 index 0000000000..bc78f50a09 --- /dev/null +++ b/js/src/tests/non262/PrivateName/proxy-init-set.js @@ -0,0 +1,74 @@ +// |reftest| +// Ensure that the distinction between Proxy Init and Proxy Set holds + +function assertThrowsTypeError(f) { + var type; + try { + f(); + } catch (ex) { + type = ex.name; + } + assertEq(type, 'TypeError'); +} + + + +var target = {}; +var p1 = new Proxy(target, {}); +var p2 = new Proxy(target, {}); + +class Base { + constructor(o) { + return o; + } +} + +class A extends Base { + #field = 10; + static gf(o) { + return o.#field; + } + static sf(o) { + o.#field = 15; + } +} + +class B extends Base { + #field = 25; + static gf(o) { + return o.#field; + } + static sf(o) { + o.#field = 20; + } +} + +// Verify field handling on the proxy we install it on. +new A(p1); +assertEq(A.gf(p1), 10); +A.sf(p1) +assertEq(A.gf(p1), 15); + +// Despite P1 being stamped with A's field, it shouldn't +// be sufficient to set B's field. +assertThrowsTypeError(() => B.sf(p1)); +assertThrowsTypeError(() => B.gf(p1)); +assertThrowsTypeError(() => B.sf(p1)); +new B(p1); +assertEq(B.gf(p1), 25); +B.sf(p1); +assertEq(B.gf(p1), 20); + +// A's field should't be on the target +assertThrowsTypeError(() => A.gf(target)); + +// Can't set the field, doesn't exist +assertThrowsTypeError(() => A.sf(p2)); + +// Definitely can't get the field, doesn't exist. +assertThrowsTypeError(() => A.gf(p2)); + +// Still should't be on the target. +assertThrowsTypeError(() => A.gf(target)); + +if (typeof reportCompare === 'function') reportCompare(0, 0);
\ No newline at end of file |