b6c9086ca1
New intstrumentation consists of: - kAsyncFunctionSuspended when async function is suspended on await (called on each await), - kAsyncFunctionFinished when async function is finished. Old instrumentation was based on reusing async function promise. Using this promise produces couple side effects: - for any promise instrumentation we first need to check if it is special case for async function promise or not - it requires expensive reading from promise object. - we capture stack for async functions even if it does not contain awaits. - we do not properly cancel async task created for async function. New intsrumntation resolved all these problems as well as provide clear mapping between async task and generator which we can use later to fetch scope information for async functions on pause. R=dgozman@chromium.org,yangguo@chromium.org Bug: v8:7078 Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: Ifdcec947d91e6e3d4d5f9029bc080a19b8e23d41 Reviewed-on: https://chromium-review.googlesource.com/1043096 Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Dmitry Gozman <dgozman@chromium.org> Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Cr-Commit-Position: refs/heads/master@{#53445}
162 lines
3.3 KiB
JavaScript
162 lines
3.3 KiB
JavaScript
// 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.
|
|
|
|
let {session, contextGroup, Protocol} = InspectorTest.start('Checks that async chains for for-await-of are correct.');
|
|
|
|
contextGroup.addInlineScript(`
|
|
|
|
function Debugger(value) {
|
|
debugger;
|
|
}
|
|
|
|
function Reject(reason) {
|
|
var reject;
|
|
var promise = new Promise(function(resolvefn, rejectfn) {
|
|
reject = rejectfn;
|
|
});
|
|
setTimeout(reject.bind(undefined, reason), 0);
|
|
return promise;
|
|
}
|
|
|
|
function Throw(reason) {
|
|
return {
|
|
get then() { throw reason; }
|
|
};
|
|
}
|
|
|
|
function ThrowOnReturn(items) {
|
|
var it = items[Symbol.iterator]();
|
|
return {
|
|
[Symbol.iterator]() { return this; },
|
|
next(v) { return it.next(v); },
|
|
return(v) { throw new Error("boop"); }
|
|
};
|
|
}
|
|
|
|
function RejectOnReturn(items) {
|
|
var it = items[Symbol.iterator]();
|
|
return {
|
|
[Symbol.iterator]() { return this; },
|
|
next(v) { return it.next(v); },
|
|
return(v) { return Reject(new Error("boop")); }
|
|
};
|
|
}
|
|
|
|
async function Basic() {
|
|
for await (let x of ["a"]) {
|
|
Debugger();
|
|
}
|
|
}
|
|
|
|
async function UncaughtReject() {
|
|
async function loop() {
|
|
for await (let x of [Reject(new Error("boop"))]) {
|
|
Debugger();
|
|
}
|
|
}
|
|
return loop().catch(Debugger);
|
|
}
|
|
|
|
async function UncaughtThrow() {
|
|
async function loop() {
|
|
for await (let x of [Throw(new Error("boop"))]) {
|
|
Debugger();
|
|
}
|
|
}
|
|
return loop().catch(Debugger);
|
|
}
|
|
|
|
async function CaughtReject() {
|
|
try {
|
|
for await (let x of [Reject(new Error("boop"))]) {
|
|
Debugger(x);
|
|
}
|
|
} catch (e) {
|
|
Debugger(e);
|
|
}
|
|
}
|
|
|
|
async function CaughtThrow() {
|
|
try {
|
|
for await (let x of [Throw(new Error("boop"))]) {
|
|
Debugger(x);
|
|
}
|
|
} catch (e) {
|
|
Debugger(e);
|
|
}
|
|
}
|
|
|
|
async function UncaughtRejectOnBreak() {
|
|
async function loop() {
|
|
for await (let x of RejectOnReturn(["0", "1"])) {
|
|
break;
|
|
}
|
|
}
|
|
return loop().catch(Debugger);
|
|
}
|
|
|
|
async function UncaughtThrowOnBreak() {
|
|
async function loop() {
|
|
for await (let x of ThrowOnReturn(["0", "1"])) {
|
|
break;
|
|
}
|
|
}
|
|
return loop().catch(Debugger);
|
|
}
|
|
|
|
async function CaughtRejectOnBreak() {
|
|
try {
|
|
for await (let x of RejectOnReturn(["0", "1"])) {
|
|
break;
|
|
}
|
|
} catch (e) {
|
|
Debugger(e);
|
|
}
|
|
}
|
|
|
|
async function CaughtThrowOnBreak() {
|
|
try {
|
|
for await (let x of ThrowOnReturn(["0", "1"])) {
|
|
break;
|
|
}
|
|
} catch (e) {
|
|
Debugger(e);
|
|
}
|
|
}`, 'test.js');
|
|
|
|
session.setupScriptMap();
|
|
Protocol.Debugger.onPaused(message => {
|
|
session.logCallFrames(message.params.callFrames);
|
|
session.logAsyncStackTrace(message.params.asyncStackTrace);
|
|
InspectorTest.log('');
|
|
Protocol.Debugger.resume();
|
|
});
|
|
|
|
Protocol.Debugger.enable();
|
|
Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 });
|
|
var testList = [
|
|
'Basic',
|
|
'UncaughtReject',
|
|
'UncaughtThrow',
|
|
'CaughtReject',
|
|
'CaughtThrow',
|
|
'UncaughtRejectOnBreak',
|
|
'UncaughtThrowOnBreak',
|
|
'CaughtRejectOnBreak',
|
|
'CaughtThrowOnBreak',
|
|
]
|
|
InspectorTest.runTestSuite(testList.map(name => {
|
|
return eval(`
|
|
(function test${capitalize(name)}(next) {
|
|
Protocol.Runtime.evaluate({ expression: \`${name}()
|
|
//# sourceURL=test${capitalize(name)}.js\`, awaitPromise: true})
|
|
.then(next);
|
|
})
|
|
`);
|
|
}));
|
|
|
|
function capitalize(string) {
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
}
|