inspector: prevent propagation of promise hooks to noPromise hooks · nodejs/node@b35041c
@@ -189,7 +189,7 @@ function lookupPublicResource(resource) {
189189// Used by C++ to call all init() callbacks. Because some state can be setup
190190// from C++ there's no need to perform all the same operations as in
191191// emitInitScript.
192-function emitInitNative(asyncId, type, triggerAsyncId, resource) {
192+function emitInitNative(asyncId, type, triggerAsyncId, resource, isPromiseHook) {
193193active_hooks.call_depth += 1;
194194resource = lookupPublicResource(resource);
195195// 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) {
199199// eslint-disable-next-line no-var
200200for (var i = 0; i < active_hooks.array.length; i++) {
201201if (typeof active_hooks.array[i][init_symbol] === 'function') {
202+if (isPromiseHook &&
203+active_hooks.array[i][kNoPromiseHook]) {
204+continue;
205+}
202206active_hooks.array[i][init_symbol](
203207asyncId, type, triggerAsyncId,
204208resource,
@@ -222,7 +226,7 @@ function emitInitNative(asyncId, type, triggerAsyncId, resource) {
222226223227// Called from native. The asyncId stack handling is taken care of there
224228// before this is called.
225-function emitHook(symbol, asyncId) {
229+function emitHook(symbol, asyncId, isPromiseHook) {
226230active_hooks.call_depth += 1;
227231// Use a single try/catch for all hook to avoid setting up one per
228232// iteration.
@@ -232,6 +236,10 @@ function emitHook(symbol, asyncId) {
232236// eslint-disable-next-line no-var
233237for (var i = 0; i < active_hooks.array.length; i++) {
234238if (typeof active_hooks.array[i][symbol] === 'function') {
239+if (isPromiseHook &&
240+active_hooks.array[i][kNoPromiseHook]) {
241+continue;
242+}
235243active_hooks.array[i][symbol](asyncId);
236244}
237245}
@@ -321,7 +329,7 @@ function promiseInitHook(promise, parent) {
321329trackPromise(promise, parent);
322330const asyncId = promise[async_id_symbol];
323331const triggerAsyncId = promise[trigger_async_id_symbol];
324-emitInitScript(asyncId, 'PROMISE', triggerAsyncId, promise);
332+emitInitScript(asyncId, 'PROMISE', triggerAsyncId, promise, true);
325333}
326334327335function promiseInitHookWithDestroyTracking(promise, parent) {
@@ -339,14 +347,14 @@ function promiseBeforeHook(promise) {
339347trackPromise(promise);
340348const asyncId = promise[async_id_symbol];
341349const triggerId = promise[trigger_async_id_symbol];
342-emitBeforeScript(asyncId, triggerId, promise);
350+emitBeforeScript(asyncId, triggerId, promise, true);
343351}
344352345353function promiseAfterHook(promise) {
346354trackPromise(promise);
347355const asyncId = promise[async_id_symbol];
348356if (hasHooks(kAfter)) {
349-emitAfterNative(asyncId);
357+emitAfterNative(asyncId, true);
350358}
351359if (asyncId === executionAsyncId()) {
352360// This condition might not be true if async_hooks was enabled during
@@ -361,7 +369,7 @@ function promiseAfterHook(promise) {
361369function promiseResolveHook(promise) {
362370trackPromise(promise);
363371const asyncId = promise[async_id_symbol];
364-emitPromiseResolveNative(asyncId);
372+emitPromiseResolveNative(asyncId, true);
365373}
366374367375let wantPromiseHook = false;
@@ -492,7 +500,7 @@ function promiseResolveHooksExist() {
492500}
493501494502495-function emitInitScript(asyncId, type, triggerAsyncId, resource) {
503+function emitInitScript(asyncId, type, triggerAsyncId, resource, isPromiseHook = false) {
496504// Short circuit all checks for the common case. Which is that no hooks have
497505// been set. Do this to remove performance impact for embedders (and core).
498506if (!hasHooks(kInit))
@@ -502,15 +510,15 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) {
502510triggerAsyncId = getDefaultTriggerAsyncId();
503511}
504512505-emitInitNative(asyncId, type, triggerAsyncId, resource);
513+emitInitNative(asyncId, type, triggerAsyncId, resource, isPromiseHook);
506514}
507515508516509-function emitBeforeScript(asyncId, triggerAsyncId, resource) {
517+function emitBeforeScript(asyncId, triggerAsyncId, resource, isPromiseHook = false) {
510518pushAsyncContext(asyncId, triggerAsyncId, resource);
511519512520if (hasHooks(kBefore))
513-emitBeforeNative(asyncId);
521+emitBeforeNative(asyncId, isPromiseHook);
514522}
515523516524