diff --git a/src/dstr-binding/ary-init-iter-close.case b/src/dstr-binding/ary-init-iter-close.case new file mode 100644 index 0000000000..ab18446305 --- /dev/null +++ b/src/dstr-binding/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/ary-init-iter-get-err.case b/src/dstr-binding/ary-init-iter-get-err.case new file mode 100644 index 0000000000..3fd5f5c99e --- /dev/null +++ b/src/dstr-binding/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/ary-init-iter-no-close.case b/src/dstr-binding/ary-init-iter-no-close.case new file mode 100644 index 0000000000..b9277b1234 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-ary-elem-init.case b/src/dstr-binding/ary-ptrn-elem-ary-elem-init.case new file mode 100644 index 0000000000..15df36937e --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-ary-elem-iter.case b/src/dstr-binding/ary-ptrn-elem-ary-elem-iter.case new file mode 100644 index 0000000000..b3668d6180 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-ary-elision-init.case b/src/dstr-binding/ary-ptrn-elem-ary-elision-init.case new file mode 100644 index 0000000000..49933f6364 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-ary-elision-iter.case b/src/dstr-binding/ary-ptrn-elem-ary-elision-iter.case new file mode 100644 index 0000000000..47da0accc9 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-ary-empty-init.case b/src/dstr-binding/ary-ptrn-elem-ary-empty-init.case new file mode 100644 index 0000000000..df0c90fdb5 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-ary-empty-iter.case b/src/dstr-binding/ary-ptrn-elem-ary-empty-iter.case new file mode 100644 index 0000000000..b2c0aa1f59 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-ary-rest-init.case b/src/dstr-binding/ary-ptrn-elem-ary-rest-init.case new file mode 100644 index 0000000000..18ac2bb211 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-ary-rest-iter.case b/src/dstr-binding/ary-ptrn-elem-ary-rest-iter.case new file mode 100644 index 0000000000..63f77b64b3 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-ary-val-null.case b/src/dstr-binding/ary-ptrn-elem-ary-val-null.case new file mode 100644 index 0000000000..abe6ac4f3d --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-init-exhausted.case b/src/dstr-binding/ary-ptrn-elem-id-init-exhausted.case new file mode 100644 index 0000000000..fbd4ffa0ac --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-init-fn-name-arrow.case b/src/dstr-binding/ary-ptrn-elem-id-init-fn-name-arrow.case new file mode 100644 index 0000000000..0dda822299 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-init-fn-name-class.case b/src/dstr-binding/ary-ptrn-elem-id-init-fn-name-class.case new file mode 100644 index 0000000000..5ac7081660 --- /dev/null +++ b/src/dstr-binding/ary-ptrn-elem-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.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 {}] +//- vals +[] +//- body +assert.sameValue(cls.name, 'cls'); +assert.notSameValue(xCls.name, 'xCls'); diff --git a/src/dstr-binding/ary-ptrn-elem-id-init-fn-name-cover.case b/src/dstr-binding/ary-ptrn-elem-id-init-fn-name-cover.case new file mode 100644 index 0000000000..40f16c07f2 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-init-fn-name-fn.case b/src/dstr-binding/ary-ptrn-elem-id-init-fn-name-fn.case new file mode 100644 index 0000000000..d6b36ee6ac --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-init-fn-name-gen.case b/src/dstr-binding/ary-ptrn-elem-id-init-fn-name-gen.case new file mode 100644 index 0000000000..04587c07cd --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-init-hole.case b/src/dstr-binding/ary-ptrn-elem-id-init-hole.case new file mode 100644 index 0000000000..e34d9a1fd4 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-init-skipped.case b/src/dstr-binding/ary-ptrn-elem-id-init-skipped.case new file mode 100644 index 0000000000..803289ac0e --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-init-throws.case b/src/dstr-binding/ary-ptrn-elem-id-init-throws.case new file mode 100644 index 0000000000..2b05bf7cd5 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-init-undef.case b/src/dstr-binding/ary-ptrn-elem-id-init-undef.case new file mode 100644 index 0000000000..1767bd23db --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-init-unresolvable.case b/src/dstr-binding/ary-ptrn-elem-id-init-unresolvable.case new file mode 100644 index 0000000000..109063ea87 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-iter-complete.case b/src/dstr-binding/ary-ptrn-elem-id-iter-complete.case new file mode 100644 index 0000000000..93f3588e1d --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-iter-done.case b/src/dstr-binding/ary-ptrn-elem-id-iter-done.case new file mode 100644 index 0000000000..745eb08019 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-iter-step-err.case b/src/dstr-binding/ary-ptrn-elem-id-iter-step-err.case new file mode 100644 index 0000000000..58feda2796 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-iter-val-err.case b/src/dstr-binding/ary-ptrn-elem-id-iter-val-err.case new file mode 100644 index 0000000000..e52c52a93d --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-id-iter-val.case b/src/dstr-binding/ary-ptrn-elem-id-iter-val.case new file mode 100644 index 0000000000..20a3e47ba4 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-obj-id-init.case b/src/dstr-binding/ary-ptrn-elem-obj-id-init.case new file mode 100644 index 0000000000..2133fc1fc3 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-obj-id.case b/src/dstr-binding/ary-ptrn-elem-obj-id.case new file mode 100644 index 0000000000..a8cf157efc --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-obj-prop-id-init.case b/src/dstr-binding/ary-ptrn-elem-obj-prop-id-init.case new file mode 100644 index 0000000000..1ad7f3a6ca --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-obj-prop-id.case b/src/dstr-binding/ary-ptrn-elem-obj-prop-id.case new file mode 100644 index 0000000000..8517cae5d7 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-obj-val-null.case b/src/dstr-binding/ary-ptrn-elem-obj-val-null.case new file mode 100644 index 0000000000..9f15b25aae --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elem-obj-val-undef.case b/src/dstr-binding/ary-ptrn-elem-obj-val-undef.case new file mode 100644 index 0000000000..1f0c3aa990 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elision-exhausted.case b/src/dstr-binding/ary-ptrn-elision-exhausted.case new file mode 100644 index 0000000000..1f3b1fd8e6 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-elision-step-err.case b/src/dstr-binding/ary-ptrn-elision-step-err.case new file mode 100644 index 0000000000..296f6e6f67 --- /dev/null +++ b/src/dstr-binding/ary-ptrn-elision-step-err.case @@ -0,0 +1,40 @@ +// 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 +//- teardown +iter.next(); +assert.sameValue(following, 0, 'Iterator was properly closed.'); diff --git a/src/dstr-binding/ary-ptrn-elision.case b/src/dstr-binding/ary-ptrn-elision.case new file mode 100644 index 0000000000..9784dea4f2 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-empty.case b/src/dstr-binding/ary-ptrn-empty.case new file mode 100644 index 0000000000..49b126c225 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-rest-ary-elem.case b/src/dstr-binding/ary-ptrn-rest-ary-elem.case new file mode 100644 index 0000000000..a143fdf1d9 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-rest-ary-elision.case b/src/dstr-binding/ary-ptrn-rest-ary-elision.case new file mode 100644 index 0000000000..dc6b008a6d --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-rest-ary-empty.case b/src/dstr-binding/ary-ptrn-rest-ary-empty.case new file mode 100644 index 0000000000..11994f9933 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-rest-ary-rest.case b/src/dstr-binding/ary-ptrn-rest-ary-rest.case new file mode 100644 index 0000000000..c794f9b447 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-rest-id-elision-next-err.case b/src/dstr-binding/ary-ptrn-rest-id-elision-next-err.case new file mode 100644 index 0000000000..413ec04398 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-rest-id-elision.case b/src/dstr-binding/ary-ptrn-rest-id-elision.case new file mode 100644 index 0000000000..49780b19dc --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-rest-id-exhausted.case b/src/dstr-binding/ary-ptrn-rest-id-exhausted.case new file mode 100644 index 0000000000..1476e3cb96 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-rest-id-iter-step-err.case b/src/dstr-binding/ary-ptrn-rest-id-iter-step-err.case new file mode 100644 index 0000000000..0e9cec26f3 --- /dev/null +++ b/src/dstr-binding/ary-ptrn-rest-id-iter-step-err.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. +/*--- +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 +//- teardown +iter.next(); +assert.sameValue(first, 1); +assert.sameValue(second, 0, 'Iterator is closed following abrupt completion.'); diff --git a/src/dstr-binding/ary-ptrn-rest-id-iter-val-err.case b/src/dstr-binding/ary-ptrn-rest-id-iter-val-err.case new file mode 100644 index 0000000000..b3fb42708b --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-rest-id.case b/src/dstr-binding/ary-ptrn-rest-id.case new file mode 100644 index 0000000000..1b0f446417 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-rest-init-ary.case b/src/dstr-binding/ary-ptrn-rest-init-ary.case new file mode 100644 index 0000000000..dd8cba348b --- /dev/null +++ b/src/dstr-binding/ary-ptrn-rest-init-ary.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: default +desc: Reset element (nested array pattern) does not support initializer +negative: 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/ary-ptrn-rest-init-id.case b/src/dstr-binding/ary-ptrn-rest-init-id.case new file mode 100644 index 0000000000..91dd9d4329 --- /dev/null +++ b/src/dstr-binding/ary-ptrn-rest-init-id.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: default +desc: Reset element (identifier) does not support initializer +negative: 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/ary-ptrn-rest-init-obj.case b/src/dstr-binding/ary-ptrn-rest-init-obj.case new file mode 100644 index 0000000000..cfcee7403f --- /dev/null +++ b/src/dstr-binding/ary-ptrn-rest-init-obj.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: default +desc: Reset element (nested object pattern) does not support initializer +negative: 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/ary-ptrn-rest-not-final-ary.case b/src/dstr-binding/ary-ptrn-rest-not-final-ary.case new file mode 100644 index 0000000000..416826354e --- /dev/null +++ b/src/dstr-binding/ary-ptrn-rest-not-final-ary.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: default +desc: Rest element (array binding pattern) may not be followed by any element +negative: 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/ary-ptrn-rest-not-final-id.case b/src/dstr-binding/ary-ptrn-rest-not-final-id.case new file mode 100644 index 0000000000..9594641608 --- /dev/null +++ b/src/dstr-binding/ary-ptrn-rest-not-final-id.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: default +desc: Rest element (identifier) may not be followed by any element +negative: 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/ary-ptrn-rest-not-final-obj.case b/src/dstr-binding/ary-ptrn-rest-not-final-obj.case new file mode 100644 index 0000000000..f5ab82db4b --- /dev/null +++ b/src/dstr-binding/ary-ptrn-rest-not-final-obj.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: default +desc: Rest element (object binding pattern) may not be followed by any element +negative: 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/ary-ptrn-rest-obj-id.case b/src/dstr-binding/ary-ptrn-rest-obj-id.case new file mode 100644 index 0000000000..fd42f56de5 --- /dev/null +++ b/src/dstr-binding/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/ary-ptrn-rest-obj-prop-id.case b/src/dstr-binding/ary-ptrn-rest-obj-prop-id.case new file mode 100644 index 0000000000..2f6ace55dc --- /dev/null +++ b/src/dstr-binding/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. + [...] +---*/ + +//- 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.throws(ReferenceError, function() { + length; +}); diff --git a/src/dstr-binding/error/arrow-function.template b/src/dstr-binding/error/arrow-function.template new file mode 100644 index 0000000000..92b1a41c45 --- /dev/null +++ b/src/dstr-binding/error/arrow-function.template @@ -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. +/*--- +path: language/expressions/arrow-function/dstr- +name: arrow function expression +esid: sec-arrow-function-definitions-runtime-semantics-evaluation +es6id: 14.2.16 +features: [destructuring-binding] +info: | + ArrowFunction : ArrowParameters => ConciseBody + + [...] + 4. Let closure be FunctionCreate(Arrow, parameters, ConciseBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +var f = (/*{ elems }*/) => {}; + +assert.throws(/*{ error }*/, function() { + f(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/cls-decl-gen-meth-static.template b/src/dstr-binding/error/cls-decl-gen-meth-static.template new file mode 100644 index 0000000000..21467eb02b --- /dev/null +++ b/src/dstr-binding/error/cls-decl-gen-meth-static.template @@ -0,0 +1,68 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/class/dstr-gen-meth-static- +name: static class expression generator method +esid: sec-runtime-semantics-bindingclassdeclarationevaluation +es6id: 14.5.15 +features: [destructuring-binding] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + b. Else, + Let status be the result of performing PropertyDefinitionEvaluation for + m with arguments F and false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, GeneratorBody, scope, strict). + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +class C { + static *method(/*{ elems }*/) {} +}; + +assert.throws(/*{ error }*/, function() { + C.method(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/cls-decl-gen-meth.template b/src/dstr-binding/error/cls-decl-gen-meth.template new file mode 100644 index 0000000000..347402fd94 --- /dev/null +++ b/src/dstr-binding/error/cls-decl-gen-meth.template @@ -0,0 +1,69 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/class/dstr-gen-meth- +name: class expression method +esid: sec-class-definitions-runtime-semantics-evaluation +es6id: 14.5.16 +features: [destructuring-binding] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, GeneratorBody, scope, strict). + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +class C { + *method(/*{ elems }*/) {} +}; +var c = new C(); + +assert.throws(/*{ error }*/, function() { + c.method(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/cls-decl-meth-static.template b/src/dstr-binding/error/cls-decl-meth-static.template new file mode 100644 index 0000000000..d299bd0f05 --- /dev/null +++ b/src/dstr-binding/error/cls-decl-meth-static.template @@ -0,0 +1,66 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/class/dstr-meth-static- +name: static class expression method +esid: sec-runtime-semantics-bindingclassdeclarationevaluation +es6id: 14.5.15 +features: [destructuring-binding] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + b. Else, + Let status be the result of performing PropertyDefinitionEvaluation for + m with arguments F and false. + [...] + + 14.3.8 Runtime Semantics: DefineMethod + + MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody } + + [...] + 6. Let closure be FunctionCreate(kind, StrictFormalParameters, FunctionBody, + scope, strict). If functionPrototype was passed as a parameter then pass its + value as the functionPrototype optional argument of FunctionCreate. + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +class C { + static method(/*{ elems }*/) {} +}; + +assert.throws(/*{ error }*/, function() { + C.method(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/cls-decl-meth.template b/src/dstr-binding/error/cls-decl-meth.template new file mode 100644 index 0000000000..e1738089d2 --- /dev/null +++ b/src/dstr-binding/error/cls-decl-meth.template @@ -0,0 +1,68 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/class/dstr-meth- +name: class expression method +esid: sec-runtime-semantics-bindingclassdeclarationevaluation +es6id: 14.5.15 +features: [destructuring-binding] +info: | + ClassDeclaration : class BindingIdentifier ClassTail + + 1. Let className be StringValue of BindingIdentifier. + 2. Let value be the result of ClassDefinitionEvaluation of ClassTail with + argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.3.8 Runtime Semantics: DefineMethod + + MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody } + + [...] + 6. Let closure be FunctionCreate(kind, StrictFormalParameters, FunctionBody, + scope, strict). If functionPrototype was passed as a parameter then pass its + value as the functionPrototype optional argument of FunctionCreate. + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +class C { + method(/*{ elems }*/) {} +}; + +var c = new C(); + +assert.throws(/*{ error }*/, function() { + c.method(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/cls-expr-gen-meth-static.template b/src/dstr-binding/error/cls-expr-gen-meth-static.template new file mode 100644 index 0000000000..73c67100fb --- /dev/null +++ b/src/dstr-binding/error/cls-expr-gen-meth-static.template @@ -0,0 +1,70 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/expressions/class/dstr-gen-meth-static- +name: static class expression generator method +esid: sec-class-definitions-runtime-semantics-evaluation +es6id: 14.5.16 +features: [destructuring-binding] +info: | + ClassExpression : class BindingIdentifieropt ClassTail + + 1. If BindingIdentifieropt is not present, let className be undefined. + 2. Else, let className be StringValue of BindingIdentifier. + 3. Let value be the result of ClassDefinitionEvaluation of ClassTail + with argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + b. Else, + Let status be the result of performing PropertyDefinitionEvaluation + for m with arguments F and false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : + * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, GeneratorBody, scope, strict). + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +var C = class { + static *method(/*{ elems }*/) {} +}; + +assert.throws(/*{ error }*/, function() { + C.method(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/cls-expr-gen-meth.template b/src/dstr-binding/error/cls-expr-gen-meth.template new file mode 100644 index 0000000000..4a90b4d7af --- /dev/null +++ b/src/dstr-binding/error/cls-expr-gen-meth.template @@ -0,0 +1,71 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/expressions/class/dstr-gen-meth- +name: class expression method +esid: sec-class-definitions-runtime-semantics-evaluation +es6id: 14.5.16 +features: [destructuring-binding] +info: | + ClassExpression : class BindingIdentifieropt ClassTail + + 1. If BindingIdentifieropt is not present, let className be undefined. + 2. Else, let className be StringValue of BindingIdentifier. + 3. Let value be the result of ClassDefinitionEvaluation of ClassTail + with argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation + + GeneratorMethod : + * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, GeneratorBody, scope, strict). + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +var C = class { + *method(/*{ elems }*/) {} +}; +var c = new C(); + +assert.throws(/*{ error }*/, function() { + c.method(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/cls-expr-meth-static.template b/src/dstr-binding/error/cls-expr-meth-static.template new file mode 100644 index 0000000000..ce97598e6a --- /dev/null +++ b/src/dstr-binding/error/cls-expr-meth-static.template @@ -0,0 +1,67 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/expressions/class/dstr-meth-static- +name: static class expression method +esid: sec-class-definitions-runtime-semantics-evaluation +es6id: 14.5.16 +features: [destructuring-binding] +info: | + ClassExpression : class BindingIdentifieropt ClassTail + + 1. If BindingIdentifieropt is not present, let className be undefined. + 2. Else, let className be StringValue of BindingIdentifier. + 3. Let value be the result of ClassDefinitionEvaluation of ClassTail + with argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + b. Else, + Let status be the result of performing PropertyDefinitionEvaluation for + m with arguments F and false. + [...] + + 14.3.8 Runtime Semantics: DefineMethod + + MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody } + + [...] + 6. Let closure be FunctionCreate(kind, StrictFormalParameters, FunctionBody, + scope, strict). If functionPrototype was passed as a parameter then pass its + value as the functionPrototype optional argument of FunctionCreate. + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +var C = class { + static method(/*{ elems }*/) {} +}; + +assert.throws(/*{ error }*/, function() { + C.method(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/cls-expr-meth.template b/src/dstr-binding/error/cls-expr-meth.template new file mode 100644 index 0000000000..ff07a66968 --- /dev/null +++ b/src/dstr-binding/error/cls-expr-meth.template @@ -0,0 +1,69 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/expressions/class/dstr-meth- +name: class expression method +esid: sec-class-definitions-runtime-semantics-evaluation +es6id: 14.5.16 +features: [destructuring-binding] +info: | + ClassExpression : class BindingIdentifieropt ClassTail + + 1. If BindingIdentifieropt is not present, let className be undefined. + 2. Else, let className be StringValue of BindingIdentifier. + 3. Let value be the result of ClassDefinitionEvaluation of ClassTail + with argument className. + [...] + + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 21. For each ClassElement m in order from methods + a. If IsStatic of m is false, then + i. Let status be the result of performing + PropertyDefinitionEvaluation for m with arguments proto and + false. + [...] + + 14.3.8 Runtime Semantics: DefineMethod + + MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody } + + [...] + 6. Let closure be FunctionCreate(kind, StrictFormalParameters, FunctionBody, + scope, strict). If functionPrototype was passed as a parameter then pass its + value as the functionPrototype optional argument of FunctionCreate. + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +var C = class { + method(/*{ elems }*/) {} +}; + +var c = new C(); + +assert.throws(/*{ error }*/, function() { + c.method(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/const-stmt.template b/src/dstr-binding/error/const-stmt.template new file mode 100644 index 0000000000..4016210c2d --- /dev/null +++ b/src/dstr-binding/error/const-stmt.template @@ -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. +/*--- +path: language/statements/const/dstr- +name: > + `const` statement +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +es6id: 13.3.1.4 +features: [destructuring-binding] +info: | + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context's LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ + +assert.throws(/*{ error }*/, function() { + const /*{ elems }*/ = /*{ vals }*/; +}); diff --git a/src/dstr-binding/error/for-const.template b/src/dstr-binding/error/for-const.template new file mode 100644 index 0000000000..c3e47fe797 --- /dev/null +++ b/src/dstr-binding/error/for-const.template @@ -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. +/*--- +path: language/statements/for/dstr-const- +name: for statement +esid: sec-for-statement-runtime-semantics-labelledevaluation +es6id: 13.7.4.7 +features: [destructuring-binding] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ + +assert.throws(/*{ error }*/, function() { + for (const /*{ elems }*/ = /*{ vals }*/; ; ) { + return; + } +}); diff --git a/src/dstr-binding/error/for-let.template b/src/dstr-binding/error/for-let.template new file mode 100644 index 0000000000..8efd2feaad --- /dev/null +++ b/src/dstr-binding/error/for-let.template @@ -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. +/*--- +path: language/statements/for/dstr-let- +name: for statement +esid: sec-for-statement-runtime-semantics-labelledevaluation +es6id: 13.7.4.7 +features: [destructuring-binding] +info: | + IterationStatement : + for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement + + [...] + 7. Let forDcl be the result of evaluating LexicalDeclaration. + [...] + + LexicalDeclaration : LetOrConst BindingList ; + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return NormalCompletion(empty). + + BindingList : BindingList , LexicalBinding + + 1. Let next be the result of evaluating BindingList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating LexicalBinding. + + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context’s LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ + +assert.throws(/*{ error }*/, function() { + for (let /*{ elems }*/ = /*{ vals }*/; ; ) { + return; + } +}); diff --git a/src/dstr-binding/error/for-of-const.template b/src/dstr-binding/error/for-of-const.template new file mode 100644 index 0000000000..4b3bcbd529 --- /dev/null +++ b/src/dstr-binding/error/for-of-const.template @@ -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. +/*--- +path: language/statements/for-of/dstr-const- +name: for-of statement +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +es6id: 13.7.5.11 +features: [destructuring-binding] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ + +assert.throws(/*{ error }*/, function() { + for (const /*{ elems }*/ of [/*{ vals }*/]) { + return; + } +}); diff --git a/src/dstr-binding/error/for-of-let.template b/src/dstr-binding/error/for-of-let.template new file mode 100644 index 0000000000..73f3e2175b --- /dev/null +++ b/src/dstr-binding/error/for-of-let.template @@ -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. +/*--- +path: language/statements/for-of/dstr-let- +name: for-of statement +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +es6id: 13.7.5.11 +features: [destructuring-binding] +info: | + IterationStatement : + for ( ForDeclaration of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, + lexicalBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + [...] + iii. Else, + 1. Assert: lhsKind is lexicalBinding. + 2. Assert: lhs is a ForDeclaration. + 3. Let status be the result of performing BindingInitialization + for lhs passing nextValue and iterationEnv as arguments. + [...] +---*/ + +assert.throws(/*{ error }*/, function() { + for (let /*{ elems }*/ of [/*{ vals }*/]) { + return; + } +}); diff --git a/src/dstr-binding/error/for-of-var.template b/src/dstr-binding/error/for-of-var.template new file mode 100644 index 0000000000..a16c42556c --- /dev/null +++ b/src/dstr-binding/error/for-of-var.template @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for-of/dstr-var- +name: for-of statement +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +es6id: 13.7.5.11 +features: [destructuring-binding] +info: | + IterationStatement : + for ( var ForBinding of AssignmentExpression ) Statement + + [...] + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 3. Let destructuring be IsDestructuring of lhs. + [...] + 5. Repeat + [...] + h. If destructuring is false, then + [...] + i. Else + i. If lhsKind is assignment, then + [...] + ii. Else if lhsKind is varBinding, then + 1. Assert: lhs is a ForBinding. + 2. Let status be the result of performing BindingInitialization + for lhs passing nextValue and undefined as the arguments. + [...] +---*/ + +assert.throws(/*{ error }*/, function() { + for (var /*{ elems }*/ of [/*{ vals }*/]) { + return; + } +}); diff --git a/src/dstr-binding/error/for-var.template b/src/dstr-binding/error/for-var.template new file mode 100644 index 0000000000..7780e112ab --- /dev/null +++ b/src/dstr-binding/error/for-var.template @@ -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. +/*--- +path: language/statements/for/dstr-var- +name: for statement +esid: sec-for-statement-runtime-semantics-labelledevaluation +es6id: 13.7.4.7 +features: [destructuring-binding] +info: | + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + [...] + + 13.3.2.4 Runtime Semantics: Evaluation + + VariableDeclarationList : VariableDeclarationList , VariableDeclaration + + 1. Let next be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(next). + 3. Return the result of evaluating VariableDeclaration. + + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for BindingPattern + passing rval and undefined as arguments. +---*/ + +assert.throws(/*{ error }*/, function() { + for (var /*{ elems }*/ = /*{ vals }*/; iterCount < 1; ) { + return; + } +}); diff --git a/src/dstr-binding/error/func-decl.template b/src/dstr-binding/error/func-decl.template new file mode 100644 index 0000000000..13dff27199 --- /dev/null +++ b/src/dstr-binding/error/func-decl.template @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/function/dstr- +name: function declaration +esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject +es6id: 14.1.19 +features: [destructuring-binding] +info: | + FunctionDeclaration : + function BindingIdentifier ( FormalParameters ) { FunctionBody } + + [...] + 3. Let F be FunctionCreate(Normal, FormalParameters, FunctionBody, + scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +function f(/*{ elems }*/) {} + +assert.throws(/*{ error }*/, function() { + f(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/func-expr.template b/src/dstr-binding/error/func-expr.template new file mode 100644 index 0000000000..4ee783d950 --- /dev/null +++ b/src/dstr-binding/error/func-expr.template @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/expressions/function/dstr- +name: function expression +esid: sec-function-definitions-runtime-semantics-evaluation +es6id: 14.1.20 +features: [destructuring-binding] +info: | + FunctionExpression : function ( FormalParameters ) { FunctionBody } + + [...] + 3. Let closure be FunctionCreate(Normal, FormalParameters, FunctionBody, + scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +var f = function(/*{ elems }*/) {}; + +assert.throws(/*{ error }*/, function() { + f(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/gen-func-decl.template b/src/dstr-binding/error/gen-func-decl.template new file mode 100644 index 0000000000..3e3f83e160 --- /dev/null +++ b/src/dstr-binding/error/gen-func-decl.template @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/generators/dstr- +name: generator function declaration +esid: sec-generator-function-definitions-runtime-semantics-instantiatefunctionobject +es6id: 14.4.12 +features: [destructuring-binding] +info: | + GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody } + + [...] + 2. Let F be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +function* f(/*{ elems }*/) {} + +assert.throws(/*{ error }*/, function() { + f(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/gen-func-expr.template b/src/dstr-binding/error/gen-func-expr.template new file mode 100644 index 0000000000..8351bb5e5c --- /dev/null +++ b/src/dstr-binding/error/gen-func-expr.template @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/expressions/generators/dstr- +name: generator function expression +esid: sec-generator-function-definitions-runtime-semantics-evaluation +es6id: 14.4.14 +features: [destructuring-binding] +info: | + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + [...] + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +var f = function*(/*{ elems }*/) {}; + +assert.throws(/*{ error }*/, function() { + f(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/gen-meth.template b/src/dstr-binding/error/gen-meth.template new file mode 100644 index 0000000000..2abd12f537 --- /dev/null +++ b/src/dstr-binding/error/gen-meth.template @@ -0,0 +1,52 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/expressions/object/dstr-gen-meth- +name: generator method +esid: sec-generator-function-definitions-runtime-semantics-propertydefinitionevaluation +es6id: 14.4.13 +features: [destructuring-binding] +info: | + GeneratorMethod : + * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + 1. Let propKey be the result of evaluating PropertyName. + 2. ReturnIfAbrupt(propKey). + 3. If the function code for this GeneratorMethod is strict mode code, + let strict be true. Otherwise let strict be false. + 4. Let scope be the running execution context's LexicalEnvironment. + 5. Let closure be GeneratorFunctionCreate(Method, + StrictFormalParameters, GeneratorBody, scope, strict). + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +var obj = { + *method(/*{ elems }*/) {} +}; + +assert.throws(/*{ error }*/, function() { + obj.method(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/let-stmt.template b/src/dstr-binding/error/let-stmt.template new file mode 100644 index 0000000000..66ba68be67 --- /dev/null +++ b/src/dstr-binding/error/let-stmt.template @@ -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. +/*--- +path: language/statements/let/dstr- +name: > + `let` statement +esid: sec-let-and-const-declarations-runtime-semantics-evaluation +es6id: 13.3.1.4 +features: [destructuring-binding] +info: | + LexicalBinding : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let value be GetValue(rhs). + 3. ReturnIfAbrupt(value). + 4. Let env be the running execution context's LexicalEnvironment. + 5. Return the result of performing BindingInitialization for BindingPattern + using value and env as the arguments. +---*/ + +assert.throws(/*{ error }*/, function() { + let /*{ elems }*/ = /*{ vals }*/; +}); diff --git a/src/dstr-binding/error/meth.template b/src/dstr-binding/error/meth.template new file mode 100644 index 0000000000..b0fdecc58d --- /dev/null +++ b/src/dstr-binding/error/meth.template @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/expressions/object/dstr-meth- +name: method +esid: sec-runtime-semantics-definemethod +es6id: 14.3.8 +features: [destructuring-binding] +info: | + MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody } + + [...] + 6. Let closure be FunctionCreate(kind, StrictFormalParameters, + FunctionBody, scope, strict). If functionPrototype was passed as a + parameter then pass its value as the functionPrototype optional argument + of FunctionCreate. + [...] + + 9.2.1 [[Call]] ( thisArgument, argumentsList) + + [...] + 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + [...] + + 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) + + 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). + [...] + + 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) + + [...] + 23. Let iteratorRecord be Record {[[iterator]]: + CreateListIterator(argumentsList), [[done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + b. Let formalStatus be IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] +---*/ + +var obj = { + method(/*{ elems }*/) {} +}; + +assert.throws(/*{ error }*/, function() { + obj.method(/*{ vals }*/); +}); diff --git a/src/dstr-binding/error/try.template b/src/dstr-binding/error/try.template new file mode 100644 index 0000000000..a7a83647ca --- /dev/null +++ b/src/dstr-binding/error/try.template @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/try/dstr- +name: try statement +esid: sec-runtime-semantics-catchclauseevaluation +es6id: 13.15.7 +features: [destructuring-binding] +info: | + Catch : catch ( CatchParameter ) Block + + [...] + 5. Let status be the result of performing BindingInitialization for + CatchParameter passing thrownValue and catchEnv as arguments. + [...] +---*/ + +assert.throws(/*{ error }*/, function() { + try { + throw /*{ vals }*/; + } catch (/*{ elems }*/) {} +}); diff --git a/src/dstr-binding/error/var-stmt.template b/src/dstr-binding/error/var-stmt.template new file mode 100644 index 0000000000..f3adc65f60 --- /dev/null +++ b/src/dstr-binding/error/var-stmt.template @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/variable/dstr- +name: > + `var` statement +esid: sec-variable-statement-runtime-semantics-evaluation +es6id: 13.3.2.4 +features: [destructuring-binding] +info: | + VariableDeclaration : BindingPattern Initializer + + 1. Let rhs be the result of evaluating Initializer. + 2. Let rval be GetValue(rhs). + 3. ReturnIfAbrupt(rval). + 4. Return the result of performing BindingInitialization for + BindingPattern passing rval and undefined as arguments. +---*/ + +assert.throws(/*{ error }*/, function() { + var /*{ elems }*/ = /*{ vals }*/; +}); diff --git a/src/dstr-binding/obj-init-null.case b/src/dstr-binding/obj-init-null.case new file mode 100644 index 0000000000..0772e36f77 --- /dev/null +++ b/src/dstr-binding/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/obj-init-undefined.case b/src/dstr-binding/obj-init-undefined.case new file mode 100644 index 0000000000..f41405f6fe --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-empty.case b/src/dstr-binding/obj-ptrn-empty.case new file mode 100644 index 0000000000..97ecebd347 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-id-get-value-err.case b/src/dstr-binding/obj-ptrn-id-get-value-err.case new file mode 100644 index 0000000000..68ae3348af --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-id-init-fn-name-arrow.case b/src/dstr-binding/obj-ptrn-id-init-fn-name-arrow.case new file mode 100644 index 0000000000..55cc1ad0ba --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-id-init-fn-name-class.case b/src/dstr-binding/obj-ptrn-id-init-fn-name-class.case new file mode 100644 index 0000000000..f74c1e7da7 --- /dev/null +++ b/src/dstr-binding/obj-ptrn-id-init-fn-name-class.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" 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 {} } +//- vals +{} +//- body +assert.sameValue(cls.name, 'cls'); +assert.notSameValue(xCls.name, 'xCls'); diff --git a/src/dstr-binding/obj-ptrn-id-init-fn-name-cover.case b/src/dstr-binding/obj-ptrn-id-init-fn-name-cover.case new file mode 100644 index 0000000000..624b00fce0 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-id-init-fn-name-fn.case b/src/dstr-binding/obj-ptrn-id-init-fn-name-fn.case new file mode 100644 index 0000000000..d6130cc9a6 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-id-init-fn-name-gen.case b/src/dstr-binding/obj-ptrn-id-init-fn-name-gen.case new file mode 100644 index 0000000000..977d9f08d9 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-id-init-skipped.case b/src/dstr-binding/obj-ptrn-id-init-skipped.case new file mode 100644 index 0000000000..ef10476d53 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-id-init-throws.case b/src/dstr-binding/obj-ptrn-id-init-throws.case new file mode 100644 index 0000000000..e67f63480e --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-id-init-unresolvable.case b/src/dstr-binding/obj-ptrn-id-init-unresolvable.case new file mode 100644 index 0000000000..dd6d9dc839 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-id-trailing-comma.case b/src/dstr-binding/obj-ptrn-id-trailing-comma.case new file mode 100644 index 0000000000..5dc0cbe68a --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-list-err.case b/src/dstr-binding/obj-ptrn-list-err.case new file mode 100644 index 0000000000..4c46d2a715 --- /dev/null +++ b/src/dstr-binding/obj-ptrn-list-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: 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 +//- teardown +assert.sameValue(initCount, 0); diff --git a/src/dstr-binding/obj-ptrn-prop-ary-init.case b/src/dstr-binding/obj-ptrn-prop-ary-init.case new file mode 100644 index 0000000000..41ffaa1ac6 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-ary-trailing-comma.case b/src/dstr-binding/obj-ptrn-prop-ary-trailing-comma.case new file mode 100644 index 0000000000..17007b54cf --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-ary-value-null.case b/src/dstr-binding/obj-ptrn-prop-ary-value-null.case new file mode 100644 index 0000000000..abe84e43f7 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-ary.case b/src/dstr-binding/obj-ptrn-prop-ary.case new file mode 100644 index 0000000000..254c8f06ba --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-eval-err.case b/src/dstr-binding/obj-ptrn-prop-eval-err.case new file mode 100644 index 0000000000..9721474c36 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-id-get-value-err.case b/src/dstr-binding/obj-ptrn-prop-id-get-value-err.case new file mode 100644 index 0000000000..50be759877 --- /dev/null +++ b/src/dstr-binding/obj-ptrn-prop-id-get-value-err.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: 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 +//- teardown +assert.sameValue(initEvalCount, 0); diff --git a/src/dstr-binding/obj-ptrn-prop-id-init-skipped.case b/src/dstr-binding/obj-ptrn-prop-id-init-skipped.case new file mode 100644 index 0000000000..49ec6684f2 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-id-init-throws.case b/src/dstr-binding/obj-ptrn-prop-id-init-throws.case new file mode 100644 index 0000000000..e878fc6f3a --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-id-init-unresolvable.case b/src/dstr-binding/obj-ptrn-prop-id-init-unresolvable.case new file mode 100644 index 0000000000..d11f68d9df --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-id-init.case b/src/dstr-binding/obj-ptrn-prop-id-init.case new file mode 100644 index 0000000000..5b6723f746 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-id-trailing-comma.case b/src/dstr-binding/obj-ptrn-prop-id-trailing-comma.case new file mode 100644 index 0000000000..cee4bc0577 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-id.case b/src/dstr-binding/obj-ptrn-prop-id.case new file mode 100644 index 0000000000..ebd0652976 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-obj-init.case b/src/dstr-binding/obj-ptrn-prop-obj-init.case new file mode 100644 index 0000000000..cc6da66b45 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-obj-value-null.case b/src/dstr-binding/obj-ptrn-prop-obj-value-null.case new file mode 100644 index 0000000000..828049f9a0 --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-obj-value-undef.case b/src/dstr-binding/obj-ptrn-prop-obj-value-undef.case new file mode 100644 index 0000000000..6c4582af3d --- /dev/null +++ b/src/dstr-binding/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/obj-ptrn-prop-obj.case b/src/dstr-binding/obj-ptrn-prop-obj.case new file mode 100644 index 0000000000..da412ccd6a --- /dev/null +++ b/src/dstr-binding/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; +});