Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-12-09 05:53:02 +0300
committerRuben Bridgewater <ruben@bridgewater.de>2020-01-03 18:12:08 +0300
commit37ffa8c2aec472ebd6133d387898239875395600 (patch)
tree29f4922c035cba91e93ca8bbc713e75cb46ca24b /src/node.cc
parent93cf1231db5de04bffdbf359dee5682566f8058b (diff)
bootstrap: use different scripts to setup different configurations
This patch splits the handling of `isMainThread` and `ownsProcessState` from conditionals in `lib/internal/bootstrap/node.js` into different scripts under `lib/internal/bootstrap/switches/`, and call them accordingly from C++ after `node.js` is run. This: - Creates a common denominator of the main thread and the worker thread bootstrap that can be snapshotted and shared by both. - Makes it possible to override the configurations on-the-fly. PR-URL: https://github.com/nodejs/node/pull/30862 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Diffstat (limited to 'src/node.cc')
-rw-r--r--src/node.cc47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/node.cc b/src/node.cc
index d8da205b681..f5ae0159d27 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -128,7 +128,6 @@ namespace node {
using native_module::NativeModuleEnv;
-using v8::Boolean;
using v8::EscapableHandleScope;
using v8::Function;
using v8::FunctionCallbackInfo;
@@ -297,26 +296,60 @@ MaybeLocal<Value> Environment::BootstrapNode() {
global->Set(context(), FIXED_ONE_BYTE_STRING(isolate_, "global"), global)
.Check();
- // process, require, internalBinding, isMainThread,
- // ownsProcessState, primordials
+ // process, require, internalBinding, primordials
std::vector<Local<String>> node_params = {
process_string(),
require_string(),
internal_binding_string(),
- FIXED_ONE_BYTE_STRING(isolate_, "isMainThread"),
- FIXED_ONE_BYTE_STRING(isolate_, "ownsProcessState"),
primordials_string()};
std::vector<Local<Value>> node_args = {
process_object(),
native_module_require(),
internal_binding_loader(),
- Boolean::New(isolate_, is_main_thread()),
- Boolean::New(isolate_, owns_process_state()),
primordials()};
MaybeLocal<Value> result = ExecuteBootstrapper(
this, "internal/bootstrap/node", &node_params, &node_args);
+ if (result.IsEmpty()) {
+ return scope.EscapeMaybe(result);
+ }
+
+ if (is_main_thread()) {
+ result = ExecuteBootstrapper(this,
+ "internal/bootstrap/switches/is_main_thread",
+ &node_params,
+ &node_args);
+ } else {
+ result =
+ ExecuteBootstrapper(this,
+ "internal/bootstrap/switches/is_not_main_thread",
+ &node_params,
+ &node_args);
+ }
+
+ if (result.IsEmpty()) {
+ return scope.EscapeMaybe(result);
+ }
+
+ if (owns_process_state()) {
+ result = ExecuteBootstrapper(
+ this,
+ "internal/bootstrap/switches/does_own_process_state",
+ &node_params,
+ &node_args);
+ } else {
+ result = ExecuteBootstrapper(
+ this,
+ "internal/bootstrap/switches/does_not_own_process_state",
+ &node_params,
+ &node_args);
+ }
+
+ if (result.IsEmpty()) {
+ return scope.EscapeMaybe(result);
+ }
+
Local<Object> env_var_proxy;
if (!CreateEnvVarProxy(context(), isolate_, as_callback_data())
.ToLocal(&env_var_proxy) ||