From 62c640b5a22bdd8cb99ff00577e9ddb5b380f550 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 19 Sep 2022 20:50:47 +0800 Subject: [PATCH 1/2] bootstrap: update comments in bootstrap/node.js The comments in bootstrap/node.js are now out of date due to recent changes to the bootstrap process. Update them to reflect the current status. --- lib/internal/bootstrap/node.js | 48 ++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 4295ce79d88956..ab6f2d8f0aec8c 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -1,39 +1,55 @@ // Hello, and welcome to hacking node.js! // -// This file is invoked by `node::RunBootstrapping()` in `src/node.cc`, and is -// responsible for setting up node.js core before executing main scripts -// under `lib/internal/main/`. +// This file is invoked by `Realm::BootstrapNode()` in `src/node_realm.cc`, +// and is responsible for setting up node.js core before main scripts +// under `lib/internal/main/` are executed. // -// This file is expected not to perform any asynchronous operations itself +// By default, Node.js binaries come with an embedded V8 startup snapshot +// that is generated at build-time with a `node_mksnapshot` executable. +// The snapshot generation code can be found in `SnapshotBuilder::Generate()` +// from `src/node_snapshotable.cc` +// This snapshot captures the V8 heap initialized by scripts under +// `lib/internal/bootstrap/`, including this file. When initializing the main +// thread, Node.js deserializes the heap from the snapshot, instead of actually +// running this script and others in `lib/internal/bootstrap/`. To disable this +// behavior, pass `--no-node-snapshot` when starting the process so that +// Node.js actually runs this script to initialize the heap. +// +// This script is expected not to perform any asynchronous operations itself // when being executed - those should be done in either -// `lib/internal/process/pre_execution.js` or in main scripts. The majority -// of the code here focuses on setting up the global proxy and the process -// object in a synchronous manner. -// As special caution is given to the performance of the startup process, -// many dependencies are invoked lazily. +// `lib/internal/process/pre_execution.js` or in main scripts. It should not +// query any run-time states (e.g. command line arguments, environment +// variables) when being executed - functions in this script that are invoked +// at a later time can, however, query those states lazily. +// The majority of the code here focuses on setting up the global object and +// the process object in a synchronous, environment-independent manner. // // Scripts run before this file: -// - `lib/internal/per_context/primordials.js`: to save copies of JavaScript +// - `lib/internal/per_context/primordials.js`: this saves copies of JavaScript // builtins that won't be affected by user land monkey-patching for internal // modules to use. -// - `lib/internal/bootstrap/loaders.js`: to setup internal binding and +// - `lib/internal/per_context/domexception.js`: implementation of the +// `DOMException` class. +// - `lib/internal/per_context/messageport.js`: JS-side components of the +// `MessagePort` implementation. +// - `lib/internal/bootstrap/loaders.js`: this sets up internal binding and // module loaders, including `process.binding()`, `process._linkedBinding()`, // `internalBinding()` and `BuiltinModule`. // -// This file is run to bootstrap both the main thread and the worker threads. -// After this file is run, certain properties are setup according to the -// configuration of the Node.js instance using the files in +// The initialization done in this script is included in both the main thread +// and the worker threads. After this, further initialization is done based +// on the configuration of the Node.js instance by executing the scripts in // `lib/internal/bootstrap/switches/`. // // Then, depending on how the Node.js instance is launched, one of the main // scripts in `lib/internal/main` will be selected by C++ to start the actual // execution. They may run additional setups exported by -// `lib/internal/process/pre_execution.js` depending on the runtime states. +// `lib/internal/process/pre_execution.js` depending on the run-time states. 'use strict'; // This file is compiled as if it's wrapped in a function with arguments -// passed by node::RunBootstrapping() +// passed by BuiltinLoader::CompileAndCall(). /* global process, require, internalBinding, primordials */ setupPrepareStackTrace(); From ccd57622dba6a1c7c579236006182b3e3b86d3b6 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 20 Sep 2022 19:36:35 +0800 Subject: [PATCH 2/2] fixup! bootstrap: update comments in bootstrap/node.js Co-authored-by: Luigi Pinca Co-authored-by: Daeyeon Jeong --- lib/internal/bootstrap/node.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index ab6f2d8f0aec8c..f267d28d3821cd 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -1,13 +1,13 @@ // Hello, and welcome to hacking node.js! // // This file is invoked by `Realm::BootstrapNode()` in `src/node_realm.cc`, -// and is responsible for setting up node.js core before main scripts +// and is responsible for setting up Node.js core before main scripts // under `lib/internal/main/` are executed. // // By default, Node.js binaries come with an embedded V8 startup snapshot // that is generated at build-time with a `node_mksnapshot` executable. // The snapshot generation code can be found in `SnapshotBuilder::Generate()` -// from `src/node_snapshotable.cc` +// from `src/node_snapshotable.cc`. // This snapshot captures the V8 heap initialized by scripts under // `lib/internal/bootstrap/`, including this file. When initializing the main // thread, Node.js deserializes the heap from the snapshot, instead of actually @@ -49,7 +49,7 @@ 'use strict'; // This file is compiled as if it's wrapped in a function with arguments -// passed by BuiltinLoader::CompileAndCall(). +// passed by `BuiltinLoader::CompileAndCall()`. /* global process, require, internalBinding, primordials */ setupPrepareStackTrace();