diff --git a/test/language/class/method-definition/generator-no-yield.js b/test/language/class/method-definition/generator-no-yield.js new file mode 100644 index 0000000000..fbdd4ce00f --- /dev/null +++ b/test/language/class/method-definition/generator-no-yield.js @@ -0,0 +1,20 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + Generators declared with GeneratorMethod syntax do not require a + `yield` expression. + features: [generators] + es6id: 14.4 + ---*/ + +var result; +class A { + *foo(a) {} +} + +result = A.prototype.foo(3).next(); + +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/class/method-definition/generator-return.js b/test/language/class/method-definition/generator-return.js new file mode 100644 index 0000000000..dc03f99e02 --- /dev/null +++ b/test/language/class/method-definition/generator-return.js @@ -0,0 +1,23 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `return` is a valid statement within generator function bodies. + features: [generators] + es6id: 14.4 + ---*/ + +var result; +class A { + *g1() { return; } + *g2() { return 1; } +} + +result = A.prototype.g1().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +result = A.prototype.g2().next(); +assert.sameValue(result.value, 1); +assert.sameValue(result.done, true); diff --git a/test/language/class/method-definition/yield-as-binding-identifier.js b/test/language/class/method-definition/yield-as-binding-identifier.js new file mode 100644 index 0000000000..3bcdafe5d3 --- /dev/null +++ b/test/language/class/method-definition/yield-as-binding-identifier.js @@ -0,0 +1,17 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a reserved keyword within generator function bodies and may + not be used as a binding identifier. + features: [generators] + es6id: 12.1.1 + negative: SyntaxError + ---*/ + +class A { + *g() { + yield = 1; + } +} diff --git a/test/language/class/method-definition/yield-as-expression-with-rhs.js b/test/language/class/method-definition/yield-as-expression-with-rhs.js new file mode 100644 index 0000000000..bea22a1d7b --- /dev/null +++ b/test/language/class/method-definition/yield-as-expression-with-rhs.js @@ -0,0 +1,118 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid expression within generator function bodies. + features: [generators] + es6id: 14.4 + ---*/ + +var iter, result; +class A { + *g1() { (yield 1) } + *g2() { [yield 1] } + *g3() { {yield 1} } + *g4() { yield 1, yield 2; } + *g5() { (yield 1) ? yield 2 : yield 3; } +} + +iter = A.prototype.g1(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within grouping operator: result `value`'); +assert.sameValue( + result.done, false, 'Within grouping operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following grouping operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following grouping operator: result `done` flag' +); + +iter = A.prototype.g2(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within array literal: result `value`'); +assert.sameValue( + result.done, false, 'Within array literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following array literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following array literal: result `done` flag' +); + +iter = A.prototype.g3(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within object literal: result `value`'); +assert.sameValue( + result.done, false, 'Within object literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following object literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following object literal: result `done` flag' +); + +iter = A.prototype.g4(); +result = iter.next(); +assert.sameValue( + result.value, 1, 'First expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'First expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, 2, 'Second expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'Second expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following comma expression: result `value`' +); +assert.sameValue( + result.done, true, 'Following comma expression: result `done` flag' +); + +iter = A.prototype.g5(); +result = iter.next(); +assert.sameValue( + result.value, + 1, + 'Conditional expression in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Conditional expression in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + 3, + 'Branch in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Branch in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following conditional operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following conditional operator: result `done` flag' +); diff --git a/test/language/class/method-definition/yield-as-expression-without-rhs.js b/test/language/class/method-definition/yield-as-expression-without-rhs.js new file mode 100644 index 0000000000..8fb5aa2657 --- /dev/null +++ b/test/language/class/method-definition/yield-as-expression-without-rhs.js @@ -0,0 +1,128 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid expression within generator function bodies. + features: [generators] + es6id: 14.4 + ---*/ + +var iter, result; +class A { + *g1() { (yield) } + *g2() { [yield] } + *g3() { {yield} } + *g4() { yield, yield; } + *g5() { (yield) ? yield : yield; } +} + +iter = A.prototype.g1(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within grouping operator: result `value`' +); +assert.sameValue( + result.done, false, 'Within grouping operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following grouping operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following grouping operator: result `done` flag' +); + +iter = A.prototype.g2(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within array literal: result `value`' +); +assert.sameValue( + result.done, false, 'Within array literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following array literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following array literal: result `done` flag' +); + +iter = A.prototype.g3(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within object literal: result `value`' +); +assert.sameValue( + result.done, false, 'Within object literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following object literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following object literal: result `done` flag' +); + +iter = A.prototype.g4(); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'First expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'First expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Second expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'Second expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following comma expression: result `value`' +); +assert.sameValue( + result.done, true, 'Following comma expression: result `done` flag' +); + +iter = A.prototype.g5(); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Conditional expression in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Conditional expression in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Branch in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Branch in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following conditional operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following conditional operator: result `done` flag' +); diff --git a/test/language/class/method-definition/yield-as-function-expression-binding-identifier.js b/test/language/class/method-definition/yield-as-function-expression-binding-identifier.js new file mode 100644 index 0000000000..7b1db5ddce --- /dev/null +++ b/test/language/class/method-definition/yield-as-function-expression-binding-identifier.js @@ -0,0 +1,23 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may be used as the binding identifier of a function expression + within generator bodies. + features: [generators] + es6id: 14.1 + flags: [noStrict] + ---*/ + +var result; +class A { + *g() { + (function yield() {}); + } +} + +result = A.prototype.g().next(); + +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/class/method-definition/yield-as-generator-method-binding-identifier.js b/test/language/class/method-definition/yield-as-generator-method-binding-identifier.js new file mode 100644 index 0000000000..441d522a73 --- /dev/null +++ b/test/language/class/method-definition/yield-as-generator-method-binding-identifier.js @@ -0,0 +1,30 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid BindingIdentifier for GeneratorMethods outside of + strict mode. + features: [generators] + es6id: 12.1.1 + flags: [noStrict] + ---*/ + +var iter, result; +class A { + *yield() { (yield 3) + (yield 4); } +} + +iter = A.prototype.yield(); + +result = iter.next(); +assert.sameValue(result.value, 3, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 4, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Third result `value`'); +assert.sameValue(result.done, true, 'Third result `done` flag'); diff --git a/test/language/class/method-definition/yield-as-identifier-in-nested-function.js b/test/language/class/method-definition/yield-as-identifier-in-nested-function.js new file mode 100644 index 0000000000..10a1d11064 --- /dev/null +++ b/test/language/class/method-definition/yield-as-identifier-in-nested-function.js @@ -0,0 +1,24 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is not a reserved keyword within normal function bodies declared + within generator function bodies. + features: [generators] + es6id: 12.1.1 + flags: [noStrict] + ---*/ + +var result; +class A { + *g() { + function h() { + yield = 1; + } + } +} + +result = A.prototype.g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/class/method-definition/yield-as-label.js b/test/language/class/method-definition/yield-as-label.js new file mode 100644 index 0000000000..094f90ac72 --- /dev/null +++ b/test/language/class/method-definition/yield-as-label.js @@ -0,0 +1,17 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a reserved keyword within generator function bodies and may + not be used as a label. + features: [generators] + es6id: 12.1.1 + negative: SyntaxError + ---*/ + +class A { + *g() { + yield: 1; + } +} diff --git a/test/language/class/method-definition/yield-as-literal-property-name.js b/test/language/class/method-definition/yield-as-literal-property-name.js new file mode 100644 index 0000000000..9f71c92ef4 --- /dev/null +++ b/test/language/class/method-definition/yield-as-literal-property-name.js @@ -0,0 +1,21 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may be used as a literal property name in an object literal + within generator function bodies. + features: [generators] + es6id: 12.1.1 + ---*/ + +var result; +class A { + *g() { + ({ get yield() { return 1 } }); + } +} + +result = A.prototype.g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/class/method-definition/yield-as-logical-or-expression.js b/test/language/class/method-definition/yield-as-logical-or-expression.js new file mode 100644 index 0000000000..f4bb32f416 --- /dev/null +++ b/test/language/class/method-definition/yield-as-logical-or-expression.js @@ -0,0 +1,16 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions are not LogicalOrExpressions. + features: [generators] + es6id: 12.1.1 + negative: SyntaxError + ---*/ + +class A { + *g() { + yield ? yield : yield; + } +} diff --git a/test/language/class/method-definition/yield-as-parameter.js b/test/language/class/method-definition/yield-as-parameter.js new file mode 100644 index 0000000000..a1b648051e --- /dev/null +++ b/test/language/class/method-definition/yield-as-parameter.js @@ -0,0 +1,15 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a reserved keyword within generator function bodies and may + not be used as the binding identifier of a parameter. + features: [generators] + es6id: 12.1.1 + negative: SyntaxError + ---*/ + +class A { + *g(yield) {} +} diff --git a/test/language/class/method-definition/yield-as-property-name.js b/test/language/class/method-definition/yield-as-property-name.js new file mode 100644 index 0000000000..98e8873bde --- /dev/null +++ b/test/language/class/method-definition/yield-as-property-name.js @@ -0,0 +1,21 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may be used as a literal property name in an object literal + within generator function bodies. + features: [generators] + es6id: 12.1.1 + ---*/ + +var result; +class A { + *g() { + ({ yield: 1 }); + } +} + +result = A.prototype.g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/class/method-definition/yield-as-statement.js b/test/language/class/method-definition/yield-as-statement.js new file mode 100644 index 0000000000..2ae05047ed --- /dev/null +++ b/test/language/class/method-definition/yield-as-statement.js @@ -0,0 +1,47 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid statement within generator function bodies. + features: [generators] + es6id: 14.4 + ---*/ + +var iter, result; +class A { + *g1() { yield; } + *g2() { yield 1; } +} + +iter = A.prototype.g1(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Without right-hand-side: first result `value`' +); +assert.sameValue( + result.done, false, 'Without right-hand-side: first result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Without right-hand-side: second result `value`' +); +assert.sameValue( + result.done, true, 'Without right-hand-eside: second result `done` flag' +); + +iter = A.prototype.g2(); +result = iter.next(); +assert.sameValue( + result.value, 1, 'With right-hand-side: first result `value`' +); +assert.sameValue( + result.done, false, 'With right-hand-side: first result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'With right-hand-side: second result `value`' +); +assert.sameValue( + result.done, true, 'With right-hand-eside: second result `done` flag' +); diff --git a/test/language/class/method-definition/yield-as-yield-operand.js b/test/language/class/method-definition/yield-as-yield-operand.js new file mode 100644 index 0000000000..3bc45e9845 --- /dev/null +++ b/test/language/class/method-definition/yield-as-yield-operand.js @@ -0,0 +1,31 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions may be used as the right-hand-side of other `yield` + expressions. + features: [generators] + es6id: 14.4 + ---*/ + +var iter, result; +class A { + *g() { + yield yield 1; + } +} + +iter = A.prototype.g(); + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Third result `value`'); +assert.sameValue(result.done, true, 'Thid result `done` flag'); diff --git a/test/language/class/method-definition/yield-newline.js b/test/language/class/method-definition/yield-newline.js new file mode 100644 index 0000000000..96ea9a1b71 --- /dev/null +++ b/test/language/class/method-definition/yield-newline.js @@ -0,0 +1,27 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + Newlines terminate `yield` expressions. + features: [generators] + es6id: 14.4 + ---*/ + +var iter, result; +class A { + *g() { + yield + 1 + } +} + +iter = A.prototype.g(); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Second result `value`'); +assert.sameValue(result.done, true, 'Second result `done` flag'); diff --git a/test/language/class/method-definition/yield-star-after-newline.js b/test/language/class/method-definition/yield-star-after-newline.js new file mode 100644 index 0000000000..80cef3e561 --- /dev/null +++ b/test/language/class/method-definition/yield-star-after-newline.js @@ -0,0 +1,17 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + A newline may not precede the `*` token in a `yield` expression. + features: [generators] + es6id: 14.4 + negative: SyntaxError + ---*/ + +class A { + *g() { + yield + * 1 + } +} diff --git a/test/language/class/method-definition/yield-star-before-newline.js b/test/language/class/method-definition/yield-star-before-newline.js new file mode 100644 index 0000000000..e27e009c89 --- /dev/null +++ b/test/language/class/method-definition/yield-star-before-newline.js @@ -0,0 +1,22 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The right-hand side of a `yield *` expression may appear on a new line. + features: [generators] + es6id: 14.4 + ---*/ + +var result; +class A { + *g() { + yield * + g2() + } +} +var g2 = function*() {}; + +result = A.prototype.g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/class/method-definition/yield-weak-binding.js b/test/language/class/method-definition/yield-weak-binding.js new file mode 100644 index 0000000000..8a8d4aa491 --- /dev/null +++ b/test/language/class/method-definition/yield-weak-binding.js @@ -0,0 +1,14 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions bind weakly + features: [generators] + es6id: 14.4 + negative: SyntaxError + ---*/ + +class A { + *g() { yield 3 + yield 4; } +} diff --git a/test/language/expressions/generators/no-yield.js b/test/language/expressions/generators/no-yield.js new file mode 100644 index 0000000000..b172b0e2a8 --- /dev/null +++ b/test/language/expressions/generators/no-yield.js @@ -0,0 +1,17 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + Generators declared with GeneratorExpression syntax do not require a + `yield` expression. + es6id: 14.4 + ---*/ + +var result; +var foo = function*(a) {}; + +result = foo(3).next(); + +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/generators/return.js b/test/language/expressions/generators/return.js new file mode 100644 index 0000000000..2d7822cb47 --- /dev/null +++ b/test/language/expressions/generators/return.js @@ -0,0 +1,20 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `return` is a valid statement within generator function bodies. + es6id: 14.4 + ---*/ + +var result; +var g1 = function*() { return; }; +var g2 = function*() { return 1; }; + +result = g1().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +result = g2().next(); +assert.sameValue(result.value, 1); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/generators/yield-as-binding-identifier.js b/test/language/expressions/generators/yield-as-binding-identifier.js new file mode 100644 index 0000000000..ed9abdc800 --- /dev/null +++ b/test/language/expressions/generators/yield-as-binding-identifier.js @@ -0,0 +1,14 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a reserved keyword within generator function bodies and may + not be used as a binding identifier. + es6id: 12.1.1 + negative: SyntaxError + ---*/ + +var g = function*() { + yield = 1; +}; diff --git a/test/language/expressions/generators/yield-as-expression-with-rhs.js b/test/language/expressions/generators/yield-as-expression-with-rhs.js new file mode 100644 index 0000000000..a7fb6e9fc6 --- /dev/null +++ b/test/language/expressions/generators/yield-as-expression-with-rhs.js @@ -0,0 +1,115 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid expression within generator function bodies. + es6id: 14.4 + ---*/ + +var result, iter; +var g1 = function*() { (yield 1) }; +var g2 = function*() { [yield 1] }; +var g3 = function*() { {yield 1} }; +var g4 = function*() { yield 1, yield 2; }; +var g5 = function*() { (yield 1) ? yield 2 : yield 3; }; + +iter = g1(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within grouping operator: result `value`'); +assert.sameValue( + result.done, false, 'Within grouping operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following grouping operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following grouping operator: result `done` flag' +); + +iter = g2(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within array literal: result `value`'); +assert.sameValue( + result.done, false, 'Within array literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following array literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following array literal: result `done` flag' +); + +iter = g3(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within object literal: result `value`'); +assert.sameValue( + result.done, false, 'Within object literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following object literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following object literal: result `done` flag' +); + +iter = g4(); +result = iter.next(); +assert.sameValue( + result.value, 1, 'First expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'First expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, 2, 'Second expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'Second expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following comma expression: result `value`' +); +assert.sameValue( + result.done, true, 'Following comma expression: result `done` flag' +); + +iter = g5(); +result = iter.next(); +assert.sameValue( + result.value, + 1, + 'Conditional expression in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Conditional expression in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + 3, + 'Branch in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Branch in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following conditional operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following conditional operator: result `done` flag' +); diff --git a/test/language/expressions/generators/yield-as-expression-without-rhs.js b/test/language/expressions/generators/yield-as-expression-without-rhs.js new file mode 100644 index 0000000000..4b13cb34d1 --- /dev/null +++ b/test/language/expressions/generators/yield-as-expression-without-rhs.js @@ -0,0 +1,125 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid expression within generator function bodies. + es6id: 14.4 + ---*/ + +var iter, result; +var g1 = function*() { (yield) }; +var g2 = function*() { [yield] }; +var g3 = function*() { {yield} }; +var g4 = function*() { yield, yield; }; +var g5 = function*() { (yield) ? yield : yield; }; + +iter = g1(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within grouping operator: result `value`' +); +assert.sameValue( + result.done, false, 'Within grouping operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following grouping operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following grouping operator: result `done` flag' +); + +iter = g2(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within array literal: result `value`' +); +assert.sameValue( + result.done, false, 'Within array literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following array literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following array literal: result `done` flag' +); + +iter = g3(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within object literal: result `value`' +); +assert.sameValue( + result.done, false, 'Within object literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following object literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following object literal: result `done` flag' +); + +iter = g4(); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'First expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'First expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Second expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'Second expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following comma expression: result `value`' +); +assert.sameValue( + result.done, true, 'Following comma expression: result `done` flag' +); + +iter = g5(); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Conditional expression in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Conditional expression in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Branch in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Branch in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following conditional operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following conditional operator: result `done` flag' +); diff --git a/test/language/expressions/generators/yield-as-function-expression-binding-identifier.js b/test/language/expressions/generators/yield-as-function-expression-binding-identifier.js new file mode 100644 index 0000000000..3cc20907a6 --- /dev/null +++ b/test/language/expressions/generators/yield-as-function-expression-binding-identifier.js @@ -0,0 +1,20 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may be used as the binding identifier of a function expression + within generator bodies. + es6id: 14.1 + flags: [noStrict] + ---*/ + +var result; +var g = function*() { + (function yield() {}); +}; + +result = g().next(); + +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/generators/yield-as-generator-expression-binding-identifier.js b/test/language/expressions/generators/yield-as-generator-expression-binding-identifier.js new file mode 100644 index 0000000000..dc0b188e21 --- /dev/null +++ b/test/language/expressions/generators/yield-as-generator-expression-binding-identifier.js @@ -0,0 +1,12 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is not a valid BindingIdentifier for GeneratorExpressions. + es6id: 12.1.1 + flags: [noStrict] + negative: SyntaxError + ---*/ + +var g = function* yield() {}; diff --git a/test/language/expressions/generators/yield-as-identifier-in-nested-function.js b/test/language/expressions/generators/yield-as-identifier-in-nested-function.js new file mode 100644 index 0000000000..141526e761 --- /dev/null +++ b/test/language/expressions/generators/yield-as-identifier-in-nested-function.js @@ -0,0 +1,21 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is not a reserved keyword within normal function bodies declared + within generator function bodies. + es6id: 12.1.1 + flags: [noStrict] + ---*/ + +var result; +var g = function*() { + function h() { + yield = 1; + } +}; + +result = g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/generators/yield-as-label.js b/test/language/expressions/generators/yield-as-label.js new file mode 100644 index 0000000000..ffc9d4c75a --- /dev/null +++ b/test/language/expressions/generators/yield-as-label.js @@ -0,0 +1,14 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a reserved keyword within generator function bodies and may + not be used as a label. + es6id: 12.1.1 + negative: SyntaxError + ---*/ + +var g = function*() { + yield: 1; +}; diff --git a/test/language/expressions/generators/yield-as-literal-property-name.js b/test/language/expressions/generators/yield-as-literal-property-name.js new file mode 100644 index 0000000000..7d5cfc7a19 --- /dev/null +++ b/test/language/expressions/generators/yield-as-literal-property-name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may be used as a literal property name in an object literal + within generator function bodies. + es6id: 12.1.1 + ---*/ + +var result; +var g = function*() { + ({ get yield() { return 1 } }); +}; + +result = g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/generators/yield-as-logical-or-expression.js b/test/language/expressions/generators/yield-as-logical-or-expression.js new file mode 100644 index 0000000000..1c4264d26e --- /dev/null +++ b/test/language/expressions/generators/yield-as-logical-or-expression.js @@ -0,0 +1,14 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions are not LogicalOrExpressions. + es6id: 12.1.1 + negative: SyntaxError + ---*/ + + +var g = function*() { + yield ? yield : yield; +}; diff --git a/test/language/expressions/generators/yield-as-parameter.js b/test/language/expressions/generators/yield-as-parameter.js new file mode 100644 index 0000000000..8c05503db7 --- /dev/null +++ b/test/language/expressions/generators/yield-as-parameter.js @@ -0,0 +1,12 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a reserved keyword within generator function bodies and may + not be used as the binding identifier of a parameter. + es6id: 12.1.1 + negative: SyntaxError + ---*/ + +var g = function*(yield) {}; diff --git a/test/language/expressions/generators/yield-as-property-name.js b/test/language/expressions/generators/yield-as-property-name.js new file mode 100644 index 0000000000..90feae5313 --- /dev/null +++ b/test/language/expressions/generators/yield-as-property-name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may be used as a literal property name in an object literal + within generator function bodies. + es6id: 12.1.1 + ---*/ + +var result; +var g = function*() { + ({ yield: 1 }); +}; + +result = g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/generators/yield-as-statement.js b/test/language/expressions/generators/yield-as-statement.js new file mode 100644 index 0000000000..30ff098592 --- /dev/null +++ b/test/language/expressions/generators/yield-as-statement.js @@ -0,0 +1,44 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid statement within generator function bodies. + es6id: 14.4 + ---*/ + +var iter, result; +var g1 = function*() { yield; }; +var g2 = function*() { yield 1; }; + +iter = g1(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Without right-hand-side: first result `value`' +); +assert.sameValue( + result.done, false, 'Without right-hand-side: first result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Without right-hand-side: second result `value`' +); +assert.sameValue( + result.done, true, 'Without right-hand-eside: second result `done` flag' +); + +iter = g2(); +result = iter.next(); +assert.sameValue( + result.value, 1, 'With right-hand-side: first result `value`' +); +assert.sameValue( + result.done, false, 'With right-hand-side: first result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'With right-hand-side: second result `value`' +); +assert.sameValue( + result.done, true, 'With right-hand-eside: second result `done` flag' +); diff --git a/test/language/expressions/generators/yield-as-yield-operand.js b/test/language/expressions/generators/yield-as-yield-operand.js new file mode 100644 index 0000000000..7599fcecd5 --- /dev/null +++ b/test/language/expressions/generators/yield-as-yield-operand.js @@ -0,0 +1,28 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions may be used as the right-hand-side of other `yield` + expressions. + es6id: 14.4 + ---*/ + +var iter, result; +var g = function*() { + yield yield 1; +}; + +iter = g(); + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Third result `value`'); +assert.sameValue(result.done, true, 'Thid result `done` flag'); diff --git a/test/language/expressions/generators/yield-newline.js b/test/language/expressions/generators/yield-newline.js new file mode 100644 index 0000000000..f9783c0326 --- /dev/null +++ b/test/language/expressions/generators/yield-newline.js @@ -0,0 +1,24 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + Newlines terminate `yield` expressions. + es6id: 14.4 + ---*/ + +var iter, result; +var g = function*() { + yield + 1 +}; + +iter = g(); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Second result `value`'); +assert.sameValue(result.done, true, 'Second result `done` flag'); diff --git a/test/language/expressions/generators/yield-star-after-newline.js b/test/language/expressions/generators/yield-star-after-newline.js new file mode 100644 index 0000000000..8d407be326 --- /dev/null +++ b/test/language/expressions/generators/yield-star-after-newline.js @@ -0,0 +1,14 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + A newline may not precede the `*` token in a `yield` expression. + es6id: 14.4 + negative: SyntaxError + ---*/ + +var g = function*() { + yield + * 1 +}; diff --git a/test/language/expressions/generators/yield-star-before-newline.js b/test/language/expressions/generators/yield-star-before-newline.js new file mode 100644 index 0000000000..ec28071b97 --- /dev/null +++ b/test/language/expressions/generators/yield-star-before-newline.js @@ -0,0 +1,19 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The right-hand side of a `yield *` expression may appear on a new line. + es6id: 14.4 + ---*/ + +var result; +var g = function*() { + yield * + g2(); +}; +var g2 = function*() {}; + +result = g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/generators/yield-weak-binding.js b/test/language/expressions/generators/yield-weak-binding.js new file mode 100644 index 0000000000..b61a23b3a1 --- /dev/null +++ b/test/language/expressions/generators/yield-weak-binding.js @@ -0,0 +1,11 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions bind weakly + es6id: 14.4 + negative: SyntaxError + ---*/ + +var g = function*() { yield 3 + yield 4; }; diff --git a/test/language/expressions/object/method-definition/generator-no-yield.js b/test/language/expressions/object/method-definition/generator-no-yield.js new file mode 100644 index 0000000000..fd9473de5c --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-no-yield.js @@ -0,0 +1,20 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + Generators declared with GeneratorMethod syntax do not require a + `yield` expression. + features: [generators] + es6id: 14.4 + ---*/ + +var result; +var obj = { + *foo(a) {} +}; + +result = obj.foo(3).next(); + +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/object/method-definition/generator-return.js b/test/language/expressions/object/method-definition/generator-return.js new file mode 100644 index 0000000000..557b09ef44 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-return.js @@ -0,0 +1,23 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `return` is a valid statement within generator function bodies. + features: [generators] + es6id: 14.4 + ---*/ + +var result; +var obj = { + *g1() { return; }, + *g2() { return 1; } +}; + +result = obj.g1().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +result = obj.g2().next(); +assert.sameValue(result.value, 1); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/object/method-definition/yield-as-binding-identifier.js b/test/language/expressions/object/method-definition/yield-as-binding-identifier.js new file mode 100644 index 0000000000..c3199ecc60 --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-binding-identifier.js @@ -0,0 +1,17 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a reserved keyword within generator function bodies and may + not be used as a binding identifier. + features: [generators] + es6id: 12.1.1 + negative: SyntaxError + ---*/ + +var obj = { + *g() { + yield = 1; + } +}; diff --git a/test/language/expressions/object/method-definition/yield-as-expression-with-rhs.js b/test/language/expressions/object/method-definition/yield-as-expression-with-rhs.js new file mode 100644 index 0000000000..a8d48b47f0 --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-expression-with-rhs.js @@ -0,0 +1,118 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid expression within generator function bodies. + features: [generators] + es6id: 14.4 + ---*/ + +var iter, result; +var obj = { + *g1() { (yield 1) }, + *g2() { [yield 1] }, + *g3() { {yield 1} }, + *g4() { yield 1, yield 2; }, + *g5() { (yield 1) ? yield 2 : yield 3; } +}; + +iter = obj.g1(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within grouping operator: result `value`'); +assert.sameValue( + result.done, false, 'Within grouping operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following grouping operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following grouping operator: result `done` flag' +); + +iter = obj.g2(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within array literal: result `value`'); +assert.sameValue( + result.done, false, 'Within array literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following array literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following array literal: result `done` flag' +); + +iter = obj.g3(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within object literal: result `value`'); +assert.sameValue( + result.done, false, 'Within object literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following object literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following object literal: result `done` flag' +); + +iter = obj.g4(); +result = iter.next(); +assert.sameValue( + result.value, 1, 'First expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'First expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, 2, 'Second expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'Second expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following comma expression: result `value`' +); +assert.sameValue( + result.done, true, 'Following comma expression: result `done` flag' +); + +iter = obj.g5(); +result = iter.next(); +assert.sameValue( + result.value, + 1, + 'Conditional expression in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Conditional expression in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + 3, + 'Branch in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Branch in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following conditional operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following conditional operator: result `done` flag' +); diff --git a/test/language/expressions/object/method-definition/yield-as-expression-without-rhs.js b/test/language/expressions/object/method-definition/yield-as-expression-without-rhs.js new file mode 100644 index 0000000000..27f29d9d56 --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-expression-without-rhs.js @@ -0,0 +1,128 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid expression within generator function bodies. + features: [generators] + es6id: 14.4 + ---*/ + +var iter, result; +var obj = { + *g1() { (yield) }, + *g2() { [yield] }, + *g3() { {yield} }, + *g4() { yield, yield; }, + *g5() { (yield) ? yield : yield; } +}; + +iter = obj.g1(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within grouping operator: result `value`' +); +assert.sameValue( + result.done, false, 'Within grouping operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following grouping operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following grouping operator: result `done` flag' +); + +iter = obj.g2(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within array literal: result `value`' +); +assert.sameValue( + result.done, false, 'Within array literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following array literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following array literal: result `done` flag' +); + +iter = obj.g3(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within object literal: result `value`' +); +assert.sameValue( + result.done, false, 'Within object literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following object literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following object literal: result `done` flag' +); + +iter = obj.g4(); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'First expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'First expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Second expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'Second expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following comma expression: result `value`' +); +assert.sameValue( + result.done, true, 'Following comma expression: result `done` flag' +); + +iter = obj.g5(); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Conditional expression in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Conditional expression in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Branch in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Branch in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following conditional operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following conditional operator: result `done` flag' +); diff --git a/test/language/expressions/object/method-definition/yield-as-function-expression-binding-identifier.js b/test/language/expressions/object/method-definition/yield-as-function-expression-binding-identifier.js new file mode 100644 index 0000000000..61071254c8 --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-function-expression-binding-identifier.js @@ -0,0 +1,23 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may be used as the binding identifier of a function expression + within generator bodies. + features: [generators] + es6id: 14.1 + flags: [noStrict] + ---*/ + +var result; +var obj = { + *g() { + (function yield() {}); + } +}; + +result = A.prototype.g().next(); + +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/object/method-definition/yield-as-generator-method-binding-identifier.js b/test/language/expressions/object/method-definition/yield-as-generator-method-binding-identifier.js new file mode 100644 index 0000000000..d239c9a7f5 --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-generator-method-binding-identifier.js @@ -0,0 +1,30 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid BindingIdentifier for GeneratorMethods outside of + strict mode. + features: [generators] + es6id: 12.1.1 + flags: [noStrict] + ---*/ + +var iter, result; +var obj = { + *yield() { (yield 3) + (yield 4); } +} + +iter = obj.yield(); + +result = iter.next(); +assert.sameValue(result.value, 3, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 4, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Third result `value`'); +assert.sameValue(result.done, true, 'Third result `done` flag');; diff --git a/test/language/expressions/object/method-definition/yield-as-identifier-in-nested-function.js b/test/language/expressions/object/method-definition/yield-as-identifier-in-nested-function.js new file mode 100644 index 0000000000..82ff77b099 --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-identifier-in-nested-function.js @@ -0,0 +1,24 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is not a reserved keyword within normal function bodies declared + within generator function bodies. + features: [generators] + es6id: 12.1.1 + flags: [noStrict] + ---*/ + +var result; +var obj = { + *g() { + function h() { + yield = 1; + } + } +}; + +result = obj.g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/object/method-definition/yield-as-label.js b/test/language/expressions/object/method-definition/yield-as-label.js new file mode 100644 index 0000000000..7bfc52d601 --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-label.js @@ -0,0 +1,17 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a reserved keyword within generator function bodies and may + not be used as a label. + features: [generators] + es6id: 12.1.1 + negative: SyntaxError + ---*/ + +var obj = { + *g() { + yield: 1; + } +}; diff --git a/test/language/expressions/object/method-definition/yield-as-literal-property-name.js b/test/language/expressions/object/method-definition/yield-as-literal-property-name.js new file mode 100644 index 0000000000..2125e2aa9c --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-literal-property-name.js @@ -0,0 +1,21 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may be used as a literal property name in an object literal + within generator function bodies. + features: [generators] + es6id: 12.1.1 + ---*/ + +var result; +var obj = { + *g() { + ({ get yield() { return 1 } }); + } +}; + +result = obj.g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/object/method-definition/yield-as-logical-or-expression.js b/test/language/expressions/object/method-definition/yield-as-logical-or-expression.js new file mode 100644 index 0000000000..922ca27a0e --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-logical-or-expression.js @@ -0,0 +1,16 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions are not LogicalOrExpressions. + features: [generators] + es6id: 12.1.1 + negative: SyntaxError + ---*/ + +var obj = { + *g() { + yield ? yield : yield; + } +}; diff --git a/test/language/expressions/object/method-definition/yield-as-parameter.js b/test/language/expressions/object/method-definition/yield-as-parameter.js new file mode 100644 index 0000000000..a5edb6c440 --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-parameter.js @@ -0,0 +1,15 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a reserved keyword within generator function bodies and may + not be used as the binding identifier of a parameter. + features: [generators] + es6id: 12.1.1 + negative: SyntaxError + ---*/ + +var obj = { + *g(yield) {} +}; diff --git a/test/language/expressions/object/method-definition/yield-as-property-name.js b/test/language/expressions/object/method-definition/yield-as-property-name.js new file mode 100644 index 0000000000..84d6b42bb5 --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-property-name.js @@ -0,0 +1,21 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may be used as a literal property name in an object literal + within generator function bodies. + features: [generators] + es6id: 12.1.1 + ---*/ + +var result; +var obj = { + *g() { + ({ yield: 1 }); + } +}; + +result = obj.g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/object/method-definition/yield-as-statement.js b/test/language/expressions/object/method-definition/yield-as-statement.js new file mode 100644 index 0000000000..717030e4aa --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-statement.js @@ -0,0 +1,47 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid statement within generator function bodies. + features: [generators] + es6id: 14.4 + ---*/ + +var iter, result; +var obj = { + *g1() { yield; }, + *g2() { yield 1; } +}; + +iter = obj.g1(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Without right-hand-side: first result `value`' +); +assert.sameValue( + result.done, false, 'Without right-hand-side: first result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Without right-hand-side: second result `value`' +); +assert.sameValue( + result.done, true, 'Without right-hand-eside: second result `done` flag' +); + +iter = obj.g2(); +result = iter.next(); +assert.sameValue( + result.value, 1, 'With right-hand-side: first result `value`' +); +assert.sameValue( + result.done, false, 'With right-hand-side: first result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'With right-hand-side: second result `value`' +); +assert.sameValue( + result.done, true, 'With right-hand-eside: second result `done` flag' +); diff --git a/test/language/expressions/object/method-definition/yield-as-yield-operand.js b/test/language/expressions/object/method-definition/yield-as-yield-operand.js new file mode 100644 index 0000000000..b1c0c7950e --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-as-yield-operand.js @@ -0,0 +1,31 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions may be used as the right-hand-side of other `yield` + expressions. + features: [generators] + es6id: 14.4 + ---*/ + +var iter, result; +var obj = { + *g() { + yield yield 1; + } +}; + +iter = obj.g(); + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Third result `value`'); +assert.sameValue(result.done, true, 'Thid result `done` flag'); diff --git a/test/language/expressions/object/method-definition/yield-newline.js b/test/language/expressions/object/method-definition/yield-newline.js new file mode 100644 index 0000000000..b8b2f16e8e --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-newline.js @@ -0,0 +1,27 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + Newlines terminate `yield` expressions. + features: [generators] + es6id: 14.4 + ---*/ + +var iter, result; +var obj = { + *g() { + yield + 1 + } +}; + +iter = obj.g(); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Second result `value`'); +assert.sameValue(result.done, true, 'Second result `done` flag'); diff --git a/test/language/expressions/object/method-definition/yield-star-after-newline.js b/test/language/expressions/object/method-definition/yield-star-after-newline.js new file mode 100644 index 0000000000..820a60d2f8 --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-star-after-newline.js @@ -0,0 +1,17 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + A newline may not precede the `*` token in a `yield` expression. + features: [generators] + es6id: 14.4 + negative: SyntaxError + ---*/ + +var obj = { + *g() { + yield + * 1 + } +}; diff --git a/test/language/expressions/object/method-definition/yield-star-before-newline.js b/test/language/expressions/object/method-definition/yield-star-before-newline.js new file mode 100644 index 0000000000..a932428d9b --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-star-before-newline.js @@ -0,0 +1,22 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The right-hand side of a `yield *` expression may appear on a new line. + features: [generators] + es6id: 14.4 + ---*/ + +var result; +var obj = { + *g() { + yield * + g2() + } +}; +var g2 = function*() {}; + +result = obj.g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); diff --git a/test/language/expressions/object/method-definition/yield-weak-binding.js b/test/language/expressions/object/method-definition/yield-weak-binding.js new file mode 100644 index 0000000000..6e40c6684d --- /dev/null +++ b/test/language/expressions/object/method-definition/yield-weak-binding.js @@ -0,0 +1,14 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions bind weakly + features: [generators] + es6id: 14.4 + negative: SyntaxError + ---*/ + +var obj = { + *g() { yield 3 + yield 4; } +};