Skip to content
Snippets Groups Projects
Commit e14a9ad9 authored by Valerie's avatar Valerie Committed by Leo Balter
Browse files

async-iteration: AsyncGeneratorPrototype tests (#1451)

parent 4a3e19b3
No related branches found
No related tags found
No related merge requests found
Showing
with 959 additions and 0 deletions
// 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,
});
// 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,
});
// 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)
// 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,
});
// 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,
});
// 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,
});
// 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);
// 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);
// 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);
// 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);
// 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)
// 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)
// 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)
// 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)
// 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,
});
// 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,
});
// 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,
});
// 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);
// 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)
// 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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment