src: use CreateEnvironment instead of inlining its code where possible
We had a number of places in which we created an `Environment` instance by performing each step in `CreateEnvironment` manually. Instead, just call the function itself. PR-URL: https://github.com/nodejs/node/pull/45886 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
parent
70d269de77
commit
01323d50c4
@ -375,12 +375,13 @@ Environment* CreateEnvironment(
|
|||||||
// options than the global parse call.
|
// options than the global parse call.
|
||||||
Environment* env = new Environment(
|
Environment* env = new Environment(
|
||||||
isolate_data, context, args, exec_args, nullptr, flags, thread_id);
|
isolate_data, context, args, exec_args, nullptr, flags, thread_id);
|
||||||
|
|
||||||
#if HAVE_INSPECTOR
|
#if HAVE_INSPECTOR
|
||||||
if (env->should_create_inspector()) {
|
if (env->should_create_inspector()) {
|
||||||
if (inspector_parent_handle) {
|
if (inspector_parent_handle) {
|
||||||
env->InitializeInspector(
|
env->InitializeInspector(std::move(
|
||||||
std::move(static_cast<InspectorParentHandleImpl*>(
|
static_cast<InspectorParentHandleImpl*>(inspector_parent_handle.get())
|
||||||
inspector_parent_handle.get())->impl));
|
->impl));
|
||||||
} else {
|
} else {
|
||||||
env->InitializeInspector({});
|
env->InitializeInspector({});
|
||||||
}
|
}
|
||||||
|
@ -191,19 +191,8 @@ NodeMainInstance::CreateMainEnvironment(ExitCode* exit_code) {
|
|||||||
context = NewContext(isolate_);
|
context = NewContext(isolate_);
|
||||||
CHECK(!context.IsEmpty());
|
CHECK(!context.IsEmpty());
|
||||||
Context::Scope context_scope(context);
|
Context::Scope context_scope(context);
|
||||||
env.reset(new Environment(isolate_data_.get(),
|
env.reset(
|
||||||
context,
|
CreateEnvironment(isolate_data_.get(), context, args_, exec_args_));
|
||||||
args_,
|
|
||||||
exec_args_,
|
|
||||||
nullptr,
|
|
||||||
EnvironmentFlags::kDefaultFlags,
|
|
||||||
{}));
|
|
||||||
#if HAVE_INSPECTOR
|
|
||||||
env->InitializeInspector({});
|
|
||||||
#endif
|
|
||||||
if (env->principal_realm()->RunBootstrapping().IsEmpty()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
|
@ -1151,16 +1151,21 @@ ExitCode SnapshotBuilder::Generate(SnapshotData* out,
|
|||||||
Context::Scope context_scope(main_context);
|
Context::Scope context_scope(main_context);
|
||||||
|
|
||||||
// Create the environment.
|
// Create the environment.
|
||||||
env = new Environment(main_instance->isolate_data(),
|
// It's not guaranteed that a context that goes through
|
||||||
main_context,
|
// v8_inspector::V8Inspector::contextCreated() is runtime-independent,
|
||||||
args,
|
// so do not start the inspector on the main context when building
|
||||||
exec_args,
|
// the default snapshot.
|
||||||
nullptr,
|
uint64_t env_flags = EnvironmentFlags::kDefaultFlags |
|
||||||
node::EnvironmentFlags::kDefaultFlags,
|
EnvironmentFlags::kNoCreateInspector;
|
||||||
{});
|
|
||||||
|
|
||||||
// Run scripts in lib/internal/bootstrap/
|
env = CreateEnvironment(main_instance->isolate_data(),
|
||||||
if (env->principal_realm()->RunBootstrapping().IsEmpty()) {
|
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 ExitCode::kBootstrapFailure;
|
return ExitCode::kBootstrapFailure;
|
||||||
}
|
}
|
||||||
// If --build-snapshot is true, lib/internal/main/mksnapshot.js would be
|
// If --build-snapshot is true, lib/internal/main/mksnapshot.js would be
|
||||||
|
Loading…
x
Reference in New Issue
Block a user