Skip to content

Commit c2359bd

Browse files
committedFeb 1, 2019
process: expose process.features.inspector
Instead of using process.config.variables.v8_enable_inspector to detect whether inspector is enabled in the build. PR-URL: #25819 Refs: #25343 Reviewed-By: Eugene Ostroukhov <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 39d9221 commit c2359bd

15 files changed

+25
-28
lines changed
 

‎lib/internal/bootstrap/node.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,13 @@ process.assert = deprecate(
268268

269269
// TODO(joyeecheung): this property has not been well-maintained, should we
270270
// deprecate it in favor of a better API?
271-
const { isDebugBuild, hasOpenSSL } = config;
271+
const { isDebugBuild, hasOpenSSL, hasInspector } = config;
272272
Object.defineProperty(process, 'features', {
273273
enumerable: true,
274274
writable: false,
275275
configurable: false,
276276
value: {
277+
inspector: hasInspector,
277278
debug: isDebugBuild,
278279
uv: true,
279280
ipv6: true, // TODO(bnoordhuis) ping libuv

‎lib/internal/util/inspector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
let session;
44
function sendInspectorCommand(cb, onError) {
55
const { hasInspector } = internalBinding('config');
6-
const inspector = hasInspector ? require('inspector') : undefined;
76
if (!hasInspector) return onError();
7+
const inspector = require('inspector');
88
if (session === undefined) session = new inspector.Session();
99
try {
1010
session.connect();

‎src/node_config.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ 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-
6660
#if !defined(NODE_WITHOUT_NODE_OPTIONS)
6761
READONLY_TRUE_PROPERTY(target, "hasNodeOptions");
6862
#endif
6963

7064
#endif // NODE_HAVE_I18N_SUPPORT
7165

66+
#if HAVE_INSPECTOR
67+
READONLY_TRUE_PROPERTY(target, "hasInspector");
68+
#else
69+
READONLY_FALSE_PROPERTY(target, "hasInspector");
70+
#endif
71+
7272
if (env->abort_on_uncaught_exception())
7373
READONLY_TRUE_PROPERTY(target, "shouldAbortOnUncaughtException");
7474

‎test/common/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ if (process.argv.length === 2 &&
8080
hasCrypto &&
8181
// If the binary is build without `intl` the inspect option is
8282
// invalid. The test itself should handle this case.
83-
(process.config.variables.v8_enable_inspector !== 0 ||
84-
!flag.startsWith('--inspect'))) {
83+
(process.features.inspector || !flag.startsWith('--inspect'))) {
8584
throw new Error(`Test has to be started with the flag: '${flag}'`);
8685
}
8786
}
@@ -618,7 +617,7 @@ function expectsError(fn, settings, exact) {
618617
}
619618

620619
function skipIfInspectorDisabled() {
621-
if (process.config.variables.v8_enable_inspector === 0) {
620+
if (!process.features.inspector) {
622621
skip('V8 inspector is disabled');
623622
}
624623
}

‎test/known_issues/test-inspector-cluster-port-clash.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const assert = require('assert');
1313

1414
// This following check should be replaced by common.skipIfInspectorDisabled()
1515
// if moved out of the known_issues directory.
16-
if (process.config.variables.v8_enable_inspector === 0) {
16+
if (!process.features.inspector) {
1717
// When the V8 inspector is disabled, using either --without-inspector or
1818
// --without-ssl, this test will not fail which it is expected to do.
1919
// The following fail will allow this test to be skipped by failing it.

‎test/parallel/test-cli-bad-options.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require('../common');
66
const assert = require('assert');
77
const spawn = require('child_process').spawnSync;
88

9-
if (process.config.variables.v8_enable_inspector === 1) {
9+
if (process.features.inspector) {
1010
requiresArgument('--inspect-port');
1111
requiresArgument('--inspect-port=');
1212
requiresArgument('--debug-port');

‎test/parallel/test-cli-node-print-help.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ function startPrintHelpTest() {
2222
}
2323

2424
function validateNodePrintHelp() {
25-
const config = process.config;
2625
const HAVE_OPENSSL = common.hasCrypto;
2726
const NODE_HAVE_I18N_SUPPORT = common.hasIntl;
28-
const HAVE_INSPECTOR = config.variables.v8_enable_inspector === 1;
27+
const HAVE_INSPECTOR = process.features.inspector;
2928

3029
const cliHelpOptions = [
3130
{ compileConstant: HAVE_OPENSSL,

‎test/parallel/test-module-cjs-helpers.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ require('../common');
55
const assert = require('assert');
66
const { builtinLibs } = require('internal/modules/cjs/helpers');
77

8-
const hasInspector = process.config.variables.v8_enable_inspector === 1;
9-
10-
const expectedLibs = hasInspector ? 34 : 33;
8+
const expectedLibs = process.features.inspector ? 34 : 33;
119
assert.strictEqual(builtinLibs.length, expectedLibs);

‎test/parallel/test-process-env-allowed-flags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require('../common');
1616
'r',
1717
'--stack-trace-limit=100',
1818
'--stack-trace-limit=-=xX_nodejs_Xx=-',
19-
].concat(process.config.variables.v8_enable_inspector ? [
19+
].concat(process.features.inspector ? [
2020
'--inspect-brk',
2121
'inspect-brk',
2222
'--inspect_brk',

‎test/parallel/test-process-features.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const assert = require('assert');
66
const keys = new Set(Object.keys(process.features));
77

88
assert.deepStrictEqual(keys, new Set([
9+
'inspector',
910
'debug',
1011
'uv',
1112
'ipv6',

‎test/parallel/test-repl-tab-complete.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const {
2929
} = require('../common/hijackstdio');
3030
const assert = require('assert');
3131
const fixtures = require('../common/fixtures');
32-
const hasInspector = process.config.variables.v8_enable_inspector === 1;
32+
const hasInspector = process.features.inspector;
3333

3434
if (!common.isMainThread)
3535
common.skip('process.chdir is not available in Workers');

‎test/parallel/test-v8-coverage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
if (!process.config.variables.v8_enable_inspector) return;
3+
if (!process.features.inspector) return;
44

55
const common = require('../common');
66
const assert = require('assert');

‎test/sequential/test-async-wrap-getasyncid.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
289289
testInitialized(req, 'SendWrap');
290290
}
291291

292-
if (process.config.variables.v8_enable_inspector !== 0 &&
293-
common.isMainThread) {
292+
if (process.features.inspector && common.isMainThread) {
294293
const binding = internalBinding('inspector');
295294
const handle = new binding.Connection(() => {});
296295
testInitialized(handle, 'Connection');

‎test/sequential/test-inspector-has-inspector-false.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
const common = require('../common');
55

6-
// This is to ensure that the sendInspectorCommand function calls the error
7-
// function if its called with the v8_enable_inspector is disabled
6+
if (process.features.inspector) {
7+
common.skip('V8 inspector is enabled');
8+
}
89

9-
process.config.variables.v8_enable_inspector = 0;
1010
const inspector = require('internal/util/inspector');
1111

1212
inspector.sendInspectorCommand(

‎tools/test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1653,8 +1653,8 @@ def Main():
16531653

16541654
# We want to skip the inspector tests if node was built without the inspector.
16551655
has_inspector = Execute([vm,
1656-
'-p', 'process.config.variables.v8_enable_inspector'], context)
1657-
if has_inspector.stdout.rstrip() == '0':
1656+
'-p', 'process.features.inspector'], context)
1657+
if has_inspector.stdout.rstrip() == 'false':
16581658
context.v8_enable_inspector = False
16591659

16601660
has_crypto = Execute([vm,

0 commit comments

Comments
 (0)
Please sign in to comment.