mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 05:55:36 +02:00
Additional coverage for computed yield values
Ref #865 Ref https://github.com/tc39/test262/pull/890#issuecomment-284600429
This commit is contained in:
parent
0cc55bb44d
commit
77fbf1cada
33
src/generators/default/class-method-definition.template
Normal file
33
src/generators/default/class-method-definition.template
Normal 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.
|
||||||
|
/*---
|
||||||
|
path: language/expressions/class/gen-method-
|
||||||
|
name: Generator method as a ClassElement
|
||||||
|
esid: prod-GeneratorMethod
|
||||||
|
info: |
|
||||||
|
ClassElement[Yield, Await]:
|
||||||
|
MethodDefinition[?Yield, ?Await]
|
||||||
|
|
||||||
|
MethodDefinition[Yield, Await]:
|
||||||
|
GeneratorMethod[?Yield, ?Await]
|
||||||
|
|
||||||
|
14.4 Generator Function Definitions
|
||||||
|
|
||||||
|
GeneratorMethod[Yield, Await]:
|
||||||
|
* PropertyName[?Yield, ?Await] ( UniqueFormalParameters[+Yield, ~Await] ) { GeneratorBody }
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
class C { *gen() {
|
||||||
|
callCount += 1;
|
||||||
|
/*{ body }*/
|
||||||
|
}}
|
||||||
|
|
||||||
|
var gen = C.prototype.gen;
|
||||||
|
|
||||||
|
var iter = gen();
|
||||||
|
|
||||||
|
/*{ assertions }*/
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1);
|
25
src/generators/default/expression.template
Normal file
25
src/generators/default/expression.template
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
path: language/expressions/generators/
|
||||||
|
name: Generator expression
|
||||||
|
esid: prod-GeneratorExpression
|
||||||
|
info: |
|
||||||
|
14.4 Generator Function Definitions
|
||||||
|
|
||||||
|
GeneratorExpression:
|
||||||
|
function * BindingIdentifier[+Yield, ~Await]opt ( FormalParameters[+Yield, ~Await] ) { GeneratorBody }
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
var gen = function *() {
|
||||||
|
callCount += 1;
|
||||||
|
/*{ body }*/
|
||||||
|
};
|
||||||
|
|
||||||
|
var iter = gen();
|
||||||
|
|
||||||
|
/*{ assertions }*/
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1);
|
27
src/generators/default/method-definition.template
Normal file
27
src/generators/default/method-definition.template
Normal 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/generator-
|
||||||
|
name: Generator method
|
||||||
|
esid: prod-GeneratorMethod
|
||||||
|
info: |
|
||||||
|
14.4 Generator Function Definitions
|
||||||
|
|
||||||
|
GeneratorMethod[Yield, Await]:
|
||||||
|
* PropertyName[?Yield, ?Await] ( UniqueFormalParameters[+Yield, ~Await] ) { GeneratorBody }
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
var gen = {
|
||||||
|
*method() {
|
||||||
|
callCount += 1;
|
||||||
|
/*{ body }*/
|
||||||
|
}
|
||||||
|
}.method;
|
||||||
|
|
||||||
|
var iter = gen();
|
||||||
|
|
||||||
|
/*{ assertions }*/
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1);
|
25
src/generators/default/statement.template
Normal file
25
src/generators/default/statement.template
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
path: language/statements/generators/
|
||||||
|
name: Generator function declaration
|
||||||
|
esid: prod-GeneratorDeclaration
|
||||||
|
info: |
|
||||||
|
14.4 Generator Function Definitions
|
||||||
|
|
||||||
|
GeneratorDeclaration[Yield, Await, Default]:
|
||||||
|
function * BindingIdentifier[?Yield, ?Await] ( FormalParameters[+Yield, ~Await] ) { GeneratorBody }
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
function *gen() {
|
||||||
|
callCount += 1;
|
||||||
|
/*{ body }*/
|
||||||
|
}
|
||||||
|
|
||||||
|
var iter = gen();
|
||||||
|
|
||||||
|
/*{ assertions }*/
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1);
|
25
src/generators/non-strict/expression.template
Normal file
25
src/generators/non-strict/expression.template
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
path: language/expressions/generators/
|
||||||
|
name: Generator expression - valid for non-strict only cases
|
||||||
|
esid: prod-GeneratorExpression
|
||||||
|
info: |
|
||||||
|
14.4 Generator Function Definitions
|
||||||
|
|
||||||
|
GeneratorExpression:
|
||||||
|
function * BindingIdentifier[+Yield, ~Await]opt ( FormalParameters[+Yield, ~Await] ) { GeneratorBody }
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
var gen = function *() {
|
||||||
|
callCount += 1;
|
||||||
|
/*{ body }*/
|
||||||
|
};
|
||||||
|
|
||||||
|
var iter = gen();
|
||||||
|
|
||||||
|
/*{ assertions }*/
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1);
|
27
src/generators/non-strict/method-definition.template
Normal file
27
src/generators/non-strict/method-definition.template
Normal 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/generator-
|
||||||
|
name: Generator method - valid for non-strict only cases
|
||||||
|
esid: prod-GeneratorMethod
|
||||||
|
info: |
|
||||||
|
14.4 Generator Function Definitions
|
||||||
|
|
||||||
|
GeneratorMethod[Yield, Await]:
|
||||||
|
* PropertyName[?Yield, ?Await] ( UniqueFormalParameters[+Yield, ~Await] ) { GeneratorBody }
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
var gen = {
|
||||||
|
*method() {
|
||||||
|
callCount += 1;
|
||||||
|
/*{ body }*/
|
||||||
|
}
|
||||||
|
}.method;
|
||||||
|
|
||||||
|
var iter = gen();
|
||||||
|
|
||||||
|
/*{ assertions }*/
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1);
|
25
src/generators/non-strict/statement.template
Normal file
25
src/generators/non-strict/statement.template
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
path: language/statements/generators/
|
||||||
|
name: Generator function declaration - valid for non-strict only cases
|
||||||
|
esid: prod-GeneratorDeclaration
|
||||||
|
info: |
|
||||||
|
14.4 Generator Function Definitions
|
||||||
|
|
||||||
|
GeneratorDeclaration[Yield, Await, Default]:
|
||||||
|
function * BindingIdentifier[?Yield, ?Await] ( FormalParameters[+Yield, ~Await] ) { GeneratorBody }
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
function *gen() {
|
||||||
|
callCount += 1;
|
||||||
|
/*{ body }*/
|
||||||
|
}
|
||||||
|
|
||||||
|
var iter = gen();
|
||||||
|
|
||||||
|
/*{ assertions }*/
|
||||||
|
|
||||||
|
assert.sameValue(callCount, 1);
|
26
src/generators/yield-identifier-non-strict.case
Normal file
26
src/generators/yield-identifier-non-strict.case
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
desc: >
|
||||||
|
Use of yield as a valid identifier in a function body inside a generator body
|
||||||
|
in non strict mode
|
||||||
|
template: non-strict
|
||||||
|
flags: [noStrict]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- body
|
||||||
|
return (function(arg) {
|
||||||
|
var yield = arg + 1;
|
||||||
|
return yield;
|
||||||
|
}(yield))
|
||||||
|
//- assertions
|
||||||
|
var item = iter.next();
|
||||||
|
|
||||||
|
assert.sameValue(item.done, false);
|
||||||
|
assert.sameValue(item.value, undefined);
|
||||||
|
|
||||||
|
item = iter.next(42);
|
||||||
|
|
||||||
|
assert.sameValue(item.done, true);
|
||||||
|
assert.sameValue(item.value, 43);
|
43
src/generators/yield-identifier-spread-non-strict.case
Normal file
43
src/generators/yield-identifier-spread-non-strict.case
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// 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]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- 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 });
|
||||||
|
|
||||||
|
assert.sameValue(item.done, false);
|
||||||
|
assert.sameValue(item.value.x, 10);
|
||||||
|
assert.sameValue(item.value.y, 20);
|
||||||
|
assert.sameValue(item.value.z, 30);
|
||||||
|
assert.sameValue(item.value.a, 1);
|
||||||
|
assert.sameValue(item.value.b, 2);
|
||||||
|
assert.sameValue(Object.keys(item.value).length, 5);
|
28
src/generators/yield-identifier-spread-strict.case
Normal file
28
src/generators/yield-identifier-spread-strict.case
Normal 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();
|
||||||
|
}()),
|
||||||
|
}
|
19
src/generators/yield-identifier-strict.case
Normal file
19
src/generators/yield-identifier-strict.case
Normal 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();
|
||||||
|
}())
|
27
src/generators/yield-spread-arr-multiple.case
Normal file
27
src/generators/yield-spread-arr-multiple.case
Normal 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.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
desc: Use yield value in a array spread position
|
||||||
|
template: default
|
||||||
|
info: |
|
||||||
|
Array Initializer
|
||||||
|
|
||||||
|
SpreadElement[Yield, Await]:
|
||||||
|
...AssignmentExpression[+In, ?Yield, ?Await]
|
||||||
|
includes:
|
||||||
|
- compareArray.js
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- setup
|
||||||
|
var arr = ['a', 'b', 'c'];
|
||||||
|
var item;
|
||||||
|
//- body
|
||||||
|
yield [...yield yield];
|
||||||
|
//- assertions
|
||||||
|
iter.next(false);
|
||||||
|
item = iter.next(['a', 'b', 'c']);
|
||||||
|
item = iter.next(item.value);
|
||||||
|
|
||||||
|
assert(compareArray(item.value, arr));
|
||||||
|
assert.sameValue(item.done, false);
|
25
src/generators/yield-spread-arr-single.case
Normal file
25
src/generators/yield-spread-arr-single.case
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
desc: Use yield value in a array spread position
|
||||||
|
template: default
|
||||||
|
info: |
|
||||||
|
Array Initializer
|
||||||
|
|
||||||
|
SpreadElement[Yield, Await]:
|
||||||
|
...AssignmentExpression[+In, ?Yield, ?Await]
|
||||||
|
includes:
|
||||||
|
- compareArray.js
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- setup
|
||||||
|
var arr = ['a', 'b', 'c'];
|
||||||
|
//- body
|
||||||
|
yield [...yield];
|
||||||
|
//- assertions
|
||||||
|
iter.next(false);
|
||||||
|
var item = iter.next(['a', 'b', 'c']);
|
||||||
|
|
||||||
|
assert(compareArray(item.value, arr));
|
||||||
|
assert.sameValue(item.done, false);
|
33
src/generators/yield-spread-obj.case
Normal file
33
src/generators/yield-spread-obj.case
Normal 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 object spread position
|
||||||
|
template: default
|
||||||
|
info: |
|
||||||
|
Spread Properties
|
||||||
|
|
||||||
|
PropertyDefinition[Yield]:
|
||||||
|
(...)
|
||||||
|
...AssignmentExpression[In, ?Yield]
|
||||||
|
features: [object-spread]
|
||||||
|
includes:
|
||||||
|
- compareArray.js
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- body
|
||||||
|
yield {
|
||||||
|
...yield,
|
||||||
|
y: 1,
|
||||||
|
...yield yield,
|
||||||
|
};
|
||||||
|
//- assertions
|
||||||
|
iter.next();
|
||||||
|
iter.next({ x: 42 });
|
||||||
|
iter.next({ x: 'lol' });
|
||||||
|
var item = iter.next({ y: 39 });
|
||||||
|
|
||||||
|
assert.sameValue(item.value.x, 42);
|
||||||
|
assert.sameValue(item.value.y, 39);
|
||||||
|
assert.sameValue(Object.keys(item.value).length, 2);
|
||||||
|
assert.sameValue(item.done, false);
|
Loading…
x
Reference in New Issue
Block a user