@@ -77,34 +77,9 @@ static void GetParentProcessId(Local<Name> property,
77
77
info.GetReturnValue ().Set (uv_os_getppid ());
78
78
}
79
79
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 ();
106
82
107
- Local<Object> versions = Object::New (isolate);
108
83
// Node.js version is always on the top
109
84
READONLY_STRING_PROPERTY (
110
85
versions, " node" , per_process::metadata.versions .node );
@@ -137,8 +112,38 @@ MaybeLocal<Object> CreateProcessObject(Realm* realm) {
137
112
v8::ReadOnly)
138
113
.Check ();
139
114
}
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));
140
143
141
144
// process.versions
145
+ Local<Object> versions = Object::New (isolate);
146
+ SetVersions (isolate, versions);
142
147
READONLY_PROPERTY (process, " versions" , versions);
143
148
144
149
// process.arch
@@ -248,6 +253,11 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
248
253
None,
249
254
SideEffectType::kHasNoSideEffect )
250
255
.FromJust ());
256
+
257
+ // process.versions
258
+ Local<Object> versions = Object::New (isolate);
259
+ SetVersions (isolate, versions);
260
+ READONLY_PROPERTY (process, " versions" , versions);
251
261
}
252
262
253
263
void RegisterProcessExternalReferences (ExternalReferenceRegistry* registry) {
0 commit comments