| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -189,7 +189,7 @@ function lookupPublicResource(resource) { | |||
| 189 | 189 | // Used by C++ to call all init() callbacks. Because some state can be setup | |
| 190 | 190 | // from C++ there's no need to perform all the same operations as in | |
| 191 | 191 | // emitInitScript. | |
| 192 | - function emitInitNative(asyncId, type, triggerAsyncId, resource) { | ||
| 192 | + function emitInitNative(asyncId, type, triggerAsyncId, resource, isPromiseHook) { | ||
| 193 | 193 | active_hooks.call_depth += 1; | |
| 194 | 194 | resource = lookupPublicResource(resource); | |
| 195 | 195 | // Use a single try/catch for all hooks to avoid setting up one per iteration. | |
@@ -199,6 +199,10 @@ function emitInitNative(asyncId, type, triggerAsyncId, resource) { | |||
| 199 | 199 | // eslint-disable-next-line no-var | |
| 200 | 200 | for (var i = 0; i < active_hooks.array.length; i++) { | |
| 201 | 201 | if (typeof active_hooks.array[i][init_symbol] === 'function') { | |
| 202 | + if (isPromiseHook && | ||
| 203 | + active_hooks.array[i][kNoPromiseHook]) { | ||
| 204 | + continue; | ||
| 205 | + } | ||
| 202 | 206 | active_hooks.array[i][init_symbol]( | |
| 203 | 207 | asyncId, type, triggerAsyncId, | |
| 204 | 208 | resource, | |
@@ -222,7 +226,7 @@ function emitInitNative(asyncId, type, triggerAsyncId, resource) { | |||
| 222 | 226 | ||
| 223 | 227 | // Called from native. The asyncId stack handling is taken care of there | |
| 224 | 228 | // before this is called. | |
| 225 | - function emitHook(symbol, asyncId) { | ||
| 229 | + function emitHook(symbol, asyncId, isPromiseHook) { | ||
| 226 | 230 | active_hooks.call_depth += 1; | |
| 227 | 231 | // Use a single try/catch for all hook to avoid setting up one per | |
| 228 | 232 | // iteration. | |
@@ -232,6 +236,10 @@ function emitHook(symbol, asyncId) { | |||
| 232 | 236 | // eslint-disable-next-line no-var | |
| 233 | 237 | for (var i = 0; i < active_hooks.array.length; i++) { | |
| 234 | 238 | if (typeof active_hooks.array[i][symbol] === 'function') { | |
| 239 | + if (isPromiseHook && | ||
| 240 | + active_hooks.array[i][kNoPromiseHook]) { | ||
| 241 | + continue; | ||
| 242 | + } | ||
| 235 | 243 | active_hooks.array[i][symbol](asyncId); | |
| 236 | 244 | } | |
| 237 | 245 | } | |
@@ -321,7 +329,7 @@ function promiseInitHook(promise, parent) { | |||
| 321 | 329 | trackPromise(promise, parent); | |
| 322 | 330 | const asyncId = promise[async_id_symbol]; | |
| 323 | 331 | const triggerAsyncId = promise[trigger_async_id_symbol]; | |
| 324 | - emitInitScript(asyncId, 'PROMISE', triggerAsyncId, promise); | ||
| 332 | + emitInitScript(asyncId, 'PROMISE', triggerAsyncId, promise, true); | ||
| 325 | 333 | } | |
| 326 | 334 | ||
| 327 | 335 | function promiseInitHookWithDestroyTracking(promise, parent) { | |
@@ -339,14 +347,14 @@ function promiseBeforeHook(promise) { | |||
| 339 | 347 | trackPromise(promise); | |
| 340 | 348 | const asyncId = promise[async_id_symbol]; | |
| 341 | 349 | const triggerId = promise[trigger_async_id_symbol]; | |
| 342 | - emitBeforeScript(asyncId, triggerId, promise); | ||
| 350 | + emitBeforeScript(asyncId, triggerId, promise, true); | ||
| 343 | 351 | } | |
| 344 | 352 | ||
| 345 | 353 | function promiseAfterHook(promise) { | |
| 346 | 354 | trackPromise(promise); | |
| 347 | 355 | const asyncId = promise[async_id_symbol]; | |
| 348 | 356 | if (hasHooks(kAfter)) { | |
| 349 | - emitAfterNative(asyncId); | ||
| 357 | + emitAfterNative(asyncId, true); | ||
| 350 | 358 | } | |
| 351 | 359 | if (asyncId === executionAsyncId()) { | |
| 352 | 360 | // This condition might not be true if async_hooks was enabled during | |
@@ -361,7 +369,7 @@ function promiseAfterHook(promise) { | |||
| 361 | 369 | function promiseResolveHook(promise) { | |
| 362 | 370 | trackPromise(promise); | |
| 363 | 371 | const asyncId = promise[async_id_symbol]; | |
| 364 | - emitPromiseResolveNative(asyncId); | ||
| 372 | + emitPromiseResolveNative(asyncId, true); | ||
| 365 | 373 | } | |
| 366 | 374 | ||
| 367 | 375 | let wantPromiseHook = false; | |
@@ -492,7 +500,7 @@ function promiseResolveHooksExist() { | |||
| 492 | 500 | } | |
| 493 | 501 | ||
| 494 | 502 | ||
| 495 | - function emitInitScript(asyncId, type, triggerAsyncId, resource) { | ||
| 503 | + function emitInitScript(asyncId, type, triggerAsyncId, resource, isPromiseHook = false) { | ||
| 496 | 504 | // Short circuit all checks for the common case. Which is that no hooks have | |
| 497 | 505 | // been set. Do this to remove performance impact for embedders (and core). | |
| 498 | 506 | if (!hasHooks(kInit)) | |
@@ -502,15 +510,15 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) { | |||
| 502 | 510 | triggerAsyncId = getDefaultTriggerAsyncId(); | |
| 503 | 511 | } | |
| 504 | 512 | ||
| 505 | - emitInitNative(asyncId, type, triggerAsyncId, resource); | ||
| 513 | + emitInitNative(asyncId, type, triggerAsyncId, resource, isPromiseHook); | ||
| 506 | 514 | } | |
| 507 | 515 | ||
| 508 | 516 | ||
| 509 | - function emitBeforeScript(asyncId, triggerAsyncId, resource) { | ||
| 517 | + function emitBeforeScript(asyncId, triggerAsyncId, resource, isPromiseHook = false) { | ||
| 510 | 518 | pushAsyncContext(asyncId, triggerAsyncId, resource); | |
| 511 | 519 | ||
| 512 | 520 | if (hasHooks(kBefore)) | |
| 513 | - emitBeforeNative(asyncId); | ||
| 521 | + emitBeforeNative(asyncId, isPromiseHook); | ||
| 514 | 522 | } | |
| 515 | 523 | ||
| 516 | 524 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,31 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + common.skipIfInspectorDisabled(); | ||
| 4 | + const test = require('node:test'); | ||
| 5 | + const { NodeInstance } = require('../common/inspector-helper'); | ||
| 6 | + | ||
| 7 | + const script = ` | ||
| 8 | + import { createHook } from "async_hooks" | ||
| 9 | + import fs from "fs" | ||
| 10 | + | ||
| 11 | + const hook = createHook({ | ||
| 12 | + after() { | ||
| 13 | + } | ||
| 14 | + }); | ||
| 15 | + hook.enable(true); | ||
| 16 | + console.log('Async hook enabled'); | ||
| 17 | + `; | ||
| 18 | + | ||
| 19 | + test('inspector async hooks should not crash in debug build', async () => { | ||
| 20 | + const instance = new NodeInstance([ | ||
| 21 | + '--inspect-brk=0', | ||
| 22 | + ], script); | ||
| 23 | + const session = await instance.connectInspectorSession(); | ||
| 24 | + await session.send({ method: 'NodeRuntime.enable' }); | ||
| 25 | + await session.waitForNotification('NodeRuntime.waitingForDebugger'); | ||
| 26 | + await session.send({ method: 'Runtime.enable' }); | ||
| 27 | + await session.send({ method: 'Debugger.enable' }); | ||
| 28 | + await session.send({ id: 6, method: 'Debugger.setAsyncCallStackDepth', params: { maxDepth: 32 } }); | ||
| 29 | + await session.send({ method: 'Runtime.runIfWaitingForDebugger' }); | ||
| 30 | + await session.waitForDisconnect(); | ||
| 31 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments