@@ -13,6 +13,7 @@ using v8::Context;
13
13
using v8::DEFAULT;
14
14
using v8::EscapableHandleScope;
15
15
using v8::Function;
16
+ using v8::FunctionCallbackInfo;
16
17
using v8::FunctionTemplate;
17
18
using v8::HandleScope;
18
19
using v8::Integer;
@@ -84,20 +85,6 @@ MaybeLocal<Object> CreateProcessObject(
84
85
return MaybeLocal<Object>();
85
86
}
86
87
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
-
101
88
// process.version
102
89
READONLY_PROPERTY (process,
103
90
" version" ,
@@ -140,34 +127,56 @@ MaybeLocal<Object> CreateProcessObject(
140
127
#endif // _WIN32
141
128
#endif // NODE_HAS_RELEASE_URLS
142
129
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
+
143
157
// 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 ();
147
161
148
162
// 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 () )
152
166
.ToLocalChecked ()).FromJust ();
153
167
154
168
READONLY_PROPERTY (process, " pid" ,
155
- Integer::New (env-> isolate () , uv_os_getpid ()));
169
+ Integer::New (isolate, uv_os_getpid ()));
156
170
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" ),
159
173
GetParentProcessId).FromJust ());
160
174
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
-
166
175
// --security-revert flags
167
176
#define V (code, _, __ ) \
168
177
do { \
169
178
if (IsReverted (SECURITY_REVERT_ ## code)) { \
170
- READONLY_PROPERTY (process, " REVERT_" #code, True (env-> isolate ())); \
179
+ READONLY_PROPERTY (process, " REVERT_" #code, True (isolate)); \
171
180
} \
172
181
} while (0 );
173
182
SECURITY_REVERSIONS (V)
@@ -181,7 +190,7 @@ MaybeLocal<Object> CreateProcessObject(
181
190
if (uv_exepath (exec_path_buf, &exec_path_len) == 0 ) {
182
191
exec_path = std::string (exec_path_buf, exec_path_len);
183
192
} else {
184
- exec_path = args [0 ];
193
+ exec_path = env-> argv () [0 ];
185
194
}
186
195
// On OpenBSD process.execPath will be relative unless we
187
196
// get the full path before process.execPath is used.
@@ -196,9 +205,9 @@ MaybeLocal<Object> CreateProcessObject(
196
205
uv_fs_req_cleanup (&req);
197
206
#endif
198
207
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,
202
211
exec_path.c_str (),
203
212
NewStringType::kInternalized ,
204
213
exec_path.size ())
@@ -207,20 +216,13 @@ MaybeLocal<Object> CreateProcessObject(
207
216
}
208
217
209
218
// process.debugPort
210
- auto debug_port_string = FIXED_ONE_BYTE_STRING (env->isolate (), " debugPort" );
211
219
CHECK (process
212
- ->SetAccessor (env-> context () ,
213
- debug_port_string ,
220
+ ->SetAccessor (context,
221
+ FIXED_ONE_BYTE_STRING (isolate, " debugPort " ) ,
214
222
DebugPortGetter,
215
223
env->owns_process_state () ? DebugPortSetter : nullptr ,
216
224
env->as_callback_data ())
217
225
.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);
224
226
}
225
227
226
228
} // namespace node
0 commit comments