Import tests from Google V8 (generators semantics)

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

    test/mjsunit/es6/generators-iteration.js
    test/mjsunit/es6/generators-objects.js
    test/mjsunit/es6/generators-runtime.js
    test/mjsunit/es6/generators-states.js
This commit is contained in:
Mike Pennisi 2015-03-20 11:23:38 -04:00
parent 5188ab028a
commit 779a59f30c
64 changed files with 1781 additions and 0 deletions

View File

@ -0,0 +1,33 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2
description: >
Generator function instances are correctly reported as instances of the
GeneratorFunction intrinsic.
---*/
var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;
function* gDecl() {}
var gExpr = function* () {};
assert(
gDecl instanceof GeneratorFunction,
'Generators created via GeneratorDeclaration syntax are proper instances of GeneratorFunction'
);
assert(
gExpr instanceof GeneratorFunction,
'Generators created via GeneratorExpression syntax are proper instances of GeneratorFunction'
);
assert(
new GeneratorFunction() instanceof GeneratorFunction,
'Generators created via constructor invocation of GeneratorFunction are proper instances of GeneratorFunction'
);
assert(
GeneratorFunction() instanceof GeneratorFunction,
'Generators created via function invocation of GeneratorFunction are proper instances of GeneratorFunction'
);

View File

@ -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.
/*---
es6id: 25.2
description: >
When invoked via the constructor invocation pattern without arguments, the
GeneratorFunction intrinsic returns a valid generator with an empty body.
---*/
var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;
var g = new GeneratorFunction();
var iter = g();
var result = iter.next();
assert.sameValue(result.value, undefined, 'Result `value`');
assert.sameValue(result.done, true, 'Result `done` flag');

View File

@ -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.
/*---
es6id: 25.2
description: >
When invoked via the function invocation pattern with multiple arguments,
the GeneratorFunction intrinsic creates a valid generator whose body is the
last argument evaluated as source code and whose formal parameters are
defined by the preceeding arguments.
---*/
var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;
var g = GeneratorFunction('x', 'y', 'yield x + y;');
var iter = g(2, 3);
var result;
result = iter.next();
assert.sameValue(result.value, 5, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -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.
/*---
es6id: 25.2
description: >
When invoked via the function invocation pattern without arguments, the
GeneratorFunction intrinsic returns a valid generator with an empty body.
---*/
var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;
var g = GeneratorFunction();
var iter = g();
var result = iter.next();
assert.sameValue(result.value, undefined, 'Result `value`');
assert.sameValue(result.done, true, 'Result `done` flag');

View File

@ -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.
/*---
es6id: 25.2
description: >
When invoked via the function invocation pattern with a single argument,
the GeneratorFunction intrinsic creates a valid generator whose body is the
first argument evaluated as source code.
---*/
var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;
var g = GeneratorFunction('yield 1;');
var iter = g();
var result;
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, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -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: >
The GeneratorPrototype intrinsic should define a `constructor` property
that is non-enumerable, non-writable, and configurable.
includes: [propertyHelper.js]
es6id: 25.3.1
---*/
function* g() {}
var Generator = Object.getPrototypeOf(g);
var GeneratorPrototype = Generator.prototype;
assert.sameValue(GeneratorPrototype.constructor, Generator);
verifyNotEnumerable(GeneratorPrototype, 'constructor');
verifyNotWritable(GeneratorPrototype, 'constructor');
verifyConfigurable(GeneratorPrototype, 'constructor');

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.
/*---
es6id: 25.2.3.2
description: >
The value of GeneratorFunction.prototype.prototype is the
%GeneratorPrototype% intrinsic object.
---*/
assert.sameValue(
Object.getPrototypeOf(function*() {}).prototype,
Object.getPrototypeOf(function*() {}.prototype)
);

View File

@ -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 GeneratorFunctionPrototype defines an `@@toStringTag` property.
es6id: 25.2.3.3
includes: [propertyHelper.js]
---*/
var GeneratorFunctionPrototype = Object.getPrototypeOf(function*() {});
assert.sameValue(
GeneratorFunctionPrototype[Symbol.toStringTag], 'GeneratorFunction'
);
verifyNotEnumerable(GeneratorFunctionPrototype, Symbol.toStringTag);
verifyNotWritable(GeneratorFunctionPrototype, Symbol.toStringTag);
verifyConfigurable(GeneratorFunctionPrototype, Symbol.toStringTag);

View File

@ -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 Generator prototype defines a `@@toStringTag` attribute.
es6id: 25.3.1.5
includes: [propertyHelper.js]
---*/
var GeneratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf(function*() {}())
);
assert.sameValue(GeneratorPrototype[Symbol.toStringTag], 'Generator');
verifyNotEnumerable(GeneratorPrototype, Symbol.toStringTag);
verifyNotWritable(GeneratorPrototype, Symbol.toStringTag);
verifyConfigurable(GeneratorPrototype, Symbol.toStringTag);

View File

@ -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.
/*---
es6id: 25.2
description: >
When a generator body contains two consecutive yield statements, it should
produce an iterable that visits each yielded value and then completes.
---*/
function* g() { yield 1; yield 2; }
var iter = g();
var result;
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, 2, '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');

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.
/*---
es6id: 25.2
description: >
If the generator was invoked using [[Construct]], the this bind is not
initialized and any references to `this` within the FunctionBody will
produce a ReferenceError exception.
---*/
function* g() { this; }
var iter = new g();
assert.throws(ReferenceError, function() {
iter.next();
});

View File

@ -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.
/*---
es6id: 25.2
description: >
When a generator function is invoked as a method of an object, its context
is that object.
---*/
var context;
function* g() { context = this; }
var obj = { g: g };
var iter = obj.g();
iter.next();
assert.sameValue(context, obj);

View File

@ -0,0 +1,25 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.3.2
description: >
A TypeError should be thrown if the generator is resumed while running.
---*/
var iter;
function* withoutVal() {
iter.next();
}
function* withVal() {
iter.next(42);
}
iter = withoutVal();
assert.throws(TypeError, function() {
iter.next();
});
iter = withVal();
assert.throws(TypeError, function() {
iter.next();
});

View File

@ -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.
/*---
es6id: 25.3.1.2
description: >
A TypeError should be thrown from GeneratorValidate (25.3.3.2) if the
context of `next` does not defined the [[GeneratorState]] internal slot.
---*/
function* g() {}
var GeneratorPrototype = Object.getPrototypeOf(g).prototype;
assert.throws(TypeError, function() { GeneratorPrototype.next.call(1); });
assert.throws(TypeError, function() { GeneratorPrototype.next.call(1, 1); });
assert.throws(TypeError, function() { GeneratorPrototype.next.call({}); });
assert.throws(TypeError, function() { GeneratorPrototype.next.call({}, 1); });
assert.throws(TypeError, function() { GeneratorPrototype.next.call(function() {}); });
assert.throws(TypeError, function() { GeneratorPrototype.next.call(function() {}, 1); });
assert.throws(TypeError, function() { GeneratorPrototype.next.call(g); });
assert.throws(TypeError, function() { GeneratorPrototype.next.call(g, 1); });
assert.throws(TypeError, function() { GeneratorPrototype.next.call(g.prototype); });
assert.throws(TypeError, function() { GeneratorPrototype.next.call(g.prototype, 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.
/*---
es6id: 25.2
description: >
When a generator body contains a lone return statement, it should produce
an iterator that immediately completes with the returned value.
---*/
function* g() { return 23; }
var iter = g();
var result;
result = iter.next();
assert.sameValue(result.value, 23, 'Result value');
assert.sameValue(result.done, true, 'Result `done` flag');

View File

@ -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.
/*---
es6id: 25.2
description: >
When a generator body contains a lone yield statement, it should produce an
iterable that visits the yielded value and then completes.
---*/
function* g() { yield 1; }
var iter = g();
var result;
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, true, 'Second result `done` flag');

View File

@ -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.
/*---
es6id: 25.2
description: >
When a generator body contains no control flow statements, it should
produce an iterator that is initially completed with `undefined` as its
value.
---*/
function* g() {}
var iter = g();
var result;
result = iter.next();
assert.sameValue(result.value, undefined, 'First result `value`');
assert.sameValue(result.done, true, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, undefined, 'Second result `value`');
assert.sameValue(result.done, true, 'Second result `done` flag');

View File

@ -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: >
The GeneratorPrototype intrinsic should define a `next` property that is
non-enumerable, writable, and configurable (as per section 17).
includes: [propertyHelper.js]
es6id: 25.3.1
---*/
function* g() {}
var GeneratorPrototype = Object.getPrototypeOf(g).prototype;
verifyNotEnumerable(GeneratorPrototype, 'next');
verifyWritable(GeneratorPrototype, 'next');
verifyConfigurable(GeneratorPrototype, 'next');

View File

@ -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.
/*---
es6id: 25.2
description: >
The `next` method returns an object that has "own" properties `value` and
`done` and that inherits directly from the Object prototype.
---*/
function* g() {}
var result = g().next();
assert(
Object.hasOwnProperty.call(result, 'value'), 'Has "own" property `value`'
);
assert(
Object.hasOwnProperty.call(result, 'done'), 'Has "own" property `done`'
);
assert.sameValue(Object.getPrototypeOf(result), Object.prototype);

View File

@ -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.
/*---
es6id: 25.2
description: >
Yield expressions are valid yield expression operands.
---*/
function* g() {
return yield 1;
}
var iter = g();
var result;
result = iter.next();
assert.sameValue(result.value, 1, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
result = iter.next(3);
assert.sameValue(result.value, 3, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
Resuming abuptly from a generator in the 'completed' state should honor the
abrupt completion and remain in the 'completed' state.
---*/
function E() {}
function* G() {}
var iter;
iter = G();
iter.next();
assert.throws(E, function() { iter.throw(new E()); });
result = iter.next();
assert.sameValue(result.value, undefined, 'Result `value`');
assert.sameValue(result.done, true, 'Result `done` flag');

View File

@ -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.
/*---
es6id: 25.3.3.2
description: >
A TypeError should be thrown if the generator is resumed abruptly while
running.
---*/
var iter;
function* g() {
iter.throw(42);
}
iter = g();
assert.throws(TypeError, function() {
iter.next();
});

View File

@ -0,0 +1,24 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
Resuming abuptly from a generator in the 'suspendedStart' state should
honor the abrupt completion and trigger a transition into the 'completed'
state.
---*/
function E() {}
function* G() {
yield 1;
yield 2;
}
var iter;
iter = G();
assert.throws(E, function() { iter.throw(new E()); });
result = iter.next();
assert.sameValue(result.value, undefined, 'Result `value`');
assert.sameValue(result.done, true, 'Result `done` flag');

View File

@ -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.
/*---
es6id: 25.3.1.4
description: >
A TypeError should be thrown from GeneratorValidate (25.3.3.2) if the
context of `throw` does not defined the [[GeneratorState]] internal slot.
---*/
function* g() {}
var GeneratorPrototype = Object.getPrototypeOf(g).prototype;
assert.throws(TypeError, function() { GeneratorPrototype.throw.call(1); });
assert.throws(TypeError, function() { GeneratorPrototype.throw.call({}); });
assert.throws(TypeError, function() { GeneratorPrototype.throw.call(function() {}); });
assert.throws(TypeError, function() { GeneratorPrototype.throw.call(g); });
assert.throws(TypeError, function() { GeneratorPrototype.throw.call(g.prototype); });

View File

@ -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: >
The GeneratorPrototype intrinsic should define a `throw` property that is
non-enumerable, writable, and configurable (as per section 17).
includes: [propertyHelper.js]
es6id: 25.3.1
---*/
function* g() {}
var GeneratorPrototype = Object.getPrototypeOf(g).prototype;
verifyNotEnumerable(GeneratorPrototype, 'throw');
verifyWritable(GeneratorPrototype, 'throw');
verifyConfigurable(GeneratorPrototype, 'throw');

View File

@ -0,0 +1,35 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused before a `try..catch` statement, `throw` should
interrupt control flow as if a `throw` statement had appeared at that
location in the function body.
---*/
function* g() {
yield 1;
try {
yield 2;
} catch (e) {
yield e;
}
yield 3;
}
var iter, result, exception;
iter = g();
result = iter.next();
assert.sameValue(result.value, 1, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
assert.throws(Test262Error, function() { iter.throw(new Test262Error()); });
result = iter.next();
assert.sameValue(result.value,
undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -0,0 +1,43 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
When a generator is puased after a `try..catch` statement, `throw` should
interrupt control flow as if a `throw` statement had appeared at that
location in the function body.
---*/
function* g() {
yield 1;
try {
yield 2;
} catch (e) {
yield e;
}
yield 3;
}
var iter, result, exception;
exception = new Test262Error();
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.throw(exception);
assert.sameValue(result.value, exception, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
assert.throws(Test262Error, function() { iter.throw(new Test262Error()); });
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -0,0 +1,49 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused within the `catch` block of a `try..catch`
statement, `throw` should interrupt control flow as if a `throw` statement
had appeared at that location in the function body.
---*/
function* g() {
yield 1;
try {
yield 2;
throw exception;
} catch (e) {
yield e;
}
yield 3;
}
var iter, result, exception;
exception = new Test262Error();
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, exception, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(result.value, 3, 'Fourth result `value`');
assert.sameValue(result.done, false, 'Fourth result `done` flag');
assert.throws(Test262Error, function() { iter.throw(new Test262Error()); });
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -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.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused within the `try` block of a `try..catch`
statement, `throw` should interrupt control flow as if a `throw` statement
had appeared at that location in the function body.
---*/
function* g() {
yield 1;
try {
yield 2;
} catch (e) {
yield e;
}
yield 3;
}
var iter, result, exception;
exception = new Test262Error();
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.throw(exception);
assert.sameValue(result.value, exception, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(result.value, 3, 'Fourth result `done` flag');
assert.sameValue(result.done, false, 'Fourth result `value`');
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -0,0 +1,38 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused before a `try..finally` statement, `throw`
should interrupt control flow as if a `throw` statement had appeared at
that location in the function body.
---*/
function* g() {
yield 1;
try {
yield 2;
} finally {
yield 3;
}
yield 4;
}
var iter, result;
iter = g();
result = iter.next();
assert.sameValue(result.value, 1, 'First result `value`');
assert.sameValue(
result.done, false, 'First result `done` flag'
);
assert.throws(Test262Error, function() { iter.throw(new Test262Error()); });
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue( result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -0,0 +1,43 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused after a `try..finally` statement, `throw` should
interrupt control flow as if a `throw` statement had appeared at that
location in the function body.
---*/
function* g() {
yield 1;
try {
yield 2;
} finally {
yield 3;
}
yield 4;
}
var iter = g();
var result;
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.throw(new Error());
assert.sameValue(result.value, 3, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
assert.throws(Test262Error, function() { iter.throw(new Test262Error()); });
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -0,0 +1,55 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused within a `catch` block that is declared within a
`try` block of a `try..catch` statement, `throw` should interrupt control
flow as if a `throw` statement had appeared at that location in the
function body.
---*/
function* g() {
try {
yield 1;
try {
yield 2;
throw exception;
} catch (e) {
yield e;
}
yield 3;
} finally {
yield 4;
}
yield 5;
}
var exception = new Error();
var iter = g();
var result;
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, exception, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.throw(new Test262Error());
assert.sameValue(result.value, 4, 'Fourth result `value`');
assert.sameValue(result.done, false, 'Fourth result `done` flag');
assert.throws(Test262Error, function() { iter.next(); });
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -0,0 +1,45 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused within a `finally` block of a `try..catch`
statement, `throw` should interrupt control flow as if a `throw` statement
had appeared at that location in the function body.
---*/
function* g() {
try {
yield 1;
throw new Error();
try {
yield 2;
} catch (e) {
yield e;
}
yield 3;
} finally {
yield 4;
}
yield 5;
}
var iter = g();
var result;
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, 4, 'Second result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
assert.throws(Test262Error, function() { iter.throw(new Test262Error()); });
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -0,0 +1,60 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused within a `try` block that is declared within a
`try` block of a `try..catch` statement, `throw` should interrupt control
flow as if a `throw` statement had appeared at that location in the
function body.
---*/
function* g() {
try {
yield 1;
try {
yield 2;
} catch (e) {
yield e;
}
yield 3;
} finally {
yield 4;
}
yield 5;
}
var iter = g();
var exception = new Error();
var result;
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.throw(exception);
assert.sameValue(result.value, exception, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(result.value, 3, 'Fourth result `value');
assert.sameValue(result.done, false, 'Fourth result `done` flag');
result = iter.next();
assert.sameValue(result.value, 4, 'Fifth result `value`');
assert.sameValue(result.done, false, 'Firth result `done` flag');
result = iter.next();
assert.sameValue(result.value, 5, 'Sixth result `value`');
assert.sameValue(result.done, false, 'Sixth result `done` flag');
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -0,0 +1,59 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused within a `try` block of a `try..catch` statement
and following a nested `try..catch` statment, `throw` should interrupt
control flow as if a `throw` statement had appeared at that location in the
function body.
---*/
function* g() {
try {
yield 1;
try {
yield 2;
throw exception;
} catch (e) {
yield e;
}
yield 3;
} finally {
yield 4;
}
yield 5;
}
var exception = new Error();
var iter = g();
var result;
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, exception, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(result.value, 3, 'Fourth result `value`');
assert.sameValue(result.done, false, 'Fourth result `done` flag');
result = iter.throw(new Test262Error());
assert.sameValue(result.value, 4, 'Fifth result `value`');
assert.sameValue(result.done, false, 'Fifth result `done` flag');
assert.throws(Test262Error, function() { iter.next(); });
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -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.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused within a `try` block of a `try..catch` statement
and before a nested `try..catch` statement, `throw` should interrupt
control flow as if a `throw` statement had appeared at that location in the
function body.
---*/
function* g() {
try {
yield 1;
try {
yield 2;
} catch (e) {
yield e;
}
yield 3;
} finally {
yield 4;
}
yield 5;
}
var iter = g();
var result;
iter = g();
result = iter.next();
assert.sameValue(result.value, 1, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
result = iter.throw(new Test262Error());
assert.sameValue(result.value, 4, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
assert.throws(Test262Error, function() { iter.next(); });
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -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.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused within the `finally` block of a `try..finally`
statement, `throw` should interrupt control flow as if a `throw` statement
had appeared at that location in the function body.
---*/
function* g() {
yield 1;
try {
yield 2;
} finally {
yield 3;
}
yield 4;
}
var iter = g();
var result;
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, 3, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(result.value, 4, 'Fourth result `value`');
assert.sameValue(result.done, false, 'Fourth result `done` flag');
assert.throws(Test262Error, function() { iter.throw(new Test262Error()); });
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

View File

@ -0,0 +1,43 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.3.1.4
description: >
When a generator is paused within a `try` block of a `try..finally`
statement, `throw` should interrupt control flow as if a `throw` statement
had appeared at that location in the function body.
---*/
function* g() {
yield 1;
try {
yield 2;
} finally {
yield 3;
}
yield 4;
}
var iter = g();
var result;
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, 3, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
assert.throws(Test262Error, function() { iter.throw(new Test262Error()); });
result = iter.next();
assert.sameValue(
result.value, undefined, 'Result `value` is undefined when done'
);
assert.sameValue(result.done, true, 'Result `done` flag is `true` when done');
iter.next();

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.
/*---
es6id: 25.2.4.2
description: >
The `prototype` property of GeneratorFunction instances are created as
plain objects with no "own" properties.
---*/
var ownProperties = Object.getOwnPropertyNames(function*() {}.prototype);
assert.sameValue(ownProperties.length, 0);

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: >
GeneratorFunction instances are created with a unique prototype object.
es6id: 25.2.1
---*/
var g1 = function*() {};
var g2 = function*() {};
assert(g1.prototype !== g2.prototype);

View File

@ -0,0 +1,40 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2
description: >
Attributes of the `arguments` object are valid yield expression operands.
---*/
function* g() {
yield arguments[0];
yield arguments[1];
yield arguments[2];
yield arguments[3];
}
var iter = g(23, 45, 33);
var result;
result = iter.next();
assert.sameValue(result.value, 23, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
result = iter.next();
assert.sameValue(result.value, 45, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, 33, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(
result.value, undefined, 'Fourth result `value` (unspecified parameter)'
);
assert.sameValue(
result.done, false, 'Fourth result `done` flag (unspecified parameter)'
);
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -0,0 +1,35 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2
description: >
Free variables captured within the GeneratorFunction closure are valid
yield expression operands.
---*/
var a = 1;
var b = 2;
var c = 3;
function* g() {
yield a;
yield b;
yield c;
}
var iter = g();
var result;
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, 3, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -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.
/*---
es6id: 25.2
description: >
When the `next` method of a generator-produced iterable is invoked without
an argument, the corresponding `yield` expression should be evaluated as
`undefined`.
---*/
function* g() { actual = yield; }
var expected = {};
var iter = g();
var actual, result;
result = iter.next();
assert.sameValue(result.value, undefined, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
assert.sameValue(
actual, undefined, 'Value of `yield` expression (prior to continuation)'
);
result = iter.next(expected);
assert.sameValue(result.value, undefined, 'Second result `value`');
assert.sameValue(result.done, true, 'Second result `done` flag');
assert.sameValue(
actual, expected, 'Value of `yield` expression (following continuation)'
);

View File

@ -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.
/*---
es6id: 25.2
description: >
When the `next` method of a generator-produced iterable is invoked without
an argument, the corresponding `yield` expression should be evaluated as
`undefined`.
---*/
function* g() { actual = yield; }
var iter = g();
var actual, result;
result = iter.next();
assert.sameValue(result.value, undefined);
assert.sameValue(result.done, false);
assert.sameValue(actual, undefined);
result = iter.next();
assert.sameValue(result.value, undefined);
assert.sameValue(result.done, true);
assert.sameValue(actual, undefined);

View File

@ -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.
/*---
es6id: 25.2
description: >
Formal parameters are valid yield expression operands.
flags: [noStrict]
---*/
function* g(a, b, c, d) {
arguments[0] = 32;
arguments[1] = 54;
arguments[2] = 333;
yield a;
yield b;
yield c;
yield d;
}
var iter = g(23, 45, 33);
var result;
result = iter.next();
assert.sameValue(result.value, 32, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
result = iter.next();
assert.sameValue(result.value, 54, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, 333, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(
result.value, undefined, 'Fourth result `value` (unspecified parameter)'
);
assert.sameValue(
result.done, false, 'Fourth result `done` flag (unspecified parameter)'
);
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -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.
/*---
es6id: 25.2
description: >
Formal parameters are valid yield expression operands.
flags: [onlyStrict]
---*/
function* g(a, b, c, d) {
arguments[0] = 32;
arguments[1] = 54;
arguments[2] = 333;
yield a;
yield b;
yield c;
yield d;
}
var iter = g(23, 45, 33);
var result;
result = iter.next();
assert.sameValue(result.value, 23, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
result = iter.next();
assert.sameValue(result.value, 45, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, 33, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(
result.value, undefined, 'Fourth result `value` (unspecified parameter)'
);
assert.sameValue(
result.done, false, 'Fourth result `done` flag (unspecified parameter)'
);
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -0,0 +1,40 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2
description: >
Formal parameters are valid yield expression operands.
---*/
function* g(a, b, c, d) {
yield a;
yield b;
yield c;
yield d;
}
var iter = g(23, 45, 33);
var result;
result = iter.next();
assert.sameValue(result.value, 23, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
result = iter.next();
assert.sameValue(result.value, 45, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, 33, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(
result.value, undefined, 'Fourth result `value` (unspecified parameter)'
);
assert.sameValue(
result.done, false, 'Fourth result `done` flag (unspecified parameter)'
);
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -0,0 +1,26 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2
description: >
The behavior of `yield` expressions should not be affected when they appear
within the `catch` block of `try` statements.
---*/
function* g() {
try {
throw new Error();
} catch (err) {
yield 1;
}
}
var iter = g();
var result;
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, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done`flag');

View File

@ -0,0 +1,26 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2
description: >
The behavior of `yield` expressions should not be affected when they appear
within the `try` block of `try` statements.
---*/
function* g() {
try {
yield 1;
} catch (err) {
throw err;
}
}
var iter = g();
var result;
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, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done`flag');

View File

@ -0,0 +1,38 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2
description: >
The operand to a `yield` expression should honor the semantics of the
`with` statement.
---*/
function* g() {
var x = 1;
yield x;
with ({ x: 2 }) {
yield x;
}
yield x;
}
var iter = g();
var result;
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, 1, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -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.
/*---
es6id: 25.2
description: >
When an array is the operand of a `yield *` expression, the generator
should produce an iterator that visits each element in order.
---*/
function* g() {
yield* [1, 2, 3];
}
var iter = g();
var result;
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, 2, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, 3, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -0,0 +1,39 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2
description: >
When an iterator is the operand of a `yield *` expression, the generator
should produce an iterator that visits each iterated item.
---*/
var results = [{ value: 1 }, { value: 8 }, { value: 34, done: true }];
var idx = 0;
var iterator = {};
var iterable = {
next: function() {
var result = results[idx];
idx += 1;
return result;
}
};
iterator[Symbol.iterator] = function() {
return iterable;
};
function* g() {
yield* iterator;
}
var iter = g();
var result;
result = iter.next();
assert.sameValue(result.value, 1, 'First result `value`');
assert.sameValue(result.done, undefined, 'First result `done` flag');
result = iter.next();
assert.sameValue(result.value, 8, 'Third result `value`');
assert.sameValue(result.done, undefined, 'Third result `done` flag');
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -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.
/*---
es6id: 25.2
description: >
When a string is the operand of a `yield *` expression, the generator
should produce an iterator that visits each character in order.
---*/
function* g() {
yield* 'abc';
}
var iter = g();
var result;
result = iter.next();
assert.sameValue(result.value, 'a', 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
result = iter.next();
assert.sameValue(result.value, 'b', 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, 'c', 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -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.
/*---
es6id: 25.2
description: >
When a generator body contains a yield statement followed by a return
statement, it should produce an iterator that visits the yieled value and
completes on the returned value.
---*/
function* g() { yield 1; return 2; }
var iter = g();
var result;
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, 2, 'Second result `value`');
assert.sameValue(result.done, true, 'Second result `done` flag');

View File

@ -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.
/*---
es6id: 25.2
description: >
`yield` expressions should suspend `for` loop iteration.
---*/
function* g() {
for (var idx = 0; idx < 3; idx++) {
yield idx;
}
}
var iter = g();
var result;
result = iter.next();
assert.sameValue(result.value, 0, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
result = iter.next();
assert.sameValue(result.value, 1, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, 2, 'Third result `value`');
assert.sameValue(result.done, false, 'Third result `done` flag');
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done` flag');

View File

@ -0,0 +1,25 @@
// Copyright (C) 2013 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2
description: >
Yield expressions are valid yield expression operands.
---*/
function* g() {
yield yield 1;
}
var iter = g();
var result;
result = iter.next();
assert.sameValue(result.value, 1, 'First result `value`');
assert.sameValue(result.done, false, 'First result `done` flag');
result = iter.next(3);
assert.sameValue(result.value, 3, 'Second result `value`');
assert.sameValue(result.done, false, 'Second result `done` flag');
result = iter.next();
assert.sameValue(result.value, undefined, 'Final result `value`');
assert.sameValue(result.done, true, 'Final result `done`flag');

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: >
A Generator object is an instance of a generator function.
es6id: 25.3
---*/
function* g() {}
assert(g() instanceof g, 'Instance created via function invocation');
assert(new g() instanceof g, 'Instance created via constructor invocation');

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: >
Generator functions should define a `length` property.
includes: [propertyHelper.js]
es6id: 25.2.4
---*/
function* g() {}
assert.sameValue(g.length, 0);
verifyNotEnumerable(g, 'length');
verifyNotWritable(g, 'length');
verifyConfigurable(g, 'length');

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: >
Generator functions should define a `name` property.
includes: [propertyHelper.js]
es6id: 25.2.4
---*/
function* g() {}
assert.sameValue(g.name, 'g');
verifyNotEnumerable(g, 'name');
verifyNotWritable(g, 'name');
verifyConfigurable(g, 'name');

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: >
Generator objects should define a `prototype` property.
includes: [propertyHelper.js]
es6id: 25.2.4
---*/
function* g() {}
verifyNotEnumerable(g, 'prototype');
verifyWritable(g, 'prototype');
verifyNotConfigurable(g, 'prototype');

View File

@ -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: >
The value of the [[Prototype]] internal slot of the GeneratorFunction
prototype object is the FunctionPrototype intrinsic object.
es6id: 25.2.2.2
---*/
function f() {}
function* g() {}
assert.sameValue(
Object.getPrototypeOf(Object.getPrototypeOf(g)),
Object.getPrototypeOf(f)
);

View File

@ -0,0 +1,12 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2.4.2
description: >
Whenever a GeneratorFunction instance is created another ordinary object is
also created and is the initial value of the generator functions prototype
property.
---*/
function* g() {}
assert.sameValue(typeof g.prototype, 'object');

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: >
GeneratorFunction instances are created with a unique prototype object.
es6id: 25.2.1
---*/
function* g1() {}
function* g2() {}
assert(g1.prototype !== g2.prototype);

View File

@ -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: >
Generator instances directly inherit properties from the object that is the
value of the prototype property of the Generator function that created the
instance.
es6id: 25.3
---*/
function* g() {}
assert.sameValue(
Object.getPrototypeOf(g()),
g.prototype,
'Instance created via function invocation'
);
assert.sameValue(
Object.getPrototypeOf(new g()),
g.prototype,
'Instance created via constructor invocation'
);