Import tests from Google V8 (generator syntax)

These tests are derived from the following files within the Google V8
project:

    test/mjsunit/es6/generators-parsing.js
This commit is contained in:
Mike Pennisi 2015-03-17 13:50:15 -04:00
parent 2df6c4f219
commit 93d994df0f
23 changed files with 302 additions and 0 deletions

View File

@ -0,0 +1,13 @@
// 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 identifier in strict mode code and may not be used
as an identifier.
es6id: 12.1.1
negative: SyntaxError
flags: [onlyStrict]
---*/
var yield = 13;

View File

@ -0,0 +1,10 @@
// 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.
es6id: 12.1.1
---*/
({ yield: 1 });

View File

@ -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 reserved identifier in non-strict mode code and may be
used as a label.
es6id: 12.1.1
flags: [noStrict]
---*/
yield: 1;

View File

@ -0,0 +1,13 @@
// 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 identifier in strict mode code and may not be used
as a label.
es6id: 12.1.1
negative: SyntaxError
flags: [onlyStrict]
---*/
yield: 1;

View File

@ -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: >
Generators declared with GeneratorDeclaration syntax do not require a
`yield` expression.
es6id: 14.4
---*/
function *foo(a) {}
var g = foo(3);
assert.sameValue(g.next().value, undefined);
assert.sameValue(g.next().done, true);

View File

@ -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: >
`return` is a valid statement within generator function bodies.
es6id: 14.4
---*/
function* g() { return; }
function* g() { return 1; }

View File

@ -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
---*/
function* g() {
yield = 1;
}

View File

@ -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 valid expression within generator function bodies.
es6id: 14.4
---*/
function* g() { (yield 1) }
function* g() { [yield 1] }
function* g() { {yield 1} }
function* g() { yield 1, yield 1; }
function* g() { (yield 1) ? yield 1 : yield 1 }

View File

@ -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 valid expression within generator function bodies.
es6id: 14.4
---*/
function* g() { (yield) }
function* g() { [yield] }
function* g() { {yield} }
function* g() { yield, yield; }
function* g() { (yield) ? yield : yield }

View File

@ -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` may be used as the binding identifier of a function expression
within generator bodies.
es6id: 14.1
flags: [noStrict]
---*/
function* g() {
(function yield() {})
}

View File

@ -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 valid BindingIdentifier for GeneratorDeclarations outside of
strict mode.
es6id: 12.1.1
flags: [noStrict]
---*/
function* yield() { (yield 3) + (yield 4); }

View File

@ -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` is not a reserved keyword within normal function bodies declared
within generator function bodies.
es6id: 12.1.1
flags: [noStrict]
---*/
function* g() {
function h() {
yield = 1;
}
}

View File

@ -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
---*/
function* g() {
yield: 1;
}

View File

@ -0,0 +1,13 @@
// 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
---*/
function* g() {
({ get yield() { return 1 } });
}

View File

@ -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
---*/
function* g() {
yield ? yield : yield
}

View File

@ -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
---*/
function* g(yield) {}

View File

@ -0,0 +1,13 @@
// 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
---*/
function* g() {
({ yield: 1 });
}

View File

@ -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` is a valid statement within generator function bodies.
es6id: 14.4
---*/
function* g() { yield; }
function* g() { yield 1; }

View File

@ -0,0 +1,13 @@
// 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
---*/
function* g() {
yield yield 1;
}

View File

@ -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: >
Newlines terminate `yield` expressions.
es6id: 14.4
---*/
function* g() {
yield
1
}
assert.sameValue(g().next().value, undefined);

View File

@ -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
---*/
function* g() {
yield
* 1
}

View File

@ -0,0 +1,13 @@
// 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
---*/
function* g() {
yield *
1
}

View File

@ -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
---*/
function* g() { yield 3 + yield 4; }