Skip to content

Commit

Permalink
fixup! src: use option parser for expose_internals
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-github committed Apr 11, 2017
1 parent 8b07404 commit 88ca10f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
5 changes: 2 additions & 3 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,9 @@
return NativeModule._source.hasOwnProperty(id);
};

const EXPOSE_INTERNALS = process._exposeInternals;
const config = process.binding('config');

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

NativeModule.isInternal = function(id) {
Expand Down
16 changes: 7 additions & 9 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ static bool trace_sync_io = false;
static bool track_heap_objects = false;
static const char* eval_string = nullptr;
static std::vector<std::string> preload_modules;
static bool expose_internals = false;
static const int v8_default_thread_pool_size = 4;
static int v8_thread_pool_size = v8_default_thread_pool_size;
static bool prof_process = false;
Expand Down Expand Up @@ -216,6 +215,12 @@ bool config_preserve_symlinks = false;
// Set in node.cc by ParseArgs when --redirect-warnings= is used.
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;

// process-relative uptime base, initialized at start-up
Expand Down Expand Up @@ -3334,13 +3339,6 @@ void SetupProcessObject(Environment* env,
READONLY_PROPERTY(process, "_debugWaitConnect", True(env->isolate()));
}

// --expose_internals, --expose-internals
// Note that this is not exposed as a process property, it is deleted when
// node's javascript bootstrap code runs.
if (expose_internals) {
READONLY_PROPERTY(process, "_exposeInternals", True(env->isolate()));
}

// --security-revert flags
#define V(code, _, __) \
do { \
Expand Down Expand Up @@ -3794,7 +3792,7 @@ static void ParseArgs(int* argc,
#endif
} else if (strcmp(arg, "--expose-internals") == 0 ||
strcmp(arg, "--expose_internals") == 0) {
expose_internals = true;
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 @@ -58,6 +58,9 @@ void InitConfig(Local<Object> target,
.ToLocalChecked();
target->DefineOwnProperty(env->context(), name, value).FromJust();
}

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 @@ -65,6 +65,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;

// Set in node.cc by ParseArgs when --redirect-warnings= is used.
// Used to redirect warning output to a file rather than sending
// it to stderr.
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-internal-modules-expose.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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(!('_exposeInternals' in process), 'no process property is leaked');
assert.strictEqual(config.exposeInternals, true);

0 comments on commit 88ca10f

Please sign in to comment.