summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/parser/arrow-rest.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/parser/arrow-rest.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/parser/arrow-rest.js')
-rw-r--r--js/src/jit-test/tests/parser/arrow-rest.js204
1 files changed, 204 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/parser/arrow-rest.js b/js/src/jit-test/tests/parser/arrow-rest.js
new file mode 100644
index 0000000000..52db6eb867
--- /dev/null
+++ b/js/src/jit-test/tests/parser/arrow-rest.js
@@ -0,0 +1,204 @@
+// The parser should throw SyntaxError immediately if it finds "..." in a
+// context where it's not allowed.
+
+function testThrow(code, column) {
+ var caught = false;
+ try {
+ eval(code);
+ } catch (e) {
+ caught = true;
+ assertEq(e.columnNumber, column);
+ }
+ assertEq(caught, true,
+ "failed to throw evaluating <" + code + ">");
+}
+
+// expression statement
+
+testThrow(`
+...a)=>
+`, 1);
+
+// default parameter
+
+testThrow(`
+function f(x=...a) =>
+`, 14);
+
+// rest parameter
+
+testThrow(`
+function f(... ...a) =>
+`, 16);
+
+// destructuring parameter
+
+testThrow(`
+([... ...a)=>
+`, 7);
+
+testThrow(`
+({...a)=>
+`, 7);
+
+testThrow(`
+function f([... ...a)=>
+`, 17);
+
+testThrow(`
+function f({...a)=>
+`, 17);
+
+// arrow
+
+testThrow(`
+x => ...a)=>
+`, 6);
+
+// template literal
+
+testThrow("`${ ...a)=>}`", 5);
+
+// destructing assignment
+
+testThrow(`
+var [... ...a)=>
+`, 10);
+
+testThrow(`
+var {...a)=>
+`, 10);
+
+// initializer
+
+testThrow(`
+var [a] = ...a)=>
+`, 11);
+
+testThrow(`
+var {a:a} = ...a)=>
+`, 13);
+
+testThrow(`
+var a = ...a)=>
+`, 9);
+
+// if statement
+
+testThrow(`
+if (...a) =>
+`, 5);
+
+// for statement
+
+testThrow(`
+for (...a)=>
+`, 6);
+
+testThrow(`
+for (let a in ...a)=>
+`, 15);
+
+testThrow(`
+for (let a of ...a)=>
+`, 15);
+
+testThrow(`
+for (; ...a)=>
+`, 8);
+
+testThrow(`
+for (;; ...a)=>
+`, 9);
+
+// case
+
+testThrow(`
+switch (x) { case ...a)=>
+`, 19);
+
+// return statement
+
+testThrow(`
+function f(x) { return ...a)=>
+`, 24);
+
+// yield expression
+
+testThrow(`
+function* f(x) { yield ...a)=>
+`, 24);
+
+// throw statement
+
+testThrow(`
+throw ...a) =>
+`, 7);
+
+// class
+
+testThrow(`
+class A extends ...a) =>
+`, 17);
+
+// conditional expression
+
+testThrow(`
+1 ? ...a) =>
+`, 5);
+
+testThrow(`
+1 ? 2 : ...a) =>
+`, 9);
+
+// unary operators
+
+testThrow(`
+void ...a) =>
+`, 6);
+
+testThrow(`
+typeof ...a) =>
+`, 8);
+
+testThrow(`
+++ ...a) =>
+`, 4);
+
+testThrow(`
+delete ...a) =>
+`, 8);
+
+// new
+
+testThrow(`
+new ...a) =>
+`, 5);
+
+// member expression
+
+testThrow(`
+x[...a) =>
+`, 3);
+
+// array literal
+
+testThrow(`
+[... ...a) =>
+`, 6);
+
+// object literal
+
+testThrow(`
+({[...a) =>
+`, 4);
+
+testThrow(`
+({x: ...a) =>
+`, 6);
+
+// assignment
+
+testThrow(`
+x = ...a) =>
+`, 5);