| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1b9e573 commit 698508a
20 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,7 +84,7 @@ | |||
| 84 | 84 | /doc/api/module.md @nodejs/modules @nodejs/loaders | |
| 85 | 85 | /doc/api/modules.md @nodejs/modules @nodejs/loaders | |
| 86 | 86 | /doc/api/packages.md @nodejs/modules @nodejs/loaders | |
| 87 | - /lib/internal/bootstrap/loaders.js @nodejs/modules @nodejs/loaders | ||
| 87 | + /lib/internal/bootstrap/realm.js @nodejs/modules @nodejs/loaders | ||
| 88 | 88 | /lib/internal/modules/* @nodejs/modules @nodejs/loaders | |
| 89 | 89 | /lib/internal/process/esm_loader.js @nodejs/modules @nodejs/loaders | |
| 90 | 90 | /lib/internal/process/execution.js @nodejs/modules @nodejs/loaders | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,7 +65,7 @@ const { openSync, closeSync, readSync } = require('fs'); | |||
| 65 | 65 | const { inspect } = require('internal/util/inspect'); | |
| 66 | 66 | const { isPromise, isRegExp } = require('internal/util/types'); | |
| 67 | 67 | const { EOL } = require('internal/constants'); | |
| 68 | - const { BuiltinModule } = require('internal/bootstrap/loaders'); | ||
| 68 | + const { BuiltinModule } = require('internal/bootstrap/realm'); | ||
| 69 | 69 | const { isError } = require('internal/util'); | |
| 70 | 70 | ||
| 71 | 71 | const errorCache = new SafeMap(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | // Hello, and welcome to hacking node.js! | |
| 2 | 2 | // | |
| 3 | - // This file is invoked by `Realm::BootstrapNode()` in `src/node_realm.cc`, | ||
| 3 | + // This file is invoked by `Realm::BootstrapRealm()` in `src/node_realm.cc`, | ||
| 4 | 4 | // and is responsible for setting up Node.js core before main scripts | |
| 5 | 5 | // under `lib/internal/main/` are executed. | |
| 6 | 6 | // | |
@@ -32,9 +32,10 @@ | |||
| 32 | 32 | // `DOMException` class. | |
| 33 | 33 | // - `lib/internal/per_context/messageport.js`: JS-side components of the | |
| 34 | 34 | // `MessagePort` implementation. | |
| 35 | - // - `lib/internal/bootstrap/loaders.js`: this sets up internal binding and | ||
| 35 | + // - `lib/internal/bootstrap/realm.js`: this sets up internal binding and | ||
| 36 | 36 | // module loaders, including `process.binding()`, `process._linkedBinding()`, | |
| 37 | - // `internalBinding()` and `BuiltinModule`. | ||
| 37 | + // `internalBinding()` and `BuiltinModule`, and per-realm internal states | ||
| 38 | + // and bindings, including `prepare_stack_trace_callback`. | ||
| 38 | 39 | // | |
| 39 | 40 | // The initialization done in this script is included in both the main thread | |
| 40 | 41 | // and the worker threads. After this, further initialization is done based | |
@@ -52,8 +53,6 @@ | |||
| 52 | 53 | // passed by `BuiltinLoader::CompileAndCall()`. | |
| 53 | 54 | /* global process, require, internalBinding, primordials */ | |
| 54 | 55 | ||
| 55 | - setupPrepareStackTrace(); | ||
| 56 | - | ||
| 57 | 56 | const { | |
| 58 | 57 | FunctionPrototypeCall, | |
| 59 | 58 | JSONParse, | |
@@ -336,25 +335,6 @@ process.emitWarning = emitWarning; | |||
| 336 | 335 | // Note: only after this point are the timers effective | |
| 337 | 336 | } | |
| 338 | 337 | ||
| 339 | - function setupPrepareStackTrace() { | ||
| 340 | - const { | ||
| 341 | - setEnhanceStackForFatalException, | ||
| 342 | - setPrepareStackTraceCallback, | ||
| 343 | - } = internalBinding('errors'); | ||
| 344 | - const { | ||
| 345 | - prepareStackTrace, | ||
| 346 | - fatalExceptionStackEnhancers: { | ||
| 347 | - beforeInspector, | ||
| 348 | - afterInspector, | ||
| 349 | - }, | ||
| 350 | - } = require('internal/errors'); | ||
| 351 | - // Tell our PrepareStackTraceCallback passed to the V8 API | ||
| 352 | - // to call prepareStackTrace(). | ||
| 353 | - setPrepareStackTraceCallback(prepareStackTrace); | ||
| 354 | - // Set the function used to enhance the error stack for printing | ||
| 355 | - setEnhanceStackForFatalException(beforeInspector, afterInspector); | ||
| 356 | - } | ||
| 357 | - | ||
| 358 | 338 | function setupProcessObject() { | |
| 359 | 339 | const EventEmitter = require('events'); | |
| 360 | 340 | const origProcProto = ObjectGetPrototypeOf(process); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,8 @@ | |||
| 1 | + // This file is executed in every realm that is created by Node.js, including | ||
| 2 | + // the context of main thread, worker threads, and ShadowRealms. | ||
| 3 | + // Only per-realm internal states and bindings should be bootstrapped in this | ||
| 4 | + // file and no globals should be exposed to the user code. | ||
| 5 | + // | ||
| 1 | 6 | // This file creates the internal module & binding loaders used by built-in | |
| 2 | 7 | // modules. In contrast, user land modules are loaded using | |
| 3 | 8 | // lib/internal/modules/cjs/loader.js (CommonJS Modules) or | |
@@ -30,7 +35,7 @@ | |||
| 30 | 35 | // so they can be loaded faster without the cost of I/O. This class makes the | |
| 31 | 36 | // lib/internal/*, deps/internal/* modules and internalBinding() available by | |
| 32 | 37 | // default to core modules, and lets the core modules require itself via | |
| 33 | - // require('internal/bootstrap/loaders') even when this file is not written in | ||
| 38 | + // require('internal/bootstrap/realm') even when this file is not written in | ||
| 34 | 39 | // CommonJS style. | |
| 35 | 40 | // | |
| 36 | 41 | // Other objects: | |
@@ -178,7 +183,7 @@ let internalBinding; | |||
| 178 | 183 | }; | |
| 179 | 184 | } | |
| 180 | 185 | ||
| 181 | - const loaderId = 'internal/bootstrap/loaders'; | ||
| 186 | + const selfId = 'internal/bootstrap/realm'; | ||
| 182 | 187 | const { | |
| 183 | 188 | builtinIds, | |
| 184 | 189 | compileFunction, | |
@@ -235,7 +240,7 @@ class BuiltinModule { | |||
| 235 | 240 | static exposeInternals() { | |
| 236 | 241 | for (const { 0: id, 1: mod } of BuiltinModule.map) { | |
| 237 | 242 | // Do not expose this to user land even with --expose-internals. | |
| 238 | - if (id !== loaderId) { | ||
| 243 | + if (id !== selfId) { | ||
| 239 | 244 | mod.canBeRequiredByUsers = true; | |
| 240 | 245 | } | |
| 241 | 246 | } | |
@@ -354,7 +359,7 @@ const loaderExports = { | |||
| 354 | 359 | }; | |
| 355 | 360 | ||
| 356 | 361 | function requireBuiltin(id) { | |
| 357 | - if (id === loaderId) { | ||
| 362 | + if (id === selfId) { | ||
| 358 | 363 | return loaderExports; | |
| 359 | 364 | } | |
| 360 | 365 | ||
@@ -374,5 +379,27 @@ function requireWithFallbackInDeps(request) { | |||
| 374 | 379 | return requireBuiltin(request); | |
| 375 | 380 | } | |
| 376 | 381 | ||
| 382 | + function setupPrepareStackTrace() { | ||
| 383 | + const { | ||
| 384 | + setEnhanceStackForFatalException, | ||
| 385 | + setPrepareStackTraceCallback, | ||
| 386 | + } = internalBinding('errors'); | ||
| 387 | + const { | ||
| 388 | + prepareStackTrace, | ||
| 389 | + fatalExceptionStackEnhancers: { | ||
| 390 | + beforeInspector, | ||
| 391 | + afterInspector, | ||
| 392 | + }, | ||
| 393 | + } = requireBuiltin('internal/errors'); | ||
| 394 | + // Tell our PrepareStackTraceCallback passed to the V8 API | ||
| 395 | + // to call prepareStackTrace(). | ||
| 396 | + setPrepareStackTraceCallback(prepareStackTrace); | ||
| 397 | + // Set the function used to enhance the error stack for printing | ||
| 398 | + setEnhanceStackForFatalException(beforeInspector, afterInspector); | ||
| 399 | + } | ||
| 400 | + | ||
| 377 | 401 | // Store the internal loaders in C++. | |
| 378 | 402 | setInternalLoaders(internalBinding, requireBuiltin); | |
| 403 | + | ||
| 404 | + // Setup per-realm bindings. | ||
| 405 | + setupPrepareStackTrace(); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ const { | |||
| 10 | 10 | } = primordials; | |
| 11 | 11 | ||
| 12 | 12 | const binding = internalBinding('mksnapshot'); | |
| 13 | - const { BuiltinModule } = require('internal/bootstrap/loaders'); | ||
| 13 | + const { BuiltinModule } = require('internal/bootstrap/realm'); | ||
| 14 | 14 | const { | |
| 15 | 15 | getEmbedderEntryFunction, | |
| 16 | 16 | compileSerializeMain, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,7 +75,7 @@ module.exports = { | |||
| 75 | 75 | initializeCJS, | |
| 76 | 76 | }; | |
| 77 | 77 | ||
| 78 | - const { BuiltinModule } = require('internal/bootstrap/loaders'); | ||
| 78 | + const { BuiltinModule } = require('internal/bootstrap/realm'); | ||
| 79 | 79 | const { | |
| 80 | 80 | maybeCacheSourceMap, | |
| 81 | 81 | } = require('internal/source_map/source_map_cache'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -190,7 +190,7 @@ class Hooks { | |||
| 190 | 190 | filename: '<preload>', | |
| 191 | 191 | }, | |
| 192 | 192 | ); | |
| 193 | - const { BuiltinModule } = require('internal/bootstrap/loaders'); | ||
| 193 | + const { BuiltinModule } = require('internal/bootstrap/realm'); | ||
| 194 | 194 | // We only allow replacing the importMetaInitializer during preload; | |
| 195 | 195 | // after preload is finished, we disable the ability to replace it. | |
| 196 | 196 | // | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,7 @@ const { | |||
| 24 | 24 | StringPrototypeStartsWith, | |
| 25 | 25 | } = primordials; | |
| 26 | 26 | const internalFS = require('internal/fs/utils'); | |
| 27 | - const { BuiltinModule } = require('internal/bootstrap/loaders'); | ||
| 27 | + const { BuiltinModule } = require('internal/bootstrap/realm'); | ||
| 28 | 28 | const { | |
| 29 | 29 | realpathSync, | |
| 30 | 30 | statSync, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ const { | |||
| 17 | 17 | ERR_MANIFEST_DEPENDENCY_MISSING, | |
| 18 | 18 | ERR_UNKNOWN_BUILTIN_MODULE, | |
| 19 | 19 | } = require('internal/errors').codes; | |
| 20 | - const { BuiltinModule } = require('internal/bootstrap/loaders'); | ||
| 20 | + const { BuiltinModule } = require('internal/bootstrap/realm'); | ||
| 21 | 21 | ||
| 22 | 22 | const { validateString } = require('internal/validators'); | |
| 23 | 23 | const path = require('path'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -351,7 +351,7 @@ function initializeReport() { | |||
| 351 | 351 | function setupDebugEnv() { | |
| 352 | 352 | require('internal/util/debuglog').initializeDebugEnv(process.env.NODE_DEBUG); | |
| 353 | 353 | if (getOptionValue('--expose-internals')) { | |
| 354 | - require('internal/bootstrap/loaders').BuiltinModule.exposeInternals(); | ||
| 354 | + require('internal/bootstrap/realm').BuiltinModule.exposeInternals(); | ||
| 355 | 355 | } | |
| 356 | 356 | } | |
| 357 | 357 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments