v8/test/inspector/debugger/async-instrumentation.js

69 lines
2.0 KiB
JavaScript
Raw Normal View History

// 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 async instrumentation enabled in the middle.');
contextGroup.addScript(`
function foo() {
// asyncTaskStarted
debugger;
// asyncTaskFinished
debugger;
}
function test() {
[inspector] change target promise for kDebugWillHandle & kDebugDidHandle - kDebugPromiseCreated(task, parent_task) This event occurs when promise is created (PromiseHookType::Init). V8Debugger uses this event to maintain task -> parent task map. - kDebugEnqueueAsyncFunction(task) This event occurs when first internal promise for async function is created. V8Debugger collects stack trace at this point. - kDebugEnqueuePromiseResolve(task), This event occurs when Promise fulfills with resolved status. V8Debugger collects stack trace at this point. - kDebugEnqueuePromiseReject(task), This event occurs when Promise fulfills with rejected status. V8Debugger collects stack trace at this point. - kDebugPromiseCollected, This event occurs when Promise is collected and no other chained callbacks can be added. V8Debugger removes information about async task for this promise. - kDebugWillHandle, This event occurs when chained promise function (either resolve or reject handler) is called. V8Debugger installs parent promise's stack (based on task -> parent_task map) as current if available or current promise's scheduled stack otherwise. - kDebugDidHandle, This event occurs after chained promise function has finished. V8Debugger restores asynchronous call chain to previous one. With this change all instrumentation calls are related to current promise (before WillHandle and DidHandle were related to next async task). Before V8Debugger supported only the following: - asyncTaskScheduled(task1) - asyncTaskStarted(task1) - asyncTaskFinished(task1) Now V8Debugger supports the following: - asyncTaskScheduled(parent_task) .. - asyncTaskCreated(task, parent_task), - asyncTaskStarted(task), uses parent_task scheduled stack - asyncTaskScheduled(task) - asyncTaskFinished(task) Additionally: WillHandle and DidHandle were migrated to PromiseHook API. More details: https://docs.google.com/document/d/1u19N45f1gSF7M39mGsycJEK3IPyJgIXCBnWyiPeuJFE BUG=v8:5738 R=dgozman@chromium.org,gsathya@chromium.org,yangguo@chromium.org Review-Url: https://codereview.chromium.org/2650803003 Cr-Commit-Position: refs/heads/master@{#42644}
2017-01-25 07:05:43 +00:00
debugger;
var resolve1;
var p1 = new Promise(resolve => resolve1 = resolve);
var p2 = p1.then(foo);
resolve1(); // asyncTaskScheduled
debugger;
return p2;
}
//# sourceURL=test.js`, 7, 26);
session.setupScriptMap();
Protocol.Debugger.onPaused(message => {
if (enableOnPause-- === 0)
Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 });
session.logCallFrames(message.params.callFrames);
var asyncStackTrace = message.params.asyncStackTrace;
while (asyncStackTrace) {
InspectorTest.log(`-- ${asyncStackTrace.description} --`);
session.logCallFrames(asyncStackTrace.callFrames);
asyncStackTrace = asyncStackTrace.parent;
}
InspectorTest.log('');
Protocol.Debugger.resume();
});
Protocol.Debugger.enable();
var enableOnPause = 0;
InspectorTest.runTestSuite([
function beforeAsyncTaskScheduled(next) {
enableOnPause = 0;
Protocol.Runtime.evaluate({ expression: 'test()//# sourceURL=expr1.js',
awaitPromise: true })
.then(() => Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 0 }))
.then(next);
},
function afterAsyncTaskScheduled(next) {
enableOnPause = 2;
Protocol.Runtime.evaluate({ expression: 'test()//# sourceURL=expr1.js',
awaitPromise: true })
.then(() => Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 0 }))
.then(next);
},
function afterAsyncTaskStarted(next) {
enableOnPause = 3;
Protocol.Runtime.evaluate({ expression: 'test()//# sourceURL=expr1.js',
awaitPromise: true })
.then(() => Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 0 }))
.then(next);
}
]);