From 40df84fe59014f0ae502ceeb7b6c671d69ef445b Mon Sep 17 00:00:00 2001 From: Beni von Cheni Date: Sun, 9 Dec 2018 22:12:39 -0500 Subject: [PATCH] inspector: move process.binding to internalBinding In places of process.binding('inspector'), migrate code to adapt internalBinding. PR-URL: https://github.com/nodejs/node/pull/24931 Refs: https://github.com/nodejs/node/issues/22160 Reviewed-By: Joyee Cheung Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater --- lib/inspector.js | 2 +- lib/internal/bootstrap/loaders.js | 1 + lib/internal/inspector_async_hook.js | 2 +- lib/internal/modules/cjs/helpers.js | 2 +- lib/internal/modules/cjs/loader.js | 2 +- lib/internal/modules/esm/module_job.js | 2 +- lib/internal/process/coverage.js | 2 +- src/inspector_js_api.cc | 2 +- src/node.cc | 2 +- test/parallel/test-process-binding-internalbinding-whitelist.js | 1 + test/sequential/test-async-wrap-getasyncid.js | 2 +- 11 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/inspector.js b/lib/inspector.js index 6988eccf82c9ef..f79ef9cec4e639 100644 --- a/lib/inspector.js +++ b/lib/inspector.js @@ -11,7 +11,7 @@ const { } = require('internal/errors').codes; const { validateString } = require('internal/validators'); const util = require('util'); -const { Connection, open, url } = process.binding('inspector'); +const { Connection, open, url } = internalBinding('inspector'); const { originalConsole } = require('internal/process/per_thread'); if (!Connection) diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 5c0a5b6aa1fb80..4d7bfa43f658d8 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -85,6 +85,7 @@ 'fs_event_wrap', 'http_parser', 'icu', + 'inspector', 'js_stream', 'natives', 'os', diff --git a/lib/internal/inspector_async_hook.js b/lib/internal/inspector_async_hook.js index 1ad0cbf3a533f2..4a3d31fc2ab7de 100644 --- a/lib/internal/inspector_async_hook.js +++ b/lib/internal/inspector_async_hook.js @@ -1,6 +1,6 @@ 'use strict'; -const inspector = process.binding('inspector'); +const inspector = internalBinding('inspector'); if (!inspector || !inspector.asyncTaskScheduled) { exports.setup = function() {}; diff --git a/lib/internal/modules/cjs/helpers.js b/lib/internal/modules/cjs/helpers.js index 2c856a99c6b8fd..fcb536c3df3738 100644 --- a/lib/internal/modules/cjs/helpers.js +++ b/lib/internal/modules/cjs/helpers.js @@ -108,7 +108,7 @@ if (getOptionValue('--experimental-worker')) { builtinLibs.sort(); } -if (typeof process.binding('inspector').open === 'function') { +if (typeof internalBinding('inspector').open === 'function') { builtinLibs.push('inspector'); builtinLibs.sort(); } diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 83ca0699773fa8..1b75f823f167ed 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -706,7 +706,7 @@ Module.prototype._compile = function(content, filename) { // Set breakpoint on module start if (filename === resolvedArgv) { delete process._breakFirstLine; - inspectorWrapper = process.binding('inspector').callAndPauseOnStart; + inspectorWrapper = internalBinding('inspector').callAndPauseOnStart; } } var dirname = path.dirname(filename); diff --git a/lib/internal/modules/esm/module_job.js b/lib/internal/modules/esm/module_job.js index 50aa00a09a03ee..fbb29aef783006 100644 --- a/lib/internal/modules/esm/module_job.js +++ b/lib/internal/modules/esm/module_job.js @@ -73,7 +73,7 @@ class ModuleJob { try { if (this.isMain && process._breakFirstLine) { delete process._breakFirstLine; - const initWrapper = process.binding('inspector').callAndPauseOnStart; + const initWrapper = internalBinding('inspector').callAndPauseOnStart; initWrapper(this.module.instantiate, this.module); } else { this.module.instantiate(); diff --git a/lib/internal/process/coverage.js b/lib/internal/process/coverage.js index 9c9b2b47119ea7..5c5d0c2b6171f3 100644 --- a/lib/internal/process/coverage.js +++ b/lib/internal/process/coverage.js @@ -51,7 +51,7 @@ function disableAllAsyncHooks() { exports.writeCoverage = writeCoverage; function setup() { - const { Connection } = process.binding('inspector'); + const { Connection } = internalBinding('inspector'); if (!Connection) { console.warn('inspector not enabled'); return; diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index 8f0332cc616341..3f05f02bb50ddb 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -315,5 +315,5 @@ void Initialize(Local target, Local unused, } // namespace inspector } // namespace node -NODE_BUILTIN_MODULE_CONTEXT_AWARE(inspector, +NODE_MODULE_CONTEXT_AWARE_INTERNAL(inspector, node::inspector::Initialize); diff --git a/src/node.cc b/src/node.cc index e8710bef22d3d7..769d1ed8f447f3 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2238,5 +2238,5 @@ int Start(int argc, char** argv) { #if !HAVE_INSPECTOR void Initialize() {} -NODE_BUILTIN_MODULE_CONTEXT_AWARE(inspector, Initialize) +NODE_MODULE_CONTEXT_AWARE_INTERNAL(inspector, Initialize) #endif // !HAVE_INSPECTOR diff --git a/test/parallel/test-process-binding-internalbinding-whitelist.js b/test/parallel/test-process-binding-internalbinding-whitelist.js index c7b683a88a1376..7689ff1ca31ed4 100644 --- a/test/parallel/test-process-binding-internalbinding-whitelist.js +++ b/test/parallel/test-process-binding-internalbinding-whitelist.js @@ -16,4 +16,5 @@ assert(process.binding('url')); assert(process.binding('spawn_sync')); assert(process.binding('js_stream')); assert(process.binding('buffer')); +assert(process.binding('inspector')); assert(process.binding('os')); diff --git a/test/sequential/test-async-wrap-getasyncid.js b/test/sequential/test-async-wrap-getasyncid.js index 3a59ade9a950a4..5c3a7b766fda99 100644 --- a/test/sequential/test-async-wrap-getasyncid.js +++ b/test/sequential/test-async-wrap-getasyncid.js @@ -291,7 +291,7 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check if (process.config.variables.v8_enable_inspector !== 0 && common.isMainThread) { - const binding = process.binding('inspector'); + const binding = internalBinding('inspector'); const handle = new binding.Connection(() => {}); testInitialized(handle, 'Connection'); handle.disconnect();