mirror of https://github.com/tc39/test262.git
Merge pull request #2640 from shvaikalesh/async-yield-return-is-awaited
Test that yield* return() awaits received value
This commit is contained in:
commit
14478c9061
|
@ -0,0 +1,44 @@
|
|||
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-generator-function-definitions-runtime-semantics-evaluation
|
||||
description: >
|
||||
If iterator's "return" method is missing,
|
||||
received value is awaited before forwarded to the runtime.
|
||||
info: |
|
||||
YieldExpression : yield * AssignmentExpression
|
||||
|
||||
[...]
|
||||
7. Repeat,
|
||||
[...]
|
||||
c. Else,
|
||||
i. Assert: received.[[Type]] is return.
|
||||
ii. Let return be ? GetMethod(iterator, "return").
|
||||
iii. If return is undefined, then
|
||||
1. If generatorKind is async, then set received.[[Value]] to ? Await(received.[[Value]]).
|
||||
2. Return Completion(received).
|
||||
features: [Symbol.asyncIterator, async-iteration]
|
||||
flags: [async]
|
||||
---*/
|
||||
|
||||
var asyncIterable = {
|
||||
[Symbol.asyncIterator]: function() {
|
||||
return this;
|
||||
},
|
||||
next: function() {
|
||||
return {value: 1, done: false};
|
||||
},
|
||||
};
|
||||
|
||||
async function* asyncGenerator() {
|
||||
yield* asyncIterable;
|
||||
}
|
||||
|
||||
var asyncIterator = asyncGenerator();
|
||||
asyncIterator.next().then(function() {
|
||||
var promise = Promise.resolve(2).then(() => 3);
|
||||
return asyncIterator.return(promise).then(function(result) {
|
||||
assert.sameValue(result.value, 3);
|
||||
assert.sameValue(result.done, true);
|
||||
});
|
||||
}).then($DONE, $DONE);
|
Loading…
Reference in New Issue