diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/language/statements/async-generator | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
311 files changed, 16337 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/async-generator/array-destructuring-param-strict-body.js b/js/src/tests/test262/language/statements/async-generator/array-destructuring-param-strict-body.js new file mode 100644 index 0000000000..4660b77b66 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/array-destructuring-param-strict-body.js @@ -0,0 +1,113 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/array-destructuring-param-strict-body.case +// - src/function-forms/syntax/async-gen-func-decl.template +/*--- +description: ArrayBindingPattern and Use Strict Directive are not allowed to coexist for the same function. (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [rest-parameters, async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.4 Static Semantics: IsSimpleParameterList + + BindingElement : BindingPattern + + 1. Return false. + + 14.1.2 Static Semantics: Early Errors + + FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } + FunctionDeclaration : function ( FormalParameters ) { FunctionBody } + FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.2.1 Static Semantics: Early Errors + + ArrowFunction : ArrowParameters => ConciseBody + + - It is a Syntax Error if ContainsUseStrict of ConciseBody is true and + IsSimpleParameterList of ArrowParameters is false. + + 14.3.1 Static Semantics: Early Errors + + MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of PropertySetParameterList is false. + + 14.4.1 Static Semantics: Early Errors + + GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody } + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + 14.5.1 Static Semantics: Early Errors + + AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.7.1 Static Semantics: Early Errors + + AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.8.1 Static Semantics: Early Errors + + AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody + + - It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is true and + IsSimpleParameterList of CoverCallExpressionAndAsyncArrowHead is false. + +---*/ +$DONOTEVALUATE(); + + +async function* f([element]) { + "use strict"; +} diff --git a/js/src/tests/test262/language/statements/async-generator/await-as-binding-identifier-escaped.js b/js/src/tests/test262/language/statements/async-generator/await-as-binding-identifier-escaped.js new file mode 100644 index 0000000000..a16ff93677 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/await-as-binding-identifier-escaped.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/await-as-binding-identifier-escaped.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: await is a reserved keyword within generator function bodies and may not be used as a binding identifier. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + BindingIdentifier : Identifier + + It is a Syntax Error if this production has a [Await] parameter and + StringValue of Identifier is "await". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + var \u0061wait; +} diff --git a/js/src/tests/test262/language/statements/async-generator/await-as-binding-identifier.js b/js/src/tests/test262/language/statements/async-generator/await-as-binding-identifier.js new file mode 100644 index 0000000000..7542c47b57 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/await-as-binding-identifier.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/await-as-binding-identifier.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: await is a reserved keyword within generator function bodies and may not be used as a binding identifier. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + BindingIdentifier : Identifier + + It is a Syntax Error if this production has a [Await] parameter and + StringValue of Identifier is "await". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + var await; +} diff --git a/js/src/tests/test262/language/statements/async-generator/await-as-identifier-reference-escaped.js b/js/src/tests/test262/language/statements/async-generator/await-as-identifier-reference-escaped.js new file mode 100644 index 0000000000..51e5721c93 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/await-as-identifier-reference-escaped.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/await-as-identifier-reference-escaped.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: await is a reserved keyword within generator function bodies and may not be used as an identifier reference. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + IdentifierReference : Identifier + + It is a Syntax Error if this production has a [Await] parameter and + StringValue of Identifier is "await". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + void \u0061wait; +} diff --git a/js/src/tests/test262/language/statements/async-generator/await-as-identifier-reference.js b/js/src/tests/test262/language/statements/async-generator/await-as-identifier-reference.js new file mode 100644 index 0000000000..8a6a5d34df --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/await-as-identifier-reference.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/await-as-identifier-reference.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: await is a reserved keyword within generator function bodies and may not be used as an identifier reference. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + IdentifierReference : Identifier + + It is a Syntax Error if this production has a [Await] parameter and + StringValue of Identifier is "await". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + void await; +} diff --git a/js/src/tests/test262/language/statements/async-generator/await-as-label-identifier-escaped.js b/js/src/tests/test262/language/statements/async-generator/await-as-label-identifier-escaped.js new file mode 100644 index 0000000000..b84fe46ab9 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/await-as-label-identifier-escaped.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/await-as-label-identifier-escaped.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: await is a reserved keyword within generator function bodies and may not be used as a label identifier. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + LabelIdentifier : Identifier + + It is a Syntax Error if this production has a [Await] parameter and + StringValue of Identifier is "await". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + \u0061wait: ; +} diff --git a/js/src/tests/test262/language/statements/async-generator/await-as-label-identifier.js b/js/src/tests/test262/language/statements/async-generator/await-as-label-identifier.js new file mode 100644 index 0000000000..bf5216ae72 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/await-as-label-identifier.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/await-as-label-identifier.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: await is a reserved keyword within generator function bodies and may not be used as a label identifier. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + LabelIdentifier : Identifier + + It is a Syntax Error if this production has a [Await] parameter and + StringValue of Identifier is "await". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + await: ; +} diff --git a/js/src/tests/test262/language/statements/async-generator/browser.js b/js/src/tests/test262/language/statements/async-generator/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/browser.js diff --git a/js/src/tests/test262/language/statements/async-generator/dflt-params-abrupt.js b/js/src/tests/test262/language/statements/async-generator/dflt-params-abrupt.js new file mode 100644 index 0000000000..e22664b6d2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dflt-params-abrupt.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-abrupt.case +// - src/function-forms/error/async-gen-func-decl.template +/*--- +description: Abrupt completion returned by evaluation of initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [default-parameters, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + 1. Let status be the result of performing IteratorBindingInitialization for + FormalsList using iteratorRecord and environment as the arguments. + 2. ReturnIfAbrupt(status). + 3. Return the result of performing IteratorBindingInitialization for + FormalParameter using iteratorRecord and environment as the arguments. + +---*/ + + +var callCount = 0; +async function* f(_ = (function() { throw new Test262Error(); }())) { + + callCount = callCount + 1; +} + +assert.throws(Test262Error, function() { + f(); +}); + +assert.sameValue(callCount, 0, 'generator function body not evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dflt-params-arg-val-not-undefined.js b/js/src/tests/test262/language/statements/async-generator/dflt-params-arg-val-not-undefined.js new file mode 100644 index 0000000000..dee107ae7e --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dflt-params-arg-val-not-undefined.js @@ -0,0 +1,65 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-arg-val-not-undefined.case +// - src/function-forms/default/async-gen-func-decl.template +/*--- +description: Use of initializer when argument value is not `undefined` (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [default-parameters, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + [...] + 23. Let iteratorRecord be Record {[[Iterator]]: + CreateListIterator(argumentsList), [[Done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + a. Perform ? IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + +---*/ +var obj = {}; +var falseCount = 0; +var stringCount = 0; +var nanCount = 0; +var zeroCount = 0; +var nullCount = 0; +var objCount = 0; + + +var callCount = 0; +// Stores a reference `ref` for case evaluation +async function* ref(aFalse = falseCount +=1, aString = stringCount += 1, aNaN = nanCount += 1, a0 = zeroCount += 1, aNull = nullCount += 1, aObj = objCount +=1) { + assert.sameValue(aFalse, false); + assert.sameValue(aString, ''); + assert.sameValue(aNaN, NaN); + assert.sameValue(a0, 0); + assert.sameValue(aNull, null); + assert.sameValue(aObj, obj); + callCount = callCount + 1; +} + +ref(false, '', NaN, 0, null, obj).next().then(() => { + assert.sameValue(callCount, 1, 'generator function invoked exactly once'); +}).then($DONE, $DONE); + +assert.sameValue(falseCount, 0, 'initializer not evaluated: false'); +assert.sameValue(stringCount, 0, 'initializer not evaluated: string'); +assert.sameValue(nanCount, 0, 'initializer not evaluated: NaN'); +assert.sameValue(zeroCount, 0, 'initializer not evaluated: 0'); +assert.sameValue(nullCount, 0, 'initializer not evaluated: null'); +assert.sameValue(objCount, 0, 'initializer not evaluated: object'); diff --git a/js/src/tests/test262/language/statements/async-generator/dflt-params-arg-val-undefined.js b/js/src/tests/test262/language/statements/async-generator/dflt-params-arg-val-undefined.js new file mode 100644 index 0000000000..614a523460 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dflt-params-arg-val-undefined.js @@ -0,0 +1,48 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-arg-val-undefined.case +// - src/function-forms/default/async-gen-func-decl.template +/*--- +description: Use of initializer when argument value is `undefined` (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [default-parameters, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + [...] + 23. Let iteratorRecord be Record {[[Iterator]]: + CreateListIterator(argumentsList), [[Done]]: false}. + 24. If hasDuplicates is true, then + [...] + 25. Else, + a. Perform ? IteratorBindingInitialization for formals with + iteratorRecord and env as arguments. + [...] + +---*/ + + +var callCount = 0; +// Stores a reference `ref` for case evaluation +async function* ref(fromLiteral = 23, fromExpr = 45, fromHole = 99) { + assert.sameValue(fromLiteral, 23); + assert.sameValue(fromExpr, 45); + assert.sameValue(fromHole, 99); + callCount = callCount + 1; +} + +ref(undefined, void 0).next().then(() => { + assert.sameValue(callCount, 1, 'generator function invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dflt-params-duplicates.js b/js/src/tests/test262/language/statements/async-generator/dflt-params-duplicates.js new file mode 100644 index 0000000000..48ac553082 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dflt-params-duplicates.js @@ -0,0 +1,42 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-duplicates.case +// - src/function-forms/syntax/async-gen-func-decl.template +/*--- +description: It is a Syntax Error if BoundNames of FormalParameters contains any duplicate elements. (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [default-parameters, async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 14.1.2 Static Semantics: Early Errors + + StrictFormalParameters : FormalParameters + + - It is a Syntax Error if BoundNames of FormalParameters contains any + duplicate elements. + + FormalParameters : FormalParameterList + + - It is a Syntax Error if IsSimpleParameterList of FormalParameterList is + false and BoundNames of FormalParameterList contains any duplicate + elements. + +---*/ +$DONOTEVALUATE(); + + +async function* f(x = 0, x) { + +} diff --git a/js/src/tests/test262/language/statements/async-generator/dflt-params-ref-later.js b/js/src/tests/test262/language/statements/async-generator/dflt-params-ref-later.js new file mode 100644 index 0000000000..e17f8f5136 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dflt-params-ref-later.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-ref-later.case +// - src/function-forms/error/async-gen-func-decl.template +/*--- +description: Referencing a parameter that occurs later in the ParameterList (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [default-parameters, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + 1. Let status be the result of performing IteratorBindingInitialization for + FormalsList using iteratorRecord and environment as the arguments. + 2. ReturnIfAbrupt(status). + 3. Return the result of performing IteratorBindingInitialization for + FormalParameter using iteratorRecord and environment as the arguments. + +---*/ +var x = 0; + + +var callCount = 0; +async function* f(x = y, y) { + + callCount = callCount + 1; +} + +assert.throws(ReferenceError, function() { + f(); +}); + +assert.sameValue(callCount, 0, 'generator function body not evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dflt-params-ref-prior.js b/js/src/tests/test262/language/statements/async-generator/dflt-params-ref-prior.js new file mode 100644 index 0000000000..2df4cd9872 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dflt-params-ref-prior.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-ref-prior.case +// - src/function-forms/default/async-gen-func-decl.template +/*--- +description: Referencing a parameter that occurs earlier in the ParameterList (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [default-parameters, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + 1. Let status be the result of performing IteratorBindingInitialization for + FormalsList using iteratorRecord and environment as the arguments. + 2. ReturnIfAbrupt(status). + 3. Return the result of performing IteratorBindingInitialization for + FormalParameter using iteratorRecord and environment as the arguments. + +---*/ +var x = 0; + + +var callCount = 0; +// Stores a reference `ref` for case evaluation +async function* ref(x, y = x, z = y) { + assert.sameValue(x, 3, 'first argument value'); + assert.sameValue(y, 3, 'second argument value'); + assert.sameValue(z, 3, 'third argument value'); + callCount = callCount + 1; +} + +ref(3).next().then(() => { + assert.sameValue(callCount, 1, 'generator function invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dflt-params-ref-self.js b/js/src/tests/test262/language/statements/async-generator/dflt-params-ref-self.js new file mode 100644 index 0000000000..24b4278be1 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dflt-params-ref-self.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-ref-self.case +// - src/function-forms/error/async-gen-func-decl.template +/*--- +description: Referencing a parameter from within its own initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [default-parameters, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 14.1.19 Runtime Semantics: IteratorBindingInitialization + + FormalsList : FormalsList , FormalParameter + + 1. Let status be the result of performing IteratorBindingInitialization for + FormalsList using iteratorRecord and environment as the arguments. + 2. ReturnIfAbrupt(status). + 3. Return the result of performing IteratorBindingInitialization for + FormalParameter using iteratorRecord and environment as the arguments. + +---*/ +var x = 0; + + +var callCount = 0; +async function* f(x = x) { + + callCount = callCount + 1; +} + +assert.throws(ReferenceError, function() { + f(); +}); + +assert.sameValue(callCount, 0, 'generator function body not evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dflt-params-rest.js b/js/src/tests/test262/language/statements/async-generator/dflt-params-rest.js new file mode 100644 index 0000000000..50094b3de8 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dflt-params-rest.js @@ -0,0 +1,46 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-rest.case +// - src/function-forms/syntax/async-gen-func-decl.template +/*--- +description: RestParameter does not support an initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [default-parameters, async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 14.1 Function Definitions + + Syntax + + FunctionRestParameter[Yield] : + + BindingRestElement[?Yield] + + 13.3.3 Destructuring Binding Patterns + + Syntax + + BindingRestElement[Yield] : + + ...BindingIdentifier[?Yield] + ...BindingPattern[?Yield] + +---*/ +$DONOTEVALUATE(); + + +async function* f(...x = []) { + +} diff --git a/js/src/tests/test262/language/statements/async-generator/dflt-params-trailing-comma.js b/js/src/tests/test262/language/statements/async-generator/dflt-params-trailing-comma.js new file mode 100644 index 0000000000..f5e049aeda --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dflt-params-trailing-comma.js @@ -0,0 +1,40 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/dflt-params-trailing-comma.case +// - src/function-forms/default/async-gen-func-decl.template +/*--- +description: A trailing comma should not increase the respective length, using default parameters (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + Trailing comma in the parameters list + + 14.1 Function Definitions + + FormalParameters[Yield, Await] : FormalParameterList[?Yield, ?Await] , +---*/ + + +var callCount = 0; +// Stores a reference `ref` for case evaluation +async function* ref(a, b = 39,) { + assert.sameValue(a, 42); + assert.sameValue(b, 39); + callCount = callCount + 1; +} + +ref(42, undefined, 1).next().then(() => { + assert.sameValue(callCount, 1, 'generator function invoked exactly once'); +}).then($DONE, $DONE); + +assert.sameValue(ref.length, 1, 'length is properly set'); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-close.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-close.js new file mode 100644 index 0000000000..66717ee508 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-close.js @@ -0,0 +1,52 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-close.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: false }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + + +var callCount = 0; +async function* f([x]) { + assert.sameValue(doneCallCount, 1); + callCount = callCount + 1; +}; +f(iter).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..1a9865bda0 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-get-err-array-prototype.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err-array-prototype.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Abrupt completion returned by GetIterator (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iteratorRecord be ? GetIterator(value). + + GetIterator ( obj [ , hint [ , method ] ] ) + + [...] + 4. Let iterator be ? Call(method, obj). + + Call ( F, V [ , argumentsList ] ) + + [...] + 2. If IsCallable(F) is false, throw a TypeError exception. + +---*/ +delete Array.prototype[Symbol.iterator]; + + +async function* f([x, y, z]) { + +}; + +assert.throws(TypeError, function() { + f([1, 2, 3]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-get-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-get-err.js new file mode 100644 index 0000000000..47760857b7 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-get-err.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Abrupt completion returned by GetIterator (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + + +async function* f([x]) { + +}; + +assert.throws(Test262Error, function() { + f(iter); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-no-close.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-no-close.js new file mode 100644 index 0000000000..f42a6ef574 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-init-iter-no-close.js @@ -0,0 +1,52 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-no-close.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: true }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + + +var callCount = 0; +async function* f([x]) { + assert.sameValue(doneCallCount, 0); + callCount = callCount + 1; +}; +f(iter).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-name-iter-val.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-name-iter-val.js new file mode 100644 index 0000000000..9dd28b5cbd --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-name-iter-val.js @@ -0,0 +1,51 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-name-iter-val.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding with normal value iteration (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x, y, z]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + callCount = callCount + 1; +}; +f([1, 2, 3]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..5eeaddad31 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elem-init.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-init.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with array binding pattern and initializer is used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([[x, y, z] = [4, 5, 6]]) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..cbbc764a7b --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elem-iter.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-iter.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([[x, y, z] = [4, 5, 6]]) { + assert.sameValue(x, 7); + assert.sameValue(y, 8); + assert.sameValue(z, 9); + callCount = callCount + 1; +}; +f([[7, 8, 9]]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..723e86f68d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elision-init.js @@ -0,0 +1,50 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-init.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with array binding pattern and initializer is used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + + +var callCount = 0; +async function* f([[,] = g()]) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..40495d162f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-elision-iter.js @@ -0,0 +1,47 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-iter.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var callCount = 0; +function* g() { + callCount += 1; +}; + + +var callCount = 0; +async function* f([[,] = g()]) { + assert.sameValue(callCount, 0); + callCount = callCount + 1; +}; +f([[]]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..fbdc137fd1 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-empty-init.js @@ -0,0 +1,46 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-init.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with array binding pattern and initializer is used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var initCount = 0; +var iterCount = 0; +var iter = function*() { iterCount += 1; }(); + + +var callCount = 0; +async function* f([[] = function() { initCount += 1; return iter; }()]) { + assert.sameValue(initCount, 1); + assert.sameValue(iterCount, 0); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..51d5ea22a1 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-empty-iter.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-iter.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var initCount = 0; + + +var callCount = 0; +async function* f([[] = function() { initCount += 1; }()]) { + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; +f([[23]]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..78f1782d92 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-rest-init.js @@ -0,0 +1,47 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-init.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with array binding pattern and initializer is used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; + + +var callCount = 0; +async function* f([[...x] = values]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..9271decb43 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-rest-iter.js @@ -0,0 +1,50 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-iter.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; +var initCount = 0; + + +var callCount = 0; +async function* f([[...x] = function() { initCount += 1; }()]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; +f([values]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..d0ebed22f0 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-ary-val-null.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-val-null.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Nested array destructuring with a null value (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). +---*/ + + +async function* f([[x]]) { + +}; + +assert.throws(TypeError, function() { + f([null]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..aaf0cfd4cd --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-exhausted.js @@ -0,0 +1,42 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-exhausted.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Destructuring initializer with an exhausted iterator (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x = 23]) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..41133d343f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-arrow.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-arrow.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding does assign name to arrow functions (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([arrow = () => {}]) { + assert.sameValue(arrow.name, 'arrow'); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..361a54ca1e --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-class.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-class.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }]) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..35ac762a96 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-cover.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-cover.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([cover = (function () {}), xCover = (0, function() {})]) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..0553c068fe --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-fn.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-fn.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([fn = function () {}, xFn = function x() {}]) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..c785c7d025 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-fn-name-gen.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-gen.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). + +---*/ + + +var callCount = 0; +async function* f([gen = function* () {}, xGen = function* x() {}]) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..2e66084421 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-hole.js @@ -0,0 +1,38 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-hole.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Destructuring initializer with a "hole" (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + SingleNameBinding : BindingIdentifier Initializeropt + [...] 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x = 23]) { + assert.sameValue(x, 23); + // another statement + callCount = callCount + 1; +}; +f([,]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..937670ce09 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-skipped.js @@ -0,0 +1,47 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-skipped.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + + +var callCount = 0; +async function* f([w = counter(), x = counter(), y = counter(), z = counter()]) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; +f([null, 0, false, '']).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..a47cab8a60 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-throws.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-throws.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Destructuring initializer returns an abrupt completion (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ + + +async function* f([x = (function() { throw new Test262Error(); })()]) { + +}; + +assert.throws(Test262Error, function() { + f([undefined]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..711fcfc10b --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-undef.js @@ -0,0 +1,41 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-undef.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Destructuring initializer with an undefined value (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x = 23]) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; +f([undefined]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..91a4c062fe --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-init-unresolvable.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-unresolvable.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Destructuring initializer is an unresolvable reference (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + + +async function* f([ x = unresolvableReference ]) { + +}; + +assert.throws(ReferenceError, function() { + f([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..d1a11c6fac --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-complete.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-complete.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding when value iteration completes (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x]) { + assert.sameValue(x, undefined); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..d4b4d4e018 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-done.js @@ -0,0 +1,40 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-done.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding when value iteration was completed previously (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([_, x]) { + assert.sameValue(x, undefined); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..f572a96d70 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-step-err.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-step-err.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + + +async function* f([x]) { + +}; + +assert.throws(Test262Error, function() { + f(g); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..38b3441861 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-val-array-prototype.js @@ -0,0 +1,61 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-array-prototype.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializer_opt + + 1. Let bindingId be StringValue of BindingIdentifier. + 2. Let lhs be ? ResolveBinding(bindingId, environment). + 3. If iteratorRecord.[[Done]] is false, then + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[Done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[Done]] to true. + iii. ReturnIfAbrupt(v). + [...] + 7. Return InitializeReferencedBinding(lhs, v). + +---*/ +Array.prototype[Symbol.iterator] = function* () { + if (this.length > 0) { + yield this[0]; + } + if (this.length > 1) { + yield this[1]; + } + if (this.length > 2) { + yield 42; + } +}; + + +var callCount = 0; +async function* f([x, y, z]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 42); + callCount = callCount + 1; +}; +f([1, 2, 3]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..178441885a --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-val-err.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-err.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(v). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + + +async function* f([x]) { + +}; + +assert.throws(Test262Error, function() { + f(g); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..5c49770c68 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-id-iter-val.js @@ -0,0 +1,51 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding when value iteration was completed previously (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x, y, z]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + callCount = callCount + 1; +}; +f([1, 2, 3]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..050ac6608e --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-id-init.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id-init.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with object binding pattern and initializer is used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([{ x, y, z } = { x: 44, y: 55, z: 66 }]) { + assert.sameValue(x, 44); + assert.sameValue(y, 55); + assert.sameValue(z, 66); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..5b956e129f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-id.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([{ x, y, z } = { x: 44, y: 55, z: 66 }]) { + assert.sameValue(x, 11); + assert.sameValue(y, 22); + assert.sameValue(z, 33); + callCount = callCount + 1; +}; +f([{ x: 11, y: 22, z: 33 }]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..1880fe720f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-prop-id-init.js @@ -0,0 +1,53 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id-init.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with object binding pattern and initializer is used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }]) { + assert.sameValue(v, 444); + assert.sameValue(x, 555); + assert.sameValue(z, 666); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..46e8755d07 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-prop-id.js @@ -0,0 +1,53 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }]) { + assert.sameValue(v, 777); + assert.sameValue(x, 888); + assert.sameValue(z, 999); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; +f([{ u: 777, w: 888, y: 999 }]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..a70d7d5795 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-val-null.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-null.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Nested object destructuring with a null value (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + + +async function* f([{ x }]) { + +}; + +assert.throws(TypeError, function() { + f([null]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..025274a7d6 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elem-obj-val-undef.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-undef.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Nested object destructuring with a value of `undefined` (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + + +async function* f([{ x }]) { + +}; + +assert.throws(TypeError, function() { + f([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..b7f11d1ab4 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elision-exhausted.js @@ -0,0 +1,48 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-exhausted.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Elision accepts exhausted iterator (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + [...] + 2. Return NormalCompletion(empty). + +---*/ +var iter = function*() {}(); +iter.next(); + + +var callCount = 0; +async function* f([,]) { + + callCount = callCount + 1; +}; +f(iter).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..cf759e2f6f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elision-step-err.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-step-err.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Elision advances iterator and forwards abrupt completions (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var following = 0; +var iter =function* () { + throw new Test262Error(); + following += 1; +}(); + + +async function* f([,]) { + +}; + +assert.throws(Test262Error, function() { + f(iter); +}); + +iter.next(); +assert.sameValue(following, 0, 'Iterator was properly closed.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elision.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elision.js new file mode 100644 index 0000000000..2571145e47 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-elision.js @@ -0,0 +1,57 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Elision advances iterator (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + + +var callCount = 0; +async function* f([,]) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + callCount = callCount + 1; +}; +f(g()).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-empty.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-empty.js new file mode 100644 index 0000000000..db417ba5bf --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-empty.js @@ -0,0 +1,40 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-empty.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + + +var callCount = 0; +async function* f([]) { + assert.sameValue(iterations, 0); + callCount = callCount + 1; +}; +f(iter).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..1d1e9fd881 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-elem.js @@ -0,0 +1,64 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elem.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element containing an array BindingElementList pattern (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([...[x, y, z]]) { + assert.sameValue(x, 3); + assert.sameValue(y, 4); + assert.sameValue(z, 5); + callCount = callCount + 1; +}; +f([3, 4, 5]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..e83247fdc5 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-elision.js @@ -0,0 +1,70 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elision.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element containing an elision (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + + +var callCount = 0; +async function* f([...[,]]) { + assert.sameValue(first, 1); + assert.sameValue(second, 1); + callCount = callCount + 1; +}; +f(g()).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..73693bd1bd --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-empty.js @@ -0,0 +1,53 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-empty.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element containing an "empty" array pattern (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + + +var callCount = 0; +async function* f([...[]]) { + assert.sameValue(iterations, 1); + callCount = callCount + 1; +}; +f(iter).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..d1a09db82f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-ary-rest.js @@ -0,0 +1,49 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-rest.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element containing a rest element (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +var values = [1, 2, 3]; + + +var callCount = 0; +async function* f([...[...x]]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + + callCount = callCount + 1; +}; +f(values).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..e12f4ca909 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-direct.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-direct.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Lone rest element (direct binding) (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +includes: [compareArray.js] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingIdentifier + + [...] + 2. Let A be ! ArrayCreate(0). + 3. Let n be 0. + 4. Repeat, + [...] + f. Perform ! CreateDataPropertyOrThrow(A, ! ToString(n), nextValue). + g. Set n to n + 1. + +---*/ + + +var callCount = 0; +async function* f([...x]) { + assert(Array.isArray(x)); + assert.compareArray(x, [1]); + callCount = callCount + 1; +}; +f([1]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..17aef78e13 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-elision-next-err.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision-next-err.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Rest element following elision elements (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. + +---*/ +var iter = (function*() { throw new Test262Error(); })(); + + +async function* f([, ...x]) { + +}; + +assert.throws(Test262Error, function() { + f(iter); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..e78db95d58 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-elision.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element following elision elements (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. +---*/ +var values = [1, 2, 3, 4, 5]; + + +var callCount = 0; +async function* f([ , , ...x]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 3); + assert.sameValue(x[1], 4); + assert.sameValue(x[2], 5); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; +f(values).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..afbae9f5b7 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-exhausted.js @@ -0,0 +1,41 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-exhausted.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: RestElement applied to an exhausted iterator (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + b. If iteratorRecord.[[done]] is true, then + i. If environment is undefined, return PutValue(lhs, A). + ii. Return InitializeReferencedBinding(lhs, A). + +---*/ + + +var callCount = 0; +async function* f([, , ...x]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 0); + callCount = callCount + 1; +}; +f([1, 2]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..c8ea051d59 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-iter-step-err.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-step-err.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + a. If iteratorRecord.[[done]] is false, + i. Let next be IteratorStep(iteratorRecord.[[iterator]]). + ii. If next is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(next). + +---*/ +var first = 0; +var second = 0; +var iter = function*() { + first += 1; + throw new Test262Error(); + second += 1; +}(); + + +async function* f([...x]) { + +}; + +assert.throws(Test262Error, function() { + f(iter); +}); + +iter.next(); +assert.sameValue(first, 1); +assert.sameValue(second, 0, 'Iterator is closed following abrupt completion.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..58b4e41cae --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id-iter-val-err.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-val-err.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + c. Let nextValue be IteratorValue(next). + d. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to + true. + e. ReturnIfAbrupt(nextValue). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + + +async function* f([...x]) { + +}; + +assert.throws(Test262Error, function() { + f(iter); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id.js new file mode 100644 index 0000000000..c6841c4a97 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-id.js @@ -0,0 +1,42 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Lone rest element (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + [...] 3. Let A be ArrayCreate(0). [...] 5. Repeat + [...] + f. Let status be CreateDataProperty(A, ToString (n), nextValue). + [...] +---*/ +var values = [1, 2, 3]; + + +var callCount = 0; +async function* f([...x]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; +f(values).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..bb9b3db04e --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-init-ary.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-ary.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element (nested array pattern) does not support initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...[ x ] = []]) { + + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..ff6045f1af --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-init-id.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-id.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element (identifier) does not support initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...x = []]) { + + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..613a299c64 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-init-obj.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-obj.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element (nested object pattern) does not support initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...{ x } = []]) { + + callCount = callCount + 1; +}; +f([]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..5f7c9ee7e0 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-not-final-ary.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-ary.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...[x], y]) { + + callCount = callCount + 1; +}; +f([1, 2, 3]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..e05edefa89 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-not-final-id.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-id.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element (identifier) may not be followed by any element (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...x, y]) { + + callCount = callCount + 1; +}; +f([1, 2, 3]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..33c334013c --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-not-final-obj.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-obj.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...{ x }, y]) { + + callCount = callCount + 1; +}; +f([1, 2, 3]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..29a9d3265b --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-obj-id.js @@ -0,0 +1,42 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-id.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element containing an object binding pattern (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ + + +var callCount = 0; +async function* f([...{ length }]) { + assert.sameValue(length, 3); + callCount = callCount + 1; +}; +f([1, 2, 3]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..684eb38b2f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/ary-ptrn-rest-obj-prop-id.js @@ -0,0 +1,49 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-prop-id.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest element containing an object binding pattern (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +let length = "outer"; + + +var callCount = 0; +async function* f([...{ 0: v, 1: w, 2: x, 3: y, length: z }]) { + assert.sameValue(v, 7); + assert.sameValue(w, 8); + assert.sameValue(x, 9); + assert.sameValue(y, undefined); + assert.sameValue(z, 3); + + assert.sameValue(length, "outer", "the length prop is not set as a binding name"); + callCount = callCount + 1; +}; +f([7, 8, 9]).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/browser.js b/js/src/tests/test262/language/statements/async-generator/dstr/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/browser.js diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-close.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-close.js new file mode 100644 index 0000000000..6414b85cc5 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-close.js @@ -0,0 +1,52 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-close.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Iterator is closed when not exhausted by pattern evaluation (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: false }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + + +var callCount = 0; +async function* f([x] = iter) { + assert.sameValue(doneCallCount, 1); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-get-err-array-prototype.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-get-err-array-prototype.js new file mode 100644 index 0000000000..1a56240ee1 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-get-err-array-prototype.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err-array-prototype.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Abrupt completion returned by GetIterator (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iteratorRecord be ? GetIterator(value). + + GetIterator ( obj [ , hint [ , method ] ] ) + + [...] + 4. Let iterator be ? Call(method, obj). + + Call ( F, V [ , argumentsList ] ) + + [...] + 2. If IsCallable(F) is false, throw a TypeError exception. + +---*/ +delete Array.prototype[Symbol.iterator]; + + +async function* f([x, y, z] = [1, 2, 3]) { + +}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-get-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-get-err.js new file mode 100644 index 0000000000..de44a6cc57 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-get-err.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-get-err.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Abrupt completion returned by GetIterator (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). + +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + + +async function* f([x] = iter) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-no-close.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-no-close.js new file mode 100644 index 0000000000..e8e41b61f0 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-init-iter-no-close.js @@ -0,0 +1,52 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-init-iter-no-close.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Iterator is not closed when exhausted by pattern evaluation (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + [...] + 4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, + result). + [...] + +---*/ +var doneCallCount = 0; +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return { value: null, done: true }; + }, + return: function() { + doneCallCount += 1; + return {}; + } + }; +}; + + +var callCount = 0; +async function* f([x] = iter) { + assert.sameValue(doneCallCount, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-name-iter-val.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-name-iter-val.js new file mode 100644 index 0000000000..8465a02be4 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-name-iter-val.js @@ -0,0 +1,51 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-name-iter-val.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding with normal value iteration (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x, y, z] = [1, 2, 3]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elem-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elem-init.js new file mode 100644 index 0000000000..b1767c07f9 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elem-init.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-init.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([[x, y, z] = [4, 5, 6]] = []) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elem-iter.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elem-iter.js new file mode 100644 index 0000000000..23964a3413 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elem-iter.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elem-iter.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([[x, y, z] = [4, 5, 6]] = [[7, 8, 9]]) { + assert.sameValue(x, 7); + assert.sameValue(y, 8); + assert.sameValue(z, 9); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elision-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elision-init.js new file mode 100644 index 0000000000..0f5d51e217 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elision-init.js @@ -0,0 +1,50 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-init.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + + +var callCount = 0; +async function* f([[,] = g()] = []) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elision-iter.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elision-iter.js new file mode 100644 index 0000000000..dc8b97e069 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-elision-iter.js @@ -0,0 +1,47 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-elision-iter.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var callCount = 0; +function* g() { + callCount += 1; +}; + + +var callCount = 0; +async function* f([[,] = g()] = [[]]) { + assert.sameValue(callCount, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-empty-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-empty-init.js new file mode 100644 index 0000000000..c86116e893 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-empty-init.js @@ -0,0 +1,46 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-init.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + +---*/ +var initCount = 0; +var iterCount = 0; +var iter = function*() { iterCount += 1; }(); + + +var callCount = 0; +async function* f([[] = function() { initCount += 1; return iter; }()] = []) { + assert.sameValue(initCount, 1); + assert.sameValue(iterCount, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-empty-iter.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-empty-iter.js new file mode 100644 index 0000000000..bd28dd3256 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-empty-iter.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-empty-iter.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var initCount = 0; + + +var callCount = 0; +async function* f([[] = function() { initCount += 1; }()] = [[23]]) { + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-rest-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-rest-init.js new file mode 100644 index 0000000000..52d1b56404 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-rest-init.js @@ -0,0 +1,47 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-init.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; + + +var callCount = 0; +async function* f([[...x] = values] = []) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-rest-iter.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-rest-iter.js new file mode 100644 index 0000000000..87d6e440ae --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-rest-iter.js @@ -0,0 +1,50 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-rest-iter.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with array binding pattern and initializer is not used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + [...] + e. Else, + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ +var values = [2, 1, 3]; +var initCount = 0; + + +var callCount = 0; +async function* f([[...x] = function() { initCount += 1; }()] = [values]) { + assert(Array.isArray(x)); + assert.sameValue(x[0], 2); + assert.sameValue(x[1], 1); + assert.sameValue(x[2], 3); + assert.sameValue(x.length, 3); + assert.notSameValue(x, values); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-val-null.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-val-null.js new file mode 100644 index 0000000000..07776a80c7 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-ary-val-null.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-ary-val-null.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Nested array destructuring with a null value (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ArrayBindingPattern + + 1. Let iterator be GetIterator(value). + 2. ReturnIfAbrupt(iterator). +---*/ + + +async function* f([[x]] = [null]) { + +}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-exhausted.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-exhausted.js new file mode 100644 index 0000000000..cd7012022b --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-exhausted.js @@ -0,0 +1,42 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-exhausted.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Destructuring initializer with an exhausted iterator (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x = 23] = []) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..5618b6127c --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-arrow.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-arrow.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding does assign name to arrow functions (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([arrow = () => {}] = []) { + assert.sameValue(arrow.name, 'arrow'); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-class.js new file mode 100644 index 0000000000..f8af995ee3 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-class.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-class.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([cls = class {}, xCls = class X {}, xCls2 = class { static name() {} }] = []) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-cover.js new file mode 100644 index 0000000000..a7a2ac2817 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-cover.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-cover.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding does assign name to "anonymous" functions "through" cover grammar (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([cover = (function () {}), xCover = (0, function() {})] = []) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-fn.js new file mode 100644 index 0000000000..29cb41fcc3 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-fn.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-fn.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([fn = function () {}, xFn = function x() {}] = []) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-gen.js new file mode 100644 index 0000000000..9e06b9f8d5 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-fn-name-gen.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-fn-name-gen.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). + +---*/ + + +var callCount = 0; +async function* f([gen = function* () {}, xGen = function* x() {}] = []) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-hole.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-hole.js new file mode 100644 index 0000000000..06d9249510 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-hole.js @@ -0,0 +1,38 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-hole.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Destructuring initializer with a "hole" (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + SingleNameBinding : BindingIdentifier Initializeropt + [...] 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x = 23] = [,]) { + assert.sameValue(x, 23); + // another statement + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-skipped.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-skipped.js new file mode 100644 index 0000000000..4ac8a44b1d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-skipped.js @@ -0,0 +1,47 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-skipped.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + + +var callCount = 0; +async function* f([w = counter(), x = counter(), y = counter(), z = counter()] = [null, 0, false, '']) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-throws.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-throws.js new file mode 100644 index 0000000000..21664b01a2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-throws.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-throws.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Destructuring initializer returns an abrupt completion (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ + + +async function* f([x = (function() { throw new Test262Error(); })()] = [undefined]) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-undef.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-undef.js new file mode 100644 index 0000000000..d65d474711 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-undef.js @@ -0,0 +1,41 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-undef.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Destructuring initializer with an undefined value (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + [...] + 7. If environment is undefined, return PutValue(lhs, v). + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x = 23] = [undefined]) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-unresolvable.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-unresolvable.js new file mode 100644 index 0000000000..fafba0dda8 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-init-unresolvable.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-init-unresolvable.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Destructuring initializer is an unresolvable reference (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + + +async function* f([ x = unresolvableReference ] = []) { + +}; + +assert.throws(ReferenceError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-complete.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-complete.js new file mode 100644 index 0000000000..c1e0cdc1cb --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-complete.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-complete.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding when value iteration completes (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x] = []) { + assert.sameValue(x, undefined); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-done.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-done.js new file mode 100644 index 0000000000..ac2460e888 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-done.js @@ -0,0 +1,40 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-done.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding when value iteration was completed previously (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + [...] + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([_, x] = []) { + assert.sameValue(x, undefined); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-step-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-step-err.js new file mode 100644 index 0000000000..8c48978994 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-step-err.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-step-err.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + + +async function* f([x] = g) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-val-array-prototype.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-val-array-prototype.js new file mode 100644 index 0000000000..ea16359a78 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-val-array-prototype.js @@ -0,0 +1,61 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-array-prototype.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Array destructuring uses overriden Array.prototype[Symbol.iterator] (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializer_opt + + 1. Let bindingId be StringValue of BindingIdentifier. + 2. Let lhs be ? ResolveBinding(bindingId, environment). + 3. If iteratorRecord.[[Done]] is false, then + a. Let next be IteratorStep(iteratorRecord). + b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[Done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[Done]] to true. + iii. ReturnIfAbrupt(v). + [...] + 7. Return InitializeReferencedBinding(lhs, v). + +---*/ +Array.prototype[Symbol.iterator] = function* () { + if (this.length > 0) { + yield this[0]; + } + if (this.length > 1) { + yield this[1]; + } + if (this.length > 2) { + yield 42; + } +}; + + +var callCount = 0; +async function* f([x, y, z] = [1, 2, 3]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 42); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-val-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-val-err.js new file mode 100644 index 0000000000..b35c1aae02 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-val-err.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val-err.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(v). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var g = {}; +g[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + + +async function* f([x] = g) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-val.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-val.js new file mode 100644 index 0000000000..25876266b0 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-id-iter-val.js @@ -0,0 +1,51 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-id-iter-val.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding when value iteration was completed previously (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([x, y, z] = [1, 2, 3]) { + assert.sameValue(x, 1); + assert.sameValue(y, 2); + assert.sameValue(z, 3); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-id-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-id-init.js new file mode 100644 index 0000000000..0b777e4c10 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-id-init.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id-init.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with object binding pattern and initializer is used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([{ x, y, z } = { x: 44, y: 55, z: 66 }] = []) { + assert.sameValue(x, 44); + assert.sameValue(y, 55); + assert.sameValue(z, 66); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-id.js new file mode 100644 index 0000000000..32510ad6ff --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-id.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-id.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([{ x, y, z } = { x: 44, y: 55, z: 66 }] = [{ x: 11, y: 22, z: 33 }]) { + assert.sameValue(x, 11); + assert.sameValue(y, 22); + assert.sameValue(z, 33); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-prop-id-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-prop-id-init.js new file mode 100644 index 0000000000..5a8c4cf500 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-prop-id-init.js @@ -0,0 +1,53 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id-init.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with object binding pattern and initializer is used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = []) { + assert.sameValue(v, 444); + assert.sameValue(x, 555); + assert.sameValue(z, 666); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-prop-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-prop-id.js new file mode 100644 index 0000000000..e1894c266d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-prop-id.js @@ -0,0 +1,53 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-prop-id.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: BindingElement with object binding pattern and initializer is not used (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPatternInitializer opt + + [...] + 2. If iteratorRecord.[[done]] is true, let v be undefined. + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be ? GetValue(defaultValue). + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. +---*/ + + +var callCount = 0; +async function* f([{ u: v, w: x, y: z } = { u: 444, w: 555, y: 666 }] = [{ u: 777, w: 888, y: 999 }]) { + assert.sameValue(v, 777); + assert.sameValue(x, 888); + assert.sameValue(z, 999); + + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-val-null.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-val-null.js new file mode 100644 index 0000000000..b1da8b1b5f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-val-null.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-null.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Nested object destructuring with a null value (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + + +async function* f([{ x }] = [null]) { + +}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-val-undef.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-val-undef.js new file mode 100644 index 0000000000..98f8e419ac --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elem-obj-val-undef.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elem-obj-val-undef.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Nested object destructuring with a value of `undefined` (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. If iteratorRecord.[[done]] is false, then + [...] + e. Else + i. Let v be IteratorValue(next). + [...] + 4. Return the result of performing BindingInitialization of BindingPattern + with v and environment as the arguments. + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPattern : ObjectBindingPattern + + 1. Let valid be RequireObjectCoercible(value). + 2. ReturnIfAbrupt(valid). +---*/ + + +async function* f([{ x }] = []) { + +}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elision-exhausted.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elision-exhausted.js new file mode 100644 index 0000000000..36ee1dd508 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elision-exhausted.js @@ -0,0 +1,48 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-exhausted.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Elision accepts exhausted iterator (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + [...] + 2. Return NormalCompletion(empty). + +---*/ +var iter = function*() {}(); +iter.next(); + + +var callCount = 0; +async function* f([,] = iter) { + + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elision-step-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elision-step-err.js new file mode 100644 index 0000000000..7961fd0631 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elision-step-err.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision-step-err.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Elision advances iterator and forwards abrupt completions (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + +---*/ +var following = 0; +var iter =function* () { + throw new Test262Error(); + following += 1; +}(); + + +async function* f([,] = iter) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +iter.next(); +assert.sameValue(following, 0, 'Iterator was properly closed.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elision.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elision.js new file mode 100644 index 0000000000..d6b839cf5c --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-elision.js @@ -0,0 +1,57 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-elision.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Elision advances iterator (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + + +var callCount = 0; +async function* f([,] = g()) { + assert.sameValue(first, 1); + assert.sameValue(second, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-empty.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-empty.js new file mode 100644 index 0000000000..8d415e85d6 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-empty.js @@ -0,0 +1,40 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-empty.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: No iteration occurs for an "empty" array binding pattern (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + + +var callCount = 0; +async function* f([] = iter) { + assert.sameValue(iterations, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-elem.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-elem.js new file mode 100644 index 0000000000..d59f9184cf --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-elem.js @@ -0,0 +1,64 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elem.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element containing an array BindingElementList pattern (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + e. Else, + [...] + i. Let v be IteratorValue(next). + ii. If v is an abrupt completion, set + iteratorRecord.[[done]] to true. + iii. ReturnIfAbrupt(v). + 5. If iteratorRecord.[[done]] is true, let v be undefined. + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f([...[x, y, z]] = [3, 4, 5]) { + assert.sameValue(x, 3); + assert.sameValue(y, 4); + assert.sameValue(z, 5); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-elision.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-elision.js new file mode 100644 index 0000000000..74ce17b637 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-elision.js @@ -0,0 +1,70 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-elision.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element containing an elision (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ Elision ] + + 1. Return the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord + as the argument. + + 12.14.5.3 Runtime Semantics: IteratorDestructuringAssignmentEvaluation + + Elision : , + + 1. If iteratorRecord.[[done]] is false, then + a. Let next be IteratorStep(iteratorRecord.[[iterator]]). + b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. + c. ReturnIfAbrupt(next). + d. If next is false, set iteratorRecord.[[done]] to true. + 2. Return NormalCompletion(empty). + +---*/ +var first = 0; +var second = 0; +function* g() { + first += 1; + yield; + second += 1; +}; + + +var callCount = 0; +async function* f([...[,]] = g()) { + assert.sameValue(first, 1); + assert.sameValue(second, 1); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-empty.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-empty.js new file mode 100644 index 0000000000..534fee7f9e --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-empty.js @@ -0,0 +1,53 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-empty.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element containing an "empty" array pattern (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + ArrayBindingPattern : [ ] + + 1. Return NormalCompletion(empty). + +---*/ +var iterations = 0; +var iter = function*() { + iterations += 1; +}(); + + +var callCount = 0; +async function* f([...[]] = iter) { + assert.sameValue(iterations, 1); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-rest.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-rest.js new file mode 100644 index 0000000000..97ef5cf592 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-ary-rest.js @@ -0,0 +1,49 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-ary-rest.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element containing a rest element (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +var values = [1, 2, 3]; + + +var callCount = 0; +async function* f([...[...x]] = values) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-direct.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-direct.js new file mode 100644 index 0000000000..20ab4e6e64 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-direct.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-direct.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Lone rest element (direct binding) (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +includes: [compareArray.js] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingIdentifier + + [...] + 2. Let A be ! ArrayCreate(0). + 3. Let n be 0. + 4. Repeat, + [...] + f. Perform ! CreateDataPropertyOrThrow(A, ! ToString(n), nextValue). + g. Set n to n + 1. + +---*/ + + +var callCount = 0; +async function* f([...x] = [1]) { + assert(Array.isArray(x)); + assert.compareArray(x, [1]); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-elision-next-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-elision-next-err.js new file mode 100644 index 0000000000..3b681e70e2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-elision-next-err.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision-next-err.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Rest element following elision elements (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. + +---*/ +var iter = (function*() { throw new Test262Error(); })(); + + +async function* f([, ...x] = iter) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-elision.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-elision.js new file mode 100644 index 0000000000..a3a71900f0 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-elision.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-elision.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element following elision elements (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + ArrayBindingPattern : [ Elisionopt BindingRestElement ] + 1. If Elision is present, then + a. Let status be the result of performing + IteratorDestructuringAssignmentEvaluation of Elision with + iteratorRecord as the argument. + b. ReturnIfAbrupt(status). + 2. Return the result of performing IteratorBindingInitialization for + BindingRestElement with iteratorRecord and environment as arguments. +---*/ +var values = [1, 2, 3, 4, 5]; + + +var callCount = 0; +async function* f([ , , ...x] = values) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 3); + assert.sameValue(x[1], 4); + assert.sameValue(x[2], 5); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-exhausted.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-exhausted.js new file mode 100644 index 0000000000..0dd8596944 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-exhausted.js @@ -0,0 +1,41 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-exhausted.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: RestElement applied to an exhausted iterator (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + b. If iteratorRecord.[[done]] is true, then + i. If environment is undefined, return PutValue(lhs, A). + ii. Return InitializeReferencedBinding(lhs, A). + +---*/ + + +var callCount = 0; +async function* f([, , ...x] = [1, 2]) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-iter-step-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-iter-step-err.js new file mode 100644 index 0000000000..77cd5280ed --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-iter-step-err.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-step-err.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Error forwarding when IteratorStep returns an abrupt completion (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + a. If iteratorRecord.[[done]] is false, + i. Let next be IteratorStep(iteratorRecord.[[iterator]]). + ii. If next is an abrupt completion, set iteratorRecord.[[done]] to + true. + iii. ReturnIfAbrupt(next). + +---*/ +var first = 0; +var second = 0; +var iter = function*() { + first += 1; + throw new Test262Error(); + second += 1; +}(); + + +async function* f([...x] = iter) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +iter.next(); +assert.sameValue(first, 1); +assert.sameValue(second, 0, 'Iterator is closed following abrupt completion.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-iter-val-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-iter-val-err.js new file mode 100644 index 0000000000..daea98a488 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id-iter-val-err.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id-iter-val-err.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Error forwarding when IteratorValue returns an abrupt completion (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [Symbol.iterator, async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, + environment). + 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, + [...] + c. Let nextValue be IteratorValue(next). + d. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to + true. + e. ReturnIfAbrupt(nextValue). + +---*/ +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + + +async function* f([...x] = iter) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id.js new file mode 100644 index 0000000000..39b0da8701 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-id.js @@ -0,0 +1,42 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-id.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Lone rest element (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + BindingRestElement : ... BindingIdentifier + [...] 3. Let A be ArrayCreate(0). [...] 5. Repeat + [...] + f. Let status be CreateDataProperty(A, ToString (n), nextValue). + [...] +---*/ +var values = [1, 2, 3]; + + +var callCount = 0; +async function* f([...x] = values) { + assert(Array.isArray(x)); + assert.sameValue(x.length, 3); + assert.sameValue(x[0], 1); + assert.sameValue(x[1], 2); + assert.sameValue(x[2], 3); + assert.notSameValue(x, values); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-init-ary.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-init-ary.js new file mode 100644 index 0000000000..4ce335cf4e --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-init-ary.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-ary.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element (nested array pattern) does not support initializer (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...[ x ] = []] = []) { + + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-init-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-init-id.js new file mode 100644 index 0000000000..9b4c9810e3 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-init-id.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-id.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element (identifier) does not support initializer (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...x = []] = []) { + + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-init-obj.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-init-obj.js new file mode 100644 index 0000000000..215054fba8 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-init-obj.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-init-obj.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element (nested object pattern) does not support initializer (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...{ x } = []] = []) { + + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-not-final-ary.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-not-final-ary.js new file mode 100644 index 0000000000..30829b32c1 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-not-final-ary.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-ary.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element (array binding pattern) may not be followed by any element (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...[x], y] = [1, 2, 3]) { + + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-not-final-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-not-final-id.js new file mode 100644 index 0000000000..61dc0c55af --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-not-final-id.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-id.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element (identifier) may not be followed by any element (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...x, y] = [1, 2, 3]) { + + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-not-final-obj.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-not-final-obj.js new file mode 100644 index 0000000000..b968e3a5c9 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-not-final-obj.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-not-final-obj.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element (object binding pattern) may not be followed by any element (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + ArrayBindingPattern[Yield] : + [ Elisionopt BindingRestElement[?Yield]opt ] + [ BindingElementList[?Yield] ] + [ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ] +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; +async function* f([...{ x }, y] = [1, 2, 3]) { + + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-obj-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-obj-id.js new file mode 100644 index 0000000000..22573b9f72 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-obj-id.js @@ -0,0 +1,42 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-id.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element containing an object binding pattern (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ + + +var callCount = 0; +async function* f([...{ length }] = [1, 2, 3]) { + assert.sameValue(length, 3); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-obj-prop-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-obj-prop-id.js new file mode 100644 index 0000000000..1ec00fde2f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-ary-ptrn-rest-obj-prop-id.js @@ -0,0 +1,49 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/ary-ptrn-rest-obj-prop-id.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest element containing an object binding pattern (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.6 Runtime Semantics: IteratorBindingInitialization + + BindingRestElement : ... BindingPattern + + 1. Let A be ArrayCreate(0). + [...] + 3. Repeat + [...] + b. If iteratorRecord.[[done]] is true, then + i. Return the result of performing BindingInitialization of + BindingPattern with A and environment as the arguments. + [...] +---*/ +let length = "outer"; + + +var callCount = 0; +async function* f([...{ 0: v, 1: w, 2: x, 3: y, length: z }] = [7, 8, 9]) { + assert.sameValue(v, 7); + assert.sameValue(w, 8); + assert.sameValue(x, 9); + assert.sameValue(y, undefined); + assert.sameValue(z, 3); + + assert.sameValue(length, "outer", "the length prop is not set as a binding name"); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-init-null.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-init-null.js new file mode 100644 index 0000000000..7666e0fee3 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-init-null.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-null.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + + +async function* f({} = null) { + +}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-init-undefined.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-init-undefined.js new file mode 100644 index 0000000000..72af21f978 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-init-undefined.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-undefined.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + + +async function* f({} = undefined) { + +}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-empty.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-empty.js new file mode 100644 index 0000000000..d09c56d7bb --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-empty.js @@ -0,0 +1,41 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-empty.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: No property access occurs for an "empty" object binding pattern (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ +var accessCount = 0; +var obj = Object.defineProperty({}, 'attr', { + get: function() { + accessCount += 1; + } +}); + + +var callCount = 0; +async function* f({} = obj) { + assert.sameValue(accessCount, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..eca4bc75ab --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-get-value-err.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-get-value-err.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. Let v be GetV(value, propertyName). + 5. ReturnIfAbrupt(v). +---*/ +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + + +async function* f({ poisoned } = poisonedProperty) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..305dd74e47 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-arrow.js @@ -0,0 +1,42 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-arrow.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + + +var callCount = 0; +async function* f({ arrow = () => {} } = {}) { + assert.sameValue(arrow.name, 'arrow'); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..4c1ffddfc3 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-class.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-class.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + + +var callCount = 0; +async function* f({ cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } } = {}) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..27a82ff7ef --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-cover.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-cover.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + + +var callCount = 0; +async function* f({ cover = (function () {}), xCover = (0, function() {}) } = {}) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..98a366aa31 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-fn.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-fn.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + + +var callCount = 0; +async function* f({ fn = function () {}, xFn = function x() {} } = {}) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..4496b1a371 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-fn-name-gen.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-gen.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). + +---*/ + + +var callCount = 0; +async function* f({ gen = function* () {}, xGen = function* x() {} } = {}) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..f16fd9dde4 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-skipped.js @@ -0,0 +1,46 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-skipped.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + + +var callCount = 0; +async function* f({ w = counter(), x = counter(), y = counter(), z = counter() } = { w: null, x: 0, y: false, z: '' }) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..50b1cf0c36 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-throws.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-throws.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Error thrown when evaluating the initializer (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + + +async function* f({ x = thrower() } = {}) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..b15b7359c3 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-init-unresolvable.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-unresolvable.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Destructuring initializer is an unresolvable reference (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + + +async function* f({ x = unresolvableReference } = {}) { + +}; + +assert.throws(ReferenceError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..be253e56a2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-id-trailing-comma.js @@ -0,0 +1,36 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-trailing-comma.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + + +var callCount = 0; +async function* f({ x, } = { x: 23 }) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-list-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-list-err.js new file mode 100644 index 0000000000..75d1b49d22 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-list-err.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-list-err.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPropertyList : BindingPropertyList , BindingProperty + + 1. Let status be the result of performing BindingInitialization for + BindingPropertyList using value and environment as arguments. + 2. ReturnIfAbrupt(status). +---*/ +var initCount = 0; +function thrower() { + throw new Test262Error(); +} + + +async function* f({ a, b = thrower(), c = ++initCount } = {}) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..6b7db21671 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary-init.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-init.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +var callCount = 0; +async function* f({ w: [x, y, z] = [4, 5, 6] } = {}) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..44112cd71b --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary-trailing-comma.js @@ -0,0 +1,36 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-trailing-comma.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + + +var callCount = 0; +async function* f({ x: [y], } = { x: [45] }) { + assert.sameValue(y,45); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..118f16b3e8 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary-value-null.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-value-null.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +async function* f({ w: [x, y, z] = [4, 5, 6] } = { w: null }) { + +}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..552d85c163 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-ary.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +var callCount = 0; +async function* f({ w: [x, y, z] = [4, 5, 6] } = { w: [7, undefined, ] }) { + assert.sameValue(x, 7); + assert.sameValue(y, undefined); + assert.sameValue(z, undefined); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..f5e611718d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-eval-err.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-eval-err.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Evaluation of property name returns an abrupt completion (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingProperty : PropertyName : BindingElement + + 1. Let P be the result of evaluating PropertyName + 2. ReturnIfAbrupt(P). +---*/ +function thrower() { + throw new Test262Error(); +} + + +async function* f({ [thrower()]: x } = {}) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..ef6f3f23e2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-get-value-err.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-get-value-err.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. Let v be GetV(value, propertyName). + 2. ReturnIfAbrupt(v). +---*/ +var initEvalCount = 0; +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + + +async function* f({ poisoned: x = ++initEvalCount } = poisonedProperty) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..edcc87ceb3 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init-skipped.js @@ -0,0 +1,58 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-skipped.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + + +var callCount = 0; +async function* f({ s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } = { s: null, u: 0, w: false, y: '' }) { + assert.sameValue(t, null); + assert.sameValue(v, 0); + assert.sameValue(x, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + assert.throws(ReferenceError, function() { + s; + }); + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..b0814dabfe --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init-throws.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-throws.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Error thrown when evaluating the initializer (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + + +async function* f({ x: y = thrower() } = {}) { + +}; + +assert.throws(Test262Error, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..74ef7127dd --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init-unresolvable.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-unresolvable.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Destructuring initializer is an unresolvable reference (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + + +async function* f({ x: y = unresolvableReference } = {}) { + +}; + +assert.throws(ReferenceError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..5edab18821 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-init.js @@ -0,0 +1,39 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Binding as specified via property name, identifier, and initializer (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f({ x: y = 33 } = { }) { + assert.sameValue(y, 33); + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..308f9f5aca --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id-trailing-comma.js @@ -0,0 +1,40 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-trailing-comma.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + + +var callCount = 0; +async function* f({ x: y, } = { x: 23 }) { + assert.sameValue(y, 23); + + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id.js new file mode 100644 index 0000000000..660995b69d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-id.js @@ -0,0 +1,39 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Binding as specified via property name and identifier (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f({ x: y } = { x: 23 }) { + assert.sameValue(y, 23); + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..62ed8e5e15 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj-init.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-init.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +var callCount = 0; +async function* f({ w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: undefined }) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..7d4681cde7 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj-value-null.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-null.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +async function* f({ w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: null }) { + +}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..a241147697 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj-value-undef.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-undef.case +// - src/dstr-binding/error/async-gen-func-decl-dflt.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +async function* f({ w: { x, y, z } = undefined } = { }) { + +}; + +assert.throws(TypeError, function() { + f(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..4e1490ec4d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-prop-obj.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +var callCount = 0; +async function* f({ w: { x, y, z } = { x: 4, y: 5, z: 6 } } = { w: { x: undefined, z: 7 } }) { + assert.sameValue(x, undefined); + assert.sameValue(y, undefined); + assert.sameValue(z, 7); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-rest-getter.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..4cfe3fafe0 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-rest-getter.js @@ -0,0 +1,38 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-getter.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [object-rest, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + +---*/ +var count = 0; + + +var callCount = 0; +async function* f({...x} = { get v() { count++; return 2; } }) { + assert.sameValue(count, 1); + + verifyProperty(x, "v", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..3563a9ae17 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-rest-skip-non-enumerable.js @@ -0,0 +1,46 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-skip-non-enumerable.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest object doesn't contain non-enumerable properties (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [object-rest, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + +---*/ +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); + + +var callCount = 0; +async function* f({...rest} = o) { + assert.sameValue(rest.x, undefined); + + verifyProperty(rest, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(rest, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 4 + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..a5a3e3b2ca --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/dflt-obj-ptrn-rest-val-obj.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-val-obj.case +// - src/dstr-binding/default/async-gen-func-decl-dflt.template +/*--- +description: Rest object contains just unextracted data (async generator function declaration (default parameter)) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [object-rest, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + +---*/ + + +var callCount = 0; +async function* f({a, b, ...rest} = {x: 1, y: 2, a: 5, b: 3}) { + assert.sameValue(rest.a, undefined); + assert.sameValue(rest.b, undefined); + + verifyProperty(rest, "x", { + enumerable: true, + writable: true, + configurable: true, + value: 1 + }); + + verifyProperty(rest, "y", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + callCount = callCount + 1; +}; +f().next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-init-null.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-init-null.js new file mode 100644 index 0000000000..deeb256b6e --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-init-null.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-null.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Value specifed for object binding pattern must be object coercible (null) (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + + +async function* f({}) { + +}; + +assert.throws(TypeError, function() { + f(null); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-init-undefined.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-init-undefined.js new file mode 100644 index 0000000000..f04f037892 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-init-undefined.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-init-undefined.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Value specifed for object binding pattern must be object coercible (undefined) (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ + + +async function* f({}) { + +}; + +assert.throws(TypeError, function() { + f(undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-empty.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-empty.js new file mode 100644 index 0000000000..23428d35f0 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-empty.js @@ -0,0 +1,41 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-empty.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: No property access occurs for an "empty" object binding pattern (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + Runtime Semantics: BindingInitialization + + ObjectBindingPattern : { } + + 1. Return NormalCompletion(empty). +---*/ +var accessCount = 0; +var obj = Object.defineProperty({}, 'attr', { + get: function() { + accessCount += 1; + } +}); + + +var callCount = 0; +async function* f({}) { + assert.sameValue(accessCount, 0); + callCount = callCount + 1; +}; +f(obj).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-get-value-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-get-value-err.js new file mode 100644 index 0000000000..1795f3cc65 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-get-value-err.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-get-value-err.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 4. Let v be GetV(value, propertyName). + 5. ReturnIfAbrupt(v). +---*/ +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + + +async function* f({ poisoned }) { + +}; + +assert.throws(Test262Error, function() { + f(poisonedProperty); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-arrow.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..237d5f9694 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-arrow.js @@ -0,0 +1,42 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-arrow.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding assigns `name` to arrow functions (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + + +var callCount = 0; +async function* f({ arrow = () => {} }) { + assert.sameValue(arrow.name, 'arrow'); + callCount = callCount + 1; +}; +f({}).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-class.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-class.js new file mode 100644 index 0000000000..e272d987e0 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-class.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-class.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" classes (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + + +var callCount = 0; +async function* f({ cls = class {}, xCls = class X {}, xCls2 = class { static name() {} } }) { + assert.sameValue(cls.name, 'cls'); + assert.notSameValue(xCls.name, 'xCls'); + assert.notSameValue(xCls2.name, 'xCls2'); + callCount = callCount + 1; +}; +f({}).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-cover.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-cover.js new file mode 100644 index 0000000000..6389dbcb7d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-cover.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-cover.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding assigns `name` to "anonymous" functions "through" cover grammar (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + + +var callCount = 0; +async function* f({ cover = (function () {}), xCover = (0, function() {}) }) { + assert.sameValue(cover.name, 'cover'); + assert.notSameValue(xCover.name, 'xCover'); + callCount = callCount + 1; +}; +f({}).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-fn.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-fn.js new file mode 100644 index 0000000000..1ccd8761ae --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-fn.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-fn.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding assigns name to "anonymous" functions (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). +---*/ + + +var callCount = 0; +async function* f({ fn = function () {}, xFn = function x() {} }) { + assert.sameValue(fn.name, 'fn'); + assert.notSameValue(xFn.name, 'xFn'); + callCount = callCount + 1; +}; +f({}).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-gen.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-gen.js new file mode 100644 index 0000000000..c9679afdfc --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-fn-name-gen.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-fn-name-gen.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: SingleNameBinding assigns name to "anonymous" generator functions (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [generators, async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, + bindingId). + +---*/ + + +var callCount = 0; +async function* f({ gen = function* () {}, xGen = function* x() {} }) { + assert.sameValue(gen.name, 'gen'); + assert.notSameValue(xGen.name, 'xGen'); + callCount = callCount + 1; +}; +f({}).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-skipped.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-skipped.js new file mode 100644 index 0000000000..3770316b3d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-skipped.js @@ -0,0 +1,46 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-skipped.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + [...] + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + + +var callCount = 0; +async function* f({ w = counter(), x = counter(), y = counter(), z = counter() }) { + assert.sameValue(w, null); + assert.sameValue(x, 0); + assert.sameValue(y, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + callCount = callCount + 1; +}; +f({ w: null, x: 0, y: false, z: '' }).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-throws.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-throws.js new file mode 100644 index 0000000000..34eda335f8 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-throws.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-throws.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Error thrown when evaluating the initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + + +async function* f({ x = thrower() }) { + +}; + +assert.throws(Test262Error, function() { + f({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-unresolvable.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-unresolvable.js new file mode 100644 index 0000000000..3e8e754b26 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-init-unresolvable.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-init-unresolvable.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Destructuring initializer is an unresolvable reference (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 6. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + + +async function* f({ x = unresolvableReference }) { + +}; + +assert.throws(ReferenceError, function() { + f({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-trailing-comma.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-trailing-comma.js new file mode 100644 index 0000000000..3fb2d68313 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-id-trailing-comma.js @@ -0,0 +1,36 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-id-trailing-comma.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + + +var callCount = 0; +async function* f({ x, }) { + assert.sameValue(x, 23); + callCount = callCount + 1; +}; +f({ x: 23 }).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-list-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-list-err.js new file mode 100644 index 0000000000..2eb05668ef --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-list-err.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-list-err.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Binding property list evaluation is interrupted by an abrupt completion (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingPropertyList : BindingPropertyList , BindingProperty + + 1. Let status be the result of performing BindingInitialization for + BindingPropertyList using value and environment as arguments. + 2. ReturnIfAbrupt(status). +---*/ +var initCount = 0; +function thrower() { + throw new Test262Error(); +} + + +async function* f({ a, b = thrower(), c = ++initCount }) { + +}; + +assert.throws(Test262Error, function() { + f({}); +}); + +assert.sameValue(initCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary-init.js new file mode 100644 index 0000000000..0f9f618d41 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary-init.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-init.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Object binding pattern with "nested" array binding pattern using initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +var callCount = 0; +async function* f({ w: [x, y, z] = [4, 5, 6] }) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; +f({}).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary-trailing-comma.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary-trailing-comma.js new file mode 100644 index 0000000000..8739c17c46 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary-trailing-comma.js @@ -0,0 +1,36 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-trailing-comma.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + + +var callCount = 0; +async function* f({ x: [y], }) { + assert.sameValue(y,45); + callCount = callCount + 1; +}; +f({ x: [45] }).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary-value-null.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary-value-null.js new file mode 100644 index 0000000000..0ce6940358 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary-value-null.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary-value-null.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Object binding pattern with "nested" array binding pattern taking the `null` value (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +async function* f({ w: [x, y, z] = [4, 5, 6] }) { + +}; + +assert.throws(TypeError, function() { + f({ w: null }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary.js new file mode 100644 index 0000000000..121f6a935d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-ary.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-ary.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Object binding pattern with "nested" array binding pattern not using initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +var callCount = 0; +async function* f({ w: [x, y, z] = [4, 5, 6] }) { + assert.sameValue(x, 7); + assert.sameValue(y, undefined); + assert.sameValue(z, undefined); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; +f({ w: [7, undefined, ] }).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-eval-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-eval-err.js new file mode 100644 index 0000000000..83da8522d1 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-eval-err.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-eval-err.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Evaluation of property name returns an abrupt completion (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.5 Runtime Semantics: BindingInitialization + + BindingProperty : PropertyName : BindingElement + + 1. Let P be the result of evaluating PropertyName + 2. ReturnIfAbrupt(P). +---*/ +function thrower() { + throw new Test262Error(); +} + + +async function* f({ [thrower()]: x }) { + +}; + +assert.throws(Test262Error, function() { + f({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-get-value-err.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-get-value-err.js new file mode 100644 index 0000000000..dbbae145d7 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-get-value-err.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-get-value-err.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Error thrown when accessing the corresponding property of the value object (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + 1. Let v be GetV(value, propertyName). + 2. ReturnIfAbrupt(v). +---*/ +var initEvalCount = 0; +var poisonedProperty = Object.defineProperty({}, 'poisoned', { + get: function() { + throw new Test262Error(); + } +}); + + +async function* f({ poisoned: x = ++initEvalCount }) { + +}; + +assert.throws(Test262Error, function() { + f(poisonedProperty); +}); + +assert.sameValue(initEvalCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init-skipped.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init-skipped.js new file mode 100644 index 0000000000..70d3ccd06c --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init-skipped.js @@ -0,0 +1,58 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-skipped.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Destructuring initializer is not evaluated when value is not `undefined` (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + [...] +---*/ +var initCount = 0; +function counter() { + initCount += 1; +} + + +var callCount = 0; +async function* f({ s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() }) { + assert.sameValue(t, null); + assert.sameValue(v, 0); + assert.sameValue(x, false); + assert.sameValue(z, ''); + assert.sameValue(initCount, 0); + + assert.throws(ReferenceError, function() { + s; + }); + assert.throws(ReferenceError, function() { + u; + }); + assert.throws(ReferenceError, function() { + w; + }); + assert.throws(ReferenceError, function() { + y; + }); + callCount = callCount + 1; +}; +f({ s: null, u: 0, w: false, y: '' }).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init-throws.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init-throws.js new file mode 100644 index 0000000000..eca60f73b4 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init-throws.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-throws.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Error thrown when evaluating the initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). +---*/ +function thrower() { + throw new Test262Error(); +} + + +async function* f({ x: y = thrower() }) { + +}; + +assert.throws(Test262Error, function() { + f({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init-unresolvable.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init-unresolvable.js new file mode 100644 index 0000000000..302e84b74c --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init-unresolvable.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init-unresolvable.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Destructuring initializer is an unresolvable reference (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + BindingElement : BindingPattern Initializeropt + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + + +async function* f({ x: y = unresolvableReference }) { + +}; + +assert.throws(ReferenceError, function() { + f({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init.js new file mode 100644 index 0000000000..f93d9daeb7 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-init.js @@ -0,0 +1,39 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-init.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Binding as specified via property name, identifier, and initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f({ x: y = 33 }) { + assert.sameValue(y, 33); + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; +f({ }).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-trailing-comma.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-trailing-comma.js new file mode 100644 index 0000000000..e938f19afc --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id-trailing-comma.js @@ -0,0 +1,40 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id-trailing-comma.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Trailing comma is allowed following BindingPropertyList (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3 Destructuring Binding Patterns + + ObjectBindingPattern[Yield] : + { } + { BindingPropertyList[?Yield] } + { BindingPropertyList[?Yield] , } +---*/ + + +var callCount = 0; +async function* f({ x: y, }) { + assert.sameValue(y, 23); + + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; +f({ x: 23 }).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id.js new file mode 100644 index 0000000000..e7aa455720 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-id.js @@ -0,0 +1,39 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-id.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Binding as specified via property name and identifier (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + SingleNameBinding : BindingIdentifier Initializeropt + + [...] + 8. Return InitializeReferencedBinding(lhs, v). +---*/ + + +var callCount = 0; +async function* f({ x: y }) { + assert.sameValue(y, 23); + assert.throws(ReferenceError, function() { + x; + }); + callCount = callCount + 1; +}; +f({ x: 23 }).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj-init.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj-init.js new file mode 100644 index 0000000000..b3afb6e80d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj-init.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-init.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Object binding pattern with "nested" object binding pattern using initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + a. Let defaultValue be the result of evaluating Initializer. + b. Let v be GetValue(defaultValue). + c. ReturnIfAbrupt(v). + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +var callCount = 0; +async function* f({ w: { x, y, z } = { x: 4, y: 5, z: 6 } }) { + assert.sameValue(x, 4); + assert.sameValue(y, 5); + assert.sameValue(z, 6); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; +f({ w: undefined }).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj-value-null.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj-value-null.js new file mode 100644 index 0000000000..7685385e43 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj-value-null.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-null.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +async function* f({ w: { x, y, z } = { x: 4, y: 5, z: 6 } }) { + +}; + +assert.throws(TypeError, function() { + f({ w: null }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj-value-undef.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj-value-undef.js new file mode 100644 index 0000000000..17a2359eaf --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj-value-undef.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj-value-undef.case +// - src/dstr-binding/error/async-gen-func-decl.template +/*--- +description: Object binding pattern with "nested" object binding pattern taking the `null` value (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +async function* f({ w: { x, y, z } = undefined }) { + +}; + +assert.throws(TypeError, function() { + f({ }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj.js new file mode 100644 index 0000000000..6656224cd8 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-prop-obj.js @@ -0,0 +1,43 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-prop-obj.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Object binding pattern with "nested" object binding pattern not using initializer (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.7 Runtime Semantics: KeyedBindingInitialization + + [...] + 3. If Initializer is present and v is undefined, then + [...] + 4. Return the result of performing BindingInitialization for BindingPattern + passing v and environment as arguments. +---*/ + + +var callCount = 0; +async function* f({ w: { x, y, z } = { x: 4, y: 5, z: 6 } }) { + assert.sameValue(x, undefined); + assert.sameValue(y, undefined); + assert.sameValue(z, 7); + + assert.throws(ReferenceError, function() { + w; + }); + callCount = callCount + 1; +}; +f({ w: { x: undefined, z: 7 } }).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-rest-getter.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-rest-getter.js new file mode 100644 index 0000000000..b68d00047c --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-rest-getter.js @@ -0,0 +1,38 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-getter.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Getter is called when obj is being deconstructed to a rest Object (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [object-rest, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + +---*/ +var count = 0; + + +var callCount = 0; +async function* f({...x}) { + assert.sameValue(count, 1); + + verifyProperty(x, "v", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + callCount = callCount + 1; +}; +f({ get v() { count++; return 2; } }).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-rest-skip-non-enumerable.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-rest-skip-non-enumerable.js new file mode 100644 index 0000000000..14ade21962 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-rest-skip-non-enumerable.js @@ -0,0 +1,46 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-skip-non-enumerable.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest object doesn't contain non-enumerable properties (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [object-rest, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + +---*/ +var o = {a: 3, b: 4}; +Object.defineProperty(o, "x", { value: 4, enumerable: false }); + + +var callCount = 0; +async function* f({...rest}) { + assert.sameValue(rest.x, undefined); + + verifyProperty(rest, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(rest, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 4 + }); + callCount = callCount + 1; +}; +f(o).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-rest-val-obj.js b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-rest-val-obj.js new file mode 100644 index 0000000000..60b6b9e206 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/obj-ptrn-rest-val-obj.js @@ -0,0 +1,45 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/dstr-binding/obj-ptrn-rest-val-obj.case +// - src/dstr-binding/default/async-gen-func-decl.template +/*--- +description: Rest object contains just unextracted data (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [object-rest, async-iteration] +flags: [generated, async] +includes: [propertyHelper.js] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + +---*/ + + +var callCount = 0; +async function* f({a, b, ...rest}) { + assert.sameValue(rest.a, undefined); + assert.sameValue(rest.b, undefined); + + verifyProperty(rest, "x", { + enumerable: true, + writable: true, + configurable: true, + value: 1 + }); + + verifyProperty(rest, "y", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + callCount = callCount + 1; +}; +f({x: 1, y: 2, a: 5, b: 3}).next().then(() => { + assert.sameValue(callCount, 1, 'invoked exactly once'); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/dstr/shell.js b/js/src/tests/test262/language/statements/async-generator/dstr/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/dstr/shell.js diff --git a/js/src/tests/test262/language/statements/async-generator/escaped-async.js b/js/src/tests/test262/language/statements/async-generator/escaped-async.js new file mode 100644 index 0000000000..953409edfd --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/escaped-async.js @@ -0,0 +1,25 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-grammar-notation +description: > + The `async` contextual keyword must not contain Unicode escape sequences. +info: | + Terminal symbols are shown + in fixed width font, both in the productions of the grammars and throughout this + specification whenever the text directly refers to such a terminal symbol. These + are to appear in a script exactly as written. All terminal symbol code points + specified in this way are to be understood as the appropriate Unicode code points + from the Basic Latin range, as opposed to any similar-looking code points from + other Unicode ranges. +negative: + phase: parse + type: SyntaxError +features: [async-iteration] +---*/ + +$DONOTEVALUATE(); + +\u0061sync function* f(){} diff --git a/js/src/tests/test262/language/statements/async-generator/eval-var-scope-syntax-err.js b/js/src/tests/test262/language/statements/async-generator/eval-var-scope-syntax-err.js new file mode 100644 index 0000000000..2711c015b4 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/eval-var-scope-syntax-err.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/function-forms/eval-var-scope-syntax-err.case +// - src/function-forms/error-no-strict/async-gen-func-decl.template +/*--- +description: sloppy direct eval in params introduces var (async generator function declaration in sloppy code) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [default-parameters, async-iteration] +flags: [generated, noStrict] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + + Runtime Semantics: IteratorBindingInitialization + FormalParameter : BindingElement + + 1. Return the result of performing IteratorBindingInitialization for BindingElement with arguments iteratorRecord and environment. + +---*/ + + +var callCount = 0; +async function* f(a = eval("var a = 42")) { + + callCount = callCount + 1; +} + +assert.throws(SyntaxError, function() { + f(); +}); + +assert.sameValue(callCount, 0, 'generator function body not evaluated'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/async-gen-func-decl-forbidden-ext-direct-access-prop-arguments.js b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/async-gen-func-decl-forbidden-ext-direct-access-prop-arguments.js new file mode 100644 index 0000000000..2fba1e4405 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/async-gen-func-decl-forbidden-ext-direct-access-prop-arguments.js @@ -0,0 +1,38 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/forbidden-ext-direct-access-prop-arguments.case +// - src/function-forms/forbidden-extensions/bullet-one/async-gen-func-decl.template +/*--- +description: Forbidden extension, f.arguments (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [arrow-function, async-functions, async-iteration] +flags: [generated, noStrict, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + + ECMAScript function objects defined using syntactic constructors in strict mode code must + not be created with own properties named "caller" or "arguments". Such own properties also + must not be created for function objects defined using an ArrowFunction, MethodDefinition, + GeneratorDeclaration, GeneratorExpression, AsyncGeneratorDeclaration, AsyncGeneratorExpression, + ClassDeclaration, ClassExpression, AsyncFunctionDeclaration, AsyncFunctionExpression, or + AsyncArrowFunction regardless of whether the definition is contained in strict mode code. + Built-in functions, strict functions created using the Function constructor, generator functions + created using the Generator constructor, async functions created using the AsyncFunction + constructor, and functions created using the bind method also must not be created with such own + properties. + +---*/ + + +var callCount = 0; +async function* f() { + assert.sameValue(f.hasOwnProperty("arguments"), false); + callCount++; +} + +f().next() + .then(() => { + assert.sameValue(callCount, 1, 'function body evaluated'); + }, $DONE).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/async-gen-func-decl-forbidden-ext-direct-access-prop-caller.js b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/async-gen-func-decl-forbidden-ext-direct-access-prop-caller.js new file mode 100644 index 0000000000..d791f45a6f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/async-gen-func-decl-forbidden-ext-direct-access-prop-caller.js @@ -0,0 +1,38 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/forbidden-ext-direct-access-prop-caller.case +// - src/function-forms/forbidden-extensions/bullet-one/async-gen-func-decl.template +/*--- +description: Forbidden extension, o.caller (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [arrow-function, async-functions, async-iteration] +flags: [generated, noStrict, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + + ECMAScript function objects defined using syntactic constructors in strict mode code must + not be created with own properties named "caller" or "arguments". Such own properties also + must not be created for function objects defined using an ArrowFunction, MethodDefinition, + GeneratorDeclaration, GeneratorExpression, AsyncGeneratorDeclaration, AsyncGeneratorExpression, + ClassDeclaration, ClassExpression, AsyncFunctionDeclaration, AsyncFunctionExpression, or + AsyncArrowFunction regardless of whether the definition is contained in strict mode code. + Built-in functions, strict functions created using the Function constructor, generator functions + created using the Generator constructor, async functions created using the AsyncFunction + constructor, and functions created using the bind method also must not be created with such own + properties. + +---*/ + + +var callCount = 0; +async function* f() { + assert.sameValue(f.hasOwnProperty("caller"), false); + callCount++; +} + +f().next() + .then(() => { + assert.sameValue(callCount, 1, 'function body evaluated'); + }, $DONE).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/browser.js b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/browser.js diff --git a/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/shell.js b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b1/shell.js diff --git a/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/async-gen-func-decl-forbidden-ext-indirect-access-own-prop-caller-get.js b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/async-gen-func-decl-forbidden-ext-indirect-access-own-prop-caller-get.js new file mode 100644 index 0000000000..c662810e41 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/async-gen-func-decl-forbidden-ext-indirect-access-own-prop-caller-get.js @@ -0,0 +1,64 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/forbidden-ext-indirect-access-own-prop-caller-get.case +// - src/function-forms/forbidden-extensions/bullet-two/async-gen-func-decl.template +/*--- +description: Forbidden extension, o.caller (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [arrow-function, async-functions, async-iteration] +flags: [generated, noStrict, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + + If an implementation extends any function object with an own property named "caller" the value of + that property, as observed using [[Get]] or [[GetOwnProperty]], must not be a strict function + object. If it is an accessor property, the function that is the value of the property's [[Get]] + attribute must never return a strict function when called. + +---*/ +var CALLER_OWN_PROPERTY_DOES_NOT_EXIST = Symbol(); +function inner() { + // This property may exist, but is forbidden from having a value that is a strict function object + return inner.hasOwnProperty("caller") + ? inner.caller + : CALLER_OWN_PROPERTY_DOES_NOT_EXIST; +} + + +var callCount = 0; +async function* f() { + "use strict"; + // This and the following conditional value is set in the test's .case file. + // For every test that has a "true" value here, there is a + // corresponding test that has a "false" value here. + // They are generated from two different case files, which use + // the same templates. + let descriptor = Object.getOwnPropertyDescriptor(inner, "caller"); + if (descriptor && descriptor.configurable && true) { + Object.defineProperty(inner, "caller", {get(){return 1}}); + } + var result = inner(); + if (descriptor && descriptor.configurable && true) { + assert.sameValue(result, 1, 'If this test defined an own "caller" property on the inner function, then it should be accessible and should return the value it was set to.'); + } + // "CALLER_OWN_PROPERTY_DOES_NOT_EXIST" is from + // forbidden-ext-indirect-access-prop-caller.case + // + // If the function object "inner" has an own property + // named "caller", then its value will be returned. + // + // If the function object "inner" DOES NOT have an + // own property named "caller", then the symbol + // CALLER_OWN_PROPERTY_DOES_NOT_EXIST will be returned. + if (result !== CALLER_OWN_PROPERTY_DOES_NOT_EXIST) { + assert.notSameValue(result, f); + } + callCount++; +} + +f().next() + .then(() => { + assert.sameValue(callCount, 1, 'function body evaluated'); + }, $DONE).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/async-gen-func-decl-forbidden-ext-indirect-access-own-prop-caller-value.js b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/async-gen-func-decl-forbidden-ext-indirect-access-own-prop-caller-value.js new file mode 100644 index 0000000000..d6e06a187c --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/async-gen-func-decl-forbidden-ext-indirect-access-own-prop-caller-value.js @@ -0,0 +1,64 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/forbidden-ext-indirect-access-own-prop-caller-value.case +// - src/function-forms/forbidden-extensions/bullet-two/async-gen-func-decl.template +/*--- +description: Forbidden extension, o.caller (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [arrow-function, async-functions, async-iteration] +flags: [generated, noStrict, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + + If an implementation extends any function object with an own property named "caller" the value of + that property, as observed using [[Get]] or [[GetOwnProperty]], must not be a strict function + object. If it is an accessor property, the function that is the value of the property's [[Get]] + attribute must never return a strict function when called. + +---*/ +var CALLER_OWN_PROPERTY_DOES_NOT_EXIST = Symbol(); +function inner() { + // This property may exist, but is forbidden from having a value that is a strict function object + return inner.hasOwnProperty("caller") + ? inner.caller + : CALLER_OWN_PROPERTY_DOES_NOT_EXIST; +} + + +var callCount = 0; +async function* f() { + "use strict"; + // This and the following conditional value is set in the test's .case file. + // For every test that has a "true" value here, there is a + // corresponding test that has a "false" value here. + // They are generated from two different case files, which use + // the same templates. + let descriptor = Object.getOwnPropertyDescriptor(inner, "caller"); + if (descriptor && descriptor.configurable && true) { + Object.defineProperty(inner, "caller", {value: 1}); + } + var result = inner(); + if (descriptor && descriptor.configurable && true) { + assert.sameValue(result, 1, 'If this test defined an own "caller" property on the inner function, then it should be accessible and should return the value it was set to.'); + } + // "CALLER_OWN_PROPERTY_DOES_NOT_EXIST" is from + // forbidden-ext-indirect-access-prop-caller.case + // + // If the function object "inner" has an own property + // named "caller", then its value will be returned. + // + // If the function object "inner" DOES NOT have an + // own property named "caller", then the symbol + // CALLER_OWN_PROPERTY_DOES_NOT_EXIST will be returned. + if (result !== CALLER_OWN_PROPERTY_DOES_NOT_EXIST) { + assert.notSameValue(result, f); + } + callCount++; +} + +f().next() + .then(() => { + assert.sameValue(callCount, 1, 'function body evaluated'); + }, $DONE).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/async-gen-func-decl-forbidden-ext-indirect-access-prop-caller.js b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/async-gen-func-decl-forbidden-ext-indirect-access-prop-caller.js new file mode 100644 index 0000000000..e6de8ef013 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/async-gen-func-decl-forbidden-ext-indirect-access-prop-caller.js @@ -0,0 +1,64 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/forbidden-ext-indirect-access-prop-caller.case +// - src/function-forms/forbidden-extensions/bullet-two/async-gen-func-decl.template +/*--- +description: Forbidden extension, o.caller (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [arrow-function, async-functions, async-iteration] +flags: [generated, noStrict, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + + If an implementation extends any function object with an own property named "caller" the value of + that property, as observed using [[Get]] or [[GetOwnProperty]], must not be a strict function + object. If it is an accessor property, the function that is the value of the property's [[Get]] + attribute must never return a strict function when called. + +---*/ +var CALLER_OWN_PROPERTY_DOES_NOT_EXIST = Symbol(); +function inner() { + // This property may exist, but is forbidden from having a value that is a strict function object + return inner.hasOwnProperty("caller") + ? inner.caller + : CALLER_OWN_PROPERTY_DOES_NOT_EXIST; +} + + +var callCount = 0; +async function* f() { + "use strict"; + // This and the following conditional value is set in the test's .case file. + // For every test that has a "true" value here, there is a + // corresponding test that has a "false" value here. + // They are generated from two different case files, which use + // the same templates. + let descriptor = Object.getOwnPropertyDescriptor(inner, "caller"); + if (descriptor && descriptor.configurable && false) { + Object.defineProperty(inner, "caller", {}); + } + var result = inner(); + if (descriptor && descriptor.configurable && false) { + assert.sameValue(result, 1, 'If this test defined an own "caller" property on the inner function, then it should be accessible and should return the value it was set to.'); + } + // "CALLER_OWN_PROPERTY_DOES_NOT_EXIST" is from + // forbidden-ext-indirect-access-prop-caller.case + // + // If the function object "inner" has an own property + // named "caller", then its value will be returned. + // + // If the function object "inner" DOES NOT have an + // own property named "caller", then the symbol + // CALLER_OWN_PROPERTY_DOES_NOT_EXIST will be returned. + if (result !== CALLER_OWN_PROPERTY_DOES_NOT_EXIST) { + assert.notSameValue(result, f); + } + callCount++; +} + +f().next() + .then(() => { + assert.sameValue(callCount, 1, 'function body evaluated'); + }, $DONE).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/browser.js b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/browser.js diff --git a/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/shell.js b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/b2/shell.js diff --git a/js/src/tests/test262/language/statements/async-generator/forbidden-ext/browser.js b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/browser.js diff --git a/js/src/tests/test262/language/statements/async-generator/forbidden-ext/shell.js b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/forbidden-ext/shell.js diff --git a/js/src/tests/test262/language/statements/async-generator/generator-created-after-decl-inst.js b/js/src/tests/test262/language/statements/async-generator/generator-created-after-decl-inst.js new file mode 100644 index 0000000000..403a0b70fc --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/generator-created-after-decl-inst.js @@ -0,0 +1,26 @@ +// Copyright (C) 2018 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-asyncgenerator-definitions-evaluatebody +description: > + The generator object is created after FunctionDeclarationInstantiation. +info: | + 14.5.10 Runtime Semantics: EvaluateBody + + 1. Perform ? FunctionDeclarationInstantiation(functionObject, argumentsList). + 2. Let generator be ? OrdinaryCreateFromConstructor(functionObject, "%AsyncGeneratorPrototype%", + « [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]] »). + 3. Perform ! AsyncGeneratorStart(generator, FunctionBody). + ... + +features: [async-iteration] +---*/ + +async function* g(a = (g.prototype = null)) {} +var oldPrototype = g.prototype; +var it = g(); + +assert.notSameValue(Object.getPrototypeOf(it), oldPrototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/async-generator/object-destructuring-param-strict-body.js b/js/src/tests/test262/language/statements/async-generator/object-destructuring-param-strict-body.js new file mode 100644 index 0000000000..cf3968ee69 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/object-destructuring-param-strict-body.js @@ -0,0 +1,113 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/object-destructuring-param-strict-body.case +// - src/function-forms/syntax/async-gen-func-decl.template +/*--- +description: ObjectBindingPattern and Use Strict Directive are not allowed to coexist for the same function. (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [rest-parameters, async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 13.3.3.4 Static Semantics: IsSimpleParameterList + + BindingElement : BindingPattern + + 1. Return false. + + 14.1.2 Static Semantics: Early Errors + + FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } + FunctionDeclaration : function ( FormalParameters ) { FunctionBody } + FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.2.1 Static Semantics: Early Errors + + ArrowFunction : ArrowParameters => ConciseBody + + - It is a Syntax Error if ContainsUseStrict of ConciseBody is true and + IsSimpleParameterList of ArrowParameters is false. + + 14.3.1 Static Semantics: Early Errors + + MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of PropertySetParameterList is false. + + 14.4.1 Static Semantics: Early Errors + + GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody } + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + 14.5.1 Static Semantics: Early Errors + + AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.7.1 Static Semantics: Early Errors + + AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.8.1 Static Semantics: Early Errors + + AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody + + - It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is true and + IsSimpleParameterList of CoverCallExpressionAndAsyncArrowHead is false. + +---*/ +$DONOTEVALUATE(); + + +async function* f({property}) { + "use strict"; +} diff --git a/js/src/tests/test262/language/statements/async-generator/params-trailing-comma-multiple.js b/js/src/tests/test262/language/statements/async-generator/params-trailing-comma-multiple.js new file mode 100644 index 0000000000..6bd7572487 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/params-trailing-comma-multiple.js @@ -0,0 +1,40 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/params-trailing-comma-multiple.case +// - src/function-forms/default/async-gen-func-decl.template +/*--- +description: A trailing comma should not increase the respective length, using multiple parameters (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + Trailing comma in the parameters list + + 14.1 Function Definitions + + FormalParameters[Yield, Await] : FormalParameterList[?Yield, ?Await] , +---*/ + + +var callCount = 0; +// Stores a reference `ref` for case evaluation +async function* ref(a, b,) { + assert.sameValue(a, 42); + assert.sameValue(b, 39); + callCount = callCount + 1; +} + +ref(42, 39, 1).next().then(() => { + assert.sameValue(callCount, 1, 'generator function invoked exactly once'); +}).then($DONE, $DONE); + +assert.sameValue(ref.length, 2, 'length is properly set'); diff --git a/js/src/tests/test262/language/statements/async-generator/params-trailing-comma-single.js b/js/src/tests/test262/language/statements/async-generator/params-trailing-comma-single.js new file mode 100644 index 0000000000..073dab2edb --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/params-trailing-comma-single.js @@ -0,0 +1,39 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/params-trailing-comma-single.case +// - src/function-forms/default/async-gen-func-decl.template +/*--- +description: A trailing comma should not increase the respective length, using a single parameter (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + Trailing comma in the parameters list + + 14.1 Function Definitions + + FormalParameters[Yield, Await] : FormalParameterList[?Yield, ?Await] , +---*/ + + +var callCount = 0; +// Stores a reference `ref` for case evaluation +async function* ref(a,) { + assert.sameValue(a, 42); + callCount = callCount + 1; +} + +ref(42, 39).next().then(() => { + assert.sameValue(callCount, 1, 'generator function invoked exactly once'); +}).then($DONE, $DONE); + +assert.sameValue(ref.length, 1, 'length is properly set'); diff --git a/js/src/tests/test262/language/statements/async-generator/rest-param-strict-body.js b/js/src/tests/test262/language/statements/async-generator/rest-param-strict-body.js new file mode 100644 index 0000000000..5ea01c0c44 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/rest-param-strict-body.js @@ -0,0 +1,113 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/rest-param-strict-body.case +// - src/function-forms/syntax/async-gen-func-decl.template +/*--- +description: RestParameter and Use Strict Directive are not allowed to coexist for the same function. (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [rest-parameters, async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + 14.1.13 Static Semantics: IsSimpleParameterList + + FormalParameters : FormalParameterList , FunctionRestParameter + + 1. Return false. + + 14.1.2 Static Semantics: Early Errors + + FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } + FunctionDeclaration : function ( FormalParameters ) { FunctionBody } + FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.2.1 Static Semantics: Early Errors + + ArrowFunction : ArrowParameters => ConciseBody + + - It is a Syntax Error if ContainsUseStrict of ConciseBody is true and + IsSimpleParameterList of ArrowParameters is false. + + 14.3.1 Static Semantics: Early Errors + + MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody } + + - It is a Syntax Error if ContainsUseStrict of FunctionBody is true and + IsSimpleParameterList of PropertySetParameterList is false. + + 14.4.1 Static Semantics: Early Errors + + GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody } + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of GeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + 14.5.1 Static Semantics: Early Errors + + AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody } + AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncGeneratorBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.7.1 Static Semantics: Early Errors + + AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of UniqueFormalParameters is false. + + AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody } + AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } + + - It is a Syntax Error if ContainsUseStrict of AsyncFunctionBody is true and + IsSimpleParameterList of FormalParameters is false. + + 14.8.1 Static Semantics: Early Errors + + AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody + + - It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is true and + IsSimpleParameterList of CoverCallExpressionAndAsyncArrowHead is false. + +---*/ +$DONOTEVALUATE(); + + +async function* f(a,...rest) { + "use strict"; +} diff --git a/js/src/tests/test262/language/statements/async-generator/rest-params-trailing-comma-early-error.js b/js/src/tests/test262/language/statements/async-generator/rest-params-trailing-comma-early-error.js new file mode 100644 index 0000000000..758af25e8b --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/rest-params-trailing-comma-early-error.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/function-forms/rest-params-trailing-comma-early-error.case +// - src/function-forms/syntax/async-gen-func-decl.template +/*--- +description: It's a syntax error if a FunctionRestParameter is followed by a trailing comma (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + Trailing comma in the parameters list + + 14.1 Function Definitions + + FormalParameters[Yield, Await] : + [empty] + FunctionRestParameter[?Yield, ?Await] + FormalParameterList[?Yield, ?Await] + FormalParameterList[?Yield, ?Await] , + FormalParameterList[?Yield, ?Await] , FunctionRestParameter[?Yield, ?Await] +---*/ +$DONOTEVALUATE(); + + +async function* f(...a,) { + +} diff --git a/js/src/tests/test262/language/statements/async-generator/return-undefined-implicit-and-explicit.js b/js/src/tests/test262/language/statements/async-generator/return-undefined-implicit-and-explicit.js new file mode 100644 index 0000000000..75bc5dd2d1 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/return-undefined-implicit-and-explicit.js @@ -0,0 +1,81 @@ +// |reftest| async +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-return-statement-runtime-semantics-evaluation +description: > + Return with an explicit return value awaits this value. +info: | + 13.10.1 Runtime Semantics: Evaluation + + ReturnStatement : return; + 1. Return Completion { [[Type]]: return, [[Value]]: undefined, [[Target]]: empty }. + + ReturnStatement : return Expression ; + 1. Let exprRef be the result of evaluating Expression. + 2. Let exprValue be ? GetValue(exprRef). + 3. If ! GetGeneratorKind() is async, set exprValue to ? Await(exprValue). + 4. Return Completion { [[Type]]: return, [[Value]]: exprValue, [[Target]]: empty }. + + 25.5.3.2 AsyncGeneratorStart ( generator, generatorBody ) + + ... + 5. Set the code evaluation state of genContext such that when evaluation is resumed for that + execution context the following steps will be performed: + a. Let result be the result of evaluating generatorBody. + ... + e. If result is a normal completion, let resultValue be undefined. + ... + g. Return ! AsyncGeneratorResolve(generator, resultValue, true). + +includes: [compareArray.js] +flags: [async] +features: [async-iteration] +---*/ + +// 25.5.3.2, step 5.e: |generatorBody| execution ends with a normal completion. +async function* g1() { + // no return +} + +// 13.10.1: No expression form means direct return. +async function* g2() { + return; +} + +// 13.10.1: Explicit expression requires Await. +async function* g3() { + return undefined; // Return undefined via global value `undefined`. +} + +// 13.10.1: Explicit expression requires Await. +async function* g4() { + return void 0; // Return undefined via void expression. +} + +var expected = [ + "tick 1", + + "g1 ret", + "g2 ret", + + "tick 2", + + "g3 ret", + "g4 ret", +]; + +var actual = []; + +Promise.resolve(0) + .then(() => actual.push("tick 1")) + .then(() => actual.push("tick 2")) + .then(() => { + assert.compareArray(actual, expected, "Ticks for implicit and explicit return undefined"); +}).then($DONE, $DONE); + +g1().next().then(v => actual.push("g1 ret")); +g2().next().then(v => actual.push("g2 ret")); +g3().next().then(v => actual.push("g3 ret")); +g4().next().then(v => actual.push("g4 ret")); diff --git a/js/src/tests/test262/language/statements/async-generator/shell.js b/js/src/tests/test262/language/statements/async-generator/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/shell.js diff --git a/js/src/tests/test262/language/statements/async-generator/unscopables-with-in-nested-fn.js b/js/src/tests/test262/language/statements/async-generator/unscopables-with-in-nested-fn.js new file mode 100644 index 0000000000..7c63a23776 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/unscopables-with-in-nested-fn.js @@ -0,0 +1,82 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/unscopables-with-in-nested-fn.case +// - src/function-forms/default/async-gen-func-decl.template +/*--- +description: Symbol.unscopables behavior across scope boundaries (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [globalThis, Symbol.unscopables, async-iteration] +flags: [generated, noStrict, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + ... + Let envRec be lex's EnvironmentRecord. + Let exists be ? envRec.HasBinding(name). + + HasBinding + + ... + If the withEnvironment flag of envRec is false, return true. + Let unscopables be ? Get(bindings, @@unscopables). + If Type(unscopables) is Object, then + Let blocked be ToBoolean(? Get(unscopables, N)). + If blocked is true, return false. + + (The `with` Statement) Runtime Semantics: Evaluation + + ... + Set the withEnvironment flag of newEnv’s EnvironmentRecord to true. + ... + +---*/ +let count = 0; +var v = 1; +globalThis[Symbol.unscopables] = { + v: true, +}; + +{ + count++; + + +var callCount = 0; +// Stores a reference `ref` for case evaluation +async function* ref(x) { + (function() { + count++; + with (globalThis) { + count++; + assert.sameValue(v, 1, 'The value of `v` is 1'); + } + })(); + (function() { + count++; + var v = x; + with (globalThis) { + count++; + assert.sameValue(v, 10, 'The value of `v` is 10'); + v = 20; + } + assert.sameValue(v, 20, 'The value of `v` is 20'); + assert.sameValue(globalThis.v, 1, 'The value of globalThis.v is 1'); + })(); + assert.sameValue(v, 1, 'The value of `v` is 1'); + assert.sameValue(globalThis.v, 1, 'The value of globalThis.v is 1'); + callCount = callCount + 1; +} + +ref(10).next().then(() => { + assert.sameValue(callCount, 1, 'generator function invoked exactly once'); +}).then($DONE, $DONE); + + count++; +} +assert.sameValue(count, 6, 'The value of `count` is 6'); diff --git a/js/src/tests/test262/language/statements/async-generator/unscopables-with.js b/js/src/tests/test262/language/statements/async-generator/unscopables-with.js new file mode 100644 index 0000000000..791c40315f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/unscopables-with.js @@ -0,0 +1,76 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/function-forms/unscopables-with.case +// - src/function-forms/default/async-gen-func-decl.template +/*--- +description: Symbol.unscopables behavior across scope boundaries (async generator function declaration) +esid: sec-asyncgenerator-definitions-instantiatefunctionobject +features: [globalThis, Symbol.unscopables, async-iteration] +flags: [generated, noStrict, async] +info: | + AsyncGeneratorDeclaration : async [no LineTerminator here] function * BindingIdentifier + ( FormalParameters ) { AsyncGeneratorBody } + + [...] + 3. Let F be ! AsyncGeneratorFunctionCreate(Normal, FormalParameters, AsyncGeneratorBody, + scope, strict). + [...] + + + ... + Let envRec be lex's EnvironmentRecord. + Let exists be ? envRec.HasBinding(name). + + HasBinding + + ... + If the withEnvironment flag of envRec is false, return true. + Let unscopables be ? Get(bindings, @@unscopables). + If Type(unscopables) is Object, then + Let blocked be ToBoolean(? Get(unscopables, N)). + If blocked is true, return false. + + (The `with` Statement) Runtime Semantics: Evaluation + + ... + Set the withEnvironment flag of newEnv’s EnvironmentRecord to true. + ... + +---*/ +let count = 0; +var v = 1; +globalThis[Symbol.unscopables] = { + v: true, +}; + +{ + count++; + + +var callCount = 0; +// Stores a reference `ref` for case evaluation +async function* ref(x) { + count++; + with (globalThis) { + count++; + assert.sameValue(v, undefined, 'The value of `v` is expected to equal `undefined`'); + } + count++; + var v = x; + with (globalThis) { + count++; + assert.sameValue(v, 10, 'The value of `v` is 10'); + v = 20; + } + assert.sameValue(v, 20, 'The value of `v` is 20'); + assert.sameValue(globalThis.v, 1, 'The value of globalThis.v is 1'); + callCount = callCount + 1; +} + +ref(10).next().then(() => { + assert.sameValue(callCount, 1, 'generator function invoked exactly once'); +}).then($DONE, $DONE); + + count++; +} +assert.sameValue(count, 6, 'The value of `count` is 6'); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-as-binding-identifier-escaped.js b/js/src/tests/test262/language/statements/async-generator/yield-as-binding-identifier-escaped.js new file mode 100644 index 0000000000..866f682069 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-as-binding-identifier-escaped.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-as-binding-identifier-escaped.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a binding identifier. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + BindingIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + var yi\u0065ld; +} diff --git a/js/src/tests/test262/language/statements/async-generator/yield-as-binding-identifier.js b/js/src/tests/test262/language/statements/async-generator/yield-as-binding-identifier.js new file mode 100644 index 0000000000..8351c65c5d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-as-binding-identifier.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-as-binding-identifier.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a binding identifier. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + BindingIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + var yield; +} diff --git a/js/src/tests/test262/language/statements/async-generator/yield-as-identifier-reference-escaped.js b/js/src/tests/test262/language/statements/async-generator/yield-as-identifier-reference-escaped.js new file mode 100644 index 0000000000..951a7741b2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-as-identifier-reference-escaped.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-as-identifier-reference-escaped.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as an identifier reference. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + IdentifierReference : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + void yi\u0065ld; +} diff --git a/js/src/tests/test262/language/statements/async-generator/yield-as-identifier-reference.js b/js/src/tests/test262/language/statements/async-generator/yield-as-identifier-reference.js new file mode 100644 index 0000000000..db16bf85e6 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-as-identifier-reference.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-as-identifier-reference.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as an identifier reference. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + IdentifierReference : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + void yield; +} diff --git a/js/src/tests/test262/language/statements/async-generator/yield-as-label-identifier-escaped.js b/js/src/tests/test262/language/statements/async-generator/yield-as-label-identifier-escaped.js new file mode 100644 index 0000000000..a523fed8c9 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-as-label-identifier-escaped.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-as-label-identifier-escaped.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a label identifier. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + LabelIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + yi\u0065ld: ; +} diff --git a/js/src/tests/test262/language/statements/async-generator/yield-as-label-identifier.js b/js/src/tests/test262/language/statements/async-generator/yield-as-label-identifier.js new file mode 100644 index 0000000000..78cbbb63ee --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-as-label-identifier.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-as-label-identifier.case +// - src/async-generators/syntax/async-declaration.template +/*--- +description: yield is a reserved keyword within generator function bodies and may not be used as a label identifier. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + LabelIdentifier : Identifier + + It is a Syntax Error if this production has a [Yield] parameter and + StringValue of Identifier is "yield". + +---*/ +$DONOTEVALUATE(); + + +async function *gen() { + yield: ; +} diff --git a/js/src/tests/test262/language/statements/async-generator/yield-identifier-non-strict.js b/js/src/tests/test262/language/statements/async-generator/yield-identifier-non-strict.js new file mode 100644 index 0000000000..d1d4c66c8d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-identifier-non-strict.js @@ -0,0 +1,46 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-identifier-non-strict.case +// - src/async-generators/non-strict/async-declaration.template +/*--- +description: Use of yield as a valid identifier in a function body inside a generator body in non strict mode (Async generator function declaration - valid for non-strict only cases) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated, noStrict, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + +---*/ + + +var callCount = 0; + +async function *gen() { + callCount += 1; + return (function(arg) { + var yield = arg + 1; + return yield; + }(yield)) +} + +var iter = gen(); + +var item = iter.next(); + +item.then(({ done, value }) => { + assert.sameValue(done, false); + assert.sameValue(value, undefined); +}); + +item = iter.next(42); + +item.then(({ done, value }) => { + assert.sameValue(done, true); + assert.sameValue(value, 43); +}).then($DONE, $DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-identifier-spread-non-strict.js b/js/src/tests/test262/language/statements/async-generator/yield-identifier-spread-non-strict.js new file mode 100644 index 0000000000..ef3a5bcef0 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-identifier-spread-non-strict.js @@ -0,0 +1,64 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-identifier-spread-non-strict.case +// - src/async-generators/non-strict/async-declaration.template +/*--- +description: Mixed use of object spread and yield as a valid identifier in a function body inside a generator body in non strict mode (Async generator function declaration - valid for non-strict only cases) +esid: prod-AsyncGeneratorDeclaration +features: [object-spread, Symbol, async-iteration] +flags: [generated, noStrict, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] + +---*/ +var s = Symbol('s'); + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield { + ...yield yield, + ...(function(arg) { + var yield = arg; + return {...yield}; + }(yield)), + ...yield, + } +} + +var iter = gen(); + +var iter = gen(); + +iter.next(); +iter.next(); +iter.next({ x: 10, a: 0, b: 0, [s]: 1 }); +iter.next({ y: 20, a: 1, b: 1, [s]: 42 }); +var item = iter.next({ z: 30, b: 2 }); + +item.then(({ done, value }) => { + assert.sameValue(done, false); + assert.sameValue(value.x, 10); + assert.sameValue(value.y, 20); + assert.sameValue(value.z, 30); + assert.sameValue(value.a, 1); + assert.sameValue(value.b, 2); + assert.sameValue(value[s], 42); + assert.sameValue(Object.keys(value).length, 5); + assert(Object.prototype.hasOwnProperty.call(value, s), "s is an own property"); +}).then($DONE, $DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-identifier-spread-strict-strict.js b/js/src/tests/test262/language/statements/async-generator/yield-identifier-spread-strict-strict.js new file mode 100644 index 0000000000..fd6e9a2fd8 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-identifier-spread-strict-strict.js @@ -0,0 +1,48 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-identifier-spread-strict.case +// - src/async-generators/default/async-declaration.template +/*--- +description: It's an early error if the AssignmentExpression is a function body with yield as an identifier in strict mode. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [object-spread, async-iteration] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] + +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; + +async function *gen() { + callCount += 1; + return { + ...(function() { + var yield; + throw new Test262Error(); + }()), + } +} + +var iter = gen(); + + + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-identifier-strict-strict.js b/js/src/tests/test262/language/statements/async-generator/yield-identifier-strict-strict.js new file mode 100644 index 0000000000..76ce9ef46d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-identifier-strict-strict.js @@ -0,0 +1,39 @@ +// |reftest| error:SyntaxError +'use strict'; +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-identifier-strict.case +// - src/async-generators/default/async-declaration.template +/*--- +description: It's an early error if the generator body has another function body with yield as an identifier in strict mode. (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated, onlyStrict] +negative: + phase: parse + type: SyntaxError +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + +---*/ +$DONOTEVALUATE(); + + +var callCount = 0; + +async function *gen() { + callCount += 1; + (function() { + var yield; + throw new Test262Error(); + }()) +} + +var iter = gen(); + + + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-catch.js b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-catch.js new file mode 100644 index 0000000000..c215587a00 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-catch.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-promise-reject-next-catch.case +// - src/async-generators/default/async-declaration.template +/*--- +description: yield Promise.reject(value) is treated as throw value (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + +---*/ +let error = new Error(); + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield Promise.reject(error); + yield "unreachable"; +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error("Promise incorrectly resolved."); +}).catch(rejectValue => { + // yield Promise.reject(error); + assert.sameValue(rejectValue, error); + + iter.next().then(({done, value}) => { + // iter is closed now. + assert.sameValue(done, true, "The value of IteratorResult.done is `true`"); + assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`"); + }).then($DONE, $DONE); +}); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-for-await-of-async-iterator.js b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-for-await-of-async-iterator.js new file mode 100644 index 0000000000..19d00d022f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-for-await-of-async-iterator.js @@ -0,0 +1,50 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-promise-reject-next-for-await-of-async-iterator.case +// - src/async-generators/default/async-declaration.template +/*--- +description: yield * [Promise.reject(value)] is treated as throw value (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + +---*/ +let error = new Error(); +async function * readFile() { + yield Promise.reject(error); + yield "unreachable"; +} + + +var callCount = 0; + +async function *gen() { + callCount += 1; + for await (let line of readFile()) { + yield line; + } +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error("Promise incorrectly resolved."); +}, rejectValue => { + + // yield Promise.reject(error); + assert.sameValue(rejectValue, error); + + iter.next().then(({done, value}) => { + // iter is closed now. + assert.sameValue(done, true, "The value of IteratorResult.done is `true`"); + assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-for-await-of-sync-iterator.js b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-for-await-of-sync-iterator.js new file mode 100644 index 0000000000..fa67f67422 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-for-await-of-sync-iterator.js @@ -0,0 +1,49 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-promise-reject-next-for-await-of-sync-iterator.case +// - src/async-generators/default/async-declaration.template +/*--- +description: yield Promise.reject(value) in for-await-of is treated as throw value (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + +---*/ +let error = new Error(); +let iterable = [ + Promise.reject(error), + "unreachable" +]; + + +var callCount = 0; + +async function *gen() { + callCount += 1; + for await (let value of iterable) { + yield value; + } +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error("Promise incorrectly resolved."); +}, rejectValue => { + // yield Promise.reject(error); + assert.sameValue(rejectValue, error); + + iter.next().then(({done, value}) => { + // iter is closed now. + assert.sameValue(done, true, "The value of IteratorResult.done is `true`"); + assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-yield-star-async-iterator.js b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-yield-star-async-iterator.js new file mode 100644 index 0000000000..5c9d76f588 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-yield-star-async-iterator.js @@ -0,0 +1,48 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-promise-reject-next-yield-star-async-iterator.case +// - src/async-generators/default/async-declaration.template +/*--- +description: yield * (async iterator) is treated as throw value (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + +---*/ +let error = new Error(); +async function * readFile() { + yield Promise.reject(error); + yield "unreachable"; +} + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield * readFile(); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error("Promise incorrectly resolved."); +}, rejectValue => { + // yield Promise.reject(error); + assert.sameValue(rejectValue, error); + + iter.next().then(({done, value}) => { + // iter is closed now. + assert.sameValue(done, true, "The value of IteratorResult.done is `true`"); + assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`"); + }).then($DONE, $DONE); +}, $DONE).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-yield-star-sync-iterator.js b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-yield-star-sync-iterator.js new file mode 100644 index 0000000000..d1833caa7e --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next-yield-star-sync-iterator.js @@ -0,0 +1,47 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-promise-reject-next-yield-star-sync-iterator.case +// - src/async-generators/default/async-declaration.template +/*--- +description: yield * (async iterator) is treated as throw value (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + +---*/ +let error = new Error(); +let iterable = [ + Promise.reject(error), + "unreachable" +]; + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield * iterable; +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error("Promise incorrectly resolved."); +}, rejectValue => { + // yield Promise.reject(error); + assert.sameValue(rejectValue, error); + + iter.next().then(({done, value}) => { + // iter is closed now. + assert.sameValue(done, true, "The value of IteratorResult.done is `true`"); + assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next.js b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next.js new file mode 100644 index 0000000000..f4972beae6 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-promise-reject-next.js @@ -0,0 +1,44 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-promise-reject-next.case +// - src/async-generators/default/async-declaration.template +/*--- +description: yield Promise.reject(value) is treated as throw value (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + +---*/ +let error = new Error(); + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield Promise.reject(error); + yield "unreachable"; +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error("Promise incorrectly resolved."); +}, rejectValue => { + // yield Promise.reject(error); + assert.sameValue(rejectValue, error); + + iter.next().then(({done, value}) => { + // iter is closed now. + assert.sameValue(done, true, "The value of IteratorResult.done is `true`"); + assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-return-then-getter-ticks.js b/js/src/tests/test262/language/statements/async-generator/yield-return-then-getter-ticks.js new file mode 100644 index 0000000000..2a3b580a91 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-return-then-getter-ticks.js @@ -0,0 +1,105 @@ +// |reftest| async +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: > + Return resumption value is awaited upon and hence is treated as a thenable. +info: | + 14.4.14 Runtime Semantics: Evaluation + YieldExpression : yield AssignmentExpression + + ... + 3. Let value be ? GetValue(exprRef). + 4. If generatorKind is async, then return ? AsyncGeneratorYield(value). + ... + + 25.5.3.7 AsyncGeneratorYield ( value ) + ... + 5. Set value to ? Await(value). + ... + 8. Set the code evaluation state of genContext such that when evaluation is resumed with a + Completion resumptionValue the following steps will be performed: + ... + b. Let awaited be Await(resumptionValue.[[Value]]). + ... + e. Return Completion { [[Type]]: return, [[Value]]: awaited.[[Value]], [[Target]]: empty }. + ... + + 6.2.3.1 Await + ... + 2. Let promise be ? PromiseResolve(%Promise%, « value »). + ... + + 25.6.4.5.1 PromiseResolve ( C, x ) + ... + 3. Let promiseCapability be ? NewPromiseCapability(C). + 4. Perform ? Call(promiseCapability.[[Resolve]], undefined, « x »). + ... + + 25.6.1.5 NewPromiseCapability ( C ) + ... + 7. Let promise be ? Construct(C, « executor »). + ... + + 25.6.3.1 Promise ( executor ) + ... + 8. Let resolvingFunctions be CreateResolvingFunctions(promise). + ... + + 25.6.1.3 CreateResolvingFunctions ( promise ) + ... + 2. Let stepsResolve be the algorithm steps defined in Promise Resolve Functions (25.6.1.3.2). + 3. Let resolve be CreateBuiltinFunction(stepsResolve, « [[Promise]], [[AlreadyResolved]] »). + ... + + 25.6.1.3.2 Promise Resolve Functions + ... + 9. Let then be Get(resolution, "then"). + ... + +includes: [compareArray.js] +flags: [async] +features: [async-iteration] +---*/ + +var expected = [ + "start", + + // `Await(value)` promise resolved. + "tick 1", + + // "then" of `resumptionValue.[[Value]]` accessed. + "get then", + + // `Await(resumptionValue.[[Value]])` promise resolved. + "tick 2", +]; + +var actual = []; + +async function* f() { + actual.push("start"); + yield 123; + actual.push("stop - never reached"); +} + +Promise.resolve(0) + .then(() => actual.push("tick 1")) + .then(() => actual.push("tick 2")) + .then(() => { + assert.compareArray(actual, expected, "Ticks for return with thenable getter"); +}).then($DONE, $DONE); + +var it = f(); + +// Start generator execution. +it.next(); + +// Stop generator execution. +it.return({ + get then() { + actual.push("get then"); + } +}); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-spread-arr-multiple.js b/js/src/tests/test262/language/statements/async-generator/yield-spread-arr-multiple.js new file mode 100644 index 0000000000..3f22543cca --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-spread-arr-multiple.js @@ -0,0 +1,50 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-spread-arr-multiple.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Use yield value in a array spread position (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated, async] +includes: [compareArray.js] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + Array Initializer + + SpreadElement[Yield, Await]: + ...AssignmentExpression[+In, ?Yield, ?Await] + +---*/ +var arr = ['a', 'b', 'c']; +var item; + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield [...yield yield]; +} + +var iter = gen(); + +iter.next(false); +item = iter.next(['a', 'b', 'c']); + +item.then(({ done, value }) => { + item = iter.next(value); + + item.then(({ done, value }) => { + assert.compareArray(value, arr); + assert.sameValue(done, false); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-spread-arr-single.js b/js/src/tests/test262/language/statements/async-generator/yield-spread-arr-single.js new file mode 100644 index 0000000000..c68224b07b --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-spread-arr-single.js @@ -0,0 +1,49 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-spread-arr-single.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Use yield value in a array spread position (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + Array Initializer + + SpreadElement[Yield, Await]: + ...AssignmentExpression[+In, ?Yield, ?Await] + +---*/ +var arr = ['a', 'b', 'c']; + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield [...yield]; +} + +var iter = gen(); + +iter.next(false); +var item = iter.next(arr); + +item.then(({ done, value }) => { + assert.notSameValue(value, arr, 'value is a new array'); + assert(Array.isArray(value), 'value is an Array exotic object'); + assert.sameValue(value.length, 3) + assert.sameValue(value[0], 'a'); + assert.sameValue(value[1], 'b'); + assert.sameValue(value[2], 'c'); + assert.sameValue(done, false); +}).then($DONE, $DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-spread-obj.js b/js/src/tests/test262/language/statements/async-generator/yield-spread-obj.js new file mode 100644 index 0000000000..e5611226af --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-spread-obj.js @@ -0,0 +1,52 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-spread-obj.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Use yield value in a object spread position (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [object-spread, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] + +---*/ + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield { + ...yield, + y: 1, + ...yield yield, + }; +} + +var iter = gen(); + +iter.next(); +iter.next({ x: 42 }); +iter.next({ x: 'lol' }); +var item = iter.next({ y: 39 }); + +item.then(({ done, value }) => { + assert.sameValue(value.x, 42); + assert.sameValue(value.y, 39); + assert.sameValue(Object.keys(value).length, 2); + assert.sameValue(done, false); +}).then($DONE, $DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-async-from-sync-iterator-inaccessible.js b/js/src/tests/test262/language/statements/async-generator/yield-star-async-from-sync-iterator-inaccessible.js new file mode 100644 index 0000000000..f962045044 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-async-from-sync-iterator-inaccessible.js @@ -0,0 +1,56 @@ +// |reftest| async +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-createasyncfromsynciterator +description: > + Async-from-Sync Iterator instances are not accessible from user code. +info: | + 25.1.4.1 CreateAsyncFromSyncIterator ( syncIteratorRecord ) + 1. Let asyncIterator be ! ObjectCreate(%AsyncFromSyncIteratorPrototype%, « [[SyncIteratorRecord]] »). + 2. Set asyncIterator.[[SyncIteratorRecord]] to syncIteratorRecord. + 3. Let nextMethod be ! Get(asyncIterator, "next"). + 4. Let iteratorRecord be Record { [[Iterator]]: asyncIterator, [[NextMethod]]: nextMethod, [[Done]]: false }. + 5. Return iteratorRecord. + + 14.4.14 Runtime Semantics: Evaluation + YieldExpression : yield * AssignmentExpression + 1. Let generatorKind be ! GetGeneratorKind(). + ... + 4. Let iteratorRecord be ? GetIterator(value, generatorKind). + ... + + 7.4.1 GetIterator ( obj [ , hint [ , method ] ] ) + ... + 3. If method is not present, then + a. If hint is async, then + i. Set method to ? GetMethod(obj, @@asyncIterator). + ii. If method is undefined, then + 1. Let syncMethod be ? GetMethod(obj, @@iterator). + 2. Let syncIteratorRecord be ? GetIterator(obj, sync, syncMethod). + 3. Return ? CreateAsyncFromSyncIterator(syncIteratorRecord). + ... + +flags: [async] +features: [async-iteration] +---*/ + +var AsyncIteratorPrototype = Object.getPrototypeOf(async function*(){}.constructor.prototype.prototype); + +Object.defineProperty(AsyncIteratorPrototype, Symbol.iterator, { + get() { + throw new Error("@@iterator accessed"); + } +}); + +Object.defineProperty(AsyncIteratorPrototype, Symbol.asyncIterator, { + get() { + throw new Error("@@asyncIterator accessed"); + } +}); + +async function* g() { + yield* []; +} +g().next().then(() => $DONE(), $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-async-next.js b/js/src/tests/test262/language/statements/async-generator/yield-star-async-next.js new file mode 100644 index 0000000000..155a5d02cd --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-async-next.js @@ -0,0 +1,219 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-next.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Execution order for yield* with async iterator and next() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration, Symbol.asyncIterator] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ name: "get [Symbol.iterator]" }); + }, + get [Symbol.asyncIterator]() { + log.push({ + name: "get [Symbol.asyncIterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.asyncIterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-promise-1", + get then() { + log.push({ + name: "get next then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "next-promise-2", + get then() { + log.push({ + name: "get next then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +} + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue"); + + assert.sameValue(log[2].name, "call [Symbol.asyncIterator]"); + assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue"); + assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length"); + + assert.sameValue(log[3].name, "get next"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[4].name, "call next"); + assert.sameValue(log[4].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[4].args.length, 1, "next args.length"); + assert.sameValue(log[4].args[0], undefined, "next args[0]"); + + assert.sameValue(log[5].name, "get next then (1)"); + assert.sameValue(log[5].thisValue.name, "next-promise-1", "get next then thisValue"); + + assert.sameValue(log[6].name, "call next then (1)"); + assert.sameValue(log[6].thisValue.name, "next-promise-1", "next then thisValue"); + assert.sameValue(log[6].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[6].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[6].args[1], "function", "next then args[1]"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(log[8].name, "get next value (1)"); + assert.sameValue(log[8].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[9].name, "call next"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[9].args.length, 1, "next args.length"); + assert.sameValue(log[9].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[10].name, "get next then (2)"); + assert.sameValue(log[10].thisValue.name, "next-promise-2", "get next then thisValue"); + + assert.sameValue(log[11].name, "call next then (2)"); + assert.sameValue(log[11].thisValue.name, "next-promise-2", "next then thisValue"); + assert.sameValue(log[11].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[11].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[11].args[1], "function", "next then args[1]"); + + assert.sameValue(log[12].name, "get next done (2)"); + assert.sameValue(log[12].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[13].name, "get next value (2)"); + assert.sameValue(log[13].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[14].name, "after yield*"); + assert.sameValue(log[14].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 15, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-async-return.js b/js/src/tests/test262/language/statements/async-generator/yield-star-async-return.js new file mode 100644 index 0000000000..9e2c42bae3 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-async-return.js @@ -0,0 +1,235 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-return.case +// - src/async-generators/default/async-declaration.template +/*--- +description: execution order for yield* with async iterator and return() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration, Symbol.asyncIterator] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. If generatorKind is async, then set value to ? Await(value). + 3. Return Completion{[[Type]]: return, [[Value]]: value, [[Target]]: empty}. + ix. If generatorKind is async, then let received be AsyncGeneratorYield(? IteratorValue(innerResult)). + ... + + AsyncGeneratorYield ( value ) + ... + 8. Return ! AsyncGeneratorResolve(generator, value, false). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var returnCount = 0; + return { + name: 'asyncIterator', + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-promise-1", + get then() { + log.push({ + name: "get return then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "return-promise-2", + get then() { + log.push({ + name: "get return then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +} + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return then (1)"); + assert.sameValue(log[4].thisValue.name, "return-promise-1", "get return then thisValue"); + + assert.sameValue(log[5].name, "call return then (1)"); + assert.sameValue(log[5].thisValue.name, "return-promise-1", "return then thisValue"); + assert.sameValue(log[5].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "return then args[1]"); + + assert.sameValue(log[6].name, "get return done (1)"); + assert.sameValue(log[6].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(log[7].name, "get return value (1)"); + assert.sameValue(log[7].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 8, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[8].name, "get return"); + assert.sameValue(log[8].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[9].name, "call return"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[9].args.length, 1, "return args.length"); + assert.sameValue(log[9].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[10].name, "get return then (2)"); + assert.sameValue(log[10].thisValue.name, "return-promise-2", "get return then thisValue"); + + assert.sameValue(log[11].name, "call return then (2)"); + assert.sameValue(log[11].thisValue.name, "return-promise-2", "return then thisValue"); + assert.sameValue(log[11].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[11].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[11].args[1], "function", "return then args[1]"); + + assert.sameValue(log[12].name, "get return done (2)"); + assert.sameValue(log[12].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(log[13].name, "get return value (2)"); + assert.sameValue(log[13].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 14, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-async-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-async-throw.js new file mode 100644 index 0000000000..465156fa18 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-async-throw.js @@ -0,0 +1,243 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: execution order for yield* with async iterator and throw() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration, Symbol.asyncIterator] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Let resultValue be Return ? IteratorValue(innerResult). + b. If generatorKind is async, then set resultValue to ? Await(resultValue). + c. Return resultValue. + 7. If generatorKind is async, then let received be AsyncGeneratorYield(? IteratorValue(innerResult)). + ... + + AsyncGeneratorYield ( value ) + + ... + 8. Return ! AsyncGeneratorResolve(generator, value, false). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var throwCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-promise-1", + get then() { + log.push({ + name: "get throw then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "throw-promise-2", + get then() { + log.push({ + name: "get throw then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +} + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw then (1)"); + assert.sameValue(log[4].thisValue.name, "throw-promise-1", "get throw thisValue"); + + assert.sameValue(log[5].name, "call throw then (1)"); + assert.sameValue(log[5].thisValue.name, "throw-promise-1", "throw thisValue"); + assert.sameValue(log[5].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[6].name, "get throw done (1)"); + assert.sameValue(log[6].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(log[7].name, "get throw value (1)"); + assert.sameValue(log[7].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 8, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[8].name, "get throw"); + assert.sameValue(log[8].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[9].name, "call throw"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[9].args.length, 1, "throw args.length"); + assert.sameValue(log[9].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[10].name, "get throw then (2)"); + assert.sameValue(log[10].thisValue.name, "throw-promise-2", "get throw thisValue"); + + assert.sameValue(log[11].name, "call throw then (2)"); + assert.sameValue(log[11].thisValue.name, "throw-promise-2", "throw thisValue"); + assert.sameValue(log[11].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[11].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[11].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[12].name, "get throw done (2)"); + assert.sameValue(log[12].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[13].name, "get throw value (2)"); + assert.sameValue(log[13].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[14].name, "after yield*"); + assert.sameValue(log[14].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 15, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-expr-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-expr-abrupt.js new file mode 100644 index 0000000000..0c41b9ec6d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-expr-abrupt.js @@ -0,0 +1,54 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-expr-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Abrupt completion while getting yield* operand (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + ... + +---*/ +var obj = {}; +var abrupt = function() { + throw obj; +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* abrupt(); + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, obj, "reject reason"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-get-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-get-abrupt.js new file mode 100644 index 0000000000..7796050a16 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-get-abrupt.js @@ -0,0 +1,74 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-get-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Abrupt completion while getting [Symbol.asyncIterator] (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + ... + +---*/ +var reason = {}; +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + get [Symbol.asyncIterator]() { + throw reason; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, "reject reason"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-boolean-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-boolean-throw.js new file mode 100644 index 0000000000..5c5a180678 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-boolean-throw.js @@ -0,0 +1,73 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-not-callable-boolean-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Throws a TypeError on a non-callable [Symbol.asyncIterator] (boolean) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]: false +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-number-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-number-throw.js new file mode 100644 index 0000000000..7fd8825b29 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-number-throw.js @@ -0,0 +1,73 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-not-callable-number-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Throws a TypeError on a non-callable [Symbol.asyncIterator] (number) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]: 0 +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-object-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-object-throw.js new file mode 100644 index 0000000000..4d985ae446 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-object-throw.js @@ -0,0 +1,73 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-not-callable-object-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Throws a TypeError on a non-callable [Symbol.asyncIterator] (object) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]: {} +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-string-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-string-throw.js new file mode 100644 index 0000000000..19439f18f3 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-string-throw.js @@ -0,0 +1,73 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-not-callable-string-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Throws a TypeError on a non-callable [Symbol.asyncIterator] (string) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]: '' +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-symbol-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-symbol-throw.js new file mode 100644 index 0000000000..2d9cfc5c55 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-not-callable-symbol-throw.js @@ -0,0 +1,73 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-not-callable-symbol-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Throws a TypeError on a non-callable [Symbol.asyncIterator] (symbol) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]: Symbol.asyncIterator +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-null-sync-get-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-null-sync-get-abrupt.js new file mode 100644 index 0000000000..7bc93f03e6 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-null-sync-get-abrupt.js @@ -0,0 +1,79 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-null-sync-get-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Abrupt completion while getting @@iterator after null @@asyncIterator (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + ... + +---*/ +var calls = 0; +var reason = {}; +var obj = { + get [Symbol.iterator]() { + throw reason; + }, + get [Symbol.asyncIterator]() { + calls += 1; + return null; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, 'reject reason'); + assert.sameValue(calls, 1); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-abrupt.js new file mode 100644 index 0000000000..883bc0973f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-abrupt.js @@ -0,0 +1,70 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-returns-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Abrupt completion while calling [Symbol.asyncIterator] (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + 6. Let iterator be ? Call(method, obj). + ... + +---*/ +var reason = {}; +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + throw reason; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, "reject reason"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-boolean-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-boolean-throw.js new file mode 100644 index 0000000000..cadf3d6496 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-boolean-throw.js @@ -0,0 +1,70 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-returns-boolean-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.asyncIterator]() - boolean (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + 6. Let iterator be ? Call(method, obj). + 7. If Type(iterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return true; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-null-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-null-throw.js new file mode 100644 index 0000000000..81284e6d0b --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-null-throw.js @@ -0,0 +1,70 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-returns-null-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.asyncIterator]() - null (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + 6. Let iterator be ? Call(method, obj). + 7. If Type(iterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return null; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-number-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-number-throw.js new file mode 100644 index 0000000000..e6688ecb7f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-number-throw.js @@ -0,0 +1,70 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-returns-number-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.asyncIterator]() - number (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + 6. Let iterator be ? Call(method, obj). + 7. If Type(iterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return 42; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-string-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-string-throw.js new file mode 100644 index 0000000000..92943314d9 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-string-throw.js @@ -0,0 +1,70 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-returns-string-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.asyncIterator]() - string (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + 6. Let iterator be ? Call(method, obj). + 7. If Type(iterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return '42'; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-symbol-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-symbol-throw.js new file mode 100644 index 0000000000..ae3539c5e6 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-symbol-throw.js @@ -0,0 +1,70 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-returns-symbol-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.asyncIterator]() - symbol (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + 6. Let iterator be ? Call(method, obj). + 7. If Type(iterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return Symbol.asyncIterator; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-undefined-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-undefined-throw.js new file mode 100644 index 0000000000..40aea77591 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-returns-undefined-throw.js @@ -0,0 +1,70 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-returns-undefined-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.asyncIterator]() - undefined (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + ... + 6. Let iterator be ? Call(method, obj). + 7. If Type(iterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return undefined; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-undefined-sync-get-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-undefined-sync-get-abrupt.js new file mode 100644 index 0000000000..ee81acbf34 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-async-undefined-sync-get-abrupt.js @@ -0,0 +1,79 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-async-undefined-sync-get-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Abrupt completion while getting @@iterator after undefined @@asyncIterator (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + ... + +---*/ +var calls = 0; +var reason = {}; +var obj = { + get [Symbol.iterator]() { + throw reason; + }, + get [Symbol.asyncIterator]() { + calls += 1; + return undefined; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, 'reject reason'); + assert.sameValue(calls, 1); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-get-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-get-abrupt.js new file mode 100644 index 0000000000..1bd3ca00ad --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-get-abrupt.js @@ -0,0 +1,73 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-get-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Abrupt completion while getting [Symbol.iterator] (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + ... + +---*/ +var reason = {}; +var obj = { + get [Symbol.iterator]() { + throw reason; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, "reject reason"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-boolean-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-boolean-throw.js new file mode 100644 index 0000000000..a87cfc0adf --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-boolean-throw.js @@ -0,0 +1,72 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-not-callable-boolean-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Throws a TypeError on a non-callable [Symbol.iterator] (boolean) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + ... + 4. If IsCallable(func) is false, throw a TypeError exception. + ... + +---*/ +var obj = { + [Symbol.iterator]: false +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-number-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-number-throw.js new file mode 100644 index 0000000000..aa32053600 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-number-throw.js @@ -0,0 +1,72 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-not-callable-number-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Throws a TypeError on a non-callable [Symbol.iterator] (number) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + ... + 4. If IsCallable(func) is false, throw a TypeError exception. + ... + +---*/ +var obj = { + [Symbol.iterator]: 0 +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-object-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-object-throw.js new file mode 100644 index 0000000000..0fa5e2d73c --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-object-throw.js @@ -0,0 +1,72 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-not-callable-object-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Throws a TypeError on a non-callable [Symbol.iterator] (object) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + ... + 4. If IsCallable(func) is false, throw a TypeError exception. + ... + +---*/ +var obj = { + [Symbol.iterator]: {} +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-string-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-string-throw.js new file mode 100644 index 0000000000..86f31ce384 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-string-throw.js @@ -0,0 +1,72 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-not-callable-string-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Throws a TypeError on a non-callable [Symbol.iterator] (string) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + ... + 4. If IsCallable(func) is false, throw a TypeError exception. + ... + +---*/ +var obj = { + [Symbol.iterator]: '' +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-symbol-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-symbol-throw.js new file mode 100644 index 0000000000..4bec50b862 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-not-callable-symbol-throw.js @@ -0,0 +1,72 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-not-callable-symbol-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Throws a TypeError on a non-callable [Symbol.iterator] (symbol) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ... + + GetMethod ( V, P ) + + ... + 2. Let func be ? GetV(V, P). + ... + 4. If IsCallable(func) is false, throw a TypeError exception. + ... + +---*/ +var obj = { + [Symbol.iterator]: Symbol.iterator +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-abrupt.js new file mode 100644 index 0000000000..c2094a328f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-abrupt.js @@ -0,0 +1,67 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-returns-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Abrupt completion while calling [Symbol.iterator] (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + ... + +---*/ +var reason = {}; +var obj = { + [Symbol.iterator]() { + throw reason; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, "reject reason"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-boolean-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-boolean-throw.js new file mode 100644 index 0000000000..327afe9fde --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-boolean-throw.js @@ -0,0 +1,72 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-returns-boolean-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.iterator]() - boolean (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + CreateAsyncFromSyncIterator(syncIterator) + + 1. If Type(syncIterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + [Symbol.iterator]() { + return true; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-null-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-null-throw.js new file mode 100644 index 0000000000..4b0e3cf33c --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-null-throw.js @@ -0,0 +1,72 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-returns-null-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.iterator]() - null (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + CreateAsyncFromSyncIterator(syncIterator) + + 1. If Type(syncIterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + [Symbol.iterator]() { + return null; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-number-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-number-throw.js new file mode 100644 index 0000000000..9cd51156c8 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-number-throw.js @@ -0,0 +1,72 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-returns-number-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.iterator]() - number (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + CreateAsyncFromSyncIterator(syncIterator) + + 1. If Type(syncIterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + [Symbol.iterator]() { + return 0; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-string-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-string-throw.js new file mode 100644 index 0000000000..1ce242fde1 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-string-throw.js @@ -0,0 +1,72 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-returns-string-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.iterator]() - string (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + CreateAsyncFromSyncIterator(syncIterator) + + 1. If Type(syncIterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + [Symbol.iterator]() { + return ''; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-symbol-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-symbol-throw.js new file mode 100644 index 0000000000..6f87f06bc8 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-symbol-throw.js @@ -0,0 +1,72 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-returns-symbol-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.iterator]() - symbol (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + CreateAsyncFromSyncIterator(syncIterator) + + 1. If Type(syncIterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + [Symbol.iterator]() { + return Symbol.iterator; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-undefined-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-undefined-throw.js new file mode 100644 index 0000000000..71c01c4e0f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-getiter-sync-returns-undefined-throw.js @@ -0,0 +1,72 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-getiter-sync-returns-undefined-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Non object returned by [Symbol.iterator]() - undefined (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + 1. Let exprRef be the result of evaluating AssignmentExpression. + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + CreateAsyncFromSyncIterator(syncIterator) + + 1. If Type(syncIterator) is not Object, throw a TypeError exception. + ... + +---*/ +var obj = { + [Symbol.iterator]() { + return undefined; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-call-done-get-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-call-done-get-abrupt.js new file mode 100644 index 0000000000..9bc62c10fd --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-call-done-get-abrupt.js @@ -0,0 +1,73 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-call-done-get-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Abrupt completion while getting done (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + v. Let done be ? IteratorComplete(innerResult). + ... + +---*/ +var reason = {}; +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return { + get done() { + throw reason; + } + }; + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, "reject reason"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-call-returns-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-call-returns-abrupt.js new file mode 100644 index 0000000000..8ca899a840 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-call-returns-abrupt.js @@ -0,0 +1,65 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-call-returns-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Abrupt completion while calling next (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + ... + +---*/ +var reason = {}; +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + throw reason; + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, "reject reason"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-call-value-get-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-call-value-get-abrupt.js new file mode 100644 index 0000000000..033348b08d --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-call-value-get-abrupt.js @@ -0,0 +1,75 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-call-value-get-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Abrupt completion while getting value (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + vi. If done is true, then + 1. Return ? IteratorValue(innerResult). + ... + +---*/ +var reason = {}; +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return { + done: true, + get value() { + throw reason; + } + }; + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, "reject reason"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-get-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-get-abrupt.js new file mode 100644 index 0000000000..e1d269458e --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-get-abrupt.js @@ -0,0 +1,65 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-get-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Abrupt completion while getting next (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + ... + +---*/ +var reason = {}; +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + get next() { + throw reason; + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, "reject reason"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-non-object-ignores-then.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-non-object-ignores-then.js new file mode 100644 index 0000000000..271fa593c9 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-non-object-ignores-then.js @@ -0,0 +1,85 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-non-object-ignores-then.case +// - src/async-generators/default/async-declaration.template +/*--- +description: If next() value is not-object, do not access respective then property (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + iv. If Type(innerResult) is not Object, throw a TypeError exception. + ... + + Await + + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). + ... + + Promise Resolve Functions + + ... + 7. If Type(resolution) is not Object, then + a. Return FulfillPromise(promise, resolution). + 8. Let then be Get(resolution, "then"). + ... + +---*/ +Number.prototype.then = function() { + throw new Test262Error('Number#then should not be used'); +}; +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return 42; + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, 'TypeError'); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-boolean-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-boolean-throw.js new file mode 100644 index 0000000000..cd7b5607ba --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-boolean-throw.js @@ -0,0 +1,62 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-not-callable-boolean-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Not-callable next value in a yield star position - boolean (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next: true + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-null-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-null-throw.js new file mode 100644 index 0000000000..88662200ce --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-null-throw.js @@ -0,0 +1,62 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-not-callable-null-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Not-callable next value in a yield star position - null (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next: null + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-number-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-number-throw.js new file mode 100644 index 0000000000..ba69eeffc8 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-number-throw.js @@ -0,0 +1,62 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-not-callable-number-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Not-callable next value in a yield star position - number (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next: 42 + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-object-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-object-throw.js new file mode 100644 index 0000000000..7871989780 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-object-throw.js @@ -0,0 +1,62 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-not-callable-object-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Not-callable next value in a yield star position - object (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next: {} + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-string-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-string-throw.js new file mode 100644 index 0000000000..14557c4e67 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-string-throw.js @@ -0,0 +1,62 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-not-callable-string-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Not-callable next value in a yield star position - string (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next: '' + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-symbol-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-symbol-throw.js new file mode 100644 index 0000000000..2584c8a5a2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-symbol-throw.js @@ -0,0 +1,62 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-not-callable-symbol-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Not-callable next value in a yield star position - symbol (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next: Symbol('oi') + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-undefined-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-undefined-throw.js new file mode 100644 index 0000000000..75fa4c5333 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-not-callable-undefined-throw.js @@ -0,0 +1,62 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-not-callable-undefined-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Not-callable next value in a yield star position - undefined (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next: undefined + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v.constructor, TypeError, "TypeError"); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-get-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-get-abrupt.js new file mode 100644 index 0000000000..f7cc2f3588 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-get-abrupt.js @@ -0,0 +1,89 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-then-get-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Return abrupt after getting next().then (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + + Await + + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). + ... + + Promise Resolve Functions + + ... + 8. Let then be Get(resolution, "then"). + ... + 10. Get thenAction be then.[[Value]]. + ... + 12. Perform EnqueueJob("PromiseJobs", PromiseResolveThenableJob, « promise, + resolution, thenAction »). + ... + +---*/ +var reason = {}; +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return { + get then() { + throw reason; + } + }; + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, 'reject reason'); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-boolean-fulfillpromise.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-boolean-fulfillpromise.js new file mode 100644 index 0000000000..9a486d6b4f --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-boolean-fulfillpromise.js @@ -0,0 +1,83 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-then-non-callable-boolean-fulfillpromise.case +// - src/async-generators/default/async-declaration.template +/*--- +description: FulfillPromise if next().then is not-callable (boolean) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + iv. If Type(innerResult) is not Object, throw a TypeError exception. + ... + + Await + + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). + ... + + Promise Resolve Functions + + ... + 7. If Type(resolution) is not Object, then + a. Return FulfillPromise(promise, resolution). + 8. Let then be Get(resolution, "then"). + ... + 11. If IsCallable(thenAction) is false, then + a. Return FulfillPromise(promise, resolution). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return { + then: true, + value: 42, + done: false + } + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(({ value, done }) => { + assert.sameValue(value, 42); + assert.sameValue(done, false); +}).then($DONE, $DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-null-fulfillpromise.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-null-fulfillpromise.js new file mode 100644 index 0000000000..767625c782 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-null-fulfillpromise.js @@ -0,0 +1,83 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-then-non-callable-null-fulfillpromise.case +// - src/async-generators/default/async-declaration.template +/*--- +description: FulfillPromise if next().then is not-callable (null) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + iv. If Type(innerResult) is not Object, throw a TypeError exception. + ... + + Await + + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). + ... + + Promise Resolve Functions + + ... + 7. If Type(resolution) is not Object, then + a. Return FulfillPromise(promise, resolution). + 8. Let then be Get(resolution, "then"). + ... + 11. If IsCallable(thenAction) is false, then + a. Return FulfillPromise(promise, resolution). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return { + then: null, + value: 42, + done: false + } + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(({ value, done }) => { + assert.sameValue(value, 42); + assert.sameValue(done, false); +}).then($DONE, $DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-number-fulfillpromise.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-number-fulfillpromise.js new file mode 100644 index 0000000000..2864b5a9b0 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-number-fulfillpromise.js @@ -0,0 +1,83 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-then-non-callable-number-fulfillpromise.case +// - src/async-generators/default/async-declaration.template +/*--- +description: FulfillPromise if next().then is not-callable (number) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + iv. If Type(innerResult) is not Object, throw a TypeError exception. + ... + + Await + + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). + ... + + Promise Resolve Functions + + ... + 7. If Type(resolution) is not Object, then + a. Return FulfillPromise(promise, resolution). + 8. Let then be Get(resolution, "then"). + ... + 11. If IsCallable(thenAction) is false, then + a. Return FulfillPromise(promise, resolution). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return { + then: 39, + value: 42, + done: false + } + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(({ value, done }) => { + assert.sameValue(value, 42); + assert.sameValue(done, false); +}).then($DONE, $DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-object-fulfillpromise.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-object-fulfillpromise.js new file mode 100644 index 0000000000..37271cc528 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-object-fulfillpromise.js @@ -0,0 +1,83 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-then-non-callable-object-fulfillpromise.case +// - src/async-generators/default/async-declaration.template +/*--- +description: FulfillPromise if next().then is not-callable (object) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + iv. If Type(innerResult) is not Object, throw a TypeError exception. + ... + + Await + + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). + ... + + Promise Resolve Functions + + ... + 7. If Type(resolution) is not Object, then + a. Return FulfillPromise(promise, resolution). + 8. Let then be Get(resolution, "then"). + ... + 11. If IsCallable(thenAction) is false, then + a. Return FulfillPromise(promise, resolution). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return { + then: {}, + value: 42, + done: false + } + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(({ value, done }) => { + assert.sameValue(value, 42); + assert.sameValue(done, false); +}).then($DONE, $DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-string-fulfillpromise.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-string-fulfillpromise.js new file mode 100644 index 0000000000..7863bf280a --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-string-fulfillpromise.js @@ -0,0 +1,83 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-then-non-callable-string-fulfillpromise.case +// - src/async-generators/default/async-declaration.template +/*--- +description: FulfillPromise if next().then is not-callable (string) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + iv. If Type(innerResult) is not Object, throw a TypeError exception. + ... + + Await + + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). + ... + + Promise Resolve Functions + + ... + 7. If Type(resolution) is not Object, then + a. Return FulfillPromise(promise, resolution). + 8. Let then be Get(resolution, "then"). + ... + 11. If IsCallable(thenAction) is false, then + a. Return FulfillPromise(promise, resolution). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return { + then: '', + value: 42, + done: false + } + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(({ value, done }) => { + assert.sameValue(value, 42); + assert.sameValue(done, false); +}).then($DONE, $DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-symbol-fulfillpromise.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-symbol-fulfillpromise.js new file mode 100644 index 0000000000..639fc0c175 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-symbol-fulfillpromise.js @@ -0,0 +1,83 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-then-non-callable-symbol-fulfillpromise.case +// - src/async-generators/default/async-declaration.template +/*--- +description: FulfillPromise if next().then is not-callable (symbol) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + iv. If Type(innerResult) is not Object, throw a TypeError exception. + ... + + Await + + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). + ... + + Promise Resolve Functions + + ... + 7. If Type(resolution) is not Object, then + a. Return FulfillPromise(promise, resolution). + 8. Let then be Get(resolution, "then"). + ... + 11. If IsCallable(thenAction) is false, then + a. Return FulfillPromise(promise, resolution). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return { + then: Symbol('oi'), + value: 42, + done: false + } + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(({ value, done }) => { + assert.sameValue(value, 42); + assert.sameValue(done, false); +}).then($DONE, $DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-undefined-fulfillpromise.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-undefined-fulfillpromise.js new file mode 100644 index 0000000000..4c3469f468 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-non-callable-undefined-fulfillpromise.js @@ -0,0 +1,83 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-then-non-callable-undefined-fulfillpromise.case +// - src/async-generators/default/async-declaration.template +/*--- +description: FulfillPromise if next().then is not-callable (undefined) (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + iv. If Type(innerResult) is not Object, throw a TypeError exception. + ... + + Await + + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). + ... + + Promise Resolve Functions + + ... + 7. If Type(resolution) is not Object, then + a. Return FulfillPromise(promise, resolution). + 8. Let then be Get(resolution, "then"). + ... + 11. If IsCallable(thenAction) is false, then + a. Return FulfillPromise(promise, resolution). + ... + +---*/ +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return { + then: undefined, + value: 42, + done: false + } + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(({ value, done }) => { + assert.sameValue(value, 42); + assert.sameValue(done, false); +}).then($DONE, $DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-returns-abrupt.js b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-returns-abrupt.js new file mode 100644 index 0000000000..adc3d00793 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-next-then-returns-abrupt.js @@ -0,0 +1,89 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-next-then-returns-abrupt.case +// - src/async-generators/default/async-declaration.template +/*--- +description: Return abrupt after calling next().then (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + ... + 6. Repeat + a. If received.[[Type]] is normal, then + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + + Await + + ... + 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). + 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). + ... + + Promise Resolve Functions + + ... + 8. Let then be Get(resolution, "then"). + ... + 10. Get thenAction be then.[[Value]]. + ... + 12. Perform EnqueueJob("PromiseJobs", PromiseResolveThenableJob, « promise, + resolution, thenAction »). + ... + +---*/ +var reason = {}; +var obj = { + get [Symbol.iterator]() { + throw new Test262Error('it should not get Symbol.iterator'); + }, + [Symbol.asyncIterator]() { + return { + next() { + return { + then() { + throw reason; + } + }; + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + yield* obj; + throw new Test262Error('abrupt completion closes iter'); + +} + +var iter = gen(); + +iter.next().then(() => { + throw new Test262Error('Promise incorrectly fulfilled.'); +}, v => { + assert.sameValue(v, reason, 'reject reason'); + + iter.next().then(({ done, value }) => { + assert.sameValue(done, true, 'the iterator is completed'); + assert.sameValue(value, undefined, 'value is undefined'); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-normal-notdone-iter-value-throws.js b/js/src/tests/test262/language/statements/async-generator/yield-star-normal-notdone-iter-value-throws.js new file mode 100644 index 0000000000..4a4d8a4d30 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-normal-notdone-iter-value-throws.js @@ -0,0 +1,54 @@ +// |reftest| async +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: > + Abrupt completion when calling IteratorValue is propagated when received.[[Type]] is normal. +info: | + 14.4.14 Runtime Semantics: Evaluation + YieldExpression : yield* AssignmentExpression + + ... + 7. Repeat, + a. If received.[[Type]] is normal, then + ... + vi. If generatorKind is async, then set received to AsyncGeneratorYield(? IteratorValue(innerResult)). + ... + +flags: [async] +features: [async-iteration] +---*/ + +var token = {}; + +var asyncIter = { + [Symbol.asyncIterator]() { + return this; + }, + next() { + return { + done: false, + get value() { + throw token; + } + }; + } +}; + +async function* f() { + var thrown; + try { + yield* asyncIter; + } catch (e) { + thrown = e; + } + return thrown; +} + +var iter = f(); + +iter.next().then(({value}) => { + assert.sameValue(value, token); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-promise-not-unwrapped.js b/js/src/tests/test262/language/statements/async-generator/yield-star-promise-not-unwrapped.js new file mode 100644 index 0000000000..4dabe6af43 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-promise-not-unwrapped.js @@ -0,0 +1,42 @@ +// |reftest| async +// Copyright (C) 2022 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: > + `yield*` in an async generator does not await promises returned by a manually implemented async iterator. +flags: [async] +features: [async-iteration] +---*/ + +var innerPromise = Promise.resolve("unwrapped value"); + +var asyncIter = { + [Symbol.asyncIterator]() { + return this; + }, + next() { + return { + done: false, + value: innerPromise, + }; + }, + get return() { + throw new Test262Error(".return should not be accessed"); + }, + get throw() { + throw new Test262Error(".throw should not be accessed"); + }, +}; + +async function* f() { + yield* asyncIter; +} + +f() + .next() + .then(v => { + assert.sameValue(v.value, innerPromise, "yield* should not unwrap promises from manually-implemented async iterators"); + }) + .then($DONE, $DONE) diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-return-missing-value-is-awaited.js b/js/src/tests/test262/language/statements/async-generator/yield-star-return-missing-value-is-awaited.js new file mode 100644 index 0000000000..d4d3f641be --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-return-missing-value-is-awaited.js @@ -0,0 +1,45 @@ +// |reftest| async +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: > + If iterator's "return" method is missing, + received value is awaited before forwarded to the runtime. +info: | + YieldExpression : yield * AssignmentExpression + + [...] + 7. Repeat, + [...] + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, then + 1. If generatorKind is async, then set received.[[Value]] to ? Await(received.[[Value]]). + 2. Return Completion(received). +features: [Symbol.asyncIterator, async-iteration] +flags: [async] +---*/ + +var asyncIterable = { + [Symbol.asyncIterator]: function() { + return this; + }, + next: function() { + return {value: 1, done: false}; + }, +}; + +async function* asyncGenerator() { + yield* asyncIterable; +} + +var asyncIterator = asyncGenerator(); +asyncIterator.next().then(function() { + var promise = Promise.resolve(2).then(() => 3); + return asyncIterator.return(promise).then(function(result) { + assert.sameValue(result.value, 3); + assert.sameValue(result.done, true); + }); +}).then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-return-notdone-iter-value-throws.js b/js/src/tests/test262/language/statements/async-generator/yield-star-return-notdone-iter-value-throws.js new file mode 100644 index 0000000000..f0fbdabdd6 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-return-notdone-iter-value-throws.js @@ -0,0 +1,64 @@ +// |reftest| async +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: > + Abrupt completion when calling IteratorValue is propagated when received.[[Type]] is return. +info: | + 14.4.14 Runtime Semantics: Evaluation + YieldExpression : yield* AssignmentExpression + + ... + 7. Repeat, + ... + c. Else, + i. Assert: received.[[Type]] is return. + ... + ix. If generatorKind is async, then set received to AsyncGeneratorYield(? IteratorValue(innerReturnResult)). + ... + +flags: [async] +features: [async-iteration] +---*/ + +var token = {}; + +var asyncIter = { + [Symbol.asyncIterator]() { + return this; + }, + next() { + return { + done: false, + value: undefined, + }; + }, + return() { + return { + done: false, + get value() { + throw token; + } + }; + } +}; + +async function* f() { + var thrown; + try { + yield* asyncIter; + } catch (e) { + thrown = e; + } + return thrown; +} + +var iter = f(); + +iter.next().then(() => { + iter.return().then(({value}) => { + assert.sameValue(value, token); + }).then($DONE, $DONE); +}).catch($DONE); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-return-then-getter-ticks.js b/js/src/tests/test262/language/statements/async-generator/yield-star-return-then-getter-ticks.js new file mode 100644 index 0000000000..efa97408a2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-return-then-getter-ticks.js @@ -0,0 +1,145 @@ +// |reftest| async +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: > + Return resumption value is awaited upon and hence is treated as a thenable. +info: | + 15.5.5 Runtime Semantics: Evaluation + YieldExpression : yield* AssignmentExpression + + ... + 7. Repeat, + a. If received.[[Type]] is normal, then + i. Let innerResult be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], + « received.[[Value]] »). + ii. If generatorKind is async, then set innerResult to ? Await(innerResult). + ... + vi. If generatorKind is async, then set received to AsyncGeneratorYield(? IteratorValue(innerResult)). + ... + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, then + 1. If generatorKind is async, then set received.[[Value]] to ? Await(received.[[Value]]). + 2. Return Completion(received). + ... + + 27.6.3.8 AsyncGeneratorYield ( value ) + ... + 12. If queue is not empty, then + ... + 13. Else, + ... + c. Set the code evaluation state of genContext such that when evaluation is resumed with a + Completion resumptionValue the following steps will be performed: + i. Return ? AsyncGeneratorUnwrapYieldResumption(resumptionValue). + + 27.6.3.7 AsyncGeneratorUnwrapYieldResumption ( resumptionValue ) + ... + 2. Let awaited be Completion(Await(resumptionValue.[[Value]])). + ... + + 6.2.3.1 Await + ... + 2. Let promise be ? PromiseResolve(%Promise%, « value »). + ... + + 27.2.4.7.1 PromiseResolve ( C, x ) + ... + 2. Let promiseCapability be ? NewPromiseCapability(C). + 3. Perform ? Call(promiseCapability.[[Resolve]], undefined, « x »). + ... + + 27.2.1.5 NewPromiseCapability ( C ) + ... + 7. Let promise be ? Construct(C, « executor »). + ... + + 27.2.3.1 Promise ( executor ) + ... + 8. Let resolvingFunctions be CreateResolvingFunctions(promise). + ... + + 27.2.1.3 CreateResolvingFunctions ( promise ) + ... + 2. Let stepsResolve be the algorithm steps defined in Promise Resolve Functions (25.6.1.3.2). + 3. Let resolve be CreateBuiltinFunction(stepsResolve, « [[Promise]], [[AlreadyResolved]] »). + ... + + 27.2.1.3.2 Promise Resolve Functions + ... + 9. Let then be Get(resolution, "then"). + ... + +includes: [compareArray.js] +flags: [async] +features: [async-iteration] +---*/ + +var expected = [ + "start", + + // `Await(innerResult)` promise resolved. + "tick 1", + + // "then" of `resumptionValue.[[Value]]` accessed. + "get then", + + // `Await(resumptionValue.[[Value]])` promise resolved. + "tick 2", + + // Get iterator "return" method. + "get return", + + // "then" of `received.[[Value]]` accessed. + "get then", + + // `Await(received.[[Value]])` promise resolved. + "tick 3", +]; + +var actual = []; + +var asyncIter = { + [Symbol.asyncIterator]() { + return this; + }, + next() { + return { + done: false, + }; + }, + get return() { + actual.push("get return"); + } +}; + +async function* f() { + actual.push("start"); + yield* asyncIter; + actual.push("stop - never reached"); +} + +Promise.resolve(0) + .then(() => actual.push("tick 1")) + .then(() => actual.push("tick 2")) + .then(() => actual.push("tick 3")) + .then(() => { + assert.compareArray(actual, expected, "Ticks for return with thenable getter"); +}).then($DONE, $DONE); + +var it = f(); + +// Start generator execution. +it.next(); + +// Stop generator execution. +it.return({ + get then() { + actual.push("get then"); + } +}); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-sync-next.js b/js/src/tests/test262/language/statements/async-generator/yield-star-sync-next.js new file mode 100644 index 0000000000..a0f99421a2 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-sync-next.js @@ -0,0 +1,222 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-next.case +// - src/async-generators/default/async-declaration.template +/*--- +description: execution order for yield* with sync iterator and next() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration, Symbol.asyncIterator] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + 5. Let received be NormalCompletion(undefined). + 6. Repeat + a. If received.[[Type]] is normal, then + i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + v. Let done be ? IteratorComplete(innerResult). + vi. If done is true, then + 1. Return ? IteratorValue(innerResult). + vii. Let received be GeneratorYield(innerResult). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + %AsyncFromSyncIteratorPrototype%.next ( value ) + + ... + 5. Let nextResult be IteratorNext(syncIterator, value). + ... + 7. Let nextValue be IteratorValue(nextResult). + ... + 9. Let nextDone be IteratorComplete(nextResult). + ... + 12. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « nextValue »). + ... + 14. Set onFulfilled.[[Done]] to nextDone. + 15. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + + Async Iterator Value Unwrap Functions + + 1. Return ! CreateIterResultObject(value, F.[[Done]]). + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ + name: "get [Symbol.iterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.iterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + }; + }, + get [Symbol.asyncIterator]() { + log.push({ name: "get [Symbol.asyncIterator]" }); + return null; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +} + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + + assert.sameValue(log[2].name, "get [Symbol.iterator]"); + assert.sameValue(log[2].thisValue, obj, "get [Symbol.iterator] thisValue"); + + assert.sameValue(log[3].name, "call [Symbol.iterator]"); + assert.sameValue(log[3].thisValue, obj, "[Symbol.iterator] thisValue"); + assert.sameValue(log[3].args.length, 0, "[Symbol.iterator] args.length"); + + assert.sameValue(log[4].name, "get next"); + assert.sameValue(log[4].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[5].name, "call next"); + assert.sameValue(log[5].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[5].args.length, 1, "next args.length"); + assert.sameValue(log[5].args[0], undefined, "next args[0]"); + + assert.sameValue(log[6].name, "get next done (1)"); + assert.sameValue(log[6].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(log[7].name, "get next value (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 8, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[8].name, "call next"); + assert.sameValue(log[8].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[8].args.length, 1, "next args.length"); + assert.sameValue(log[8].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[9].name, "get next done (2)"); + assert.sameValue(log[9].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[10].name, "get next value (2)"); + assert.sameValue(log[10].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[11].name, "after yield*"); + assert.sameValue(log[11].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 12, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-sync-return.js b/js/src/tests/test262/language/statements/async-generator/yield-star-sync-return.js new file mode 100644 index 0000000000..ff28d86c36 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-sync-return.js @@ -0,0 +1,197 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-return.case +// - src/async-generators/default/async-declaration.template +/*--- +description: execution order for yield* with sync iterator and return() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration, Symbol.asyncIterator] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + %AsyncFromSyncIteratorPrototype%.return ( value ) + + 5. Let return be GetMethod(syncIterator, "return"). + ... + ... + 8. Let returnResult be Call(return, syncIterator, « value »). + ... + 11. Let returnValue be IteratorValue(returnResult). + .. + 13. Let returnDone be IteratorComplete(returnResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, « returnValue »). + ... + 18. Set onFulfilled.[[Done]] to returnDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var returnCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +} + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return done (1)"); + assert.sameValue(log[4].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(log[5].name, "get return value (1)"); + assert.sameValue(log[5].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.return().then(v => { + assert.sameValue(log[6].name, "get return"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[7].name, "call return"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "get return thisValue"); + assert.sameValue(log[7].args.length, 1, "return args.length"); + assert.sameValue(log[7].args[0], undefined, "return args[0]"); + + assert.sameValue(log[8].name, "get return done (2)"); + assert.sameValue(log[8].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(log[9].name, "get return value (2)"); + assert.sameValue(log[9].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 10, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-sync-throw.js b/js/src/tests/test262/language/statements/async-generator/yield-star-sync-throw.js new file mode 100644 index 0000000000..f656b36759 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-sync-throw.js @@ -0,0 +1,203 @@ +// |reftest| async +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-throw.case +// - src/async-generators/default/async-declaration.template +/*--- +description: execution order for yield* with sync iterator and throw() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [Symbol.iterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + %AsyncFromSyncIteratorPrototype%.throw ( value ) + + ... + 5. Let throw be GetMethod(syncIterator, "throw"). + ... + 8. Let throwResult be Call(throw, syncIterator, « value »). + ... + 11. Let throwValue be IteratorValue(throwResult). + ... + 13. Let throwDone be IteratorComplete(throwResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « throwValue »). + ... + 18. Set onFulfilled.[[Done]] to throwDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var throwCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +async function *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +} + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw done (1)"); + assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(log[5].name, "get throw value (1)"); + assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.throw().then(v => { + assert.sameValue(log[6].name, "get throw"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[7].name, "call throw"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[7].args.length, 1, "throw args.length"); + assert.sameValue(log[7].args[0], undefined, "throw args[0]"); + + assert.sameValue(log[8].name, "get throw done (2)"); + assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[9].name, "get throw value (2)"); + assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[10].name, "after yield*"); + assert.sameValue(log[10].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 11, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/js/src/tests/test262/language/statements/async-generator/yield-star-throw-notdone-iter-value-throws.js b/js/src/tests/test262/language/statements/async-generator/yield-star-throw-notdone-iter-value-throws.js new file mode 100644 index 0000000000..fbb3376934 --- /dev/null +++ b/js/src/tests/test262/language/statements/async-generator/yield-star-throw-notdone-iter-value-throws.js @@ -0,0 +1,65 @@ +// |reftest| async +// Copyright (C) 2019 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: > + Abrupt completion when calling IteratorValue is propagated when received.[[Type]] is throw. +info: | + 14.4.14 Runtime Semantics: Evaluation + YieldExpression : yield* AssignmentExpression + + ... + 7. Repeat, + ... + b. Else if received.[[Type]] is throw, then + ... + ii. If throw is not undefined, then + ... + 7. If generatorKind is async, then set received to AsyncGeneratorYield(? IteratorValue(innerResult)). + ... + +flags: [async] +features: [async-iteration] +---*/ + +var token = {}; + +var asyncIter = { + [Symbol.asyncIterator]() { + return this; + }, + next() { + return { + done: false, + value: undefined, + }; + }, + throw() { + return { + done: false, + get value() { + throw token; + } + }; + } +}; + +async function* f() { + var thrown; + try { + yield* asyncIter; + } catch (e) { + thrown = e; + } + return thrown; +} + +var iter = f(); + +iter.next().then(() => { + iter.throw().then(({value}) => { + assert.sameValue(value, token); + }).then($DONE, $DONE); +}).catch($DONE); |