Skip to content

Commit 6c0fd55

Browse files
danbevevanlucas
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 <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7ba3599 commit 6c0fd55

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

‎lib/internal/bootstrap_node.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@
327327
}
328328

329329
functionsetupInspector(originalConsole,wrappedConsole,Module){
330-
const{ addCommandLineAPI, consoleCall }=process.binding('inspector');
331-
if(!consoleCall){
330+
if(!process.config.variables.v8_enable_inspector){
332331
return;
333332
}
333+
const{ addCommandLineAPI, consoleCall }=process.binding('inspector');
334334
// Setup inspector command line API
335335
const{ makeRequireFunction }=NativeModule.require('internal/module');
336336
constpath=NativeModule.require('path');
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
constcommon=require('../common');
3+
common.skipIfInspectorDisabled();
4+
5+
process.config={};
Lines changed: 41 additions & 0 deletions
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+
constcommon=require('../common');
14+
constassert=require('assert');
15+
constinspector=require('inspector');
16+
constmsg='Test inspector logging';
17+
letasserted=false;
18+
19+
asyncfunctiontestConsoleLog(){
20+
constsession=newinspector.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+
asyncfunctionrunTests(){
37+
awaittestConsoleLog();
38+
assert.ok(asserted,'log statement did not reach the inspector');
39+
}
40+
41+
runTests();

0 commit comments

Comments
 (0)