diff options
Diffstat (limited to 'js/src/tests/test262/language/statements/for/dstr')
287 files changed, 17501 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/for/dstr/browser.js b/js/src/tests/test262/language/statements/for/dstr/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/browser.js diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-init-iter-close.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-init-iter-close.js new file mode 100644 index 0000000000..82b8dcccb5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x] = iter; iterCount < 1; ) { + 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/dstr/const-ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..a8a6141051 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Abrupt completion returned by GetIterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x, y, z] = [1, 2, 3]; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-init-iter-get-err.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-init-iter-get-err.js new file mode 100644 index 0000000000..b2d551a7f3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Abrupt completion returned by GetIterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x] = iter; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-init-iter-no-close.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-init-iter-no-close.js new file mode 100644 index 0000000000..f2a591d689 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x] = iter; iterCount < 1; ) { + 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/dstr/const-ary-name-iter-val.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-name-iter-val.js new file mode 100644 index 0000000000..1155e61c1c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding with normal value iteration (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..d9ae3db7bb --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [[x, y, z] = [4, 5, 6]] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..8aeffa2527 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [[x, y, z] = [4, 5, 6]] = [[7, 8, 9]]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..633be24808 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [[,] = g()] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..d99f5f3c9b --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [[,] = g()] = [[]]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..9d0d0edbfd --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [[] = function() { initCount += 1; return iter; }()] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..41cb484112 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [[] = function() { initCount += 1; }()] = [[23]]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..e999f90e58 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [[...x] = values] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..cf579a270b --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [[...x] = function() { initCount += 1; }()] = [values]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..9d27df4662 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Nested array destructuring with a null value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [[x]] = [null]; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..bd92b0f02f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Destructuring initializer with an exhausted iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x = 23] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..e799ee7f5d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding does assign name to arrow functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [arrow = () => {}] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..e51e737b3c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..982e819c20 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [cover = (function () {}), xCover = (0, function() {})] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..ed27fff8c0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [fn = function () {}, xFn = function x() {}] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..34ecbf8f24 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [gen = function* () {}, xGen = function* x() {}] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..eb79898c9c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Destructuring initializer with a "hole" (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x = 23] = [,]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..2ee1c9d75a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [w = counter(), x = counter(), y = counter(), z = counter()] = [null, 0, false, '']; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..0196c4863f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Destructuring initializer returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x = (function() { throw new Test262Error(); })()] = [undefined]; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..40ffe0553d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Destructuring initializer with an undefined value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x = 23] = [undefined]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..dfacdf5de4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Destructuring initializer is an unresolvable reference (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [ x = unresolvableReference ] = []; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..b897e7ee3f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding when value iteration completes (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..36b1422ed1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [_, x] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..a728f01648 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x] = g; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..98ae3362c4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x, y, z] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..81fcf8b192 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [x] = g; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..bca24af5b8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..3aa212bb2d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [{ x, y, z } = { x: 44, y: 55, z: 66 }] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..8f19eb03d9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [{ x, y, z } = { x: 44, y: 55, z: 66 }] = [{ x: 11, y: 22, z: 33 }]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..daa57464db --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = []; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..7af2967d3d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = [{ u: 777, w: 888, y: 999 }]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..a3327710d8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Nested object destructuring with a null value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [{ x }] = [null]; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..6c8646eecd --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Nested object destructuring with a value of `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [{ x }] = []; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..cf5b500fb9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Elision accepts exhausted iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [,] = iter; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elision-iter-close.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elision-iter-close.js new file mode 100644 index 0000000000..711f4efb8a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (const [,] = 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/dstr/const-ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..a0ee1f3409 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Elision advances iterator and forwards abrupt completions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [,] = 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/dstr/const-ary-ptrn-elision.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-elision.js new file mode 100644 index 0000000000..dacc91f8e5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Elision advances iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 [,] = g(); iterCount < 1; ) { + 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/dstr/const-ary-ptrn-empty.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-empty.js new file mode 100644 index 0000000000..511fcbbd64 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 [] = iter; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..8dc450d5eb --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element containing an array BindingElementList pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...[x, y, z]] = [3, 4, 5]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..b32cf05e5c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element containing an elision (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...[,]] = g(); iterCount < 1; ) { + 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/dstr/const-ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..6f2bed0ff0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element containing an "empty" array pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...[]] = iter; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..916036de12 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element containing a rest element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...[...x]] = values; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..27cf937eb1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Lone rest element (direct binding) (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [compareArray.js] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...x] = [1]; iterCount < 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/dstr/const-ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..0f9ff83330 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element following elision elements (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [, ...x] = iter; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..661a007a00 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element following elision elements (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [ , , ...x] = values; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..7535e7ad0e --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: RestElement applied to an exhausted iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [, , ...x] = [1, 2]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-rest-id-iter-close.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-id-iter-close.js new file mode 100644 index 0000000000..6944224356 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (const [...x] = 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/dstr/const-ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..08002818b2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...x] = 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/dstr/const-ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..3bd553bc52 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...x] = iter; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-id.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-id.js new file mode 100644 index 0000000000..fb77daed83 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Lone rest element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...x] = values; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..4110b965a5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element (nested array pattern) does not support initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...[ x ] = []] = []; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..dcb35c356c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element (identifier) does not support initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...x = []] = []; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..5af8cddb87 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element (nested object pattern) does not support initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...{ x } = []] = []; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..585619c48f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...[x], y] = [1, 2, 3]; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..df2ffe4347 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element (identifier) may not be followed by any element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...x, y] = [1, 2, 3]; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..b8fdc570ee --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...{ x }, y] = [1, 2, 3]; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..07b35b16ae --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element containing an object binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...{ length }] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/const-ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/statements/for/dstr/const-ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..6a9e1e0d4a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest element containing an object binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const [...{ 0: v, 1: w, 2: x, 3: y, length: z }] = [7, 8, 9]; iterCount < 1; ) { + 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/dstr/const-obj-init-null.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-init-null.js new file mode 100644 index 0000000000..68ef6e2d0b --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (const {} = null; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-init-undefined.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-init-undefined.js new file mode 100644 index 0000000000..ad8c5af4da --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (const {} = undefined; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-empty.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-empty.js new file mode 100644 index 0000000000..bf2a673944 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: No property access occurs for an "empty" object binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const {} = obj; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..03babd9f86 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { poisoned } = poisonedProperty; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..994be64197 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { arrow = () => {} } = {}; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..1c74976df0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } } = {}; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..948ebc828b --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { cover = (function () {}), xCover = (0, function() {}) } = {}; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..126b172d8a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { fn = function () {}, xFn = function x() {} } = {}; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..d911b27e27 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { gen = function* () {}, xGen = function* x() {} } = {}; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..221f28a559 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { w = counter(), x = counter(), y = counter(), z = counter() } = { w: null, x: 0, y: false, z: '' }; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..e06d8b8ade --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Error thrown when evaluating the initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { x = thrower() } = {}; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..ac987849aa --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Destructuring initializer is an unresolvable reference (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { x = unresolvableReference } = {}; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..4dff9fa61b --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (const { x, } = { x: 23 }; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-list-err.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-list-err.js new file mode 100644 index 0000000000..a4b4e86927 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { a, b = thrower(), c = ++initCount } = {}; ; ) { + return; + } +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..7aedeedf91 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { w: [x, y, z] = [4, 5, 6] } = {}; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..ec65932309 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (const { x: [y], } = { x: [45] }; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..f411e7aa64 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { w: [x, y, z] = [4, 5, 6] } = { w: null }; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-ary.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..38ccfb74e1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { w: [x, y, z] = [4, 5, 6] } = { w: [7, undefined, ] }; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..4a827b7bc8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Evaluation of property name returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { [thrower()]: x } = {}; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..5a3b29e4e6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { poisoned: x = ++initEvalCount } = poisonedProperty; ; ) { + return; + } +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..0368f83485 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } = { s: null, u: 0, w: false, y: '' }; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..408eed7502 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Error thrown when evaluating the initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { x: y = thrower() } = {}; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..946f6274bd --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Destructuring initializer is an unresolvable reference (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { x: y = unresolvableReference } = {}; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..0ec7e0c7e4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Binding as specified via property name, identifier, and initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const { x: y = 33 } = { }; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..17c0198427 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (const { x: y, } = { x: 23 }; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-prop-id.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-id.js new file mode 100644 index 0000000000..9fe44433ae --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Binding as specified via property name and identifier (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (const { x: y } = { x: 23 }; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..01c5de1836 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: undefined }; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..0074f7be11 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: null }; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..bde5850380 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { w: { x, y, z } = undefined } = { }; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-obj.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..0952820109 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (const { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: { x: undefined, z: 7 } }; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-rest-getter.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..0c1e3bac81 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ +var count = 0; + +var iterCount = 0; + +for (const {...x} = { get v() { count++; return 2; } }; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..cc1e0ba07a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest object doesn't contain non-enumerable properties (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); + +var iterCount = 0; + +for (const {...rest} = o; iterCount < 1; ) { + 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/dstr/const-obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/statements/for/dstr/const-obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..5e5831fcc4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-const.template +/*--- +description: Rest object contains just unextracted data (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ + +var iterCount = 0; + +for (const {a, b, ...rest} = {x: 1, y: 2, a: 5, b: 3}; iterCount < 1; ) { + 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/dstr/let-ary-init-iter-close.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-init-iter-close.js new file mode 100644 index 0000000000..b46d5fd597 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x] = iter; iterCount < 1; ) { + 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/dstr/let-ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..beb50ef2c8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Abrupt completion returned by GetIterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x, y, z] = [1, 2, 3]; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-init-iter-get-err.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-init-iter-get-err.js new file mode 100644 index 0000000000..790cc5eb81 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Abrupt completion returned by GetIterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x] = iter; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-init-iter-no-close.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-init-iter-no-close.js new file mode 100644 index 0000000000..245bc645cd --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x] = iter; iterCount < 1; ) { + 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/dstr/let-ary-name-iter-val.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-name-iter-val.js new file mode 100644 index 0000000000..b4b1112b23 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding with normal value iteration (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..0f3756a158 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [[x, y, z] = [4, 5, 6]] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..94de4d43ba --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [[x, y, z] = [4, 5, 6]] = [[7, 8, 9]]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..445298a95b --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [[,] = g()] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..99458724a9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [[,] = g()] = [[]]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..3c9585ccf5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [[] = function() { initCount += 1; return iter; }()] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..466820ed07 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [[] = function() { initCount += 1; }()] = [[23]]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..436a374073 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [[...x] = values] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..a7d995ea65 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [[...x] = function() { initCount += 1; }()] = [values]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..635ba4adb5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Nested array destructuring with a null value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [[x]] = [null]; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..b295973196 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Destructuring initializer with an exhausted iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x = 23] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..94209b3b63 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding does assign name to arrow functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [arrow = () => {}] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..b46b359b97 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..d65aab5bd7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [cover = (function () {}), xCover = (0, function() {})] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..69cdf63467 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [fn = function () {}, xFn = function x() {}] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..4e070e3c7e --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [gen = function* () {}, xGen = function* x() {}] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..f13bdb02ef --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Destructuring initializer with a "hole" (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x = 23] = [,]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..03debf5045 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [w = counter(), x = counter(), y = counter(), z = counter()] = [null, 0, false, '']; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..641a491813 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Destructuring initializer returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x = (function() { throw new Test262Error(); })()] = [undefined]; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..832c202585 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Destructuring initializer with an undefined value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x = 23] = [undefined]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..d15504afe8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Destructuring initializer is an unresolvable reference (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [ x = unresolvableReference ] = []; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..4bce1d556a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding when value iteration completes (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..8205a32305 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [_, x] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..9eba7c8eaf --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x] = g; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..008f32cf8d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x, y, z] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..62d54f3f50 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [x] = g; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..cea92a6f26 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..02f6a50032 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [{ x, y, z } = { x: 44, y: 55, z: 66 }] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..6ce4298e86 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [{ x, y, z } = { x: 44, y: 55, z: 66 }] = [{ x: 11, y: 22, z: 33 }]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..ddb13b3454 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = []; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..82aa90dc5d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = [{ u: 777, w: 888, y: 999 }]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..14454e0d69 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Nested object destructuring with a null value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [{ x }] = [null]; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..503cf609ca --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Nested object destructuring with a value of `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [{ x }] = []; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..1f500678fd --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Elision accepts exhausted iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [,] = iter; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elision-iter-close.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elision-iter-close.js new file mode 100644 index 0000000000..b7925772cc --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/let-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-let.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (let [,] = 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/dstr/let-ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..6b8e6d793d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Elision advances iterator and forwards abrupt completions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [,] = 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/dstr/let-ary-ptrn-elision.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-elision.js new file mode 100644 index 0000000000..ee609a1dfd --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Elision advances iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 [,] = g(); iterCount < 1; ) { + 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/dstr/let-ary-ptrn-empty.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-empty.js new file mode 100644 index 0000000000..113b950db5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 [] = iter; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..b4de8e4e9c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element containing an array BindingElementList pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...[x, y, z]] = [3, 4, 5]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..df1a046293 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element containing an elision (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...[,]] = g(); iterCount < 1; ) { + 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/dstr/let-ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..1527a0298f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element containing an "empty" array pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...[]] = iter; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..2538b698a7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element containing a rest element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...[...x]] = values; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..fb4bf0d235 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Lone rest element (direct binding) (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [compareArray.js] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...x] = [1]; iterCount < 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/dstr/let-ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..a4e11ba5fd --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element following elision elements (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [, ...x] = iter; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..51e1dcf888 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element following elision elements (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [ , , ...x] = values; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..cc520886d9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: RestElement applied to an exhausted iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [, , ...x] = [1, 2]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-rest-id-iter-close.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-id-iter-close.js new file mode 100644 index 0000000000..6eeeced81b --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/let-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-let.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (let [...x] = 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/dstr/let-ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..42349f9537 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...x] = 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/dstr/let-ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..4438a09945 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...x] = iter; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-id.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-id.js new file mode 100644 index 0000000000..43336a1d31 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Lone rest element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...x] = values; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..38325cc35e --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element (nested array pattern) does not support initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...[ x ] = []] = []; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..7807b11e6c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element (identifier) does not support initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...x = []] = []; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..dbec97b0d5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element (nested object pattern) does not support initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...{ x } = []] = []; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..f6429d3d3c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...[x], y] = [1, 2, 3]; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..43e6e4c30c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element (identifier) may not be followed by any element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...x, y] = [1, 2, 3]; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..eb725cba74 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...{ x }, y] = [1, 2, 3]; iterCount < 1; ) { + + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..334c180952 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element containing an object binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...{ length }] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/let-ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/statements/for/dstr/let-ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..475e677ed7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest element containing an object binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let [...{ 0: v, 1: w, 2: x, 3: y, length: z }] = [7, 8, 9]; iterCount < 1; ) { + 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/dstr/let-obj-init-null.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-init-null.js new file mode 100644 index 0000000000..1248850347 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (let {} = null; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-init-undefined.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-init-undefined.js new file mode 100644 index 0000000000..18f71d6b61 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (let {} = undefined; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-empty.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-empty.js new file mode 100644 index 0000000000..d2135e7d4d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: No property access occurs for an "empty" object binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let {} = obj; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..4505dcd718 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { poisoned } = poisonedProperty; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..454e3b9376 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { arrow = () => {} } = {}; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..a70b17f042 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } } = {}; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..252de0a8a4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { cover = (function () {}), xCover = (0, function() {}) } = {}; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..aa0f6e57f8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { fn = function () {}, xFn = function x() {} } = {}; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..ed3020e4d9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { gen = function* () {}, xGen = function* x() {} } = {}; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..591115ef56 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { w = counter(), x = counter(), y = counter(), z = counter() } = { w: null, x: 0, y: false, z: '' }; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..01a86e5636 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Error thrown when evaluating the initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { x = thrower() } = {}; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..06ece3e50a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Destructuring initializer is an unresolvable reference (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { x = unresolvableReference } = {}; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..c547644141 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (let { x, } = { x: 23 }; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-list-err.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-list-err.js new file mode 100644 index 0000000000..4683057f6a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { a, b = thrower(), c = ++initCount } = {}; ; ) { + return; + } +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..bc6f8e301d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { w: [x, y, z] = [4, 5, 6] } = {}; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..61f0b2b0d3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (let { x: [y], } = { x: [45] }; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..ce9f1306e9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { w: [x, y, z] = [4, 5, 6] } = { w: null }; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-ary.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..9b25e5eee4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { w: [x, y, z] = [4, 5, 6] } = { w: [7, undefined, ] }; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..62215ef8fe --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Evaluation of property name returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { [thrower()]: x } = {}; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..908a2439d1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { poisoned: x = ++initEvalCount } = poisonedProperty; ; ) { + return; + } +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..5225a15d39 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } = { s: null, u: 0, w: false, y: '' }; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..3c16194865 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Error thrown when evaluating the initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { x: y = thrower() } = {}; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..188d9619ff --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Destructuring initializer is an unresolvable reference (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { x: y = unresolvableReference } = {}; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..dd7e1eeede --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Binding as specified via property name, identifier, and initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let { x: y = 33 } = { }; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..4acce0897b --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (let { x: y, } = { x: 23 }; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-prop-id.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-id.js new file mode 100644 index 0000000000..91b06b0970 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Binding as specified via property name and identifier (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (let { x: y } = { x: 23 }; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..69d56260eb --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: undefined }; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..c37923195d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: null }; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..5c576e9690 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { w: { x, y, z } = undefined } = { }; ; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-obj.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..1b5c431d45 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env 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 (let { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: { x: undefined, z: 7 } }; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-rest-getter.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..9fc329218a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ +var count = 0; + +var iterCount = 0; + +for (let {...x} = { get v() { count++; return 2; } }; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..a96b4e8c1f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest object doesn't contain non-enumerable properties (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); + +var iterCount = 0; + +for (let {...rest} = o; iterCount < 1; ) { + 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/dstr/let-obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/statements/for/dstr/let-obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..e951bc1079 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/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-let.template +/*--- +description: Rest object contains just unextracted data (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ + +var iterCount = 0; + +for (let {a, b, ...rest} = {x: 1, y: 2, a: 5, b: 3}; iterCount < 1; ) { + 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/dstr/shell.js b/js/src/tests/test262/language/statements/for/dstr/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/shell.js diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-init-iter-close.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-init-iter-close.js new file mode 100644 index 0000000000..129718d89c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-init-iter-close.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-close.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x] = iter; iterCount < 1; ) { + 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/dstr/var-ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..9f73854ed4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-init-iter-get-err-array-prototype.js @@ -0,0 +1,57 @@ +// 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-var.template +/*--- +description: Abrupt completion returned by GetIterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x, y, z] = [1, 2, 3]; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-init-iter-get-err.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-init-iter-get-err.js new file mode 100644 index 0000000000..e85b650ba3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-init-iter-get-err.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Abrupt completion returned by GetIterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x] = iter; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-init-iter-no-close.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-init-iter-no-close.js new file mode 100644 index 0000000000..e732e7cb2d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-init-iter-no-close.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-no-close.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x] = iter; iterCount < 1; ) { + 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/dstr/var-ary-name-iter-val.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-name-iter-val.js new file mode 100644 index 0000000000..2ed173c001 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-name-iter-val.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-name-iter-val.case +// - src/dstr-binding/default/for-var.template +/*--- +description: SingleNameBinding with normal value iteration (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x, y, z] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..0c1dca7ab5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-elem-init.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-init.case +// - src/dstr-binding/default/for-var.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [[x, y, z] = [4, 5, 6]] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..63683edd92 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-elem-iter.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-iter.case +// - src/dstr-binding/default/for-var.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [[x, y, z] = [4, 5, 6]] = [[7, 8, 9]]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..aabe9affb1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-elision-init.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-init.case +// - src/dstr-binding/default/for-var.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [[,] = g()] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..2b1d75eaed --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-elision-iter.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-iter.case +// - src/dstr-binding/default/for-var.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [[,] = g()] = [[]]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..ccf471099b --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-empty-init.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-init.case +// - src/dstr-binding/default/for-var.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [[] = function() { initCount += 1; return iter; }()] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..4a13b8f650 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-empty-iter.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-iter.case +// - src/dstr-binding/default/for-var.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [[] = function() { initCount += 1; }()] = [[23]]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..fdc4dd526f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-rest-init.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-init.case +// - src/dstr-binding/default/for-var.template +/*--- +description: BindingElement with array binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [[...x] = values] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..bf23b35010 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-rest-iter.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-iter.case +// - src/dstr-binding/default/for-var.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [[...x] = function() { initCount += 1; }()] = [values]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..b43a20b073 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-ary-val-null.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-val-null.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Nested array destructuring with a null value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [[x]] = [null]; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..d68bc7555f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-exhausted.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-exhausted.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Destructuring initializer with an exhausted iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x = 23] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..50f5ad59e3 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-arrow.js @@ -0,0 +1,56 @@ +// 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-var.template +/*--- +description: SingleNameBinding does assign name to arrow functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [arrow = () => {}] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..5417255ee2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-class.js @@ -0,0 +1,58 @@ +// 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-var.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..a6a29e3811 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-cover.js @@ -0,0 +1,57 @@ +// 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-var.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [cover = (function () {}), xCover = (0, function() {})] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..28282c1ce4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-fn.js @@ -0,0 +1,57 @@ +// 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-var.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [fn = function () {}, xFn = function x() {}] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..d4f6ed5d07 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-fn-name-gen.js @@ -0,0 +1,58 @@ +// 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-var.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [gen = function* () {}, xGen = function* x() {}] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..02e831cb1c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-hole.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-hole.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Destructuring initializer with a "hole" (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x = 23] = [,]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..e722b63540 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-skipped.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-skipped.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [w = counter(), x = counter(), y = counter(), z = counter()] = [null, 0, false, '']; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..954647a2c1 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-throws.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-throws.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Destructuring initializer returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x = (function() { throw new Test262Error(); })()] = [undefined]; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..0735d20017 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-undef.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-undef.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Destructuring initializer with an undefined value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x = 23] = [undefined]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..e4d31ce81e --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-init-unresolvable.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-unresolvable.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Destructuring initializer is an unresolvable reference (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [ x = unresolvableReference ] = []; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..8295a4f98a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-complete.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-complete.case +// - src/dstr-binding/default/for-var.template +/*--- +description: SingleNameBinding when value iteration completes (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..1ce24f3e06 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-done.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-done.case +// - src/dstr-binding/default/for-var.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [_, x] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..a44a5fabc6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-step-err.js @@ -0,0 +1,58 @@ +// 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-var.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x] = g; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..2ac8c9c875 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-val-array-prototype.js @@ -0,0 +1,74 @@ +// 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-var.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x, y, z] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..094dd242f4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-val-err.js @@ -0,0 +1,69 @@ +// 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-var.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x] = g; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..e0a769ee4c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-id-iter-val.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val.case +// - src/dstr-binding/default/for-var.template +/*--- +description: SingleNameBinding when value iteration was completed previously (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [x, y, z] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..dc2ab3aee9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-id-init.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id-init.case +// - src/dstr-binding/default/for-var.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [{ x, y, z } = { x: 44, y: 55, z: 66 }] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..0c8e34f38f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-id.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id.case +// - src/dstr-binding/default/for-var.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [{ x, y, z } = { x: 44, y: 55, z: 66 }] = [{ x: 11, y: 22, z: 33 }]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..8c8e23edf5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-prop-id-init.js @@ -0,0 +1,66 @@ +// 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-var.template +/*--- +description: BindingElement with object binding pattern and initializer is used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = []; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..5a4b153ba5 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-prop-id.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id.case +// - src/dstr-binding/default/for-var.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = [{ u: 777, w: 888, y: 999 }]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..216a04f957 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-val-null.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-null.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Nested object destructuring with a null value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [{ x }] = [null]; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..2f9539ef9c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elem-obj-val-undef.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-undef.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Nested object destructuring with a value of `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [{ x }] = []; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..0a2f99fa8f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elision-exhausted.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-exhausted.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Elision accepts exhausted iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [,] = iter; iterCount < 1; ) { + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elision-iter-close.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elision-iter-close.js new file mode 100644 index 0000000000..99ebd655bb --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elision-iter-close.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-iter-close.case +// - src/dstr-binding/iter-close/for-var.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (var [,] = 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/dstr/var-ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..34f3d448a8 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elision-step-err.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-step-err.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Elision advances iterator and forwards abrupt completions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [,] = iter; iterCount < 1; ) { + return; + } +}); + +iter.next(); +assert.sameValue(following, 0, 'Iterator was properly closed.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elision.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elision.js new file mode 100644 index 0000000000..2a811a9707 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-elision.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Elision advances iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [,] = g(); iterCount < 1; ) { + 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/dstr/var-ary-ptrn-empty.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-empty.js new file mode 100644 index 0000000000..444d963a19 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-empty.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-empty.case +// - src/dstr-binding/default/for-var.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [] = iter; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..6d614de849 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-ary-elem.js @@ -0,0 +1,77 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elem.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Rest element containing an array BindingElementList pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...[x, y, z]] = [3, 4, 5]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..881d70548b --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-ary-elision.js @@ -0,0 +1,83 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elision.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Rest element containing an elision (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...[,]] = g(); iterCount < 1; ) { + 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/dstr/var-ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..ca48e43467 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-ary-empty.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-empty.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Rest element containing an "empty" array pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...[]] = iter; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..c8c9fdeb91 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-ary-rest.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-rest.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Rest element containing a rest element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...[...x]] = values; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..942a0ed9ee --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-direct.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-direct.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Lone rest element (direct binding) (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +includes: [compareArray.js] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...x] = [1]; iterCount < 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/dstr/var-ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..c3fa1a7240 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-elision-next-err.js @@ -0,0 +1,51 @@ +// 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-var.template +/*--- +description: Rest element following elision elements (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [, ...x] = iter; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..7bedba63d7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-elision.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Rest element following elision elements (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [ , , ...x] = values; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..8581df1c5a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-exhausted.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-exhausted.case +// - src/dstr-binding/default/for-var.template +/*--- +description: RestElement applied to an exhausted iterator (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [, , ...x] = [1, 2]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-rest-id-iter-close.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-iter-close.js new file mode 100644 index 0000000000..58e80c4044 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-iter-close.js @@ -0,0 +1,48 @@ +// 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-var.template +/*--- +description: The iterator is properly consumed by the destructuring pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. +---*/ +const iter = (function* () { + yield; + yield; +})(); + + +function fn() { + for (var [...x] = 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/dstr/var-ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..be83886322 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-iter-step-err.js @@ -0,0 +1,62 @@ +// 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-var.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...x] = iter; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..602a318e7a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id-iter-val-err.js @@ -0,0 +1,64 @@ +// 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-var.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...x] = iter; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id.js new file mode 100644 index 0000000000..eeb55e48b4 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-id.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Lone rest element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...x] = values; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..6926feb507 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-init-ary.js @@ -0,0 +1,51 @@ +// |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-var.template +/*--- +description: Rest element (nested array pattern) does not support initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...[ x ] = []] = []; iterCount < 1; ) { + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..1ad10c2b12 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-init-id.js @@ -0,0 +1,51 @@ +// |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-var.template +/*--- +description: Rest element (identifier) does not support initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...x = []] = []; iterCount < 1; ) { + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..dcf432fd60 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-init-obj.js @@ -0,0 +1,51 @@ +// |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-var.template +/*--- +description: Rest element (nested object pattern) does not support initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...{ x } = []] = []; iterCount < 1; ) { + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..5f394ad50c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-not-final-ary.js @@ -0,0 +1,51 @@ +// |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-var.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...[x], y] = [1, 2, 3]; iterCount < 1; ) { + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..86435acbf7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-not-final-id.js @@ -0,0 +1,51 @@ +// |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-var.template +/*--- +description: Rest element (identifier) may not be followed by any element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...x, y] = [1, 2, 3]; iterCount < 1; ) { + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..618185a34a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-not-final-obj.js @@ -0,0 +1,51 @@ +// |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-var.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...{ x }, y] = [1, 2, 3]; iterCount < 1; ) { + + iterCount += 1; +} + +assert.sameValue(iterCount, 1, 'Iteration occurred as expected'); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..8045fb2d8f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-obj-id.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-id.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Rest element containing an object binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...{ length }] = [1, 2, 3]; iterCount < 1; ) { + 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/dstr/var-ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..f73b4052f2 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-ary-ptrn-rest-obj-prop-id.js @@ -0,0 +1,62 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-prop-id.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Rest element containing an object binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var [...{ 0: v, 1: w, 2: x, 3: y, length: z }] = [7, 8, 9]; iterCount < 1; ) { + 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/dstr/var-obj-init-null.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-init-null.js new file mode 100644 index 0000000000..0525eb1192 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-init-null.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-null.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (var {} = null; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-init-undefined.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-init-undefined.js new file mode 100644 index 0000000000..6bdd7b18d9 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-init-undefined.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-undefined.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +assert.throws(TypeError, function() { + for (var {} = undefined; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-empty.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-empty.js new file mode 100644 index 0000000000..de5dd79e18 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-empty.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-empty.case +// - src/dstr-binding/default/for-var.template +/*--- +description: No property access occurs for an "empty" object binding pattern (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var {} = obj; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..3db67066c7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-get-value-err.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-get-value-err.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { poisoned } = poisonedProperty; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..8d63ad21ba --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-arrow.js @@ -0,0 +1,55 @@ +// 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-var.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { arrow = () => {} } = {}; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..75598dad43 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-class.js @@ -0,0 +1,57 @@ +// 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-var.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } } = {}; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..eb56cfa0d7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-cover.js @@ -0,0 +1,56 @@ +// 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-var.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { cover = (function () {}), xCover = (0, function() {}) } = {}; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..40f1d9ce0f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-fn.js @@ -0,0 +1,56 @@ +// 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-var.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { fn = function () {}, xFn = function x() {} } = {}; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..68de800a76 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-fn-name-gen.js @@ -0,0 +1,57 @@ +// 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-var.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { gen = function* () {}, xGen = function* x() {} } = {}; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..d03ad26240 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-skipped.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-skipped.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { w = counter(), x = counter(), y = counter(), z = counter() } = { w: null, x: 0, y: false, z: '' }; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..660bfe92d0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-throws.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-throws.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Error thrown when evaluating the initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { x = thrower() } = {}; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..e3527c794d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-init-unresolvable.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-unresolvable.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Destructuring initializer is an unresolvable reference (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { x = unresolvableReference } = {}; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..d3cb7fa306 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-id-trailing-comma.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-trailing-comma.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (var { x, } = { x: 23 }; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-list-err.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-list-err.js new file mode 100644 index 0000000000..09dc7e4dfc --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-list-err.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-list-err.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { a, b = thrower(), c = ++initCount } = {}; iterCount < 1; ) { + return; + } +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..ad154a1618 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-ary-init.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-init.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { w: [x, y, z] = [4, 5, 6] } = {}; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..525a68a8a7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-ary-trailing-comma.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-trailing-comma.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (var { x: [y], } = { x: [45] }; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..fbff3585f6 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-ary-value-null.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-value-null.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { w: [x, y, z] = [4, 5, 6] } = { w: null }; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-ary.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..3c4262b248 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-ary.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { w: [x, y, z] = [4, 5, 6] } = { w: [7, undefined, ] }; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..12c7faab71 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-eval-err.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-eval-err.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Evaluation of property name returns an abrupt completion (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { [thrower()]: x } = {}; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..c6e9060bac --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-get-value-err.js @@ -0,0 +1,54 @@ +// 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-var.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { poisoned: x = ++initEvalCount } = poisonedProperty; iterCount < 1; ) { + return; + } +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..596f91b9ac --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-init-skipped.js @@ -0,0 +1,71 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-skipped.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } = { s: null, u: 0, w: false, y: '' }; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..54c7598640 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-init-throws.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-throws.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Error thrown when evaluating the initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { x: y = thrower() } = {}; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..ef159092f7 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-init-unresolvable.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-unresolvable.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Destructuring initializer is an unresolvable reference (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { x: y = unresolvableReference } = {}; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..d385a4da51 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-init.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Binding as specified via property name, identifier, and initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var { x: y = 33 } = { }; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..ec712d14ef --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id-trailing-comma.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-trailing-comma.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +var iterCount = 0; + +for (var { x: y, } = { x: 23 }; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-prop-id.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id.js new file mode 100644 index 0000000000..54e457a1d0 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-id.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Binding as specified via property name and identifier (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +var iterCount = 0; + +for (var { x: y } = { x: 23 }; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..ecd9bcfe9c --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-obj-init.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-init.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: undefined }; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..35b6b5a780 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-obj-value-null.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-null.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: null }; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..e7c991650d --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-obj-value-undef.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-undef.case +// - src/dstr-binding/error/for-var.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { w: { x, y, z } = undefined } = { }; iterCount < 1; ) { + return; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-obj.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..d08728ab0f --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-prop-obj.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [destructuring-binding] +flags: [generated] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined 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 (var { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: { x: undefined, z: 7 } }; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-rest-getter.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..7deeeb3097 --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-rest-getter.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-getter.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. +---*/ +var count = 0; + +var iterCount = 0; + +for (var {...x} = { get v() { count++; return 2; } }; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..b20ee225cc --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-rest-skip-non-enumerable.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-skip-non-enumerable.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Rest object doesn't contain non-enumerable properties (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. +---*/ +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); + +var iterCount = 0; + +for (var {...rest} = o; iterCount < 1; ) { + 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/dstr/var-obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..ff4410b29a --- /dev/null +++ b/js/src/tests/test262/language/statements/for/dstr/var-obj-ptrn-rest-val-obj.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-val-obj.case +// - src/dstr-binding/default/for-var.template +/*--- +description: Rest object contains just unextracted data (for statement) +esid: sec-for-statement-runtime-semantics-labelledevaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. +---*/ + +var iterCount = 0; + +for (var {a, b, ...rest} = {x: 1, y: 2, a: 5, b: 3}; iterCount < 1; ) { + 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); |