Detect assignment pattern for for-in/of (#4140)

Furthermore do not allow default value for rest parameter

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-08-24 14:47:10 +02:00
committed by GitHub
parent 5b3f01af9d
commit 84bc1e03fb
10 changed files with 123 additions and 446 deletions
+3
View File
@@ -60,6 +60,9 @@ checkSyntax ("[()] = []");
checkSyntax ("try { let [$] = $;");
checkSyntax ("let a, [ b.c ] = [6];");
checkSyntax ("let [(a)] = [1]");
checkSyntax ("[...a = []] = [1]");
checkSyntax ("[...[a] = []] = [1]");
checkSyntax ("[...[a, [...b] = []] = []] = [1]");
mustThrow ("var [a] = 4");
mustThrow ("var [a] = 5");
+47 -5
View File
@@ -12,6 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
function check_syntax_error (code)
{
try {
eval (code)
assert (false)
} catch (e) {
assert (e instanceof SyntaxError)
}
}
var idx = 0;
for (var [a,b] of [[1,2], [3,4]])
{
@@ -69,9 +79,41 @@ for (let [a,b] of [[11,12], [13,14]])
assert(a === 3);
assert(b === 4);
try {
eval("for (let [a,b] = [1,2] of [[3,4]]) {}");
assert(false);
} catch (e) {
assert(e instanceof SyntaxError);
check_syntax_error("for (let [a,b] = [1,2] of [[3,4]]) {}")
idx = 0;
for ([a,b] of [[10,true], ["x",null]])
{
if (idx == 0)
{
assert(a === 10);
assert(b === true);
idx = 1;
}
else
{
assert(a === "x");
assert(b === null);
}
}
assert(a === "x");
assert(b === null);
check_syntax_error("for ([a,b] = [1,2] of [[3,4]]) {}")
var o = {}
for ([a, b] = [o,false]; false; )
{
assert(false);
}
assert(a === o);
assert(b === false);
for ([a, b] + [a, b]; false; )
{
assert(false);
}
check_syntax_error("for ([a,b] + 1 of [[3,4]]) {}")