Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e8bedd2

Browse filesBrowse files
joyeecheungBridgeAR
authored andcommitted
src: split RunBootstrapping()
Split `RunBootstrapping()` into `BootstrapInternalLoaders()` and `BootstrapNode()` from so the two can be snapshotted incrementally. PR-URL: #27539 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent c20c6e5 commit e8bedd2
Copy full SHA for e8bedd2

File tree

Expand file treeCollapse file tree

6 files changed

+82
-68
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+82
-68
lines changed
Open diff view settings
Collapse file

‎src/api/environment.cc‎

Copy file name to clipboardExpand all lines: src/api/environment.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Environment* CreateEnvironment(IsolateData* isolate_data,
287287
Environment::kOwnsProcessState |
288288
Environment::kOwnsInspector));
289289
env->InitializeLibuv(per_process::v8_is_profiling);
290-
if (RunBootstrapping(env).IsEmpty()) {
290+
if (env->RunBootstrapping().IsEmpty()) {
291291
return nullptr;
292292
}
293293

Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,10 @@ class Environment : public MemoryRetainer {
809809
int InitializeInspector(inspector::ParentInspectorHandle* parent_handle);
810810
#endif
811811

812+
v8::MaybeLocal<v8::Value> BootstrapInternalLoaders();
813+
v8::MaybeLocal<v8::Value> BootstrapNode();
814+
v8::MaybeLocal<v8::Value> RunBootstrapping();
815+
812816
inline size_t async_callback_scope_depth() const;
813817
inline void PushAsyncCallbackScope();
814818
inline void PopAsyncCallbackScope();
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+75-64Lines changed: 75 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ using options_parser::kAllowedInEnvironment;
119119
using options_parser::kDisallowedInEnvironment;
120120

121121
using v8::Boolean;
122-
using v8::Context;
123122
using v8::EscapableHandleScope;
124123
using v8::Exception;
125124
using v8::Function;
@@ -271,99 +270,111 @@ void Environment::InitializeDiagnostics() {
271270
#endif
272271
}
273272

274-
MaybeLocal<Value> RunBootstrapping(Environment* env) {
275-
CHECK(!env->has_run_bootstrapping_code());
276-
277-
EscapableHandleScope scope(env->isolate());
278-
Isolate* isolate = env->isolate();
279-
Local<Context> context = env->context();
280-
281-
282-
// Add a reference to the global object
283-
Local<Object> global = context->Global();
284-
Local<Object> process = env->process_object();
285-
286-
// Setting global properties for the bootstrappers to use:
287-
// - global
288-
// Expose the global object as a property on itself
289-
// (Allows you to set stuff on `global` from anywhere in JavaScript.)
290-
global->Set(context, FIXED_ONE_BYTE_STRING(env->isolate(), "global"), global)
291-
.Check();
292-
273+
MaybeLocal<Value> Environment::BootstrapInternalLoaders() {
274+
EscapableHandleScope scope(isolate_);
293275

294276
// Create binding loaders
295277
std::vector<Local<String>> loaders_params = {
296-
env->process_string(),
297-
FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"),
298-
FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"),
299-
env->primordials_string()};
278+
process_string(),
279+
FIXED_ONE_BYTE_STRING(isolate_, "getLinkedBinding"),
280+
FIXED_ONE_BYTE_STRING(isolate_, "getInternalBinding"),
281+
primordials_string()};
300282
std::vector<Local<Value>> loaders_args = {
301-
process,
302-
env->NewFunctionTemplate(binding::GetLinkedBinding)
303-
->GetFunction(context)
283+
process_object(),
284+
NewFunctionTemplate(binding::GetLinkedBinding)
285+
->GetFunction(context())
304286
.ToLocalChecked(),
305-
env->NewFunctionTemplate(binding::GetInternalBinding)
306-
->GetFunction(context)
287+
NewFunctionTemplate(binding::GetInternalBinding)
288+
->GetFunction(context())
307289
.ToLocalChecked(),
308-
env->primordials()};
290+
primordials()};
309291

310292
// Bootstrap internal loaders
311-
MaybeLocal<Value> loader_exports = ExecuteBootstrapper(
312-
env, "internal/bootstrap/loaders", &loaders_params, &loaders_args);
313-
if (loader_exports.IsEmpty()) {
293+
Local<Value> loader_exports;
294+
if (!ExecuteBootstrapper(
295+
this, "internal/bootstrap/loaders", &loaders_params, &loaders_args)
296+
.ToLocal(&loader_exports)) {
314297
return MaybeLocal<Value>();
315298
}
316-
317-
Local<Object> loader_exports_obj =
318-
loader_exports.ToLocalChecked().As<Object>();
299+
CHECK(loader_exports->IsObject());
300+
Local<Object> loader_exports_obj = loader_exports.As<Object>();
319301
Local<Value> internal_binding_loader =
320-
loader_exports_obj->Get(context, env->internal_binding_string())
302+
loader_exports_obj->Get(context(), internal_binding_string())
321303
.ToLocalChecked();
322-
env->set_internal_binding_loader(internal_binding_loader.As<Function>());
323-
304+
CHECK(internal_binding_loader->IsFunction());
305+
set_internal_binding_loader(internal_binding_loader.As<Function>());
324306
Local<Value> require =
325-
loader_exports_obj->Get(context, env->require_string()).ToLocalChecked();
326-
env->set_native_module_require(require.As<Function>());
307+
loader_exports_obj->Get(context(), require_string()).ToLocalChecked();
308+
CHECK(require->IsFunction());
309+
set_native_module_require(require.As<Function>());
310+
311+
return scope.Escape(loader_exports);
312+
}
313+
314+
MaybeLocal<Value> Environment::BootstrapNode() {
315+
EscapableHandleScope scope(isolate_);
316+
317+
Local<Object> global = context()->Global();
318+
// TODO(joyeecheung): this can be done in JS land now.
319+
global->Set(context(), FIXED_ONE_BYTE_STRING(isolate_, "global"), global)
320+
.Check();
327321

328322
// process, require, internalBinding, isMainThread,
329323
// ownsProcessState, primordials
330324
std::vector<Local<String>> node_params = {
331-
env->process_string(),
332-
env->require_string(),
333-
env->internal_binding_string(),
334-
FIXED_ONE_BYTE_STRING(isolate, "isMainThread"),
335-
FIXED_ONE_BYTE_STRING(isolate, "ownsProcessState"),
336-
env->primordials_string()};
325+
process_string(),
326+
require_string(),
327+
internal_binding_string(),
328+
FIXED_ONE_BYTE_STRING(isolate_, "isMainThread"),
329+
FIXED_ONE_BYTE_STRING(isolate_, "ownsProcessState"),
330+
primordials_string()};
337331
std::vector<Local<Value>> node_args = {
338-
process,
339-
require,
340-
internal_binding_loader,
341-
Boolean::New(isolate, env->is_main_thread()),
342-
Boolean::New(isolate, env->owns_process_state()),
343-
env->primordials()};
332+
process_object(),
333+
native_module_require(),
334+
internal_binding_loader(),
335+
Boolean::New(isolate_, is_main_thread()),
336+
Boolean::New(isolate_, owns_process_state()),
337+
primordials()};
344338

345339
MaybeLocal<Value> result = ExecuteBootstrapper(
346-
env, "internal/bootstrap/node", &node_params, &node_args);
340+
this, "internal/bootstrap/node", &node_params, &node_args);
347341

348342
Local<Object> env_var_proxy;
349-
if (!CreateEnvVarProxy(context, isolate, env->as_callback_data())
343+
if (!CreateEnvVarProxy(context(), isolate_, as_callback_data())
350344
.ToLocal(&env_var_proxy) ||
351-
process
352-
->Set(env->context(),
353-
FIXED_ONE_BYTE_STRING(env->isolate(), "env"),
354-
env_var_proxy)
355-
.IsNothing())
345+
process_object()
346+
->Set(
347+
context(), FIXED_ONE_BYTE_STRING(isolate_, "env"), env_var_proxy)
348+
.IsNothing()) {
349+
return MaybeLocal<Value>();
350+
}
351+
352+
return scope.EscapeMaybe(result);
353+
}
354+
355+
MaybeLocal<Value> Environment::RunBootstrapping() {
356+
EscapableHandleScope scope(isolate_);
357+
358+
CHECK(!has_run_bootstrapping_code());
359+
360+
if (BootstrapInternalLoaders().IsEmpty()) {
361+
return MaybeLocal<Value>();
362+
}
363+
364+
Local<Value> result;
365+
if (!BootstrapNode().ToLocal(&result)) {
356366
return MaybeLocal<Value>();
367+
}
357368

358369
// Make sure that no request or handle is created during bootstrap -
359370
// if necessary those should be done in pre-execution.
360371
// TODO(joyeecheung): print handles/requests before aborting
361-
CHECK(env->req_wrap_queue()->IsEmpty());
362-
CHECK(env->handle_wrap_queue()->IsEmpty());
372+
CHECK(req_wrap_queue()->IsEmpty());
373+
CHECK(handle_wrap_queue()->IsEmpty());
363374

364-
env->set_has_run_bootstrapping_code(true);
375+
set_has_run_bootstrapping_code(true);
365376

366-
return scope.EscapeMaybe(result);
377+
return scope.Escape(result);
367378
}
368379

369380
void MarkBootstrapComplete(const FunctionCallbackInfo<Value>& args) {
Collapse file

‎src/node_internals.h‎

Copy file name to clipboardExpand all lines: src/node_internals.h
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ void DefineZlibConstants(v8::Local<v8::Object> target);
278278
v8::Isolate* NewIsolate(v8::Isolate::CreateParams* params,
279279
uv_loop_t* event_loop,
280280
MultiIsolatePlatform* platform);
281-
v8::MaybeLocal<v8::Value> RunBootstrapping(Environment* env);
282281
v8::MaybeLocal<v8::Value> StartExecution(Environment* env,
283282
const char* main_script_id);
284283
v8::MaybeLocal<v8::Object> GetPerContextExports(v8::Local<v8::Context> context);
Collapse file

‎src/node_main_instance.cc‎

Copy file name to clipboardExpand all lines: src/node_main_instance.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment(
205205
return env;
206206
}
207207

208-
if (RunBootstrapping(env.get()).IsEmpty()) {
208+
if (env->RunBootstrapping().IsEmpty()) {
209209
*exit_code = 1;
210210
}
211211

Collapse file

‎src/node_worker.cc‎

Copy file name to clipboardExpand all lines: src/node_worker.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ void Worker::Run() {
271271
HandleScope handle_scope(isolate_);
272272
AsyncCallbackScope callback_scope(env_.get());
273273
env_->async_hooks()->push_async_ids(1, 0);
274-
if (!RunBootstrapping(env_.get()).IsEmpty()) {
274+
if (!env_->RunBootstrapping().IsEmpty()) {
275275
CreateEnvMessagePort(env_.get());
276276
if (is_stopped()) return;
277277
Debug(this, "Created message port for worker %llu", thread_id_);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.