src: do not call into JS in the maxAsyncCallStackDepthChanged interrupt · nodejs/node@e776b01 (original) (raw)

Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ function prepareMainThreadExecution() {
6 6 // Patch the process object with legacy properties and normalizations
7 7 patchProcessObject();
8 8 setupTraceCategoryState();
9 -
9 + setupInspectorHooks();
10 10 setupWarningHandler();
11 11
12 12 // Resolve the coverage directory to an absolute path, and
@@ -181,6 +181,21 @@ function setupTraceCategoryState() {
181 181 toggleTraceCategoryState(isTraceCategoryEnabled('node.async_hooks'));
182 182 }
183 183
184 +function setupInspectorHooks() {
185 +// If Debugger.setAsyncCallStackDepth is sent during bootstrap,
186 +// we cannot immediately call into JS to enable the hooks, which could
187 +// interrupt the JS execution of bootstrap. So instead we save the
188 +// notification in the inspector agent if it's sent in the middle of
189 +// bootstrap, and process the notification later here.
190 +if (internalBinding('config').hasInspector) {
191 +const {
192 + enable,
193 + disable
194 +} = require('internal/inspector_async_hook');
195 +internalBinding('inspector').registerAsyncHook(enable, disable);
196 +}
197 +}
198 +
184 199 // In general deprecations are intialized wherever the APIs are implemented,
185 200 // this is used to deprecate APIs implemented in C++ where the deprecation
186 201 // utitlities are not easily accessible.
@@ -360,5 +375,6 @@ module.exports = {
360 375 initializeFrozenIntrinsics,
361 376 loadPreloadModules,
362 377 setupTraceCategoryState,
378 + setupInspectorHooks,
363 379 initializeReport
364 380 };