|
1 | 1 | // Hello, and welcome to hacking node.js!
|
2 | 2 | //
|
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/`. |
| 3 | +// This file is invoked by `Realm::BootstrapNode()` in `src/node_realm.cc`, |
| 4 | +// and is responsible for setting up Node.js core before main scripts |
| 5 | +// under `lib/internal/main/` are executed. |
6 | 6 | //
|
7 |
| -// This file is expected not to perform any asynchronous operations itself |
| 7 | +// By default, Node.js binaries come with an embedded V8 startup snapshot |
| 8 | +// that is generated at build-time with a `node_mksnapshot` executable. |
| 9 | +// The snapshot generation code can be found in `SnapshotBuilder::Generate()` |
| 10 | +// from `src/node_snapshotable.cc`. |
| 11 | +// This snapshot captures the V8 heap initialized by scripts under |
| 12 | +// `lib/internal/bootstrap/`, including this file. When initializing the main |
| 13 | +// thread, Node.js deserializes the heap from the snapshot, instead of actually |
| 14 | +// running this script and others in `lib/internal/bootstrap/`. To disable this |
| 15 | +// behavior, pass `--no-node-snapshot` when starting the process so that |
| 16 | +// Node.js actually runs this script to initialize the heap. |
| 17 | +// |
| 18 | +// This script is expected not to perform any asynchronous operations itself |
8 | 19 | // when being executed - those should be done in either
|
9 |
| -// `lib/internal/process/pre_execution.js` or in main scripts. The majority |
10 |
| -// of the code here focuses on setting up the global proxy and the process |
11 |
| -// object in a synchronous manner. |
12 |
| -// As special caution is given to the performance of the startup process, |
13 |
| -// many dependencies are invoked lazily. |
| 20 | +// `lib/internal/process/pre_execution.js` or in main scripts. It should not |
| 21 | +// query any run-time states (e.g. command line arguments, environment |
| 22 | +// variables) when being executed - functions in this script that are invoked |
| 23 | +// at a later time can, however, query those states lazily. |
| 24 | +// The majority of the code here focuses on setting up the global object and |
| 25 | +// the process object in a synchronous, environment-independent manner. |
14 | 26 | //
|
15 | 27 | // Scripts run before this file:
|
16 |
| -// - `lib/internal/per_context/primordials.js`: to save copies of JavaScript |
| 28 | +// - `lib/internal/per_context/primordials.js`: this saves copies of JavaScript |
17 | 29 | // builtins that won't be affected by user land monkey-patching for internal
|
18 | 30 | // modules to use.
|
19 |
| -// - `lib/internal/bootstrap/loaders.js`: to setup internal binding and |
| 31 | +// - `lib/internal/per_context/domexception.js`: implementation of the |
| 32 | +// `DOMException` class. |
| 33 | +// - `lib/internal/per_context/messageport.js`: JS-side components of the |
| 34 | +// `MessagePort` implementation. |
| 35 | +// - `lib/internal/bootstrap/loaders.js`: this sets up internal binding and |
20 | 36 | // module loaders, including `process.binding()`, `process._linkedBinding()`,
|
21 | 37 | // `internalBinding()` and `BuiltinModule`.
|
22 | 38 | //
|
23 |
| -// This file is run to bootstrap both the main thread and the worker threads. |
24 |
| -// After this file is run, certain properties are setup according to the |
25 |
| -// configuration of the Node.js instance using the files in |
| 39 | +// The initialization done in this script is included in both the main thread |
| 40 | +// and the worker threads. After this, further initialization is done based |
| 41 | +// on the configuration of the Node.js instance by executing the scripts in |
26 | 42 | // `lib/internal/bootstrap/switches/`.
|
27 | 43 | //
|
28 | 44 | // Then, depending on how the Node.js instance is launched, one of the main
|
29 | 45 | // scripts in `lib/internal/main` will be selected by C++ to start the actual
|
30 | 46 | // execution. They may run additional setups exported by
|
31 |
| -// `lib/internal/process/pre_execution.js` depending on the runtime states. |
| 47 | +// `lib/internal/process/pre_execution.js` depending on the run-time states. |
32 | 48 |
|
33 | 49 | 'use strict';
|
34 | 50 |
|
35 | 51 | // This file is compiled as if it's wrapped in a function with arguments
|
36 |
| -// passed by node::RunBootstrapping() |
| 52 | +// passed by `BuiltinLoader::CompileAndCall()`. |
37 | 53 | /* global process, require, internalBinding, primordials */
|
38 | 54 |
|
39 | 55 | setupPrepareStackTrace();
|
|
0 commit comments