Add generators templates for async gen

This commit is contained in:
Leonardo Balter 2017-03-16 13:45:43 -04:00 committed by Leo Balter
parent 74b07de387
commit 3a4e3bd8b1
No known key found for this signature in database
GPG Key ID: 2C75F319D398E36B
19 changed files with 572 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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();
}()),
}

View File

@ -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();
}())

View File

@ -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);

View File

@ -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);

View File

@ -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);