Async/await event listener test
This patch adds a test for async/await analogous to a previous Promise test. It also fixes a typo in promise.js and makes a previous Promise test more correct by ensuring that all assertions run before completion, fixing the test expectations for the real result (which seems correct). BUG=v8:4483 CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_chromium_rel_ng;tryserver.blink:linux_blink_rel Review-Url: https://codereview.chromium.org/2037653002 Cr-Commit-Position: refs/heads/master@{#36903}
This commit is contained in:
parent
87ccb1d8af
commit
5d7b9ece16
@ -278,7 +278,9 @@ function ResolvePromise(promise, resolution) {
|
||||
|
||||
if (IS_CALLABLE(then)) {
|
||||
// PromiseResolveThenableJob
|
||||
var id, name, instrumenting = DEBUG_IS_ACTIVE;
|
||||
var id;
|
||||
var name = "PromiseResolveThenableJob";
|
||||
var instrumenting = DEBUG_IS_ACTIVE;
|
||||
%EnqueueMicrotask(function() {
|
||||
if (instrumenting) {
|
||||
%DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name });
|
||||
@ -295,7 +297,6 @@ function ResolvePromise(promise, resolution) {
|
||||
});
|
||||
if (instrumenting) {
|
||||
id = ++lastMicrotaskId;
|
||||
name = "PromseResolveThenableJob";
|
||||
%DebugAsyncTaskEvent({ type: "enqueue", id: id, name: name });
|
||||
}
|
||||
return;
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Flags: --expose-debug-as debug
|
||||
// Flags: --expose-debug-as debug --allow-natives-syntax
|
||||
|
||||
Debug = debug.Debug;
|
||||
|
||||
@ -16,8 +16,8 @@ var expected = [
|
||||
"didHandle #1",
|
||||
"willHandle #2",
|
||||
"then #2",
|
||||
"enqueue #3",
|
||||
"didHandle #2",
|
||||
"enqueue #3",
|
||||
"willHandle #3",
|
||||
"didHandle #3"
|
||||
];
|
||||
@ -58,4 +58,6 @@ p.then(function() {
|
||||
});
|
||||
resolver();
|
||||
|
||||
%RunMicrotasks();
|
||||
|
||||
assertNull(exception);
|
||||
|
@ -0,0 +1,70 @@
|
||||
// Copyright 2016 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-await --expose-debug-as debug --allow-natives-syntax
|
||||
|
||||
Debug = debug.Debug;
|
||||
|
||||
var base_id = -1;
|
||||
var exception = null;
|
||||
var expected = [
|
||||
"enqueue #1",
|
||||
"willHandle #1",
|
||||
"then #1",
|
||||
"enqueue #2",
|
||||
"enqueue #3",
|
||||
"didHandle #1",
|
||||
"willHandle #2",
|
||||
"then #2",
|
||||
"didHandle #2",
|
||||
"willHandle #3",
|
||||
"enqueue #4",
|
||||
"didHandle #3",
|
||||
"willHandle #4",
|
||||
"didHandle #4",
|
||||
];
|
||||
|
||||
function assertLog(msg) {
|
||||
print(msg);
|
||||
assertTrue(expected.length > 0);
|
||||
assertEquals(expected.shift(), msg);
|
||||
if (!expected.length) {
|
||||
Debug.setListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
function listener(event, exec_state, event_data, data) {
|
||||
if (event != Debug.DebugEvent.AsyncTaskEvent) return;
|
||||
try {
|
||||
if (base_id < 0)
|
||||
base_id = event_data.id();
|
||||
var id = event_data.id() - base_id + 1;
|
||||
assertTrue("Promise.resolve" == event_data.name() ||
|
||||
"PromiseResolveThenableJob" == event_data.name());
|
||||
assertLog(event_data.type() + " #" + id);
|
||||
} catch (e) {
|
||||
print(e + e.stack)
|
||||
exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.setListener(listener);
|
||||
|
||||
var resolver;
|
||||
var p = new Promise(function(resolve, reject) {
|
||||
resolver = resolve;
|
||||
});
|
||||
|
||||
async function main() {
|
||||
await p;
|
||||
assertLog("then #1");
|
||||
await undefined;
|
||||
assertLog("then #2");
|
||||
}
|
||||
main();
|
||||
resolver();
|
||||
|
||||
%RunMicrotasks();
|
||||
|
||||
assertNull(exception);
|
Loading…
Reference in New Issue
Block a user