summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/reflect-parse/for-loop-destructuring.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/non262/reflect-parse/for-loop-destructuring.js
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/reflect-parse/for-loop-destructuring.js')
-rw-r--r--js/src/tests/non262/reflect-parse/for-loop-destructuring.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/js/src/tests/non262/reflect-parse/for-loop-destructuring.js b/js/src/tests/non262/reflect-parse/for-loop-destructuring.js
new file mode 100644
index 0000000000..06a745334e
--- /dev/null
+++ b/js/src/tests/non262/reflect-parse/for-loop-destructuring.js
@@ -0,0 +1,47 @@
+// |reftest| skip-if(!xulRuntime.shell)
+function test() {
+
+// destructuring in for-in and for-of loop heads
+
+var axbycz = objPatt([assignProp("a", ident("x")),
+ assignProp("b", ident("y")),
+ assignProp("c", ident("z"))]);
+var xyz = arrPatt([assignElem("x"), assignElem("y"), assignElem("z")]);
+
+assertStmt("for (var {a:x,b:y,c:z} in foo);", forInStmt(varDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt));
+assertStmt("for (let {a:x,b:y,c:z} in foo);", forInStmt(letDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt));
+assertStmt("for ({a:x,b:y,c:z} in foo);", forInStmt(axbycz, ident("foo"), emptyStmt));
+assertStmt("for (var [x,y,z] in foo);", forInStmt(varDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
+assertStmt("for (let [x,y,z] in foo);", forInStmt(letDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
+assertStmt("for ([x,y,z] in foo);", forInStmt(xyz, ident("foo"), emptyStmt));
+assertStmt("for (var {a:x,b:y,c:z} of foo);", forOfStmt(varDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt));
+assertStmt("for (let {a:x,b:y,c:z} of foo);", forOfStmt(letDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt));
+assertStmt("for ({a:x,b:y,c:z} of foo);", forOfStmt(axbycz, ident("foo"), emptyStmt));
+assertStmt("for (var [x,y,z] of foo);", forOfStmt(varDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
+assertStmt("for (let [x,y,z] of foo);", forOfStmt(letDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
+assertStmt("for ([x,y,z] of foo);", forOfStmt(xyz, ident("foo"), emptyStmt));
+
+assertStmt("for (const x in foo);",
+ forInStmt(constDecl([{ id: ident("x"), init: null }]), ident("foo"), emptyStmt));
+assertStmt("for (const {a:x,b:y,c:z} in foo);",
+ forInStmt(constDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt));
+assertStmt("for (const [x,y,z] in foo);",
+ forInStmt(constDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
+
+assertStmt("for (const x of foo);",
+ forOfStmt(constDecl([{id: ident("x"), init: null }]), ident("foo"), emptyStmt));
+assertStmt("for (const {a:x,b:y,c:z} of foo);",
+ forOfStmt(constDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt));
+assertStmt("for (const [x,y,z] of foo);",
+ forOfStmt(constDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
+
+assertError("for (x = 22 in foo);", SyntaxError);-
+assertError("for ({a:x,b:y,c:z} = 22 in foo);", SyntaxError);
+assertError("for ([x,y,z] = 22 in foo);", SyntaxError);
+assertError("for (const x = 22 in foo);", SyntaxError);
+assertError("for (const {a:x,b:y,c:z} = 22 in foo);", SyntaxError);
+assertError("for (const [x,y,z] = 22 in foo);", SyntaxError);
+
+}
+
+runtest(test);