Skip to content

Commit 49cfb9d

Browse files
richardlautargos
authored andcommitted
src: reset process.versions during pre-execution
Reset `process.versions` during pre-execution so that it reflects the versions at run-time rather than when the snapshot was taken. PR-URL: #53444 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 30858ec commit 49cfb9d

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

src/node_process_object.cc

+37-27
Original file line numberDiff line numberDiff line change
@@ -78,34 +78,9 @@ static void GetParentProcessId(Local<Name> property,
7878
info.GetReturnValue().Set(uv_os_getppid());
7979
}
8080

81-
MaybeLocal<Object> CreateProcessObject(Realm* realm) {
82-
Isolate* isolate = realm->isolate();
83-
EscapableHandleScope scope(isolate);
84-
Local<Context> context = realm->context();
85-
86-
Local<FunctionTemplate> process_template = FunctionTemplate::New(isolate);
87-
process_template->SetClassName(realm->env()->process_string());
88-
Local<Function> process_ctor;
89-
Local<Object> process;
90-
if (!process_template->GetFunction(context).ToLocal(&process_ctor) ||
91-
!process_ctor->NewInstance(context).ToLocal(&process)) {
92-
return MaybeLocal<Object>();
93-
}
94-
95-
// process[exit_info_private_symbol]
96-
if (process
97-
->SetPrivate(context,
98-
realm->env()->exit_info_private_symbol(),
99-
realm->env()->exit_info().GetJSArray())
100-
.IsNothing()) {
101-
return {};
102-
}
103-
104-
// process.version
105-
READONLY_PROPERTY(
106-
process, "version", FIXED_ONE_BYTE_STRING(isolate, NODE_VERSION));
81+
static void SetVersions(Isolate* isolate, Local<Object> versions) {
82+
Local<Context> context = isolate->GetCurrentContext();
10783

108-
Local<Object> versions = Object::New(isolate);
10984
// Node.js version is always on the top
11085
READONLY_STRING_PROPERTY(
11186
versions, "node", per_process::metadata.versions.node);
@@ -138,8 +113,38 @@ MaybeLocal<Object> CreateProcessObject(Realm* realm) {
138113
v8::ReadOnly)
139114
.Check();
140115
}
116+
}
117+
118+
MaybeLocal<Object> CreateProcessObject(Realm* realm) {
119+
Isolate* isolate = realm->isolate();
120+
EscapableHandleScope scope(isolate);
121+
Local<Context> context = realm->context();
122+
123+
Local<FunctionTemplate> process_template = FunctionTemplate::New(isolate);
124+
process_template->SetClassName(realm->env()->process_string());
125+
Local<Function> process_ctor;
126+
Local<Object> process;
127+
if (!process_template->GetFunction(context).ToLocal(&process_ctor) ||
128+
!process_ctor->NewInstance(context).ToLocal(&process)) {
129+
return MaybeLocal<Object>();
130+
}
131+
132+
// process[exit_info_private_symbol]
133+
if (process
134+
->SetPrivate(context,
135+
realm->env()->exit_info_private_symbol(),
136+
realm->env()->exit_info().GetJSArray())
137+
.IsNothing()) {
138+
return {};
139+
}
140+
141+
// process.version
142+
READONLY_PROPERTY(
143+
process, "version", FIXED_ONE_BYTE_STRING(isolate, NODE_VERSION));
141144

142145
// process.versions
146+
Local<Object> versions = Object::New(isolate);
147+
SetVersions(isolate, versions);
143148
READONLY_PROPERTY(process, "versions", versions);
144149

145150
// process.arch
@@ -241,6 +246,11 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
241246
env->owns_process_state() ? DebugPortSetter : nullptr,
242247
Local<Value>())
243248
.FromJust());
249+
250+
// process.versions
251+
Local<Object> versions = Object::New(isolate);
252+
SetVersions(isolate, versions);
253+
READONLY_PROPERTY(process, "versions", versions);
244254
}
245255

246256
void RegisterProcessExternalReferences(ExternalReferenceRegistry* registry) {

0 commit comments

Comments
 (0)