diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/language/statements/for-of/dstr | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/language/statements/for-of/dstr')
571 files changed, 31941 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-assignment.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-assignment.js new file mode 100644 index 0000000000..20143823c0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-assignment.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-assignment.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the Initializer is present and v is undefined, the Initializer should be evaluated and the result assigned to the target reference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var v2, vNull, vHole, vUndefined, vOob; + +var counter = 0; + +for ([v2 = 10, vNull = 11, vHole = 12, vUndefined = 13, vOob = 14] of [[2, null, , undefined]]) { + assert.sameValue(v2, 2); + assert.sameValue(vNull, null); + assert.sameValue(vHole, 12); + assert.sameValue(vUndefined, 13); + assert.sameValue(vOob, 14); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-evaluation.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-evaluation.js new file mode 100644 index 0000000000..bbccdbc9c8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-evaluation.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-evaluation.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The Initializer should only be evaluated if v is undefined. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var flag1 = false, flag2 = false; +var _; + +var counter = 0; + +for ([ _ = flag1 = true, _ = flag2 = true ] of [[14]]) { + assert.sameValue(flag1, false); + assert.sameValue(flag2, true); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-arrow.js new file mode 100644 index 0000000000..8be5d38d3d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-arrow.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-fn-name-arrow.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (ArrowFunction) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var arrow; + +var counter = 0; + +for ([ arrow = () => {} ] of [[]]) { + verifyProperty(arrow, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'arrow' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-class.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-class.js new file mode 100644 index 0000000000..8defd41fb5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-class.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-fn-name-class.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (ClassExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [class, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var xCls, cls, xCls2; + +var counter = 0; + +for ([ xCls = class x {}, cls = class {}, xCls2 = class { static name() {} } ] of [[]]) { + assert(xCls.name !== 'xCls'); + assert(xCls2.name !== 'xCls2'); + + verifyProperty(cls, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'cls' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-cover.js new file mode 100644 index 0000000000..3da40d6f12 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-cover.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-fn-name-cover.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (CoverParenthesizedExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var xCover, cover; + +var counter = 0; + +for ([ xCover = (0, function() {}), cover = (function() {}) ] of [[]]) { + assert(xCover.name !== 'xCover'); + + verifyProperty(cover, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'cover' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-fn.js new file mode 100644 index 0000000000..803fc9cad4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-fn.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-fn-name-fn.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (FunctionExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [class, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var xFn, fn; + +var counter = 0; + +for ([ xFn = function x() {}, fn = function() {} ] of [[]]) { + assert(xFn.name !== 'xFn'); + + verifyProperty(fn, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'fn' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-gen.js new file mode 100644 index 0000000000..dba9a58abb --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-fn-name-gen.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-fn-name-gen.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (GeneratorExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var xGen, gen; + +var counter = 0; + +for ([ xGen = function* x() {}, gen = function*() {} ] of [[]]) { + assert.notSameValue(xGen.name, 'xGen'); + + verifyProperty(gen, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'gen' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-in.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-in.js new file mode 100644 index 0000000000..e96d24918c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-in.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-in.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The Initializer in an AssignmentElement may be an `in` expression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ([ x = 'x' in {} ] of [[]]) { + assert.sameValue(x, false); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-let.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-let.js new file mode 100644 index 0000000000..b0a3900788 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-let.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-let.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Value retrieval of Initializer obeys `let` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [let, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(ReferenceError, function() { + for ([ x = y ] of [[]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +let y; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-order.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-order.js new file mode 100644 index 0000000000..44df138ffb --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-order.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-order.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Initializer values should be assigned in left-to-right order. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = 0; +var a, b; + +var counter = 0; + +for ([ a = x += 1, b = x *= 2 ] of [[]]) { + assert.sameValue(a, 1); + assert.sameValue(b, 2); + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-simple-no-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-simple-no-strict.js new file mode 100644 index 0000000000..0d27234e42 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-simple-no-strict.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-simple-no-strict.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Identifiers that appear as the DestructuringAssignmentTarget in an AssignmentElement should take on the iterated value corresponding to their position in the ArrayAssignmentPattern. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var argument, eval; + +var counter = 0; + +for ([arguments = 4, eval = 5] of [[]]) { + assert.sameValue(arguments, 4); + assert.sameValue(eval, 5); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-yield-expr.js new file mode 100644 index 0000000000..986b32c2a1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-yield-expr.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of an AssignmentElement within a generator function body, it behaves as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var value = []; +var iterationResult, iter, x; +iter = (function*() { + +var counter = 0; + +for ([ x = yield ] of [[]]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +})(); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x, undefined); + +iterationResult = iter.next(86); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x, 86); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..7cb9b2a429 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-yield-ident-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of an AssignmentElement outside of a generator function body, it behaves as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([ x = yield ] of [[]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-yield-ident-valid.js new file mode 100644 index 0000000000..8d12e33155 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-init-yield-ident-valid.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-init-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of an AssignmentElement outside of a generator function body, it behaves as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 4; +var x; + +var counter = 0; + +for ([ x = yield ] of [[]]) { + assert.sameValue(x, 4); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-get-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-get-err.js new file mode 100644 index 0000000000..a3d0803fe6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-get-err.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-iter-get-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned from GetIterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iterable = {}; +iterable[Symbol.iterator] = function() { + throw new Test262Error(); +}; +var _; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ _ ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close-err.js new file mode 100644 index 0000000000..77e23d0684 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close-err.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-iter-nrml-close-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned from IteratorClose (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, result). + +---*/ +var nextCount = 0; +var returnCount = 0; +var _; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + throw new Test262Error(); + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ _ ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close-null.js new file mode 100644 index 0000000000..6cd47504a1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close-null.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-iter-nrml-close-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose throws a TypeError when `return` returns a non-Object value (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 6. Return result. + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + 9. If Type(innerResult.[[value]]) is not Object, throw a TypeError + exception. + +---*/ +var _; +var iterable = {}; +var nextCount = 0; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + return null; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([ _ ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close-skip.js new file mode 100644 index 0000000000..d6f1d8eb3e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close-skip.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-iter-nrml-close-skip.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is not called when assignment evaluation has exhausted the iterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, result). + 6. Return result. + +---*/ +var nextCount = 0; +var returnCount = 0; +var _; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + return {}; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([ _ ] of [iterable]) { + assert.sameValue(nextCount, 1); + assert.sameValue(returnCount, 0); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close.js new file mode 100644 index 0000000000..66cd1fa186 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-nrml-close.js @@ -0,0 +1,78 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-iter-nrml-close.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is called when assignment evaluation has not exhausted the iterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 6. Return result. + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var _; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([ _ ] of [iterable]) { + assert.sameValue(nextCount, 1); + assert.sameValue(returnCount, 1); + assert.sameValue(thisValue, iterator, 'correct `this` value'); + assert(!!args, 'arguments object provided'); + assert.sameValue(args.length, 0, 'zero arguments specified'); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-rtrn-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-rtrn-close-err.js new file mode 100644 index 0000000000..2f057606e8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-rtrn-close-err.js @@ -0,0 +1,77 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-iter-rtrn-close-err.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is called when reference evaluation produces a "return" completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 6. Return result. + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + +---*/ +var returnCount = 0; +var unreachable = 0; +var iterable = {}; +var iterator = { + return: function() { + returnCount += 1; + throw new Test262Error(); + } +}; +var iter; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +function* g() { + +var counter = 0; + +for ([ {}[ yield ] ] of [iterable]) { + unreachable += 1; + counter += 1; +} + +assert.sameValue(counter, 1); + +} +iter = g(); +iter.next(); +assert.throws(Test262Error, function() { + iter.return(); +}); + +assert.sameValue(returnCount, 1); +assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-rtrn-close-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-rtrn-close-null.js new file mode 100644 index 0000000000..f3fa8bfba7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-rtrn-close-null.js @@ -0,0 +1,86 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-iter-rtrn-close-null.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose throws a TypeError when `return` returns a non-Object value (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 6. Return result. + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + 9. If Type(innerResult.[[value]]) is not Object, throw a TypeError + exception. + +---*/ +var nextCount = 0; +var returnCount = 0; +var unreachable = 0; +var iterator = { + next: function() { + nextCount += 1; + return {done: false, value: undefined}; + }, + return: function() { + returnCount += 1; + return null; + } +}; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return iterator; +}; +function* g() { + +var counter = 0; + +for ([ {} = yield ] of [iterable]) { + unreachable += 1; + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +var iter = g(); +iter.next(); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); +assert.throws(TypeError, function() { + iter.return(); +}); +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); +assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-rtrn-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-rtrn-close.js new file mode 100644 index 0000000000..1ba48978a9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-rtrn-close.js @@ -0,0 +1,93 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-iter-rtrn-close.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is called when reference evaluation produces a "return" completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 6. Return result. + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + +---*/ +var nextCount = 0; +var returnCount = 0; +var unreachable = 0; +var thisValue = null; +var args = null; +var iterator = { + next: function() { + nextCount += 1; + return {done: false, value: undefined}; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +function* g() { + +var counter = 0; + +for ([ {} = yield ] of [iterable]) { + unreachable += 1; + counter += 1; +} + +assert.sameValue(counter, 1); + +} +var iter = g(); +iter.next(); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +var result = iter.return(777); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); +assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); +assert.sameValue(result.value, 777); +assert(result.done, 'Iterator correctly closed'); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-thrw-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-thrw-close-err.js new file mode 100644 index 0000000000..7b6fffcc4c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-thrw-close-err.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-iter-thrw-close-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is called when reference evaluation produces a "throw" completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 6. Return result. + +---*/ +var nextCount = 0; +var returnCount = 0; +function ReturnError() {} +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + + // This value should be discarded. + throw new ReturnError(); + } +}; +var thrower = function() { + throw new Test262Error(); +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ {}[thrower()] ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 0); +assert.sameValue(returnCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-thrw-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-thrw-close-skip.js new file mode 100644 index 0000000000..992ab88a44 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-thrw-close-skip.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-iter-thrw-close-skip.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is not called when iteration produces an abrupt completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 6. Return result. + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + throw new Test262Error(); + }, + return: function() { + returnCount += 1; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; +var _; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ x ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-thrw-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-thrw-close.js new file mode 100644 index 0000000000..807c4cdb81 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-iter-thrw-close.js @@ -0,0 +1,81 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-iter-thrw-close.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is called when reference evaluation produces a "throw" completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 6. Return result. + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + } +}; +var thrower = function() { + throw new Test262Error(); +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ {}[thrower()] ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 0); +assert.sameValue(returnCount, 1); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-invalid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-invalid.js new file mode 100644 index 0000000000..8a5fc098ce --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-invalid.js @@ -0,0 +1,33 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-array-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if the lexical token sequence matched by LeftHandSideExpression cannot be parsed with no tokens left over using AssignmentPattern as the goal symbol. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([[(x, y)]] of [[[]]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-null.js new file mode 100644 index 0000000000..2b675653cb --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-null.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-array-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the value is `null`, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var _; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([[ _ ]] of [[null]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-undefined-hole.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-undefined-hole.js new file mode 100644 index 0000000000..a204f6a461 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-undefined-hole.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-array-undefined-hole.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the value is a "hole", a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var _; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([[ _ ]] of [[ , ]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-undefined-own.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-undefined-own.js new file mode 100644 index 0000000000..e63ba1a3d3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-undefined-own.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-array-undefined-own.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the value is `undefined`, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var _; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([[ x ]] of [[undefined]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-undefined.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-undefined.js new file mode 100644 index 0000000000..d8d5ffcb87 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-undefined.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-array-undefined.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and no value is defined, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var _; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([[ x ]] of [[]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-yield-expr.js new file mode 100644 index 0000000000..138133f07d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-yield-expr.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-array-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of a nested destructuring assignment and within a generator function body, it behaves as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var value = [[22]]; +var x = {}; +var iterationResult, iter; + +iter = (function*() { + +var counter = 0; + +for ([[x[yield]]] of [value]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +}()); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x.prop, undefined); + +iterationResult = iter.next('prop'); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x.prop, 22); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..d4a52b24fa --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-yield-ident-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-array-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of a nested destructuring assignment outside of strict mode, it behaves as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([[x[yield]]] of [[[]]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-yield-ident-valid.js new file mode 100644 index 0000000000..145115147f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array-yield-ident-valid.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-array-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of a nested destructuring assignment outside of strict mode, it behaves as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 'prop'; +var x = {}; + +var counter = 0; + +for ([[x[yield]]] of [[[22]]]) { + assert.sameValue(x.prop, 22); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array.js new file mode 100644 index 0000000000..5a3dd3d619 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-array.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-array.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal, it should be parsed parsed as a DestructuringAssignmentPattern and evaluated as a destructuring assignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ([[x]] of [[[1]]]) { + assert.sameValue(x, 1); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-memberexpr-optchain-prop-ref-init.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-memberexpr-optchain-prop-ref-init.js new file mode 100644 index 0000000000..7c69c77bbe --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-memberexpr-optchain-prop-ref-init.js @@ -0,0 +1,66 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-memberexpr-optchain-prop-ref-init.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if LeftHandSideExpression of an DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple Using Object (MemberExpression OptionalChain .IdentifierName Initializer) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [optional-chaining, destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + Syntax + + AssignmentElement : DestructuringAssignmentTarget Initializer_opt + DestructuringAssignmentTarget : LeftHandSideExpression + + Static Semantics: Early Errors + + OptionalExpression: + MemberExpression OptionalChain + CallExpression OptionalChain + OptionalExpression OptionalChain + + OptionalChain: + ?. [ Expression ] + ?. IdentifierName + ?. Arguments + ?. TemplateLiteral + OptionalChain [ Expression ] + OptionalChain .IdentifierName + OptionalChain Arguments + OptionalChain TemplateLiteral + + DestructuringAssignmentTarget : LeftHandSideExpression + + - It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is not true. + + Static Semantics: IsValidSimpleAssignmentTarget + + LeftHandSideExpression : OptionalExpression + 1. Return false. + +---*/ +$DONOTEVALUATE(); +var x = {}; + +for ([x?.y = 42] of [[23]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-invalid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-invalid.js new file mode 100644 index 0000000000..6d366da8d7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-invalid.js @@ -0,0 +1,33 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-obj-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if the lexical token sequence matched by LeftHandSideExpression cannot be parsed with no tokens left over using AssignmentPattern as the goal symbol. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([{ get x() {} }] of [[{}]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-null.js new file mode 100644 index 0000000000..b6864a4638 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-null.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-obj-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object literal and the value is `null`, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([{ x }] of [[null]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-undefined-hole.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-undefined-hole.js new file mode 100644 index 0000000000..a521cbca92 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-undefined-hole.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-obj-undefined-hole.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object literal and the value is a "hole", a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([{ x }] of [[ , ]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-undefined-own.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-undefined-own.js new file mode 100644 index 0000000000..552d0751e9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-undefined-own.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-obj-undefined-own.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object literal and the value is `undefined`, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([{ x }] of [[undefined]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-undefined.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-undefined.js new file mode 100644 index 0000000000..b6f0adc559 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-undefined.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-obj-undefined.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object literal and no value is defined, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([{ x }] of [[]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-yield-expr.js new file mode 100644 index 0000000000..e5a2a41058 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-yield-expr.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-obj-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment and within a generator function body, it behaves as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var iterationResult, iter, x; + +iter = (function*() { + +var counter = 0; + +for ([{ x = yield }] of [[{}]]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +}()); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x, undefined); + +iterationResult = iter.next(4); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x, 4); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..a7a49a4947 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-yield-ident-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-obj-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment outside of a generator function body, it behaves as a IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([{ x = yield }] of [[{}]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-yield-ident-valid.js new file mode 100644 index 0000000000..c3935a3ac5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj-yield-ident-valid.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-obj-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment outside of a generator function body, it behaves as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 2; +var x; + +var counter = 0; + +for ([{ x = yield }] of [[{}]]) { + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj.js new file mode 100644 index 0000000000..d4c064fbd2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-nested-obj.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-nested-obj.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object literal, it should be parsed as a DestructuringAssignmentPattern and evaluated as a destructuring assignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ([{ x }] of [[{ x: 2 }]]) { + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-const.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-const.js new file mode 100644 index 0000000000..eb90ecce08 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-const.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-put-const.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: The assignment target should obey `const` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [const, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +const c = null; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([ c ] of [[1]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-let.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-let.js new file mode 100644 index 0000000000..1347eb8ec2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-let.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-put-let.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: The assignment target should obey `let` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [let, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(ReferenceError, function() { + for ([ x ] of [[]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +let x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-optchain-prop-ref-init.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-optchain-prop-ref-init.js new file mode 100644 index 0000000000..b83831dde1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-optchain-prop-ref-init.js @@ -0,0 +1,69 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-put-obj-literal-optchain-prop-ref-init.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if LeftHandSideExpression of an DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple Using Object (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [optional-chaining, destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + Syntax + + AssignmentElement : DestructuringAssignmentTarget Initializer_opt + DestructuringAssignmentTarget : LeftHandSideExpression + + Static Semantics: Early Errors + + OptionalExpression: + MemberExpression OptionalChain + CallExpression OptionalChain + OptionalExpression OptionalChain + + OptionalChain: + ?. [ Expression ] + ?. IdentifierName + ?. Arguments + ?. TemplateLiteral + OptionalChain [ Expression ] + OptionalChain .IdentifierName + OptionalChain Arguments + OptionalChain TemplateLiteral + + DestructuringAssignmentTarget : LeftHandSideExpression + + - It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is not true. + + Static Semantics: IsValidSimpleAssignmentTarget + + LeftHandSideExpression : OptionalExpression + 1. Return false. + +---*/ +$DONOTEVALUATE(); + +for ([{ + set y(val) { + throw new Test262Error('The property should not be accessed.'); + } +}?.y = 42] of [[23]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-prop-ref-init-active.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-prop-ref-init-active.js new file mode 100644 index 0000000000..9f222e6814 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-prop-ref-init-active.js @@ -0,0 +1,79 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-put-obj-literal-prop-ref-init-active.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The DestructuringAssignmentTarget of an AssignmentElement can extend to LHSExpressions if it is neither an ObjectLiteral nor an ArrayLiteral and its AssignmentTargetTyp is simple. Using MemberExpression (ObjLiteral + identifier) with activated initializer. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + Syntax + + AssignmentPattern : ArrayAssignmentPattern + ArrayAssignmentPattern : [ AssignmentElementList ] + AssignmentElementList : AssignmentElisionElement + AssignmentElisionElement : Elision_opt AssignmentElement + AssignmentElement : DestructuringAssignmentTarget Initializer_opt + DestructuringAssignmentTarget : LeftHandSideExpression + + Static Semantics: Early Errors + + DestructuringAssignmentTarget : LeftHandSideExpression + + - It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if LeftHandSideExpression is not covering an AssignmentPattern. + - It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple. + + Runtime Semantics: DestructuringAssignmentEvaluation + ArrayAssignmentPattern : [ AssignmentElementList ] + + 1. Let iteratorRecord be ? GetIterator(value). + 2. Let result be IteratorDestructuringAssignmentEvaluation of AssignmentElementList with argument iteratorRecord. + 3. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iteratorRecord, result). + 4. Return result. + + Runtime Semantics: IteratorDestructuringAssignmentEvaluation + AssignmentElement : DestructuringAssignmentTarget Initializer + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + ... + 7. Return ? PutValue(lref, v). + +---*/ +var x, setValue; + +var counter = 0; + +for ([{ + get y() { + throw new Test262Error('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}.y = 42] of [[undefined]]) { + assert.sameValue(setValue, 42); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-prop-ref-init.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-prop-ref-init.js new file mode 100644 index 0000000000..3edd7eb750 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-prop-ref-init.js @@ -0,0 +1,79 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-put-obj-literal-prop-ref-init.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The DestructuringAssignmentTarget of an AssignmentElement can extend to LHSExpressions if it is neither an ObjectLiteral nor an ArrayLiteral and its AssignmentTargetTyp is simple. Using MemberExpression (ObjLiteral + identifier) with initializer. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + Syntax + + AssignmentPattern : ArrayAssignmentPattern + ArrayAssignmentPattern : [ AssignmentElementList ] + AssignmentElementList : AssignmentElisionElement + AssignmentElisionElement : Elision_opt AssignmentElement + AssignmentElement : DestructuringAssignmentTarget Initializer_opt + DestructuringAssignmentTarget : LeftHandSideExpression + + Static Semantics: Early Errors + + DestructuringAssignmentTarget : LeftHandSideExpression + + - It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if LeftHandSideExpression is not covering an AssignmentPattern. + - It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple. + + Runtime Semantics: DestructuringAssignmentEvaluation + ArrayAssignmentPattern : [ AssignmentElementList ] + + 1. Let iteratorRecord be ? GetIterator(value). + 2. Let result be IteratorDestructuringAssignmentEvaluation of AssignmentElementList with argument iteratorRecord. + 3. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iteratorRecord, result). + 4. Return result. + + Runtime Semantics: IteratorDestructuringAssignmentEvaluation + AssignmentElement : DestructuringAssignmentTarget Initializer + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + ... + 7. Return ? PutValue(lref, v). + +---*/ +var x, setValue; + +var counter = 0; + +for ([{ + get y() { + throw new Test262Error('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}.y = 42] of [[23]]) { + assert.sameValue(setValue, 23); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-prop-ref.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-prop-ref.js new file mode 100644 index 0000000000..712b25cd02 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-obj-literal-prop-ref.js @@ -0,0 +1,79 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-put-obj-literal-prop-ref.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The DestructuringAssignmentTarget of an AssignmentElement can extend to LHSExpressions if it is neither an ObjectLiteral nor an ArrayLiteral and its AssignmentTargetTyp is simple. Using MemberExpression (ObjLiteral + identifier). (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + Syntax + + AssignmentPattern : ArrayAssignmentPattern + ArrayAssignmentPattern : [ AssignmentElementList ] + AssignmentElementList : AssignmentElisionElement + AssignmentElisionElement : Elision_opt AssignmentElement + AssignmentElement : DestructuringAssignmentTarget Initializer_opt + DestructuringAssignmentTarget : LeftHandSideExpression + + Static Semantics: Early Errors + + DestructuringAssignmentTarget : LeftHandSideExpression + + - It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if LeftHandSideExpression is not covering an AssignmentPattern. + - It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple. + + Runtime Semantics: DestructuringAssignmentEvaluation + ArrayAssignmentPattern : [ AssignmentElementList ] + + 1. Let iteratorRecord be ? GetIterator(value). + 2. Let result be IteratorDestructuringAssignmentEvaluation of AssignmentElementList with argument iteratorRecord. + 3. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iteratorRecord, result). + 4. Return result. + + Runtime Semantics: IteratorDestructuringAssignmentEvaluation + AssignmentElement : DestructuringAssignmentTarget Initializer + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + ... + 7. Return ? PutValue(lref, v). + +---*/ +var x, setValue; + +var counter = 0; + +for ([{ + get y() { + throw new Test262Error('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}.y] of [[23]]) { + assert.sameValue(setValue, 23); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-prop-ref-no-get.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-prop-ref-no-get.js new file mode 100644 index 0000000000..b4f82d1792 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-prop-ref-no-get.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-put-prop-ref-no-get.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the DestructuringAssignmentTarget of an AssignmentElement is a PropertyReference, it should not be evaluated. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x, setValue; +x = { + get y() { + throw new Test262Error('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}; + +var counter = 0; + +for ([x.y] of [[23]]) { + assert.sameValue(setValue, 23); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-prop-ref-user-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-prop-ref-user-err.js new file mode 100644 index 0000000000..bca0379d3c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-prop-ref-user-err.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-put-prop-ref-user-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Any error raised as a result of setting the value should be forwarded to the runtime. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = { + set y(val) { + throw new Test262Error(); + } +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([x.y] of [[23]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-prop-ref.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-prop-ref.js new file mode 100644 index 0000000000..fabda343d2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-prop-ref.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-put-prop-ref.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The DestructuringAssignmentTarget of an AssignmentElement may be a PropertyReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = {}; + +var counter = 0; + +for ([x.y] of [[4]]) { + assert.sameValue(x.y, 4); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-unresolvable-no-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-unresolvable-no-strict.js new file mode 100644 index 0000000000..76ec86c3a4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-unresolvable-no-strict.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-put-unresolvable-no-strict.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Outside of strict mode, if the the assignment target is an unresolvable reference, a new `var` binding should be created in the environment record. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +{ + +var counter = 0; + +for ([ unresolvable ] of [[]]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +assert.sameValue(unresolvable, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-unresolvable-strict-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-unresolvable-strict-strict.js new file mode 100644 index 0000000000..7a29183272 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-put-unresolvable-strict-strict.js @@ -0,0 +1,40 @@ +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-put-unresolvable-strict.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: In strict mode, if the the assignment target is an unresolvable reference, a ReferenceError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(ReferenceError, function() { + for ([ unresolvable ] of [[]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-identifier.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-identifier.js new file mode 100644 index 0000000000..dabe6c34d9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-identifier.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-target-identifier.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Identifiers that appear as the DestructuringAssignmentTarget in an AssignmentElement should take on the iterated value corresponding to their position in the ArrayAssignmentPattern. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x, y, z; + +var counter = 0; + +for ([x, y, z] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-simple-no-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-simple-no-strict.js new file mode 100644 index 0000000000..e046d2cfb0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-simple-no-strict.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-target-simple-no-strict.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Identifiers that appear as the DestructuringAssignmentTarget in an AssignmentElement should take on the iterated value corresponding to their position in the ArrayAssignmentPattern. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var argument, eval; + +var counter = 0; + +for ([arguments, eval] of [[2, 3]]) { + assert.sameValue(arguments, 2); + assert.sameValue(eval, 3); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-simple-strict-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-simple-strict-strict.js new file mode 100644 index 0000000000..344718e293 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-simple-strict-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-target-simple-strict.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is false. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([arguments] of [[]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-yield-expr.js new file mode 100644 index 0000000000..253ebe13de --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-yield-expr.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-target-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of an AssignmentElement within a generator function body, it behaves as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var value = [33]; +var x = {}; +var iterationResult, iter; + +iter = (function*() { + +var counter = 0; + +for ([ x[yield] ] of [[33]]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +}()); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x.prop, undefined); + +iterationResult = iter.next('prop'); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x.prop, 33); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-yield-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-yield-invalid-strict.js new file mode 100644 index 0000000000..a39b7cc37a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-yield-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-target-yield-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of an AssignmentElement and outside of a generator function body, it behaves as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([ x[yield] ] of [[]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-yield-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-yield-valid.js new file mode 100644 index 0000000000..779f769d75 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-target-yield-valid.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-target-yield-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of an AssignmentElement outside of a generator function body, it behaves as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 'prop'; +var x = {}; + +var counter = 0; + +for ([ x[yield] ] of [[33]]) { + assert.sameValue(x.prop, 33); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-abpt.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-abpt.js new file mode 100644 index 0000000000..209a650414 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-abpt.js @@ -0,0 +1,80 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-elision-iter-abpt.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned during evaluation of elision (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 6. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. If status is an abrupt completion, then + i. If iteratorRecord.[[done]] is false, return + IteratorClose(iterator, status). + ii. Return Completion(status). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var x; +var iterator = { + next: function() { + nextCount += 1; + + if (nextCount === 2) { + throw new Test262Error(); + } + + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ x , , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 2); +assert.sameValue(returnCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close-err.js new file mode 100644 index 0000000000..f43fbcfa38 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close-err.js @@ -0,0 +1,76 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-elision-iter-nrml-close-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned from IteratorClose (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 6. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. If status is an abrupt completion, then + [...] + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var x; +var iterator = { + next: function() { + nextCount += 1; + + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + throw new Test262Error(); + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ x , , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 2); +assert.sameValue(returnCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close-null.js new file mode 100644 index 0000000000..c55e73a43b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close-null.js @@ -0,0 +1,79 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-elision-iter-nrml-close-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose throws a TypeError when `return` returns a non-Object value (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 6. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. If status is an abrupt completion, then + [...] + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + 9. If Type(innerResult.[[value]]) is not Object, throw a TypeError + exception. + +---*/ +var iterable = {}; +var x; +var nextCount = 0; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + return null; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([ x , , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close-skip.js new file mode 100644 index 0000000000..9894c4ce57 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close-skip.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-elision-iter-nrml-close-skip.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose not invoked when elision exhausts the iterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 6. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. If status is an abrupt completion, then + [...] + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + 9. Return Completion(status). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var x; +var iterator = { + next: function() { + nextCount += 1; + + return { done: nextCount > 1 }; + }, + return: function() { + returnCount += 1; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([ x , , ] of [iterable]) { + assert.sameValue(nextCount, 2); + assert.sameValue(returnCount, 0); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close.js new file mode 100644 index 0000000000..50f94cba56 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-elision-iter-nrml-close.js @@ -0,0 +1,85 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-elision-iter-nrml-close.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose invoked when elision does not exhaust the iterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 6. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. If status is an abrupt completion, then + [...] + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var iterable = {}; +var x; +var iterator = { + next: function() { + nextCount += 1; + + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([ x , , ] of [iterable]) { + assert.sameValue(nextCount, 2); + assert.sameValue(returnCount, 1); + assert.sameValue(thisValue, iterator, 'correct `this` value'); + assert(!!args, 'arguments object provided'); + assert.sameValue(args.length, 0, 'zero arguments specified'); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-get-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-get-err.js new file mode 100644 index 0000000000..eb9e0a6f16 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-get-err.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-get-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned from GetIterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iterable = {}; +iterable[Symbol.iterator] = function() { + throw new Test262Error(); +}; +var x; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ x , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close-err.js new file mode 100644 index 0000000000..d825c94adf --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close-err.js @@ -0,0 +1,76 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-list-nrml-close-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned from IteratorClose (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + b. Return Completion(status). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var thrower = function() { + throw new Test262Error(); +}; +var x; +var iterator = { + next: function() { + nextCount += 1; + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + throw new Test262Error(); + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ x , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close-null.js new file mode 100644 index 0000000000..2e1ac4dc2f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close-null.js @@ -0,0 +1,79 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-list-nrml-close-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose throws a TypeError when `return` returns a non-Object value (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + b. Return Completion(status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + 9. If Type(innerResult.[[value]]) is not Object, throw a TypeError + exception. + +---*/ +var iterable = {}; +var x; +var nextCount = 0; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + return null; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([ x , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close-skip.js new file mode 100644 index 0000000000..f8b8c96b8b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close-skip.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-list-nrml-close-skip.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is not invoked when evaluation of AssignmentElementList exhausts the iterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + b. Return Completion(status). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var thrower = function() { + throw new Test262Error(); +}; +var x; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([ x , ] of [iterable]) { + assert.sameValue(nextCount, 1); + assert.sameValue(returnCount, 0); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close.js new file mode 100644 index 0000000000..8b279ded51 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-nrml-close.js @@ -0,0 +1,84 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-list-nrml-close.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is invoked when evaluation of AssignmentElementList completes without exhausting the iterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + b. Return Completion(status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var iterable = {}; +var x; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([ x , ] of [iterable]) { + assert.sameValue(nextCount, 1); + assert.sameValue(returnCount, 1); + assert.sameValue(thisValue, iterator, 'correct `this` value'); + assert(!!args, 'arguments object provided'); + assert.sameValue(args.length, 0, 'zero arguments specified'); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close-err.js new file mode 100644 index 0000000000..02520bfd06 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close-err.js @@ -0,0 +1,91 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-list-rtrn-close-err.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is invoked when evaluation of AssignmentElementList returns a "return" completion and the iterator has not been marked as "done" (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + +---*/ +var nextCount = 0; +var returnCount = 0; +var unreachable = 0; +var iterator = { + next: function() { + nextCount += 1; + return {done: false, value: undefined}; + }, + return: function() { + returnCount += 1; + + throw new Test262Error(); + } +}; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +function* g() { + +var counter = 0; + +for ([ {} = yield , ] of [iterable]) { + unreachable += 1; + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +var iter = g(); +iter.next(); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); +assert.throws(Test262Error, function() { + iter.return(); +}); +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); +assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close-null.js new file mode 100644 index 0000000000..3ecd873557 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close-null.js @@ -0,0 +1,91 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-list-rtrn-close-null.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose throws a TypeError when `return` returns a non-Object value (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + b. Return Completion(status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + 9. If Type(innerResult.[[value]]) is not Object, throw a TypeError + exception. + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterator = { + next: function() { + nextCount += 1; + return {done: false, value: undefined}; + }, + return: function() { + returnCount += 1; + return null; + } +}; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +function* g() { + +var counter = 0; + +for ([ {} = yield , ] of [iterable]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +var iter = g(); +iter.next(); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); +assert.throws(TypeError, function() { + iter.return(); +}); +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close.js new file mode 100644 index 0000000000..09c39d4e3a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-rtrn-close.js @@ -0,0 +1,102 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-list-rtrn-close.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is invoked when evaluation of AssignmentElementList returns a "return" completion and the iterator has not been marked as "done" (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + b. Return Completion(status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + +---*/ +var nextCount = 0; +var returnCount = 0; +var unreachable = 0; +var thisValue = null; +var args = null; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return {done: false, value: undefined}; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +var iter, result; + +iterable[Symbol.iterator] = function() { + return iterator; +}; + +function* g() { + +var counter = 0; + +for ([ {} = yield , ] of [iterable]) { + unreachable += 1; + counter += 1; +} + +assert.sameValue(counter, 1); + +}; + +iter = g(); +iter.next(); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +result = iter.return(888); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); +assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); +assert.sameValue(result.value, 888); +assert(result.done, 'Iterator correctly closed'); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close-err.js new file mode 100644 index 0000000000..f7932463fb --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close-err.js @@ -0,0 +1,84 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-list-thrw-close-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is invoked when evaluation of AssignmentElementList returns a "throw" completion and the iterator has not been marked as "done" (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 7. If completion.[[type]] is throw, return Completion(completion). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var thrower = function() { + throw new Test262Error(); +}; +function ReturnError() {} +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + + // This value should be discarded. + throw new ReturnError(); + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ {}[thrower()] , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + + +assert.sameValue(nextCount, 0); +assert.sameValue(returnCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close-skip.js new file mode 100644 index 0000000000..6091d997bc --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close-skip.js @@ -0,0 +1,75 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-list-thrw-close-skip.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is not invoked when evaluation of AssignmentElementList returns an abrupt completion and the iterator has been marked as "done" (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + b. Return Completion(status). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var thrower = function() { + throw new Test262Error(); +}; +var iterator = { + next: function() { + nextCount += 1; + throw new Test262Error(); + }, + return: function() { + returnCount += 1; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; +var x; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ x , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close.js new file mode 100644 index 0000000000..ee99d2439e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-list-thrw-close.js @@ -0,0 +1,87 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-list-thrw-close.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is invoked when evaluation of AssignmentElementList returns a "throw" completion and the iterator has not been marked as "done" (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + b. Return Completion(status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var iterable = {}; +var thrower = function() { + throw new Test262Error(); +}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ {}[thrower()] , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 0); +assert.sameValue(returnCount, 1); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-nrml-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-nrml-close-skip.js new file mode 100644 index 0000000000..d14e6f9d3e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-nrml-close-skip.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-rest-nrml-close-skip.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is not called when rest element evaluation has exhausted the iterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 7. If AssignmentRestElement is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement + with iteratorRecord as the argument. + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + 9. Return Completion(status). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var x, y; +var iterator = { + next: function() { + nextCount += 1; + return { value: nextCount, done: nextCount > 1 }; + }, + return: function() { + returnCount += 1; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([ x , ...y ] of [iterable]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +assert.sameValue(nextCount, 2, 'nextCount'); +assert.sameValue(returnCount, 0, 'returnCount'); +assert.sameValue(x, 1, 'x'); +assert.sameValue(y.length, 0, 'y.length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close-err.js new file mode 100644 index 0000000000..ea6f727c9f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close-err.js @@ -0,0 +1,93 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-rest-rtrn-close-err.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is called when AssignmentRestEvaluation produces a "return" completion due to reference evaluation (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 7. If AssignmentRestElement is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement + with iteratorRecord as the argument. + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + 9. Return Completion(status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + +---*/ +var nextCount = 0; +var returnCount = 0; +var unreachable = 0; +var x; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + + throw new Test262Error(); + } +}; +var iter; +iterable[Symbol.iterator] = function() { + return iterator; +}; +function* g() { + +var counter = 0; + +for ([ x , ...{}[yield] ] of [iterable]) { + unreachable += 1; + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +iter = g(); +iter.next(); + +assert.throws(Test262Error, function() { + iter.return(); +}); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); +assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close-null.js new file mode 100644 index 0000000000..95e723e06b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close-null.js @@ -0,0 +1,88 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-rest-rtrn-close-null.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose throws a TypeError when `return` returns a non-Object value (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 7. If AssignmentRestElement is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement + with iteratorRecord as the argument. + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + 9. Return Completion(status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + +---*/ +var nextCount = 0; +var iterable = {}; +var x; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + return null; + } +}; +var iter; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +function* g() { + +var counter = 0; + +for ([ x , ...{}[yield] ] of [iterable]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +iter = g(); +iter.next(); + +assert.throws(TypeError, function() { + iter.return(); +}); + +assert.sameValue(nextCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close.js new file mode 100644 index 0000000000..20a278c1ca --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-rtrn-close.js @@ -0,0 +1,99 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-rest-rtrn-close.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is called when AssignmentRestEvaluation produces a "return" completion due to reference evaluation (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 7. If AssignmentRestElement is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement + with iteratorRecord as the argument. + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + 9. Return Completion(status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + +---*/ +var nextCount = 0; +var returnCount = 0; +var unreachable = 0; +var thisValue = null; +var args = null; +var iterable = {}; +var x; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +var iter, result; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +function* g() { + +var counter = 0; + +for ([ x , ...{}[yield] ] of [iterable]) { + unreachable += 1; + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +iter = g(); +iter.next(); +result = iter.return(999); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); +assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); +assert.sameValue(result.value, 999); +assert(result.done, 'Iterator correctly closed'); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close-err.js new file mode 100644 index 0000000000..7e669658ba --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close-err.js @@ -0,0 +1,85 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-rest-thrw-close-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is called when AssignmentRestEvaluation produces a "throw" completion due to reference evaluation (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 7. If AssignmentRestElement is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement + with iteratorRecord as the argument. + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + 9. Return Completion(status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 7. If completion.[[type]] is throw, return Completion(completion) + +---*/ +var nextCount = 0; +var returnCount = 0; +var x; +function ReturnError() {} +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + + // This value should be discarded. + throw new ReturnError(); + } +}; +var thrower = function() { + throw new Test262Error(); +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ x , ...{}[thrower()] ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close-skip.js new file mode 100644 index 0000000000..2b210e7b00 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close-skip.js @@ -0,0 +1,78 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-rest-thrw-close-skip.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned during iteration for rest element (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 7. If AssignmentRestElement is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement + with iteratorRecord as the argument. + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + 9. Return Completion(status). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var x; +var iterator = { + next: function() { + nextCount += 1; + + if (nextCount === 2) { + throw new Test262Error(); + } + + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ x , ...x ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 2); +assert.sameValue(returnCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close.js new file mode 100644 index 0000000000..62a5eea52c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elem-trlg-iter-rest-thrw-close.js @@ -0,0 +1,89 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elem-trlg-iter-rest-thrw-close.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is called when AssignmentRestEvaluation produces a "throw" completion due to reference evaluation (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 7. If AssignmentRestElement is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement + with iteratorRecord as the argument. + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + 9. Return Completion(status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var iterable = {}; +var x; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + } +}; +var thrower = function() { + throw new Test262Error(); +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ x , ...{}[thrower()] ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-abpt.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-abpt.js new file mode 100644 index 0000000000..ec3c4fdb92 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-abpt.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-iter-abpt.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is not called when iteration produces an abrupt completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elision ] + + 1. Let iterator be GetIterator(value). + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + throw new Test262Error(); + }, + return: function() { + returnCount += 1; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-get-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-get-err.js new file mode 100644 index 0000000000..1c4e3e0c27 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-get-err.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-iter-get-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned from GetIterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elision ] + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iterable = {}; +iterable[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close-err.js new file mode 100644 index 0000000000..10c4ed8604 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close-err.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-iter-nrml-close-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned from IteratorClose (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elision ] + + 1. Let iterator be GetIterator(value). + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 6. Return result. + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + throw new Test262Error(); + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close-null.js new file mode 100644 index 0000000000..80d05752b2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close-null.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-iter-nrml-close-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose throws a TypeError when `return` returns a non-Object value (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elision ] + + 1. Let iterator be GetIterator(value). + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + [...] + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + 9. If Type(innerResult.[[value]]) is not Object, throw a TypeError + exception. + +---*/ +var iterable = {}; +var nextCount = 0; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + return null; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([ , ] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close-skip.js new file mode 100644 index 0000000000..aa8d78b8fd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close-skip.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-iter-nrml-close-skip.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is not called when iteration has exhausted the iterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elision ] + + 1. Let iterator be GetIterator(value). + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + return {}; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([ , ] of [iterable]) { + assert.sameValue(nextCount, 1); + assert.sameValue(returnCount, 0); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close.js new file mode 100644 index 0000000000..d49c8e3f12 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-iter-nrml-close.js @@ -0,0 +1,78 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-iter-nrml-close.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is called when assignment evaluation has not exhausted the iterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elision ] + + 1. Let iterator be GetIterator(value). + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + [...] + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([ , ] of [iterable]) { + assert.sameValue(nextCount, 1); + assert.sameValue(returnCount, 1); + assert.sameValue(thisValue, iterator, 'correct `this` value'); + assert(!!args, 'arguments object provided'); + assert.sameValue(args.length, 0, 'zero arguments specified'); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-array.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-array.js new file mode 100644 index 0000000000..928f7371b1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-array.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-val-array.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: An ArrayAssignmentPattern containing only Elisions requires iterable values (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +for ([,] of [[]]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-bool.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-bool.js new file mode 100644 index 0000000000..d0ac48f268 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-bool.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-val-bool.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ArrayAssignmentPattern containing only Elisions requires iterable values and throws for boolean values. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(TypeError, function() { + for ([,] of [true]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-null.js new file mode 100644 index 0000000000..cc9f581817 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-null.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-val-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ArrayAssignmentPattern containing only Elisions requires iterable values and throws for `null`. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(TypeError, function() { + for ([,] of [null]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-num.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-num.js new file mode 100644 index 0000000000..67b15faa51 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-num.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-val-num.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ArrayAssignmentPattern containing only Elisions requires iterable values and throws for number values. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(TypeError, function() { + for ([,] of [1]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-string.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-string.js new file mode 100644 index 0000000000..7e3eb227cb --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-string.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-val-string.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: An ArrayAssignmentPattern containing only Elisions requires iterable values (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +for ([,] of ['string literal']) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-symbol.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-symbol.js new file mode 100644 index 0000000000..5e108f191e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-symbol.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-val-symbol.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ArrayAssignmentPattern containing only Elisions requires iterable values and throws for symbol values. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var s = Symbol(); + +var counter = 0; + +assert.throws(TypeError, function() { + for ([,] of [s]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-undef.js new file mode 100644 index 0000000000..34f979d148 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-elision-val-undef.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-elision-val-undef.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ArrayAssignmentPattern containing only Elisions requires iterable values and throws for `undefined`. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(TypeError, function() { + for ([,] of [undefined]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-close-err.js new file mode 100644 index 0000000000..1de55b5d7d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-close-err.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-empty-iter-close-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned from IteratorClose (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ ] + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + 3. Return IteratorClose(iterator, NormalCompletion(empty)). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + throw new Test262Error(); + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 0); +assert.sameValue(returnCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-close-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-close-null.js new file mode 100644 index 0000000000..974e7ee66e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-close-null.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-empty-iter-close-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose throws a TypeError when `return` returns a non-Object value (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ ] + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + 3. Return IteratorClose(iterator, NormalCompletion(empty)). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + 9. If Type(innerResult.[[value]]) is not Object, throw a TypeError + exception. + +---*/ +var iterable = {}; +var iterator = { + next: function() { + return { done: true }; + }, + return: function() { + return null; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-close.js new file mode 100644 index 0000000000..cb2179bb78 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-close.js @@ -0,0 +1,74 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-empty-iter-close.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Iterator is closed without iterating (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ ] + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + 3. Return IteratorClose(iterator, NormalCompletion(empty)). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([] of [iterable]) { + assert.sameValue(nextCount, 0); + assert.sameValue(returnCount, 1); + assert.sameValue(thisValue, iterator, 'correct `this` value'); + assert(!!args, 'arguments object provided'); + assert.sameValue(args.length, 0, 'zero arguments specified'); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-get-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-get-err.js new file mode 100644 index 0000000000..78b769aaff --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-iter-get-err.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-empty-iter-get-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned from GetIterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ ] + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iterable = {}; +iterable[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-array.js b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-array.js new file mode 100644 index 0000000000..35c4607eea --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-array.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-empty-val-array.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: An ArrayAssignmentPattern without an AssignmentElementList requires iterable values. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +for ([] of [[]]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-bool.js b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-bool.js new file mode 100644 index 0000000000..d214286a58 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-bool.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-empty-val-bool.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ArrayAssignmentPattern without an AssignmentElementList requires iterable values and throws for boolean values (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(TypeError, function() { + for ([] of [true]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-null.js new file mode 100644 index 0000000000..9b443df948 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-null.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-empty-val-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ArrayAssignmentPattern without an AssignmentElementList requires iterable values and throws for `null`. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(TypeError, function() { + for ([] of [null]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-num.js b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-num.js new file mode 100644 index 0000000000..810a70201d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-num.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-empty-val-num.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ArrayAssignmentPattern without an AssignmentElementList requires iterable values and throws for number values. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(TypeError, function() { + for ([] of [1]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-string.js b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-string.js new file mode 100644 index 0000000000..42c37c37b3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-string.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-empty-val-string.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: An ArrayAssignmentPattern without an AssignmentElementList requires iterable values. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +for ([] of ['string literal']) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-symbol.js b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-symbol.js new file mode 100644 index 0000000000..10dbd8e691 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-symbol.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-empty-val-symbol.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ArrayAssignmentPattern without an AssignmentElementList requires iterable values and throws for Symbol values. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var s = Symbol(); + +var counter = 0; + +assert.throws(TypeError, function() { + for ([] of [s]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-undef.js new file mode 100644 index 0000000000..21bb4b5eb3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-empty-val-undef.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-empty-val-undef.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ArrayAssignmentPattern without an AssignmentElementList requires iterable values and throws for `undefined`. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(TypeError, function() { + for ([] of [undefined]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-iteration.js b/js/src/tests/test262/language/statements/for-of/dstr/array-iteration.js new file mode 100644 index 0000000000..3610f3a338 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-iteration.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-iteration.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Value iteration only proceeds for the number of elements in the ArrayAssignmentPattern. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var count = 0; +var g = function*() { + count += 1; + yield; + count += 1; + yield; + count += 1; +} + +var counter = 0; + +for ([,,] of [g()]) { + assert.sameValue(count, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-after-element.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-after-element.js new file mode 100644 index 0000000000..479d42ce9c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-after-element.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-after-element.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: An AssignmentRestElement following an AssignmentElement consumes all remaining iterable values. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x, y; + +var counter = 0; + +for ([x, ...y] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + assert.sameValue(y.length, 2); + assert.sameValue(y[0], 2); + assert.sameValue(y[1], 3); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-after-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-after-elision.js new file mode 100644 index 0000000000..12d68319a0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-after-elision.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-after-elision.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: An AssignmentRestElement following an elision consumes all remaining iterable values. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ([, ...x] of [[1, 2, 3]]) { + assert.sameValue(x.length, 2); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 3); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-before-element.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-before-element.js new file mode 100644 index 0000000000..4f85f4ed44 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-before-element.js @@ -0,0 +1,33 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-before-element.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: An AssignmentElement may not follow an AssignmentRestElement in an AssignmentElementList. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([...x, y] of [[]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-before-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-before-elision.js new file mode 100644 index 0000000000..6c81944496 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-before-elision.js @@ -0,0 +1,33 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-before-elision.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: An elision may not follow an AssignmentRestElement in an AssignmentElementList. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([...x,] of [[]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-before-rest.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-before-rest.js new file mode 100644 index 0000000000..8898ee2dd1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-before-rest.js @@ -0,0 +1,33 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-before-rest.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: An AssignmentRestElement may not follow another AssignmentRestElement in an AssignmentElementList. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([...x, ...y] of [[]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-elision-invalid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-elision-invalid.js new file mode 100644 index 0000000000..69122c7ceb --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-elision-invalid.js @@ -0,0 +1,33 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-elision-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: ArrayAssignmentPattern may not include elisions following an AssignmentRestElement in a AssignmentElementList. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([...x,] of [[]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-elision-iter-abpt.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-elision-iter-abpt.js new file mode 100644 index 0000000000..78b9770c33 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-elision-iter-abpt.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-elision-iter-abpt.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is not called when assignment evaluation produces an abrupt completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 4. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. If status is an abrupt completion, then + i. If iteratorRecord.[[done]] is false, return + IteratorClose(iterator, status). + ii. Return Completion(status). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + throw new Test262Error(); + }, + return: function() { + returnCount += 1; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; +var x; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([ , ...x] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-elision.js new file mode 100644 index 0000000000..50b9dc4d18 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-elision.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-elision.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: ArrayAssignmentPattern may include elisions at any position preceding a AssignmentRestElement in a AssignmentElementList. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x, y; + +var counter = 0; + +for ([, , x, , ...y] of [[1, 2, 3, 4, 5, 6]]) { + assert.sameValue(x, 3); + assert.sameValue(y.length, 2); + assert.sameValue(y[0], 5); + assert.sameValue(y[1], 6); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-init.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-init.js new file mode 100644 index 0000000000..f7181ff364 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-init.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-init.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: The AssignmentRestElement does not support an initializer. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); +var x; + +for ([...x = 1] of [[]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-get-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-get-err.js new file mode 100644 index 0000000000..b566e7b806 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-get-err.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-iter-get-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Abrupt completion returned from GetIterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iterable = {}; +var x; +iterable[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([...x] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-nrml-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-nrml-close-skip.js new file mode 100644 index 0000000000..497d477f7e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-nrml-close-skip.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-iter-nrml-close-skip.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is not called when assignment evaluation has exhausted the iterator (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 7. Return result. + +---*/ +var nextCount = 0; +var returnCount = 0; +var x; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([ ...x ] of [iterable]) { + assert.sameValue(nextCount, 1); + assert.sameValue(returnCount, 0); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-rtrn-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-rtrn-close-err.js new file mode 100644 index 0000000000..d35bfcfd0e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-rtrn-close-err.js @@ -0,0 +1,88 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-iter-rtrn-close-err.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is called when reference evaluation produces a "return" completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + b. ReturnIfAbrupt(lref). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + +---*/ +var returnCount = 0; +var unreachable = 0; +var iterable = {}; +var iterator = { + return: function() { + returnCount += 1; + + throw new Test262Error(); + } +}; +var iter; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +function* g() { + +var counter = 0; + +for ([...{}[yield]] of [iterable]) { + unreachable += 1; + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +iter = g(); +iter.next(); +assert.throws(Test262Error, function() { + iter.return(); +}); + +assert.sameValue(returnCount, 1); +assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-rtrn-close-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-rtrn-close-null.js new file mode 100644 index 0000000000..9c6d19e9fe --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-rtrn-close-null.js @@ -0,0 +1,88 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-iter-rtrn-close-null.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose throws a TypeError when `return` returns a non-Object value (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + b. ReturnIfAbrupt(lref). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + +---*/ +var iterable = {}; +var iterator = { + return: function() { + return null; + } +}; +var iter; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +function* g() { + +var counter = 0; + +for ([...{}[yield]] of [iterable]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +iter = g(); +iter.next(); + +assert.throws(TypeError, function() { + iter.return(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-rtrn-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-rtrn-close.js new file mode 100644 index 0000000000..2d37e4bfe2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-rtrn-close.js @@ -0,0 +1,103 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-iter-rtrn-close.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: IteratorClose is called when reference evaluation produces a "return" completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + b. ReturnIfAbrupt(lref). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). + +---*/ +var returnCount = 0; +var unreachable = 0; +var thisValue = null; +var args = null; +var iterable = {}; +var iterator = { + next() { + throw new Test262Error(); + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +var iter, result; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +function* g() { + +var counter = 0; + +for ([...{}[yield]] of [iterable]) { + unreachable += 1; + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +iter = g(); +iter.next(); +result = iter.return(444); + +assert.sameValue(returnCount, 1); +assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); +assert.sameValue(result.value, 444); +assert(result.done, 'Iterator correctly closed'); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-thrw-close-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-thrw-close-err.js new file mode 100644 index 0000000000..4d8a233e94 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-thrw-close-err.js @@ -0,0 +1,85 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-iter-thrw-close-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is called when reference evaluation produces a "throw" completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + b. ReturnIfAbrupt(lref). + +---*/ +var nextCount = 0; +var returnCount = 0; +var x; +function ReturnError() {} +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + + // This value should be discarded. + throw new ReturnError(); + } +}; +var thrower = function() { + throw new Test262Error(); +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([...{}[thrower()]] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 0); +assert.sameValue(returnCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-thrw-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-thrw-close-skip.js new file mode 100644 index 0000000000..b38d26b98d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-thrw-close-skip.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-iter-thrw-close-skip.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is not called when iteration produces an abrupt completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + +---*/ +var nextCount = 0; +var returnCount = 0; +var x; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + throw new Test262Error(); + }, + return: function() { + returnCount += 1; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([...x] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-thrw-close.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-thrw-close.js new file mode 100644 index 0000000000..8d50a51a9e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iter-thrw-close.js @@ -0,0 +1,93 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-iter-thrw-close.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is called when reference evaluation produces a "throw" completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + b. ReturnIfAbrupt(lref). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var x; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + } +}; +var thrower = function() { + throw new Test262Error(); +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([...{}[thrower()]] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 0); +assert.sameValue(returnCount, 1); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iteration.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iteration.js new file mode 100644 index 0000000000..d72db7dfa4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-iteration.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-iteration.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: In the presense of an AssignmentRestElement, value iteration exhausts the iterable value; (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var count = 0; +var g = function*() { + count += 1; + yield; + count += 1; + yield; + count += 1; +} +var x; + +var counter = 0; + +for ([...x] of [g()]) { + assert.sameValue(count, 3); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-lref-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-lref-err.js new file mode 100644 index 0000000000..bbb495da20 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-lref-err.js @@ -0,0 +1,77 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-lref-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is called when reference evaluation produces an abrupt completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + b. ReturnIfAbrupt(lref). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + } +}; +var thrower = function() { + throw new Test262Error(); +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([...{}[thrower()]] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 0); +assert.sameValue(returnCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-lref.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-lref.js new file mode 100644 index 0000000000..88c55def71 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-lref.js @@ -0,0 +1,74 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-lref.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Reference is evaluated during assignment (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + b. ReturnIfAbrupt(lref). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + } +}; +var obj = {}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +for ([...obj['a' + 'b']] of [iterable]) { + assert.sameValue(nextCount, 1); + assert.sameValue(returnCount, 0); + assert(!!obj.ab); + assert.sameValue(obj.ab.length, 0); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-invalid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-invalid.js new file mode 100644 index 0000000000..755d5ddd22 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-invalid.js @@ -0,0 +1,33 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-array-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if the lexical token sequence matched by LeftHandSideExpression cannot be parsed with no tokens left over using AssignmentPattern as the goal symbol. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([...[(x, y)]] of [[[]]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-iter-thrw-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-iter-thrw-close-skip.js new file mode 100644 index 0000000000..cbe266ff9c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-iter-thrw-close-skip.js @@ -0,0 +1,80 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-array-iter-thrw-close-skip.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is not called when nested array pattern evaluation produces an abrupt completion (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + [...] + 4. Repeat while iteratorRecord.[[done]] is false + [...] + d. If next is false, set iteratorRecord.[[done]] to true. + [...] + 7. Return the result of performing DestructuringAssignmentEvaluation of + nestedAssignmentPattern with A as the argument. + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + } +}; +var thrower = function() { + throw new Test262Error(); +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([...[...{}[thrower()]]] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-null.js new file mode 100644 index 0000000000..c19fe03c4e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-null.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-array-null.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the iterable emits `null` as the only value, an array with a single `null` element should be used as the value of the nested DestructuringAssignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x, y; + +var counter = 0; + +for ([...[x, y]] of [[null]]) { + assert.sameValue(x, null); + assert.sameValue(y, undefined); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-undefined-hole.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-undefined-hole.js new file mode 100644 index 0000000000..e54d64285b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-undefined-hole.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-array-undefined-hole.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the iterable is an array with a "hole", an array with a single `undefined` element should be used as the value of the nested DestructuringAssignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; + +var counter = 0; + +for ([...[x]] of [[ , ]]) { + assert.sameValue(x, undefined); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-undefined-own.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-undefined-own.js new file mode 100644 index 0000000000..d36db6c846 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-undefined-own.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-array-undefined-own.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the iterable emits `undefined` as the only value, an array with a single `undefined` element should be used as the value of the nested DestructuringAssignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; + +var counter = 0; + +for ([...[x]] of [[undefined]]) { + assert.sameValue(x, undefined); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-undefined.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-undefined.js new file mode 100644 index 0000000000..a9db7a0b79 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-undefined.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-array-undefined.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the iterable is emits no values, an empty array should be used as the value of the nested DestructuringAssignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; + +var counter = 0; + +for ([...[x]] of [[]]) { + assert.sameValue(x, undefined); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-yield-expr.js new file mode 100644 index 0000000000..ea7b1adfdd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-yield-expr.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-array-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of a nested destructuring assignment and within a generator function body, it should behave as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var value = [86]; +var x = {}; +var iterationResult, iter; + +iter = (function*() { + +var counter = 0; + +for ([...[x[yield]]] of [[86]]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +}()); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x.prop, undefined); + +iterationResult = iter.next('prop'); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x.prop, 86); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..fb2fb1e0d3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-yield-ident-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-array-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of a nested destructuring assignment and outside of a generator function body, it should behave as an IdentifierExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([...[x[yield]]] of [[]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-yield-ident-valid.js new file mode 100644 index 0000000000..47be4f44c6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array-yield-ident-valid.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-array-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of a nested destructuring assignment and outside of a generator function body, it should behave as an IdentifierExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 'prop'; +var x = {}; + +var counter = 0; + +for ([...[x[yield]]] of [[86]]) { + assert.sameValue(x.prop, 86); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array.js new file mode 100644 index 0000000000..348bef9481 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-array.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-array.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal, it should be parsed parsed as a DestructuringAssignmentPattern and evaluated as a destructuring assignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ([...[x]] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-invalid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-invalid.js new file mode 100644 index 0000000000..3368e6ea71 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-invalid.js @@ -0,0 +1,33 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-obj-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if the lexical token sequence matched by LeftHandSideExpression cannot be parsed with no tokens left over using AssignmentPattern as the goal symbol. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([...{ get x() {} }] of [[[]]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-null.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-null.js new file mode 100644 index 0000000000..c785308214 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-null.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-obj-null.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object literal and the iterable emits `null` as the only value, an array with a single `null` element should be used as the value of the nested DestructuringAssignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x, length; + +var counter = 0; + +for ([...{ 0: x, length }] of [[null]]) { + assert.sameValue(x, null); + assert.sameValue(length, 1); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-undefined-hole.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-undefined-hole.js new file mode 100644 index 0000000000..51a4f6a384 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-undefined-hole.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-obj-undefined-hole.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the iterable is an array with a "hole", an array with a single `undefined` element should be used as the value of the nested DestructuringAssignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; +// Use the the top-level lexical scope for 'length' to provide compatibility with browsers +// where length and name are properties of WindowProxy +let length; + +var counter = 0; + +for ([...{ 0: x, length }] of [[ , ]]) { + assert.sameValue(x, undefined); + assert.sameValue(length, 1); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-undefined-own.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-undefined-own.js new file mode 100644 index 0000000000..2c93d273ba --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-undefined-own.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-obj-undefined-own.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the iterable emits `undefined` as the only value, an array with a single `undefined` element should be used as the value of the nested DestructuringAssignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; +// Use the the top-level lexical scope for 'length' to provide compatibility with browsers +// where length and name are properties of WindowProxy +let length; + +var counter = 0; + +for ([...{ 0: x, length }] of [[undefined]]) { + assert.sameValue(x, undefined); + assert.sameValue(length, 1); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-undefined.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-undefined.js new file mode 100644 index 0000000000..c3c28db4a7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-undefined.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-obj-undefined.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an obect literal and the iterable is emits no values, an empty array should be used as the value of the nested DestructuringAssignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; +// Use the the top-level lexical scope for 'length' to provide compatibility with browsers +// where length and name are properties of WindowProxy +let length; + +var counter = 0; + +for ([...{ 0: x, length }] of [[]]) { + assert.sameValue(x, undefined); + assert.sameValue(length, 0); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-yield-expr.js new file mode 100644 index 0000000000..93a2cce8ac --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-yield-expr.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-obj-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment and within a generator function body, it should behave as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var iterationResult, iter, x; + +iter = (function*() { + +var counter = 0; + +for ([...{ x = yield }] of [[{}]]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +}()); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x, undefined); + +iterationResult = iter.next(4); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x, 4); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..7124f411be --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-yield-ident-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-obj-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment and outside of a generator function body, it should behave as an IdentifierExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ([...{ x = yield }] of [[{}]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-yield-ident-valid.js new file mode 100644 index 0000000000..7dc23a56cd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj-yield-ident-valid.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-obj-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment and outside of a generator function body, it should behave as an IdentifierExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 2; +var x; + +var counter = 0; + +for ([...{ x = yield }] of [[{}]]) { + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj.js new file mode 100644 index 0000000000..482ae1ca0a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-nested-obj.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-nested-obj.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object literal, it should be parsed as a DestructuringAssignmentPattern and evaluated as a destructuring assignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ([...{ 1: x }] of [[1, 2, 3]]) { + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-const.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-const.js new file mode 100644 index 0000000000..56c60e050e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-const.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-put-const.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: The assignment target should obey `const` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [const, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +const c = null; + +var counter = 0; + +assert.throws(TypeError, function() { + for ([ ...c ] of [[1]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-let.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-let.js new file mode 100644 index 0000000000..487d08cd62 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-let.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-put-let.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: The assignment target should obey `let` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [let, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(ReferenceError, function() { + for ([ ...x ] of [[]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +let x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref-no-get.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref-no-get.js new file mode 100644 index 0000000000..110d37c5ae --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref-no-get.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-put-prop-ref-no-get.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the DestructuringAssignmentTarget of an AssignmentElement is a PropertyReference, it should not be evaluated. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var setValue; +var x = { + get y() { + throw new Test262Error('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}; + +var counter = 0; + +for ([...x.y] of [[23, 45, 99]]) { + assert.sameValue(setValue.length, 3); + assert.sameValue(setValue[0], 23); + assert.sameValue(setValue[1], 45); + assert.sameValue(setValue[2], 99); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref-user-err-iter-close-skip.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref-user-err-iter-close-skip.js new file mode 100644 index 0000000000..2f6c3746d6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref-user-err-iter-close-skip.js @@ -0,0 +1,83 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-put-prop-ref-user-err-iter-close-skip.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: IteratorClose is not called when value assignment produces an abrupt completion. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + [...] + 4. Repeat while iteratorRecord.[[done]] is false + [...] + d. If next is false, set iteratorRecord.[[done]] to true. + [...] + 5. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Return PutValue(lref, A). + +---*/ +var nextCount = 0; +var returnCount = 0; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + } +}; +var obj = Object.defineProperty({}, 'poisoned', { + set: function(x) { + throw new Test262Error(); + } +}); +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([...obj.poisoned] of [iterable]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref-user-err.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref-user-err.js new file mode 100644 index 0000000000..45e6872020 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref-user-err.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-put-prop-ref-user-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Any error raised as a result of setting the value should be forwarded to the runtime. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = { + set y(val) { + throw new Test262Error(); + } +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ([...x.y] of [[23]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref.js new file mode 100644 index 0000000000..10b3ca6d3b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-prop-ref.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-put-prop-ref.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The DestructuringAssignmentTarget of an AssignmentElement may be a PropertyReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = {}; + +var counter = 0; + +for ([...x.y] of [[4, 3, 2]]) { + assert.sameValue(x.y.length, 3); + assert.sameValue(x.y[0], 4); + assert.sameValue(x.y[1], 3); + assert.sameValue(x.y[2], 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-unresolvable-no-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-unresolvable-no-strict.js new file mode 100644 index 0000000000..20b01f6336 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-unresolvable-no-strict.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-put-unresolvable-no-strict.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Outside of strict mode, if the the assignment target is an unresolvable reference, a new `var` binding should be created in the environment record. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +{ + +var counter = 0; + +for ([ ...unresolvable ] of [[]]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +assert.sameValue(unresolvable.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-unresolvable-strict-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-unresolvable-strict-strict.js new file mode 100644 index 0000000000..a566c3f60f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-put-unresolvable-strict-strict.js @@ -0,0 +1,40 @@ +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-put-unresolvable-strict.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: In strict mode, if the the assignment target is an unresolvable reference, a ReferenceError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(ReferenceError, function() { + for ([ ...unresolvable ] of [[]]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-yield-expr.js new file mode 100644 index 0000000000..d0c492b0a3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-yield-expr.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of an AssignmentRestElement and within the body of a generator function, it should behave as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = {}; +var iterationResult, iter; + +iter = (function*() { + +var counter = 0; + +for ([...x[yield]] of [[33, 44, 55]]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +}()); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x.prop, undefined); + +iterationResult = iter.next('prop'); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x.prop.length, 3); +assert.sameValue(x.prop[0], 33); +assert.sameValue(x.prop[1], 44); +assert.sameValue(x.prop[2], 55); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..12b41221bd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-yield-ident-invalid-strict.js @@ -0,0 +1,35 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of an AssignmentRestElement and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); +var x = {}; + +for ([...x[yield]] of [[]]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/array-rest-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-yield-ident-valid.js new file mode 100644 index 0000000000..9d2e19dff6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/array-rest-yield-ident-valid.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/array-rest-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of an AssignmentRestElement and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 'prop'; +var x = {}; + +var counter = 0; + +for ([...x[yield]] of [[33, 44, 55]]) { + assert.sameValue(x.prop.length, 3); + assert.sameValue(x.prop[0], 33); + assert.sameValue(x.prop[1], 44); + assert.sameValue(x.prop[2], 55); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/browser.js b/js/src/tests/test262/language/statements/for-of/dstr/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/browser.js diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-close.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-close.js new file mode 100644 index 0000000000..bdc6687660 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-close.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-close.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: false }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var iterCount = 0; + +for (const [x] of [iter]) { + assert.sameValue(doneCallCount, 1); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..7dcc91b449 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-get-err-array-prototype.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err-array-prototype.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Abrupt completion returned by GetIterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iteratorRecord be ? GetIterator(value). + + GetIterator ( obj [ , hint [ , method ] ] ) + + [...] + 4. Let iterator be ? Call(method, obj). + + Call ( F, V [ , argumentsList ] ) + + [...] + 2. If IsCallable(F) is false, throw a TypeError exception. + +---*/ +delete Array.prototype[Symbol.iterator]; + +assert.throws(TypeError, function() { + for (const [x, y, z] of [[1, 2, 3]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-get-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-get-err.js new file mode 100644 index 0000000000..3caf29d81b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-get-err.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Abrupt completion returned by GetIterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + for (const [x] of [iter]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-no-close.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-no-close.js new file mode 100644 index 0000000000..817876118a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-init-iter-no-close.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-no-close.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: true }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var iterCount = 0; + +for (const [x] of [iter]) { + assert.sameValue(doneCallCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-name-iter-val.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-name-iter-val.js new file mode 100644 index 0000000000..7ae6f3fb2f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-name-iter-val.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-name-iter-val.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding with normal value iteration (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [x, y, z] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..217d2adf07 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elem-init.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-init.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (const [[x, y, z] = [4, 5, 6]] of [[]]) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..8e557ea330 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elem-iter.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-iter.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (const [[x, y, z] = [4, 5, 6]] of [[[7, 8, 9]]]) { + assert.sameValue(x, 7); + assert.sameValue(y, 8); + assert.sameValue(z, 9); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..9a2ebf1553 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elision-init.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-init.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var iterCount = 0; + +for (const [[,] = g()] of [[]]) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..a0ad26fc25 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-elision-iter.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-iter.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var callCount = 0; +function* g() { + callCount += 1; +}; + +var iterCount = 0; + +for (const [[,] = g()] of [[[]]]) { + assert.sameValue(callCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..0b7d99fda1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-empty-init.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-init.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var initCount = 0; +var iterCount = 0; +var iter = function*() { iterCount += 1; }(); + +var iterCount = 0; + +for (const [[] = function() { initCount += 1; return iter; }()] of [[]]) { + assert.sameValue(initCount, 1); + assert.sameValue(iterCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..8b2d39fa32 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-empty-iter.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-iter.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var initCount = 0; + +var iterCount = 0; + +for (const [[] = function() { initCount += 1; }()] of [[[23]]]) { + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..81d8dc2de2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-rest-init.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-init.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; + +var iterCount = 0; + +for (const [[...x] = values] of [[]]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..b09b6daabe --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-rest-iter.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-iter.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; +var initCount = 0; + +var iterCount = 0; + +for (const [[...x] = function() { initCount += 1; }()] of [[values]]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..d380b761f3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-ary-val-null.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-val-null.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Nested array destructuring with a null value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). +---*/ + +assert.throws(TypeError, function() { + for (const [[x]] of [[null]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..00f39a397a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-exhausted.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-exhausted.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Destructuring initializer with an exhausted iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [x = 23] of [[]]) { + assert.sameValue(x, 23); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..0d77af2052 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-arrow.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-arrow.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding does assign name to arrow functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [arrow = () => {}] of [[]]) { + assert.sameValue(arrow.name, 'arrow'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..d536028996 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-class.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-class.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }] of [[]]) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..a48fa92448 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-cover.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-cover.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [cover = (function () {}), xCover = (0, function() {})] of [[]]) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..023f9247fc --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-fn.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-fn.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [fn = function () {}, xFn = function x() {}] of [[]]) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..e33c8f1c06 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-fn-name-gen.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-gen.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). + +---*/ + +var iterCount = 0; + +for (const [gen = function* () {}, xGen = function* x() {}] of [[]]) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..671c1fe0a0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-hole.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-hole.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Destructuring initializer with a "hole" (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + SingleNameBinding : BindingIdentifier Initializeropt + [...] 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [x = 23] of [[,]]) { + assert.sameValue(x, 23); + // another statement + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..287e32bcd7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-skipped.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-skipped.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var iterCount = 0; + +for (const [w = counter(), x = counter(), y = counter(), z = counter()] of [[null, 0, false, '']]) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..eac4b83873 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-throws.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-throws.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Destructuring initializer returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ + +assert.throws(Test262Error, function() { + for (const [x = (function() { throw new Test262Error(); })()] of [[undefined]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..1a3db28d11 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-undef.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-undef.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Destructuring initializer with an undefined value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [x = 23] of [[undefined]]) { + assert.sameValue(x, 23); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..c0169e8a17 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-init-unresolvable.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-unresolvable.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Destructuring initializer is an unresolvable reference (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + for (const [ x = unresolvableReference ] of [[]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..2776aab08d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-complete.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-complete.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding when value iteration completes (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [x] of [[]]) { + assert.sameValue(x, undefined); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..1407655409 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-done.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-done.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [_, x] of [[]]) { + assert.sameValue(x, undefined); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..6f93b69dd5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-step-err.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-step-err.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +assert.throws(Test262Error, function() { + for (const [x] of [g]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..ef03673a4e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-val-array-prototype.js @@ -0,0 +1,81 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-array-prototype.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializer_opt + + 1. Let bindingId be StringValue of BindingIdentifier. + 2. Let lhs be ? ResolveBinding(bindingId, environment). + 3. If iteratorRecord.[[Done]] is false, then + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[Done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[Done]] to true. + iii. ReturnIfAbrupt(v). + [...] + 7. Return InitializeReferencedBinding(lhs, v). + +---*/ +Array.prototype[Symbol.iterator] = function* () { + if (this.length > 0) { + yield this[0]; + } + if (this.length > 1) { + yield this[1]; + } + if (this.length > 2) { + yield 42; + } +}; + +var iterCount = 0; + +for (const [x, y, z] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 42); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..c52b85fc58 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-val-err.js @@ -0,0 +1,75 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-err.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(v). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +assert.throws(Test262Error, function() { + for (const [x] of [g]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..9751e7a674 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-id-iter-val.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [x, y, z] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..38ef7a9261 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-id-init.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id-init.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (const [{ x, y, z } = { x: 44, y: 55, z: 66 }] of [[]]) { + assert.sameValue(x, 44); + assert.sameValue(y, 55); + assert.sameValue(z, 66); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..744ef995e6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-id.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (const [{ x, y, z } = { x: 44, y: 55, z: 66 }] of [[{ x: 11, y: 22, z: 33 }]]) { + assert.sameValue(x, 11); + assert.sameValue(y, 22); + assert.sameValue(z, 33); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..600ac4b074 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-prop-id-init.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id-init.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (const [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] of [[]]) { + assert.sameValue(v, 444); + assert.sameValue(x, 555); + assert.sameValue(z, 666); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..1d9a8cbb8d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-prop-id.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (const [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] of [[{ u: 777, w: 888, y: 999 }]]) { + assert.sameValue(v, 777); + assert.sameValue(x, 888); + assert.sameValue(z, 999); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..5f6d0743a2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-val-null.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-null.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Nested object destructuring with a null value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +assert.throws(TypeError, function() { + for (const [{ x }] of [[null]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..25977c2400 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elem-obj-val-undef.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-undef.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Nested object destructuring with a value of `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +assert.throws(TypeError, function() { + for (const [{ x }] of [[]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..3952eff05c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision-exhausted.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-exhausted.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Elision accepts exhausted iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + [...] + 2. Return NormalCompletion(empty). + +---*/ +var iter = function*() {}(); +iter.next(); + +var iterCount = 0; + +for (const [,] of [iter]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision-iter-close.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision-iter-close.js new file mode 100644 index 0000000000..eb8a8b0b96 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision-iter-close.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-iter-close.case +// - src/dstr-binding/iter-close/for-of-const.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (const [,] of [iter]) { + return; + } +} + +fn(); + +assert.sameValue(iter.next().done, true, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..dcd3155f83 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision-step-err.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-step-err.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Elision advances iterator and forwards abrupt completions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var following = 0; +var iter =function* () { + throw new Test262Error(); + following += 1; +}(); + +assert.throws(Test262Error, function() { + for (const [,] of [iter]) { + return; + } +}); + +iter.next(); +assert.sameValue(following, 0, 'Iterator was properly closed.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision.js new file mode 100644 index 0000000000..b42eaaf2a8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-elision.js @@ -0,0 +1,77 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Elision advances iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var iterCount = 0; + +for (const [,] of [g()]) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-empty.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-empty.js new file mode 100644 index 0000000000..7e5df06e2e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-empty.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-empty.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var iterCount = 0; + +for (const [] of [iter]) { + assert.sameValue(iterations, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-init-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-init-err.js new file mode 100644 index 0000000000..f294826871 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-init-err.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteration-statements +description: > + Initializer is not allowed in head's ForDeclaration position. +info: | + IterationStatement: + for (ForDeclaration of AssignmentExpression) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +for (const [x] = 1 of []) {} diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..a8bfc671b0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-elem.js @@ -0,0 +1,84 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elem.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element containing an array BindingElementList pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const [...[x, y, z]] of [[3, 4, 5]]) { + assert.sameValue(x, 3); + assert.sameValue(y, 4); + assert.sameValue(z, 5); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..ea7ddad36f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-elision.js @@ -0,0 +1,90 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elision.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element containing an elision (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var iterCount = 0; + +for (const [...[,]] of [g()]) { + assert.sameValue(first, 1); + assert.sameValue(second, 1); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..5084f6f3e6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-empty.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-empty.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element containing an "empty" array pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var iterCount = 0; + +for (const [...[]] of [iter]) { + assert.sameValue(iterations, 1); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..248cac83a4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-ary-rest.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-rest.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element containing a rest element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +var values = [1, 2, 3]; + +var iterCount = 0; + +for (const [...[...x]] of [values]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..023443c909 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-direct.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-direct.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Lone rest element (direct binding) (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [compareArray.js] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingIdentifier + + [...] + 2. Let A be ! ArrayCreate(0). + 3. Let n be 0. + 4. Repeat, + [...] + f. Perform ! CreateDataPropertyOrThrow(A, ! ToString(n), nextValue). + g. Set n to n + 1. + +---*/ + +var iterCount = 0; + +for (const [...x] of [[1]]) { + assert(Array.isArray(x)); + assert.compareArray(x, [1]); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..a0cf9ee911 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-elision-next-err.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision-next-err.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Rest element following elision elements (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. + +---*/ +var iter = (function*() { throw new Test262Error(); })(); + +assert.throws(Test262Error, function() { + for (const [, ...x] of [iter]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..d2479bbedd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-elision.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element following elision elements (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. +---*/ +var values = [1, 2, 3, 4, 5]; + +var iterCount = 0; + +for (const [ , , ...x] of [values]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 3); + assert.sameValue(x[1], 4); + assert.sameValue(x[2], 5); + assert.notSameValue(x, values); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..c2e7693af8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-exhausted.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-exhausted.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: RestElement applied to an exhausted iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + b. If iteratorRecord.[[done]] is true, then + i. If environment is undefined, return PutValue(lhs, A). + ii. Return InitializeReferencedBinding(lhs, A). + +---*/ + +var iterCount = 0; + +for (const [, , ...x] of [[1, 2]]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-iter-close.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-iter-close.js new file mode 100644 index 0000000000..0534ab4866 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-iter-close.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-close.case +// - src/dstr-binding/iter-close/for-of-const.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (const [...x] of [iter]) { + return; + } +} + +fn(); + +assert.sameValue(iter.next().done, true, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..fe2263684a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-iter-step-err.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-step-err.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + a. If iteratorRecord.[[done]] is false, + i. Let next be IteratorStep(iteratorRecord.[[iterator]]). + ii. If next is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(next). + +---*/ +var first = 0; +var second = 0; +var iter = function*() { + first += 1; + throw new Test262Error(); + second += 1; +}(); + +assert.throws(Test262Error, function() { + for (const [...x] of [iter]) { + return; + } +}); + +iter.next(); +assert.sameValue(first, 1); +assert.sameValue(second, 0, 'Iterator is closed following abrupt completion.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..12472d517c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-iter-val-err.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-val-err.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + c. Let nextValue be IteratorValue(next). + d. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to + true. + e. ReturnIfAbrupt(nextValue). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +assert.throws(Test262Error, function() { + for (const [...x] of [iter]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id.js new file mode 100644 index 0000000000..2c4b3fc3a3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Lone rest element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + [...] 3. Let A be ArrayCreate(0). [...] 5. Repeat + [...] + f. Let status be CreateDataProperty(A, ToString (n), nextValue). + [...] +---*/ +var values = [1, 2, 3]; + +var iterCount = 0; + +for (const [...x] of [values]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..d20f6a8c56 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-init-ary.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-ary.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element (nested array pattern) does not support initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (const [...[ x ] = []] of [[]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..eeb53cf677 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-init-id.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-id.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element (identifier) does not support initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (const [...x = []] of [[]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..e8e3d80256 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-init-obj.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-obj.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element (nested object pattern) does not support initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (const [...{ x } = []] of [[]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..897ad82b3b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-not-final-ary.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-ary.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (const [...[x], y] of [[1, 2, 3]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..bbd9a15bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-not-final-id.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-id.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element (identifier) may not be followed by any element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (const [...x, y] of [[1, 2, 3]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..0e6ec2518c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-not-final-obj.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-obj.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (const [...{ x }, y] of [[1, 2, 3]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..de0e9babd6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-obj-id.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-id.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element containing an object binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ + +var iterCount = 0; + +for (const [...{ length }] of [[1, 2, 3]]) { + assert.sameValue(length, 3); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..d5ddf64601 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-obj-prop-id.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-prop-id.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest element containing an object binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +let length = "outer"; + +var iterCount = 0; + +for (const [...{ 0: v, 1: w, 2: x, 3: y, length: z }] of [[7, 8, 9]]) { + assert.sameValue(v, 7); + assert.sameValue(w, 8); + assert.sameValue(x, 9); + assert.sameValue(y, undefined); + assert.sameValue(z, 3); + + assert.sameValue(length, "outer", "the length prop is not set as a binding name"); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-init-null.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-init-null.js new file mode 100644 index 0000000000..53a699c8b8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-init-null.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-null.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (const {} of [null]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-init-undefined.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-init-undefined.js new file mode 100644 index 0000000000..9a0540f9e6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-init-undefined.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-undefined.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (const {} of [undefined]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-empty.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-empty.js new file mode 100644 index 0000000000..fc85ac0e64 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-empty.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-empty.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: No property access occurs for an "empty" object binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ +var accessCount = 0; +var obj = Object.defineProperty({}, 'attr', { + get: function() { + accessCount += 1; + } +}); + +var iterCount = 0; + +for (const {} of [obj]) { + assert.sameValue(accessCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..0c3baa9c5e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-get-value-err.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-get-value-err.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. Let v be GetV(value, propertyName). + 5. ReturnIfAbrupt(v). +---*/ +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + for (const { poisoned } of [poisonedProperty]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..a93573fbbb --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-arrow.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-arrow.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (const { arrow = () => {} } of [{}]) { + assert.sameValue(arrow.name, 'arrow'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..a65a8562e7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-class.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-class.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (const { cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } } of [{}]) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..1dbff80598 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-cover.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-cover.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (const { cover = (function () {}), xCover = (0, function() {}) } of [{}]) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..7113485257 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-fn.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-fn.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (const { fn = function () {}, xFn = function x() {} } of [{}]) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..71e0426536 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-fn-name-gen.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-gen.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). + +---*/ + +var iterCount = 0; + +for (const { gen = function* () {}, xGen = function* x() {} } of [{}]) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..061901ff4d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-skipped.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-skipped.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var iterCount = 0; + +for (const { w = counter(), x = counter(), y = counter(), z = counter() } of [{ w: null, x: 0, y: false, z: '' }]) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..f1aa1a7ab3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-throws.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-throws.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Error thrown when evaluating the initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (const { x = thrower() } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..ee5f500377 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-init-unresolvable.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-unresolvable.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Destructuring initializer is an unresolvable reference (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + for (const { x = unresolvableReference } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..c3476c299f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-id-trailing-comma.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-trailing-comma.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (const { x, } of [{ x: 23 }]) { + assert.sameValue(x, 23); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-init-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-init-err.js new file mode 100644 index 0000000000..7961550941 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-init-err.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteration-statements +description: > + Initializer is not allowed in head's ForDeclaration position. +info: | + IterationStatement: + for (ForDeclaration of AssignmentExpression) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +for (const {x} = 1 of []) {} diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-list-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-list-err.js new file mode 100644 index 0000000000..6b083c1b40 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-list-err.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-list-err.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPropertyList : BindingPropertyList , BindingProperty + + 1. Let status be the result of performing BindingInitialization for + BindingPropertyList using value and environment as arguments. + 2. ReturnIfAbrupt(status). +---*/ +var initCount = 0; +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (const { a, b = thrower(), c = ++initCount } of [{}]) { + return; + } +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..3070390866 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary-init.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-init.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (const { w: [x, y, z] = [4, 5, 6] } of [{}]) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..995d172198 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary-trailing-comma.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-trailing-comma.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (const { x: [y], } of [{ x: [45] }]) { + assert.sameValue(y,45); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..7ce541e952 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary-value-null.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-value-null.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + for (const { w: [x, y, z] = [4, 5, 6] } of [{ w: null }]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..cadee3690e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-ary.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (const { w: [x, y, z] = [4, 5, 6] } of [{ w: [7, undefined, ] }]) { + assert.sameValue(x, 7); + assert.sameValue(y, undefined); + assert.sameValue(z, undefined); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..2bf7de1950 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-eval-err.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-eval-err.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Evaluation of property name returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingProperty : PropertyName : BindingElement + + 1. Let P be the result of evaluating PropertyName + 2. ReturnIfAbrupt(P). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (const { [thrower()]: x } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..31a35c2605 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-get-value-err.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-get-value-err.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. Let v be GetV(value, propertyName). + 2. ReturnIfAbrupt(v). +---*/ +var initEvalCount = 0; +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + for (const { poisoned: x = ++initEvalCount } of [poisonedProperty]) { + return; + } +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..7d22df45c2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init-skipped.js @@ -0,0 +1,78 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-skipped.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var iterCount = 0; + +for (const { s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } of [{ s: null, u: 0, w: false, y: '' }]) { + assert.sameValue(t, null); + assert.sameValue(v, 0); + assert.sameValue(x, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + assert.throws(ReferenceError, function() { + s; + }); + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..3de1ee1adf --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init-throws.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-throws.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Error thrown when evaluating the initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (const { x: y = thrower() } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..dd9782c840 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init-unresolvable.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-unresolvable.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Destructuring initializer is an unresolvable reference (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + for (const { x: y = unresolvableReference } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..1e176cc385 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-init.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Binding as specified via property name, identifier, and initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const { x: y = 33 } of [{ }]) { + assert.sameValue(y, 33); + assert.throws(ReferenceError, function() { + x; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..07c7fd9758 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id-trailing-comma.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-trailing-comma.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (const { x: y, } of [{ x: 23 }]) { + assert.sameValue(y, 23); + + assert.throws(ReferenceError, function() { + x; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id.js new file mode 100644 index 0000000000..b3b4e7f218 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-id.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Binding as specified via property name and identifier (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const { x: y } of [{ x: 23 }]) { + assert.sameValue(y, 23); + assert.throws(ReferenceError, function() { + x; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..8aef591cd1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj-init.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-init.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (const { w: { x, y, z } = { x: 4, y: 5, z: 6 } } of [{ w: undefined }]) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..2cd0da6dba --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj-value-null.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-null.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + for (const { w: { x, y, z } = { x: 4, y: 5, z: 6 } } of [{ w: null }]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..c90a93a21b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj-value-undef.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-undef.case +// - src/dstr-binding/error/for-of-const.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + for (const { w: { x, y, z } = undefined } of [{ }]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..2c86bf1cee --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-prop-obj.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (const { w: { x, y, z } = { x: 4, y: 5, z: 6 } } of [{ w: { x: undefined, z: 7 } }]) { + assert.sameValue(x, undefined); + assert.sameValue(y, undefined); + assert.sameValue(z, 7); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-rest-getter.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..9ab6019a31 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-rest-getter.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-getter.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ +var count = 0; + +var iterCount = 0; + +for (const {...x} of [{ get v() { count++; return 2; } }]) { + assert.sameValue(count, 1); + + verifyProperty(x, "v", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..15ef80cd1e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-rest-skip-non-enumerable.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-skip-non-enumerable.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest object doesn't contain non-enumerable properties (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); + +var iterCount = 0; + +for (const {...rest} of [o]) { + assert.sameValue(rest.x, undefined); + + verifyProperty(rest, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(rest, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 4 + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..69fb433326 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/const-obj-ptrn-rest-val-obj.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-val-obj.case +// - src/dstr-binding/default/for-of-const.template +/*--- +description: Rest object contains just unextracted data (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ + +var iterCount = 0; + +for (const {a, b, ...rest} of [{x: 1, y: 2, a: 5, b: 3}]) { + assert.sameValue(rest.a, undefined); + assert.sameValue(rest.b, undefined); + + verifyProperty(rest, "x", { + enumerable: true, + writable: true, + configurable: true, + value: 1 + }); + + verifyProperty(rest, "y", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-close.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-close.js new file mode 100644 index 0000000000..9c2ba3f96c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-close.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-close.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: false }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var iterCount = 0; + +for (let [x] of [iter]) { + assert.sameValue(doneCallCount, 1); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..5772d2b435 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-get-err-array-prototype.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err-array-prototype.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Abrupt completion returned by GetIterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iteratorRecord be ? GetIterator(value). + + GetIterator ( obj [ , hint [ , method ] ] ) + + [...] + 4. Let iterator be ? Call(method, obj). + + Call ( F, V [ , argumentsList ] ) + + [...] + 2. If IsCallable(F) is false, throw a TypeError exception. + +---*/ +delete Array.prototype[Symbol.iterator]; + +assert.throws(TypeError, function() { + for (let [x, y, z] of [[1, 2, 3]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-get-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-get-err.js new file mode 100644 index 0000000000..d67ab5c4ac --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-get-err.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Abrupt completion returned by GetIterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + for (let [x] of [iter]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-no-close.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-no-close.js new file mode 100644 index 0000000000..63205c97cf --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-init-iter-no-close.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-no-close.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: true }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var iterCount = 0; + +for (let [x] of [iter]) { + assert.sameValue(doneCallCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-name-iter-val.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-name-iter-val.js new file mode 100644 index 0000000000..8ee75df788 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-name-iter-val.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-name-iter-val.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding with normal value iteration (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [x, y, z] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..02d52df6e6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elem-init.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-init.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (let [[x, y, z] = [4, 5, 6]] of [[]]) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..c6e3ff07bf --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elem-iter.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-iter.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (let [[x, y, z] = [4, 5, 6]] of [[[7, 8, 9]]]) { + assert.sameValue(x, 7); + assert.sameValue(y, 8); + assert.sameValue(z, 9); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..a76de3274d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elision-init.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-init.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var iterCount = 0; + +for (let [[,] = g()] of [[]]) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..1c62d7be26 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-elision-iter.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-iter.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var callCount = 0; +function* g() { + callCount += 1; +}; + +var iterCount = 0; + +for (let [[,] = g()] of [[[]]]) { + assert.sameValue(callCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..575a575b4a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-empty-init.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-init.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var initCount = 0; +var iterCount = 0; +var iter = function*() { iterCount += 1; }(); + +var iterCount = 0; + +for (let [[] = function() { initCount += 1; return iter; }()] of [[]]) { + assert.sameValue(initCount, 1); + assert.sameValue(iterCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..1494a8af29 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-empty-iter.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-iter.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var initCount = 0; + +var iterCount = 0; + +for (let [[] = function() { initCount += 1; }()] of [[[23]]]) { + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..2b0e795f53 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-rest-init.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-init.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; + +var iterCount = 0; + +for (let [[...x] = values] of [[]]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..8fc2c4e9ad --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-rest-iter.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-iter.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; +var initCount = 0; + +var iterCount = 0; + +for (let [[...x] = function() { initCount += 1; }()] of [[values]]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..b012805051 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-ary-val-null.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-val-null.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Nested array destructuring with a null value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). +---*/ + +assert.throws(TypeError, function() { + for (let [[x]] of [[null]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..73453eeff9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-exhausted.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-exhausted.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Destructuring initializer with an exhausted iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [x = 23] of [[]]) { + assert.sameValue(x, 23); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..125d850f34 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-arrow.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-arrow.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding does assign name to arrow functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [arrow = () => {}] of [[]]) { + assert.sameValue(arrow.name, 'arrow'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..fef2647aba --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-class.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-class.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }] of [[]]) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..aa30c1fbb8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-cover.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-cover.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [cover = (function () {}), xCover = (0, function() {})] of [[]]) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..2fd4c1c892 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-fn.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-fn.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [fn = function () {}, xFn = function x() {}] of [[]]) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..e16e291ec3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-fn-name-gen.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-gen.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). + +---*/ + +var iterCount = 0; + +for (let [gen = function* () {}, xGen = function* x() {}] of [[]]) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..5fda42c7d4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-hole.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-hole.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Destructuring initializer with a "hole" (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + SingleNameBinding : BindingIdentifier Initializeropt + [...] 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [x = 23] of [[,]]) { + assert.sameValue(x, 23); + // another statement + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..a53ddf7bf4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-skipped.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-skipped.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var iterCount = 0; + +for (let [w = counter(), x = counter(), y = counter(), z = counter()] of [[null, 0, false, '']]) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..ddfb202e7e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-throws.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-throws.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Destructuring initializer returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ + +assert.throws(Test262Error, function() { + for (let [x = (function() { throw new Test262Error(); })()] of [[undefined]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..d7db6260ed --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-undef.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-undef.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Destructuring initializer with an undefined value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [x = 23] of [[undefined]]) { + assert.sameValue(x, 23); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..77e2bb144a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-init-unresolvable.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-unresolvable.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Destructuring initializer is an unresolvable reference (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + for (let [ x = unresolvableReference ] of [[]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..c3066148f9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-complete.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-complete.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding when value iteration completes (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [x] of [[]]) { + assert.sameValue(x, undefined); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..b60398b7fe --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-done.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-done.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [_, x] of [[]]) { + assert.sameValue(x, undefined); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..20cd863ab3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-step-err.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-step-err.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +assert.throws(Test262Error, function() { + for (let [x] of [g]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..968f027b96 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-val-array-prototype.js @@ -0,0 +1,81 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-array-prototype.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializer_opt + + 1. Let bindingId be StringValue of BindingIdentifier. + 2. Let lhs be ? ResolveBinding(bindingId, environment). + 3. If iteratorRecord.[[Done]] is false, then + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[Done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[Done]] to true. + iii. ReturnIfAbrupt(v). + [...] + 7. Return InitializeReferencedBinding(lhs, v). + +---*/ +Array.prototype[Symbol.iterator] = function* () { + if (this.length > 0) { + yield this[0]; + } + if (this.length > 1) { + yield this[1]; + } + if (this.length > 2) { + yield 42; + } +}; + +var iterCount = 0; + +for (let [x, y, z] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 42); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..744627718e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-val-err.js @@ -0,0 +1,75 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-err.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(v). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +assert.throws(Test262Error, function() { + for (let [x] of [g]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..ecd94ba119 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-id-iter-val.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [x, y, z] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..d345996ea4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-id-init.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id-init.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (let [{ x, y, z } = { x: 44, y: 55, z: 66 }] of [[]]) { + assert.sameValue(x, 44); + assert.sameValue(y, 55); + assert.sameValue(z, 66); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..086b9871ee --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-id.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (let [{ x, y, z } = { x: 44, y: 55, z: 66 }] of [[{ x: 11, y: 22, z: 33 }]]) { + assert.sameValue(x, 11); + assert.sameValue(y, 22); + assert.sameValue(z, 33); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..37e59ddd46 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-prop-id-init.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id-init.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (let [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] of [[]]) { + assert.sameValue(v, 444); + assert.sameValue(x, 555); + assert.sameValue(z, 666); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..8bc6b1a244 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-prop-id.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (let [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] of [[{ u: 777, w: 888, y: 999 }]]) { + assert.sameValue(v, 777); + assert.sameValue(x, 888); + assert.sameValue(z, 999); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..a52a1db344 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-val-null.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-null.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Nested object destructuring with a null value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +assert.throws(TypeError, function() { + for (let [{ x }] of [[null]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..3daea7a5f7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elem-obj-val-undef.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-undef.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Nested object destructuring with a value of `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +assert.throws(TypeError, function() { + for (let [{ x }] of [[]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..4d467bf91c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision-exhausted.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-exhausted.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Elision accepts exhausted iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + [...] + 2. Return NormalCompletion(empty). + +---*/ +var iter = function*() {}(); +iter.next(); + +var iterCount = 0; + +for (let [,] of [iter]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision-iter-close.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision-iter-close.js new file mode 100644 index 0000000000..5eaef08293 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision-iter-close.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-iter-close.case +// - src/dstr-binding/iter-close/for-of-let.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (let [,] of [iter]) { + return; + } +} + +fn(); + +assert.sameValue(iter.next().done, true, 'iteration occurred as expected'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..476262dc7d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision-step-err.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-step-err.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Elision advances iterator and forwards abrupt completions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var following = 0; +var iter =function* () { + throw new Test262Error(); + following += 1; +}(); + +assert.throws(Test262Error, function() { + for (let [,] of [iter]) { + return; + } +}); + +iter.next(); +assert.sameValue(following, 0, 'Iterator was properly closed.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision.js new file mode 100644 index 0000000000..afa835f0d6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-elision.js @@ -0,0 +1,77 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Elision advances iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var iterCount = 0; + +for (let [,] of [g()]) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-empty.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-empty.js new file mode 100644 index 0000000000..66d7a0fe4a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-empty.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-empty.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var iterCount = 0; + +for (let [] of [iter]) { + assert.sameValue(iterations, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-init-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-init-err.js new file mode 100644 index 0000000000..9c9f86e19e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-init-err.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteration-statements +description: > + Initializer is not allowed in head's ForDeclaration position. +info: | + IterationStatement: + for (ForDeclaration of AssignmentExpression) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +for (let [x] = 1 of []) {} diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..2f03e1f2a6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-elem.js @@ -0,0 +1,84 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elem.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element containing an array BindingElementList pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let [...[x, y, z]] of [[3, 4, 5]]) { + assert.sameValue(x, 3); + assert.sameValue(y, 4); + assert.sameValue(z, 5); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..d9d1f9e3bd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-elision.js @@ -0,0 +1,90 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elision.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element containing an elision (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var iterCount = 0; + +for (let [...[,]] of [g()]) { + assert.sameValue(first, 1); + assert.sameValue(second, 1); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..dea5af639f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-empty.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-empty.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element containing an "empty" array pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var iterCount = 0; + +for (let [...[]] of [iter]) { + assert.sameValue(iterations, 1); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..09def53f88 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-ary-rest.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-rest.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element containing a rest element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +var values = [1, 2, 3]; + +var iterCount = 0; + +for (let [...[...x]] of [values]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..4b1b9723f2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-direct.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-direct.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Lone rest element (direct binding) (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [compareArray.js] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingIdentifier + + [...] + 2. Let A be ! ArrayCreate(0). + 3. Let n be 0. + 4. Repeat, + [...] + f. Perform ! CreateDataPropertyOrThrow(A, ! ToString(n), nextValue). + g. Set n to n + 1. + +---*/ + +var iterCount = 0; + +for (let [...x] of [[1]]) { + assert(Array.isArray(x)); + assert.compareArray(x, [1]); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..b4ebb84303 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-elision-next-err.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision-next-err.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Rest element following elision elements (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. + +---*/ +var iter = (function*() { throw new Test262Error(); })(); + +assert.throws(Test262Error, function() { + for (let [, ...x] of [iter]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..56ec257ce5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-elision.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element following elision elements (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. +---*/ +var values = [1, 2, 3, 4, 5]; + +var iterCount = 0; + +for (let [ , , ...x] of [values]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 3); + assert.sameValue(x[1], 4); + assert.sameValue(x[2], 5); + assert.notSameValue(x, values); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..c3c190675e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-exhausted.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-exhausted.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: RestElement applied to an exhausted iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + b. If iteratorRecord.[[done]] is true, then + i. If environment is undefined, return PutValue(lhs, A). + ii. Return InitializeReferencedBinding(lhs, A). + +---*/ + +var iterCount = 0; + +for (let [, , ...x] of [[1, 2]]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-iter-close.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-iter-close.js new file mode 100644 index 0000000000..ca6f9b1edd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-iter-close.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-close.case +// - src/dstr-binding/iter-close/for-of-let.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (let [...x] of [iter]) { + return; + } +} + +fn(); + +assert.sameValue(iter.next().done, true, 'iteration occurred as expected'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..da0f4ff5ef --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-iter-step-err.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-step-err.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + a. If iteratorRecord.[[done]] is false, + i. Let next be IteratorStep(iteratorRecord.[[iterator]]). + ii. If next is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(next). + +---*/ +var first = 0; +var second = 0; +var iter = function*() { + first += 1; + throw new Test262Error(); + second += 1; +}(); + +assert.throws(Test262Error, function() { + for (let [...x] of [iter]) { + return; + } +}); + +iter.next(); +assert.sameValue(first, 1); +assert.sameValue(second, 0, 'Iterator is closed following abrupt completion.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..e61fdcb66a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id-iter-val-err.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-val-err.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + c. Let nextValue be IteratorValue(next). + d. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to + true. + e. ReturnIfAbrupt(nextValue). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +assert.throws(Test262Error, function() { + for (let [...x] of [iter]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id.js new file mode 100644 index 0000000000..ef1bc67f10 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-id.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Lone rest element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + [...] 3. Let A be ArrayCreate(0). [...] 5. Repeat + [...] + f. Let status be CreateDataProperty(A, ToString (n), nextValue). + [...] +---*/ +var values = [1, 2, 3]; + +var iterCount = 0; + +for (let [...x] of [values]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..dbd5d76f0f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-init-ary.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-ary.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element (nested array pattern) does not support initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (let [...[ x ] = []] of [[]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..c4cdff33ae --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-init-id.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-id.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element (identifier) does not support initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (let [...x = []] of [[]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..1ab019d9ae --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-init-obj.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-obj.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element (nested object pattern) does not support initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (let [...{ x } = []] of [[]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..5e254fd3fb --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-not-final-ary.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-ary.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (let [...[x], y] of [[1, 2, 3]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..81967123ec --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-not-final-id.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-id.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element (identifier) may not be followed by any element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (let [...x, y] of [[1, 2, 3]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..b744247852 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-not-final-obj.js @@ -0,0 +1,58 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-obj.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (let [...{ x }, y] of [[1, 2, 3]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..982ddef1a4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-obj-id.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-id.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element containing an object binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ + +var iterCount = 0; + +for (let [...{ length }] of [[1, 2, 3]]) { + assert.sameValue(length, 3); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..20a9e2c9f4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-ary-ptrn-rest-obj-prop-id.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-prop-id.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest element containing an object binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +let length = "outer"; + +var iterCount = 0; + +for (let [...{ 0: v, 1: w, 2: x, 3: y, length: z }] of [[7, 8, 9]]) { + assert.sameValue(v, 7); + assert.sameValue(w, 8); + assert.sameValue(x, 9); + assert.sameValue(y, undefined); + assert.sameValue(z, 3); + + assert.sameValue(length, "outer", "the length prop is not set as a binding name"); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-init-null.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-init-null.js new file mode 100644 index 0000000000..8a8a72b0d2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-init-null.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-null.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (let {} of [null]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-init-undefined.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-init-undefined.js new file mode 100644 index 0000000000..748dede704 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-init-undefined.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-undefined.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (let {} of [undefined]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-empty.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-empty.js new file mode 100644 index 0000000000..85c41d7cc9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-empty.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-empty.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: No property access occurs for an "empty" object binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ +var accessCount = 0; +var obj = Object.defineProperty({}, 'attr', { + get: function() { + accessCount += 1; + } +}); + +var iterCount = 0; + +for (let {} of [obj]) { + assert.sameValue(accessCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..fb046302fc --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-get-value-err.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-get-value-err.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. Let v be GetV(value, propertyName). + 5. ReturnIfAbrupt(v). +---*/ +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + for (let { poisoned } of [poisonedProperty]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..d638a5f92f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-arrow.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-arrow.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (let { arrow = () => {} } of [{}]) { + assert.sameValue(arrow.name, 'arrow'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..c801ccd4be --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-class.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-class.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (let { cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } } of [{}]) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..5261c6c37c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-cover.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-cover.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (let { cover = (function () {}), xCover = (0, function() {}) } of [{}]) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..37ffb46c55 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-fn.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-fn.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (let { fn = function () {}, xFn = function x() {} } of [{}]) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..f2e81e9467 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-fn-name-gen.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-gen.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). + +---*/ + +var iterCount = 0; + +for (let { gen = function* () {}, xGen = function* x() {} } of [{}]) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..3d7a799f73 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-skipped.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-skipped.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var iterCount = 0; + +for (let { w = counter(), x = counter(), y = counter(), z = counter() } of [{ w: null, x: 0, y: false, z: '' }]) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..879f9cb43a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-throws.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-throws.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Error thrown when evaluating the initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (let { x = thrower() } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..a58d6660e3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-init-unresolvable.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-unresolvable.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Destructuring initializer is an unresolvable reference (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + for (let { x = unresolvableReference } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..08c770b922 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-id-trailing-comma.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-trailing-comma.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (let { x, } of [{ x: 23 }]) { + assert.sameValue(x, 23); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-init-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-init-err.js new file mode 100644 index 0000000000..88325bbe6a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-init-err.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteration-statements +description: > + Initializer is not allowed in head's ForDeclaration position. +info: | + IterationStatement: + for (ForDeclaration of AssignmentExpression) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +for (let {x} = 1 of []) {} diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-list-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-list-err.js new file mode 100644 index 0000000000..4062d8cba0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-list-err.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-list-err.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPropertyList : BindingPropertyList , BindingProperty + + 1. Let status be the result of performing BindingInitialization for + BindingPropertyList using value and environment as arguments. + 2. ReturnIfAbrupt(status). +---*/ +var initCount = 0; +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (let { a, b = thrower(), c = ++initCount } of [{}]) { + return; + } +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..70e5fb41e4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary-init.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-init.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (let { w: [x, y, z] = [4, 5, 6] } of [{}]) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..2e591bda71 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary-trailing-comma.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-trailing-comma.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (let { x: [y], } of [{ x: [45] }]) { + assert.sameValue(y,45); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..6598982c47 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary-value-null.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-value-null.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + for (let { w: [x, y, z] = [4, 5, 6] } of [{ w: null }]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..d92b0bf095 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-ary.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (let { w: [x, y, z] = [4, 5, 6] } of [{ w: [7, undefined, ] }]) { + assert.sameValue(x, 7); + assert.sameValue(y, undefined); + assert.sameValue(z, undefined); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..d8af00ee04 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-eval-err.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-eval-err.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Evaluation of property name returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingProperty : PropertyName : BindingElement + + 1. Let P be the result of evaluating PropertyName + 2. ReturnIfAbrupt(P). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (let { [thrower()]: x } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..377f712820 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-get-value-err.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-get-value-err.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. Let v be GetV(value, propertyName). + 2. ReturnIfAbrupt(v). +---*/ +var initEvalCount = 0; +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + for (let { poisoned: x = ++initEvalCount } of [poisonedProperty]) { + return; + } +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..3b0aa20fa9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init-skipped.js @@ -0,0 +1,78 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-skipped.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var iterCount = 0; + +for (let { s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } of [{ s: null, u: 0, w: false, y: '' }]) { + assert.sameValue(t, null); + assert.sameValue(v, 0); + assert.sameValue(x, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + assert.throws(ReferenceError, function() { + s; + }); + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..252bc11ebb --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init-throws.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-throws.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Error thrown when evaluating the initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (let { x: y = thrower() } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..beacb6eb2c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init-unresolvable.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-unresolvable.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Destructuring initializer is an unresolvable reference (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + for (let { x: y = unresolvableReference } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..362f8a7b4a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-init.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Binding as specified via property name, identifier, and initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let { x: y = 33 } of [{ }]) { + assert.sameValue(y, 33); + assert.throws(ReferenceError, function() { + x; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..153a9df8a9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id-trailing-comma.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-trailing-comma.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (let { x: y, } of [{ x: 23 }]) { + assert.sameValue(y, 23); + + assert.throws(ReferenceError, function() { + x; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id.js new file mode 100644 index 0000000000..6ce9783e5b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-id.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Binding as specified via property name and identifier (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let { x: y } of [{ x: 23 }]) { + assert.sameValue(y, 23); + assert.throws(ReferenceError, function() { + x; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..07a09d319a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj-init.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-init.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (let { w: { x, y, z } = { x: 4, y: 5, z: 6 } } of [{ w: undefined }]) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..fb956c7135 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj-value-null.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-null.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + for (let { w: { x, y, z } = { x: 4, y: 5, z: 6 } } of [{ w: null }]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..51dbb5df4e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj-value-undef.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-undef.case +// - src/dstr-binding/error/for-of-let.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + for (let { w: { x, y, z } = undefined } of [{ }]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..ab47647d69 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-prop-obj.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (let { w: { x, y, z } = { x: 4, y: 5, z: 6 } } of [{ w: { x: undefined, z: 7 } }]) { + assert.sameValue(x, undefined); + assert.sameValue(y, undefined); + assert.sameValue(z, 7); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-rest-getter.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..405a223d0f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-rest-getter.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-getter.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ +var count = 0; + +var iterCount = 0; + +for (let {...x} of [{ get v() { count++; return 2; } }]) { + assert.sameValue(count, 1); + + verifyProperty(x, "v", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..2b87b2cbef --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-rest-skip-non-enumerable.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-skip-non-enumerable.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest object doesn't contain non-enumerable properties (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); + +var iterCount = 0; + +for (let {...rest} of [o]) { + assert.sameValue(rest.x, undefined); + + verifyProperty(rest, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(rest, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 4 + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..c9f408b6f4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/let-obj-ptrn-rest-val-obj.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-val-obj.case +// - src/dstr-binding/default/for-of-let.template +/*--- +description: Rest object contains just unextracted data (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ + +var iterCount = 0; + +for (let {a, b, ...rest} of [{x: 1, y: 2, a: 5, b: 3}]) { + assert.sameValue(rest.a, undefined); + assert.sameValue(rest.b, undefined); + + verifyProperty(rest, "x", { + enumerable: true, + writable: true, + configurable: true, + value: 1 + }); + + verifyProperty(rest, "y", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-bool.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-bool.js new file mode 100644 index 0000000000..cb9927622f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-bool.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-empty-bool.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: An ObjectAssignmentPattern without an AssignmentPropertyList requires an object-coercible value (boolean value) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +for ({} of [false]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-null.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-null.js new file mode 100644 index 0000000000..361d985be5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-null.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-empty-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ObjectAssignmentPattern without an AssignmentPropertyList requires an object-coercible value (null value) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(TypeError, function() { + for ({} of [null]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-num.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-num.js new file mode 100644 index 0000000000..4545eb9388 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-num.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-empty-num.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: An ObjectAssignmentPattern without an AssignmentPropertyList requires an object-coercible value (number value) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +for ({} of [0]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-obj.js new file mode 100644 index 0000000000..f6276f0852 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-obj.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-empty-obj.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: An ObjectAssignmentPattern without an AssignmentPropertyList requires an object-coercible value (object value) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +for ({} of [{}]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-string.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-string.js new file mode 100644 index 0000000000..14d2b37c1d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-string.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-empty-string.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: An ObjectAssignmentPattern without an AssignmentPropertyList requires an object-coercible value (string value) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +for ({} of ['']) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-symbol.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-symbol.js new file mode 100644 index 0000000000..61755aba3f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-symbol.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-empty-symbol.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: An ObjectAssignmentPattern without an AssignmentPropertyList requires an object-coercible value (symbol value) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var s = Symbol(); + +var counter = 0; + +for ({} of [s]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-undef.js new file mode 100644 index 0000000000..890974faf5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-empty-undef.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-empty-undef.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: An ObjectAssignmentPattern without an AssignmentPropertyList requires an object-coercible value (undefined value) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(TypeError, function() { + for ({} of [undefined]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-first.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-first.js new file mode 100644 index 0000000000..70f808185e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-first.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-identifier-resolution-first.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget (first of many) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; +var y; + +var counter = 0; + +for ({ x, y } of [{ x: 3 }]) { + assert.sameValue(x, 3); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-last.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-last.js new file mode 100644 index 0000000000..085041b37d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-last.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-identifier-resolution-last.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget (last of many) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; +var w; + +var counter = 0; + +for ({ w, x } of [{ x: 4 }]) { + assert.sameValue(x, 4); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-lone.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-lone.js new file mode 100644 index 0000000000..61fc0d65fa --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-lone.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-identifier-resolution-lone.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget (lone identifier) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; + +var counter = 0; + +for ({ x, } of [{ x: 2 }]) { + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-middle.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-middle.js new file mode 100644 index 0000000000..febd089b8b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-middle.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-identifier-resolution-middle.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget (within many) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; +var w, y; + +var counter = 0; + +for ({ w, x, y } of [{ x: 5 }]) { + assert.sameValue(x, 5); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-trlng.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-trlng.js new file mode 100644 index 0000000000..02e6c6779f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-resolution-trlng.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-identifier-resolution-trlng.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget (lone identifier with trailing comma) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; + +var counter = 0; + +for ({ x } of [{ x: 1 }]) { + assert.sameValue(x, 1); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-yield-expr.js new file mode 100644 index 0000000000..84ed8fd2c3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-yield-expr.js @@ -0,0 +1,36 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-identifier-yield-expr.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: yield is not a valid IdentifierReference in an AssignmentProperty within generator function bodies. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated, noStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); +(function*() { + +for ({ yield } of [{}]) ; + +}); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..c67a9cc2d6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-yield-ident-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-identifier-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: yield is not a valid IdentifierReference in an AssignmentProperty within strict mode code. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ({ yield } of [{}]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-yield-ident-valid.js new file mode 100644 index 0000000000..6cc660d6b4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-identifier-yield-ident-valid.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-identifier-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: yield is a valid IdentifierReference in an AssignmentProperty outside of strict mode and generator functions. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield; + +var counter = 0; + +for ({ yield } of [{ yield: 3 }]) { + assert.sameValue(yield, 3); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-missing.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-missing.js new file mode 100644 index 0000000000..d284a52c94 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-missing.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-assignment-missing.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the Initializer is present and v is undefined, the Initializer should be evaluated and the result assigned to the target reference (no corresponding property defined). (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ({ x = 1 } of [{}]) { + assert.sameValue(x, 1); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-null.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-null.js new file mode 100644 index 0000000000..176c1aef23 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-null.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-assignment-null.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the Initializer is present and v is undefined, the Initializer should be evaluated and the result assigned to the target reference (null property value defined). (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ({ x = 1 } of [{ x: null }]) { + assert.sameValue(x, null); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-truthy.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-truthy.js new file mode 100644 index 0000000000..68a032b78c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-truthy.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-assignment-truthy.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the Initializer is present and v is undefined, the Initializer should be evaluated and the result assigned to the target reference (truthy property value defined). (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ({ x = 1 } of [{ x: 2 }]) { + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-undef.js new file mode 100644 index 0000000000..8e139d9f14 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-assignment-undef.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-assignment-undef.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the Initializer is present and v is undefined, the Initializer should be evaluated and the result assigned to the target reference ("undefined" property value defined). (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ({ x = 1 } of [{ x: undefined }]) { + assert.sameValue(x, 1); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-evaluation.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-evaluation.js new file mode 100644 index 0000000000..765faed324 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-evaluation.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-evaluation.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The Initializer should only be evaluated if v is undefined. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var flag1 = false; +var flag2 = false; +var x, y; + +var counter = 0; + +for ({ x = flag1 = true, y = flag2 = true } of [{ y: 1 }]) { + assert.sameValue(flag1, true); + assert.sameValue(flag2, false); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..f6a3c37add --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-arrow.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-fn-name-arrow.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (ArrowFunction) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentProperty : IdentifierReference Initializeropt + [...] 6. If Initializeropt is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, P). + +---*/ +var arrow; + +var counter = 0; + +for ({ arrow = () => {} } of [{}]) { + verifyProperty(arrow, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'arrow' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-class.js new file mode 100644 index 0000000000..e9b35c5bb0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-class.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-fn-name-class.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (ClassExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [class, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentProperty : IdentifierReference Initializeropt + [...] 6. If Initializeropt is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, P). + +---*/ +var xCls, cls, xCls2; + +var counter = 0; + +for ({ xCls = class x {}, cls = class {}, xCls2 = class { static name() {} } } of [{}]) { + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + + verifyProperty(cls, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'cls' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-cover.js new file mode 100644 index 0000000000..d79cbdf0f7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-cover.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-fn-name-cover.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (CoverParenthesizedExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentProperty : IdentifierReference Initializeropt + [...] 6. If Initializeropt is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, P). + +---*/ +var xCover, cover; + +var counter = 0; + +for ({ xCover = (0, function() {}), cover = (function() {}) } of [{}]) { + assert.notSameValue(xCover.name, 'xCover'); + + verifyProperty(cover, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'cover' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-fn.js new file mode 100644 index 0000000000..a9eccefe4d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-fn.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-fn-name-fn.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (FunctionExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentProperty : IdentifierReference Initializeropt + [...] 6. If Initializeropt is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, P). + +---*/ +var xFn, fn; + +var counter = 0; + +for ({ xFn = function x() {}, fn = function() {} } of [{}]) { + assert.notSameValue(xFn.name, 'xFn'); + + verifyProperty(fn, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'fn' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-gen.js new file mode 100644 index 0000000000..e8be796941 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-fn-name-gen.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-fn-name-gen.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (GeneratorExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentProperty : IdentifierReference Initializeropt + [...] 6. If Initializeropt is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, P). + +---*/ +var xGen, gen; + +var counter = 0; + +for ({ xGen = function* x() {}, gen = function*() {} } of [{}]) { + assert.notSameValue(xGen.name, 'xGen'); + + verifyProperty(gen, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'gen' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-in.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-in.js new file mode 100644 index 0000000000..7ffb5e146e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-in.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-in.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The Initializer in an AssignmentProperty may be an `in` expression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var prop; + +var counter = 0; + +for ({ prop = 'x' in {} } of [{}]) { + assert.sameValue(prop, false); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-let.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-let.js new file mode 100644 index 0000000000..d520041444 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-let.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-let.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Value retrieval of Initializer obeys `let` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [let, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(ReferenceError, function() { + for ({ x = y } of [{}]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +let y; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-order.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-order.js new file mode 100644 index 0000000000..cd1a3da4c0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-order.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-order.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Initializer values should be assigned in left-to-right order. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = 0; +var a, b; + +var counter = 0; + +for ({ a = x += 1, b = x *= 2 } of [{}]) { + assert.sameValue(a, 1); + assert.sameValue(b, 2); + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-simple-no-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-simple-no-strict.js new file mode 100644 index 0000000000..fe5ba9b801 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-simple-no-strict.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-simple-no-strict.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var eval, arguments; + +var counter = 0; + +for ({ eval = 3, arguments = 4 } of [{}]) { + assert.sameValue(eval, 3); + assert.sameValue(arguments, 4); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-simple-strict-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-simple-strict-strict.js new file mode 100644 index 0000000000..91a89fe260 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-simple-strict-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-simple-strict.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if IsValidSimpleAssignmentTarget of IdentifierReference is false. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ({ eval = 0 } of [{}]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-yield-expr.js new file mode 100644 index 0000000000..109aac43d4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-yield-expr.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of an AssignmentProperty and within a generator function body, it should behave as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var iterationResult, x, iter; + +iter = (function*() { + +var counter = 0; + +for ({ x = yield } of [{}]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +}()); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x, undefined); + +iterationResult = iter.next(3); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..b6d735805f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-yield-ident-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of an AssignmentProperty and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ({ x = yield } of [{}]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-yield-ident-valid.js new file mode 100644 index 0000000000..86e4ac341c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-init-yield-ident-valid.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-init-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of an AssignmentProperty and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 3; +var x; + +var counter = 0; + +for ({ x = yield } of [{}]) { + assert.sameValue(x, 3); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-const.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-const.js new file mode 100644 index 0000000000..da31cbd7e1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-const.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-put-const.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: The assignment target should obey `const` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [const, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +const c = null; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({ c } of [{ c: 1 }]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-let.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-let.js new file mode 100644 index 0000000000..f5aad869cf --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-let.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-put-let.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: The assignment target should obey `let` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [let, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(ReferenceError, function() { + for ({ x } of [{}]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +let x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-unresolvable-no-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-unresolvable-no-strict.js new file mode 100644 index 0000000000..e7e0f4f855 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-unresolvable-no-strict.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-put-unresolvable-no-strict.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Outside of strict mode, if the the assignment target is an unresolvable reference, a new `var` binding should be created in the environment record. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +{ + +var counter = 0; + +for ({ unresolvable } of [{}]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +assert.sameValue(unresolvable, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-unresolvable-strict-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-unresolvable-strict-strict.js new file mode 100644 index 0000000000..3a29252147 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-put-unresolvable-strict-strict.js @@ -0,0 +1,40 @@ +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-put-unresolvable-strict.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: In strict mode, if the the assignment target is an unresolvable reference, a ReferenceError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(ReferenceError, function() { + for ({ unresolvable } of [{}]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-simple-no-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-simple-no-strict.js new file mode 100644 index 0000000000..3f70f5f919 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-simple-no-strict.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-simple-no-strict.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var eval, arguments; + +var counter = 0; + +for ({ eval, arguments } of [{ eval: 1, arguments: 2 }]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +assert.sameValue(eval, 1); +assert.sameValue(arguments, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-id-simple-strict-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-simple-strict-strict.js new file mode 100644 index 0000000000..7b10af83c5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-id-simple-strict-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-id-simple-strict.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if IsValidSimpleAssignmentTarget of IdentifierReference is false. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ({ eval } of [{}]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-missing.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-missing.js new file mode 100644 index 0000000000..2b3e8553d2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-missing.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-assignment-missing.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the Initializer is present and v is undefined, the Initializer should be evaluated and the result assigned to the target reference (non-existent property) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ({ y: x = 1 } of [{}]) { + assert.sameValue(x, 1); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-null.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-null.js new file mode 100644 index 0000000000..0bffa7dd8c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-null.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-assignment-null.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the Initializer is present and v is not undefined, the Initializer should be evaluated and the result assigned to the target reference (null value) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ({ y: x = 1 } of [{ y: null }]) { + assert.sameValue(x, null); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-truthy.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-truthy.js new file mode 100644 index 0000000000..e09ab3a74a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-truthy.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-assignment-truthy.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the Initializer is present and v is not undefined, the Initializer should be evaluated and the result assigned to the target reference (truthy value) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ({ y: x = 1 } of [{ y: 2 }]) { + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-undef.js new file mode 100644 index 0000000000..a941f7a87a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-assignment-undef.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-assignment-undef.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the Initializer is present and v is undefined, the Initializer should be evaluated and the result assigned to the target reference (undefined value) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ({ y: x = 1 } of [{ y: undefined }]) { + assert.sameValue(x, 1); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-evaluation.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-evaluation.js new file mode 100644 index 0000000000..64720d42c3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-evaluation.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-evaluation.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The Initializer should only be evaluated if v is undefined. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var flag1 = false; +var flag2 = false; +var x, y; + +var counter = 0; + +for ({ x: x = flag1 = true, y: y = flag2 = true } of [{ y: 1 }]) { + assert.sameValue(x, true, 'value of `x`'); + assert.sameValue(flag1, true, 'value of `flag1`'); + assert.sameValue(y, 1, 'value of `y`'); + assert.sameValue(flag2, false, 'value of `flag2`'); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-arrow.js new file mode 100644 index 0000000000..37d3bd6c71 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-arrow.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-fn-name-arrow.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (ArrowFunction) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and v is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(rhsValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(rhsValue, + GetReferencedName(lref)). + +---*/ +var arrow; + +var counter = 0; + +for ({ x: arrow = () => {} } of [{}]) { + verifyProperty(arrow, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'arrow' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-class.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-class.js new file mode 100644 index 0000000000..a0c138ce84 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-class.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-fn-name-class.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (ClassExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [class, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and v is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(rhsValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(rhsValue, + GetReferencedName(lref)). + +---*/ +var xCls, cls, xCls2; + +var counter = 0; + +for ({ x: xCls = class x {}, x: cls = class {}, x: xCls2 = class { static name() {} } } of [{}]) { + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + + verifyProperty(cls, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'cls' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-cover.js new file mode 100644 index 0000000000..a2195daf85 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-cover.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-fn-name-cover.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (CoverParenthesizedExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and v is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(rhsValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(rhsValue, + GetReferencedName(lref)). + +---*/ +var xCover, cover; + +var counter = 0; + +for ({ x: xCover = (0, function() {}), x: cover = (function() {}) } of [{}]) { + assert.notSameValue(xCover.name, 'xCover'); + + verifyProperty(cover, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'cover' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-fn.js new file mode 100644 index 0000000000..6b4e905ab4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-fn.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-fn-name-fn.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (FunctionExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and v is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(rhsValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(rhsValue, + GetReferencedName(lref)). + +---*/ +var xFn, fn; + +var counter = 0; + +for ({ x: xFn = function x() {}, x: fn = function() {} } of [{}]) { + assert.notSameValue(xFn.name, 'xFn'); + + verifyProperty(fn, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'fn' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-gen.js new file mode 100644 index 0000000000..a96e87f2d3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-fn-name-gen.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-fn-name-gen.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Assignment of function `name` attribute (GeneratorExpression) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and v is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(rhsValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(rhsValue, + GetReferencedName(lref)). + +---*/ +var xGen, gen; + +var counter = 0; + +for ({ x: xGen = function* x() {}, x: gen = function*() {} } of [{}]) { + assert.notSameValue(xGen.name, 'xGen'); + + verifyProperty(gen, 'name', { + enumerable: false, + writable: false, + configurable: true, + value: 'gen' + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-in.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-in.js new file mode 100644 index 0000000000..ded1a2742b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-in.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-in.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The Initializer in an AssignmentElement may be an `in` expression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var prop; + +var counter = 0; + +for ({ x: prop = 'x' in {} } of [{}]) { + assert.sameValue(prop, false); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-let.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-let.js new file mode 100644 index 0000000000..61d75dfe7e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-let.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-let.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Value retrieval of Initializer obeys `let` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [let, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(ReferenceError, function() { + for ({ x: x = y } of [{}]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +let y; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-yield-expr.js new file mode 100644 index 0000000000..e61d64d533 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-yield-expr.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of an AssignmentElement and within a generator function body, it should behave as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var iterationResult, iter, x; +iter = (function*() { + +var counter = 0; + +for ({ x: x = yield } of [{}]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +}()); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x, undefined); + +iterationResult = iter.next(86); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x, 86); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..a0488ae63a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-yield-ident-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of an AssignmentElement and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ({ x: x = yield } of [{}]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-yield-ident-valid.js new file mode 100644 index 0000000000..460952544f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-init-yield-ident-valid.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-init-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of an AssignmentElement and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 4; +var x; + +var counter = 0; + +for ({ x: x = yield } of [{}]) { + assert.sameValue(x, 4); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-memberexpr-optchain-prop-ref-init.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-memberexpr-optchain-prop-ref-init.js new file mode 100644 index 0000000000..92718cc184 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-memberexpr-optchain-prop-ref-init.js @@ -0,0 +1,66 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-target-memberexpr-optchain-prop-ref-init.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if LeftHandSideExpression of an DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple Using Object (MemberExpression OptionalChain .IdentifierName Initializer) (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [optional-chaining, destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + Syntax + + AssignmentElement : DestructuringAssignmentTarget Initializer_opt + DestructuringAssignmentTarget : LeftHandSideExpression + + Static Semantics: Early Errors + + OptionalExpression: + MemberExpression OptionalChain + CallExpression OptionalChain + OptionalExpression OptionalChain + + OptionalChain: + ?. [ Expression ] + ?. IdentifierName + ?. Arguments + ?. TemplateLiteral + OptionalChain [ Expression ] + OptionalChain .IdentifierName + OptionalChain Arguments + OptionalChain TemplateLiteral + + DestructuringAssignmentTarget : LeftHandSideExpression + + - It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is not true. + + Static Semantics: IsValidSimpleAssignmentTarget + + LeftHandSideExpression : OptionalExpression + 1. Return false. + +---*/ +$DONOTEVALUATE(); +var y = {}; + +for ({ x: y?.z = 42 } of [{ x: 23 }]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-optchain-prop-ref-init.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-optchain-prop-ref-init.js new file mode 100644 index 0000000000..630f73e9b0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-optchain-prop-ref-init.js @@ -0,0 +1,69 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-target-obj-literal-optchain-prop-ref-init.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if LeftHandSideExpression of an DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple Using Object (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [optional-chaining, destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + Syntax + + AssignmentElement : DestructuringAssignmentTarget Initializer_opt + DestructuringAssignmentTarget : LeftHandSideExpression + + Static Semantics: Early Errors + + OptionalExpression: + MemberExpression OptionalChain + CallExpression OptionalChain + OptionalExpression OptionalChain + + OptionalChain: + ?. [ Expression ] + ?. IdentifierName + ?. Arguments + ?. TemplateLiteral + OptionalChain [ Expression ] + OptionalChain .IdentifierName + OptionalChain Arguments + OptionalChain TemplateLiteral + + DestructuringAssignmentTarget : LeftHandSideExpression + + - It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is not true. + + Static Semantics: IsValidSimpleAssignmentTarget + + LeftHandSideExpression : OptionalExpression + 1. Return false. + +---*/ +$DONOTEVALUATE(); + +for ({ x: { + set y(val) { + throw new Test262Error('The property should not be accessed.'); + } +}?.y = 42} of [{x: 42}]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-prop-ref-init-active.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-prop-ref-init-active.js new file mode 100644 index 0000000000..69913adcac --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-prop-ref-init-active.js @@ -0,0 +1,87 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-target-obj-literal-prop-ref-init-active.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The DestructuringAssignmentTarget of an AssignmentElement can extend to LHSExpressions if it is neither an ObjectLiteral nor an ArrayLiteral and its AssignmentTargetTyp is simple. Using MemberExpression (ObjLiteral + identifier) with active initializer. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + Syntax + + AssignmentPattern : ObjectAssignmentPattern + ObjectAssignmentPattern : { AssignmentPropertyList } + AssignmentPropertyList : AssignmentProperty + AssignmentProperty : PropertyName : AssignmentElement + AssignmentElement : DestructuringAssignmentTarget Initializer_opt + DestructuringAssignmentTarget : LeftHandSideExpression + + Static Semantics: Early Errors + + DestructuringAssignmentTarget : LeftHandSideExpression + + - It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if LeftHandSideExpression is not covering an AssignmentPattern. + - It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple. + + Runtime Semantics: DestructuringAssignmentEvaluation + ObjectAssignmentPattern : { AssignmentPropertyList } + + 1. Perform ? RequireObjectCoercible(value). + 2. Perform ? PropertyDestructuringAssignmentEvaluation for AssignmentPropertyList using value as the argument. + 3. Return NormalCompletion(empty). + + Runtime Semantics: PropertyDestructuringAssignmentEvaluation + + AssignmentProperty : PropertyName : AssignmentElement + + 1. Let name be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(name). + 3. Perform ? KeyedDestructuringAssignmentEvaluation of AssignmentElement with value and name as the arguments. + 4. Return a new List containing name. + + Runtime Semantics: KeyedDestructuringAssignmentEvaluation + + AssignmentElement : DestructuringAssignmentTarget Initializer + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + ... + +---*/ +var setValue; + +var counter = 0; + +for ({ x: { + get y() { + throw new Test262Error('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}.y = 42} of [{x: undefined}]) { + assert.sameValue(setValue, 42); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-prop-ref-init.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-prop-ref-init.js new file mode 100644 index 0000000000..f1b3e5c56f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-prop-ref-init.js @@ -0,0 +1,87 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-target-obj-literal-prop-ref-init.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The DestructuringAssignmentTarget of an AssignmentElement can extend to LHSExpressions if it is neither an ObjectLiteral nor an ArrayLiteral and its AssignmentTargetTyp is simple. Using MemberExpression (ObjLiteral + identifier) with initializer. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + Syntax + + AssignmentPattern : ObjectAssignmentPattern + ObjectAssignmentPattern : { AssignmentPropertyList } + AssignmentPropertyList : AssignmentProperty + AssignmentProperty : PropertyName : AssignmentElement + AssignmentElement : DestructuringAssignmentTarget Initializer_opt + DestructuringAssignmentTarget : LeftHandSideExpression + + Static Semantics: Early Errors + + DestructuringAssignmentTarget : LeftHandSideExpression + + - It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if LeftHandSideExpression is not covering an AssignmentPattern. + - It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple. + + Runtime Semantics: DestructuringAssignmentEvaluation + ObjectAssignmentPattern : { AssignmentPropertyList } + + 1. Perform ? RequireObjectCoercible(value). + 2. Perform ? PropertyDestructuringAssignmentEvaluation for AssignmentPropertyList using value as the argument. + 3. Return NormalCompletion(empty). + + Runtime Semantics: PropertyDestructuringAssignmentEvaluation + + AssignmentProperty : PropertyName : AssignmentElement + + 1. Let name be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(name). + 3. Perform ? KeyedDestructuringAssignmentEvaluation of AssignmentElement with value and name as the arguments. + 4. Return a new List containing name. + + Runtime Semantics: KeyedDestructuringAssignmentEvaluation + + AssignmentElement : DestructuringAssignmentTarget Initializer + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + ... + +---*/ +var setValue; + +var counter = 0; + +for ({ x: { + get y() { + throw new Test262Error('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}.y = 42} of [{x: 23}]) { + assert.sameValue(setValue, 23); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-prop-ref.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-prop-ref.js new file mode 100644 index 0000000000..13851a5ef7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-obj-literal-prop-ref.js @@ -0,0 +1,87 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-target-obj-literal-prop-ref.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The DestructuringAssignmentTarget of an AssignmentElement can extend to LHSExpressions if it is neither an ObjectLiteral nor an ArrayLiteral and its AssignmentTargetTyp is simple. Using MemberExpression (ObjLiteral + identifier). (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + Syntax + + AssignmentPattern : ObjectAssignmentPattern + ObjectAssignmentPattern : { AssignmentPropertyList } + AssignmentPropertyList : AssignmentProperty + AssignmentProperty : PropertyName : AssignmentElement + AssignmentElement : DestructuringAssignmentTarget Initializer_opt + DestructuringAssignmentTarget : LeftHandSideExpression + + Static Semantics: Early Errors + + DestructuringAssignmentTarget : LeftHandSideExpression + + - It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if LeftHandSideExpression is not covering an AssignmentPattern. + - It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and AssignmentTargetType(LeftHandSideExpression) is not simple. + + Runtime Semantics: DestructuringAssignmentEvaluation + ObjectAssignmentPattern : { AssignmentPropertyList } + + 1. Perform ? RequireObjectCoercible(value). + 2. Perform ? PropertyDestructuringAssignmentEvaluation for AssignmentPropertyList using value as the argument. + 3. Return NormalCompletion(empty). + + Runtime Semantics: PropertyDestructuringAssignmentEvaluation + + AssignmentProperty : PropertyName : AssignmentElement + + 1. Let name be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(name). + 3. Perform ? KeyedDestructuringAssignmentEvaluation of AssignmentElement with value and name as the arguments. + 4. Return a new List containing name. + + Runtime Semantics: KeyedDestructuringAssignmentEvaluation + + AssignmentElement : DestructuringAssignmentTarget Initializer + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + ... + +---*/ +var setValue; + +var counter = 0; + +for ({ x: { + get y() { + throw new Test262Error('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}.y} of [{x: 23}]) { + assert.sameValue(setValue, 23); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-yield-expr.js new file mode 100644 index 0000000000..26f4cfcae5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-yield-expr.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-target-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of an AssignmentElement and within a generator function body, it should behave as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = {}; +var iterationResult, iter; + +iter = (function*() { + +var counter = 0; + +for ({ x: x[yield] } of [{ x: 23 }]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +}()); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x.prop, undefined); + +iterationResult = iter.next('prop'); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x.prop, 23); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..62023d02c8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-yield-ident-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-target-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of an AssignmentElement and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ({ x: x[yield] } of [{}]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-yield-ident-valid.js new file mode 100644 index 0000000000..8b8c4cf229 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-elem-target-yield-ident-valid.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-elem-target-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of an AssignmentElement and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 'prop'; +var x = {}; + +var counter = 0; + +for ({ x: x[yield] } of [{ x: 23 }]) { + assert.sameValue(x.prop, 23); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-first.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-first.js new file mode 100644 index 0000000000..4fa0e5c937 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-first.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-identifier-resolution-first.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget (first of many). (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; +var y; + +var counter = 0; + +for ({ a: x, y } of [{ a: 3 }]) { + assert.sameValue(x, 3); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-last.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-last.js new file mode 100644 index 0000000000..0b61fd7353 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-last.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-identifier-resolution-last.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget (last of many). (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; +var w; + +var counter = 0; + +for ({ w, a: x } of [{ a: 4 }]) { + assert.sameValue(x, 4); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-lone.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-lone.js new file mode 100644 index 0000000000..e1f99e8b72 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-lone.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-identifier-resolution-lone.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget (lone element). (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; + +var counter = 0; + +for ({ a: x } of [{ a: 1 }]) { + assert.sameValue(x, 1); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-middle.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-middle.js new file mode 100644 index 0000000000..e4a03ade77 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-middle.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-identifier-resolution-middle.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget (within many). (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; +var w, y; + +var counter = 0; + +for ({ w, a: x, y } of [{ a: 5 }]) { + assert.sameValue(x, 5); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-trlng.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-trlng.js new file mode 100644 index 0000000000..1033983e67 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-identifier-resolution-trlng.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-identifier-resolution-trlng.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Evaluation of DestructuringAssignmentTarget (lone element with trailing comma). (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = null; + +var counter = 0; + +for ({ a: x, } of [{ a: 2 }]) { + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-name-evaluation-error.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-name-evaluation-error.js new file mode 100644 index 0000000000..ee9a330569 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-name-evaluation-error.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-name-evaluation-error.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Any error raised as a result of evaluating PropertyName should be forwarded to the runtime. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var a, x; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({ [a.b]: x } of [{}]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-name-evaluation.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-name-evaluation.js new file mode 100644 index 0000000000..1a36dd05bf --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-name-evaluation.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-name-evaluation.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: PropertyName of an AssignmentProperty may be a ComputedPropertyName. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x, y, xy; + +var counter = 0; + +for ({ ['x' + 'y']: x } of [{ x: 1, xy: 23, y: 2 }]) { + assert.sameValue(x, 23); + assert.sameValue(y, undefined); + assert.sameValue(xy, undefined); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-invalid.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-invalid.js new file mode 100644 index 0000000000..32772b6af9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-invalid.js @@ -0,0 +1,33 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-array-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if the lexical token sequence matched by LeftHandSideExpression cannot be parsed with no tokens left over using AssignmentPattern as the goal symbol. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ({ x: [(x, y)] } of [{ x: [] }]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-null.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-null.js new file mode 100644 index 0000000000..c303c01c77 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-null.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-array-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the value is `null`, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({ x: [ x ] } of [{ x: null }]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-undefined-own.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-undefined-own.js new file mode 100644 index 0000000000..e2b7cbcef0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-undefined-own.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-array-undefined-own.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the value is `undefined`, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({ x: [ x ] } of [{ x: undefined }]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-undefined.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-undefined.js new file mode 100644 index 0000000000..3e1525fabf --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-undefined.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-array-undefined.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal and the value is not defined, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({ x: [ x ] } of [{}]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-yield-expr.js new file mode 100644 index 0000000000..c3f8ce19d8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-yield-expr.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-array-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment and within a generator function body, it should behave as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var iterationResult, iter, x; + +iter = (function*() { + +var counter = 0; + +for ({ x: [x = yield] } of [{ x: [] }]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +}()); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x, undefined); + +iterationResult = iter.next(24601); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x, 24601); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..bfd72bbcde --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-yield-ident-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-array-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ({ x: [x = yield] } of [{ x: [] }]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-yield-ident-valid.js new file mode 100644 index 0000000000..8649b19af2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array-yield-ident-valid.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-array-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 22; +var x; + +var counter = 0; + +for ({ x: [x = yield] } of [{ x: [] }]) { + assert.sameValue(x, 22); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array.js new file mode 100644 index 0000000000..854f71e280 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-array.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-array.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an array literal, it should be parsed parsed as a DestructuringAssignmentPattern and evaluated as a destructuring assignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var y; + +var counter = 0; + +for ({ x: [y] } of [{ x: [321] }]) { + assert.sameValue(y, 321); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-invalid.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-invalid.js new file mode 100644 index 0000000000..75a901e38c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-invalid.js @@ -0,0 +1,33 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-obj-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if the lexical token sequence matched by LeftHandSideExpression cannot be parsed with no tokens left over using AssignmentPattern as the goal symbol. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ({ x: { get x() {} } } of [{ x: {} }]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-null.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-null.js new file mode 100644 index 0000000000..a22a80241b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-null.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-obj-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object literal and the value is `null`, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({ x: { x } } of [{ x: null }]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-undefined-own.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-undefined-own.js new file mode 100644 index 0000000000..252451eda9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-undefined-own.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-obj-undefined-own.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object literal and the value is `undefined`, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({ x: { x } } of [{ x: undefined }]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-undefined.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-undefined.js new file mode 100644 index 0000000000..050c25a20d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-undefined.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-obj-undefined.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object literal and the value is not defined, a TypeError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({ x: { x } } of [{}]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-yield-expr.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-yield-expr.js new file mode 100644 index 0000000000..ab651a62d9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-yield-expr.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-obj-yield-expr.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment and within a generator function body, it should behave as a YieldExpression. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var iterationResult, iter, x = undefined; + +iter = (function*() { + +var counter = 0; + +for ({ x: { x = yield } } of [{ x: {} }]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +}()); + +iterationResult = iter.next(); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, false); +assert.sameValue(x, undefined); + +iterationResult = iter.next(4); + +assert.sameValue(iterationResult.value, undefined); +assert.sameValue(iterationResult.done, true); +assert.sameValue(x, 4); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-yield-ident-invalid-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-yield-ident-invalid-strict.js new file mode 100644 index 0000000000..34d4925441 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-yield-ident-invalid-strict.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-obj-yield-ident-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); + +for ({ x: { x = yield } } of [{ x: {} }]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-yield-ident-valid.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-yield-ident-valid.js new file mode 100644 index 0000000000..2e777bda32 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj-yield-ident-valid.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-obj-yield-ident-valid.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment and outside of a generator function body, it should behave as an IdentifierReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 2; +var result, x; + +var counter = 0; + +for ({ x: { x = yield } } of [{ x: {} }]) { + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj.js new file mode 100644 index 0000000000..a0bf42f420 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-nested-obj.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-nested-obj.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object literal, it should be parsed as a DestructuringAssignmentPattern and evaluated as a destructuring assignment. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var result, y; + +var counter = 0; + +for ({ x: { y } } of [{ x: { y: 2 } }]) { + assert.sameValue(y, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-const.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-const.js new file mode 100644 index 0000000000..c4df6acda3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-const.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-put-const.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: The assignment target should obey `const` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [const, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +const c = 1; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({ a: c } of [{ a: 2 }]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-let.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-let.js new file mode 100644 index 0000000000..e60d8ec97a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-let.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-put-let.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: The assignment target should obey `let` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [let, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(ReferenceError, function() { + for ({ a: x } of [{}]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +let x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-order.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-order.js new file mode 100644 index 0000000000..771ced57d8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-order.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-put-order.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The AssignmentElements in an AssignmentElementList are evaluated in left- to-right order. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var counter = 0; + +for ({ z: x, a: x } of [{ a: 2, z: 1 }]) { + assert.sameValue(x, 2); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-prop-ref-no-get.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-prop-ref-no-get.js new file mode 100644 index 0000000000..e17cb37070 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-prop-ref-no-get.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-put-prop-ref-no-get.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: If the DestructuringAssignmentTarget of an AssignmentElement is a PropertyReference, it should not be evaluated. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var setValue; +var x = { + get y() { + throw new Test262Error('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}; + +var counter = 0; + +for ({ a: x.y } of [{ a: 23 }]) { + assert.sameValue(setValue, 23); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-prop-ref-user-err.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-prop-ref-user-err.js new file mode 100644 index 0000000000..cc2ae08add --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-prop-ref-user-err.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-put-prop-ref-user-err.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Any error raised as a result of setting the value should be forwarded to the runtime. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = { + set y(val) { + throw new Test262Error(); + } +}; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ({ a: x.y } of [{ a: 23 }]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-prop-ref.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-prop-ref.js new file mode 100644 index 0000000000..346f16d0eb --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-prop-ref.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-put-prop-ref.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: The DestructuringAssignmentTarget of an AssignmentElement may be a PropertyReference. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = {}; + +var counter = 0; + +for ({ xy: x.y } of [{ xy: 4 }]) { + assert.sameValue(x.y, 4); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-unresolvable-no-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-unresolvable-no-strict.js new file mode 100644 index 0000000000..e19b7538f4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-unresolvable-no-strict.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-put-unresolvable-no-strict.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Outside of strict mode, if the the assignment target is an unresolvable reference, a new `var` binding should be created in the environment record. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, noStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +{ + +var counter = 0; + +for ({ x: unresolvable } of [{}]) { + + counter += 1; +} + +assert.sameValue(counter, 1); + +} + +assert.sameValue(unresolvable, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-unresolvable-strict-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-unresolvable-strict-strict.js new file mode 100644 index 0000000000..90991b923c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-prop-put-unresolvable-strict-strict.js @@ -0,0 +1,40 @@ +'use strict'; +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-prop-put-unresolvable-strict.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: In strict mode, if the the assignment target is an unresolvable reference, a ReferenceError should be thrown. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated, onlyStrict] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +assert.throws(ReferenceError, function() { + for ({ x: unresolvable } of [{}]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-computed-property-no-strict.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-computed-property-no-strict.js new file mode 100644 index 0000000000..4aa57feee7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-computed-property-no-strict.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-computed-property-no-strict.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Destructuring field can be a computed property, i.e it can be defined only at runtime. Rest operantion needs to skip these properties as well. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated, noStrict] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var a = "foo"; + +var counter = 0; + +for ({[a]:b, ...rest} of [{ foo: 1, bar: 2, baz: 3 }]) { + assert.sameValue(b, 1); + assert.sameValue(rest.bar, 2); + assert.sameValue(rest.baz, 3); + + assert.sameValue(Object.getOwnPropertyDescriptor(rest, "foo"), undefined); + + verifyProperty(rest, "bar", { + enumerable: true, + writable: true, + configurable: true + }); + + verifyProperty(rest, "baz", { + enumerable: true, + writable: true, + configurable: true + }); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-computed-property.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-computed-property.js new file mode 100644 index 0000000000..91efd46098 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-computed-property.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-computed-property.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Destructuring field can be a computed property, i.e it can be defined only at runtime. Rest operantion needs to skip these properties as well. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var a = "foo"; +var b, rest; + +var counter = 0; + +for ({[a]:b, ...rest} of [{ foo: 1, bar: 2, baz: 3 }]) { + assert.sameValue(b, 1); + assert.sameValue(rest.bar, 2); + assert.sameValue(rest.baz, 3); + + assert.sameValue(Object.getOwnPropertyDescriptor(rest, "foo"), undefined); + + verifyProperty(rest, "bar", { + enumerable: true, + writable: true, + configurable: true + }); + + verifyProperty(rest, "baz", { + enumerable: true, + writable: true, + configurable: true + }); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-descriptors.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-descriptors.js new file mode 100644 index 0000000000..155d66471e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-descriptors.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-descriptors.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Object created from rest deconstruction doesn't copy source object property descriptors. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var rest; +var obj = {}; +Object.defineProperty(obj, "a", { value: 3, configurable: false, enumerable: true }); +Object.defineProperty(obj, "b", { value: 4, writable: false, enumerable: true }); + +var counter = 0; + +for ({...rest} of [obj]) { + verifyProperty(rest, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(rest, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 4 + }); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-empty-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-empty-obj.js new file mode 100644 index 0000000000..9b8df060f6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-empty-obj.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-empty-obj.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: RestBindingInitialization creates a new object even if lhs is an empty object (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var rest; + + +var counter = 0; + +for ({...rest} of [{}]) { + assert.notSameValue(rest, undefined); + assert.notSameValue(rest, null); + assert.sameValue(typeof rest, "object"); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-getter-abrupt-get-error.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-getter-abrupt-get-error.js new file mode 100644 index 0000000000..2ded1386e6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-getter-abrupt-get-error.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-getter-abrupt-get-error.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: Rest deconstruction doesn't happen if getter return is abrupt (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; +var count = 0; + +var counter = 0; + +assert.throws(Test262Error, function() { + for ({...x} of [{ get v() { count++; throw new Test262Error(); } }]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +assert.sameValue(count, 1); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-getter.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-getter.js new file mode 100644 index 0000000000..cbef6499a3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-getter.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-getter.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; +var count = 0; + +var counter = 0; + +for ({...x} of [{ get v() { count++; return 2; } }]) { + assert.sameValue(count, 1); + + verifyProperty(x, "v", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1.js new file mode 100644 index 0000000000..e792320e89 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-non-string-computed-property-1.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Destructuring field can be a non-string computed property, i.e it can be defined only at runtime. Rest operation needs to skip these properties as well. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var a = 1.; +var b, rest; + +var counter = 0; + +for ({[a]:b, ...rest} of [{[a]: 1, bar: 2 }]) { + assert.sameValue(b, 1); + + assert.sameValue(Object.getOwnPropertyDescriptor(rest, "1"), undefined); + + verifyProperty(rest, "bar", { + value: 2, + enumerable: true, + writable: true, + configurable: true + }); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1dot.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1dot.js new file mode 100644 index 0000000000..35c257b14c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1dot.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-non-string-computed-property-1dot.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Destructuring field can be a non-string computed property, i.e it can be defined only at runtime. Rest operation needs to skip these properties as well. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [compareArray.js, propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var a = 1.; +var b, rest; + +var counter = 0; + +for ({[a]:b, ...rest} of [{[a]: [1], bar: 2 }]) { + assert.compareArray(b, [1]); + + assert.sameValue(Object.getOwnPropertyDescriptor(rest, "1"), undefined); + + verifyProperty(rest, "bar", { + value: 2, + enumerable: true, + writable: true, + configurable: true + }); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1dot0.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1dot0.js new file mode 100644 index 0000000000..7860eb4412 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1dot0.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-non-string-computed-property-1dot0.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Destructuring field can be a non-string computed property, i.e it can be defined only at runtime. Rest operation needs to skip these properties as well. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var a = 1.; +var b, rest; + +var counter = 0; + +for ({[a]:b, ...rest} of [{[a]: 1.0, bar: 2 }]) { + assert.sameValue(b, 1); + + assert.sameValue(Object.getOwnPropertyDescriptor(rest, "1"), undefined); + + verifyProperty(rest, "bar", { + value: 2, + enumerable: true, + writable: true, + configurable: true + }); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1e0.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1e0.js new file mode 100644 index 0000000000..8417f17694 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-1e0.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-non-string-computed-property-1e0.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Destructuring field can be a non-string computed property, i.e it can be defined only at runtime. Rest operation needs to skip these properties as well. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var a = 1.; +var b, rest; + +var counter = 0; + +for ({[a]:b, ...rest} of [{[a]: 1e0, bar: 2 }]) { + assert.sameValue(b, 1); + + assert.sameValue(Object.getOwnPropertyDescriptor(rest, "1"), undefined); + + verifyProperty(rest, "bar", { + value: 2, + enumerable: true, + writable: true, + configurable: true + }); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-array-1.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-array-1.js new file mode 100644 index 0000000000..17417644d4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-array-1.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-non-string-computed-property-array-1.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Destructuring field can be a non-string computed property, i.e it can be defined only at runtime. Rest operation needs to skip these properties as well. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [compareArray.js, propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var a = 1.; +var b, rest; + +var counter = 0; + +for ({[a]:b, ...rest} of [{[a]: [1], bar: 2 }]) { + assert.compareArray(b, [1]); + + assert.sameValue(Object.getOwnPropertyDescriptor(rest, "1"), undefined); + + verifyProperty(rest, "bar", { + value: 2, + enumerable: true, + writable: true, + configurable: true + }); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-array-1e0.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-array-1e0.js new file mode 100644 index 0000000000..c11cded9aa --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-array-1e0.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-non-string-computed-property-array-1e0.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Destructuring field can be a non-string computed property, i.e it can be defined only at runtime. Rest operation needs to skip these properties as well. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [compareArray.js, propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var a = 1.; +var b, rest; + +var counter = 0; + +for ({[a]:b, ...rest} of [{[a]: [1e0], bar: 2 }]) { + assert.compareArray(b, [1]); + + + assert.sameValue(Object.getOwnPropertyDescriptor(rest, "1"), undefined); + + verifyProperty(rest, "bar", { + value: 2, + enumerable: true, + writable: true, + configurable: true + }); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-string-1.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-string-1.js new file mode 100644 index 0000000000..d3929f611f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-non-string-computed-property-string-1.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-non-string-computed-property-string-1.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Destructuring field can be a non-string computed property, i.e it can be defined only at runtime. Rest operation needs to skip these properties as well. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var a = 1.; +var b, rest; + +var counter = 0; + +for ({[a]:b, ...rest} of [{[a]: "1", bar: 2 }]) { + assert.sameValue(b, "1"); + + assert.sameValue(Object.getOwnPropertyDescriptor(rest, "1"), undefined); + + verifyProperty(rest, "bar", { + value: 2, + enumerable: true, + writable: true, + configurable: true + }); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-not-last-element-invalid.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-not-last-element-invalid.js new file mode 100644 index 0000000000..775541cf1a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-not-last-element-invalid.js @@ -0,0 +1,35 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-not-last-element-invalid.case +// - src/dstr-assignment/syntax/for-of.template +/*--- +description: Object rest element needs to be the last AssignmenProperty in ObjectAssignmentPattern. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +$DONOTEVALUATE(); +var rest, b; + +for ({...rest, b} of [{} +]) ; diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-number.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-number.js new file mode 100644 index 0000000000..1f007579bd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-number.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-number.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: RestBindingInitialization creates a new object even if lhs is a Number (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var rest; + + +var counter = 0; + +for ({...rest} of [51]) { + assert.notSameValue(rest, undefined); + assert.notSameValue(rest, null); + assert(rest instanceof Object); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-order.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-order.js new file mode 100644 index 0000000000..8b6767c502 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-order.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-order.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Rest operation follows [[OwnPropertyKeys]] order (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol, object-rest, destructuring-binding] +flags: [generated] +includes: [compareArray.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var rest; +var calls = []; +var o = { get z() { calls.push('z') }, get a() { calls.push('a') } }; +Object.defineProperty(o, 1, { get: () => { calls.push(1) }, enumerable: true }); +Object.defineProperty(o, Symbol('foo'), { get: () => { calls.push("Symbol(foo)") }, enumerable: true }); + +var counter = 0; + +for ({...rest} of [o]) { + assert.compareArray(calls, [1, 'z', 'a', "Symbol(foo)"]); + assert.sameValue(Object.keys(rest).length, 3); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-put-const.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-put-const.js new file mode 100644 index 0000000000..0ddcc9aadd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-put-const.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-put-const.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: The object rest deconstruction assignment target should obey `const` semantics. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +const rest = null; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({...rest} of [{} +]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-same-name.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-same-name.js new file mode 100644 index 0000000000..a51b2c71ea --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-same-name.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-same-name.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Proper setting in the values for rest name equal to a property name. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var o = { + x: 42, + y: 39, + z: 'cheeseburger' +}; + +var x, y, z; + +var counter = 0; + +for ({ x, ...z } of [o]) { + assert.sameValue(x, 42); + assert.sameValue(y, undefined); + assert.sameValue(z.y, 39); + assert.sameValue(z.z, 'cheeseburger'); + + var keys = Object.getOwnPropertyNames(z); + assert.sameValue(keys.length, 2); + assert.sameValue(keys[0], 'y'); + assert.sameValue(keys[1], 'z'); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-skip-non-enumerable.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..9c0c4e53f2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-skip-non-enumerable.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-skip-non-enumerable.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Rest object doesn't contain non-enumerable properties (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var rest; +var obj = {a: 3, b: 4}; +Object.defineProperty(obj, "x", { value: 4, enumerable: false }); + +var counter = 0; + +for ({...rest} of [obj]) { + assert.sameValue(Object.getOwnPropertyDescriptor(rest, "x"), undefined); + + verifyProperty(rest, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(rest, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 4 + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-str-val.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-str-val.js new file mode 100644 index 0000000000..e8593e80c8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-str-val.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-str-val.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: RestBindingInitialization creats an object with indexes as property name (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var rest; + + +var counter = 0; + +for ({...rest} of ["foo"]) { + assert.sameValue(rest["0"], "f"); + assert.sameValue(rest["1"], "o"); + assert.sameValue(rest["2"], "o"); + assert(rest instanceof Object); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-symbol-val.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-symbol-val.js new file mode 100644 index 0000000000..1602f40ce1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-symbol-val.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-symbol-val.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: RestBindingInitialization creates a new object if lhs is a Symbol (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol, object-rest, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var rest; + + +var counter = 0; + +for ({...rest} of [Symbol("foo")]) { + assert.notSameValue(rest, undefined); + assert.notSameValue(rest, null); + assert(rest instanceof Object); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-to-property-with-setter.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-to-property-with-setter.js new file mode 100644 index 0000000000..0ac23409db --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-to-property-with-setter.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-to-property-with-setter.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object property setter, its value should be binded as rest object. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var settedValue; +var executedGetter = false; +var src = { + get y() { executedGetter = true; }, + set y(v) { + settedValue = v; + } +} +src.y = undefined; + +var counter = 0; + +for ({...src.y} of [{ x: 1, y: 2}]) { + assert.sameValue(settedValue.x, 1); + assert.sameValue(settedValue.y, 2); + assert(!executedGetter, "The property should not be accessed"); + + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-to-property.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-to-property.js new file mode 100644 index 0000000000..f04383825c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-to-property.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-to-property.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: When DestructuringAssignmentTarget is an object property, its value should be binded as rest object. (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var src = {}; + +var counter = 0; + +for ({...src.y} of [{ x: 1, y: 2}]) { + assert.sameValue(src.y.x, 1); + assert.sameValue(src.y.y, 2); + + verifyProperty(src, "y", { + enumerable: true, + writable: true, + configurable: true + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-val-null.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-val-null.js new file mode 100644 index 0000000000..a2509f70ec --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-val-null.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-val-null.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: TypeError is thrown when rhs is null because of 7.1.13 ToObject ( argument ) used by CopyDataProperties (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var rest; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({...rest} of [null +]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-val-undefined.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-val-undefined.js new file mode 100644 index 0000000000..1390ffa8c9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-val-undefined.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-val-undefined.case +// - src/dstr-assignment/error/for-of.template +/*--- +description: TypeError is thrown when rhs is ```undefined``` because of 7.1.13 ToObject ( argument ) used by CopyDataProperties (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var rest; + +var counter = 0; + +assert.throws(TypeError, function() { + for ({...rest} of [undefined +]) { + counter += 1; + } + counter += 1; +}); + +assert.sameValue(counter, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-valid-object.js b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-valid-object.js new file mode 100644 index 0000000000..ef2b94d0ca --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/obj-rest-valid-object.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment/obj-rest-valid-object.case +// - src/dstr-assignment/default/for-of.template +/*--- +description: Rest object contains just unextracted data (For..of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 4. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var rest, a, b; + + +var counter = 0; + +for ({a, b, ...rest} of [{x: 1, y: 2, a: 5, b: 3}]) { + assert.sameValue(rest.a, undefined); + assert.sameValue(rest.b, undefined); + + verifyProperty(rest, "x", { + enumerable: true, + writable: true, + configurable: true, + value: 1 + }); + + verifyProperty(rest, "y", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + counter += 1; +} + +assert.sameValue(counter, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/shell.js b/js/src/tests/test262/language/statements/for-of/dstr/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/shell.js diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-close.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-close.js new file mode 100644 index 0000000000..d3f0dfb328 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-close.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-close.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: false }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var iterCount = 0; + +for (var [x] of [iter]) { + assert.sameValue(doneCallCount, 1); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..9677bf06a7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-get-err-array-prototype.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err-array-prototype.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Abrupt completion returned by GetIterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iteratorRecord be ? GetIterator(value). + + GetIterator ( obj [ , hint [ , method ] ] ) + + [...] + 4. Let iterator be ? Call(method, obj). + + Call ( F, V [ , argumentsList ] ) + + [...] + 2. If IsCallable(F) is false, throw a TypeError exception. + +---*/ +delete Array.prototype[Symbol.iterator]; + +assert.throws(TypeError, function() { + for (var [x, y, z] of [[1, 2, 3]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-get-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-get-err.js new file mode 100644 index 0000000000..f0346537ca --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-get-err.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Abrupt completion returned by GetIterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + for (var [x] of [iter]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-no-close.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-no-close.js new file mode 100644 index 0000000000..94ecd846d3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-init-iter-no-close.js @@ -0,0 +1,69 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-no-close.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: true }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + +var iterCount = 0; + +for (var [x] of [iter]) { + assert.sameValue(doneCallCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-name-iter-val.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-name-iter-val.js new file mode 100644 index 0000000000..8541f8ba15 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-name-iter-val.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-name-iter-val.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding with normal value iteration (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [x, y, z] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..e436b89a97 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elem-init.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-init.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (var [[x, y, z] = [4, 5, 6]] of [[]]) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..610d4adb76 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elem-iter.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-iter.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (var [[x, y, z] = [4, 5, 6]] of [[[7, 8, 9]]]) { + assert.sameValue(x, 7); + assert.sameValue(y, 8); + assert.sameValue(z, 9); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..084451edc6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elision-init.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-init.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var iterCount = 0; + +for (var [[,] = g()] of [[]]) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..2ad18591b0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-elision-iter.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-iter.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var callCount = 0; +function* g() { + callCount += 1; +}; + +var iterCount = 0; + +for (var [[,] = g()] of [[[]]]) { + assert.sameValue(callCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..048e325a0f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-empty-init.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-init.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var initCount = 0; +var iterCount = 0; +var iter = function*() { iterCount += 1; }(); + +var iterCount = 0; + +for (var [[] = function() { initCount += 1; return iter; }()] of [[]]) { + assert.sameValue(initCount, 1); + assert.sameValue(iterCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..93d9bbf8d3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-empty-iter.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-iter.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var initCount = 0; + +var iterCount = 0; + +for (var [[] = function() { initCount += 1; }()] of [[[23]]]) { + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..7cf152aead --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-rest-init.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-init.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; + +var iterCount = 0; + +for (var [[...x] = values] of [[]]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..1c2e600c19 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-rest-iter.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-iter.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; +var initCount = 0; + +var iterCount = 0; + +for (var [[...x] = function() { initCount += 1; }()] of [[values]]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..9ad7b4bf02 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-ary-val-null.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-val-null.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Nested array destructuring with a null value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). +---*/ + +assert.throws(TypeError, function() { + for (var [[x]] of [[null]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..fb414ef378 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-exhausted.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-exhausted.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Destructuring initializer with an exhausted iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [x = 23] of [[]]) { + assert.sameValue(x, 23); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..e9e4b06253 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-arrow.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-arrow.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding does assign name to arrow functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [arrow = () => {}] of [[]]) { + assert.sameValue(arrow.name, 'arrow'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..3c3f837137 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-class.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-class.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }] of [[]]) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..d9aa65af14 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-cover.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-cover.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [cover = (function () {}), xCover = (0, function() {})] of [[]]) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..fda2eb92cd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-fn.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-fn.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [fn = function () {}, xFn = function x() {}] of [[]]) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..aff711e0a8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-fn-name-gen.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-gen.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). + +---*/ + +var iterCount = 0; + +for (var [gen = function* () {}, xGen = function* x() {}] of [[]]) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..912d08c43e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-hole.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-hole.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Destructuring initializer with a "hole" (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + SingleNameBinding : BindingIdentifier Initializeropt + [...] 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [x = 23] of [[,]]) { + assert.sameValue(x, 23); + // another statement + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..c6c0dea8a8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-skipped.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-skipped.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var iterCount = 0; + +for (var [w = counter(), x = counter(), y = counter(), z = counter()] of [[null, 0, false, '']]) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..87515760c3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-throws.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-throws.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Destructuring initializer returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ + +assert.throws(Test262Error, function() { + for (var [x = (function() { throw new Test262Error(); })()] of [[undefined]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..037cbc91a8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-undef.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-undef.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Destructuring initializer with an undefined value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [x = 23] of [[undefined]]) { + assert.sameValue(x, 23); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..54ad3a10ff --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-init-unresolvable.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-unresolvable.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Destructuring initializer is an unresolvable reference (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + for (var [ x = unresolvableReference ] of [[]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..0b3349f91f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-complete.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-complete.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding when value iteration completes (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [x] of [[]]) { + assert.sameValue(x, undefined); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..cbfae7148d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-done.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-done.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [_, x] of [[]]) { + assert.sameValue(x, undefined); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..919712dde1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-step-err.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-step-err.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +assert.throws(Test262Error, function() { + for (var [x] of [g]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..7bc52580ad --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-val-array-prototype.js @@ -0,0 +1,78 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-array-prototype.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializer_opt + + 1. Let bindingId be StringValue of BindingIdentifier. + 2. Let lhs be ? ResolveBinding(bindingId, environment). + 3. If iteratorRecord.[[Done]] is false, then + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[Done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[Done]] to true. + iii. ReturnIfAbrupt(v). + [...] + 7. Return InitializeReferencedBinding(lhs, v). + +---*/ +Array.prototype[Symbol.iterator] = function* () { + if (this.length > 0) { + yield this[0]; + } + if (this.length > 1) { + yield this[1]; + } + if (this.length > 2) { + yield 42; + } +}; + +var iterCount = 0; + +for (var [x, y, z] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 42); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..ff562dc6b5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-val-err.js @@ -0,0 +1,72 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-err.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(v). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +assert.throws(Test262Error, function() { + for (var [x] of [g]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..e85402c55f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-id-iter-val.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [x, y, z] of [[1, 2, 3]]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..54993d3226 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-id-init.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id-init.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (var [{ x, y, z } = { x: 44, y: 55, z: 66 }] of [[]]) { + assert.sameValue(x, 44); + assert.sameValue(y, 55); + assert.sameValue(z, 66); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..ac5579dfa9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-id.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (var [{ x, y, z } = { x: 44, y: 55, z: 66 }] of [[{ x: 11, y: 22, z: 33 }]]) { + assert.sameValue(x, 11); + assert.sameValue(y, 22); + assert.sameValue(z, 33); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..ec4268c041 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-prop-id-init.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id-init.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (var [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] of [[]]) { + assert.sameValue(v, 444); + assert.sameValue(x, 555); + assert.sameValue(z, 666); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..7e2679764d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-prop-id.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + +var iterCount = 0; + +for (var [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] of [[{ u: 777, w: 888, y: 999 }]]) { + assert.sameValue(v, 777); + assert.sameValue(x, 888); + assert.sameValue(z, 999); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..2d60795965 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-val-null.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-null.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Nested object destructuring with a null value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +assert.throws(TypeError, function() { + for (var [{ x }] of [[null]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..20784131d5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elem-obj-val-undef.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-undef.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Nested object destructuring with a value of `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + +assert.throws(TypeError, function() { + for (var [{ x }] of [[]]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..89d53d7e2c --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision-exhausted.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-exhausted.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Elision accepts exhausted iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + [...] + 2. Return NormalCompletion(empty). + +---*/ +var iter = function*() {}(); +iter.next(); + +var iterCount = 0; + +for (var [,] of [iter]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision-iter-close.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision-iter-close.js new file mode 100644 index 0000000000..b3bafbb48b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision-iter-close.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-iter-close.case +// - src/dstr-binding/iter-close/for-of-var.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (var [,] of [iter]) { + return; + } +} + +fn(); + +assert.sameValue(iter.next().done, true, 'iteration occurred as expected'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..472c07b379 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision-step-err.js @@ -0,0 +1,68 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-step-err.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Elision advances iterator and forwards abrupt completions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var following = 0; +var iter =function* () { + throw new Test262Error(); + following += 1; +}(); + +assert.throws(Test262Error, function() { + for (var [,] of [iter]) { + return; + } +}); + +iter.next(); +assert.sameValue(following, 0, 'Iterator was properly closed.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision.js new file mode 100644 index 0000000000..825866ae24 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-elision.js @@ -0,0 +1,74 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Elision advances iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var iterCount = 0; + +for (var [,] of [g()]) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-empty.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-empty.js new file mode 100644 index 0000000000..5f231ae680 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-empty.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-empty.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var iterCount = 0; + +for (var [] of [iter]) { + assert.sameValue(iterations, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-init-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-init-err.js new file mode 100644 index 0000000000..c46e67f5cc --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-init-err.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteration-statements +description: > + Initializer is not allowed in head's ForBinding position. +info: | + IterationStatement: + for (var ForBinding of AssignmentExpression) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +for (var [x] = 1 of []) {} diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..796759d802 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-elem.js @@ -0,0 +1,81 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elem.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element containing an array BindingElementList pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var [...[x, y, z]] of [[3, 4, 5]]) { + assert.sameValue(x, 3); + assert.sameValue(y, 4); + assert.sameValue(z, 5); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..ab25275749 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-elision.js @@ -0,0 +1,87 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elision.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element containing an elision (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + +var iterCount = 0; + +for (var [...[,]] of [g()]) { + assert.sameValue(first, 1); + assert.sameValue(second, 1); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..8888d31dde --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-empty.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-empty.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element containing an "empty" array pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + +var iterCount = 0; + +for (var [...[]] of [iter]) { + assert.sameValue(iterations, 1); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..25a6d7b401 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-ary-rest.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-rest.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element containing a rest element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +var values = [1, 2, 3]; + +var iterCount = 0; + +for (var [...[...x]] of [values]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..91ada24c57 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-direct.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-direct.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Lone rest element (direct binding) (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [compareArray.js] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingIdentifier + + [...] + 2. Let A be ! ArrayCreate(0). + 3. Let n be 0. + 4. Repeat, + [...] + f. Perform ! CreateDataPropertyOrThrow(A, ! ToString(n), nextValue). + g. Set n to n + 1. + +---*/ + +var iterCount = 0; + +for (var [...x] of [[1]]) { + assert(Array.isArray(x)); + assert.compareArray(x, [1]); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..35e56ada55 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-elision-next-err.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision-next-err.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Rest element following elision elements (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. + +---*/ +var iter = (function*() { throw new Test262Error(); })(); + +assert.throws(Test262Error, function() { + for (var [, ...x] of [iter]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..171d45bd62 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-elision.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element following elision elements (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. +---*/ +var values = [1, 2, 3, 4, 5]; + +var iterCount = 0; + +for (var [ , , ...x] of [values]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 3); + assert.sameValue(x[1], 4); + assert.sameValue(x[2], 5); + assert.notSameValue(x, values); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..da5af0d7cc --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-exhausted.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-exhausted.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: RestElement applied to an exhausted iterator (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + b. If iteratorRecord.[[done]] is true, then + i. If environment is undefined, return PutValue(lhs, A). + ii. Return InitializeReferencedBinding(lhs, A). + +---*/ + +var iterCount = 0; + +for (var [, , ...x] of [[1, 2]]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-iter-close.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-iter-close.js new file mode 100644 index 0000000000..dbff7e55b8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-iter-close.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-close.case +// - src/dstr-binding/iter-close/for-of-var.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (var [...x] of [iter]) { + return; + } +} + +fn(); + +assert.sameValue(iter.next().done, true, 'iteration occurred as expected'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..d243017b82 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-iter-step-err.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-step-err.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + a. If iteratorRecord.[[done]] is false, + i. Let next be IteratorStep(iteratorRecord.[[iterator]]). + ii. If next is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(next). + +---*/ +var first = 0; +var second = 0; +var iter = function*() { + first += 1; + throw new Test262Error(); + second += 1; +}(); + +assert.throws(Test262Error, function() { + for (var [...x] of [iter]) { + return; + } +}); + +iter.next(); +assert.sameValue(first, 1); +assert.sameValue(second, 0, 'Iterator is closed following abrupt completion.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..4ef4dd47cb --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id-iter-val-err.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-val-err.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + c. Let nextValue be IteratorValue(next). + d. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to + true. + e. ReturnIfAbrupt(nextValue). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +assert.throws(Test262Error, function() { + for (var [...x] of [iter]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id.js new file mode 100644 index 0000000000..26f87e48ac --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-id.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Lone rest element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + [...] 3. Let A be ArrayCreate(0). [...] 5. Repeat + [...] + f. Let status be CreateDataProperty(A, ToString (n), nextValue). + [...] +---*/ +var values = [1, 2, 3]; + +var iterCount = 0; + +for (var [...x] of [values]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..f1e04d9601 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-init-ary.js @@ -0,0 +1,55 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-ary.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element (nested array pattern) does not support initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (var [...[ x ] = []] of [[]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..fd2ac5b50e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-init-id.js @@ -0,0 +1,55 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-id.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element (identifier) does not support initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (var [...x = []] of [[]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..233d21059e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-init-obj.js @@ -0,0 +1,55 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-obj.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element (nested object pattern) does not support initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (var [...{ x } = []] of [[]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..e86e6dcb97 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-not-final-ary.js @@ -0,0 +1,55 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-ary.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (var [...[x], y] of [[1, 2, 3]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..e1d647b8d6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-not-final-id.js @@ -0,0 +1,55 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-id.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element (identifier) may not be followed by any element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (var [...x, y] of [[1, 2, 3]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..cbc74de10d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-not-final-obj.js @@ -0,0 +1,55 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-obj.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + +var iterCount = 0; + +for (var [...{ x }, y] of [[1, 2, 3]]) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..01b6daecdd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-obj-id.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-id.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element containing an object binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ + +var iterCount = 0; + +for (var [...{ length }] of [[1, 2, 3]]) { + assert.sameValue(length, 3); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..477f4c5e9e --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-ary-ptrn-rest-obj-prop-id.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-prop-id.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest element containing an object binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +let length = "outer"; + +var iterCount = 0; + +for (var [...{ 0: v, 1: w, 2: x, 3: y, length: z }] of [[7, 8, 9]]) { + assert.sameValue(v, 7); + assert.sameValue(w, 8); + assert.sameValue(x, 9); + assert.sameValue(y, undefined); + assert.sameValue(z, 3); + + assert.sameValue(length, "outer", "the length prop is not set as a binding name"); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-init-null.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-init-null.js new file mode 100644 index 0000000000..f000d07a54 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-init-null.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-null.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (var {} of [null]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-init-undefined.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-init-undefined.js new file mode 100644 index 0000000000..3b94ad21fd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-init-undefined.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-undefined.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (var {} of [undefined]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-empty.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-empty.js new file mode 100644 index 0000000000..53508700b3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-empty.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-empty.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: No property access occurs for an "empty" object binding pattern (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ +var accessCount = 0; +var obj = Object.defineProperty({}, 'attr', { + get: function() { + accessCount += 1; + } +}); + +var iterCount = 0; + +for (var {} of [obj]) { + assert.sameValue(accessCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..1fc9af43c2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-get-value-err.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-get-value-err.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. Let v be GetV(value, propertyName). + 5. ReturnIfAbrupt(v). +---*/ +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + for (var { poisoned } of [poisonedProperty]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..05332ad39b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-arrow.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-arrow.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (var { arrow = () => {} } of [{}]) { + assert.sameValue(arrow.name, 'arrow'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..7f8cce3325 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-class.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-class.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (var { cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } } of [{}]) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..b2c855f183 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-cover.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-cover.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (var { cover = (function () {}), xCover = (0, function() {}) } of [{}]) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..98b78fd411 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-fn.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-fn.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + +var iterCount = 0; + +for (var { fn = function () {}, xFn = function x() {} } of [{}]) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..6f7ee71468 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-fn-name-gen.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-gen.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). + +---*/ + +var iterCount = 0; + +for (var { gen = function* () {}, xGen = function* x() {} } of [{}]) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..b7af3e4968 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-skipped.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-skipped.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var iterCount = 0; + +for (var { w = counter(), x = counter(), y = counter(), z = counter() } of [{ w: null, x: 0, y: false, z: '' }]) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..d6cfe57116 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-throws.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-throws.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Error thrown when evaluating the initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (var { x = thrower() } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..273fc8422f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-init-unresolvable.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-unresolvable.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Destructuring initializer is an unresolvable reference (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + for (var { x = unresolvableReference } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..0f8c247d2d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-id-trailing-comma.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-trailing-comma.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (var { x, } of [{ x: 23 }]) { + assert.sameValue(x, 23); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-init-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-init-err.js new file mode 100644 index 0000000000..6d912b28a4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-init-err.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteration-statements +description: > + Initializer is not allowed in head's ForBinding position. +info: | + IterationStatement: + for (var ForBinding of AssignmentExpression) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +for (var {x} = 1 of []) {} diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-list-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-list-err.js new file mode 100644 index 0000000000..c9534bd7d3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-list-err.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-list-err.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPropertyList : BindingPropertyList , BindingProperty + + 1. Let status be the result of performing BindingInitialization for + BindingPropertyList using value and environment as arguments. + 2. ReturnIfAbrupt(status). +---*/ +var initCount = 0; +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (var { a, b = thrower(), c = ++initCount } of [{}]) { + return; + } +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..25ad8096dd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary-init.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-init.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (var { w: [x, y, z] = [4, 5, 6] } of [{}]) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..ede1ac1210 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary-trailing-comma.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-trailing-comma.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (var { x: [y], } of [{ x: [45] }]) { + assert.sameValue(y,45); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..1ffcf14f73 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary-value-null.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-value-null.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + for (var { w: [x, y, z] = [4, 5, 6] } of [{ w: null }]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..a6ddc5865a --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-ary.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (var { w: [x, y, z] = [4, 5, 6] } of [{ w: [7, undefined, ] }]) { + assert.sameValue(x, 7); + assert.sameValue(y, undefined); + assert.sameValue(z, undefined); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..527d6303a1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-eval-err.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-eval-err.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Evaluation of property name returns an abrupt completion (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingProperty : PropertyName : BindingElement + + 1. Let P be the result of evaluating PropertyName + 2. ReturnIfAbrupt(P). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (var { [thrower()]: x } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..ca4c6e44a0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-get-value-err.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-get-value-err.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. Let v be GetV(value, propertyName). + 2. ReturnIfAbrupt(v). +---*/ +var initEvalCount = 0; +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + for (var { poisoned: x = ++initEvalCount } of [poisonedProperty]) { + return; + } +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..d6cb0f7c9d --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init-skipped.js @@ -0,0 +1,75 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-skipped.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + +var iterCount = 0; + +for (var { s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } of [{ s: null, u: 0, w: false, y: '' }]) { + assert.sameValue(t, null); + assert.sameValue(v, 0); + assert.sameValue(x, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + assert.throws(ReferenceError, function() { + s; + }); + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..d732cee124 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init-throws.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-throws.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Error thrown when evaluating the initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + for (var { x: y = thrower() } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..11550ff952 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init-unresolvable.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-unresolvable.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Destructuring initializer is an unresolvable reference (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +assert.throws(ReferenceError, function() { + for (var { x: y = unresolvableReference } of [{}]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..d8edc4fcdd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-init.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Binding as specified via property name, identifier, and initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var { x: y = 33 } of [{ }]) { + assert.sameValue(y, 33); + assert.throws(ReferenceError, function() { + x; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..e8c9fbaff1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id-trailing-comma.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-trailing-comma.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (var { x: y, } of [{ x: 23 }]) { + assert.sameValue(y, 23); + + assert.throws(ReferenceError, function() { + x; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id.js new file mode 100644 index 0000000000..fbfb842c58 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-id.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Binding as specified via property name and identifier (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var { x: y } of [{ x: 23 }]) { + assert.sameValue(y, 23); + assert.throws(ReferenceError, function() { + x; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..6b148f8351 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj-init.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-init.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (var { w: { x, y, z } = { x: 4, y: 5, z: 6 } } of [{ w: undefined }]) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..4f5578046f --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj-value-null.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-null.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + for (var { w: { x, y, z } = { x: 4, y: 5, z: 6 } } of [{ w: null }]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..1816ef51ba --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj-value-undef.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-undef.case +// - src/dstr-binding/error/for-of-var.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +assert.throws(TypeError, function() { + for (var { w: { x, y, z } = undefined } of [{ }]) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..38214fd142 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-prop-obj.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + +var iterCount = 0; + +for (var { w: { x, y, z } = { x: 4, y: 5, z: 6 } } of [{ w: { x: undefined, z: 7 } }]) { + assert.sameValue(x, undefined); + assert.sameValue(y, undefined); + assert.sameValue(z, 7); + + assert.throws(ReferenceError, function() { + w; + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-rest-getter.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..a45a39a69b --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-rest-getter.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-getter.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] +---*/ +var count = 0; + +var iterCount = 0; + +for (var {...x} of [{ get v() { count++; return 2; } }]) { + assert.sameValue(count, 1); + + verifyProperty(x, "v", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..27820d5b91 --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-rest-skip-non-enumerable.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-skip-non-enumerable.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest object doesn't contain non-enumerable properties (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] +---*/ +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); + +var iterCount = 0; + +for (var {...rest} of [o]) { + assert.sameValue(rest.x, undefined); + + verifyProperty(rest, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(rest, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 4 + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..b0cec431bd --- /dev/null +++ b/js/src/tests/test262/language/statements/for-of/dstr/var-obj-ptrn-rest-val-obj.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-val-obj.case +// - src/dstr-binding/default/for-of-var.template +/*--- +description: Rest object contains just unextracted data (for-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] +---*/ + +var iterCount = 0; + +for (var {a, b, ...rest} of [{x: 1, y: 2, a: 5, b: 3}]) { + assert.sameValue(rest.a, undefined); + assert.sameValue(rest.b, undefined); + + verifyProperty(rest, "x", { + enumerable: true, + writable: true, + configurable: true, + value: 1 + }); + + verifyProperty(rest, "y", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); |