Reland "[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:6187, v8:5855
R=littledan@chromium.org, neis@chromium.org, adamk@chromium.org
TBR=rmcilroy@chromium.org, neis@chromium.org
Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: Id7718028fd555481f9f4ca0dbecfa788e3057c48
Reviewed-on: https://chromium-review.googlesource.com/594500
Reviewed-by: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Cr-Commit-Position: refs/heads/master@{#47058}
2017-08-01 14:45:03 +00:00
|
|
|
// 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.
|
|
|
|
|
2018-01-12 19:33:13 +00:00
|
|
|
// Flags: --allow-natives-syntax
|
Reland "[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:6187, v8:5855
R=littledan@chromium.org, neis@chromium.org, adamk@chromium.org
TBR=rmcilroy@chromium.org, neis@chromium.org
Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: Id7718028fd555481f9f4ca0dbecfa788e3057c48
Reviewed-on: https://chromium-review.googlesource.com/594500
Reviewed-by: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Cr-Commit-Position: refs/heads/master@{#47058}
2017-08-01 14:45:03 +00:00
|
|
|
|
2018-07-31 14:16:40 +00:00
|
|
|
load('test/mjsunit/test-async.js');
|
|
|
|
|
Reland "[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:6187, v8:5855
R=littledan@chromium.org, neis@chromium.org, adamk@chromium.org
TBR=rmcilroy@chromium.org, neis@chromium.org
Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: Id7718028fd555481f9f4ca0dbecfa788e3057c48
Reviewed-on: https://chromium-review.googlesource.com/594500
Reviewed-by: Caitlin Potter <caitp@igalia.com>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Cr-Commit-Position: refs/heads/master@{#47058}
2017-08-01 14:45:03 +00:00
|
|
|
// 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");
|