From 3a4e3bd8b13b887bd61a6b07c24c1eb1f9e74dc9 Mon Sep 17 00:00:00 2001 From: Leonardo Balter <leonardo.balter@gmail.com> Date: Thu, 16 Mar 2017 13:45:43 -0400 Subject: [PATCH] Add generators templates for async gen --- .../default/async-class-decl-method.template | 34 ++++++++++++++ .../async-class-decl-static-method.template | 34 ++++++++++++++ .../default/async-class-expr-method.template | 34 ++++++++++++++ .../async-class-expr-static-method.template | 34 ++++++++++++++ .../default/async-declaration.template | 27 +++++++++++ .../default/async-expression-named.template | 27 +++++++++++ .../default/async-expression.template | 27 +++++++++++ .../default/async-obj-method.template | 27 +++++++++++ .../non-strict/async-declaration.template | 27 +++++++++++ .../async-expression-named.template | 27 +++++++++++ .../non-strict/async-expression.template | 27 +++++++++++ .../non-strict/async-obj-method.template | 28 ++++++++++++ .../yield-identifier-non-strict.case | 30 +++++++++++++ .../yield-identifier-spread-non-strict.case | 45 +++++++++++++++++++ .../yield-identifier-spread-strict.case | 28 ++++++++++++ .../yield-identifier-strict.case | 19 ++++++++ .../yield-spread-arr-multiple.case | 33 ++++++++++++++ .../yield-spread-arr-single.case | 28 ++++++++++++ src/async-generators/yield-spread-obj.case | 36 +++++++++++++++ 19 files changed, 572 insertions(+) create mode 100644 src/async-generators/default/async-class-decl-method.template create mode 100644 src/async-generators/default/async-class-decl-static-method.template create mode 100644 src/async-generators/default/async-class-expr-method.template create mode 100644 src/async-generators/default/async-class-expr-static-method.template create mode 100644 src/async-generators/default/async-declaration.template create mode 100644 src/async-generators/default/async-expression-named.template create mode 100644 src/async-generators/default/async-expression.template create mode 100644 src/async-generators/default/async-obj-method.template create mode 100644 src/async-generators/non-strict/async-declaration.template create mode 100644 src/async-generators/non-strict/async-expression-named.template create mode 100644 src/async-generators/non-strict/async-expression.template create mode 100644 src/async-generators/non-strict/async-obj-method.template create mode 100644 src/async-generators/yield-identifier-non-strict.case create mode 100644 src/async-generators/yield-identifier-spread-non-strict.case create mode 100644 src/async-generators/yield-identifier-spread-strict.case create mode 100644 src/async-generators/yield-identifier-strict.case create mode 100644 src/async-generators/yield-spread-arr-multiple.case create mode 100644 src/async-generators/yield-spread-arr-single.case create mode 100644 src/async-generators/yield-spread-obj.case diff --git a/src/async-generators/default/async-class-decl-method.template b/src/async-generators/default/async-class-decl-method.template new file mode 100644 index 0000000000..4bdf97b1bc --- /dev/null +++ b/src/async-generators/default/async-class-decl-method.template @@ -0,0 +1,34 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/class/async-gen-method- +name: Async Generator method as a ClassDeclaration element +esid: prod-AsyncGeneratorMethod +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } +---*/ + +var callCount = 0; + +class C { async *gen() { + callCount += 1; + /*{ body }*/ +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/default/async-class-decl-static-method.template b/src/async-generators/default/async-class-decl-static-method.template new file mode 100644 index 0000000000..d352943b5f --- /dev/null +++ b/src/async-generators/default/async-class-decl-static-method.template @@ -0,0 +1,34 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/class/async-gen-method-static- +name: Static async generator method as a ClassDeclaration element +esid: prod-AsyncGeneratorMethod +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } +---*/ + +var callCount = 0; + +class C { static async *gen() { + callCount += 1; + /*{ body }*/ +}} + +var gen = C.gen; + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/default/async-class-expr-method.template b/src/async-generators/default/async-class-expr-method.template new file mode 100644 index 0000000000..141f3ab391 --- /dev/null +++ b/src/async-generators/default/async-class-expr-method.template @@ -0,0 +1,34 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/class/async-gen-method- +name: Async generator method as a ClassExpression element +esid: prod-AsyncGeneratorMethod +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } +---*/ + +var callCount = 0; + +var C = class { async *gen() { + callCount += 1; + /*{ body }*/ +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/default/async-class-expr-static-method.template b/src/async-generators/default/async-class-expr-static-method.template new file mode 100644 index 0000000000..85a18a69c4 --- /dev/null +++ b/src/async-generators/default/async-class-expr-static-method.template @@ -0,0 +1,34 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/class/async-gen-method-static- +name: Static async generator method as a ClassExpression element +esid: prod-AsyncGeneratorMethod +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } +---*/ + +var callCount = 0; + +var C = class { static async *gen() { + callCount += 1; + /*{ body }*/ +}} + +var gen = C.gen; + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/default/async-declaration.template b/src/async-generators/default/async-declaration.template new file mode 100644 index 0000000000..e1af489b82 --- /dev/null +++ b/src/async-generators/default/async-declaration.template @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/async-generator/ +name: Async generator Function declaration +esid: prod-AsyncGeneratorDeclaration +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } +---*/ + +var callCount = 0; + +async function *gen() { + callCount += 1; + /*{ body }*/ +} + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/default/async-expression-named.template b/src/async-generators/default/async-expression-named.template new file mode 100644 index 0000000000..ef348b6317 --- /dev/null +++ b/src/async-generators/default/async-expression-named.template @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/async-generator/named- +name: Named async generator expression +esid: prod-AsyncGeneratorExpression +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } +---*/ + +var callCount = 0; + +var gen = async function *g() { + callCount += 1; + /*{ body }*/ +}; + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/default/async-expression.template b/src/async-generators/default/async-expression.template new file mode 100644 index 0000000000..dbbabb63a6 --- /dev/null +++ b/src/async-generators/default/async-expression.template @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/async-generator/ +name: Unnamed async generator expression +esid: prod-AsyncGeneratorExpression +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } +---*/ + +var callCount = 0; + +var gen = async function *() { + callCount += 1; + /*{ body }*/ +}; + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/default/async-obj-method.template b/src/async-generators/default/async-obj-method.template new file mode 100644 index 0000000000..6527dd071c --- /dev/null +++ b/src/async-generators/default/async-obj-method.template @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: language/expressions/object/method-definition/async-gen- +name: Async generator method +esid: prod-AsyncGeneratorMethod +info: | + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } +---*/ + +var callCount = 0; + +var gen = { + async *method() { + callCount += 1; + /*{ body }*/ + } +}.method; + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/non-strict/async-declaration.template b/src/async-generators/non-strict/async-declaration.template new file mode 100644 index 0000000000..c7b9c09874 --- /dev/null +++ b/src/async-generators/non-strict/async-declaration.template @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/statements/async-generator/ +name: Async generator function declaration - valid for non-strict only cases +esid: prod-AsyncGeneratorDeclaration +info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } +---*/ + +var callCount = 0; + +async function *gen() { + callCount += 1; + /*{ body }*/ +} + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/non-strict/async-expression-named.template b/src/async-generators/non-strict/async-expression-named.template new file mode 100644 index 0000000000..c6d7c07b83 --- /dev/null +++ b/src/async-generators/non-strict/async-expression-named.template @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/async-generator/named- +name: Async generator named expression - valid for non-strict only cases +esid: prod-AsyncGeneratorExpression +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } +---*/ + +var callCount = 0; + +var gen = async function *g() { + callCount += 1; + /*{ body }*/ +}; + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/non-strict/async-expression.template b/src/async-generators/non-strict/async-expression.template new file mode 100644 index 0000000000..3a6dc2c2b9 --- /dev/null +++ b/src/async-generators/non-strict/async-expression.template @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/async-generator/ +name: Async generator expression - valid for non-strict only cases +esid: prod-AsyncGeneratorExpression +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } +---*/ + +var callCount = 0; + +var gen = async function *() { + callCount += 1; + /*{ body }*/ +}; + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/non-strict/async-obj-method.template b/src/async-generators/non-strict/async-obj-method.template new file mode 100644 index 0000000000..0216a24495 --- /dev/null +++ b/src/async-generators/non-strict/async-obj-method.template @@ -0,0 +1,28 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +path: language/expressions/object/method-definition/async-gen- +name: Generator method - valid for non-strict only cases +esid: prod-AsyncGeneratorMethod +info: | + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } +---*/ + +var callCount = 0; + +var gen = { + async *method() { + callCount += 1; + /*{ body }*/ + } +}.method; + +var iter = gen(); + +/*{ assertions }*/ + +assert.sameValue(callCount, 1); diff --git a/src/async-generators/yield-identifier-non-strict.case b/src/async-generators/yield-identifier-non-strict.case new file mode 100644 index 0000000000..ebbcb1add8 --- /dev/null +++ b/src/async-generators/yield-identifier-non-strict.case @@ -0,0 +1,30 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Use of yield as a valid identifier in a function body inside a generator body + in non strict mode +template: non-strict +flags: [noStrict, async] +---*/ + +//- body + return (function(arg) { + var yield = arg + 1; + return yield; + }(yield)) +//- assertions +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); diff --git a/src/async-generators/yield-identifier-spread-non-strict.case b/src/async-generators/yield-identifier-spread-non-strict.case new file mode 100644 index 0000000000..99356ce29f --- /dev/null +++ b/src/async-generators/yield-identifier-spread-non-strict.case @@ -0,0 +1,45 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + Mixed use of object spread and yield as a valid identifier in a function body + inside a generator body in non strict mode +template: non-strict +info: | + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] +features: [object-spread] +flags: [noStrict, async] +---*/ + +//- body + yield { + ...yield yield, + ...(function(arg) { + var yield = arg; + return {...yield}; + }(yield)), + ...yield, + } +//- assertions +var iter = gen(); + +iter.next(); +iter.next(); +iter.next({ x: 10, a: 0, b: 0 }); +iter.next({ y: 20, a: 1, b: 1 }); +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(Object.keys(value).length, 5); +}).then($DONE, $DONE); diff --git a/src/async-generators/yield-identifier-spread-strict.case b/src/async-generators/yield-identifier-spread-strict.case new file mode 100644 index 0000000000..7c84ac4dae --- /dev/null +++ b/src/async-generators/yield-identifier-spread-strict.case @@ -0,0 +1,28 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + It's an early error if the AssignmentExpression is a function body with yield + as an identifier in strict mode. +template: default +info: | + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] +features: [object-spread] +flags: [onlyStrict] +negative: + phase: early + type: SyntaxError +---*/ + +//- body + return { + ...(function() { + var yield; + throw new Test262Error(); + }()), + } diff --git a/src/async-generators/yield-identifier-strict.case b/src/async-generators/yield-identifier-strict.case new file mode 100644 index 0000000000..6c9e49f828 --- /dev/null +++ b/src/async-generators/yield-identifier-strict.case @@ -0,0 +1,19 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: > + It's an early error if the generator body has another function body with + yield as an identifier in strict mode. +template: default +flags: [onlyStrict] +negative: + phase: early + type: SyntaxError +---*/ + +//- body + (function() { + var yield; + throw new Test262Error(); + }()) diff --git a/src/async-generators/yield-spread-arr-multiple.case b/src/async-generators/yield-spread-arr-multiple.case new file mode 100644 index 0000000000..33f431766b --- /dev/null +++ b/src/async-generators/yield-spread-arr-multiple.case @@ -0,0 +1,33 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Use yield value in a array spread position +template: default +info: | + Array Initializer + + SpreadElement[Yield, Await]: + ...AssignmentExpression[+In, ?Yield, ?Await] +includes: + - compareArray.js +flags: [async] +---*/ + +//- setup +var arr = ['a', 'b', 'c']; +var item; +//- body + yield [...yield yield]; +//- assertions +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); diff --git a/src/async-generators/yield-spread-arr-single.case b/src/async-generators/yield-spread-arr-single.case new file mode 100644 index 0000000000..87116db83b --- /dev/null +++ b/src/async-generators/yield-spread-arr-single.case @@ -0,0 +1,28 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Use yield value in a array spread position +template: default +info: | + Array Initializer + + SpreadElement[Yield, Await]: + ...AssignmentExpression[+In, ?Yield, ?Await] +includes: + - compareArray.js +flags: [async] +---*/ + +//- setup +var arr = ['a', 'b', 'c']; +//- body + yield [...yield]; +//- assertions +iter.next(false); +var item = iter.next(['a', 'b', 'c']); + +item.then(({ done, value }) => { + assert(compareArray(value, arr)); + assert.sameValue(done, false); +}).then($DONE, $DONE); diff --git a/src/async-generators/yield-spread-obj.case b/src/async-generators/yield-spread-obj.case new file mode 100644 index 0000000000..f7d14c022a --- /dev/null +++ b/src/async-generators/yield-spread-obj.case @@ -0,0 +1,36 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Use yield value in a object spread position +template: default +info: | + Spread Properties + + PropertyDefinition[Yield]: + (...) + ...AssignmentExpression[In, ?Yield] +features: [object-spread] +includes: + - compareArray.js +flags: [async] +---*/ + +//- body + yield { + ...yield, + y: 1, + ...yield yield, + }; +//- assertions +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); -- GitLab