Skip to content

Commit 69d8e60

Browse files
joyeecheungBridgeAR
authored andcommitted
src: use internalBinding('config').hasInspector in JS land
Instead of `process.config.variables.v8_enable_inspector` which depends on the variable name in gyp files, or detecting `internalBinding('inspector').Connection`. PR-URL: #25291 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5eada9d commit 69d8e60

6 files changed

Lines changed: 22 additions & 12 deletions

File tree

‎lib/inspector.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
constEventEmitter=require('events');
43
const{
54
ERR_INSPECTOR_ALREADY_CONNECTED,
65
ERR_INSPECTOR_CLOSED,
@@ -9,13 +8,16 @@ const {
98
ERR_INVALID_ARG_TYPE,
109
ERR_INVALID_CALLBACK
1110
}=require('internal/errors').codes;
11+
12+
const{ hasInspector }=internalBinding('config');
13+
if(!hasInspector)
14+
thrownewERR_INSPECTOR_NOT_AVAILABLE();
15+
16+
constEventEmitter=require('events');
1217
const{ validateString }=require('internal/validators');
1318
constutil=require('util');
1419
const{ Connection, open, url }=internalBinding('inspector');
1520

16-
if(!Connection)
17-
thrownewERR_INSPECTOR_NOT_AVAILABLE();
18-
1921
constconnectionSymbol=Symbol('connectionProperty');
2022
constmessageCallbacksSymbol=Symbol('messageCallbacks');
2123
constnextIdSymbol=Symbol('nextId');

‎lib/internal/bootstrap/cache.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { NativeModule } = require('internal/bootstrap/loaders');
99
const{
1010
source, getCodeCache, compileFunction
1111
}=internalBinding('native_module');
12-
const{ hasTracing }=process.binding('config');
12+
const{ hasTracing, hasInspector}=process.binding('config');
1313

1414
constdepsModule=Object.keys(source).filter(
1515
(key)=>NativeModule.isDepsModule(key)||key.startsWith('internal/deps')
@@ -33,7 +33,7 @@ const cannotUseCache = [
3333

3434
// Skip modules that cannot be required when they are not
3535
// built into the binary.
36-
if(process.config.variables.v8_enable_inspector!==1){
36+
if(!hasInspector){
3737
cannotUseCache.push(
3838
'inspector',
3939
'internal/util/inspector',

‎lib/internal/bootstrap/node.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
const{ internalBinding, NativeModule }=loaderExports;
2020

2121
const{ getOptionValue }=NativeModule.require('internal/options');
22+
constconfig=internalBinding('config');
2223

2324
functionstartup(){
2425
setupTraceCategoryState();
@@ -156,7 +157,7 @@ function startup() {
156157
NativeModule.require('internal/process/coverage').setupExitHooks();
157158
}
158159

159-
if(process.config.variables.v8_enable_inspector){
160+
if(config.hasInspector){
160161
NativeModule.require('internal/inspector_async_hook').setup();
161162
}
162163

@@ -296,7 +297,7 @@ function startup() {
296297

297298
// TODO(joyeecheung): this property has not been well-maintained, should we
298299
// deprecate it in favor of a better API?
299-
const{ isDebugBuild, hasOpenSSL }=internalBinding('config');
300+
const{ isDebugBuild, hasOpenSSL }=config;
300301
Object.defineProperty(process,'features',{
301302
enumerable: true,
302303
writable: false,
@@ -636,7 +637,7 @@ function setupGlobalConsole() {
636637
writable: true
637638
});
638639
// TODO(joyeecheung): can we skip this if inspector is not active?
639-
if(process.config.variables.v8_enable_inspector){
640+
if(config.hasInspector){
640641
constinspector=
641642
NativeModule.require('internal/console/inspector');
642643
inspector.addInspectorApis(consoleFromNode,consoleFromVM);

‎lib/internal/process/coverage.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ function disableAllAsyncHooks() {
5151
exports.writeCoverage=writeCoverage;
5252

5353
functionsetup(){
54-
const{Connection}=internalBinding('inspector');
55-
if(!Connection){
54+
const{hasInspector}=internalBinding('config');
55+
if(!hasInspector){
5656
process._rawDebug('inspector not enabled');
5757
return;
5858
}
5959

60+
const{ Connection }=internalBinding('inspector');
6061
coverageConnection=newConnection((res)=>{
6162
if(coverageConnection._coverageCallback){
6263
coverageConnection._coverageCallback(res);

‎lib/internal/util/inspector.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
consthasInspector=process.config.variables.v8_enable_inspector===1;
3+
const{hasInspector }=internalBinding('config');
44
constinspector=hasInspector ? require('inspector') : undefined;
55

66
letsession;

‎src/node_config.cc‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ static void Initialize(Local<Object> target,
5757
READONLY_TRUE_PROPERTY(target, "hasTracing");
5858
#endif
5959

60+
#if HAVE_INSPECTOR
61+
READONLY_TRUE_PROPERTY(target, "hasInspector");
62+
#else
63+
READONLY_FALSE_PROPERTY(target, "hasInspector");
64+
#endif
65+
6066
#if !defined(NODE_WITHOUT_NODE_OPTIONS)
6167
READONLY_TRUE_PROPERTY(target, "hasNodeOptions");
6268
#endif

0 commit comments

Comments
 (0)