diff --git a/src/dstr-binding-async-iteration/ary-init-iter-close.case b/src/dstr-binding-async-iteration/ary-init-iter-close.case new file mode 100644 index 0000000000..ab18446305 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-init-iter-close.case @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Iterator is closed when not exhausted by pattern evaluation +template: default +info: | + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] +features: [Symbol.iterator] +---*/ + +//- setup +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: false }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; +//- elems +[x] +//- vals +iter +//- body +assert.sameValue(doneCallCount, 1); diff --git a/src/dstr-binding-async-iteration/ary-init-iter-get-err.case b/src/dstr-binding-async-iteration/ary-init-iter-get-err.case new file mode 100644 index 0000000000..3fd5f5c99e --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-init-iter-get-err.case @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Abrupt completion returned by GetIterator +template: error +info: | + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). +features: [Symbol.iterator] +---*/ + +//- setup +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; +//- elems +[x] +//- vals +iter +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/ary-init-iter-no-close.case b/src/dstr-binding-async-iteration/ary-init-iter-no-close.case new file mode 100644 index 0000000000..b9277b1234 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-init-iter-no-close.case @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Iterator is not closed when exhausted by pattern evaluation +template: default +info: | + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] +features: [Symbol.iterator] +---*/ + +//- setup +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: true }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; +//- elems +[x] +//- vals +iter +//- body +assert.sameValue(doneCallCount, 0); diff --git a/src/dstr-binding-async-iteration/ary-name-iter-val.case b/src/dstr-binding-async-iteration/ary-name-iter-val.case new file mode 100644 index 0000000000..8c65a0868f --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-name-iter-val.case @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding with normal value iteration +template: default +info: | + 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). +---*/ + +//- elems +[x, y, z] +//- vals +[1, 2, 3] +//- body +assert.sameValue(x, 1); +assert.sameValue(y, 2); +assert.sameValue(z, 3); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elem-init.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elem-init.case new file mode 100644 index 0000000000..15df36937e --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elem-init.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with array binding pattern and initializer is used +template: default +info: | + 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. +---*/ + +//- elems +[[x, y, z] = [4, 5, 6]] +//- vals +[] +//- body +assert.sameValue(x, 4); +assert.sameValue(y, 5); +assert.sameValue(z, 6); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elem-iter.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elem-iter.case new file mode 100644 index 0000000000..b3668d6180 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elem-iter.case @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with array binding pattern and initializer is not used +template: default +info: | + 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. +---*/ + +//- elems +[[x, y, z] = [4, 5, 6]] +//- vals +[[7, 8, 9]] +//- body +assert.sameValue(x, 7); +assert.sameValue(y, 8); +assert.sameValue(z, 9); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elision-init.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elision-init.case new file mode 100644 index 0000000000..49933f6364 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elision-init.case @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with array binding pattern and initializer is used +template: default +info: | + 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. +features: [generators] +---*/ + +//- setup +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; +//- elems +[[,] = g()] +//- vals +[] +//- body +assert.sameValue(first, 1); +assert.sameValue(second, 0); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elision-iter.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elision-iter.case new file mode 100644 index 0000000000..47da0accc9 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-elision-iter.case @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with array binding pattern and initializer is not used +template: default +info: | + 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. +features: [generators] +---*/ + +//- setup +var callCount = 0; +function* g() { + callCount += 1; +}; +//- elems +[[,] = g()] +//- vals +[[]] +//- body +assert.sameValue(callCount, 0); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-empty-init.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-empty-init.case new file mode 100644 index 0000000000..df0c90fdb5 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-empty-init.case @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with array binding pattern and initializer is used +template: default +info: | + 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. +---*/ + +//- setup +var initCount = 0; +var iterCount = 0; +var iter = function*() { iterCount += 1; }(); +//- elems +[[] = function() { initCount += 1; return iter; }()] +//- vals +[] +//- body +assert.sameValue(initCount, 1); +assert.sameValue(iterCount, 0); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-empty-iter.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-empty-iter.case new file mode 100644 index 0000000000..b2c0aa1f59 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-empty-iter.case @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with array binding pattern and initializer is not used +template: default +info: | + 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. +---*/ + +//- setup +var initCount = 0; +//- elems +[[] = function() { initCount += 1; }()] +//- vals +[[23]] +//- body +assert.sameValue(initCount, 0); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-rest-init.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-rest-init.case new file mode 100644 index 0000000000..18ac2bb211 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-rest-init.case @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with array binding pattern and initializer is used +template: default +info: | + 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. +---*/ + +//- setup +var values = [2, 1, 3]; +//- elems +[[...x] = values] +//- vals +[] +//- body +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); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-rest-iter.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-rest-iter.case new file mode 100644 index 0000000000..63f77b64b3 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-rest-iter.case @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with array binding pattern and initializer is not used +template: default +info: | + 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. +---*/ + +//- setup +var values = [2, 1, 3]; +var initCount = 0; +//- elems +[[...x] = function() { initCount += 1; }()] +//- vals +[values] +//- body +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); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-val-null.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-val-null.case new file mode 100644 index 0000000000..abe6ac4f3d --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-ary-val-null.case @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Nested array destructuring with a null value +template: error +info: | + 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). +---*/ + +//- elems +[[x]] +//- vals +[null] +//- error +TypeError diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-exhausted.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-exhausted.case new file mode 100644 index 0000000000..fbd4ffa0ac --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-exhausted.case @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Destructuring initializer with an exhausted iterator +template: default +info: | + 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). +---*/ + +//- elems +[x = 23] +//- vals +[] +//- body +assert.sameValue(x, 23); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-arrow.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-arrow.case new file mode 100644 index 0000000000..0dda822299 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-arrow.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding does assign name to arrow functions +template: default +info: | + 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). +---*/ + +//- elems +[arrow = () => {}] +//- vals +[] +//- body +assert.sameValue(arrow.name, 'arrow'); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-class.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-class.case new file mode 100644 index 0000000000..fd129368d4 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-class.case @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding assigns `name` to "anonymous" classes +template: default +info: | + 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). +---*/ + +//- elems +[cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }] +//- vals +[] +//- body +assert.sameValue(cls.name, 'cls'); +assert.notSameValue(xCls.name, 'xCls'); +assert.notSameValue(xCls2.name, 'xCls2'); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-cover.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-cover.case new file mode 100644 index 0000000000..40f16c07f2 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-cover.case @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar +template: default +info: | + 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). +---*/ + +//- elems +[cover = (function () {}), xCover = (0, function() {})] +//- vals +[] +//- body +assert.sameValue(cover.name, 'cover'); +assert.notSameValue(xCover.name, 'xCover'); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-fn.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-fn.case new file mode 100644 index 0000000000..d6b36ee6ac --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-fn.case @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding assigns name to "anonymous" functions +template: default +info: | + 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). +---*/ + +//- elems +[fn = function () {}, xFn = function x() {}] +//- vals +[] +//- body +assert.sameValue(fn.name, 'fn'); +assert.notSameValue(xFn.name, 'xFn'); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-gen.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-gen.case new file mode 100644 index 0000000000..04587c07cd --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-fn-name-gen.case @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding assigns name to "anonymous" generator functions +template: default +info: | + 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). +---*/ + +//- elems +[gen = function* () {}, xGen = function* x() {}] +//- vals +[] +//- body +assert.sameValue(gen.name, 'gen'); +assert.notSameValue(xGen.name, 'xGen'); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-hole.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-hole.case new file mode 100644 index 0000000000..e34d9a1fd4 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-hole.case @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Destructuring initializer with a "hole" +template: default +info: > + 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). +---*/ + +//- elems +[x = 23] +//- vals +[,] +//- body +assert.sameValue(x, 23); +// another statement diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-skipped.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-skipped.case new file mode 100644 index 0000000000..803289ac0e --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-skipped.case @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Destructuring initializer is not evaluated when value is not `undefined` +template: default +info: | + 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). +---*/ + +//- setup +var initCount = 0; +function counter() { + initCount += 1; +} +//- elems +[w = counter(), x = counter(), y = counter(), z = counter()] +//- vals +[null, 0, false, ''] +//- body +assert.sameValue(w, null); +assert.sameValue(x, 0); +assert.sameValue(y, false); +assert.sameValue(z, ''); +assert.sameValue(initCount, 0); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-throws.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-throws.case new file mode 100644 index 0000000000..2b05bf7cd5 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-throws.case @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Destructuring initializer returns an abrupt completion +template: error +info: | + 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). +---*/ + +//- elems +[x = (function() { throw new Test262Error(); })()] +//- vals +[undefined] +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-undef.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-undef.case new file mode 100644 index 0000000000..1767bd23db --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-undef.case @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Destructuring initializer with an undefined value +template: default +info: | + 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). +---*/ + +//- elems +[x = 23] +//- vals +[undefined] +//- body +assert.sameValue(x, 23); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-unresolvable.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-unresolvable.case new file mode 100644 index 0000000000..109063ea87 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-init-unresolvable.case @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Destructuring initializer is an unresolvable reference +template: error +info: | + 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. +---*/ + +//- elems +[ x = unresolvableReference ] +//- vals +[] +//- error +ReferenceError diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-complete.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-complete.case new file mode 100644 index 0000000000..93f3588e1d --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-complete.case @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding when value iteration completes +template: default +info: | + 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). +---*/ + +//- elems +[x] +//- vals +[] +//- body +assert.sameValue(x, undefined); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-done.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-done.case new file mode 100644 index 0000000000..745eb08019 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-done.case @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding when value iteration was completed previously +template: default +info: | + 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). +---*/ + +//- elems +[_, x] +//- vals +[] +//- body +assert.sameValue(x, undefined); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-step-err.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-step-err.case new file mode 100644 index 0000000000..58feda2796 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-step-err.case @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Error forwarding when IteratorStep returns an abrupt completion +template: error +info: | + 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). +---*/ + +//- setup +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; +//- elems +[x] +//- vals +g +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-val-err.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-val-err.case new file mode 100644 index 0000000000..e52c52a93d --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-val-err.case @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Error forwarding when IteratorValue returns an abrupt completion +template: error +info: | + 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). +---*/ + +//- setup +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; +//- elems +[x] +//- vals +g +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-val.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-val.case new file mode 100644 index 0000000000..20a3e47ba4 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-id-iter-val.case @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding when value iteration was completed previously +template: default +info: | + 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). +---*/ + +//- elems +[x, y, z] +//- vals +[1, 2, 3] +//- body +assert.sameValue(x, 1); +assert.sameValue(y, 2); +assert.sameValue(z, 3); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-id-init.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-id-init.case new file mode 100644 index 0000000000..2133fc1fc3 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-id-init.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with object binding pattern and initializer is used +template: default +info: | + 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. +---*/ + +//- elems +[{ x, y, z } = { x: 44, y: 55, z: 66 }] +//- vals +[] +//- body +assert.sameValue(x, 44); +assert.sameValue(y, 55); +assert.sameValue(z, 66); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-id.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-id.case new file mode 100644 index 0000000000..a8cf157efc --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-id.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with object binding pattern and initializer is not used +template: default +info: | + 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. +---*/ + +//- elems +[{ x, y, z } = { x: 44, y: 55, z: 66 }] +//- vals +[{ x: 11, y: 22, z: 33 }] +//- body +assert.sameValue(x, 11); +assert.sameValue(y, 22); +assert.sameValue(z, 33); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-prop-id-init.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-prop-id-init.case new file mode 100644 index 0000000000..1ad7f3a6ca --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-prop-id-init.case @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with object binding pattern and initializer is used +template: default +info: | + 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. +---*/ + +//- elems +[{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] +//- vals +[] +//- body +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; +}); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-prop-id.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-prop-id.case new file mode 100644 index 0000000000..8517cae5d7 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-prop-id.case @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: BindingElement with object binding pattern and initializer is not used +template: default +info: | + 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. +---*/ + +//- elems +[{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] +//- vals +[{ u: 777, w: 888, y: 999 }] +//- body +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; +}); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-val-null.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-val-null.case new file mode 100644 index 0000000000..9f15b25aae --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-val-null.case @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Nested object destructuring with a null value +template: error +info: | + 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). +---*/ + +//- elems +[{ x }] +//- vals +[null] +//- error +TypeError diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-val-undef.case b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-val-undef.case new file mode 100644 index 0000000000..1f0c3aa990 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elem-obj-val-undef.case @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Nested object destructuring with a value of `undefined` +template: error +info: | + 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). +---*/ + +//- elems +[{ x }] +//- vals +[] +//- error +TypeError diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elision-exhausted.case b/src/dstr-binding-async-iteration/ary-ptrn-elision-exhausted.case new file mode 100644 index 0000000000..1f3b1fd8e6 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elision-exhausted.case @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Elision accepts exhausted iterator +template: default +info: | + 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). +features: [generator] +---*/ + +//- setup +var iter = function*() {}(); +iter.next(); +//- elems +[,] +//- vals +iter diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elision-iter-close.case b/src/dstr-binding-async-iteration/ary-ptrn-elision-iter-close.case new file mode 100644 index 0000000000..18c0046a3a --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elision-iter-close.case @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +template: iter-close +desc: > + The iterator is properly consumed by the destructuring pattern +---*/ + +//- setup +const iter = (function* () { + yield; + yield; +})(); + +//- elems +[,] +//- iter +iter +//- assertions +assert.sameValue(iter.next().done, true, 'iteration occurred as expected'); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elision-step-err.case b/src/dstr-binding-async-iteration/ary-ptrn-elision-step-err.case new file mode 100644 index 0000000000..7f0b3789f1 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elision-step-err.case @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Elision advances iterator and forwards abrupt completions +template: error +info: | + 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). +features: [generator] +---*/ + +//- setup +var following = 0; +var iter =function* () { + throw new Test262Error(); + following += 1; +}(); +//- elems +[,] +//- vals +iter +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/ary-ptrn-elision.case b/src/dstr-binding-async-iteration/ary-ptrn-elision.case new file mode 100644 index 0000000000..9784dea4f2 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-elision.case @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Elision advances iterator +template: default +info: | + 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). +features: [generator] +---*/ + +//- setup +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; +//- elems +[,] +//- vals +g() +//- body +assert.sameValue(first, 1); +assert.sameValue(second, 0); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-empty.case b/src/dstr-binding-async-iteration/ary-ptrn-empty.case new file mode 100644 index 0000000000..49b126c225 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-empty.case @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: No iteration occurs for an "empty" array binding pattern +template: default +info: | + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). +features: [generators] +---*/ + +//- setup +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); +//- elems +[] +//- vals +iter +//- body +assert.sameValue(iterations, 0); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-elem.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-elem.case new file mode 100644 index 0000000000..a143fdf1d9 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-elem.case @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Rest element containing an array BindingElementList pattern +info: | + 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). +---*/ + +//- elems +[...[x, y, z]] +//- vals +[3, 4, 5] +//- body +assert.sameValue(x, 3); +assert.sameValue(y, 4); +assert.sameValue(z, 5); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-elision.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-elision.case new file mode 100644 index 0000000000..dc6b008a6d --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-elision.case @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Rest element containing an elision +info: | + 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). +features: [generators] +---*/ + +//- setup +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; +//- elems +[...[,]] +//- vals +g() +//- body +assert.sameValue(first, 1); +assert.sameValue(second, 1); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-empty.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-empty.case new file mode 100644 index 0000000000..11994f9933 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-empty.case @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Rest element containing an "empty" array pattern +info: | + 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). +features: [generators] +---*/ + +//- setup +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); +//- elems +[...[]] +//- vals +iter +//- body +assert.sameValue(iterations, 1); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-rest.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-rest.case new file mode 100644 index 0000000000..c794f9b447 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-ary-rest.case @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Rest element containing a rest element +info: | + 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. + [...] +---*/ + +//- setup +var values = [1, 2, 3]; +//- elems +[...[...x]] +//- vals +values +//- body +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); + diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-id-elision-next-err.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-elision-next-err.case new file mode 100644 index 0000000000..413ec04398 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-elision-next-err.case @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Rest element following elision elements +info: > + 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. +features: [generators] +---*/ + +//- setup +var iter = (function*() { throw new Test262Error(); })(); +//- elems +[, ...x] +//- vals +iter +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-id-elision.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-elision.case new file mode 100644 index 0000000000..49780b19dc --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-elision.case @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Rest element following elision elements +info: > + 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. +---*/ + +//- setup +var values = [1, 2, 3, 4, 5]; +//- elems +[ , , ...x] +//- vals +values +//- body +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); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-id-exhausted.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-exhausted.case new file mode 100644 index 0000000000..1476e3cb96 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-exhausted.case @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: RestElement applied to an exhausted iterator +info: > + 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). +features: [Symbol.iterator] +---*/ + +//- elems +[, , ...x] +//- vals +[1, 2] +//- body +assert(Array.isArray(x)); +assert.sameValue(x.length, 0); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-id-iter-close.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-iter-close.case new file mode 100644 index 0000000000..2127b9edaf --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-iter-close.case @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +template: iter-close +desc: > + The iterator is properly consumed by the destructuring pattern +---*/ + +//- setup +const iter = (function* () { + yield; + yield; +})(); + +//- elems +[...x] +//- iter +iter +//- assertions +assert.sameValue(iter.next().done, true, 'iteration occurred as expected'); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-id-iter-step-err.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-iter-step-err.case new file mode 100644 index 0000000000..1bb3bd0637 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-iter-step-err.case @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Error forwarding when IteratorStep returns an abrupt completion +info: > + 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). +features: [generators] +---*/ + +//- setup +var first = 0; +var second = 0; +var iter = function*() { + first += 1; + throw new Test262Error(); + second += 1; +}(); +//- elems +[...x] +//- vals +iter +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-id-iter-val-err.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-iter-val-err.case new file mode 100644 index 0000000000..b3fb42708b --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-id-iter-val-err.case @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Error forwarding when IteratorValue returns an abrupt completion +info: > + 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). +features: [Symbol.iterator] +---*/ + +//- setup +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; +//- elems +[...x] +//- vals +iter +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-id.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-id.case new file mode 100644 index 0000000000..1b0f446417 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-id.case @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Lone rest element +info: > + 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). + [...] +---*/ + +//- setup +var values = [1, 2, 3]; +//- elems +[...x] +//- vals +values +//- body +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); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-init-ary.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-init-ary.case new file mode 100644 index 0000000000..ab359ad3f3 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-init-ary.case @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Reset element (nested array pattern) does not support initializer +negative: + phase: early + type: SyntaxError +info: > + 13.3.3 Destructuring Binding Patterns + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ + +//- elems +[...[ x ] = []] +//- vals +[] diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-init-id.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-init-id.case new file mode 100644 index 0000000000..e5ab514c08 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-init-id.case @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Reset element (identifier) does not support initializer +negative: + phase: early + type: SyntaxError +info: > + 13.3.3 Destructuring Binding Patterns + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ + +//- elems +[...x = []] +//- vals +[] diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-init-obj.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-init-obj.case new file mode 100644 index 0000000000..dc3cf7437a --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-init-obj.case @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Reset element (nested object pattern) does not support initializer +negative: + phase: early + type: SyntaxError +info: > + 13.3.3 Destructuring Binding Patterns + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ + +//- elems +[...{ x } = []] +//- vals +[] diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-not-final-ary.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-not-final-ary.case new file mode 100644 index 0000000000..c76c83d0a4 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-not-final-ary.case @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Rest element (array binding pattern) may not be followed by any element +negative: + phase: early + type: SyntaxError +info: > + 13.3.3 Destructuring Binding Patterns + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ + +//- elems +[...[x], y] +//- vals +[1, 2, 3] diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-not-final-id.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-not-final-id.case new file mode 100644 index 0000000000..962733013a --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-not-final-id.case @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Rest element (identifier) may not be followed by any element +negative: + phase: early + type: SyntaxError +info: > + 13.3.3 Destructuring Binding Patterns + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ + +//- elems +[...x, y] +//- vals +[1, 2, 3] diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-not-final-obj.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-not-final-obj.case new file mode 100644 index 0000000000..00c70507ea --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-not-final-obj.case @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Rest element (object binding pattern) may not be followed by any element +negative: + phase: early + type: SyntaxError +info: > + 13.3.3 Destructuring Binding Patterns + + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ + +//- elems +[...{ x }, y] +//- vals +[1, 2, 3] diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-obj-id.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-obj-id.case new file mode 100644 index 0000000000..fd42f56de5 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-obj-id.case @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Rest element containing an object binding pattern +info: | + 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. + [...] +---*/ + +//- elems +[...{ length }] +//- vals +[1, 2, 3] +//- body +assert.sameValue(length, 3); diff --git a/src/dstr-binding-async-iteration/ary-ptrn-rest-obj-prop-id.case b/src/dstr-binding-async-iteration/ary-ptrn-rest-obj-prop-id.case new file mode 100644 index 0000000000..3ad1150230 --- /dev/null +++ b/src/dstr-binding-async-iteration/ary-ptrn-rest-obj-prop-id.case @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Rest element containing an object binding pattern +info: | + 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. + [...] +---*/ + +//- setup +let length = "outer"; +//- elems +[...{ 0: v, 1: w, 2: x, 3: y, length: z }] +//- vals +[7, 8, 9] +//- body +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"); diff --git a/src/dstr-binding/default/for-await-of-async-func-const-async.template b/src/dstr-binding-async-iteration/default/for-await-of-async-func-const-async.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-func-const-async.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-func-const-async.template diff --git a/src/dstr-binding/default/for-await-of-async-func-const.template b/src/dstr-binding-async-iteration/default/for-await-of-async-func-const.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-func-const.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-func-const.template diff --git a/src/dstr-binding/default/for-await-of-async-func-let-async.template b/src/dstr-binding-async-iteration/default/for-await-of-async-func-let-async.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-func-let-async.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-func-let-async.template diff --git a/src/dstr-binding/default/for-await-of-async-func-let.template b/src/dstr-binding-async-iteration/default/for-await-of-async-func-let.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-func-let.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-func-let.template diff --git a/src/dstr-binding/default/for-await-of-async-func-var-async.template b/src/dstr-binding-async-iteration/default/for-await-of-async-func-var-async.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-func-var-async.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-func-var-async.template diff --git a/src/dstr-binding/default/for-await-of-async-func-var.template b/src/dstr-binding-async-iteration/default/for-await-of-async-func-var.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-func-var.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-func-var.template diff --git a/src/dstr-binding/default/for-await-of-async-gen-const-async.template b/src/dstr-binding-async-iteration/default/for-await-of-async-gen-const-async.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-gen-const-async.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-gen-const-async.template diff --git a/src/dstr-binding/default/for-await-of-async-gen-const.template b/src/dstr-binding-async-iteration/default/for-await-of-async-gen-const.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-gen-const.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-gen-const.template diff --git a/src/dstr-binding/default/for-await-of-async-gen-let-async.template b/src/dstr-binding-async-iteration/default/for-await-of-async-gen-let-async.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-gen-let-async.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-gen-let-async.template diff --git a/src/dstr-binding/default/for-await-of-async-gen-let.template b/src/dstr-binding-async-iteration/default/for-await-of-async-gen-let.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-gen-let.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-gen-let.template diff --git a/src/dstr-binding/default/for-await-of-async-gen-var-async.template b/src/dstr-binding-async-iteration/default/for-await-of-async-gen-var-async.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-gen-var-async.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-gen-var-async.template diff --git a/src/dstr-binding/default/for-await-of-async-gen-var.template b/src/dstr-binding-async-iteration/default/for-await-of-async-gen-var.template similarity index 100% rename from src/dstr-binding/default/for-await-of-async-gen-var.template rename to src/dstr-binding-async-iteration/default/for-await-of-async-gen-var.template diff --git a/src/dstr-binding/error/for-await-of-async-func-const.template b/src/dstr-binding-async-iteration/error/for-await-of-async-func-const.template similarity index 100% rename from src/dstr-binding/error/for-await-of-async-func-const.template rename to src/dstr-binding-async-iteration/error/for-await-of-async-func-const.template diff --git a/src/dstr-binding/error/for-await-of-async-func-let.template b/src/dstr-binding-async-iteration/error/for-await-of-async-func-let.template similarity index 100% rename from src/dstr-binding/error/for-await-of-async-func-let.template rename to src/dstr-binding-async-iteration/error/for-await-of-async-func-let.template diff --git a/src/dstr-binding/error/for-await-of-async-func-var.template b/src/dstr-binding-async-iteration/error/for-await-of-async-func-var.template similarity index 100% rename from src/dstr-binding/error/for-await-of-async-func-var.template rename to src/dstr-binding-async-iteration/error/for-await-of-async-func-var.template diff --git a/src/dstr-binding/error/for-await-of-async-gen-const.template b/src/dstr-binding-async-iteration/error/for-await-of-async-gen-const.template similarity index 100% rename from src/dstr-binding/error/for-await-of-async-gen-const.template rename to src/dstr-binding-async-iteration/error/for-await-of-async-gen-const.template diff --git a/src/dstr-binding/error/for-await-of-async-gen-let.template b/src/dstr-binding-async-iteration/error/for-await-of-async-gen-let.template similarity index 100% rename from src/dstr-binding/error/for-await-of-async-gen-let.template rename to src/dstr-binding-async-iteration/error/for-await-of-async-gen-let.template diff --git a/src/dstr-binding/error/for-await-of-async-gen-var.template b/src/dstr-binding-async-iteration/error/for-await-of-async-gen-var.template similarity index 100% rename from src/dstr-binding/error/for-await-of-async-gen-var.template rename to src/dstr-binding-async-iteration/error/for-await-of-async-gen-var.template diff --git a/src/dstr-binding/iter-close/for-await-of-async-func-const.template b/src/dstr-binding-async-iteration/iter-close/for-await-of-async-func-const.template similarity index 100% rename from src/dstr-binding/iter-close/for-await-of-async-func-const.template rename to src/dstr-binding-async-iteration/iter-close/for-await-of-async-func-const.template diff --git a/src/dstr-binding/iter-close/for-await-of-async-func-let.template b/src/dstr-binding-async-iteration/iter-close/for-await-of-async-func-let.template similarity index 100% rename from src/dstr-binding/iter-close/for-await-of-async-func-let.template rename to src/dstr-binding-async-iteration/iter-close/for-await-of-async-func-let.template diff --git a/src/dstr-binding/iter-close/for-await-of-async-func-var.template b/src/dstr-binding-async-iteration/iter-close/for-await-of-async-func-var.template similarity index 100% rename from src/dstr-binding/iter-close/for-await-of-async-func-var.template rename to src/dstr-binding-async-iteration/iter-close/for-await-of-async-func-var.template diff --git a/src/dstr-binding/iter-close/for-await-of-async-gen-const.template b/src/dstr-binding-async-iteration/iter-close/for-await-of-async-gen-const.template similarity index 100% rename from src/dstr-binding/iter-close/for-await-of-async-gen-const.template rename to src/dstr-binding-async-iteration/iter-close/for-await-of-async-gen-const.template diff --git a/src/dstr-binding/iter-close/for-await-of-async-gen-let.template b/src/dstr-binding-async-iteration/iter-close/for-await-of-async-gen-let.template similarity index 100% rename from src/dstr-binding/iter-close/for-await-of-async-gen-let.template rename to src/dstr-binding-async-iteration/iter-close/for-await-of-async-gen-let.template diff --git a/src/dstr-binding/iter-close/for-await-of-async-gen-var.template b/src/dstr-binding-async-iteration/iter-close/for-await-of-async-gen-var.template similarity index 100% rename from src/dstr-binding/iter-close/for-await-of-async-gen-var.template rename to src/dstr-binding-async-iteration/iter-close/for-await-of-async-gen-var.template diff --git a/src/dstr-binding-async-iteration/obj-init-null.case b/src/dstr-binding-async-iteration/obj-init-null.case new file mode 100644 index 0000000000..0772e36f77 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-init-null.case @@ -0,0 +1,19 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Value specifed for object binding pattern must be object coercible (null) +info: | + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +//- elems +{} +//- vals +null +//- error +TypeError diff --git a/src/dstr-binding-async-iteration/obj-init-undefined.case b/src/dstr-binding-async-iteration/obj-init-undefined.case new file mode 100644 index 0000000000..f41405f6fe --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-init-undefined.case @@ -0,0 +1,19 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Value specifed for object binding pattern must be object coercible (undefined) +info: | + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +//- elems +{} +//- vals +undefined +//- error +TypeError diff --git a/src/dstr-binding-async-iteration/obj-ptrn-empty.case b/src/dstr-binding-async-iteration/obj-ptrn-empty.case new file mode 100644 index 0000000000..97ecebd347 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-empty.case @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: No property access occurs for an "empty" object binding pattern +info: | + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + +//- setup +var accessCount = 0; +var obj = Object.defineProperty({}, 'attr', { + get: function() { + accessCount += 1; + } +}); +//- elems +{} +//- vals +obj +//- body +assert.sameValue(accessCount, 0); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-id-get-value-err.case b/src/dstr-binding-async-iteration/obj-ptrn-id-get-value-err.case new file mode 100644 index 0000000000..68ae3348af --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-id-get-value-err.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Error thrown when accessing the corresponding property of the value object +info: | + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. Let v be GetV(value, propertyName). + 5. ReturnIfAbrupt(v). +---*/ + +//- setup +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); +//- elems +{ poisoned } +//- vals +poisonedProperty +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-arrow.case b/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-arrow.case new file mode 100644 index 0000000000..55cc1ad0ba --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-arrow.case @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding assigns `name` to arrow functions +template: default +info: | + 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). +---*/ + +//- elems +{ arrow = () => {} } +//- vals +{} +//- body +assert.sameValue(arrow.name, 'arrow'); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-class.case b/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-class.case new file mode 100644 index 0000000000..2b5a385dda --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-class.case @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding assigns `name` to "anonymous" classes +template: default +info: | + 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). +---*/ + +//- elems +{ cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } } +//- vals +{} +//- body +assert.sameValue(cls.name, 'cls'); +assert.notSameValue(xCls.name, 'xCls'); +assert.notSameValue(xCls2.name, 'xCls2'); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-cover.case b/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-cover.case new file mode 100644 index 0000000000..624b00fce0 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-cover.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar +template: default +info: | + 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). +---*/ + +//- elems +{ cover = (function () {}), xCover = (0, function() {}) } +//- vals +{} +//- body +assert.sameValue(cover.name, 'cover'); +assert.notSameValue(xCover.name, 'xCover'); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-fn.case b/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-fn.case new file mode 100644 index 0000000000..d6130cc9a6 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-fn.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding assigns name to "anonymous" functions +template: default +info: | + 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). +---*/ + +//- elems +{ fn = function () {}, xFn = function x() {} } +//- vals +{} +//- body +assert.sameValue(fn.name, 'fn'); +assert.notSameValue(xFn.name, 'xFn'); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-gen.case b/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-gen.case new file mode 100644 index 0000000000..977d9f08d9 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-id-init-fn-name-gen.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: SingleNameBinding assigns name to "anonymous" generator functions +template: default +info: | + 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). +---*/ + +//- elems +{ gen = function* () {}, xGen = function* x() {} } +//- vals +{} +//- body +assert.sameValue(gen.name, 'gen'); +assert.notSameValue(xGen.name, 'xGen'); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-id-init-skipped.case b/src/dstr-binding-async-iteration/obj-ptrn-id-init-skipped.case new file mode 100644 index 0000000000..ef10476d53 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-id-init-skipped.case @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Destructuring initializer is not evaluated when value is not `undefined` +template: default +info: | + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + [...] +---*/ + +//- setup +var initCount = 0; +function counter() { + initCount += 1; +} +//- elems +{ w = counter(), x = counter(), y = counter(), z = counter() } +//- vals +{ w: null, x: 0, y: false, z: '' } +//- body +assert.sameValue(w, null); +assert.sameValue(x, 0); +assert.sameValue(y, false); +assert.sameValue(z, ''); +assert.sameValue(initCount, 0); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-id-init-throws.case b/src/dstr-binding-async-iteration/obj-ptrn-id-init-throws.case new file mode 100644 index 0000000000..e67f63480e --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-id-init-throws.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Error thrown when evaluating the initializer +info: | + 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). +---*/ + +//- setup +function thrower() { + throw new Test262Error(); +} +//- elems +{ x = thrower() } +//- vals +{} +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/obj-ptrn-id-init-unresolvable.case b/src/dstr-binding-async-iteration/obj-ptrn-id-init-unresolvable.case new file mode 100644 index 0000000000..dd6d9dc839 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-id-init-unresolvable.case @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Destructuring initializer is an unresolvable reference +template: error +info: | + 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. +---*/ + +//- elems +{ x = unresolvableReference } +//- vals +{} +//- error +ReferenceError diff --git a/src/dstr-binding-async-iteration/obj-ptrn-id-trailing-comma.case b/src/dstr-binding-async-iteration/obj-ptrn-id-trailing-comma.case new file mode 100644 index 0000000000..5dc0cbe68a --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-id-trailing-comma.case @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Trailing comma is allowed following BindingPropertyList +info: | + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +//- elems +{ x, } +//- vals +{ x: 23 } +//- body +assert.sameValue(x, 23); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-list-err.case b/src/dstr-binding-async-iteration/obj-ptrn-list-err.case new file mode 100644 index 0000000000..73dc15e7df --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-list-err.case @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Binding property list evaluation is interrupted by an abrupt completion +info: | + 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). +---*/ + +//- setup +var initCount = 0; +function thrower() { + throw new Test262Error(); +} +//- elems +{ a, b = thrower(), c = ++initCount } +//- vals +{} +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-ary-init.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-ary-init.case new file mode 100644 index 0000000000..41ffaa1ac6 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-ary-init.case @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Object binding pattern with "nested" array binding pattern using initializer +info: | + 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. +---*/ + +//- elems +{ w: [x, y, z] = [4, 5, 6] } +//- vals +{} +//- body +assert.sameValue(x, 4); +assert.sameValue(y, 5); +assert.sameValue(z, 6); + +assert.throws(ReferenceError, function() { + w; +}); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-ary-trailing-comma.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-ary-trailing-comma.case new file mode 100644 index 0000000000..17007b54cf --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-ary-trailing-comma.case @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Trailing comma is allowed following BindingPropertyList +info: | + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +//- elems +{ x: [y], } +//- vals +{ x: [45] } +//- body +assert.sameValue(y,45); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-ary-value-null.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-ary-value-null.case new file mode 100644 index 0000000000..abe84e43f7 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-ary-value-null.case @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Object binding pattern with "nested" array binding pattern taking the `null` value +info: | + 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. +---*/ + +//- elems +{ w: [x, y, z] = [4, 5, 6] } +//- vals +{ w: null } +//- error +TypeError diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-ary.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-ary.case new file mode 100644 index 0000000000..254c8f06ba --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-ary.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Object binding pattern with "nested" array binding pattern not using initializer +info: | + 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. +---*/ + +//- elems +{ w: [x, y, z] = [4, 5, 6] } +//- vals +{ w: [7, undefined, ] } +//- body +assert.sameValue(x, 7); +assert.sameValue(y, undefined); +assert.sameValue(z, undefined); + +assert.throws(ReferenceError, function() { + w; +}); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-eval-err.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-eval-err.case new file mode 100644 index 0000000000..9721474c36 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-eval-err.case @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Evaluation of property name returns an abrupt completion +template: error +info: | + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingProperty : PropertyName : BindingElement + + 1. Let P be the result of evaluating PropertyName + 2. ReturnIfAbrupt(P). +---*/ + +//- setup +function thrower() { + throw new Test262Error(); +} +//- elems +{ [thrower()]: x } +//- vals +{} +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-id-get-value-err.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-get-value-err.case new file mode 100644 index 0000000000..3851240d08 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-get-value-err.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Error thrown when accessing the corresponding property of the value object +template: error +info: | + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. Let v be GetV(value, propertyName). + 2. ReturnIfAbrupt(v). +---*/ + +//- setup +var initEvalCount = 0; +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); +//- elems +{ poisoned: x = ++initEvalCount } +//- vals +poisonedProperty +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init-skipped.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init-skipped.case new file mode 100644 index 0000000000..49ec6684f2 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init-skipped.case @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Destructuring initializer is not evaluated when value is not `undefined` +template: default +info: | + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + [...] +---*/ + +//- setup +var initCount = 0; +function counter() { + initCount += 1; +} +//- elems +{ s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } +//- vals +{ s: null, u: 0, w: false, y: '' } +//- body +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; +}); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init-throws.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init-throws.case new file mode 100644 index 0000000000..e878fc6f3a --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init-throws.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Error thrown when evaluating the initializer +info: | + 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). +---*/ + +//- setup +function thrower() { + throw new Test262Error(); +} +//- elems +{ x: y = thrower() } +//- vals +{} +//- error +Test262Error diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init-unresolvable.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init-unresolvable.case new file mode 100644 index 0000000000..d11f68d9df --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init-unresolvable.case @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: Destructuring initializer is an unresolvable reference +template: error +info: | + 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. +---*/ + +//- elems +{ x: y = unresolvableReference } +//- vals +{} +//- error +ReferenceError diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init.case new file mode 100644 index 0000000000..5b6723f746 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-init.case @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Binding as specified via property name, identifier, and initializer +info: | + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +//- elems +{ x: y = 33 } +//- vals +{ } +//- body +assert.sameValue(y, 33); +assert.throws(ReferenceError, function() { + x; +}); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-id-trailing-comma.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-trailing-comma.case new file mode 100644 index 0000000000..cee4bc0577 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-id-trailing-comma.case @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Trailing comma is allowed following BindingPropertyList +info: | + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + +//- elems +{ x: y, } +//- vals +{ x: 23 } +//- body +assert.sameValue(y, 23); + +assert.throws(ReferenceError, function() { + x; +}); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-id.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-id.case new file mode 100644 index 0000000000..ebd0652976 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-id.case @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Binding as specified via property name and identifier +info: | + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + +//- elems +{ x: y } +//- vals +{ x: 23 } +//- body +assert.sameValue(y, 23); +assert.throws(ReferenceError, function() { + x; +}); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-obj-init.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-obj-init.case new file mode 100644 index 0000000000..cc6da66b45 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-obj-init.case @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Object binding pattern with "nested" object binding pattern using initializer +info: | + 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. +---*/ + +//- elems +{ w: { x, y, z } = { x: 4, y: 5, z: 6 } } +//- vals +{ w: undefined } +//- body +assert.sameValue(x, 4); +assert.sameValue(y, 5); +assert.sameValue(z, 6); + +assert.throws(ReferenceError, function() { + w; +}); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-obj-value-null.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-obj-value-null.case new file mode 100644 index 0000000000..828049f9a0 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-obj-value-null.case @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Object binding pattern with "nested" object binding pattern taking the `null` value +info: | + 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. +---*/ + +//- elems +{ w: { x, y, z } = { x: 4, y: 5, z: 6 } } +//- vals +{ w: null } +//- error +TypeError diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-obj-value-undef.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-obj-value-undef.case new file mode 100644 index 0000000000..6c4582af3d --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-obj-value-undef.case @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: error +desc: Object binding pattern with "nested" object binding pattern taking the `null` value +info: | + 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. +---*/ + +//- elems +{ w: { x, y, z } = undefined } +//- vals +{ } +//- error +TypeError diff --git a/src/dstr-binding-async-iteration/obj-ptrn-prop-obj.case b/src/dstr-binding-async-iteration/obj-ptrn-prop-obj.case new file mode 100644 index 0000000000..da412ccd6a --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-prop-obj.case @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +template: default +desc: Object binding pattern with "nested" object binding pattern not using initializer +info: | + 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. +---*/ + +//- elems +{ w: { x, y, z } = { x: 4, y: 5, z: 6 } } +//- vals +{ w: { x: undefined, z: 7 } } +//- body +assert.sameValue(x, undefined); +assert.sameValue(y, undefined); +assert.sameValue(z, 7); + +assert.throws(ReferenceError, function() { + w; +}); diff --git a/src/dstr-binding-async-iteration/obj-ptrn-rest-getter.case b/src/dstr-binding-async-iteration/obj-ptrn-rest-getter.case new file mode 100644 index 0000000000..c5360e5e5e --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-rest-getter.case @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Getter is called when obj is being deconstructed to a rest Object +template: default +esid: pending +includes: [propertyHelper.js] +features: [object-rest] +---*/ + +//- setup +var count = 0; +//- elems +{...x} +//- vals +{ get v() { count++; return 2; } } +//- body +assert.sameValue(x.v, 2); +assert.sameValue(count, 1); + +verifyEnumerable(x, "v"); +verifyWritable(x, "v"); +verifyConfigurable(x, "v"); + diff --git a/src/dstr-binding-async-iteration/obj-ptrn-rest-nested-obj.case b/src/dstr-binding-async-iteration/obj-ptrn-rest-nested-obj.case new file mode 100644 index 0000000000..8fb0bb2d11 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-rest-nested-obj.case @@ -0,0 +1,25 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an object literal, it should be parsed + parsed as a DestructuringAssignmentPattern and evaluated as a destructuring + assignment. +template: default +esid: pending +features: [object-rest] +---*/ + +//- setup +var obj = {a: 3, b: 4}; +//- elems +{a, b, ...{c, e}} +//- vals +{a: 1, b: 2, c: 3, d: 4, e: 5} +//- body +assert.sameValue(a, 1); +assert.sameValue(b, 2); +assert.sameValue(c, 3); +assert.sameValue(e, 5); + diff --git a/src/dstr-binding-async-iteration/obj-ptrn-rest-obj-nested-rest.case b/src/dstr-binding-async-iteration/obj-ptrn-rest-obj-nested-rest.case new file mode 100644 index 0000000000..a6eb8c024d --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-rest-obj-nested-rest.case @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an object literal, it should be parsed + parsed as a DestructuringAssignmentPattern and evaluated as a destructuring + assignment and object rest desconstruction is allowed in that case. +template: default +esid: pending +includes: [propertyHelper.js] +features: [object-rest] +---*/ + +//- elems +{a, b, ...{c, ...rest}} +//- vals +{a: 1, b: 2, c: 3, d: 4, e: 5} +//- body +assert.sameValue(a, 1); +assert.sameValue(b, 2); +assert.sameValue(c, 3); + +assert.sameValue(rest.d, 4); +assert.sameValue(rest.e, 5); + +verifyEnumerable(rest, "d"); +verifyWritable(rest, "d"); +verifyConfigurable(rest, "d"); + +verifyEnumerable(rest, "e"); +verifyWritable(rest, "e"); +verifyConfigurable(rest, "e"); + diff --git a/src/dstr-binding-async-iteration/obj-ptrn-rest-obj-own-property.case b/src/dstr-binding-async-iteration/obj-ptrn-rest-obj-own-property.case new file mode 100644 index 0000000000..71c375adc8 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-rest-obj-own-property.case @@ -0,0 +1,24 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Rest object contains just soruce object's own properties +template: default +esid: pending +includes: [propertyHelper.js] +features: [object-rest] +---*/ + +//- setup +var o = Object.create({ x: 1, y: 2 }); +o.z = 3; +//- elems +{ x, ...{y , z} } +//- vals +o +//- body +assert.sameValue(x, 1); +assert.sameValue(y, undefined); +assert.sameValue(z, 3); + diff --git a/src/dstr-binding-async-iteration/obj-ptrn-rest-skip-non-enumerable.case b/src/dstr-binding-async-iteration/obj-ptrn-rest-skip-non-enumerable.case new file mode 100644 index 0000000000..869ffd2419 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-rest-skip-non-enumerable.case @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Rest object doesn't contain non-enumerable properties +template: default +esid: pending +includes: [propertyHelper.js] +features: [object-rest] +---*/ + +//- setup +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); +//- elems +{...rest} +//- vals +o +//- body +assert.sameValue(rest.a, 3); +assert.sameValue(rest.b, 4); +assert.sameValue(rest.x, undefined); + +verifyEnumerable(rest, "a"); +verifyWritable(rest, "a"); +verifyConfigurable(rest, "a"); + +verifyEnumerable(rest, "b"); +verifyWritable(rest, "b"); +verifyConfigurable(rest, "b"); + diff --git a/src/dstr-binding-async-iteration/obj-ptrn-rest-val-obj.case b/src/dstr-binding-async-iteration/obj-ptrn-rest-val-obj.case new file mode 100644 index 0000000000..0379ddd944 --- /dev/null +++ b/src/dstr-binding-async-iteration/obj-ptrn-rest-val-obj.case @@ -0,0 +1,30 @@ +// Copyright (C) 2017 Caio Lima. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Rest object contains just unextracted data +template: default +esid: pending +includes: [propertyHelper.js] +features: [object-rest] +---*/ + +//- elems +{a, b, ...rest} +//- vals +{x: 1, y: 2, a: 5, b: 3} +//- body +assert.sameValue(rest.x, 1); +assert.sameValue(rest.y, 2); +assert.sameValue(rest.a, undefined); +assert.sameValue(rest.b, undefined); + +verifyEnumerable(rest, "x"); +verifyWritable(rest, "x"); +verifyConfigurable(rest, "x"); + +verifyEnumerable(rest, "y"); +verifyWritable(rest, "y"); +verifyConfigurable(rest, "y"); +