GeezerVison is showing github.com — src: bootstrap prepare stack trace callback in shadow realm · nodejs/node@d35f870
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/CODEOWNERS +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 89 | 89 | /doc/api/module.md @nodejs/modules @nodejs/loaders | 90 | 90 | /doc/api/modules.md @nodejs/modules @nodejs/loaders | 91 | 91 | /doc/api/packages.md @nodejs/modules @nodejs/loaders | 92 | | -/lib/internal/bootstrap/loaders.js @nodejs/modules @nodejs/loaders | | 92 | +/lib/internal/bootstrap/realm.js @nodejs/modules @nodejs/loaders | 93 | 93 | /lib/internal/modules/* @nodejs/modules @nodejs/loaders | 94 | 94 | /lib/internal/process/esm_loader.js @nodejs/modules @nodejs/loaders | 95 | 95 | /lib/internal/process/execution.js @nodejs/modules @nodejs/loaders | |
Collapse file Copy file name to clipboardExpand all lines: lib/assert.js +1-1Lines changed: 1 addition & 1 deletion | 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(); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/node.js +4-24Lines changed: 4 additions & 24 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 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 | 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 | 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, | @@ -364,25 +363,6 @@ process.emitWarning = emitWarning; | 364 | 363 | // Note: only after this point are the timers effective | 365 | 364 | } | 366 | 365 |
| 367 | | -function setupPrepareStackTrace() { | 368 | | - const { | 369 | | - setEnhanceStackForFatalException, | 370 | | - setPrepareStackTraceCallback, | 371 | | - } = internalBinding('errors'); | 372 | | - const { | 373 | | - prepareStackTrace, | 374 | | - fatalExceptionStackEnhancers: { | 375 | | - beforeInspector, | 376 | | - afterInspector, | 377 | | - }, | 378 | | - } = require('internal/errors'); | 379 | | - // Tell our PrepareStackTraceCallback passed to the V8 API | 380 | | - // to call prepareStackTrace(). | 381 | | - setPrepareStackTraceCallback(prepareStackTrace); | 382 | | - // Set the function used to enhance the error stack for printing | 383 | | - setEnhanceStackForFatalException(beforeInspector, afterInspector); | 384 | | -} | 385 | | - | 386 | 366 | function setupProcessObject() { | 387 | 367 | const EventEmitter = require('events'); | 388 | 368 | const origProcProto = ObjectGetPrototypeOf(process); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/realm.js +31-4Lines changed: 31 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | 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: | @@ -181,7 +186,7 @@ let internalBinding; | 181 | 186 | }; | 182 | 187 | } | 183 | 188 |
| 184 | | -const loaderId = 'internal/bootstrap/loaders'; | | 189 | +const selfId = 'internal/bootstrap/realm'; | 185 | 190 | const { | 186 | 191 | builtinIds, | 187 | 192 | compileFunction, | @@ -238,7 +243,7 @@ class BuiltinModule { | 238 | 243 | static exposeInternals() { | 239 | 244 | for (const { 0: id, 1: mod } of BuiltinModule.map) { | 240 | 245 | // Do not expose this to user land even with --expose-internals. | 241 | | - if (id !== loaderId) { | | 246 | + if (id !== selfId) { | 242 | 247 | mod.canBeRequiredByUsers = true; | 243 | 248 | } | 244 | 249 | } | @@ -357,7 +362,7 @@ const loaderExports = { | 357 | 362 | }; | 358 | 363 |
| 359 | 364 | function requireBuiltin(id) { | 360 | | - if (id === loaderId) { | | 365 | + if (id === selfId) { | 361 | 366 | return loaderExports; | 362 | 367 | } | 363 | 368 |
| @@ -379,5 +384,27 @@ function requireWithFallbackInDeps(request) { | 379 | 384 | return requireBuiltin(request); | 380 | 385 | } | 381 | 386 |
| | 387 | +function setupPrepareStackTrace() { | | 388 | + const { | | 389 | + setEnhanceStackForFatalException, | | 390 | + setPrepareStackTraceCallback, | | 391 | + } = internalBinding('errors'); | | 392 | + const { | | 393 | + prepareStackTrace, | | 394 | + fatalExceptionStackEnhancers: { | | 395 | + beforeInspector, | | 396 | + afterInspector, | | 397 | + }, | | 398 | + } = requireBuiltin('internal/errors'); | | 399 | + // Tell our PrepareStackTraceCallback passed to the V8 API | | 400 | + // to call prepareStackTrace(). | | 401 | + setPrepareStackTraceCallback(prepareStackTrace); | | 402 | + // Set the function used to enhance the error stack for printing | | 403 | + setEnhanceStackForFatalException(beforeInspector, afterInspector); | | 404 | +} | | 405 | + | 382 | 406 | // Store the internal loaders in C++. | 383 | 407 | setInternalLoaders(internalBinding, requireBuiltin); | | 408 | + | | 409 | +// Setup per-realm bindings. | | 410 | +setupPrepareStackTrace(); |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/main/mksnapshot.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,7 @@ const { | 12 | 12 | } = primordials; | 13 | 13 |
| 14 | 14 | const binding = internalBinding('mksnapshot'); | 15 | | -const { BuiltinModule } = require('internal/bootstrap/loaders'); | | 15 | +const { BuiltinModule } = require('internal/bootstrap/realm'); | 16 | 16 | const { | 17 | 17 | compileSerializeMain, | 18 | 18 | } = binding; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -76,7 +76,7 @@ module.exports = { | 76 | 76 | initializeCJS, | 77 | 77 | }; | 78 | 78 |
| 79 | | -const { BuiltinModule } = require('internal/bootstrap/loaders'); | | 79 | +const { BuiltinModule } = require('internal/bootstrap/realm'); | 80 | 80 | const { | 81 | 81 | maybeCacheSourceMap, | 82 | 82 | } = require('internal/source_map/source_map_cache'); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/esm/hooks.js +1-1Lines changed: 1 addition & 1 deletion | 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 | // | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/esm/resolve.js +1-1Lines changed: 1 addition & 1 deletion | 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, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/helpers.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,7 @@ const { | 18 | 18 | ERR_MANIFEST_DEPENDENCY_MISSING, | 19 | 19 | ERR_UNKNOWN_BUILTIN_MODULE, | 20 | 20 | } = require('internal/errors').codes; | 21 | | -const { BuiltinModule } = require('internal/bootstrap/loaders'); | | 21 | +const { BuiltinModule } = require('internal/bootstrap/realm'); | 22 | 22 |
| 23 | 23 | const { validateString } = require('internal/validators'); | 24 | 24 | const path = require('path'); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/process/pre_execution.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -339,7 +339,7 @@ function initializeReport() { | 339 | 339 | function setupDebugEnv() { | 340 | 340 | require('internal/util/debuglog').initializeDebugEnv(process.env.NODE_DEBUG); | 341 | 341 | if (getOptionValue('--expose-internals')) { | 342 | | - require('internal/bootstrap/loaders').BuiltinModule.exposeInternals(); | | 342 | + require('internal/bootstrap/realm').BuiltinModule.exposeInternals(); | 343 | 343 | } | 344 | 344 | } | 345 | 345 |
| |
|