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/jit-test/tests/class/class-static-01.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/jit-test/tests/class/class-static-01.js')
-rw-r--r-- | js/src/jit-test/tests/class/class-static-01.js | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/class/class-static-01.js b/js/src/jit-test/tests/class/class-static-01.js new file mode 100644 index 0000000000..ee41def1fb --- /dev/null +++ b/js/src/jit-test/tests/class/class-static-01.js @@ -0,0 +1,172 @@ +// |jit-test| +load(libdir + "asserts.js"); + +// Parse +class A { + static { } +}; + +// Run +var ran = false; +class B { + static { + ran = true; + } +}; + +assertEq(ran, true); + +// Can access static assigned before. +var res; +class C { + static x = 10; + static { + res = this.x; + } +}; + +assertEq(res, 10); + +// Multiple static blocks +class D { + static { } + static { } +}; + +class D1 { + static { } static { } +}; + +// Blocks run in order. +class E { + static { + res = 10; + } + static { + assertEq(res, 10); + res = 14; + } +} + +assertEq(res, 14); + + +// Can use static to access private state. +let accessor; +class F { + #x = 10 + static { + accessor = (o) => o.#x; + } +} + +let f = new F; +assertEq(accessor(f), 10); + +class G { + static { + this.a = 10; + } +} +assertEq(G.a, 10); + +// Can use the super-keyword to access a static method in super class. +class H { + static a() { return 101; } +} + +class I extends H { + static { + res = super.a(); + } +} + +assertEq(res, 101); + +// Can add a property to a class from within a static +class J { + static { + this.x = 12; + } +} + +assertEq(J.x, 12); + + +function assertThrowsSyntaxError(str) { + assertThrowsInstanceOf(() => eval(str), SyntaxError); // Direct Eval + assertThrowsInstanceOf(() => (1, eval)(str), SyntaxError); // Indirect Eval + assertThrowsInstanceOf(() => Function(str), SyntaxError); // Function +} + +assertThrowsSyntaxError(` +class X { + static { + arguments; + } +} +`) + + +assertThrowsSyntaxError(` +class X extends class {} { + static { + super(); // can't call super in a static block + } +} +`) + +assertThrowsSyntaxError(` +class X { + static { + return 10; // Can't return in a static block + } +} +`) + +assertThrowsSyntaxError(` +class X { + static { + await 10; // Can't await in a static block + } +} +`) + +// Can't await inside a static block, even if we're inside an async function. +// +// The error message here is not good `SyntaxError: await is a reserved identifier`, +// but can be fixed later. s +assertThrowsSyntaxError(` +async function f() { + class X { + static { + await 10; // Can't await in a static block + } + } +} +`) + + +assertThrowsSyntaxError(` +class X { + static { + yield 10; // Can't yield in a static block + } +} +`) + + +assertThrowsSyntaxError(` +function* gen() { + class X { + static { + yield 10; // Can't yield in a static block, even inside a generator + } + } +} +`) + +// Incomplete should throw a sensible error. +assertThrowsSyntaxError(` +class A { static { this.x +`)
\ No newline at end of file |