diff --git a/lib/async_hooks.js b/lib/async_hooks.js index f32c9131850..3a79da27da4 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -5,13 +5,12 @@ const { ERR_INVALID_ARG_TYPE, ERR_INVALID_ASYNC_ID } = require('internal/errors').codes; -const async_wrap = process.binding('async_wrap'); const internal_async_hooks = require('internal/async_hooks'); // Get functions // For userland AsyncResources, make sure to emit a destroy event when the // resource gets gced. -const { registerDestroyHook } = async_wrap; +const { registerDestroyHook } = internal_async_hooks; const { executionAsyncId, triggerAsyncId, @@ -38,7 +37,7 @@ const { // Get constants const { kInit, kBefore, kAfter, kDestroy, kTotals, kPromiseResolve, -} = async_wrap.constants; +} = internal_async_hooks.constants; // Listener API // diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index 8c4fd08fd83..5a2a8153f3f 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -65,11 +65,12 @@ const active_hooks = { tmp_fields: null }; +const { registerDestroyHook } = async_wrap; // Each constant tracks how many callbacks there are for any given step of // async execution. These are tracked so if the user didn't include callbacks // for a given step, that step can bail out early. -const { kInit, kBefore, kAfter, kDestroy, kPromiseResolve, +const { kInit, kBefore, kAfter, kDestroy, kTotals, kPromiseResolve, kCheck, kExecutionAsyncId, kAsyncIdCounter, kTriggerAsyncId, kDefaultTriggerAsyncId, kStackLength } = async_wrap.constants; @@ -435,6 +436,9 @@ module.exports = { init_symbol, before_symbol, after_symbol, destroy_symbol, promise_resolve_symbol }, + constants: { + kInit, kBefore, kAfter, kDestroy, kTotals, kPromiseResolve + }, enableHooks, disableHooks, clearDefaultTriggerAsyncId, @@ -452,4 +456,5 @@ module.exports = { emitBefore: emitBeforeScript, emitAfter: emitAfterScript, emitDestroy: emitDestroyScript, + registerDestroyHook, };