diff --git a/lib/internal/inspector_async_hook.js b/lib/internal/inspector_async_hook.js index 4ccf862697756d..6fc197e8b85f7f 100644 --- a/lib/internal/inspector_async_hook.js +++ b/lib/internal/inspector_async_hook.js @@ -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.promises.add(asyncId); + else + inspector.asyncTaskScheduled(type, asyncId, recurring); }, before(asyncId) { + if (this.promises.has(asyncId)) + return; inspector.asyncTaskStarted(asyncId); }, after(asyncId) { + if (this.promises.has(asyncId)) + return; inspector.asyncTaskFinished(asyncId); }, destroy(asyncId) { + if (this.promises.has(asyncId)) + return this.promises.delete(asyncId); inspector.asyncTaskCanceled(asyncId); }, }); +hook.promises = new Set(); + function enable() { if (config.bits < 64) { // V8 Inspector stores task ids as (void*) pointers. diff --git a/test/sequential/test-inspector-async-stack-traces-promise-then.js b/test/sequential/test-inspector-async-stack-traces-promise-then.js index a321855b5ea613..9ed61d5ae13675 100644 --- a/test/sequential/test-inspector-async-stack-traces-promise-then.js +++ b/test/sequential/test-inspector-async-stack-traces-promise-then.js @@ -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}`);