Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v18.x backport] src: use CreateEnvironment instead of inlining its code where possible #46330

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,13 @@ Environment* CreateEnvironment(
// options than the global parse call.
Environment* env = new Environment(
isolate_data, context, args, exec_args, nullptr, flags, thread_id);

#if HAVE_INSPECTOR
if (env->should_create_inspector()) {
if (inspector_parent_handle) {
env->InitializeInspector(
std::move(static_cast<InspectorParentHandleImpl*>(
inspector_parent_handle.get())->impl));
env->InitializeInspector(std::move(
static_cast<InspectorParentHandleImpl*>(inspector_parent_handle.get())
->impl));
} else {
env->InitializeInspector({});
}
Expand Down
15 changes: 2 additions & 13 deletions src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,8 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code) {
context = NewContext(isolate_);
CHECK(!context.IsEmpty());
Context::Scope context_scope(context);
env.reset(new Environment(isolate_data_.get(),
context,
args_,
exec_args_,
nullptr,
EnvironmentFlags::kDefaultFlags,
{}));
#if HAVE_INSPECTOR
env->InitializeInspector({});
#endif
if (env->principal_realm()->RunBootstrapping().IsEmpty()) {
return nullptr;
}
env.reset(
CreateEnvironment(isolate_data_.get(), context, args_, exec_args_));
}

return env;
Expand Down
25 changes: 15 additions & 10 deletions src/node_snapshotable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1159,16 +1159,21 @@ int SnapshotBuilder::Generate(SnapshotData* out,
Context::Scope context_scope(main_context);

// Create the environment.
env = new Environment(main_instance->isolate_data(),
main_context,
args,
exec_args,
nullptr,
node::EnvironmentFlags::kDefaultFlags,
{});

// Run scripts in lib/internal/bootstrap/
if (env->principal_realm()->RunBootstrapping().IsEmpty()) {
// It's not guaranteed that a context that goes through
// v8_inspector::V8Inspector::contextCreated() is runtime-independent,
// so do not start the inspector on the main context when building
// the default snapshot.
uint64_t env_flags = EnvironmentFlags::kDefaultFlags |
EnvironmentFlags::kNoCreateInspector;

env = CreateEnvironment(main_instance->isolate_data(),
main_context,
args,
exec_args,
static_cast<EnvironmentFlags::Flags>(env_flags));

// This already ran scripts in lib/internal/bootstrap/, if it fails return
if (env == nullptr) {
return BOOTSTRAP_ERROR;
}
// If --build-snapshot is true, lib/internal/main/mksnapshot.js would be
Expand Down