diff --git a/src/dstr-assignment-async-iteration/array-elem-init-assignment.case b/src/dstr-assignment-async-iteration/array-elem-init-assignment.case new file mode 100644 index 0000000000000000000000000000000000000000..4a736a739581ae3cbfaf00f7d1ed8746e39aa8bd --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-init-assignment.case @@ -0,0 +1,28 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + If the Initializer is present and v is undefined, the Initializer should be + evaluated and the result assigned to the target reference. +template: default +---*/ + +//- setup +var v2, vNull, vHole, vUndefined, vOob; +//- elems +[v2 = 10, vNull = 11, vHole = 12, vUndefined = 13, vOob = 14] +//- vals +[2, null, , undefined] +//- body +assert.sameValue(v2, 2); +assert.sameValue(vNull, null); +assert.sameValue(vHole, 12); +assert.sameValue(vUndefined, 13); +assert.sameValue(vOob, 14); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-init-evaluation.case b/src/dstr-assignment-async-iteration/array-elem-init-evaluation.case new file mode 100644 index 0000000000000000000000000000000000000000..b3b767fa1c7dfdbfe943d21378796076a25adb55 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-init-evaluation.case @@ -0,0 +1,26 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + The Initializer should only be evaluated if v is undefined. +template: default +---*/ + +//- setup +var flag1 = false, flag2 = false; +var _; +//- elems +[ _ = flag1 = true, _ = flag2 = true ] +//- vals +[14] +//- body +assert.sameValue(flag1, false); +assert.sameValue(flag2, true); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); + diff --git a/src/dstr-assignment-async-iteration/array-elem-init-fn-name-arrow.case b/src/dstr-assignment-async-iteration/array-elem-init-fn-name-arrow.case new file mode 100644 index 0000000000000000000000000000000000000000..e95a3117c9d4e97f30bb96b3365d4ddbf43cfd87 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-init-fn-name-arrow.case @@ -0,0 +1,36 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Assignment of function `name` attribute (ArrowFunction) +template: default +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). +includes: [propertyHelper.js] +---*/ + +//- setup +var arrow; +//- elems +[ arrow = () => {} ] +//- vals +[] +//- body +assert.sameValue(arrow.name, 'arrow'); +verifyNotEnumerable(arrow, 'name'); +verifyNotWritable(arrow, 'name'); +verifyConfigurable(arrow, 'name'); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-init-fn-name-class.case b/src/dstr-assignment-async-iteration/array-elem-init-fn-name-class.case new file mode 100644 index 0000000000000000000000000000000000000000..2849395c5f02e838e46a7c37445b8834219a0d58 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-init-fn-name-class.case @@ -0,0 +1,42 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Assignment of function `name` attribute (ClassExpression) +template: default +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). +includes: [propertyHelper.js] +features: [class] +---*/ + +//- setup +var xCls, cls, xCls2; +//- elems +[ xCls = class x {}, cls = class {}, xCls2 = class { static name() {} } ] +//- vals +[] +//- body +assert(xCls.name !== 'xCls'); +assert(xCls2.name !== 'xCls2'); + +assert.sameValue(cls.name, 'cls'); +verifyNotEnumerable(cls, 'name'); +verifyNotWritable(cls, 'name'); +verifyConfigurable(cls, 'name'); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); + diff --git a/src/dstr-assignment-async-iteration/array-elem-init-fn-name-cover.case b/src/dstr-assignment-async-iteration/array-elem-init-fn-name-cover.case new file mode 100644 index 0000000000000000000000000000000000000000..093eea2614a113e41e6f307d78b158a60db05cf1 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-init-fn-name-cover.case @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Assignment of function `name` attribute (CoverParenthesizedExpression) +template: default +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). +includes: [propertyHelper.js] +---*/ + +//- setup +var xCover, cover; +//- elems +[ xCover = (0, function() {}), cover = (function() {}) ] +//- vals +[] +//- body +assert(xCover.name !== 'xCover'); + +assert.sameValue(cover.name, 'cover'); +verifyNotEnumerable(cover, 'name'); +verifyNotWritable(cover, 'name'); +verifyConfigurable(cover, 'name'); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-init-fn-name-fn.case b/src/dstr-assignment-async-iteration/array-elem-init-fn-name-fn.case new file mode 100644 index 0000000000000000000000000000000000000000..d2e65e618f99ba0c24e75a47dac648dd464ae95a --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-init-fn-name-fn.case @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Assignment of function `name` attribute (FunctionExpression) +template: default +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). +includes: [propertyHelper.js] +features: [class] +---*/ + +//- setup +var xFn, fn; +//- elems +[ xFn = function x() {}, fn = function() {} ] +//- vals +[] +//- body +assert(xFn.name !== 'xFn'); + +assert.sameValue(fn.name, 'fn'); +verifyNotEnumerable(fn, 'name'); +verifyNotWritable(fn, 'name'); +verifyConfigurable(fn, 'name'); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-init-fn-name-gen.case b/src/dstr-assignment-async-iteration/array-elem-init-fn-name-gen.case new file mode 100644 index 0000000000000000000000000000000000000000..137f38423bad28c81e0cbeffd25ab954f1fd3586 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-init-fn-name-gen.case @@ -0,0 +1,39 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Assignment of function `name` attribute (GeneratorExpression) +template: default +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). +includes: [propertyHelper.js] +features: [generators] +---*/ + +//- setup +var xGen, gen; +//- elems +[ xGen = function* x() {}, gen = function*() {} ] +//- vals +[] +//- body +assert.notSameValue(xGen.name, 'xGen'); + +assert.sameValue(gen.name, 'gen'); +verifyNotEnumerable(gen, 'name'); +verifyNotWritable(gen, 'name'); +verifyConfigurable(gen, 'name'); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-init-in.case b/src/dstr-assignment-async-iteration/array-elem-init-in.case new file mode 100644 index 0000000000000000000000000000000000000000..be7e9345d89121b681006f8553165906072f5e85 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-init-in.case @@ -0,0 +1,22 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + The Initializer in an AssignmentElement may be an `in` expression. +template: default +---*/ + +//- setup +var x; +//- elems +[ x = 'x' in {} ] +//- vals +[] +//- body +assert.sameValue(x, false); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-init-order.case b/src/dstr-assignment-async-iteration/array-elem-init-order.case new file mode 100644 index 0000000000000000000000000000000000000000..c7a11046491c4605b53ff5cdf2bb10fcb9adfdb8 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-init-order.case @@ -0,0 +1,25 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Initializer values should be assigned in left-to-right order. +template: default +---*/ + +//- setup +var x = 0; +var a, b; +//- elems +[ a = x += 1, b = x *= 2 ] +//- vals +[] +//- body +assert.sameValue(a, 1); +assert.sameValue(b, 2); +assert.sameValue(x, 2); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-init-simple-no-strict.case b/src/dstr-assignment-async-iteration/array-elem-init-simple-no-strict.case new file mode 100644 index 0000000000000000000000000000000000000000..55fd0297eb4a7485351e21cd18a18521a812cdbe --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-init-simple-no-strict.case @@ -0,0 +1,26 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Identifiers that appear as the DestructuringAssignmentTarget in an + AssignmentElement should take on the iterated value corresponding to their + position in the ArrayAssignmentPattern. +template: default +flags: [noStrict] +---*/ + +//- setup +var argument, eval; +//- elems +[arguments = 4, eval = 5] +//- vals +[] +//- body +assert.sameValue(arguments, 4); +assert.sameValue(eval, 5); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-iter-nrml-close-skip.case b/src/dstr-assignment-async-iteration/array-elem-iter-nrml-close-skip.case new file mode 100644 index 0000000000000000000000000000000000000000..322e4f2f5aa118a3efa025bea0b07415b33cfddf --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-iter-nrml-close-skip.case @@ -0,0 +1,47 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: > + IteratorClose is not called when assignment evaluation has exhausted the + iterator +info: | + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, result). + 6. Return result. +features: [Symbol.iterator] +template: default +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var nextCount = 0; +var returnCount = 0; +var _; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + return {}; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; +//- elems +[ _ ] +//- vals +iterable +//- body +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-iter-nrml-close.case b/src/dstr-assignment-async-iteration/array-elem-iter-nrml-close.case new file mode 100644 index 0000000000000000000000000000000000000000..70a33b9705d014b054d11377ebea0704e4f31e58 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-iter-nrml-close.case @@ -0,0 +1,63 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: > + IteratorClose is called when assignment evaluation has not exhausted the + iterator +info: | + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 6. Return result. + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] +features: [Symbol.iterator] +template: default +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var _; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; +//- elems +[ _ ] +//- vals +iterable +//- body +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-nested-array-yield-ident-valid.case b/src/dstr-assignment-async-iteration/array-elem-nested-array-yield-ident-valid.case new file mode 100644 index 0000000000000000000000000000000000000000..cd2b0313b1ed17f0d1c828c23e68884bb5f05e40 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-nested-array-yield-ident-valid.case @@ -0,0 +1,21 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When a `yield` token appears within the DestructuringAssignmentTarget of a + nested destructuring assignment outside of strict mode, it behaves as an + IdentifierReference. +template: default +flags: [noStrict] +---*/ + +//- setup +var yield = 'prop'; +var x = {}; +//- elems +[[x[yield]]] +//- vals +[[22]] +//- body +assert.sameValue(x.prop, 22); diff --git a/src/dstr-assignment-async-iteration/array-elem-nested-array.case b/src/dstr-assignment-async-iteration/array-elem-nested-array.case new file mode 100644 index 0000000000000000000000000000000000000000..f5cbc1ff8ac0ca7b7be7478d5a8bbf8a9f937484 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-nested-array.case @@ -0,0 +1,19 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an array literal, it should be parsed + parsed as a DestructuringAssignmentPattern and evaluated as a destructuring + assignment. +template: default +---*/ + +//- setup +var x; +//- elems +[[x]] +//- vals +[[1]] +//- body +assert.sameValue(x, 1); diff --git a/src/dstr-assignment-async-iteration/array-elem-nested-obj-yield-expr.case b/src/dstr-assignment-async-iteration/array-elem-nested-obj-yield-expr.case new file mode 100644 index 0000000000000000000000000000000000000000..84af24b9a51036fde3936330ae3bccf15ac41b94 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-nested-obj-yield-expr.case @@ -0,0 +1,31 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When a `yield` token appears within the Initializer of a nested + destructuring assignment and within a generator function body, it behaves + as a YieldExpression. +template: async-generator +---*/ + +//- setup +var x; + + +//- elems +[{ x = yield }] +//- vals +[{}] +//- teardown +iter.next().then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, false); + assert.sameValue(x, undefined); + + iter.next(4).then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, true); + assert.sameValue(x, 4); + }, $DONE).then($DONE, $DONE); +}, $DONE).catch($DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-nested-obj-yield-ident-valid.case b/src/dstr-assignment-async-iteration/array-elem-nested-obj-yield-ident-valid.case new file mode 100644 index 0000000000000000000000000000000000000000..09b4eff6141ebd08fff3591af5b4a40398274696 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-nested-obj-yield-ident-valid.case @@ -0,0 +1,28 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When a `yield` token appears within the Initializer of a nested + destructuring assignment outside of a generator function body, it behaves + as an IdentifierReference. +template: async-function +flags: [noStrict] +---*/ + +//- setup +var yield = 2; +var x; +//- elems +[{ x = yield }] +//- vals +[{}] +//- body +assert.sameValue(x, 2); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); + diff --git a/src/dstr-assignment-async-iteration/array-elem-nested-obj.case b/src/dstr-assignment-async-iteration/array-elem-nested-obj.case new file mode 100644 index 0000000000000000000000000000000000000000..50faa760f9e91790b65e597ba9ac3485a7712088 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-nested-obj.case @@ -0,0 +1,26 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an object literal, it should be + parsed as a DestructuringAssignmentPattern and evaluated as a destructuring + assignment. +template: default +---*/ + +//- setup +var x; +//- elems +[{ x }] +//- vals +[{ x: 2 }] +//- body +assert.sameValue(x, 2); + + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-put-prop-ref-no-get.case b/src/dstr-assignment-async-iteration/array-elem-put-prop-ref-no-get.case new file mode 100644 index 0000000000000000000000000000000000000000..217eff2dba2f4f1280a4e8e3bb6bfeda72fe0d18 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-put-prop-ref-no-get.case @@ -0,0 +1,32 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + If the DestructuringAssignmentTarget of an AssignmentElement is a + PropertyReference, it should not be evaluated. +template: default +---*/ + +//- setup +var x, setValue; +x = { + get y() { + $ERROR('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}; +//- elems +[x.y] +//- vals +[23] +//- body +assert.sameValue(setValue, 23); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-put-prop-ref.case b/src/dstr-assignment-async-iteration/array-elem-put-prop-ref.case new file mode 100644 index 0000000000000000000000000000000000000000..111e769e7dab735f58ff3cb2aad2b5c5ccc4cc2f --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-put-prop-ref.case @@ -0,0 +1,24 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + The DestructuringAssignmentTarget of an AssignmentElement may be a + PropertyReference. +template: default +---*/ + +//- setup +var x = {}; +//- elems +[x.y] +//- vals +[4] +//- body +assert.sameValue(x.y, 4); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-put-unresolvable-no-strict.case b/src/dstr-assignment-async-iteration/array-elem-put-unresolvable-no-strict.case new file mode 100644 index 0000000000000000000000000000000000000000..af3084436e265aa698c5307a502484b36364dbce --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-put-unresolvable-no-strict.case @@ -0,0 +1,22 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Outside of strict mode, if the the assignment target is an unresolvable + reference, a new `var` binding should be created in the environment record. +template: default +flags: [noStrict] +---*/ + +//- elems +[ unresolvable ] +//- vals +[] +//- body +assert.sameValue(unresolvable, undefined); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-target-identifier.case b/src/dstr-assignment-async-iteration/array-elem-target-identifier.case new file mode 100644 index 0000000000000000000000000000000000000000..466742c255b6b643205e9c3fac5d6fcd01d4af60 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-target-identifier.case @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Identifiers that appear as the DestructuringAssignmentTarget in an + AssignmentElement should take on the iterated value corresponding to their + position in the ArrayAssignmentPattern. +template: async-function +---*/ + +//- setup +var x, y, z; +//- elems +[x, y, z] +//- vals +[1, 2, 3] +//- body +assert.sameValue(x, 1); +assert.sameValue(y, 2); +assert.sameValue(z, 3); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-target-simple-no-strict.case b/src/dstr-assignment-async-iteration/array-elem-target-simple-no-strict.case new file mode 100644 index 0000000000000000000000000000000000000000..e626f3be26e1e407c1413736b7ad5299eef00b73 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-target-simple-no-strict.case @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Identifiers that appear as the DestructuringAssignmentTarget in an + AssignmentElement should take on the iterated value corresponding to their + position in the ArrayAssignmentPattern. +template: async-generator +flags: [noStrict] +---*/ + +//- setup +var argument, eval; +//- elems +[arguments, eval] +//- vals +[2, 3] +//- body +assert.sameValue(arguments, 2); +assert.sameValue(eval, 3); + + +//- teardown +iter.next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-target-yield-expr.case b/src/dstr-assignment-async-iteration/array-elem-target-yield-expr.case new file mode 100644 index 0000000000000000000000000000000000000000..51d841a826af7e93eb1e8bdd133052772afefb7d --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-target-yield-expr.case @@ -0,0 +1,37 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When a `yield` token appears within the DestructuringAssignmentTarget of an + AssignmentElement within a generator function body, it behaves as a + YieldExpression. +template: async-generator +features: [generators] +---*/ + +//- setup +var value = [33]; +var x = {}; +var iterationResult; + +//- elems +[ x[yield] ] +//- vals +[33] + + +//- teardown +iter.next().then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, false); + assert.sameValue(x.prop, undefined); + + // TODO add iterCount + // + iter.next('prop').then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, true); + assert.sameValue(x.prop, 33); + }).then($DONE, $DONE); +}); diff --git a/src/dstr-assignment-async-iteration/array-elem-target-yield-valid.case b/src/dstr-assignment-async-iteration/array-elem-target-yield-valid.case new file mode 100644 index 0000000000000000000000000000000000000000..5e947aab32814073615fb1c1d0540710dc77e7a2 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-target-yield-valid.case @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When a `yield` token appears within the DestructuringAssignmentTarget of an + AssignmentElement outside of a generator function body, it behaves as an + IdentifierReference. +template: async-function +flags: [noStrict] +---*/ + +//- setup +var yield = 'prop'; +var x = {}; +//- elems +[ x[yield] ] +//- vals +[33] +//- body +assert.sameValue(x.prop, 33); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-trlg-iter-elision-iter-nrml-close-skip.case b/src/dstr-assignment-async-iteration/array-elem-trlg-iter-elision-iter-nrml-close-skip.case new file mode 100644 index 0000000000000000000000000000000000000000..5f2a03b450ee0982d7c2a21b07e826cd59a9c911 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-trlg-iter-elision-iter-nrml-close-skip.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. +/*--- +desc: IteratorClose not invoked when elision exhausts the iterator +info: | + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 6. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. If status is an abrupt completion, then + [...] + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + 9. Return Completion(status). +features: [Symbol.iterator] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var nextCount = 0; +var returnCount = 0; +var x; +var iterator = { + next() { + nextCount += 1; + + return { done: nextCount > 1 }; + }, + return() { + returnCount += 1; + } +}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; +//- elems +[ x , , ] +//- vals +iterable +//- body +assert.sameValue(nextCount, 2); +assert.sameValue(returnCount, 0); + + +//- teardown +iter.next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-trlg-iter-elision-iter-nrml-close.case b/src/dstr-assignment-async-iteration/array-elem-trlg-iter-elision-iter-nrml-close.case new file mode 100644 index 0000000000000000000000000000000000000000..57df4273cfef89f522110427d289b1196c5ddb2d --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-trlg-iter-elision-iter-nrml-close.case @@ -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. +/*--- +desc: IteratorClose invoked when elision does not exhaust the iterator +info: | + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 6. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. If status is an abrupt completion, then + [...] + 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] +features: [Symbol.iterator] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var x; +var iterator = { + next() { + nextCount += 1; + + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; + +//- elems +[ x , , ] +//- vals +iterable +//- body +assert.sameValue(nextCount, 2); +assert.sameValue(returnCount, 1); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + +//- teardown +iter.next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-trlg-iter-list-nrml-close-skip.case b/src/dstr-assignment-async-iteration/array-elem-trlg-iter-list-nrml-close-skip.case new file mode 100644 index 0000000000000000000000000000000000000000..6f94122f00c531a6defc439ec32b5c6fefda3778 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-trlg-iter-list-nrml-close-skip.case @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: > + IteratorClose is not invoked when evaluation of AssignmentElementList + exhausts the iterator +info: | + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + b. Return Completion(status). +features: [Symbol.iterator] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var nextCount = 0; +var returnCount = 0; +var thrower = function() { + throw new Test262Error(); +}; +var x; +var iterator = { + next() { + nextCount += 1; + return { done: true }; + }, + return() { + returnCount += 1; + } +}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; +//- elems +[ x , ] +//- vals +iterable +//- body +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +//- teardown +iter.next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elem-trlg-iter-list-nrml-close.case b/src/dstr-assignment-async-iteration/array-elem-trlg-iter-list-nrml-close.case new file mode 100644 index 0000000000000000000000000000000000000000..792e09097adfdf8a29e4478ac14ad7ef1efaa352 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elem-trlg-iter-list-nrml-close.case @@ -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. +/*--- +desc: > + IteratorClose is invoked when evaluation of AssignmentElementList completes + without exhausting the iterator +info: | + ArrayAssignmentPattern : + [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] + + [...] + 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + 4. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentElementList using + iteratorRecord as the argument. + 5. If status is an abrupt completion, then + a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + status). + b. Return Completion(status). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] +features: [Symbol.iterator] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var x; +var iterator = { + next() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; +//- elems +[ x , ] +//- vals +iterable +//- body +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + +//- teardown +iter.next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elision-iter-nrml-close-skip.case b/src/dstr-assignment-async-iteration/array-elision-iter-nrml-close-skip.case new file mode 100644 index 0000000000000000000000000000000000000000..43a0ee8a03ecffe9ec765d0080ccde65eb522837 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elision-iter-nrml-close-skip.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. +/*--- +desc: > + IteratorClose is not called when iteration has exhausted the iterator +info: | + ArrayAssignmentPattern : [ Elision ] + + 1. Let iterator be GetIterator(value). + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + [...] +features: [Symbol.iterator] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var nextCount = 0; +var returnCount = 0; +var iterator = { + next() { + nextCount += 1; + return { done: true }; + }, + return() { + returnCount += 1; + return {}; + } +}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; +//- elems +[ , ] +//- vals +iterable +//- body +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + +//- teardown +iter.next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elision-iter-nrml-close.case b/src/dstr-assignment-async-iteration/array-elision-iter-nrml-close.case new file mode 100644 index 0000000000000000000000000000000000000000..5ec6cbbfd03b04f0094c1f95fdc92ad0e2188507 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elision-iter-nrml-close.case @@ -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. +/*--- +desc: > + IteratorClose is called when assignment evaluation has not exhausted the + iterator +info: | + ArrayAssignmentPattern : [ Elision ] + + 1. Let iterator be GetIterator(value). + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + [...] + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] +features: [Symbol.iterator] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var iterator = { + next() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; + +//- elems +[ , ] +//- vals +iterable +//- body +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 1); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + + +//- teardown +iter.next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elision-val-array.case b/src/dstr-assignment-async-iteration/array-elision-val-array.case new file mode 100644 index 0000000000000000000000000000000000000000..5502f2987802ee81dda470027a234136cc99ceb9 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elision-val-array.case @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: > + An ArrayAssignmentPattern containing only Elisions requires iterable values +template: default +---*/ + +//- elems +[,] +//- vals +[] + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-elision-val-string.case b/src/dstr-assignment-async-iteration/array-elision-val-string.case new file mode 100644 index 0000000000000000000000000000000000000000..4c6f1083a00b4d9f70d6304153a74aaa7c37f693 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-elision-val-string.case @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: > + An ArrayAssignmentPattern containing only Elisions requires iterable values +template: default +---*/ + +//- elems +[,] +//- vals +'string literal' + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-empty-iter-close.case b/src/dstr-assignment-async-iteration/array-empty-iter-close.case new file mode 100644 index 0000000000000000000000000000000000000000..95222bd089279f3c62e05a37f13a3af82a424eb9 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-empty-iter-close.case @@ -0,0 +1,59 @@ +// 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 without iterating +info: | + ArrayAssignmentPattern : [ ] + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + 3. Return IteratorClose(iterator, NormalCompletion(empty)). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] +features: [Symbol.iterator] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var iterator = { + next() { + nextCount += 1; + return { done: true }; + }, + return() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; +//- elems +[] +//- vals +iterable +//- body +assert.sameValue(nextCount, 0); +assert.sameValue(returnCount, 1); +assert.sameValue(thisValue, iterator, 'correct `this` value'); +assert(!!args, 'arguments object provided'); +assert.sameValue(args.length, 0, 'zero arguments specified'); + + +//- teardown +iter.next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-empty-val-array.case b/src/dstr-assignment-async-iteration/array-empty-val-array.case new file mode 100644 index 0000000000000000000000000000000000000000..8961f02b65c528527128640e07dc42d3376191bb --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-empty-val-array.case @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + An ArrayAssignmentPattern without an AssignmentElementList requires + iterable values. +template: default +---*/ + +//- elems +[] +//- vals +[] + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-empty-val-string.case b/src/dstr-assignment-async-iteration/array-empty-val-string.case new file mode 100644 index 0000000000000000000000000000000000000000..5f395686bdd4335f9952f1c7b20e226f7f46ecc5 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-empty-val-string.case @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + An ArrayAssignmentPattern without an AssignmentElementList requires + iterable values. +template: default +---*/ + +//- elems +[] +//- vals +'string literal' + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-rest-after-element.case b/src/dstr-assignment-async-iteration/array-rest-after-element.case new file mode 100644 index 0000000000000000000000000000000000000000..adb195276c933d43073a28670abca507f79fd2c1 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-after-element.case @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + An AssignmentRestElement following an AssignmentElement consumes all + remaining iterable values. +template: default +es6id: 12.14.5.3 +---*/ + +//- setup +var x, y; +//- elems +[x, ...y] +//- vals +[1, 2, 3] +//- body +assert.sameValue(x, 1); +assert.sameValue(y.length, 2); +assert.sameValue(y[0], 2); +assert.sameValue(y[1], 3); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-rest-after-elision.case b/src/dstr-assignment-async-iteration/array-rest-after-elision.case new file mode 100644 index 0000000000000000000000000000000000000000..de37221eca0b9d39599ecdf2b7195f0676b90ae2 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-after-elision.case @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + An AssignmentRestElement following an elision consumes all remaining + iterable values. +template: default +---*/ + +//- setup +var x; +//- elems +[, ...x] +//- vals +[1, 2, 3] +//- body +assert.sameValue(x.length, 2); +assert.sameValue(x[0], 2); +assert.sameValue(x[1], 3); + + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-rest-elision.case b/src/dstr-assignment-async-iteration/array-rest-elision.case new file mode 100644 index 0000000000000000000000000000000000000000..f505175c1dd25ccc48f9e01e2bd89564f21a340e --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-elision.case @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + ArrayAssignmentPattern may include elisions at any position preceeding a + AssignmentRestElement in a AssignmentElementList. +template: default +---*/ + +//- setup +var x, y; +//- elems +[, , x, , ...y] +//- vals +[1, 2, 3, 4, 5, 6] +//- body +assert.sameValue(x, 3); +assert.sameValue(y.length, 2); +assert.sameValue(y[0], 5); +assert.sameValue(y[1], 6); + + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-rest-iter-nrml-close-skip.case b/src/dstr-assignment-async-iteration/array-rest-iter-nrml-close-skip.case new file mode 100644 index 0000000000000000000000000000000000000000..621cb760195a86fa2da563648beb7a04a0c52f69 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-iter-nrml-close-skip.case @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: > + IteratorClose is not called when assignment evaluation has exhausted the + iterator +info: | + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 7. Return result. +features: [Symbol.iterator] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var nextCount = 0; +var returnCount = 0; +var x; +var iterator = { + next() { + nextCount += 1; + return { done: true }; + }, + return() { + returnCount += 1; + } +}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; +//- elems +[ ...x ] +//- vals +iterable +//- body +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); + + +iter.next().then(() => { + assert.throws(Test262Error, () => iter.return()); + assert.sameValue(returnCount, 1); + assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); +}) + diff --git a/src/dstr-assignment-async-iteration/array-rest-iter-rtrn-close-err.case b/src/dstr-assignment-async-iteration/array-rest-iter-rtrn-close-err.case new file mode 100644 index 0000000000000000000000000000000000000000..e7395c69c5b309de9a7febdcd9a6ffcff1873973 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-iter-rtrn-close-err.case @@ -0,0 +1,65 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: > + IteratorClose is called when reference evaluation produces a "return" + completion +info: | + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + b. ReturnIfAbrupt(lref). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). +features: [Symbol.iterator, generators] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +function ReturnError() {} +var returnCount = 0; +var unreachable = 0; +var iterator = { + return() { + returnCount += 1; + + throw new Test262Error(); + } +}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; + +//- elems +[...{}[yield]] +//- vals +iterable +//- body +unreachable += 1; +//- teardown + +iter.next().then(() => { + assert.throws(Test262Error, () => iter.return()); + assert.sameValue(returnCount, 1); + assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); +}).then($DONE, $DONE); + diff --git a/src/dstr-assignment-async-iteration/array-rest-iter-rtrn-close-null.case b/src/dstr-assignment-async-iteration/array-rest-iter-rtrn-close-null.case new file mode 100644 index 0000000000000000000000000000000000000000..169c106f01963c302eb623ce5271f0c41019461e --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-iter-rtrn-close-null.case @@ -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. +/*--- +desc: > + IteratorClose throws a TypeError when `return` returns a non-Object value +info: | + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + b. ReturnIfAbrupt(lref). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). +features: [Symbol.iterator, generators] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var iterable = {}; +var iterator = { + return() { + return null; + } +}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; + + +//- elems +[...{}[yield]] +//- vals +iterable +//- teardown + + +iter.next().then(() => { + assert.throws(Test262Error, () => iter.return()); + assert.sameValue(returnCount, 1); + assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); +}).then($DONE, $DONE); + diff --git a/src/dstr-assignment-async-iteration/array-rest-iter-rtrn-close.case b/src/dstr-assignment-async-iteration/array-rest-iter-rtrn-close.case new file mode 100644 index 0000000000000000000000000000000000000000..ccb3e18914cd73386cb9881d0988ddcfa69f170b --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-iter-rtrn-close.case @@ -0,0 +1,83 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +desc: > + IteratorClose is called when reference evaluation produces a "return" + completion +info: | + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + b. ReturnIfAbrupt(lref). + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + 7. If completion.[[type]] is throw, return Completion(completion). + 8. If innerResult.[[type]] is throw, return Completion(innerResult). +features: [Symbol.iterator, generators] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var returnCount = 0; +var unreachable = 0; +var thisValue = null; +var args = null; +var iterator = { + return() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; + +//- elems +[...{}[yield]] +//- vals +iterable +//- body +unreachable += 1; +//- teardown + + +iter.next().then(() => { + iter.return(444).then(result => { + assert.sameValue(returnCount, 1); + assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); + assert.sameValue(result.value, 444); + assert(result.done, 'Iterator correctly closed'); + assert.sameValue(thisValue, iterator, 'correct `this` value'); + assert(!!args, 'arguments object provided'); + assert.sameValue(args.length, 0, 'zero arguments specified'); + }).then($DONE, $DONE); +}); + + + + diff --git a/src/dstr-assignment-async-iteration/array-rest-iteration.case b/src/dstr-assignment-async-iteration/array-rest-iteration.case new file mode 100644 index 0000000000000000000000000000000000000000..fbe10e8a7fad6c1b8bcc48b9d3a546c70030b009 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-iteration.case @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + In the presense of an AssignmentRestElement, value iteration exhausts the + iterable value; +template: default +es6id: 12.14.5.3 +features: [generators] +---*/ + +//- setup +var count = 0; +var g = function*() { + count += 1; + yield; + count += 1; + yield; + count += 1; +} +var x; +//- elems +[...x] +//- vals +g() +//- body +assert.sameValue(count, 3); + + diff --git a/src/dstr-assignment-async-iteration/array-rest-lref.case b/src/dstr-assignment-async-iteration/array-rest-lref.case new file mode 100644 index 0000000000000000000000000000000000000000..35d2f347ca558a79bc93b5139798728eb17b977e --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-lref.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. +/*--- +desc: Reference is evaluated during assignment +info: | + ArrayAssignmentPattern : [ Elisionopt AssignmentRestElement ] + + [...] + 5. Let result be the result of performing + IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with + iteratorRecord as the argument + 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + + AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget + + 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an + ArrayLiteral, then + a. Let lref be the result of evaluating DestructuringAssignmentTarget. + b. ReturnIfAbrupt(lref). + [...] +features: [Symbol.iterator] +template: async-generator +esid: sec-runtime-semantics-destructuringassignmentevaluation +---*/ + +//- setup +var nextCount = 0; +var returnCount = 0; +var iterator = { + next() { + nextCount += 1; + return { done: true }; + }, + return() { + returnCount += 1; + } +}; +var obj = {}; +var iterable = { + [Symbol.iterator]() { + return iterator; + } +}; +//- elems +[...obj['a' + 'b']] +//- vals +iterable +//- body +assert.sameValue(nextCount, 1); +assert.sameValue(returnCount, 0); +assert(!!obj.ab); +assert.sameValue(obj.ab.length, 0); + + diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-array-null.case b/src/dstr-assignment-async-iteration/array-rest-nested-array-null.case new file mode 100644 index 0000000000000000000000000000000000000000..e44b1506a45c414b472d2f676cdbd6caaccb1c4a --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-array-null.case @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an array literal and the iterable + emits `null` as the only value, an array with a single `null` element + should be used as the value of the nested DestructuringAssignment. +template: default +---*/ + +//- setup +var x, y; +//- elems +[...[x, y]] +//- vals +[null] +//- body +assert.sameValue(x, null); +assert.sameValue(y, undefined); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-array-undefined-hole.case b/src/dstr-assignment-async-iteration/array-rest-nested-array-undefined-hole.case new file mode 100644 index 0000000000000000000000000000000000000000..a9dd40ff74bc1fb14a8221b4004b36ec67eb997b --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-array-undefined-hole.case @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an array literal and the iterable is + an array with a "hole", an array with a single `undefined` element should + be used as the value of the nested DestructuringAssignment. +template: default +es6id: 12.14.5.3 +---*/ + +//- setup +var x = null; +//- elems +[...[x]] +//- vals +[ , ] +//- body +assert.sameValue(x, undefined); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-array-undefined-own.case b/src/dstr-assignment-async-iteration/array-rest-nested-array-undefined-own.case new file mode 100644 index 0000000000000000000000000000000000000000..b8a5c809ac1e850644d5f4ba563f33b6fb27a5a1 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-array-undefined-own.case @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an array literal and the iterable + emits `undefined` as the only value, an array with a single `undefined` + element should be used as the value of the nested DestructuringAssignment. +template: default +es6id: 12.14.5.3 +---*/ + +//- setup +var x = null; +//- elems +[...[x]] +//- vals +[undefined] +//- body +assert.sameValue(x, undefined); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-array-undefined.case b/src/dstr-assignment-async-iteration/array-rest-nested-array-undefined.case new file mode 100644 index 0000000000000000000000000000000000000000..0acebafcdb65b31bd2eb403fb664c8041de270d1 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-array-undefined.case @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an array literal and the iterable is + emits no values, an empty array should be used as the value of the nested + DestructuringAssignment. +template: default +es6id: 12.14.5.3 +---*/ + +//- setup +var x = null; +//- elems +[...[x]] +//- vals +[] +//- body +assert.sameValue(x, undefined); + + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-array-yield-expr.case b/src/dstr-assignment-async-iteration/array-rest-nested-array-yield-expr.case new file mode 100644 index 0000000000000000000000000000000000000000..384f1646f277b2811dc9ea87077ae96ec7690ceb --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-array-yield-expr.case @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When a `yield` token appears within the DestructuringAssignmentTarget of a + nested destructuring assignment and within a generator function body, it + should behave as a YieldExpression. +template: async-generator +features: [generators] +---*/ + +//- setup +var value = [86]; +var x = {}; + +//- elems +[...[x[yield]]] +//- vals +[86] +//- teardown +iter.next().then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, false); + assert.sameValue(x.prop, undefined); + + // TODO add iterCount + // + iter.next(86).then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, true); + assert.sameValue(x.prop, 86); + }).then($DONE, $DONE); +}); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-array-yield-ident-valid.case b/src/dstr-assignment-async-iteration/array-rest-nested-array-yield-ident-valid.case new file mode 100644 index 0000000000000000000000000000000000000000..486ca2a21322c4cbe7d1ea9c3103ca2fcb68fdb8 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-array-yield-ident-valid.case @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When a `yield` token appears within the DestructuringAssignmentTarget of a + nested destructuring assignment and outside of a generator function body, + it should behave as an IdentifierExpression. +template: default +flags: [noStrict] +---*/ + +//- setup +var yield = 'prop'; +var x = {}; +//- elems +[...[x[yield]]] +//- vals +[86] +//- body +assert.sameValue(x.prop, 86); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-array.case b/src/dstr-assignment-async-iteration/array-rest-nested-array.case new file mode 100644 index 0000000000000000000000000000000000000000..23286b13af16dad4514d0812fbc623bed72b08c1 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-array.case @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an array literal, it should be parsed + parsed as a DestructuringAssignmentPattern and evaluated as a destructuring + assignment. +template: default +es6id: 12.14.5.3 +---*/ + +//- setup +var x; +//- elems +[...[x]] +//- vals +[1, 2, 3] +//- body +assert.sameValue(x, 1); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-obj-null.case b/src/dstr-assignment-async-iteration/array-rest-nested-obj-null.case new file mode 100644 index 0000000000000000000000000000000000000000..505df0fd6a5d8a2daedf9149300a6e8c88adc5c0 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-obj-null.case @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an object literal and the iterable + emits `null` as the only value, an array with a single `null` element + should be used as the value of the nested DestructuringAssignment. +template: default +es6id: 12.14.5.3 +---*/ + +//- setup +var x, length; +//- elems +[...{ 0: x, length }] +//- vals +[null] +//- body +assert.sameValue(x, null); +assert.sameValue(length, 1); + +//- teardown +promise + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-obj-undefined-hole.case b/src/dstr-assignment-async-iteration/array-rest-nested-obj-undefined-hole.case new file mode 100644 index 0000000000000000000000000000000000000000..7b6f5c0c417032c717986388ada8da3547fd2e02 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-obj-undefined-hole.case @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an array literal and the iterable is + an array with a "hole", an array with a single `undefined` element should + be used as the value of the nested DestructuringAssignment. +template: default +es6id: 12.14.5.3 +---*/ + +//- setup +var x = null; +// Use the the top-level lexical scope for 'length' to provide compatibility with browsers +// where length and name are properties of WindowProxy +let length; +//- elems +[...{ 0: x, length }] +//- vals +[ , ] +//- body +assert.sameValue(x, undefined); +assert.sameValue(length, 1); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-obj-undefined-own.case b/src/dstr-assignment-async-iteration/array-rest-nested-obj-undefined-own.case new file mode 100644 index 0000000000000000000000000000000000000000..553a8e46bc024ee3b3c8230b0defc460e15f615b --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-obj-undefined-own.case @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an array literal and the iterable + emits `undefined` as the only value, an array with a single `undefined` + element should be used as the value of the nested DestructuringAssignment. +template: default +es6id: 12.14.5.3 +---*/ + +//- setup +var x = null; +// Use the the top-level lexical scope for 'length' to provide compatibility with browsers +// where length and name are properties of WindowProxy +let length; +//- elems +[...{ 0: x, length }] +//- vals +[undefined] +//- body +assert.sameValue(x, undefined); +assert.sameValue(length, 1); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-obj-undefined.case b/src/dstr-assignment-async-iteration/array-rest-nested-obj-undefined.case new file mode 100644 index 0000000000000000000000000000000000000000..305df52c622e2f4fc44b8af6087fc643f9cf46ea --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-obj-undefined.case @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an obect literal and the iterable is + emits no values, an empty array should be used as the value of the nested + DestructuringAssignment. +template: default +es6id: 12.14.5.3 +---*/ + +//- setup +var x = null; +// Use the the top-level lexical scope for 'length' to provide compatibility with browsers +// where length and name are properties of WindowProxy +let length; +//- elems +[...{ 0: x, length }] +//- vals +[] +//- body +assert.sameValue(x, undefined); +assert.sameValue(length, 0); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-obj-yield-expr.case b/src/dstr-assignment-async-iteration/array-rest-nested-obj-yield-expr.case new file mode 100644 index 0000000000000000000000000000000000000000..ed1afc7531aa8267c7c538b34adafc9c27abc03d --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-obj-yield-expr.case @@ -0,0 +1,34 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When a `yield` token appears within the Initializer of a nested + destructuring assignment and within a generator function body, it should + behave as a YieldExpression. +template: async-generator +features: [generators] +---*/ + +//- setup +var x; + +//- elems +[...{ x = yield }] +//- vals +[{}] +//- teardown +iter.next().then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, false); + assert.sameValue(x, undefined); + + // TODO add iterCount + // + iter.next(4).then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, true); + assert.sameValue(x, 4); + }).then($DONE, $DONE); +}); + diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-obj-yield-ident-valid.case b/src/dstr-assignment-async-iteration/array-rest-nested-obj-yield-ident-valid.case new file mode 100644 index 0000000000000000000000000000000000000000..ecd104a23601063b3f3e9917f05ebf7a9235d377 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-obj-yield-ident-valid.case @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When a `yield` token appears within the Initializer of a nested + destructuring assignment and outside of a generator function body, it + should behave as an IdentifierExpression. +template: default +flags: [noStrict] +---*/ + +//- setup +var yield = 2; +var x; +//- elems +[...{ x = yield }] +//- vals +[{}] +//- body +assert.sameValue(x, 2); diff --git a/src/dstr-assignment-async-iteration/array-rest-nested-obj.case b/src/dstr-assignment-async-iteration/array-rest-nested-obj.case new file mode 100644 index 0000000000000000000000000000000000000000..17ba9acedcf9d680319481aaca87d8a95b8d6267 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-nested-obj.case @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When DestructuringAssignmentTarget is an object literal, it should be + parsed as a DestructuringAssignmentPattern and evaluated as a destructuring + assignment. +template: default +---*/ + +//- setup +var x; +//- elems +[...{ 1: x }] +//- vals +[1, 2, 3] +//- body +assert.sameValue(x, 2); diff --git a/src/dstr-assignment-async-iteration/array-rest-put-prop-ref-no-get.case b/src/dstr-assignment-async-iteration/array-rest-put-prop-ref-no-get.case new file mode 100644 index 0000000000000000000000000000000000000000..1adb2c2e07d0f7fb7435ed9de27050395588a38b --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-put-prop-ref-no-get.case @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + If the DestructuringAssignmentTarget of an AssignmentElement is a + PropertyReference, it should not be evaluated. +template: default +es6id: 12.14.5.3 +---*/ + +//- setup +var setValue; +var x = { + get y() { + $ERROR('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}; +//- elems +[...x.y] +//- vals +[23, 45, 99] +//- body +assert.sameValue(setValue.length, 3); +assert.sameValue(setValue[0], 23); +assert.sameValue(setValue[1], 45); +assert.sameValue(setValue[2], 99); diff --git a/src/dstr-assignment-async-iteration/array-rest-put-prop-ref.case b/src/dstr-assignment-async-iteration/array-rest-put-prop-ref.case new file mode 100644 index 0000000000000000000000000000000000000000..fda1af6dc0065c6333a52af541f082e861e2ffe3 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-put-prop-ref.case @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + The DestructuringAssignmentTarget of an AssignmentElement may be a + PropertyReference. +template: default +es6id: 12.14.5.3 +---*/ + +//- setup +var x = {}; +//- elems +[...x.y] +//- vals +[4, 3, 2] +//- body +assert.sameValue(x.y.length, 3); +assert.sameValue(x.y[0], 4); +assert.sameValue(x.y[1], 3); +assert.sameValue(x.y[2], 2); diff --git a/src/dstr-assignment-async-iteration/array-rest-put-unresolvable-no-strict.case b/src/dstr-assignment-async-iteration/array-rest-put-unresolvable-no-strict.case new file mode 100644 index 0000000000000000000000000000000000000000..7f3ac5769bfdb03abdbf0489abbcc5718c7027a7 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-put-unresolvable-no-strict.case @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Outside of strict mode, if the the assignment target is an unresolvable + reference, a new `var` binding should be created in the environment record. +template: default +flags: [noStrict] +---*/ + +//- elems +[ ...unresolvable ] +//- vals +[] +//- body + +assert.sameValue(unresolvable.length, 0); diff --git a/src/dstr-assignment-async-iteration/array-rest-yield-expr.case b/src/dstr-assignment-async-iteration/array-rest-yield-expr.case new file mode 100644 index 0000000000000000000000000000000000000000..1953e20e3691fdab7bef0bbf83ed6557c09bdff2 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-yield-expr.case @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When a `yield` token appears within the DestructuringAssignmentTarget of + an AssignmentRestElement and within the body of a generator function, it + should behave as a YieldExpression. +template: async-generator +features: [generators] +---*/ + +//- setup +var x = {}; + +//- elems +[...x[yield]] +//- vals +[33, 44, 55] + +//- teardown +iter.next().then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, false); + assert.sameValue(x.prop, undefined); + + // TODO add iterCount + // + iter.next('prop').then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, true); + assert.sameValue(x.prop.length, 3); + assert.sameValue(x.prop[0], 33); + assert.sameValue(x.prop[1], 44); + assert.sameValue(x.prop[2], 55); + }).then($DONE, $DONE); +}); diff --git a/src/dstr-assignment-async-iteration/array-rest-yield-ident-valid.case b/src/dstr-assignment-async-iteration/array-rest-yield-ident-valid.case new file mode 100644 index 0000000000000000000000000000000000000000..44727057c9d3df38e47207ceb8550a39dcb02aa4 --- /dev/null +++ b/src/dstr-assignment-async-iteration/array-rest-yield-ident-valid.case @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + When a `yield` token appears within the DestructuringAssignmentTarget of an + AssignmentRestElement and outside of a generator function body, it should + behave as an IdentifierReference. +template: async-function +flags: [noStrict] +---*/ + +//- setup +var yield = 'prop'; +var x = {}; +//- elems +[...x[yield]] +//- vals +[33, 44, 55] +//- body +assert.sameValue(x.prop.length, 3); +assert.sameValue(x.prop[0], 33); +assert.sameValue(x.prop[1], 44); +assert.sameValue(x.prop[2], 55); diff --git a/src/dstr-assignment-async-iteration/async-function/async-func-decl.template b/src/dstr-assignment-async-iteration/async-function/async-func-decl.template new file mode 100644 index 0000000000000000000000000000000000000000..31f598a0600ebae2852b763839db760830db1d64 --- /dev/null +++ b/src/dstr-assignment-async-iteration/async-function/async-func-decl.template @@ -0,0 +1,36 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for-await-of/async-func-decl-dstr- +name: for-await-of statement in an async function declaration +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +let iterCount = 0; +async function fn() { + for await (/*{ elems }*/ of [/*{ vals }*/]) { + /*{ body }*/ + iterCount += 1; + } +} + +let promise = fn(); diff --git a/src/dstr-assignment-async-iteration/async-generator/async-gen-decl.template b/src/dstr-assignment-async-iteration/async-generator/async-gen-decl.template new file mode 100644 index 0000000000000000000000000000000000000000..1fc6dbcd62b073d35cea6028ee764223867190ed --- /dev/null +++ b/src/dstr-assignment-async-iteration/async-generator/async-gen-decl.template @@ -0,0 +1,36 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for-await-of/async-gen-decl-dstr- +name: for-await-of statement in an async generator declaration +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +let iterCount = 0; +async function * fn() { + for await (/*{ elems }*/ of [/*{ vals }*/]) { + /*{ body }*/ + iterCount += 1; + } +} + +let iter = fn(); diff --git a/src/dstr-assignment-async-iteration/default/async-func-decl.template b/src/dstr-assignment-async-iteration/default/async-func-decl.template new file mode 100644 index 0000000000000000000000000000000000000000..31f598a0600ebae2852b763839db760830db1d64 --- /dev/null +++ b/src/dstr-assignment-async-iteration/default/async-func-decl.template @@ -0,0 +1,36 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for-await-of/async-func-decl-dstr- +name: for-await-of statement in an async function declaration +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +let iterCount = 0; +async function fn() { + for await (/*{ elems }*/ of [/*{ vals }*/]) { + /*{ body }*/ + iterCount += 1; + } +} + +let promise = fn(); diff --git a/src/dstr-assignment-async-iteration/default/async-gen-decl.template b/src/dstr-assignment-async-iteration/default/async-gen-decl.template new file mode 100644 index 0000000000000000000000000000000000000000..70c488d468778741dc7fe4e6ddeaa7f6b167a4b0 --- /dev/null +++ b/src/dstr-assignment-async-iteration/default/async-gen-decl.template @@ -0,0 +1,36 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for-await-of/async-gen-decl-dstr- +name: for-await-of statement in an async generator declaration +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +let iterCount = 0; +async function * fn() { + for await (/*{ elems }*/ of [/*{ vals }*/]) { + /*{ body }*/ + iterCount += 1; + } +} + +let promise = fn().next(); diff --git a/src/dstr-assignment/default/for-await-of.template b/src/dstr-assignment/default/for-await-of.template new file mode 100644 index 0000000000000000000000000000000000000000..541520c4a158d5d92ec714e6ad8335b29285e6a4 --- /dev/null +++ b/src/dstr-assignment/default/for-await-of.template @@ -0,0 +1,39 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/statements/for-await-of/dstr- +name: for-await-of statement +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var counter = 0; + +async function fn() { + for await (/*{ elems }*/ of [/*{ vals }*/]) { + /*{ body }*/ + counter += 1; + } +} + +fn() + .then(() => assert.sameValue(counter, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-init-assignment-fn.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-assignment-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..b293809c0dbca9b697da6429af3b4b8a886a48bb --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-assignment-fn.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-assignment-fn.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: If the Initializer is present and v is undefined, the Initializer should be evaluated and the result assigned to the target reference. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var v2, vNull, vHole, vUndefined, vOob; + +var iterCount = 0; +async function fn() { + for await ([v2 = 10, vNull = 11, vHole = 12, vUndefined = 13, vOob = 14] of [[2, null, , undefined]]) { + assert.sameValue(v2, 2); + assert.sameValue(vNull, null); + assert.sameValue(vHole, 12); + assert.sameValue(vUndefined, 13); + assert.sameValue(vOob, 14); + + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-init-evaluation-fn.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-evaluation-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..d3f1e2c31548cfbc4445e8a2b99e7558d2e9caee --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-evaluation-fn.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-evaluation-fn.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: The Initializer should only be evaluated if v is undefined. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var flag1 = false, flag2 = false; +var _; + +var iterCount = 0; +async function fn() { + for await ([ _ = flag1 = true, _ = flag2 = true ] of [[14]]) { + assert.sameValue(flag1, false); + assert.sameValue(flag2, true); + + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); + diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-arrow-fn.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-arrow-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..7428724d0f0e560bb2fb4a8f08ac094514f7aab8 --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-arrow-fn.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-fn-name-arrow-fn.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: Assignment of function `name` attribute (ArrowFunction) (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var arrow; + +var iterCount = 0; +async function fn() { + for await ([ arrow = () => {} ] of [[]]) { + assert.sameValue(arrow.name, 'arrow'); + verifyNotEnumerable(arrow, 'name'); + verifyNotWritable(arrow, 'name'); + verifyConfigurable(arrow, 'name'); + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-class-fn.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-class-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..88fb18c4855897c77bf1083b5afec2dc33457585 --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-class-fn.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-fn-name-class-fn.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: Assignment of function `name` attribute (ClassExpression) (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [class, destructuring-binding, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var xCls, cls, xCls2; + +var iterCount = 0; +async function fn() { + for await ([ xCls = class x {}, cls = class {}, xCls2 = class { static name() {} } ] of [[]]) { + assert(xCls.name !== 'xCls'); + assert(xCls2.name !== 'xCls2'); + + assert.sameValue(cls.name, 'cls'); + verifyNotEnumerable(cls, 'name'); + verifyNotWritable(cls, 'name'); + verifyConfigurable(cls, 'name'); + + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); + diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-cover-fn.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-cover-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..f555a07115f19940c4ac02895faa9ec30c4b5532 --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-cover-fn.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-fn-name-cover-fn.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: Assignment of function `name` attribute (CoverParenthesizedExpression) (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var xCover, cover; + +var iterCount = 0; +async function fn() { + for await ([ xCover = (0, function() {}), cover = (function() {}) ] of [[]]) { + assert(xCover.name !== 'xCover'); + + assert.sameValue(cover.name, 'cover'); + verifyNotEnumerable(cover, 'name'); + verifyNotWritable(cover, 'name'); + verifyConfigurable(cover, 'name'); + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-cover-gen.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-cover-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..3c9111e4a41f3f1470607d4cf2ee44c715047d56 --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-cover-gen.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-fn-name-cover-gen.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: Assignment of function `name` attribute (CoverParenthesizedExpression) (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var xCover, cover; + +var iterCount = 0; +async function fn() { + for await ([ xCover = (0, function() {}), cover = (function() {}) ] of [[]]) { + assert(xCover.name !== 'xCover'); + + assert.sameValue(cover.name, 'cover'); + verifyNotEnumerable(cover, 'name'); + verifyNotWritable(cover, 'name'); + verifyConfigurable(cover, 'name'); + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-fn.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..e8a71bb44bc2c5dd13290b9be819d60a80cbaa72 --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-fn-name-fn.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-fn-name-fn.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: Assignment of function `name` attribute (FunctionExpression) (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [class, destructuring-binding, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var xFn, fn; + +var iterCount = 0; +async function fn() { + for await ([ xFn = function x() {}, fn = function() {} ] of [[]]) { + assert(xFn.name !== 'xFn'); + + assert.sameValue(fn.name, 'fn'); + verifyNotEnumerable(fn, 'name'); + verifyNotWritable(fn, 'name'); + verifyConfigurable(fn, 'name'); + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-init-in.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-in.js new file mode 100644 index 0000000000000000000000000000000000000000..7067339fccd52a9d86f014981f5bd6518dbadd15 --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-in.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-in.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: The Initializer in an AssignmentElement may be an `in` expression. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var iterCount = 0; +async function fn() { + for await ([ x = 'x' in {} ] of [[]]) { + assert.sameValue(x, false); + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-init-order.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-order.js new file mode 100644 index 0000000000000000000000000000000000000000..01cbd0f9d70cc6d7992e1142bf45b434ba0d240b --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-order.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-order.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: Initializer values should be assigned in left-to-right order. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = 0; +var a, b; + +var iterCount = 0; +async function fn() { + for await ([ a = x += 1, b = x *= 2 ] of [[]]) { + assert.sameValue(a, 1); + assert.sameValue(b, 2); + assert.sameValue(x, 2); + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-init-simple-no-strict.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-simple-no-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..80488ea30c14ecff60f32d19e0c6f83a8d86ddfd --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-init-simple-no-strict.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-simple-no-strict.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: Identifiers that appear as the DestructuringAssignmentTarget in an AssignmentElement should take on the iterated value corresponding to their position in the ArrayAssignmentPattern. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, noStrict, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var argument, eval; + +var iterCount = 0; +async function fn() { + for await ([arguments = 4, eval = 5] of [[]]) { + assert.sameValue(arguments, 4); + assert.sameValue(eval, 5); + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-array-yield-ident-valid.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-array-yield-ident-valid.js new file mode 100644 index 0000000000000000000000000000000000000000..129ee714bc56432ff2934af8e4226a9f19ea1d28 --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-array-yield-ident-valid.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-nested-array-yield-ident-valid.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of a nested destructuring assignment outside of strict mode, it behaves as an IdentifierReference. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, noStrict, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 'prop'; +var x = {}; + +var iterCount = 0; +async function fn() { + for await ([[x[yield]]] of [[[22]]]) { + assert.sameValue(x.prop, 22); + iterCount += 1; + } +} diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-array.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-array.js new file mode 100644 index 0000000000000000000000000000000000000000..593906b97f4e0d1d598fb4de5605841e9524a2ee --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-array.js @@ -0,0 +1,35 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-nested-array.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: When DestructuringAssignmentTarget is an array literal, it should be parsed parsed as a DestructuringAssignmentPattern and evaluated as a destructuring assignment. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var iterCount = 0; +async function fn() { + for await ([[x]] of [[[1]]]) { + assert.sameValue(x, 1); + iterCount += 1; + } +} diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-obj-fn.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-obj-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..35726a5819ffdce6ff74cea9099ecdf76cd8ab0b --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-obj-fn.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-nested-obj-fn.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: When DestructuringAssignmentTarget is an object literal, it should be parsed as a DestructuringAssignmentPattern and evaluated as a destructuring assignment. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var iterCount = 0; +async function fn() { + for await ([{ x }] of [[{ x: 2 }]]) { + assert.sameValue(x, 2); + + + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-obj-yield-ident-valid-fn.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-obj-yield-ident-valid-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..8d48973842019e61fd34c5b8e1728b8cd6222152 --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-nested-obj-yield-ident-valid-fn.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-nested-obj-yield-ident-valid-fn.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment outside of a generator function body, it behaves as an IdentifierReference. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, noStrict, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var yield = 2; +var x; + +var iterCount = 0; +async function fn() { + for await ([{ x = yield }] of [[{}]]) { + assert.sameValue(x, 2); + + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); + diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-put-prop-ref-fn.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-put-prop-ref-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..52e30d420957b909af69dea12497077f21928f40 --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-put-prop-ref-fn.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-put-prop-ref-fn.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: The DestructuringAssignmentTarget of an AssignmentElement may be a PropertyReference. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x = {}; + +var iterCount = 0; +async function fn() { + for await ([x.y] of [[4]]) { + assert.sameValue(x.y, 4); + + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-put-prop-ref-no-get-fn.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-put-prop-ref-no-get-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..bf751d8fb9645e2b14a8885635446bf4ee885c51 --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-put-prop-ref-no-get-fn.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-put-prop-ref-no-get-fn.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: If the DestructuringAssignmentTarget of an AssignmentElement is a PropertyReference, it should not be evaluated. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x, setValue; +x = { + get y() { + $ERROR('The property should not be accessed.'); + }, + set y(val) { + setValue = val; + } +}; + +var iterCount = 0; +async function fn() { + for await ([x.y] of [[23]]) { + assert.sameValue(setValue, 23); + + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-func-dstr-array-elem-put-unresolvable-no-strict-fn.js b/test/language/statements/for-await-of/async-func-dstr-array-elem-put-unresolvable-no-strict-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..68f8f991698755cd5af0dd38360c2c61d528c796 --- /dev/null +++ b/test/language/statements/for-await-of/async-func-dstr-array-elem-put-unresolvable-no-strict-fn.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-put-unresolvable-no-strict-fn.case +// - src/dstr-assignment-async-iteration/async-function/for-await-of-async-func.template +/*--- +description: Outside of strict mode, if the the assignment target is an unresolvable reference, a new `var` binding should be created in the environment record. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, noStrict, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var iterCount = 0; +async function fn() { + for await ([ unresolvable ] of [[]]) { + + iterCount += 1; + } +} + +fn() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-gen-decl-dstr-array-elem-target-simple-no-strict.js b/test/language/statements/for-await-of/async-gen-decl-dstr-array-elem-target-simple-no-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..3d8861b8a1d8ec526c68a7d6d0daf39b2d110df9 --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-decl-dstr-array-elem-target-simple-no-strict.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-target-simple-no-strict.case +// - src/dstr-assignment-async-iteration/async-generator/async-gen-decl.template +/*--- +description: Identifiers that appear as the DestructuringAssignmentTarget in an AssignmentElement should take on the iterated value corresponding to their position in the ArrayAssignmentPattern. (for-await-of statement in an async generator declaration) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, noStrict, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var argument, eval; + +let iterCount = 0; +async function * fn() { + for await ([arguments, eval] of [[2, 3]]) { + assert.sameValue(arguments, 2); + assert.sameValue(eval, 3); + + + iterCount += 1; + } +} + +let iter = fn(); + +iter.next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-gen-decl-dstr-array-elem-target-yield-expr.js b/test/language/statements/for-await-of/async-gen-decl-dstr-array-elem-target-yield-expr.js new file mode 100644 index 0000000000000000000000000000000000000000..19c4eb80033d40c9b47719004db20214de6b4429 --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-decl-dstr-array-elem-target-yield-expr.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-target-yield-expr.case +// - src/dstr-assignment-async-iteration/async-generator/async-gen-decl.template +/*--- +description: When a `yield` token appears within the DestructuringAssignmentTarget of an AssignmentElement within a generator function body, it behaves as a YieldExpression. (for-await-of statement in an async generator declaration) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var value = [33]; +var x = {}; +var iterationResult; + + +let iterCount = 0; +async function * fn() { + for await ([ x[yield] ] of [[33] + +]) { + + iterCount += 1; + } +} + +let iter = fn(); + +iter.next().then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, false); + assert.sameValue(x.prop, undefined); + + // TODO add iterCount + // + iter.next('prop').then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, true); + assert.sameValue(x.prop, 33); + }).then($DONE, $DONE); +}); diff --git a/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-assignment-gen.js b/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-assignment-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..0436b47c41726c553957eb0df87cad288924c909 --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-assignment-gen.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-assignment-gen.case +// - src/dstr-assignment-async-iteration/async-generator/for-await-of-async-gen.template +/*--- +description: If the Initializer is present and v is undefined, the Initializer should be evaluated and the result assigned to the target reference. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var v2, vNull, vHole, vUndefined, vOob; + +var iterCount = 0; +async function * fn() { + for await ([v2 = 10, vNull = 11, vHole = 12, vUndefined = 13, vOob = 14] of [[2, null, , undefined]]) { + assert.sameValue(v2, 2); + assert.sameValue(vNull, null); + assert.sameValue(vHole, 12); + assert.sameValue(vUndefined, 13); + assert.sameValue(vOob, 14); + + + iterCount += 1; + } +} + +fn().next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-evaluation-gen.js b/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-evaluation-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..940dbecd196fdc9b62ea3fb138e716f11e2b204f --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-evaluation-gen.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-evaluation-gen.case +// - src/dstr-assignment-async-iteration/async-generator/for-await-of-async-gen.template +/*--- +description: The Initializer should only be evaluated if v is undefined. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var flag1 = false, flag2 = false; +var _; + +var iterCount = 0; +async function * fn() { + for await ([ _ = flag1 = true, _ = flag2 = true ] of [[14]]) { + assert.sameValue(flag1, false); + assert.sameValue(flag2, true); + + + iterCount += 1; + } +} + +fn().next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); + diff --git a/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-fn-name-arrow-gen.js b/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-fn-name-arrow-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..7418316daaa0353c4ab40211ad5cc7243256292b --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-fn-name-arrow-gen.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-fn-name-arrow-gen.case +// - src/dstr-assignment-async-iteration/async-generator/for-await-of-async-gen.template +/*--- +description: Assignment of function `name` attribute (ArrowFunction) (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var arrow; + +var iterCount = 0; +async function * fn() { + for await ([ arrow = () => {} ] of [[]]) { + assert.sameValue(arrow.name, 'arrow'); + verifyNotEnumerable(arrow, 'name'); + verifyNotWritable(arrow, 'name'); + verifyConfigurable(arrow, 'name'); + + iterCount += 1; + } +} + +fn().next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-fn-name-class-gen.js b/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-fn-name-class-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..bfa07d1986edf3ce552010c9c7837b141b41b047 --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-fn-name-class-gen.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-fn-name-class-gen.case +// - src/dstr-assignment-async-iteration/async-generator/for-await-of-async-gen.template +/*--- +description: Assignment of function `name` attribute (ClassExpression) (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [class, destructuring-binding, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var xCls, cls, xCls2; + +var iterCount = 0; +async function * fn() { + for await ([ xCls = class x {}, cls = class {}, xCls2 = class { static name() {} } ] of [[]]) { + assert(xCls.name !== 'xCls'); + assert(xCls2.name !== 'xCls2'); + + assert.sameValue(cls.name, 'cls'); + verifyNotEnumerable(cls, 'name'); + verifyNotWritable(cls, 'name'); + verifyConfigurable(cls, 'name'); + + + iterCount += 1; + } +} + +fn().next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); + diff --git a/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-fn-name-gen.js b/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-fn-name-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..6d3002df707d302798f8249ccf75d216ef922f67 --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-dstr-array-elem-init-fn-name-gen.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-init-fn-name-gen.case +// - src/dstr-assignment-async-iteration/async-generator/for-await-of-async-gen.template +/*--- +description: Assignment of function `name` attribute (GeneratorExpression) (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + [...] 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). + +---*/ +var xGen, gen; + +var iterCount = 0; +async function * fn() { + for await ([ xGen = function* x() {}, gen = function*() {} ] of [[]]) { + assert.notSameValue(xGen.name, 'xGen'); + + assert.sameValue(gen.name, 'gen'); + verifyNotEnumerable(gen, 'name'); + verifyNotWritable(gen, 'name'); + verifyConfigurable(gen, 'name'); + + iterCount += 1; + } +} + +fn().next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-gen-dstr-array-elem-iter-nrml-close-skip.js b/test/language/statements/for-await-of/async-gen-dstr-array-elem-iter-nrml-close-skip.js new file mode 100644 index 0000000000000000000000000000000000000000..8a4a11adf82c5146ec96aa67ad30dba6ef4ee5c8 --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-dstr-array-elem-iter-nrml-close-skip.js @@ -0,0 +1,64 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-iter-nrml-close-skip.case +// - src/dstr-assignment-async-iteration/async-generator/for-await-of-async-gen.template +/*--- +description: IteratorClose is not called when assignment evaluation has exhausted the iterator (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, result). + 6. Return result. + +---*/ +var nextCount = 0; +var returnCount = 0; +var _; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + return { done: true }; + }, + return: function() { + returnCount += 1; + return {}; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var iterCount = 0; +async function * fn() { + for await ([ _ ] of [iterable]) { + assert.sameValue(nextCount, 1); + assert.sameValue(returnCount, 0); + + iterCount += 1; + } +} + +fn().next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-gen-dstr-array-elem-iter-nrml-close.js b/test/language/statements/for-await-of/async-gen-dstr-array-elem-iter-nrml-close.js new file mode 100644 index 0000000000000000000000000000000000000000..767e1b4c0ee03481223f39b82cf586809222892f --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-dstr-array-elem-iter-nrml-close.js @@ -0,0 +1,80 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-iter-nrml-close.case +// - src/dstr-assignment-async-iteration/async-generator/for-await-of-async-gen.template +/*--- +description: IteratorClose is called when assignment evaluation has not exhausted the iterator (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [Symbol.iterator, destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] + + ArrayAssignmentPattern : [ AssignmentElementList ] + + [...] + 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, + result). + 6. Return result. + + 7.4.6 IteratorClose( iterator, completion ) + + [...] + 6. Let innerResult be Call(return, iterator, « »). + [...] + +---*/ +var nextCount = 0; +var returnCount = 0; +var thisValue = null; +var args = null; +var _; +var iterable = {}; +var iterator = { + next: function() { + nextCount += 1; + // Set an upper-bound to limit unnecessary iteration in non-conformant + // implementations + return { done: nextCount > 10 }; + }, + return: function() { + returnCount += 1; + thisValue = this; + args = arguments; + return {}; + } +}; +iterable[Symbol.iterator] = function() { + return iterator; +}; + +var iterCount = 0; +async function * fn() { + for await ([ _ ] of [iterable]) { + assert.sameValue(nextCount, 1); + assert.sameValue(returnCount, 1); + assert.sameValue(thisValue, iterator, 'correct `this` value'); + assert(!!args, 'arguments object provided'); + assert.sameValue(args.length, 0, 'zero arguments specified'); + + iterCount += 1; + } +} + +fn().next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-gen-dstr-array-elem-nested-obj-gen.js b/test/language/statements/for-await-of/async-gen-dstr-array-elem-nested-obj-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..3f164e74f6a4574b4ac9b665e0cb0266a79572ec --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-dstr-array-elem-nested-obj-gen.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-nested-obj-gen.case +// - src/dstr-assignment-async-iteration/async-generator/for-await-of-async-gen.template +/*--- +description: When DestructuringAssignmentTarget is an object literal, it should be parsed as a DestructuringAssignmentPattern and evaluated as a destructuring assignment. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var x; + +var iterCount = 0; +async function * fn() { + for await ([{ x }] of [[{ x: 2 }]]) { + assert.sameValue(x, 2); + + + + iterCount += 1; + } +} + +fn().next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE); diff --git a/test/language/statements/for-await-of/async-gen-dstr-array-elem-nested-obj-yield-expr.js b/test/language/statements/for-await-of/async-gen-dstr-array-elem-nested-obj-yield-expr.js new file mode 100644 index 0000000000000000000000000000000000000000..b23b78e865d795af24948b7e93a37fc47ef418b1 --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-dstr-array-elem-nested-obj-yield-expr.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-nested-obj-yield-expr.case +// - src/dstr-assignment-async-iteration/async-generator/for-await-of-async-gen.template +/*--- +description: When a `yield` token appears within the Initializer of a nested destructuring assignment and within a generator function body, it behaves as a YieldExpression. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [generators, destructuring-binding, async-iteration] +flags: [generated, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ +var iter, x; + + + +var iterCount = 0; +async function * fn() { + for await ([{ x = yield }] of [[{}]]) { + + iterCount += 1; + } +} + + + +iter = fn(); + +iter.next().then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, false); + assert.sameValue(x, undefined); + + iter.next(4).then(iterationResult => { + assert.sameValue(iterationResult.value, undefined); + assert.sameValue(iterationResult.done, true); + assert.sameValue(x, 4); + }).then($DONE, $DONE); +}); diff --git a/test/language/statements/for-await-of/async-gen-dstr-array-elem-put-unresolvable-no-strict-gen.js b/test/language/statements/for-await-of/async-gen-dstr-array-elem-put-unresolvable-no-strict-gen.js new file mode 100644 index 0000000000000000000000000000000000000000..86647fda79ce60605d036211c939d39de2202bbd --- /dev/null +++ b/test/language/statements/for-await-of/async-gen-dstr-array-elem-put-unresolvable-no-strict-gen.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-assignment-async-iteration/array-elem-put-unresolvable-no-strict-gen.case +// - src/dstr-assignment-async-iteration/async-generator/for-await-of-async-gen.template +/*--- +description: Outside of strict mode, if the the assignment target is an unresolvable reference, a new `var` binding should be created in the environment record. (for-await-of statement) +esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation +features: [destructuring-binding, async-iteration] +flags: [generated, noStrict, async] +info: | + IterationStatement : + for await ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », + AssignmentExpression, iterate). + 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 5. If destructuring is true and if lhsKind is assignment, then + a. Assert: lhs is a LeftHandSideExpression. + b. Let assignmentPattern be the parse of the source text corresponding to + lhs using AssignmentPattern as the goal symbol. + [...] +---*/ + +var iterCount = 0; +async function * fn() { + for await ([ unresolvable ] of [[]]) { + assert.sameValue(unresolvable, undefined); + + + iterCount += 1; + } +} + +fn().next() + .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) + .then($DONE, $DONE);