v8/test/mjsunit/harmony/async-generators-yield.js
Andreas Haas 8c3c1b6c0f [mjsunit] Move the implementation of testAsync into a separate file
The original implementation of 'testAsync' in mjsunit.js required to
put the call to '%AbortJS' into an 'eval' statement. The reason is that
this call requires the flag --allow-natives-syntax to be set, but the
flag is not set in all mjsunit tests. With the use of 'eval'
compilation errors can be avoided.

The problem with this approach was that the fuzzer started to produce
test cases which include the line 'eval("%AbortJS(message)");', and
this line crashes intentionally. Different to the line
'%Abort(message)', however, the 'eval' statement cannot be filtered
so easily in the fuzzer. Therefore I pulled the implementation of
'testAsync' into a separate file to avoid the 'eval'.

Additional changes: I use '===' now instead of 'deepEquals' in
AsyncAssertion.equals because 'deepEquals' is not available outside
mjsunit.js. Using '===' seems more appropriate anyways because for
all tests but one it is sufficient, and it is more precise than
deepEquals.

R=gsathya@chromium.org

Bug: chromium:774841
Change-Id: I47270aa63ff5a1d6aa76a771f9276eaaf579c5ac
Reviewed-on: https://chromium-review.googlesource.com/1156598
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54833}
2018-08-01 08:46:24 +00:00

71 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: --allow-natives-syntax
load('test/mjsunit/test-async.js');
// 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");