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: https://github.com/nodejs/node/pull/53444 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
parent
167ef1a621
commit
2cb3504064
@ -77,34 +77,9 @@ static void GetParentProcessId(Local<Name> property,
|
|||||||
info.GetReturnValue().Set(uv_os_getppid());
|
info.GetReturnValue().Set(uv_os_getppid());
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeLocal<Object> CreateProcessObject(Realm* realm) {
|
static void SetVersions(Isolate* isolate, Local<Object> versions) {
|
||||||
Isolate* isolate = realm->isolate();
|
Local<Context> context = isolate->GetCurrentContext();
|
||||||
EscapableHandleScope scope(isolate);
|
|
||||||
Local<Context> context = realm->context();
|
|
||||||
|
|
||||||
Local<FunctionTemplate> process_template = FunctionTemplate::New(isolate);
|
|
||||||
process_template->SetClassName(realm->env()->process_string());
|
|
||||||
Local<Function> process_ctor;
|
|
||||||
Local<Object> process;
|
|
||||||
if (!process_template->GetFunction(context).ToLocal(&process_ctor) ||
|
|
||||||
!process_ctor->NewInstance(context).ToLocal(&process)) {
|
|
||||||
return MaybeLocal<Object>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// process[exit_info_private_symbol]
|
|
||||||
if (process
|
|
||||||
->SetPrivate(context,
|
|
||||||
realm->env()->exit_info_private_symbol(),
|
|
||||||
realm->env()->exit_info().GetJSArray())
|
|
||||||
.IsNothing()) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// process.version
|
|
||||||
READONLY_PROPERTY(
|
|
||||||
process, "version", FIXED_ONE_BYTE_STRING(isolate, NODE_VERSION));
|
|
||||||
|
|
||||||
Local<Object> versions = Object::New(isolate);
|
|
||||||
// Node.js version is always on the top
|
// Node.js version is always on the top
|
||||||
READONLY_STRING_PROPERTY(
|
READONLY_STRING_PROPERTY(
|
||||||
versions, "node", per_process::metadata.versions.node);
|
versions, "node", per_process::metadata.versions.node);
|
||||||
@ -137,8 +112,38 @@ MaybeLocal<Object> CreateProcessObject(Realm* realm) {
|
|||||||
v8::ReadOnly)
|
v8::ReadOnly)
|
||||||
.Check();
|
.Check();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MaybeLocal<Object> CreateProcessObject(Realm* realm) {
|
||||||
|
Isolate* isolate = realm->isolate();
|
||||||
|
EscapableHandleScope scope(isolate);
|
||||||
|
Local<Context> context = realm->context();
|
||||||
|
|
||||||
|
Local<FunctionTemplate> process_template = FunctionTemplate::New(isolate);
|
||||||
|
process_template->SetClassName(realm->env()->process_string());
|
||||||
|
Local<Function> process_ctor;
|
||||||
|
Local<Object> process;
|
||||||
|
if (!process_template->GetFunction(context).ToLocal(&process_ctor) ||
|
||||||
|
!process_ctor->NewInstance(context).ToLocal(&process)) {
|
||||||
|
return MaybeLocal<Object>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// process[exit_info_private_symbol]
|
||||||
|
if (process
|
||||||
|
->SetPrivate(context,
|
||||||
|
realm->env()->exit_info_private_symbol(),
|
||||||
|
realm->env()->exit_info().GetJSArray())
|
||||||
|
.IsNothing()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// process.version
|
||||||
|
READONLY_PROPERTY(
|
||||||
|
process, "version", FIXED_ONE_BYTE_STRING(isolate, NODE_VERSION));
|
||||||
|
|
||||||
// process.versions
|
// process.versions
|
||||||
|
Local<Object> versions = Object::New(isolate);
|
||||||
|
SetVersions(isolate, versions);
|
||||||
READONLY_PROPERTY(process, "versions", versions);
|
READONLY_PROPERTY(process, "versions", versions);
|
||||||
|
|
||||||
// process.arch
|
// process.arch
|
||||||
@ -248,6 +253,11 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
|
|||||||
None,
|
None,
|
||||||
SideEffectType::kHasNoSideEffect)
|
SideEffectType::kHasNoSideEffect)
|
||||||
.FromJust());
|
.FromJust());
|
||||||
|
|
||||||
|
// process.versions
|
||||||
|
Local<Object> versions = Object::New(isolate);
|
||||||
|
SetVersions(isolate, versions);
|
||||||
|
READONLY_PROPERTY(process, "versions", versions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterProcessExternalReferences(ExternalReferenceRegistry* registry) {
|
void RegisterProcessExternalReferences(ExternalReferenceRegistry* registry) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user