diff options
Diffstat (limited to 'js/src/tests/test262/language/statements/let')
151 files changed, 4721 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/let/block-local-closure-get-before-initialization.js b/js/src/tests/test262/language/statements/let/block-local-closure-get-before-initialization.js new file mode 100644 index 0000000000..fd97ac02b3 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/block-local-closure-get-before-initialization.js @@ -0,0 +1,19 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: block local closure [[Get]] before initialization. + (TDZ, Temporal Dead Zone) +---*/ +{ + function f() { return x + 1; } + + assert.throws(ReferenceError, function() { + f(); + }); + + let x; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/block-local-closure-set-before-initialization.js b/js/src/tests/test262/language/statements/let/block-local-closure-set-before-initialization.js new file mode 100644 index 0000000000..76ed35c598 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/block-local-closure-set-before-initialization.js @@ -0,0 +1,19 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: block local closure [[Set]] before initialization. + (TDZ, Temporal Dead Zone) +---*/ +{ + function f() { x = 1; } + + assert.throws(ReferenceError, function() { + f(); + }); + + let x; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/block-local-use-before-initialization-in-declaration-statement.js b/js/src/tests/test262/language/statements/let/block-local-use-before-initialization-in-declaration-statement.js new file mode 100644 index 0000000000..debfa1cefe --- /dev/null +++ b/js/src/tests/test262/language/statements/let/block-local-use-before-initialization-in-declaration-statement.js @@ -0,0 +1,15 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: block local use before initialization in declaration statement. + (TDZ, Temporal Dead Zone) +---*/ +assert.throws(ReferenceError, function() { + { + let x = x + 1; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/block-local-use-before-initialization-in-prior-statement.js b/js/src/tests/test262/language/statements/let/block-local-use-before-initialization-in-prior-statement.js new file mode 100644 index 0000000000..b54d51a036 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/block-local-use-before-initialization-in-prior-statement.js @@ -0,0 +1,15 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: block local use before initialization in prior statement. + (TDZ, Temporal Dead Zone) +---*/ +assert.throws(ReferenceError, function() { + { + x; let x; + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/browser.js b/js/src/tests/test262/language/statements/let/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/browser.js diff --git a/js/src/tests/test262/language/statements/let/cptn-value.js b/js/src/tests/test262/language/statements/let/cptn-value.js new file mode 100644 index 0000000000..f32f676e10 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/cptn-value.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +es6id: 13.3.1.4 +description: Returns an empty completion +info: | + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). +---*/ + +assert.sameValue( + eval('let test262id1;'), undefined, 'Single declaration without initializer' +); +assert.sameValue( + eval('let test262id2 = 2;'), + undefined, + 'Single declaration bearing initializer' +); +assert.sameValue( + eval('let test262id3 = 3, test262id4;'), + undefined, + 'Multiple declarations, final without initializer' +); +assert.sameValue( + eval('let test262id5, test262id6 = 6;'), + undefined, + 'Multiple declarations, final bearing initializer' +); + +assert.sameValue(eval('7; let test262id8;'), 7); +assert.sameValue(eval('9; let test262id10 = 10;'), 9); +assert.sameValue(eval('11; let test262id12 = 12, test262id13;'), 11); +assert.sameValue(eval('14; let test262id15, test262id16 = 16;'), 14); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-close.js b/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-close.js new file mode 100644 index 0000000000..7c8c73e2b0 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-close.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-close.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + 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 {}; + } + }; +}; + +let [x] = iter; + +assert.sameValue(doneCallCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..f31b786c1f --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-get-err-array-prototype.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err-array-prototype.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Abrupt completion returned by GetIterator (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + 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() { + let [x, y, z] = [1, 2, 3]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-get-err.js b/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-get-err.js new file mode 100644 index 0000000000..a074c57553 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-get-err.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Abrupt completion returned by GetIterator (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + 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() { + let [x] = iter; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-no-close.js b/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-no-close.js new file mode 100644 index 0000000000..f787d6bbdc --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-init-iter-no-close.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-no-close.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + 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 {}; + } + }; +}; + +let [x] = iter; + +assert.sameValue(doneCallCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-name-iter-val.js b/js/src/tests/test262/language/statements/let/dstr/ary-name-iter-val.js new file mode 100644 index 0000000000..9dd83be9a1 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-name-iter-val.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-name-iter-val.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: SingleNameBinding with normal value iteration (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [x, y, z] = [1, 2, 3]; + +assert.sameValue(x, 1); +assert.sameValue(y, 2); +assert.sameValue(z, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..d0ac82fdeb --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elem-init.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-init.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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. +---*/ + +let [[x, y, z] = [4, 5, 6]] = []; + +assert.sameValue(x, 4); +assert.sameValue(y, 5); +assert.sameValue(z, 6); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..e7b74dcbf4 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elem-iter.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-iter.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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. +---*/ + +let [[x, y, z] = [4, 5, 6]] = [[7, 8, 9]]; + +assert.sameValue(x, 7); +assert.sameValue(y, 8); +assert.sameValue(z, 9); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..9a7f741d75 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elision-init.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-init.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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; +}; + +let [[,] = g()] = []; + +assert.sameValue(first, 1); +assert.sameValue(second, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..7db10de306 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-elision-iter.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-iter.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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; +}; + +let [[,] = g()] = [[]]; + +assert.sameValue(callCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..a1c84bcc7b --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-empty-init.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-init.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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; }(); + +let [[] = function() { initCount += 1; return iter; }()] = []; + +assert.sameValue(initCount, 1); +assert.sameValue(iterCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..62514d45da --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-empty-iter.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-iter.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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; + +let [[] = function() { initCount += 1; }()] = [[23]]; + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..5c576005d8 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-rest-init.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-init.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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]; + +let [[...x] = values] = []; + +assert(Array.isArray(x)); +assert.sameValue(x[0], 2); +assert.sameValue(x[1], 1); +assert.sameValue(x[2], 3); +assert.sameValue(x.length, 3); +assert.notSameValue(x, values); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..03d22a869c --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-rest-iter.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-iter.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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; + +let [[...x] = function() { initCount += 1; }()] = [values]; + +assert(Array.isArray(x)); +assert.sameValue(x[0], 2); +assert.sameValue(x[1], 1); +assert.sameValue(x[2], 3); +assert.sameValue(x.length, 3); +assert.notSameValue(x, values); +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..123b499419 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-ary-val-null.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-val-null.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Nested array destructuring with a null value (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let [[x]] = [null]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..b47f0379de --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-exhausted.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-exhausted.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Destructuring initializer with an exhausted iterator (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [x = 23] = []; + +assert.sameValue(x, 23); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..99c94f72ee --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js @@ -0,0 +1,38 @@ +// 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/let-stmt.template +/*--- +description: SingleNameBinding does assign name to arrow functions (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [arrow = () => {}] = []; + +assert.sameValue(arrow.name, 'arrow'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..32b66db8f8 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-class.js @@ -0,0 +1,40 @@ +// 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/let-stmt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }] = []; + +assert.sameValue(cls.name, 'cls'); +assert.notSameValue(xCls.name, 'xCls'); +assert.notSameValue(xCls2.name, 'xCls2'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..5f52505bd5 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-cover.js @@ -0,0 +1,39 @@ +// 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/let-stmt.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [cover = (function () {}), xCover = (0, function() {})] = []; + +assert.sameValue(cover.name, 'cover'); +assert.notSameValue(xCover.name, 'xCover'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..5f432c3482 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-fn.js @@ -0,0 +1,39 @@ +// 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/let-stmt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [fn = function () {}, xFn = function x() {}] = []; + +assert.sameValue(fn.name, 'fn'); +assert.notSameValue(xFn.name, 'xFn'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..592aea0ceb --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-fn-name-gen.js @@ -0,0 +1,40 @@ +// 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/let-stmt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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). + +---*/ + +let [gen = function* () {}, xGen = function* x() {}] = []; + +assert.sameValue(gen.name, 'gen'); +assert.notSameValue(xGen.name, 'xGen'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..9d0bc8cc7f --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-hole.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-hole.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Destructuring initializer with a "hole" (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [x = 23] = [,]; + +assert.sameValue(x, 23); +// another statement + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..de2e563261 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-skipped.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-skipped.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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; +} + +let [w = counter(), x = counter(), y = counter(), z = counter()] = [null, 0, false, '']; + +assert.sameValue(w, null); +assert.sameValue(x, 0); +assert.sameValue(y, false); +assert.sameValue(z, ''); +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..f73536e38a --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-throws.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-throws.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Destructuring initializer returns an abrupt completion (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let [x = (function() { throw new Test262Error(); })()] = [undefined]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..2c05ca4ff4 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-undef.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-undef.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Destructuring initializer with an undefined value (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [x = 23] = [undefined]; + +assert.sameValue(x, 23); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..41577595fc --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-init-unresolvable.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-unresolvable.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Destructuring initializer is an unresolvable reference (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let [ x = unresolvableReference ] = []; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..4f774ff808 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-complete.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-complete.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: SingleNameBinding when value iteration completes (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [x] = []; + +assert.sameValue(x, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..812c416ae7 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-done.js @@ -0,0 +1,35 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-done.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: SingleNameBinding when value iteration was completed previously (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [_, x] = []; + +assert.sameValue(x, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..075cf02863 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-step-err.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-step-err.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + 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() { + let [x] = g; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..109de67a37 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js @@ -0,0 +1,56 @@ +// 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/let-stmt.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [Symbol.iterator, generators, destructuring-binding] +flags: [generated] +info: | + 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; + } +}; + +let [x, y, z] = [1, 2, 3]; + +assert.sameValue(x, 1); +assert.sameValue(y, 2); +assert.sameValue(z, 42); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..780c85feeb --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-val-err.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-err.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + 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() { + let [x] = g; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..f2c1ebba91 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-id-iter-val.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: SingleNameBinding when value iteration was completed previously (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [x, y, z] = [1, 2, 3]; + +assert.sameValue(x, 1); +assert.sameValue(y, 2); +assert.sameValue(z, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..2e0b2fb753 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-id-init.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id-init.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with object binding pattern and initializer is used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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. +---*/ + +let [{ x, y, z } = { x: 44, y: 55, z: 66 }] = []; + +assert.sameValue(x, 44); +assert.sameValue(y, 55); +assert.sameValue(z, 66); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..bbdfb64cb5 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-id.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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. +---*/ + +let [{ x, y, z } = { x: 44, y: 55, z: 66 }] = [{ x: 11, y: 22, z: 33 }]; + +assert.sameValue(x, 11); +assert.sameValue(y, 22); +assert.sameValue(z, 33); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..140efb9b19 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-prop-id-init.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id-init.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with object binding pattern and initializer is used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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. +---*/ + +let [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = []; + +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; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..c580f7c1fe --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-prop-id.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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. +---*/ + +let [{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = [{ u: 777, w: 888, y: 999 }]; + +assert.sameValue(v, 777); +assert.sameValue(x, 888); +assert.sameValue(z, 999); + +assert.throws(ReferenceError, function() { + u; +}); +assert.throws(ReferenceError, function() { + w; +}); +assert.throws(ReferenceError, function() { + y; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..d9aba4592c --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-val-null.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-null.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Nested object destructuring with a null value (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let [{ x }] = [null]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..b88f2e22b2 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elem-obj-val-undef.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-undef.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Nested object destructuring with a value of `undefined` (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let [{ x }] = []; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..db120423e7 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elision-exhausted.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-exhausted.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Elision accepts exhausted iterator (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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(); + +let [,] = iter; + + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..072891f08b --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elision-step-err.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-step-err.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Elision advances iterator and forwards abrupt completions (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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() { + let [,] = iter; +}); + +iter.next(); +assert.sameValue(following, 0, 'Iterator was properly closed.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elision.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elision.js new file mode 100644 index 0000000000..71e129bdc7 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-elision.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Elision advances iterator (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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; +}; + +let [,] = g(); + +assert.sameValue(first, 1); +assert.sameValue(second, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-empty.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-empty.js new file mode 100644 index 0000000000..d4d6e28157 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-empty.js @@ -0,0 +1,35 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-empty.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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; +}(); + +let [] = iter; + +assert.sameValue(iterations, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..990517c33d --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-elem.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elem.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Rest element containing an array BindingElementList pattern (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let [...[x, y, z]] = [3, 4, 5]; + +assert.sameValue(x, 3); +assert.sameValue(y, 4); +assert.sameValue(z, 5); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..4546cbe0a9 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-elision.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elision.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Rest element containing an elision (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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; +}; + +let [...[,]] = g(); + +assert.sameValue(first, 1); +assert.sameValue(second, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..eef1caaa8d --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-empty.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-empty.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Rest element containing an "empty" array pattern (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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; +}(); + +let [...[]] = iter; + +assert.sameValue(iterations, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..82b68650f9 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-ary-rest.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-rest.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Rest element containing a rest element (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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]; + +let [...[...x]] = values; + +assert(Array.isArray(x)); +assert.sameValue(x.length, 3); +assert.sameValue(x[0], 1); +assert.sameValue(x[1], 2); +assert.sameValue(x[2], 3); +assert.notSameValue(x, values); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..c04060f9cd --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-direct.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-direct.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Lone rest element (direct binding) (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +includes: [compareArray.js] +info: | + 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. + +---*/ + +let [...x] = [1]; + +assert(Array.isArray(x)); +assert.compareArray(x, [1]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..96c0da10c5 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-elision-next-err.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision-next-err.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Rest element following elision elements (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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() { + let [, ...x] = iter; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..7c4b92ee9e --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-elision.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Rest element following elision elements (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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]; + +let [ , , ...x] = values; + +assert(Array.isArray(x)); +assert.sameValue(x.length, 3); +assert.sameValue(x[0], 3); +assert.sameValue(x[1], 4); +assert.sameValue(x[2], 5); +assert.notSameValue(x, values); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..8c27a133a4 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-exhausted.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-exhausted.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: RestElement applied to an exhausted iterator (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + 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). + +---*/ + +let [, , ...x] = [1, 2]; + +assert(Array.isArray(x)); +assert.sameValue(x.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..6eca0d9d4c --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-iter-step-err.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-step-err.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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() { + let [...x] = iter; +}); + +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/let/dstr/ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..001cf5ea52 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id-iter-val-err.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-val-err.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [Symbol.iterator, destructuring-binding] +flags: [generated] +info: | + 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() { + let [...x] = iter; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id.js new file mode 100644 index 0000000000..d5c0c3001c --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-id.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Lone rest element (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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]; + +let [...x] = values; + +assert(Array.isArray(x)); +assert.sameValue(x.length, 3); +assert.sameValue(x[0], 1); +assert.sameValue(x[1], 2); +assert.sameValue(x[2], 3); +assert.notSameValue(x, values); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..35216536ef --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-init-ary.js @@ -0,0 +1,33 @@ +// |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/let-stmt.template +/*--- +description: Rest element (nested array pattern) does not support initializer (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 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(); + +let [...[ x ] = []] = []; + + diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..75400737e9 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-init-id.js @@ -0,0 +1,33 @@ +// |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/let-stmt.template +/*--- +description: Rest element (identifier) does not support initializer (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 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(); + +let [...x = []] = []; + + diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..967d3cbfdb --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-init-obj.js @@ -0,0 +1,33 @@ +// |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/let-stmt.template +/*--- +description: Rest element (nested object pattern) does not support initializer (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 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(); + +let [...{ x } = []] = []; + + diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..06f6e51ebc --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-not-final-ary.js @@ -0,0 +1,33 @@ +// |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/let-stmt.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 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(); + +let [...[x], y] = [1, 2, 3]; + + diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..eb4734b341 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-not-final-id.js @@ -0,0 +1,33 @@ +// |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/let-stmt.template +/*--- +description: Rest element (identifier) may not be followed by any element (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 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(); + +let [...x, y] = [1, 2, 3]; + + diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..91769d44d2 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-not-final-obj.js @@ -0,0 +1,33 @@ +// |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/let-stmt.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + 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(); + +let [...{ x }, y] = [1, 2, 3]; + + diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..0ab9b660f2 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-obj-id.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-id.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Rest element containing an object binding pattern (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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 }] = [1, 2, 3]; + +assert.sameValue(length, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..6d892bceec --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/ary-ptrn-rest-obj-prop-id.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-prop-id.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Rest element containing an object binding pattern (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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"; + +let [...{ 0: v, 1: w, 2: x, 3: y, length: z }] = [7, 8, 9]; + +assert.sameValue(v, 7); +assert.sameValue(w, 8); +assert.sameValue(x, 9); +assert.sameValue(y, undefined); +assert.sameValue(z, 3); + +assert.sameValue(length, "outer", "the length prop is not set as a binding name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/browser.js b/js/src/tests/test262/language/statements/let/dstr/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/browser.js diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-init-null.js b/js/src/tests/test262/language/statements/let/dstr/obj-init-null.js new file mode 100644 index 0000000000..f9f11094e3 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-init-null.js @@ -0,0 +1,30 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-null.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let {} = null; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-init-undefined.js b/js/src/tests/test262/language/statements/let/dstr/obj-init-undefined.js new file mode 100644 index 0000000000..9bcdb7b965 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-init-undefined.js @@ -0,0 +1,30 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-undefined.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let {} = undefined; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-empty.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-empty.js new file mode 100644 index 0000000000..f5174f38cc --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-empty.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-empty.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: No property access occurs for an "empty" object binding pattern (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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; + } +}); + +let {} = obj; + +assert.sameValue(accessCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..259b172d79 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-get-value-err.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-get-value-err.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let { poisoned } = poisonedProperty; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..96d7e4b3dc --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-arrow.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-arrow.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let { arrow = () => {} } = {}; + +assert.sameValue(arrow.name, 'arrow'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..8d45be754a --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-class.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-class.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let { cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } } = {}; + +assert.sameValue(cls.name, 'cls'); +assert.notSameValue(xCls.name, 'xCls'); +assert.notSameValue(xCls2.name, 'xCls2'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..764d02062a --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-cover.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-cover.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let { cover = (function () {}), xCover = (0, function() {}) } = {}; + +assert.sameValue(cover.name, 'cover'); +assert.notSameValue(xCover.name, 'xCover'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..bd7698ad7c --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-fn.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-fn.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let { fn = function () {}, xFn = function x() {} } = {}; + +assert.sameValue(fn.name, 'fn'); +assert.notSameValue(xFn.name, 'xFn'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..700bbfb1f2 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-fn-name-gen.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-gen.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [generators, destructuring-binding] +flags: [generated] +info: | + 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). + +---*/ + +let { gen = function* () {}, xGen = function* x() {} } = {}; + +assert.sameValue(gen.name, 'gen'); +assert.notSameValue(xGen.name, 'xGen'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..0193b5dc2d --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-skipped.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-skipped.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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; +} + +let { w = counter(), x = counter(), y = counter(), z = counter() } = { w: null, x: 0, y: false, z: '' }; + +assert.sameValue(w, null); +assert.sameValue(x, 0); +assert.sameValue(y, false); +assert.sameValue(z, ''); +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..55cfae552c --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-throws.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-throws.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Error thrown when evaluating the initializer (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let { x = thrower() } = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..9c3114d452 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-init-unresolvable.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-unresolvable.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Destructuring initializer is an unresolvable reference (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let { x = unresolvableReference } = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..30c9ffde34 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-id-trailing-comma.js @@ -0,0 +1,31 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-trailing-comma.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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] , } +---*/ + +let { x, } = { x: 23 }; + +assert.sameValue(x, 23); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-list-err.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-list-err.js new file mode 100644 index 0000000000..92c5711bcb --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-list-err.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-list-err.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let { a, b = thrower(), c = ++initCount } = {}; +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..4d452c8f29 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary-init.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-init.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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. +---*/ + +let { w: [x, y, z] = [4, 5, 6] } = {}; + +assert.sameValue(x, 4); +assert.sameValue(y, 5); +assert.sameValue(z, 6); + +assert.throws(ReferenceError, function() { + w; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..a93be03616 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary-trailing-comma.js @@ -0,0 +1,31 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-trailing-comma.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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] , } +---*/ + +let { x: [y], } = { x: [45] }; + +assert.sameValue(y,45); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..814e2eba2f --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary-value-null.js @@ -0,0 +1,32 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-value-null.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let { w: [x, y, z] = [4, 5, 6] } = { w: null }; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..76da804abf --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-ary.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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. +---*/ + +let { w: [x, y, z] = [4, 5, 6] } = { w: [7, undefined, ] }; + +assert.sameValue(x, 7); +assert.sameValue(y, undefined); +assert.sameValue(z, undefined); + +assert.throws(ReferenceError, function() { + w; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..1f58ab7c97 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-eval-err.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-eval-err.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Evaluation of property name returns an abrupt completion (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let { [thrower()]: x } = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..3ee31ad290 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-get-value-err.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-get-value-err.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let { poisoned: x = ++initEvalCount } = poisonedProperty; +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..aef6d1236e --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init-skipped.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-skipped.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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; +} + +let { s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } = { s: null, u: 0, w: false, y: '' }; + +assert.sameValue(t, null); +assert.sameValue(v, 0); +assert.sameValue(x, false); +assert.sameValue(z, ''); +assert.sameValue(initCount, 0); + +assert.throws(ReferenceError, function() { + s; +}); +assert.throws(ReferenceError, function() { + u; +}); +assert.throws(ReferenceError, function() { + w; +}); +assert.throws(ReferenceError, function() { + y; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..986106e695 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init-throws.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-throws.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Error thrown when evaluating the initializer (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let { x: y = thrower() } = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..38d7d93e19 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init-unresolvable.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-unresolvable.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Destructuring initializer is an unresolvable reference (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let { x: y = unresolvableReference } = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..3e38ddd047 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-init.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Binding as specified via property name, identifier, and initializer (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let { x: y = 33 } = { }; + +assert.sameValue(y, 33); +assert.throws(ReferenceError, function() { + x; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..f4f096c0a4 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id-trailing-comma.js @@ -0,0 +1,35 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-trailing-comma.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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] , } +---*/ + +let { x: y, } = { x: 23 }; + +assert.sameValue(y, 23); + +assert.throws(ReferenceError, function() { + x; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id.js new file mode 100644 index 0000000000..916ce1d723 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-id.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Binding as specified via property name and identifier (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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). +---*/ + +let { x: y } = { x: 23 }; + +assert.sameValue(y, 23); +assert.throws(ReferenceError, function() { + x; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..ff3b9aa914 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj-init.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-init.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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. +---*/ + +let { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: undefined }; + +assert.sameValue(x, 4); +assert.sameValue(y, 5); +assert.sameValue(z, 6); + +assert.throws(ReferenceError, function() { + w; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..adbfb90561 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj-value-null.js @@ -0,0 +1,32 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-null.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: null }; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..714119a6f3 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj-value-undef.js @@ -0,0 +1,32 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-undef.case +// - src/dstr-binding/error/let-stmt.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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() { + let { w: { x, y, z } = undefined } = { }; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..e9274d324b --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-prop-obj.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [destructuring-binding] +flags: [generated] +info: | + 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. +---*/ + +let { w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: { x: undefined, z: 7 } }; + +assert.sameValue(x, undefined); +assert.sameValue(y, undefined); +assert.sameValue(z, 7); + +assert.throws(ReferenceError, function() { + w; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-rest-getter.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..83b6b5c774 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-rest-getter.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-getter.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + 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; + +let {...x} = { get v() { count++; return 2; } }; + +assert.sameValue(count, 1); + +verifyProperty(x, "v", { + enumerable: true, + writable: true, + configurable: true, + value: 2 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..a1819d293e --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-rest-skip-non-enumerable.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-skip-non-enumerable.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Rest object doesn't contain non-enumerable properties (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + 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 }); + +let {...rest} = o; + +assert.sameValue(rest.x, undefined); + +verifyProperty(rest, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 +}); + +verifyProperty(rest, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 4 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..456f5e1811 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/obj-ptrn-rest-val-obj.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-val-obj.case +// - src/dstr-binding/default/let-stmt.template +/*--- +description: Rest object contains just unextracted data (`let` statement) +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +features: [object-rest, destructuring-binding] +flags: [generated] +includes: [propertyHelper.js] +info: | + 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. +---*/ + +let {a, b, ...rest} = {x: 1, y: 2, a: 5, b: 3}; + +assert.sameValue(rest.a, undefined); +assert.sameValue(rest.b, undefined); + +verifyProperty(rest, "x", { + enumerable: true, + writable: true, + configurable: true, + value: 1 +}); + +verifyProperty(rest, "y", { + enumerable: true, + writable: true, + configurable: true, + value: 2 +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/dstr/shell.js b/js/src/tests/test262/language/statements/let/dstr/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/dstr/shell.js diff --git a/js/src/tests/test262/language/statements/let/fn-name-arrow.js b/js/src/tests/test262/language/statements/let/fn-name-arrow.js new file mode 100644 index 0000000000..d83d9fa27b --- /dev/null +++ b/js/src/tests/test262/language/statements/let/fn-name-arrow.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (ArrowFunction) +info: | + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +let arrow = () => {}; + +assert.sameValue(arrow.name, 'arrow'); +verifyNotEnumerable(arrow, 'name'); +verifyNotWritable(arrow, 'name'); +verifyConfigurable(arrow, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/fn-name-class.js b/js/src/tests/test262/language/statements/let/fn-name-class.js new file mode 100644 index 0000000000..26af323891 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/fn-name-class.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (ClassExpression) +info: | + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +features: [class] +---*/ + +let xCls = class x {}; +let cls = class {}; +let xCls2 = class { static name() {} }; + +assert.notSameValue(xCls.name, 'xCls'); +assert.notSameValue(xCls2.name, 'xCls2'); + +assert.sameValue(cls.name, 'cls'); +verifyNotEnumerable(cls, 'name'); +verifyNotWritable(cls, 'name'); +verifyConfigurable(cls, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/fn-name-cover.js b/js/src/tests/test262/language/statements/let/fn-name-cover.js new file mode 100644 index 0000000000..e997179639 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/fn-name-cover.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: > + Assignment of function `name` attribute (CoverParenthesizedExpression) +info: | + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +let xCover = (0, function() {}); +let cover = (function() {}); + +assert(xCover.name !== 'xCover'); + +assert.sameValue(cover.name, 'cover'); +verifyNotEnumerable(cover, 'name'); +verifyNotWritable(cover, 'name'); +verifyConfigurable(cover, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/fn-name-fn.js b/js/src/tests/test262/language/statements/let/fn-name-fn.js new file mode 100644 index 0000000000..608fe2f6b6 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/fn-name-fn.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (FunctionExpression) +info: | + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +let xFn = function x() {}; +let fn = function() {}; + +assert(xFn.name !== 'xFn'); + +assert.sameValue(fn.name, 'fn'); +verifyNotEnumerable(fn, 'name'); +verifyNotWritable(fn, 'name'); +verifyConfigurable(fn, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/fn-name-gen.js b/js/src/tests/test262/language/statements/let/fn-name-gen.js new file mode 100644 index 0000000000..849c852637 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/fn-name-gen.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (GeneratorExpression) +info: | + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +features: [generators] +---*/ + +let xGen = function* x() {}; +let gen = function*() {}; + +assert(xGen.name !== 'xGen'); + +assert.sameValue(gen.name, 'gen'); +verifyNotEnumerable(gen, 'name'); +verifyNotWritable(gen, 'name'); +verifyConfigurable(gen, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/function-local-closure-get-before-initialization.js b/js/src/tests/test262/language/statements/let/function-local-closure-get-before-initialization.js new file mode 100644 index 0000000000..f8c3bbddbc --- /dev/null +++ b/js/src/tests/test262/language/statements/let/function-local-closure-get-before-initialization.js @@ -0,0 +1,19 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: function local closure [[Get]] before initialization. + (TDZ, Temporal Dead Zone) +---*/ +(function() { + function f() { return x + 1; } + + assert.throws(ReferenceError, function() { + f(); + }); + + let x; +}()); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/function-local-closure-set-before-initialization.js b/js/src/tests/test262/language/statements/let/function-local-closure-set-before-initialization.js new file mode 100644 index 0000000000..8c9118b8c1 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/function-local-closure-set-before-initialization.js @@ -0,0 +1,19 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: function local closure [[Set]] before initialization. + (TDZ, Temporal Dead Zone) +---*/ +(function() { + function f() { x = 1; } + + assert.throws(ReferenceError, function() { + f(); + }); + + let x; +}()); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/function-local-use-before-initialization-in-declaration-statement.js b/js/src/tests/test262/language/statements/let/function-local-use-before-initialization-in-declaration-statement.js new file mode 100644 index 0000000000..74dd7dca71 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/function-local-use-before-initialization-in-declaration-statement.js @@ -0,0 +1,15 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: function local use before initialization in declaration statement. + (TDZ, Temporal Dead Zone) +---*/ +assert.throws(ReferenceError, function() { + (function() { + let x = x + 1; + }()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/function-local-use-before-initialization-in-prior-statement.js b/js/src/tests/test262/language/statements/let/function-local-use-before-initialization-in-prior-statement.js new file mode 100644 index 0000000000..eb4c8eff99 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/function-local-use-before-initialization-in-prior-statement.js @@ -0,0 +1,15 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: function local use before initialization in prior statement. + (TDZ, Temporal Dead Zone) +---*/ +assert.throws(ReferenceError, function() { + (function() { + x; let x; + }()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/global-closure-get-before-initialization.js b/js/src/tests/test262/language/statements/let/global-closure-get-before-initialization.js new file mode 100644 index 0000000000..55b667d8ed --- /dev/null +++ b/js/src/tests/test262/language/statements/let/global-closure-get-before-initialization.js @@ -0,0 +1,17 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: global closure [[Get]] before initialization. + (TDZ, Temporal Dead Zone) +---*/ +function f() { return x + 1; } + +assert.throws(ReferenceError, function() { + f(); +}); + +let x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/global-closure-set-before-initialization.js b/js/src/tests/test262/language/statements/let/global-closure-set-before-initialization.js new file mode 100644 index 0000000000..a1db51c8b5 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/global-closure-set-before-initialization.js @@ -0,0 +1,17 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: global closure [[Set]] before initialization. + (TDZ, Temporal Dead Zone) +---*/ +function f() { x = 1; } + +assert.throws(ReferenceError, function() { + f(); +}); + +let x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/global-use-before-initialization-in-declaration-statement.js b/js/src/tests/test262/language/statements/let/global-use-before-initialization-in-declaration-statement.js new file mode 100644 index 0000000000..ff38195a70 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/global-use-before-initialization-in-declaration-statement.js @@ -0,0 +1,13 @@ +// |reftest| error:ReferenceError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: global use before initialization in declaration statement. + (TDZ, Temporal Dead Zone) +negative: + phase: runtime + type: ReferenceError +---*/ +let x = x + 1; diff --git a/js/src/tests/test262/language/statements/let/global-use-before-initialization-in-prior-statement.js b/js/src/tests/test262/language/statements/let/global-use-before-initialization-in-prior-statement.js new file mode 100644 index 0000000000..c8487a32cb --- /dev/null +++ b/js/src/tests/test262/language/statements/let/global-use-before-initialization-in-prior-statement.js @@ -0,0 +1,13 @@ +// |reftest| error:ReferenceError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: global use before initialization in prior statement. + (TDZ, Temporal Dead Zone) +negative: + phase: runtime + type: ReferenceError +---*/ +x; let x; diff --git a/js/src/tests/test262/language/statements/let/redeclaration-error-from-within-strict-mode-function.js b/js/src/tests/test262/language/statements/let/redeclaration-error-from-within-strict-mode-function.js new file mode 100644 index 0000000000..6a60c8f343 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/redeclaration-error-from-within-strict-mode-function.js @@ -0,0 +1,16 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + Redeclaration error within strict mode function inside non-strict code. +negative: + phase: parse + type: SyntaxError +flags: [noStrict] +---*/ + +$DONOTEVALUATE(); +(function() { 'use strict'; { let f; var f; } }) + diff --git a/js/src/tests/test262/language/statements/let/shell.js b/js/src/tests/test262/language/statements/let/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/shell.js diff --git a/js/src/tests/test262/language/statements/let/static-init-await-binding-invalid.js b/js/src/tests/test262/language/statements/let/static-init-await-binding-invalid.js new file mode 100644 index 0000000000..842867b48b --- /dev/null +++ b/js/src/tests/test262/language/statements/let/static-init-await-binding-invalid.js @@ -0,0 +1,27 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-class-definitions-static-semantics-early-errors +description: BindingIdentifier may not be `await` within class static blocks +info: | + BindingIdentifier : Identifier + + [...] + - It is a Syntax Error if the code matched by this production is nested, + directly or indirectly (but not crossing function or static initialization + block boundaries), within a ClassStaticBlock and the StringValue of + Identifier is "await". +negative: + phase: parse + type: SyntaxError +features: [class-static-block] +---*/ + +$DONOTEVALUATE(); + +class C { + static { + let await; + } +} diff --git a/js/src/tests/test262/language/statements/let/static-init-await-binding-valid.js b/js/src/tests/test262/language/statements/let/static-init-await-binding-valid.js new file mode 100644 index 0000000000..e6a531cd3d --- /dev/null +++ b/js/src/tests/test262/language/statements/let/static-init-await-binding-valid.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-class-definitions-static-semantics-early-errors +description: The `await` keyword is interpreted as an identifier within arrow function bodies +info: | + ClassStaticBlockBody : ClassStaticBlockStatementList + + [...] + - It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true. +features: [class-static-block] +---*/ + +class C { + static { + (() => { let await; }); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/browser.js b/js/src/tests/test262/language/statements/let/syntax/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/browser.js diff --git a/js/src/tests/test262/language/statements/let/syntax/escaped-let.js b/js/src/tests/test262/language/statements/let/syntax/escaped-let.js new file mode 100644 index 0000000000..04c60ff840 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/escaped-let.js @@ -0,0 +1,29 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-grammar-notation +description: > + The `let` contextual keyword must not contain Unicode escape sequences. +info: | + Terminal symbols are shown + in fixed width font, both in the productions of the grammars and throughout this + specification whenever the text directly refers to such a terminal symbol. These + are to appear in a script exactly as written. All terminal symbol code points + specified in this way are to be understood as the appropriate Unicode code points + from the Basic Latin range, as opposed to any similar-looking code points from + other Unicode ranges. +flags: [noStrict] +---*/ + +// Add a global property "let", so we won't get a runtime reference error below. +this.let = 0; + +l\u0065t // ASI +a; + +// If the parser treated the previous escaped "let" as a lexical declaration, +// this variable declaration will result an early syntax error. +var a; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/identifier-let-allowed-as-lefthandside-expression-strict-strict.js b/js/src/tests/test262/language/statements/let/syntax/identifier-let-allowed-as-lefthandside-expression-strict-strict.js new file mode 100644 index 0000000000..3d8af4f80e --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/identifier-let-allowed-as-lefthandside-expression-strict-strict.js @@ -0,0 +1,19 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.6.0.1 +description: > + for declaration: + identifier "let" disallowed as lefthandside expression in strict mode +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +var o = { a: 1 }; +for (let in o) { } + diff --git a/js/src/tests/test262/language/statements/let/syntax/identifier-let-disallowed-as-boundname.js b/js/src/tests/test262/language/statements/let/syntax/identifier-let-disallowed-as-boundname.js new file mode 100644 index 0000000000..f93207d844 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/identifier-let-disallowed-as-boundname.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.6.4.1 +description: > + It is a Syntax Error if the BoundNames of ForDeclaration contains "let". +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +for (let let in {}) { } + diff --git a/js/src/tests/test262/language/statements/let/syntax/let-closure-inside-condition.js b/js/src/tests/test262/language/statements/let/syntax/let-closure-inside-condition.js new file mode 100644 index 0000000000..e0d20e129e --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let-closure-inside-condition.js @@ -0,0 +1,14 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: closure inside for loop condition +---*/ +let a = []; +for (let i = 0; a.push(function () { return i; }), i < 5; ++i) { } +for (let k = 0; k < 5; ++k) { + assert.sameValue(k, a[k]()); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/let-closure-inside-initialization.js b/js/src/tests/test262/language/statements/let/syntax/let-closure-inside-initialization.js new file mode 100644 index 0000000000..29322ec1e1 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let-closure-inside-initialization.js @@ -0,0 +1,16 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: closure inside for loop initialization +---*/ +let a = []; +for (let i = 0, f = function() { return i }; i < 5; ++i) { + a.push(f); +} +for (let k = 0; k < 5; ++k) { + assert.sameValue(0, a[k]()); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/let-closure-inside-next-expression.js b/js/src/tests/test262/language/statements/let/syntax/let-closure-inside-next-expression.js new file mode 100644 index 0000000000..e2d7a08ead --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let-closure-inside-next-expression.js @@ -0,0 +1,14 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let: closure inside for loop next-expression +---*/ +let a = []; +for (let i = 0; i < 5; a.push(function () { return i; }), ++i) { } +for (let k = 0; k < 5; ++k) { + assert.sameValue(k + 1, a[k]()); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/let-iteration-variable-is-freshly-allocated-for-each-iteration-multi-let-binding.js b/js/src/tests/test262/language/statements/let/syntax/let-iteration-variable-is-freshly-allocated-for-each-iteration-multi-let-binding.js new file mode 100644 index 0000000000..99b7421991 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let-iteration-variable-is-freshly-allocated-for-each-iteration-multi-let-binding.js @@ -0,0 +1,18 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + In a normal for statement the iteration variable is freshly allocated for each iteration. Multi let binding +---*/ +let a = [], b = []; +for (let i = 0, j = 10; i < 5; ++i, ++j) { + a.push(function () { return i; }); + b.push(function () { return j; }); +} +for (let k = 0; k < 5; ++k) { + assert.sameValue(k, a[k]()); + assert.sameValue(k + 10, b[k]()); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/let-iteration-variable-is-freshly-allocated-for-each-iteration-single-let-binding.js b/js/src/tests/test262/language/statements/let/syntax/let-iteration-variable-is-freshly-allocated-for-each-iteration-single-let-binding.js new file mode 100644 index 0000000000..33cc84c50a --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let-iteration-variable-is-freshly-allocated-for-each-iteration-single-let-binding.js @@ -0,0 +1,16 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + In a normal for statement the iteration variable is freshly allocated for each iteration. Single let binding +---*/ +let a = []; +for (let i = 0; i < 5; ++i) { + a.push(function () { return i; }); +} +for (let j = 0; j < 5; ++j) { + assert.sameValue(j, a[j]()); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/let-let-declaration-split-across-two-lines.js b/js/src/tests/test262/language/statements/let/syntax/let-let-declaration-split-across-two-lines.js new file mode 100644 index 0000000000..ffc309bf53 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let-let-declaration-split-across-two-lines.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2015 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Jeff Walden +es6id: 13.3.1.1 +description: > + let: |let let| split across two lines is not subject to automatic semicolon insertion. +info: | + |let| followed by a name is a lexical declaration. This is so even if the + name is on a new line. ASI applies *only* if an offending token not allowed + by the grammar is encountered, and there's no [no LineTerminator here] + restriction in LexicalDeclaration or ForDeclaration forbidding a line break. + + It's a tricky point, but this is true *even if* the name is "let", a name that + can't be bound by LexicalDeclaration or ForDeclaration. Per 5.3, static + semantics early errors are validated *after* determining productions matching + the source text. + + So in this testcase, the eval text matches LexicalDeclaration. No ASI occurs, + because "let\nlet = ..." matches LexicalDeclaration before static semantics + are considered. *Then* 13.3.1.1's static semantics for the LexicalDeclaration + just chosen, per 5.3, are validated to recognize the Script as invalid. Thus + the eval script can't be evaluated, and a SyntaxError is thrown. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +let // start of a LexicalDeclaration, *not* an ASI opportunity +let; diff --git a/js/src/tests/test262/language/statements/let/syntax/let-let-declaration-with-initializer-split-across-two-lines.js b/js/src/tests/test262/language/statements/let/syntax/let-let-declaration-with-initializer-split-across-two-lines.js new file mode 100644 index 0000000000..28d5758eb9 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let-let-declaration-with-initializer-split-across-two-lines.js @@ -0,0 +1,34 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2015 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Jeff Walden +es6id: 13.3.1.1 +description: > + let: |let let| split across two lines is not subject to automatic semicolon insertion. +info: | + |let| followed by a name is a lexical declaration. This is so even if the + name is on a new line. ASI applies *only* if an offending token not allowed + by the grammar is encountered, and there's no [no LineTerminator here] + restriction in LexicalDeclaration or ForDeclaration forbidding a line break. + + It's a tricky point, but this is true *even if* the name is "let", a name that + can't be bound by LexicalDeclaration or ForDeclaration. Per 5.3, static + semantics early errors are validated *after* determining productions matching + the source text. + + So in this testcase, the eval text matches LexicalDeclaration. No ASI occurs, + because "let\nlet = ..." matches LexicalDeclaration before static semantics + are considered. *Then* 13.3.1.1's static semantics for the LexicalDeclaration + just chosen, per 5.3, are validated to recognize the Script as invalid. Thus + the eval script can't be evaluated, and a SyntaxError is thrown. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +let // start of a LexicalDeclaration, *not* an ASI opportunity +let = "irrelevant initializer"; diff --git a/js/src/tests/test262/language/statements/let/syntax/let-newline-await-in-normal-function.js b/js/src/tests/test262/language/statements/let/syntax/let-newline-await-in-normal-function.js new file mode 100644 index 0000000000..aa3735d09a --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let-newline-await-in-normal-function.js @@ -0,0 +1,25 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Jeff Walden <jwalden+code@mit.edu> +esid: sec-let-and-const-declarations +description: > + `let await` does not permit ASI in between, as `await` is a BindingIdentifier +info: | + `await` is a perfectly cromulent binding name in any context grammatically, just + prohibited by static semantics in some contexts. Therefore ASI can never apply + between `let` (where a LexicalDeclaration is permitted) and `await`, + so a subsequent `0` where `=` was expected is a syntax error. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + let + await 0; +} diff --git a/js/src/tests/test262/language/statements/let/syntax/let-newline-yield-in-generator-function.js b/js/src/tests/test262/language/statements/let/syntax/let-newline-yield-in-generator-function.js new file mode 100644 index 0000000000..86a3c429bf --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let-newline-yield-in-generator-function.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Jeff Walden <jwalden+code@mit.edu> +esid: sec-let-and-const-declarations +description: > + `let yield` does not permit ASI in between, as `yield` is a BindingIdentifier +info: | + `yield` is a perfectly cromulent binding name in any context grammatically, just + prohibited by static semantics in some contexts. Therefore ASI can never apply + between `let` (where a LexicalDeclaration is permitted) and `yield`, + so a subsequent `0` where `=` was expected is a syntax error. +negative: + phase: parse + type: SyntaxError +features: [generators] +---*/ + +$DONOTEVALUATE(); + +function* f() { + let + yield 0; +} diff --git a/js/src/tests/test262/language/statements/let/syntax/let-newline-yield-in-normal-function.js b/js/src/tests/test262/language/statements/let/syntax/let-newline-yield-in-normal-function.js new file mode 100644 index 0000000000..fdf257f95f --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let-newline-yield-in-normal-function.js @@ -0,0 +1,24 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-let-and-const-declarations +description: > + `let yield` does not permit ASI in between, as `yield` is a BindingIdentifier +info: | + `yield` is a perfectly cromulent binding name in any context grammatically, just + prohibited by static semantics in some contexts. Therefore ASI can never apply + between `let` (where a LexicalDeclaration is permitted) and `yield`, + so a subsequent `0` where `=` was expected is a syntax error. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function f() { + let + yield 0; +} diff --git a/js/src/tests/test262/language/statements/let/syntax/let-outer-inner-let-bindings.js b/js/src/tests/test262/language/statements/let/syntax/let-outer-inner-let-bindings.js new file mode 100644 index 0000000000..ece8f016ef --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let-outer-inner-let-bindings.js @@ -0,0 +1,23 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + outer let binding unchanged by for-loop let binding +---*/ +// + +let x = "outer_x"; +let y = "outer_y"; + +for (let x = "inner_x", i = 0; i < 1; i++) { + let y = "inner_y"; + + assert.sameValue(x, "inner_x"); + assert.sameValue(y, "inner_y"); +} +assert.sameValue(x, "outer_x"); +assert.sameValue(y, "outer_y"); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/let.js b/js/src/tests/test262/language/statements/let/syntax/let.js new file mode 100644 index 0000000000..cf9bd1b53c --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/let.js @@ -0,0 +1,26 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + global and block scope let +---*/ +let x; +let y = 2; + +// Block local +{ + let y; + let x = 3; +} + +assert.sameValue(x, undefined); +assert.sameValue(y, 2); + +if (true) { + let y; + assert.sameValue(y, undefined); +} + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/shell.js b/js/src/tests/test262/language/statements/let/syntax/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/shell.js diff --git a/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-case-expression-statement-list.js b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-case-expression-statement-list.js new file mode 100644 index 0000000000..79a17ed3c4 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-case-expression-statement-list.js @@ -0,0 +1,12 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations with initialisers in statement positions: + case Expression : StatementList +---*/ +switch (true) { case true: let x = 1; } + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-default-statement-list.js b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-default-statement-list.js new file mode 100644 index 0000000000..0788ee9d8d --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-default-statement-list.js @@ -0,0 +1,12 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations with initialisers in statement positions: + default : StatementList +---*/ +switch (true) { default: let x = 1; } + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-do-statement-while-expression.js b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-do-statement-while-expression.js new file mode 100644 index 0000000000..f452223e92 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-do-statement-while-expression.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations with initialisers in statement positions: + do Statement while ( Expression ) +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +do let x = 1; while (false) diff --git a/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-for-statement.js b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-for-statement.js new file mode 100644 index 0000000000..cc0d1cd796 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-for-statement.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations with initialisers in statement positions: + for ( ;;) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +for (;false;) let x = 1; diff --git a/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-if-expression-statement-else-statement.js b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-if-expression-statement-else-statement.js new file mode 100644 index 0000000000..72ef204832 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-if-expression-statement-else-statement.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations with initialisers in statement positions: + if ( Expression ) Statement else Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +if (true) {} else let x = 1; diff --git a/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-if-expression-statement.js b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-if-expression-statement.js new file mode 100644 index 0000000000..f0b34129e5 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-if-expression-statement.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations with initialisers in statement positions: + if ( Expression ) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +if (true) let x = 1; diff --git a/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-label-statement.js b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-label-statement.js new file mode 100644 index 0000000000..55336769c3 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-label-statement.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations with initialisers in statement positions: + label: Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +label: let x = 1; diff --git a/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-while-expression-statement.js b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-while-expression-statement.js new file mode 100644 index 0000000000..eb2f85897e --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/with-initialisers-in-statement-positions-while-expression-statement.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations with initialisers in statement positions: + while ( Expression ) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +while (false) let x = 1; diff --git a/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-case-expression-statement-list.js b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-case-expression-statement-list.js new file mode 100644 index 0000000000..089beebeb3 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-case-expression-statement-list.js @@ -0,0 +1,11 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations without initialisers in statement positions: + case Expression : StatementList +---*/ +switch (true) { case true: let x; } + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-default-statement-list.js b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-default-statement-list.js new file mode 100644 index 0000000000..128f3cb6ad --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-default-statement-list.js @@ -0,0 +1,11 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations without initialisers in statement positions: + default : StatementList +---*/ +switch (true) { default: let x; } + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-do-statement-while-expression.js b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-do-statement-while-expression.js new file mode 100644 index 0000000000..568b4463b5 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-do-statement-while-expression.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations without initialisers in statement positions: + do Statement while ( Expression ) +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +do let x; while (false) diff --git a/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-for-statement.js b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-for-statement.js new file mode 100644 index 0000000000..1730e07c1a --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-for-statement.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations without initialisers in statement positions: + for ( ;;) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +for (;false;) let x; diff --git a/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-if-expression-statement-else-statement.js b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-if-expression-statement-else-statement.js new file mode 100644 index 0000000000..bf634c5103 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-if-expression-statement-else-statement.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations without initialisers in statement positions: + if ( Expression ) Statement else Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +if (true) {} else let x; diff --git a/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-if-expression-statement.js b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-if-expression-statement.js new file mode 100644 index 0000000000..8c9ad1e56b --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-if-expression-statement.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations without initialisers in statement positions: + if ( Expression ) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +if (true) let x; diff --git a/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-label-statement.js b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-label-statement.js new file mode 100644 index 0000000000..7298a666ad --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-label-statement.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations without initialisers in statement positions: + label: Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +label: let x; diff --git a/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-while-expression-statement.js b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-while-expression-statement.js new file mode 100644 index 0000000000..705e47e5d6 --- /dev/null +++ b/js/src/tests/test262/language/statements/let/syntax/without-initialisers-in-statement-positions-while-expression-statement.js @@ -0,0 +1,15 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + let declarations without initialisers in statement positions: + while ( Expression ) Statement +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +while (false) let x; |