@@ -13,6 +13,7 @@ using v8::Context;
1313using v8::DEFAULT;
1414using v8::EscapableHandleScope;
1515using v8::Function;
16+ using v8::FunctionCallbackInfo;
1617using v8::FunctionTemplate;
1718using v8::HandleScope;
1819using v8::Integer;
@@ -84,20 +85,6 @@ MaybeLocal<Object> CreateProcessObject(
8485 return MaybeLocal<Object>();
8586 }
8687
87- // process.title
88- auto title_string = FIXED_ONE_BYTE_STRING (env->isolate (), " title" );
89- CHECK (process
90- ->SetAccessor (
91- env->context (),
92- title_string,
93- ProcessTitleGetter,
94- env->owns_process_state () ? ProcessTitleSetter : nullptr ,
95- env->as_callback_data (),
96- DEFAULT,
97- None,
98- SideEffectType::kHasNoSideEffect )
99- .FromJust ());
100-
10188 // process.version
10289 READONLY_PROPERTY (process,
10390 " version" ,
@@ -140,34 +127,56 @@ MaybeLocal<Object> CreateProcessObject(
140127#endif // _WIN32
141128#endif // NODE_HAS_RELEASE_URLS
142129
130+ // process._rawDebug: may be overwritten later in JS land, but should be
131+ // availbale from the begining for debugging purposes
132+ env->SetMethod (process, " _rawDebug" , RawDebug);
133+
134+ return scope.Escape (process);
135+ }
136+
137+ void PatchProcessObject (const FunctionCallbackInfo<Value>& args) {
138+ Isolate* isolate = args.GetIsolate ();
139+ Local<Context> context = isolate->GetCurrentContext ();
140+ Environment* env = Environment::GetCurrent (context);
141+ CHECK (args[0 ]->IsObject ());
142+ Local<Object> process = args[0 ].As <Object>();
143+
144+ // process.title
145+ CHECK (process
146+ ->SetAccessor (
147+ context,
148+ FIXED_ONE_BYTE_STRING (isolate, " title" ),
149+ ProcessTitleGetter,
150+ env->owns_process_state () ? ProcessTitleSetter : nullptr ,
151+ env->as_callback_data (),
152+ DEFAULT,
153+ None,
154+ SideEffectType::kHasNoSideEffect )
155+ .FromJust ());
156+
143157 // process.argv
144- process->Set (env-> context () ,
145- FIXED_ONE_BYTE_STRING (env-> isolate () , " argv" ),
146- ToV8Value (env->context (), args ).ToLocalChecked ()).FromJust ();
158+ process->Set (context,
159+ FIXED_ONE_BYTE_STRING (isolate, " argv" ),
160+ ToV8Value (context, env->argv () ).ToLocalChecked ()).FromJust ();
147161
148162 // process.execArgv
149- process->Set (env-> context () ,
150- FIXED_ONE_BYTE_STRING (env-> isolate () , " execArgv" ),
151- ToV8Value (env->context (), exec_args )
163+ process->Set (context,
164+ FIXED_ONE_BYTE_STRING (isolate, " execArgv" ),
165+ ToV8Value (context, env->exec_argv () )
152166 .ToLocalChecked ()).FromJust ();
153167
154168 READONLY_PROPERTY (process, " pid" ,
155- Integer::New (env-> isolate () , uv_os_getpid ()));
169+ Integer::New (isolate, uv_os_getpid ()));
156170
157- CHECK (process->SetAccessor (env-> context () ,
158- FIXED_ONE_BYTE_STRING (env-> isolate () , " ppid" ),
171+ CHECK (process->SetAccessor (context,
172+ FIXED_ONE_BYTE_STRING (isolate, " ppid" ),
159173 GetParentProcessId).FromJust ());
160174
161- // TODO(joyeecheung): make this available in JS during pre-execution.
162- // Note that to use this in releases the code doing the revert need to be
163- // careful to delay the check until after the bootstrap but that may not
164- // be possible depending on the feature being reverted.
165-
166175 // --security-revert flags
167176#define V (code, _, __ ) \
168177 do { \
169178 if (IsReverted (SECURITY_REVERT_ ## code)) { \
170- READONLY_PROPERTY (process, " REVERT_" #code, True (env-> isolate ())); \
179+ READONLY_PROPERTY (process, " REVERT_" #code, True (isolate)); \
171180 } \
172181 } while (0 );
173182 SECURITY_REVERSIONS (V)
@@ -181,7 +190,7 @@ MaybeLocal<Object> CreateProcessObject(
181190 if (uv_exepath (exec_path_buf, &exec_path_len) == 0 ) {
182191 exec_path = std::string (exec_path_buf, exec_path_len);
183192 } else {
184- exec_path = args [0 ];
193+ exec_path = env-> argv () [0 ];
185194 }
186195 // On OpenBSD process.execPath will be relative unless we
187196 // get the full path before process.execPath is used.
@@ -196,9 +205,9 @@ MaybeLocal<Object> CreateProcessObject(
196205 uv_fs_req_cleanup (&req);
197206#endif
198207 process
199- ->Set (env-> context () ,
200- FIXED_ONE_BYTE_STRING (env-> isolate () , " execPath" ),
201- String::NewFromUtf8 (env-> isolate () ,
208+ ->Set (context,
209+ FIXED_ONE_BYTE_STRING (isolate, " execPath" ),
210+ String::NewFromUtf8 (isolate,
202211 exec_path.c_str (),
203212 NewStringType::kInternalized ,
204213 exec_path.size ())
@@ -207,20 +216,13 @@ MaybeLocal<Object> CreateProcessObject(
207216 }
208217
209218 // process.debugPort
210- auto debug_port_string = FIXED_ONE_BYTE_STRING (env->isolate (), " debugPort" );
211219 CHECK (process
212- ->SetAccessor (env-> context () ,
213- debug_port_string ,
220+ ->SetAccessor (context,
221+ FIXED_ONE_BYTE_STRING (isolate, " debugPort " ) ,
214222 DebugPortGetter,
215223 env->owns_process_state () ? DebugPortSetter : nullptr ,
216224 env->as_callback_data ())
217225 .FromJust ());
218-
219- // process._rawDebug: may be overwritten later in JS land, but should be
220- // availbale from the begining for debugging purposes
221- env->SetMethod (process, " _rawDebug" , RawDebug);
222-
223- return scope.Escape (process);
224226}
225227
226228} // namespace node
0 commit comments