process: handle --expose-internals during pre-execution · nodejs/node@a03552d (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -41,8 +41,7 @@ | ||
41 | 41 | |
42 | 42 | // This file is compiled as if it's wrapped in a function with arguments |
43 | 43 | // passed by node::RunBootstrapping() |
44 | -/* global process, getLinkedBinding, getInternalBinding */ | |
45 | -/* global exposeInternals, primordials */ | |
44 | +/* global process, getLinkedBinding, getInternalBinding, primordials */ | |
46 | 45 | |
47 | 46 | const { |
48 | 47 | Reflect, |
@@ -157,15 +156,19 @@ function NativeModule(id) { | ||
157 | 156 | this.exportKeys = undefined; |
158 | 157 | this.loaded = false; |
159 | 158 | this.loading = false; |
160 | -if (id === loaderId) { | |
159 | +this.canBeRequiredByUsers = !id.startsWith('internal/'); | |
160 | +} | |
161 | + | |
162 | +// To be called during pre-execution when --expose-internals is on. | |
163 | +// Enables the user-land module loader to access internal modules. | |
164 | +NativeModule.exposeInternals = function() { | |
165 | +for (const [id, mod] of NativeModule.map) { | |
161 | 166 | // Do not expose this to user land even with --expose-internals. |
162 | -this.canBeRequiredByUsers = false; | |
163 | -} else if (id.startsWith('internal/')) { | |
164 | -this.canBeRequiredByUsers = exposeInternals; | |
165 | -} else { | |
166 | -this.canBeRequiredByUsers = true; | |
167 | +if (id !== loaderId) { | |
168 | +mod.canBeRequiredByUsers = true; | |
169 | +} | |
167 | 170 | } |
168 | -} | |
171 | +}; | |
169 | 172 | |
170 | 173 | const { |
171 | 174 | moduleIds, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -146,6 +146,9 @@ function initializeReport() { | ||
146 | 146 | |
147 | 147 | function setupDebugEnv() { |
148 | 148 | require('internal/util/debuglog').initializeDebugEnv(process.env.NODE_DEBUG); |
149 | +if (getOptionValue('--expose-internals')) { | |
150 | +require('internal/bootstrap/loaders').NativeModule.exposeInternals(); | |
151 | +} | |
149 | 152 | } |
150 | 153 | |
151 | 154 | function setupSignalHandlers() { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -296,8 +296,6 @@ MaybeLocal RunBootstrapping(Environment* env) { | ||
296 | 296 | env->process_string(), |
297 | 297 | FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"), |
298 | 298 | FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"), |
299 | -// --expose-internals | |
300 | -FIXED_ONE_BYTE_STRING(isolate, "exposeInternals"), | |
301 | 299 | env->primordials_string()}; |
302 | 300 | std::vector<Local> loaders_args = { |
303 | 301 | process, |
@@ -307,7 +305,6 @@ MaybeLocal RunBootstrapping(Environment* env) { | ||
307 | 305 | env->NewFunctionTemplate(binding::GetInternalBinding) |
308 | 306 | ->GetFunction(context) |
309 | 307 | .ToLocalChecked(), |
310 | -Boolean::New(isolate, env->options()->expose_internals), | |
311 | 308 | env->primordials()}; |
312 | 309 | |
313 | 310 | // Bootstrap internal loaders |