Skip to content

Commit 2cb3504

Browse files
authored
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: nodejs#53444 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent 167ef1a commit 2cb3504

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
@@ -77,34 +77,9 @@ static void GetParentProcessId(Local<Name> property,
7777
info.GetReturnValue().Set(uv_os_getppid());
7878
}
7979

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

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

141144
// process.versions
145+
Local<Object> versions = Object::New(isolate);
146+
SetVersions(isolate, versions);
142147
READONLY_PROPERTY(process, "versions", versions);
143148

144149
// process.arch
@@ -248,6 +253,11 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
248253
None,
249254
SideEffectType::kHasNoSideEffect)
250255
.FromJust());
256+
257+
// process.versions
258+
Local<Object> versions = Object::New(isolate);
259+
SetVersions(isolate, versions);
260+
READONLY_PROPERTY(process, "versions", versions);
251261
}
252262

253263
void RegisterProcessExternalReferences(ExternalReferenceRegistry* registry) {

0 commit comments

Comments
 (0)