Skip to content

Commit

Permalink
src: use option parser for expose_internals
Browse files Browse the repository at this point in the history
bootstrap_node.js was directly parsing process.execArgv to see if
internals should be exposed, even though the argv was already parsed by
node. This is unusual and unnecessary, change it to set the option value
from the parser onto the config binding.

Backport-PR-URL: #14483
PR-URL: #12245
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
sam-github authored and MylesBorins committed Aug 14, 2017
1 parent 784f50e commit d01bcda
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
6 changes: 2 additions & 4 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,9 @@
return NativeModule._source.hasOwnProperty(id);
};

const EXPOSE_INTERNALS = process.execArgv.some(function(arg) {
return arg.match(/^--expose[-_]internals$/);
});
const config = process.binding('config');

if (EXPOSE_INTERNALS) {
if (config.exposeInternals) {
NativeModule.nonInternalExists = NativeModule.exists;

NativeModule.isInternal = function(id) {
Expand Down
8 changes: 7 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ bool trace_warnings = false;
// that is used by lib/module.js
bool config_preserve_symlinks = false;

// Set in node.cc by ParseArgs when --expose-internals or --expose_internals is
// used.
// Used in node_config.cc to set a constant on process.binding('config')
// that is used by lib/internal/bootstrap_node.js
bool config_expose_internals = false;

// process-relative uptime base, initialized at start-up
static double prog_start_time;
static bool debugger_running;
Expand Down Expand Up @@ -3896,7 +3902,7 @@ static void ParseArgs(int* argc,
#endif
} else if (strcmp(arg, "--expose-internals") == 0 ||
strcmp(arg, "--expose_internals") == 0) {
// consumed in js
config_expose_internals = true;
} else if (strcmp(arg, "--") == 0) {
index += 1;
break;
Expand Down
3 changes: 3 additions & 0 deletions src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ void InitConfig(Local<Object> target,

if (config_preserve_symlinks)
READONLY_BOOLEAN_PROPERTY("preserveSymlinks");

if (config_expose_internals)
READONLY_BOOLEAN_PROPERTY("exposeInternals");
} // InitConfig

} // namespace node
Expand Down
6 changes: 6 additions & 0 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ extern std::string openssl_config;
// that is used by lib/module.js
extern bool config_preserve_symlinks;

// Set in node.cc by ParseArgs when --expose-internals or --expose_internals is
// used.
// Used in node_config.cc to set a constant on process.binding('config')
// that is used by lib/internal/bootstrap_node.js
extern bool config_expose_internals;

// Forward declaration
class Environment;

Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-internal-modules-expose.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@

require('../common');
const assert = require('assert');
const config = process.binding('config');

console.log(config, process.argv);

assert.strictEqual(typeof require('internal/freelist').FreeList, 'function');
assert.strictEqual(config.exposeInternals, true);

0 comments on commit d01bcda

Please sign in to comment.