Skip to content

Commit

Permalink
src: create per isolate proxy env template
Browse files Browse the repository at this point in the history
PR-URL: #48655
Backport-PR-URL: #51239
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
legendecas authored and UlisesGascon committed Jan 9, 2024
1 parent d00412a commit 11b3e47
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ void IsolateData::CreateProperties() {
binding::CreateInternalBindingTemplates(this);

contextify::ContextifyContext::InitializeGlobalTemplates(this);
CreateEnvProxyTemplate(this);
}

constexpr uint16_t kDefaultCppGCEmebdderID = 0x90de;
Expand Down
3 changes: 2 additions & 1 deletion src/node_env_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ static void EnvDefiner(Local<Name> 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<FunctionTemplate> env_proxy_ctor_template =
Expand Down
2 changes: 1 addition & 1 deletion src/node_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/node_realm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,11 @@ MaybeLocal<Value> PrincipalRealm::BootstrapRealm() {
return MaybeLocal<Value>();
}

// Setup process.env proxy.
Local<String> env_string = FIXED_ONE_BYTE_STRING(isolate_, "env");
Local<Object> 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<Value>();
}
Expand Down

0 comments on commit 11b3e47

Please sign in to comment.