diff --git a/src/env.cc b/src/env.cc index 4a25309449c8c7..0befcbd6c25570 100644 --- a/src/env.cc +++ b/src/env.cc @@ -501,6 +501,7 @@ void IsolateData::CreateProperties() { binding::CreateInternalBindingTemplates(this); contextify::ContextifyContext::InitializeGlobalTemplates(this); + CreateEnvProxyTemplate(this); } constexpr uint16_t kDefaultCppGCEmebdderID = 0x90de; diff --git a/src/node_env_var.cc b/src/node_env_var.cc index 94936ea1c2bd22..bce7ae07214ddf 100644 --- a/src/node_env_var.cc +++ b/src/node_env_var.cc @@ -456,7 +456,8 @@ static void EnvDefiner(Local property, } } -void CreateEnvProxyTemplate(Isolate* isolate, IsolateData* isolate_data) { +void CreateEnvProxyTemplate(IsolateData* isolate_data) { + Isolate* isolate = isolate_data->isolate(); HandleScope scope(isolate); if (!isolate_data->env_proxy_template().IsEmpty()) return; Local env_proxy_ctor_template = diff --git a/src/node_process.h b/src/node_process.h index c911b3ddd7b78f..ee6e6a81676bd6 100644 --- a/src/node_process.h +++ b/src/node_process.h @@ -15,7 +15,7 @@ class MemoryTracker; class ExternalReferenceRegistry; class Realm; -void CreateEnvProxyTemplate(v8::Isolate* isolate, IsolateData* isolate_data); +void CreateEnvProxyTemplate(IsolateData* isolate_data); // Most of the time, it's best to use `console.error` to write // to the process.stderr stream. However, in some cases, such as diff --git a/src/node_realm.cc b/src/node_realm.cc index 7101b23e347c7c..23fb6bd55213ee 100644 --- a/src/node_realm.cc +++ b/src/node_realm.cc @@ -344,10 +344,11 @@ MaybeLocal PrincipalRealm::BootstrapRealm() { return MaybeLocal(); } + // Setup process.env proxy. Local env_string = FIXED_ONE_BYTE_STRING(isolate_, "env"); Local env_proxy; - CreateEnvProxyTemplate(isolate_, env_->isolate_data()); - if (!env_->env_proxy_template()->NewInstance(context()).ToLocal(&env_proxy) || + if (!isolate_data()->env_proxy_template()->NewInstance(context()).ToLocal( + &env_proxy) || process_object()->Set(context(), env_string, env_proxy).IsNothing()) { return MaybeLocal(); }