Skip to content

Commit 85bc64a

Browse files
joyeecheungaddaleax
authored andcommitted
process: document the bootstrap process in node.js
PR-URL: #26033 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent bd932a3 commit 85bc64a

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

lib/internal/bootstrap/node.js

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
11
// Hello, and welcome to hacking node.js!
22
//
3-
// This file is invoked by node::LoadEnvironment in src/node.cc, and is
4-
// responsible for bootstrapping the node.js core. As special caution is given
5-
// to the performance of the startup process, many dependencies are invoked
6-
// lazily.
3+
// This file is invoked by `node::RunBootstrapping()` in `src/node.cc`, and is
4+
// responsible for setting up node.js core before executing main scripts
5+
// under `lib/internal/main/`.
6+
// This file is currently run to bootstrap both the main thread and the worker
7+
// threads. Some setups are conditional, controlled with isMainThread and
8+
// ownsProcessState.
9+
// This file is expected not to perform any asynchronous operations itself
10+
// when being executed - those should be done in either
11+
// `lib/internal/bootstrap/pre_execution.js` or in main scripts. The majority
12+
// of the code here focus on setting up the global proxy and the process
13+
// object in a synchronous manner.
14+
// As special caution is given to the performance of the startup process,
15+
// many dependencies are invoked lazily.
716
//
8-
// Before this file is run, lib/internal/bootstrap/loaders.js gets run first
9-
// to bootstrap the internal binding and module loaders, including
10-
// process.binding(), process._linkedBinding(), internalBinding() and
11-
// NativeModule. And then { internalBinding, NativeModule } will be passed
12-
// into this bootstrapper to bootstrap Node.js core.
17+
// Scripts run before this file:
18+
// - `lib/internal/bootstrap/context.js`: to setup the v8::Context with
19+
// Node.js-specific tweaks - this is also done in vm contexts.
20+
// - `lib/internal/bootstrap/primordials.js`: to save copies of JavaScript
21+
// builtins that won't be affected by user land monkey-patching for internal
22+
// modules to use.
23+
// - `lib/internal/bootstrap/loaders.js`: to setup internal binding and
24+
// module loaders, including `process.binding()`, `process._linkedBinding()`,
25+
// `internalBinding()` and `NativeModule`.
26+
//
27+
// After this file is run, one of the main scripts under `lib/internal/main/`
28+
// will be selected by C++ to start the actual execution. The main scripts may
29+
// run additional setups exported by `lib/internal/bootstrap/pre_execution.js`,
30+
// depending on the execution mode.
31+
1332
'use strict';
1433

1534
// This file is compiled as if it's wrapped in a function with arguments
16-
// passed by node::LoadEnvironment()
35+
// passed by node::RunBootstrapping()
1736
/* global process, loaderExports, isMainThread, ownsProcessState */
1837

1938
const { internalBinding, NativeModule } = loaderExports;

0 commit comments

Comments
 (0)