diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/non262/reflect-parse/destructuring-variable-declarations.js | |
parent | Initial commit. (diff) | |
download | firefox-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/destructuring-variable-declarations.js')
-rw-r--r-- | js/src/tests/non262/reflect-parse/destructuring-variable-declarations.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/js/src/tests/non262/reflect-parse/destructuring-variable-declarations.js b/js/src/tests/non262/reflect-parse/destructuring-variable-declarations.js new file mode 100644 index 0000000000..6a455668af --- /dev/null +++ b/js/src/tests/non262/reflect-parse/destructuring-variable-declarations.js @@ -0,0 +1,58 @@ +// |reftest| slow skip-if(!xulRuntime.shell) +function test() { + +function testVarPatternCombinations(makePattSrc, makePattPatt) { + var pattSrcs = makePatternCombinations(n => ("x" + n), makePattSrc); + var pattPatts = makePatternCombinations(n => ({ id: ident("x" + n), init: null }), makePattPatt); + // It's illegal to have uninitialized const declarations, so we need a + // separate set of patterns and sources. + var constSrcs = makePatternCombinations(n => ("x" + n + " = undefined"), makePattSrc); + var constPatts = makePatternCombinations(n => ({ id: ident("x" + n), init: ident("undefined") }), makePattPatt); + + for (var i = 0; i < pattSrcs.length; i++) { + // variable declarations in blocks + assertDecl("var " + pattSrcs[i].join(",") + ";", varDecl(pattPatts[i])); + + assertGlobalDecl("let " + pattSrcs[i].join(",") + ";", letDecl(pattPatts[i])); + assertLocalDecl("let " + pattSrcs[i].join(",") + ";", letDecl(pattPatts[i])); + assertBlockDecl("let " + pattSrcs[i].join(",") + ";", letDecl(pattPatts[i])); + + assertDecl("const " + constSrcs[i].join(",") + ";", constDecl(constPatts[i])); + + // variable declarations in for-loop heads + assertStmt("for (var " + pattSrcs[i].join(",") + "; foo; bar);", + forStmt(varDecl(pattPatts[i]), ident("foo"), ident("bar"), emptyStmt)); + assertStmt("for (let " + pattSrcs[i].join(",") + "; foo; bar);", + forStmt(letDecl(pattPatts[i]), ident("foo"), ident("bar"), emptyStmt)); + assertStmt("for (const " + constSrcs[i].join(",") + "; foo; bar);", + forStmt(constDecl(constPatts[i]), ident("foo"), ident("bar"), emptyStmt)); + } +} + +testVarPatternCombinations(n => ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "} = 0"), + n => ({ id: objPatt([assignProp("a" + n, ident("x" + n)), + assignProp("b" + n, ident("y" + n)), + assignProp("c" + n, ident("z" + n))]), + init: lit(0) })); + +testVarPatternCombinations(n => ("{a" + n + ":x" + n + " = 10," + "b" + n + ":y" + n + " = 10," + "c" + n + ":z" + n + " = 10} = 0"), + n => ({ id: objPatt([assignProp("a" + n, ident("x" + n), lit(10)), + assignProp("b" + n, ident("y" + n), lit(10)), + assignProp("c" + n, ident("z" + n), lit(10))]), + init: lit(0) })); + +testVarPatternCombinations(n => ("[x" + n + "," + "y" + n + "," + "z" + n + "] = 0"), + n => ({ id: arrPatt([assignElem("x" + n), assignElem("y" + n), assignElem("z" + n)]), + init: lit(0) })); + +testVarPatternCombinations(n => ("[a" + n + ", ..." + "b" + n + "] = 0"), + n => ({ id: arrPatt([assignElem("a" + n), spread(ident("b" + n))]), + init: lit(0) })); + +testVarPatternCombinations(n => ("[a" + n + ", " + "b" + n + " = 10] = 0"), + n => ({ id: arrPatt([assignElem("a" + n), assignElem("b" + n, lit(10))]), + init: lit(0) })); + +} + +runtest(test); |