summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-03-19 06:11:44 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-03-26 13:53:36 -0400
commit83972ff6ac0d05f3187cb3d4bec3d20325d4afbf (patch)
tree66c5a40a8b61642e30715bf471ef1b9f96993c8d
parent8209caec3955c029c47d32f0babef627500f3c65 (diff)
downloadandroid-node-v8-83972ff6ac0d05f3187cb3d4bec3d20325d4afbf.tar.gz
android-node-v8-83972ff6ac0d05f3187cb3d4bec3d20325d4afbf.tar.bz2
android-node-v8-83972ff6ac0d05f3187cb3d4bec3d20325d4afbf.zip
process: handle --expose-internals during pre-execution
Instead of relying on the value of the CLI option when executing bootstrap/loaders.js. PR-URL: https://github.com/nodejs/node/pull/26759 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
-rw-r--r--lib/internal/bootstrap/loaders.js21
-rw-r--r--lib/internal/bootstrap/pre_execution.js3
-rw-r--r--src/node.cc3
3 files changed, 15 insertions, 12 deletions
diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js
index d4f70f2270..d8dcd65392 100644
--- a/lib/internal/bootstrap/loaders.js
+++ b/lib/internal/bootstrap/loaders.js
@@ -41,8 +41,7 @@
// This file is compiled as if it's wrapped in a function with arguments
// passed by node::RunBootstrapping()
-/* global process, getLinkedBinding, getInternalBinding */
-/* global exposeInternals, primordials */
+/* global process, getLinkedBinding, getInternalBinding, primordials */
const {
Reflect,
@@ -157,15 +156,19 @@ function NativeModule(id) {
this.exportKeys = undefined;
this.loaded = false;
this.loading = false;
- if (id === loaderId) {
+ this.canBeRequiredByUsers = !id.startsWith('internal/');
+}
+
+// To be called during pre-execution when --expose-internals is on.
+// Enables the user-land module loader to access internal modules.
+NativeModule.exposeInternals = function() {
+ for (const [id, mod] of NativeModule.map) {
// Do not expose this to user land even with --expose-internals.
- this.canBeRequiredByUsers = false;
- } else if (id.startsWith('internal/')) {
- this.canBeRequiredByUsers = exposeInternals;
- } else {
- this.canBeRequiredByUsers = true;
+ if (id !== loaderId) {
+ mod.canBeRequiredByUsers = true;
+ }
}
-}
+};
const {
moduleIds,
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js
index 233ab4f879..820d931575 100644
--- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/bootstrap/pre_execution.js
@@ -133,6 +133,9 @@ function initializeReport() {
function setupDebugEnv() {
require('internal/util/debuglog').initializeDebugEnv(process.env.NODE_DEBUG);
+ if (getOptionValue('--expose-internals')) {
+ require('internal/bootstrap/loaders').NativeModule.exposeInternals();
+ }
}
function setupSignalHandlers() {
diff --git a/src/node.cc b/src/node.cc
index 2d23ce6755..a635fe85a9 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -296,8 +296,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
env->process_string(),
FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"),
FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"),
- // --expose-internals
- FIXED_ONE_BYTE_STRING(isolate, "exposeInternals"),
env->primordials_string()};
std::vector<Local<Value>> loaders_args = {
process,
@@ -307,7 +305,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
env->NewFunctionTemplate(binding::GetInternalBinding)
->GetFunction(context)
.ToLocalChecked(),
- Boolean::New(isolate, env->options()->expose_internals),
env->primordials()};
// Bootstrap internal loaders