Skip to content

Commit 14f8cee

Browse files
danbevMylesBorins
authored andcommitted
lib: guard inspector console using process var
Currently the inspector module is always loaded and if it does not return anything the inspector console setup is skipped. This commit uses the process.config.variables.v8_enable_inspector variable to only load the inspector module if it is enabled. PR-URL: #15008 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 85fd7bb commit 14f8cee

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

lib/internal/bootstrap_node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,10 @@
319319
}
320320

321321
function setupInspector(originalConsole, wrappedConsole, Module) {
322-
const { addCommandLineAPI, consoleCall } = process.binding('inspector');
323-
if (!consoleCall) {
322+
if (!process.config.variables.v8_enable_inspector) {
324323
return;
325324
}
325+
const { addCommandLineAPI, consoleCall } = process.binding('inspector');
326326
// Setup inspector command line API
327327
const { makeRequireFunction } = NativeModule.require('internal/module');
328328
const path = NativeModule.require('path');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
const common = require('../common');
3+
common.skipIfInspectorDisabled();
4+
5+
process.config = {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Flags: --require ./test/fixtures/overwrite-config-preload-module.js
2+
'use strict';
3+
4+
// This test ensures that overwriting a process configuration
5+
// value does not affect code in bootstrap_node.js. Specifically this tests
6+
// that the inspector console functions are bound even though
7+
// overwrite-config-preload-module.js overwrote the process.config variable.
8+
9+
// We cannot do a check for the inspector because the configuration variables
10+
// were reset/removed by overwrite-config-preload-module.js.
11+
/* eslint-disable inspector-check */
12+
13+
const common = require('../common');
14+
const assert = require('assert');
15+
const inspector = require('inspector');
16+
const msg = 'Test inspector logging';
17+
let asserted = false;
18+
19+
async function testConsoleLog() {
20+
const session = new inspector.Session();
21+
session.connect();
22+
session.on('inspectorNotification', (data) => {
23+
if (data.method === 'Runtime.consoleAPICalled') {
24+
assert.strictEqual(data.params.args.length, 1);
25+
assert.strictEqual(data.params.args[0].value, msg);
26+
asserted = true;
27+
}
28+
});
29+
session.post('Runtime.enable');
30+
console.log(msg);
31+
session.disconnect();
32+
}
33+
34+
common.crashOnUnhandledRejection();
35+
36+
async function runTests() {
37+
await testConsoleLog();
38+
assert.ok(asserted, 'log statement did not reach the inspector');
39+
}
40+
41+
runTests();

0 commit comments

Comments
 (0)