Merge pull request #2640 from shvaikalesh/async-yield-return-is-awaited

Test that yield* return() awaits received value
This commit is contained in:
Leo Balter 2020-05-27 12:56:18 -07:00 committed by GitHub
commit 14478c9061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 0 deletions

View File

@ -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);