Skip to content

Commit

Permalink
inspector: no async tracking for promises
Browse files Browse the repository at this point in the history
`Promise` instances are already tracked by V8 itself.
This fixes `sequential/test-inspector-async-stack-traces-promise-then`
in debug mode (it previously crashed because our tracking
and the V8 tracking were not properly nested).

PR-URL: #17118
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/707058
Fixes: #17017
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax committed Nov 21, 2017
1 parent 5d7f5c1 commit c4a5de5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/internal/inspector_async_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,33 @@ const hook = createHook({
// in https://github.com/nodejs/node/pull/13870#discussion_r124515293,
// this should be fine as long as we call asyncTaskCanceled() too.
const recurring = true;
inspector.asyncTaskScheduled(type, asyncId, recurring);
if (type === 'PROMISE')
this.promiseIds.add(asyncId);
else
inspector.asyncTaskScheduled(type, asyncId, recurring);
},

before(asyncId) {
if (this.promiseIds.has(asyncId))
return;
inspector.asyncTaskStarted(asyncId);
},

after(asyncId) {
if (this.promiseIds.has(asyncId))
return;
inspector.asyncTaskFinished(asyncId);
},

destroy(asyncId) {
if (this.promiseIds.has(asyncId))
return this.promiseIds.delete(asyncId);
inspector.asyncTaskCanceled(asyncId);
},
});

hook.promiseIds = new Set();

function enable() {
if (config.bits < 64) {
// V8 Inspector stores task ids as (void*) pointers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function debuggerPausedAt(msg, functionName, previousTickLocation) {
`${Object.keys(msg.params)} contains "asyncStackTrace" property`);

assert.strictEqual(msg.params.callFrames[0].functionName, functionName);
assert.strictEqual(msg.params.asyncStackTrace.description, 'PROMISE');
assert.strictEqual(msg.params.asyncStackTrace.description, 'Promise.resolve');

const frameLocations = msg.params.asyncStackTrace.callFrames.map(
(frame) => `${frame.functionName}:${frame.lineNumber}`);
Expand Down

0 comments on commit c4a5de5

Please sign in to comment.