Fix evaluation order in non-binding destructuring patterns (#4173)

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik
2020-08-28 15:13:02 +02:00
committed by GitHub
parent 28c186c98f
commit 2f08d8ac08
11 changed files with 92 additions and 36 deletions
+48
View File
@@ -281,6 +281,54 @@ function __createIterableObject (arr, methods) {
assert (b === 2);
}) ();
(function () {
var value = { y: "42" };
var x = {};
var assignmentResult, iterationResult, iter;
iter = (function*() {
assignmentResult = { y: x[yield] } = value;
}());
iterationResult = iter.next();
assert (assignmentResult === undefined);
assert (iterationResult.value === undefined);
assert (iterationResult.done === false);
assert (x.prop === undefined);
iterationResult = iter.next('prop');
assert (assignmentResult === value);
assert (iterationResult.value === undefined);
assert (iterationResult.done === true);
assert (x.prop === "42");
}) ();
(function () {
var value = { foo: "42" };
var x = {};
var assignmentResult, iterationResult, iter;
iter = (function*() {
assignmentResult = { ['f' + 'o' + 'o']: x[yield] } = value;
}());
iterationResult = iter.next();
assert (assignmentResult === undefined);
assert (iterationResult.value === undefined);
assert (iterationResult.done === false);
assert (x.prop === undefined);
iterationResult = iter.next('prop');
assert (assignmentResult === value);
assert (iterationResult.value === undefined);
assert (iterationResult.done === true);
assert (x.prop === "42");
}) ();
mustThrow ("var iter = __createIterableObject([], "
+ "{ get 'return'() { throw new TypeError() }});"
+ "var [a] = iter");