Fix the initialization of let/const patterns when block context is needed. (#3320)

Also some code cuplication is removed.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2019-11-15 14:38:14 +01:00
committed by Dániel Bátyai
parent 8eda9bc1c3
commit fca0c94002
8 changed files with 297 additions and 205 deletions
+25
View File
@@ -58,6 +58,8 @@ checkSyntax ("[super] = []");
checkSyntax ("[this] = []");
checkSyntax ("[()] = []");
checkSyntax ("try { let [$] = $;");
checkSyntax ("let a, [ b.c ] = [6];");
checkSyntax ("let [(a)] = [1]");
mustThrow ("var [a] = 4");
mustThrow ("var [a] = 5");
@@ -222,3 +224,26 @@ mustThrow ("var [a] = { [Symbol.iterator] () { return { next () { return { get d
assert (a === 1);
assert (b === 2);
}) ();
// Force the creation of lexical environment I.
(function () {
const [a] = [1];
eval();
assert (a === 1);
}) ();
// Force the creation of lexical environment II.
(function () {
let [a] = [1];
eval();
assert (a === 1);
}) ();
// Check the parsing of AssignmentElement
(function () {
var a = 6;
[((a))] = [7];
assert (a === 7);
}) ();
+26
View File
@@ -48,6 +48,9 @@ checkSyntax ("let {a : b, b} = []");
checkSyntax ("const {a,a} = []");
checkSyntax ("const {a : b, b} = []");
checkSyntax ("try { let {$} = $;");
checkSyntax ("let a, { 'x': a } = {x : 4};");
checkSyntax ("let a, { x: b.c } = {x : 6};");
checkSyntax ("let {a:(a)} = {a:1}");
mustThrow ("var {a} = null");
mustThrow ("var {a} = undefined");
@@ -197,3 +200,26 @@ mustThrow ("var {a} = undefined");
assert (a === 1);
assert (b === 2);
}) ();
// Force the creation of lexical environment I.
(function () {
const {a} = {a : 1};
eval();
assert (a === 1);
}) ();
// Force the creation of lexical environment II.
(function () {
let {a} = {a : 1};
eval();
assert (a === 1);
}) ();
// Check the parsing of AssignmentElement
(function () {
var a = 6;
({"a": ((a)) } = {a : 7});
assert (a === 7);
}) ();