From 6b2af91a88b0a5e4d846701971065b8d668c8b1d Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 10 Jan 2019 23:32:05 +0800 Subject: [PATCH] process: register the inspector async hooks in bootstrap/node.js So it's easier to tell the side effects of this setup. PR-URL: https://github.com/nodejs/node/pull/25443 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca --- lib/internal/bootstrap/node.js | 6 +++++- lib/internal/inspector_async_hook.js | 13 ++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index ca979af258745d..26585f5df9c28a 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -159,7 +159,11 @@ function startup() { } if (config.hasInspector) { - NativeModule.require('internal/inspector_async_hook').setup(); + const { + enable, + disable + } = NativeModule.require('internal/inspector_async_hook'); + internalBinding('inspector').registerAsyncHook(enable, disable); } // If the process is spawned with env NODE_CHANNEL_FD, it's probably diff --git a/lib/internal/inspector_async_hook.js b/lib/internal/inspector_async_hook.js index 4a3d31fc2ab7de..b16e8d025ec957 100644 --- a/lib/internal/inspector_async_hook.js +++ b/lib/internal/inspector_async_hook.js @@ -1,16 +1,10 @@ 'use strict'; -const inspector = internalBinding('inspector'); - -if (!inspector || !inspector.asyncTaskScheduled) { - exports.setup = function() {}; - return; -} - let hook; let config; function lazyHookCreation() { + const inspector = internalBinding('inspector'); const { createHook } = require('async_hooks'); config = internalBinding('config'); @@ -72,6 +66,7 @@ function disable() { hook.disable(); } -exports.setup = function() { - inspector.registerAsyncHook(enable, disable); +module.exports = { + enable, + disable };