Browse Source

src: use option parser for expose_internals

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.

PR-URL: https://github.com/nodejs/node/pull/12245
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v6
Sam Roberts 8 years ago
parent
commit
8086cb68ae
  1. 6
      lib/internal/bootstrap_node.js
  2. 8
      src/node.cc
  3. 3
      src/node_config.cc
  4. 6
      src/node_internals.h
  5. 4
      test/parallel/test-internal-modules-expose.js

6
lib/internal/bootstrap_node.js

@ -510,11 +510,9 @@
return NativeModule._source.hasOwnProperty(id); return NativeModule._source.hasOwnProperty(id);
}; };
const EXPOSE_INTERNALS = process.execArgv.some(function(arg) { const config = process.binding('config');
return arg.match(/^--expose[-_]internals$/);
});
if (EXPOSE_INTERNALS) { if (config.exposeInternals) {
NativeModule.nonInternalExists = NativeModule.exists; NativeModule.nonInternalExists = NativeModule.exists;
NativeModule.isInternal = function(id) { NativeModule.isInternal = function(id) {

8
src/node.cc

@ -214,6 +214,12 @@ bool config_preserve_symlinks = false;
// Set in node.cc by ParseArgs when --redirect-warnings= is used. // Set in node.cc by ParseArgs when --redirect-warnings= is used.
std::string config_warning_file; // NOLINT(runtime/string) std::string config_warning_file; // NOLINT(runtime/string)
// 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;
bool v8_initialized = false; bool v8_initialized = false;
// process-relative uptime base, initialized at start-up // process-relative uptime base, initialized at start-up
@ -3787,7 +3793,7 @@ static void ParseArgs(int* argc,
#endif #endif
} else if (strcmp(arg, "--expose-internals") == 0 || } else if (strcmp(arg, "--expose-internals") == 0 ||
strcmp(arg, "--expose_internals") == 0) { strcmp(arg, "--expose_internals") == 0) {
// consumed in js config_expose_internals = true;
} else if (strcmp(arg, "--") == 0) { } else if (strcmp(arg, "--") == 0) {
index += 1; index += 1;
break; break;

3
src/node_config.cc

@ -58,6 +58,9 @@ void InitConfig(Local<Object> target,
.ToLocalChecked(); .ToLocalChecked();
target->DefineOwnProperty(env->context(), name, value).FromJust(); target->DefineOwnProperty(env->context(), name, value).FromJust();
} }
if (config_expose_internals)
READONLY_BOOLEAN_PROPERTY("exposeInternals");
} // InitConfig } // InitConfig
} // namespace node } // namespace node

6
src/node_internals.h

@ -65,6 +65,12 @@ extern std::string openssl_config;
// that is used by lib/module.js // that is used by lib/module.js
extern bool config_preserve_symlinks; 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;
// Set in node.cc by ParseArgs when --redirect-warnings= is used. // Set in node.cc by ParseArgs when --redirect-warnings= is used.
// Used to redirect warning output to a file rather than sending // Used to redirect warning output to a file rather than sending
// it to stderr. // it to stderr.

4
test/parallel/test-internal-modules-expose.js

@ -3,5 +3,9 @@
require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const config = process.binding('config');
console.log(config, process.argv);
assert.strictEqual(typeof require('internal/freelist').FreeList, 'function'); assert.strictEqual(typeof require('internal/freelist').FreeList, 'function');
assert.strictEqual(config.exposeInternals, true);

Loading…
Cancel
Save