diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2021-01-28 17:00:03 +0300 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2021-02-05 15:10:29 +0300 |
commit | 9aeb83643486328cbdffb55a23efe953f6ee54e0 (patch) | |
tree | e5f192f2ba3d20065b2cf01b2b344ef4b37e5c7f /src/node_main_instance.cc | |
parent | 664cce92ec09363d5a37c9f2a360ee0810fe30e3 (diff) |
src: refactor bookkeeping of bootstrap status
This patch
1. Refactors the bootstrap routine of the main instance so that
when --no-node-snapshot is used,
Environment::InitializeMainContext() will only be called once
(previously it would be called twice, which was harmless for now
but not ideal).
2. Mark the number of BaseObjects in RunBootstrapping() when creating
the Environment from scratch and in InitializeMainContext() when
the Environment is deserialized. Previously the marking was done in
the Environment constructor and InitializeMainContext() respectively
for the cctest which was incorrect because the cctest never uses
an Environment that's not bootstrapped. Also renames the mark
to base_object_created_after_bootstrap to reflect what it's
intended for.
PR-URL: https://github.com/nodejs/node/pull/37113
Refs: https://github.com/nodejs/node/pull/36943
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_main_instance.cc')
-rw-r--r-- | src/node_main_instance.cc | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index 07277ccfa5c..8ffeef0e8ae 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -209,10 +209,18 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code, {DeserializeNodeInternalFields, env.get()}) .ToLocalChecked(); + CHECK(!context.IsEmpty()); + Context::Scope context_scope(context); InitializeContextRuntime(context); SetIsolateErrorHandlers(isolate_, {}); + env->InitializeMainContext(context, env_info); +#if HAVE_INSPECTOR + env->InitializeInspector({}); +#endif + env->DoneBootstrapping(); } else { context = NewContext(isolate_); + CHECK(!context.IsEmpty()); Context::Scope context_scope(context); env.reset(new Environment(isolate_data_.get(), context, @@ -221,24 +229,16 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code, nullptr, EnvironmentFlags::kDefaultFlags, {})); - } - - CHECK(!context.IsEmpty()); - Context::Scope context_scope(context); - - env->InitializeMainContext(context, env_info); - #if HAVE_INSPECTOR - env->InitializeInspector({}); + env->InitializeInspector({}); #endif - - if (!deserialize_mode_ && env->RunBootstrapping().IsEmpty()) { - return nullptr; + if (env->RunBootstrapping().IsEmpty()) { + return nullptr; + } } CHECK(env->req_wrap_queue()->IsEmpty()); CHECK(env->handle_wrap_queue()->IsEmpty()); - env->set_has_run_bootstrapping_code(true); return env; } |