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/class/innerBinding.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/class/innerBinding.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/js/src/tests/non262/class/innerBinding.js b/js/src/tests/non262/class/innerBinding.js new file mode 100644 index 0000000000..b1afa177e0 --- /dev/null +++ b/js/src/tests/non262/class/innerBinding.js @@ -0,0 +1,86 @@ +// Named class definitions should create an immutable inner binding. +// Since all code in classes is in strict mode, attempts to mutate it +// should throw. +class Foof { constructor() { }; tryBreak() { Foof = 4; } } +for (let result of [Foof, class Bar { constructor() { }; tryBreak() { Bar = 4; } }]) + assertThrowsInstanceOf(() => new result().tryBreak(), TypeError); + +{ + class foo { constructor() { }; tryBreak() { foo = 4; } } + for (let result of [foo, class Bar { constructor() { }; tryBreak() { Bar = 4 } }]) + assertThrowsInstanceOf(() => new result().tryBreak(), TypeError); +} + +// TDZ applies to inner bindings +assertThrowsInstanceOf(()=>eval(`class Bar { + constructor() { }; + [Bar] () { }; + }`), ReferenceError); + +assertThrowsInstanceOf(()=>eval(`(class Bar { + constructor() { }; + [Bar] () { }; + })`), ReferenceError); + +// There's no magic "inner binding" global +{ + class Foo { + constructor() { }; + test() { + class Bar { + constructor() { } + test() { return Foo === Bar } + } + return new Bar().test(); + } + } + assertEq(new Foo().test(), false); + assertEq(new class foo { + constructor() { }; + test() { + return new class bar { + constructor() { } + test() { return foo === bar } + }().test(); + } + }().test(), false); +} + +// Inner bindings are shadowable +{ + class Foo { + constructor() { } + test(Foo) { return Foo; } + } + assertEq(new Foo().test(4), 4); + assertEq(new class foo { + constructor() { }; + test(foo) { return foo } + }().test(4), 4); +} + +// Inner bindings in expressions should shadow even existing names. +class Foo { constructor() { } static method() { throw new Error("NO!"); } } +assertEq(new class Foo { + constructor() { }; + static method() { return 4; }; + test() { return Foo.method(); } + }().test(), 4); + +// The outer binding is distinct from the inner one +{ + let orig_X; + + class X { + constructor() { } + f() { assertEq(X, orig_X); } + } + + orig_X = X; + X = 13; + assertEq(X, 13); + new orig_X().f(); +} + +if (typeof reportCompare === "function") + reportCompare(0, 0, "OK"); |