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/fields/error.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/fields/error.js')
-rw-r--r-- | js/src/jit-test/tests/fields/error.js | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/fields/error.js b/js/src/jit-test/tests/fields/error.js new file mode 100644 index 0000000000..4c164b2bbc --- /dev/null +++ b/js/src/jit-test/tests/fields/error.js @@ -0,0 +1,116 @@ +load(libdir + 'asserts.js'); + +let source = `class C { + x = +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `class C { + -2; + -2 = 2; +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `class C { + x += 2; +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `class C { + #2; +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `class C { + #["h" + "i"]; +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `class C { + #"hi"; +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `class C { + constructor; +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `class C { + "constructor"; +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `class C { + x = arguments; +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `class C { + x = super(); +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `function f() { +class C { + #"should still throw error during lazy parse"; +} +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `#outside;`; +assertErrorMessage(() => eval(source), SyntaxError, /./); + +source = `class C { + x = super(); +}`; +assertErrorMessage(() => Function(source), SyntaxError, /./); + +source = `class C { + x = sper(); +}`; +eval(source); + + +// The following test cases fail to parse because ASI does not happen if the +// next token might be valid, even if it leads to a SyntaxError further down +// the road. + +source = `class C { + x = 0 + ["computedMethodName"](){} +}`; +assertThrowsInstanceOf(() => Function(source), SyntaxError); + +source = `class C { + x = 0 + *f(){} +}`; +assertThrowsInstanceOf(() => Function(source), SyntaxError); + + +// The following test cases fail to parse because ASI doesn't happen without a +// newline. + +source = `class C { x y }`; +assertThrowsInstanceOf(() => Function(source), SyntaxError); + +source = `class C { if var } // identifiers that look like keywords`; +assertThrowsInstanceOf(() => Function(source), SyntaxError); + +source = `class C { x = 1 y }`; +assertThrowsInstanceOf(() => Function(source), SyntaxError); + +source = `class C { x async f() {} }`; +assertThrowsInstanceOf(() => Function(source), SyntaxError); + +source = `class C { x static f() {} }`; +assertThrowsInstanceOf(() => Function(source), SyntaxError); + +source = `class C { field1 static field2 }`; +assertThrowsInstanceOf(() => Function(source), SyntaxError); + +source = `class C { x get f() {} }`; +assertThrowsInstanceOf(() => Function(source), SyntaxError); + +if (typeof reportCompare === 'function') reportCompare(true, true); |