mirror of
https://github.com/tc39/test262.git
synced 2025-07-28 08:24:23 +02:00
async-iteration: AsyncGeneratorPrototype tests (#1451)
This commit is contained in:
parent
4a3e19b3e4
commit
e14a9ad9fe
28
test/built-ins/AsyncGeneratorPrototype/Symbol.toStringTag.js
Normal file
28
test/built-ins/AsyncGeneratorPrototype/Symbol.toStringTag.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-tostringtag
|
||||||
|
description: >
|
||||||
|
`Symbol.toStringTag` property descriptor
|
||||||
|
info: |
|
||||||
|
The initial value of the @@toStringTag property is the String value
|
||||||
|
"AsyncGenerator".
|
||||||
|
|
||||||
|
This property has the attributes { [[Writable]]: false, [[Enumerable]]:
|
||||||
|
false, [[Configurable]]: true }.
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [async-iteration, Symbol.toStringTag]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(
|
||||||
|
Object.getPrototypeOf(async function*() {}())
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyProperty(AsyncGeneratorPrototype, Symbol.toStringTag, {
|
||||||
|
value: 'AsyncGenerator',
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
30
test/built-ins/AsyncGeneratorPrototype/constructor.js
Normal file
30
test/built-ins/AsyncGeneratorPrototype/constructor.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-constructor
|
||||||
|
description: >
|
||||||
|
The GeneratorPrototype intrinsic's constructor.
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.constructor
|
||||||
|
|
||||||
|
The initial value of AsyncGenerator.prototype.constructor is the
|
||||||
|
intrinsic object %AsyncGenerator%.
|
||||||
|
|
||||||
|
This property has the attributes { [[Writable]]: false,
|
||||||
|
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGenerator = Object.getPrototypeOf(g);
|
||||||
|
var AsyncGeneratorPrototype = AsyncGenerator.prototype;
|
||||||
|
|
||||||
|
verifyProperty(AsyncGeneratorPrototype, 'constructor', {
|
||||||
|
value: AsyncGenerator,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-next
|
||||||
|
description: >
|
||||||
|
"next" returns a promise for an IteratorResult object
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.next ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be NormalCompletion(value).
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
4. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
5. Let request be AsyncGeneratorRequest{[[Completion]]: completion,
|
||||||
|
[[Capability]]: promiseCapability}.
|
||||||
|
6. Append request to the end of queue.
|
||||||
|
...
|
||||||
|
|
||||||
|
AsyncGeneratorResolve ( generator, value, done )
|
||||||
|
1. Assert: generator is an AsyncGenerator instance.
|
||||||
|
2. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
3. Assert: queue is not an empty List.
|
||||||
|
4. Remove the first element from queue and let next be the value of that element.
|
||||||
|
5. Let promiseCapability be next.[[Capability]].
|
||||||
|
6. Let iteratorResult be ! CreateIterResultObject(value, done).
|
||||||
|
7. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iteratorResult »).
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
|
||||||
|
g().next().then(function (result) {
|
||||||
|
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);
|
||||||
|
}).then($DONE, $DONE)
|
35
test/built-ins/AsyncGeneratorPrototype/next/length.js
Normal file
35
test/built-ins/AsyncGeneratorPrototype/next/length.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-next
|
||||||
|
description: >
|
||||||
|
AsyncGenerator.prototype.next.length is 1.
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.next ( value )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects:
|
||||||
|
Every built-in Function object, including constructors, has a length
|
||||||
|
property whose value is an integer. Unless otherwise specified, this
|
||||||
|
value is equal to the largest number of named arguments shown in the
|
||||||
|
subclause headings for the function description, including optional
|
||||||
|
parameters. However, rest parameters shown using the form “...name”
|
||||||
|
are not included in the default argument count.
|
||||||
|
|
||||||
|
Unless otherwise specified, the length property of a built-in Function
|
||||||
|
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||||
|
[[Configurable]]: true }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
verifyProperty(AsyncGeneratorPrototype.next, "length", {
|
||||||
|
value: 1,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
|
31
test/built-ins/AsyncGeneratorPrototype/next/name.js
Normal file
31
test/built-ins/AsyncGeneratorPrototype/next/name.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-next
|
||||||
|
description: >
|
||||||
|
Generator.prototype.next.name is "next".
|
||||||
|
info: |
|
||||||
|
Generator.prototype.next ( value )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects:
|
||||||
|
Every built-in Function object, including constructors, that is not
|
||||||
|
identified as an anonymous function has a name property whose value
|
||||||
|
is a String.
|
||||||
|
|
||||||
|
Unless otherwise specified, the name property of a built-in Function
|
||||||
|
object, if it exists, has the attributes { [[Writable]]: false,
|
||||||
|
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [generators]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
verifyProperty(AsyncGeneratorPrototype.next, "name", {
|
||||||
|
value: "next",
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
21
test/built-ins/AsyncGeneratorPrototype/next/prop-desc.js
Normal file
21
test/built-ins/AsyncGeneratorPrototype/next/prop-desc.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-next
|
||||||
|
description: GeneratorPrototype.next property description
|
||||||
|
info: |
|
||||||
|
This property has the attributes { [[Writable]]: false, [[Enumerable]]:
|
||||||
|
false, [[Configurable]]: false }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
verifyProperty(AsyncGeneratorPrototype, "next", {
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true,
|
||||||
|
});
|
@ -0,0 +1,66 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-next
|
||||||
|
description: next() requests from iterator processed in order, await
|
||||||
|
info: >
|
||||||
|
AsyncGenerator.prototype.next ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be NormalCompletion(value).
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
4. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
5. Let request be AsyncGeneratorRequest{[[Completion]]: completion,
|
||||||
|
[[Capability]]: promiseCapability}.
|
||||||
|
6. Append request to the end of queue.
|
||||||
|
...
|
||||||
|
|
||||||
|
AsyncGeneratorResolve ( generator, value, done )
|
||||||
|
...
|
||||||
|
2. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
3. Assert: queue is not an empty List.
|
||||||
|
4. Remove the first element from queue and let next be the value of that element.
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var yieldorder = 0;
|
||||||
|
var resolveLatePromise;
|
||||||
|
|
||||||
|
function resolveLater() {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
resolveLatePromise = resolve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function* g() {
|
||||||
|
yield resolveLater();
|
||||||
|
yield ++yieldorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
var iter = g();
|
||||||
|
|
||||||
|
assert.sameValue(yieldorder, 0);
|
||||||
|
|
||||||
|
var item1 = iter.next();
|
||||||
|
var item2 = iter.next();
|
||||||
|
var item3 = iter.next();
|
||||||
|
|
||||||
|
async function awaitnexts() {
|
||||||
|
assert.sameValue((await item3).value, undefined)
|
||||||
|
assert.sameValue(yieldorder, 2, "All next requests have been proccessed.")
|
||||||
|
assert.sameValue((await item2).value, 2)
|
||||||
|
assert.sameValue((await item1).value, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
awaitnexts().then($DONE, $DONE);
|
||||||
|
|
||||||
|
// At this point:
|
||||||
|
// yieldorder == 0
|
||||||
|
// item1 is an unresolved promise
|
||||||
|
resolveLatePromise(++yieldorder);
|
@ -0,0 +1,71 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-throw
|
||||||
|
description: next() call while iterator is in state executing
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.next ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be NormalCompletion(value).
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
4. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
5. Let request be AsyncGeneratorRequest{[[Completion]]: completion,
|
||||||
|
[[Capability]]: promiseCapability}.
|
||||||
|
6. Append request to the end of queue.
|
||||||
|
...
|
||||||
|
|
||||||
|
AsyncGeneratorResolve ( generator, value, done )
|
||||||
|
...
|
||||||
|
2. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
3. Assert: queue is not an empty List.
|
||||||
|
4. Remove the first element from queue and let next be the value of that element.
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var iter, result;
|
||||||
|
var executionorder = 0;
|
||||||
|
var valueisset = false;
|
||||||
|
|
||||||
|
async function* g() {
|
||||||
|
|
||||||
|
iter.next().then(
|
||||||
|
function(result) {
|
||||||
|
assert(valueisset, "variable valueisset should be set to true");
|
||||||
|
assert.sameValue(++executionorder, 2);
|
||||||
|
assert.sameValue(result.value, 2);
|
||||||
|
assert.sameValue(result.done, false);
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
$DONE(new Test262Error("next() should result in resolved promise."));
|
||||||
|
}
|
||||||
|
).catch($DONE)
|
||||||
|
|
||||||
|
valueisset = true;
|
||||||
|
|
||||||
|
yield 1;
|
||||||
|
yield 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
iter = g();
|
||||||
|
|
||||||
|
iter.next().then(function(result) {
|
||||||
|
assert.sameValue(++executionorder, 1);
|
||||||
|
assert.sameValue(result.value, 1);
|
||||||
|
assert.sameValue(result.done, false);
|
||||||
|
|
||||||
|
iter.next().then(function(result) {
|
||||||
|
assert.sameValue(++executionorder, 3);
|
||||||
|
assert.sameValue(result.value, undefined);
|
||||||
|
assert.sameValue(result.done, true);
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
|
||||||
|
}).catch($DONE);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-next
|
||||||
|
description: queue
|
||||||
|
info: >
|
||||||
|
AsyncGenerator.prototype.next ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be NormalCompletion(value).
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
4. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
5. Let request be AsyncGeneratorRequest{[[Completion]]: completion,
|
||||||
|
[[Capability]]: promiseCapability}.
|
||||||
|
6. Append request to the end of queue.
|
||||||
|
...
|
||||||
|
|
||||||
|
AsyncGeneratorResolve ( generator, value, done )
|
||||||
|
...
|
||||||
|
2. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
3. Assert: queue is not an empty List.
|
||||||
|
4. Remove the first element from queue and let next be the value of that element.
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var order = 0;
|
||||||
|
|
||||||
|
async function* g() {
|
||||||
|
yield 'first';
|
||||||
|
yield 'second';
|
||||||
|
}
|
||||||
|
|
||||||
|
var iter = g();
|
||||||
|
|
||||||
|
var item1 = iter.next();
|
||||||
|
var item2 = iter.next();
|
||||||
|
var item3 = iter.next();
|
||||||
|
|
||||||
|
var resolvedorder = 0;
|
||||||
|
|
||||||
|
Promise.all([
|
||||||
|
|
||||||
|
item3.then(function(result) {
|
||||||
|
resolvedorder++;
|
||||||
|
assert.sameValue(resolvedorder, 3);
|
||||||
|
assert.sameValue(result.value, undefined);
|
||||||
|
assert.sameValue(result.done, true);
|
||||||
|
}),
|
||||||
|
|
||||||
|
item2.then(function(result) {
|
||||||
|
resolvedorder++;
|
||||||
|
assert.sameValue(resolvedorder, 2);
|
||||||
|
assert.sameValue(result.value, "second");
|
||||||
|
assert.sameValue(result.done, false);
|
||||||
|
}),
|
||||||
|
|
||||||
|
item1.then(function(result) {
|
||||||
|
resolvedorder++;
|
||||||
|
assert.sameValue(resolvedorder, 1);
|
||||||
|
assert.sameValue(result.value, "first");
|
||||||
|
assert.sameValue(result.done, false);
|
||||||
|
})
|
||||||
|
|
||||||
|
]).then(function() { $DONE(); }, $DONE);
|
||||||
|
|
@ -0,0 +1,82 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-next
|
||||||
|
description: next() requests from iterator processed in order, then
|
||||||
|
info: >
|
||||||
|
AsyncGenerator.prototype.next ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be NormalCompletion(value).
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
4. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
5. Let request be AsyncGeneratorRequest{[[Completion]]: completion,
|
||||||
|
[[Capability]]: promiseCapability}.
|
||||||
|
6. Append request to the end of queue.
|
||||||
|
...
|
||||||
|
|
||||||
|
AsyncGeneratorResolve ( generator, value, done )
|
||||||
|
...
|
||||||
|
2. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
3. Assert: queue is not an empty List.
|
||||||
|
4. Remove the first element from queue and let next be the value of that element.
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var yieldorder = 0;
|
||||||
|
var resolveLatePromise;
|
||||||
|
|
||||||
|
function resolveLater() {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
resolveLatePromise = resolve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function* g() {
|
||||||
|
yield resolveLater();
|
||||||
|
yield ++yieldorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
var iter = g();
|
||||||
|
|
||||||
|
var item1 = iter.next();
|
||||||
|
var item2 = iter.next();
|
||||||
|
var item3 = iter.next();
|
||||||
|
|
||||||
|
var resolvedorder = 0;
|
||||||
|
|
||||||
|
Promise.all([
|
||||||
|
|
||||||
|
item3.then(function(result) {
|
||||||
|
resolvedorder++;
|
||||||
|
assert.sameValue(resolvedorder, 3);
|
||||||
|
assert.sameValue(result.value, undefined);
|
||||||
|
assert.sameValue(result.done, true);
|
||||||
|
}),
|
||||||
|
|
||||||
|
item2.then(function(result) {
|
||||||
|
resolvedorder++;
|
||||||
|
assert.sameValue(resolvedorder, 2);
|
||||||
|
assert.sameValue(result.value, 2);
|
||||||
|
assert.sameValue(result.done, false);
|
||||||
|
}),
|
||||||
|
|
||||||
|
item1.then(function(result) {
|
||||||
|
resolvedorder++;
|
||||||
|
assert.sameValue(resolvedorder, 1);
|
||||||
|
assert.sameValue(result.value, 1);
|
||||||
|
assert.sameValue(result.done, false);
|
||||||
|
})
|
||||||
|
|
||||||
|
]).then(function() { $DONE(); }, $DONE);
|
||||||
|
|
||||||
|
// At this point:
|
||||||
|
// yieldorder == 0
|
||||||
|
// item1 is an unresolved promise
|
||||||
|
resolveLatePromise(++yieldorder);
|
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-next
|
||||||
|
description: >
|
||||||
|
"next" returns a promise for an IteratorResult object
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.next ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be NormalCompletion(value).
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
|
...
|
||||||
|
9. Return promiseCapability.[[Promise]].
|
||||||
|
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var result = g().next()
|
||||||
|
|
||||||
|
assert(result instanceof Promise)
|
@ -0,0 +1,88 @@
|
|||||||
|
// Copyright 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-next
|
||||||
|
description: next rejects promise when `this` value is not an async generator
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.next ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be NormalCompletion(value).
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
3. If Type(generator) is not Object, or if generator does not have an
|
||||||
|
[[AsyncGeneratorState]] internal slot, then
|
||||||
|
a. Let badGeneratorError be a newly created TypeError object.
|
||||||
|
b. Perform ! Call(promiseCapability.[[Reject]], undefined, « badGeneratorError »).
|
||||||
|
c. Return promiseCapability.[[Promise]].
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
function* syncGenerator() {}
|
||||||
|
var syncIterator = syncGenerator()
|
||||||
|
|
||||||
|
var testPromises = [
|
||||||
|
AsyncGeneratorPrototype.next.call({}).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" +
|
||||||
|
" when `this` value is an object");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(object) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.next.call(function() {}).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" +
|
||||||
|
" when `this` value is a function");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(function) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.next.call(g).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" +
|
||||||
|
" when `this` value is an async generator function");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(async generator function) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.next.call(g.prototype).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" +
|
||||||
|
" when `this` value is an async generator function prototype object");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(async generator function prototype) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.next.call(syncIterator).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" +
|
||||||
|
" when `this` value is a generator");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(generator) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
Promise.all(testPromises).then(() => {}).then($DONE, $DONE)
|
@ -0,0 +1,98 @@
|
|||||||
|
// Copyright 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-next
|
||||||
|
description: next rejects promise when `this` value not an object
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.next ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be NormalCompletion(value).
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
3. If Type(generator) is not Object, or if generator does not have an
|
||||||
|
[[AsyncGeneratorState]] internal slot, then
|
||||||
|
a. Let badGeneratorError be a newly created TypeError object.
|
||||||
|
b. Perform ! Call(promiseCapability.[[Reject]], undefined, « badGeneratorError »).
|
||||||
|
c. Return promiseCapability.[[Promise]].
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
var symbol = Symbol();
|
||||||
|
|
||||||
|
var testPromises = [
|
||||||
|
AsyncGeneratorPrototype.next.call(undefined).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" +
|
||||||
|
" when `this` value `undefined`");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(undefined) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.next.call(1).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" +
|
||||||
|
" when `this` value is a Number");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(Number) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.next.call("string").then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" +
|
||||||
|
" when `this` value is a String");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(String) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.next.call(null).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" +
|
||||||
|
" when `this` value `null`");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(null) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.next.call(true).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" +
|
||||||
|
" when `this` value is a Boolean");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(Boolean) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.next.call(symbol).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.next should reject promise" +
|
||||||
|
" when `this` value is a Symbol");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(Symbol) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
Promise.all(testPromises).then(() => {}).then($DONE, $DONE)
|
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-return
|
||||||
|
description: >
|
||||||
|
"return" returns a promise for an IteratorResult object
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.return ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be Completion{[[Type]]: return, [[Value]]: value,
|
||||||
|
[[Target]]: empty}.
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
4. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
5. Let request be AsyncGeneratorRequest{[[Completion]]: completion,
|
||||||
|
[[Capability]]: promiseCapability}.
|
||||||
|
6. Append request to the end of queue.
|
||||||
|
...
|
||||||
|
|
||||||
|
AsyncGeneratorResolve ( generator, value, done )
|
||||||
|
1. Assert: generator is an AsyncGenerator instance.
|
||||||
|
2. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
3. Assert: queue is not an empty List.
|
||||||
|
4. Remove the first element from queue and let next be the value of that element.
|
||||||
|
5. Let promiseCapability be next.[[Capability]].
|
||||||
|
6. Let iteratorResult be ! CreateIterResultObject(value, done).
|
||||||
|
7. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iteratorResult »).
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
|
||||||
|
g().return().then(function (result) {
|
||||||
|
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);
|
||||||
|
}).then($DONE, $DONE)
|
35
test/built-ins/AsyncGeneratorPrototype/return/length.js
Normal file
35
test/built-ins/AsyncGeneratorPrototype/return/length.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-return
|
||||||
|
description: >
|
||||||
|
AsyncGenerator.prototype.return.length is 1.
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.return ( value )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects:
|
||||||
|
Every built-in Function object, including constructors, has a length
|
||||||
|
property whose value is an integer. Unless otherwise specified, this
|
||||||
|
value is equal to the largest number of named arguments shown in the
|
||||||
|
subclause headings for the function description, including optional
|
||||||
|
parameters. However, rest parameters shown using the form “...name”
|
||||||
|
are not included in the default argument count.
|
||||||
|
|
||||||
|
Unless otherwise specified, the length property of a built-in Function
|
||||||
|
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||||
|
[[Configurable]]: true }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
verifyProperty(AsyncGeneratorPrototype.return, "length", {
|
||||||
|
value: 1,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
|
31
test/built-ins/AsyncGeneratorPrototype/return/name.js
Normal file
31
test/built-ins/AsyncGeneratorPrototype/return/name.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-return
|
||||||
|
description: >
|
||||||
|
Generator.prototype.next.name is "return".
|
||||||
|
info: |
|
||||||
|
Generator.prototype.return ( value )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects:
|
||||||
|
Every built-in Function object, including constructors, that is not
|
||||||
|
identified as an anonymous function has a name property whose value
|
||||||
|
is a String.
|
||||||
|
|
||||||
|
Unless otherwise specified, the name property of a built-in Function
|
||||||
|
object, if it exists, has the attributes { [[Writable]]: false,
|
||||||
|
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [generators]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
verifyProperty(AsyncGeneratorPrototype.return, "name", {
|
||||||
|
value: "return",
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
21
test/built-ins/AsyncGeneratorPrototype/return/prop-desc.js
Normal file
21
test/built-ins/AsyncGeneratorPrototype/return/prop-desc.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-thow
|
||||||
|
description: GeneratorPrototype.return property description
|
||||||
|
info: |
|
||||||
|
This property has the attributes { [[Writable]]: false, [[Enumerable]]:
|
||||||
|
false, [[Configurable]]: false }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
verifyProperty(AsyncGeneratorPrototype, "return", {
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true,
|
||||||
|
});
|
@ -0,0 +1,66 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-throw
|
||||||
|
description: return() call while iterator is in state executing
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.return ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be Completion{[[Type]]: return, [[Value]]: value, [[Target]]: empty}.
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
4. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
5. Let request be AsyncGeneratorRequest{[[Completion]]: completion,
|
||||||
|
[[Capability]]: promiseCapability}.
|
||||||
|
6. Append request to the end of queue.
|
||||||
|
...
|
||||||
|
|
||||||
|
AsyncGeneratorResolve ( generator, value, done )
|
||||||
|
...
|
||||||
|
2. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
3. Assert: queue is not an empty List.
|
||||||
|
4. Remove the first element from queue and let next be the value of that element.
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var iter;
|
||||||
|
var executionorder = 0;
|
||||||
|
var valueisset = false;
|
||||||
|
|
||||||
|
async function* g() {
|
||||||
|
|
||||||
|
iter.return(42).then(
|
||||||
|
function(result) {
|
||||||
|
assert(valueisset, "variable valueisset should be set to true");
|
||||||
|
assert.sameValue(++executionorder, 2);
|
||||||
|
assert.sameValue(result.value, 42);
|
||||||
|
assert.sameValue(result.done, true);
|
||||||
|
}
|
||||||
|
).catch($DONE);
|
||||||
|
|
||||||
|
valueisset = true;
|
||||||
|
|
||||||
|
yield 1;
|
||||||
|
throw new Test262Error("This line should no be reached: generator closed by return");
|
||||||
|
}
|
||||||
|
|
||||||
|
iter = g();
|
||||||
|
|
||||||
|
iter.next().then(function(result) {
|
||||||
|
|
||||||
|
assert.sameValue(++executionorder, 1);
|
||||||
|
assert.sameValue(result.value, 1);
|
||||||
|
assert.sameValue(result.done, false);
|
||||||
|
|
||||||
|
iter.next().then(function(result) {
|
||||||
|
assert.sameValue(++executionorder, 3);
|
||||||
|
assert.sameValue(result.value, undefined);
|
||||||
|
assert.sameValue(result.done, true);
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
|
||||||
|
}).catch($DONE);
|
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-next
|
||||||
|
description: >
|
||||||
|
"return" returns a promise
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.return ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be Completion{[[Type]]: return, [[Value]]: value,
|
||||||
|
[[Target]]: empty}.
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
|
...
|
||||||
|
9. Return promiseCapability.[[Promise]].
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var result = g().return()
|
||||||
|
|
||||||
|
assert(result instanceof Promise)
|
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-return
|
||||||
|
description: return() results in fullfilled promise when called on completed iterator
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.return ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be Completion{[[Type]]: return, [[Value]]: value, [[Target]]: empty}.
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
8. If state is not "executing", then
|
||||||
|
a. Perform ! AsyncGeneratorResumeNext(generator).
|
||||||
|
...
|
||||||
|
|
||||||
|
AsyncGeneratorResumeNext:
|
||||||
|
If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is
|
||||||
|
"completed"
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var g = async function*() {};
|
||||||
|
|
||||||
|
var iter = g();
|
||||||
|
iter.next().then(function(result) {
|
||||||
|
assert.sameValue(result.value, undefined);
|
||||||
|
assert.sameValue(result.done, true);
|
||||||
|
|
||||||
|
iter.return(42).then(function(result) {
|
||||||
|
assert.sameValue(result.value, 42)
|
||||||
|
assert.sameValue(result.done, true)
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
|
||||||
|
}).catch($DONE);
|
@ -0,0 +1,89 @@
|
|||||||
|
// Copyright 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-return
|
||||||
|
description: return rejects promise when `this` value is not an async generator
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.return ( exception )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be Completion{[[Type]]: return, [[Value]]: value,
|
||||||
|
[[Target]]: empty}.
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
3. If Type(generator) is not Object, or if generator does not have an
|
||||||
|
[[AsyncGeneratorState]] internal slot, then
|
||||||
|
a. Let badGeneratorError be a newly created TypeError object.
|
||||||
|
b. Perform ! Call(promiseCapability.[[Reject]], undefined, « badGeneratorError »).
|
||||||
|
c. Return promiseCapability.[[Promise]].
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
function* syncGenerator() {}
|
||||||
|
var syncIterator = syncGenerator()
|
||||||
|
|
||||||
|
var testPromises = [
|
||||||
|
AsyncGeneratorPrototype.return.call({}).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is an object");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(object) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.return.call(function() {}).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is a function");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(function) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.return.call(g).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is an async generator function");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(async generator function) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.return.call(g.prototype).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is an async generator function prototype object");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(async generator function prototype) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.return.call(syncIterator).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is a generator");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(generator) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
Promise.all(testPromises).then(() => {}).then($DONE, $DONE)
|
@ -0,0 +1,99 @@
|
|||||||
|
// Copyright 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-return
|
||||||
|
description: return rejects promise when `this` value not an object
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.return ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be Completion{[[Type]]: return, [[Value]]: value,
|
||||||
|
[[Target]]: empty}.
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
3. If Type(generator) is not Object, or if generator does not have an
|
||||||
|
[[AsyncGeneratorState]] internal slot, then
|
||||||
|
a. Let badGeneratorError be a newly created TypeError object.
|
||||||
|
b. Perform ! Call(promiseCapability.[[Reject]], undefined, « badGeneratorError »).
|
||||||
|
c. Return promiseCapability.[[Promise]].
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
var symbol = Symbol();
|
||||||
|
|
||||||
|
var testPromises = [
|
||||||
|
AsyncGeneratorPrototype.return.call(undefined).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.return should reject promise" +
|
||||||
|
" when `this` value `undefined`");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(undefined) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.return.call(1).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.return should reject promise" +
|
||||||
|
" when `this` value is a Number");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(Number) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.return.call("string").then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.return should reject promise" +
|
||||||
|
" when `this` value is a String");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(String) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.return.call(null).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.return should reject promise" +
|
||||||
|
" when `this` value `null`");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(null) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.return.call(true).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.return should reject promise" +
|
||||||
|
" when `this` value is a Boolean");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(Boolean) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.return.call(symbol).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.return should reject promise" +
|
||||||
|
" when `this` value is a Symbol");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(Symbol) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
Promise.all(testPromises).then(() => {}).then($DONE, $DONE)
|
35
test/built-ins/AsyncGeneratorPrototype/throw/length.js
Normal file
35
test/built-ins/AsyncGeneratorPrototype/throw/length.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-throw
|
||||||
|
description: >
|
||||||
|
AsyncGenerator.prototype.throw.length is 1.
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.throw ( value )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects:
|
||||||
|
Every built-in Function object, including constructors, has a length
|
||||||
|
property whose value is an integer. Unless otherwise specified, this
|
||||||
|
value is equal to the largest number of named arguments shown in the
|
||||||
|
subclause headings for the function description, including optional
|
||||||
|
parameters. However, rest parameters shown using the form “...name”
|
||||||
|
are not included in the default argument count.
|
||||||
|
|
||||||
|
Unless otherwise specified, the length property of a built-in Function
|
||||||
|
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||||
|
[[Configurable]]: true }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
verifyProperty(AsyncGeneratorPrototype.throw, "length", {
|
||||||
|
value: 1,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
|
31
test/built-ins/AsyncGeneratorPrototype/throw/name.js
Normal file
31
test/built-ins/AsyncGeneratorPrototype/throw/name.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-throw
|
||||||
|
description: >
|
||||||
|
Generator.prototype.next.name is "throw".
|
||||||
|
info: |
|
||||||
|
Generator.prototype.throw ( value )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects:
|
||||||
|
Every built-in Function object, including constructors, that is not
|
||||||
|
identified as an anonymous function has a name property whose value
|
||||||
|
is a String.
|
||||||
|
|
||||||
|
Unless otherwise specified, the name property of a built-in Function
|
||||||
|
object, if it exists, has the attributes { [[Writable]]: false,
|
||||||
|
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [generators]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
verifyProperty(AsyncGeneratorPrototype.throw, "name", {
|
||||||
|
value: "throw",
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
21
test/built-ins/AsyncGeneratorPrototype/throw/prop-desc.js
Normal file
21
test/built-ins/AsyncGeneratorPrototype/throw/prop-desc.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-thow
|
||||||
|
description: GeneratorPrototype.throw property description
|
||||||
|
info: |
|
||||||
|
This property has the attributes { [[Writable]]: false, [[Enumerable]]:
|
||||||
|
false, [[Configurable]]: false }.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
verifyProperty(AsyncGeneratorPrototype, "throw", {
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true,
|
||||||
|
});
|
@ -0,0 +1,68 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-throw
|
||||||
|
description: return() call while iterator is in state executing
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.throw ( error )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be Completion{[[Type]]: throw, [[Value]]: error, [[Target]]: empty}.
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
4. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
5. Let request be AsyncGeneratorRequest{[[Completion]]: completion,
|
||||||
|
[[Capability]]: promiseCapability}.
|
||||||
|
6. Append request to the end of queue.
|
||||||
|
...
|
||||||
|
|
||||||
|
AsyncGeneratorResolve ( generator, value, done )
|
||||||
|
...
|
||||||
|
2. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
3. Assert: queue is not an empty List.
|
||||||
|
4. Remove the first element from queue and let next be the value of that element.
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var iter, result;
|
||||||
|
var thrownErr = new Error("Catch me.");
|
||||||
|
var caughtErr;
|
||||||
|
|
||||||
|
var order = 0;
|
||||||
|
var promises = []
|
||||||
|
|
||||||
|
async function* g() {
|
||||||
|
|
||||||
|
iter.throw(thrownErr).then(
|
||||||
|
function() {
|
||||||
|
$DONE(new Test262Error("throw() should result in reject promise."));
|
||||||
|
},
|
||||||
|
function(e) {
|
||||||
|
caughtErr = e;
|
||||||
|
order++;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
yield 1;
|
||||||
|
yield 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
iter = g();
|
||||||
|
|
||||||
|
iter.next().then(function(result) {
|
||||||
|
|
||||||
|
assert.sameValue(++order, 1);
|
||||||
|
assert.sameValue(result.value, 1);
|
||||||
|
assert.sameValue(result.done, false);
|
||||||
|
|
||||||
|
iter.next().then(function(result) {
|
||||||
|
assert.sameValue(++order, 3);
|
||||||
|
assert.sameValue(caughtErr, thrownErr);
|
||||||
|
assert.sameValue(result.done, true);
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
|
||||||
|
}).catch($DONE)
|
@ -0,0 +1,54 @@
|
|||||||
|
// Copyright (C) 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-throw
|
||||||
|
description: >
|
||||||
|
"throw" returns a rejected promise
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.next ( value )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be NormalCompletion(value).
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
|
...
|
||||||
|
4. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
5. Let request be AsyncGeneratorRequest{[[Completion]]: completion,
|
||||||
|
[[Capability]]: promiseCapability}.
|
||||||
|
6. Append request to the end of queue.
|
||||||
|
...
|
||||||
|
9. Return promiseCapability.[[Promise]].
|
||||||
|
|
||||||
|
AsyncGeneratorReject ( generator, exception )
|
||||||
|
1. Assert: generator is an AsyncGenerator instance.
|
||||||
|
2. Let queue be generator.[[AsyncGeneratorQueue]].
|
||||||
|
3. Assert: queue is not an empty List.
|
||||||
|
4. Remove the first element from queue and let next be the value of that element.
|
||||||
|
5. Let promiseCapability be next.[[Capability]].
|
||||||
|
6. Perform ! Call(promiseCapability.[[Reject]], undefined, « exception »).
|
||||||
|
...
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
|
||||||
|
var errormessage = "Promise rejected."
|
||||||
|
var result = g().throw(new Test262Error(errormessage))
|
||||||
|
|
||||||
|
assert(result instanceof Promise, "Expected result to be an instanceof Promise")
|
||||||
|
|
||||||
|
result.then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("Expected result to be rejected promise.");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e.message = errormessage)) {
|
||||||
|
throw new Test262Error("Expected thrown custom error, got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).then($DONE, $DONE)
|
@ -0,0 +1,89 @@
|
|||||||
|
// Copyright 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-throw
|
||||||
|
description: throw rejects promise when `this` value is not an async generator
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.throw ( exception )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be Completion{[[Type]]: throw, [[Value]]: exception,
|
||||||
|
[[Target]]: empty}.
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
3. If Type(generator) is not Object, or if generator does not have an
|
||||||
|
[[AsyncGeneratorState]] internal slot, then
|
||||||
|
a. Let badGeneratorError be a newly created TypeError object.
|
||||||
|
b. Perform ! Call(promiseCapability.[[Reject]], undefined, « badGeneratorError »).
|
||||||
|
c. Return promiseCapability.[[Promise]].
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
function* syncGenerator() {}
|
||||||
|
var syncIterator = syncGenerator()
|
||||||
|
|
||||||
|
var testPromises = [
|
||||||
|
AsyncGeneratorPrototype.throw.call({}).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is an object");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(object) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.throw.call(function() {}).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is a function");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(function) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.throw.call(g).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is an async generator function");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(async generator function) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.throw.call(g.prototype).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is an async generator function prototype object");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(async generator function prototype) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.throw.call(syncIterator).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is a generator");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(generator) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
Promise.all(testPromises).then(() => {}).then($DONE, $DONE)
|
@ -0,0 +1,99 @@
|
|||||||
|
// Copyright 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-throw
|
||||||
|
description: throw rejects promise when `this` value not an object
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.throw ( exception )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be Completion{[[Type]]: throw, [[Value]]: exception,
|
||||||
|
[[Target]]: empty}.
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
3. If Type(generator) is not Object, or if generator does not have an
|
||||||
|
[[AsyncGeneratorState]] internal slot, then
|
||||||
|
a. Let badGeneratorError be a newly created TypeError object.
|
||||||
|
b. Perform ! Call(promiseCapability.[[Reject]], undefined, « badGeneratorError »).
|
||||||
|
c. Return promiseCapability.[[Promise]].
|
||||||
|
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function* g() {}
|
||||||
|
var AsyncGeneratorPrototype = Object.getPrototypeOf(g).prototype;
|
||||||
|
|
||||||
|
var symbol = Symbol();
|
||||||
|
|
||||||
|
var testPromises = [
|
||||||
|
AsyncGeneratorPrototype.throw.call(undefined).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value `undefined`");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(undefined) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.throw.call(1).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is a Number");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(Number) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.throw.call("string").then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is a String");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(String) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.throw.call(null).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value `null`");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(null) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.throw.call(true).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is a Boolean");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(Boolean) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
AsyncGeneratorPrototype.throw.call(symbol).then(
|
||||||
|
function () {
|
||||||
|
throw new Test262Error("AsyncGeneratorPrototype.throw should reject promise" +
|
||||||
|
" when `this` value is a Symbol");
|
||||||
|
},
|
||||||
|
function (e) {
|
||||||
|
if (!(e instanceof TypeError)) {
|
||||||
|
throw new Test262Error("(Symbol) expected TypeError but got " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
Promise.all(testPromises).then(() => {}).then($DONE, $DONE)
|
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright 2018 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-asyncgenerator-prototype-throw
|
||||||
|
description: throw() results in rejected promise when called on completed iterator
|
||||||
|
info: |
|
||||||
|
AsyncGenerator.prototype.throw ( exception )
|
||||||
|
1. Let generator be the this value.
|
||||||
|
2. Let completion be Completion{[[Type]]: throw, [[Value]]: exception, [[Target]]: empty}.
|
||||||
|
3. Return ! AsyncGeneratorEnqueue(generator, completion).
|
||||||
|
|
||||||
|
AsyncGeneratorEnqueue ( generator, completion )
|
||||||
|
...
|
||||||
|
8. If state is not "executing", then
|
||||||
|
a. Perform ! AsyncGeneratorResumeNext(generator).
|
||||||
|
...
|
||||||
|
|
||||||
|
AsyncGeneratorResumeNext:
|
||||||
|
If completion.[[Type]] is throw, and generator.[[AsyncGeneratorState]] is
|
||||||
|
"completed", the resulting promise is rejected with the error.
|
||||||
|
flags: [async]
|
||||||
|
features: [async-iteration]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var throwError = new Error('Catch me');
|
||||||
|
var g = async function*() {};
|
||||||
|
|
||||||
|
var iter = g();
|
||||||
|
iter.next().then(function(result) {
|
||||||
|
assert.sameValue(result.value, undefined);
|
||||||
|
assert.sameValue(result.done, true);
|
||||||
|
|
||||||
|
iter.throw(throwError).then($DONE, function(err) {
|
||||||
|
assert.sameValue(err, throwError)
|
||||||
|
}).then($DONE, $DONE);
|
||||||
|
|
||||||
|
}).catch($DONE);
|
Loading…
x
Reference in New Issue
Block a user