v8/test/mjsunit/harmony/async-generators-yield.js
Caitlin Potter 409f84c93b [async-iteration] implement spec-change to yield in async generators
Per https://github.com/tc39/proposal-async-iteration/pull/102/files:

AsyncGeneratorResolve no longer unwraps a value component. Instead, the
value is unwrapped before the builtin call via Await, allowing Promise
rejections to affect the generator control flow.

Thus, all `yield <expr>` implicitly become `yield await <expr>`.

Additionally, `return <expr>` becomes `return await <expr>`. Finally, when
the generator is resumed with `.return()`, the parameter passed to .return()
is awaited before generator execution properly continues).

BUG=v8:5855
R=littledan@chromium.org, neis@chromium.org, adamk@chromium.org

Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: Ife084076c3ed434b5467e6aeba14082f8b410ad5
Reviewed-on: https://chromium-review.googlesource.com/523844
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47011}
2017-07-31 14:15:49 +00:00

69 lines
1.6 KiB
JavaScript

// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-async-iteration --allow-natives-syntax
// Yield a thenable which is never settled
testAsync(test => {
test.plan(0);
let awaitedThenable = { then() { } };
async function* gen() {
yield awaitedThenable;
test.unreachable();
}
gen().next().then(
(iterResult) => test.unreachable(),
test.unexpectedRejection());
}, "yield-await-thenable-pending");
// Yield a thenable which is fulfilled later
testAsync(test => {
test.plan(1);
let resolve;
let awaitedThenable = { then(resolveFn) { resolve = resolveFn; } };
async function* gen() {
let input = yield awaitedThenable;
test.equals("resolvedPromise", input);
}
gen().next().then(
(iterResult) => {
test.equals({ value: "resolvedPromise", done: false }, iterResult);
},
test.unexpectedRejection());
test.drainMicrotasks();
resolve("resolvedPromise");
}, "yield-await-thenable-resolved");
// Yield a thenable which is rejected later
testAsync(test => {
test.plan(2);
let reject;
let awaitedThenable = { then(resolveFn, rejectFn) { reject = rejectFn; } };
async function* gen() {
try {
yield awaitedThenable;
} catch (e) {
test.equals("rejection", e);
return e;
}
}
gen().next().then(
(iterResult) => {
test.equals({ value: "rejection", done: true }, iterResult);
},
test.unexpectedRejection());
test.drainMicrotasks();
reject("rejection");
}, "yield-await-thenable-rejected");