@@ -22,21 +22,20 @@ using v8::Isolate;
2222using v8::Local;
2323using v8::MaybeLocal;
2424using v8::Name;
25- using v8::NewStringType;
2625using v8::None;
2726using v8::Object;
2827using v8::PropertyCallbackInfo;
2928using v8::SideEffectType;
30- using v8::String;
3129using v8::Value;
3230
3331static void ProcessTitleGetter (Local<Name> property,
3432 const PropertyCallbackInfo<Value>& info) {
3533 std::string title = GetProcessTitle (" node" );
36- info.GetReturnValue ().Set (
37- String::NewFromUtf8 (info.GetIsolate (), title.data (),
38- NewStringType::kNormal , title.size ())
39- .ToLocalChecked ());
34+ Local<Value> ret;
35+ auto isolate = info.GetIsolate ();
36+ if (ToV8Value (isolate->GetCurrentContext (), title, isolate).ToLocal (&ret)) {
37+ info.GetReturnValue ().Set (ret);
38+ }
4039}
4140
4241static void ProcessTitleSetter (Local<Name> property,
@@ -196,28 +195,34 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
196195 .FromJust ());
197196
198197 // process.argv
199- process->Set (context,
200- FIXED_ONE_BYTE_STRING (isolate, " argv" ),
201- ToV8Value (context, env->argv ()).ToLocalChecked ()).Check ();
198+ Local<Value> val;
199+ if (!ToV8Value (context, env->argv ()).ToLocal (&val) ||
200+ !process->Set (context, FIXED_ONE_BYTE_STRING (isolate, " argv" ), val)
201+ .IsJust ()) {
202+ return ;
203+ }
202204
203205 // process.execArgv
204- process->Set (context,
205- FIXED_ONE_BYTE_STRING (isolate, " execArgv" ),
206- ToV8Value (context, env->exec_argv ())
207- .ToLocalChecked ()).Check ();
206+ if (!ToV8Value (context, env->exec_argv ()).ToLocal (&val) ||
207+ !process->Set (context, FIXED_ONE_BYTE_STRING (isolate, " execArgv" ), val)
208+ .IsJust ()) {
209+ return ;
210+ }
208211
209212 READONLY_PROPERTY (process, " pid" ,
210213 Integer::New (isolate, uv_os_getpid ()));
211214
212- CHECK (process
213- ->SetNativeDataProperty (context,
214- FIXED_ONE_BYTE_STRING (isolate, " ppid" ),
215- GetParentProcessId,
216- nullptr ,
217- Local<Value>(),
218- None,
219- SideEffectType::kHasNoSideEffect )
220- .FromJust ());
215+ if (!process
216+ ->SetNativeDataProperty (context,
217+ FIXED_ONE_BYTE_STRING (isolate, " ppid" ),
218+ GetParentProcessId,
219+ nullptr ,
220+ Local<Value>(),
221+ None,
222+ SideEffectType::kHasNoSideEffect )
223+ .IsJust ()) {
224+ return ;
225+ }
221226
222227 // --security-revert flags
223228#define V (code, _, __ ) \
@@ -230,27 +235,25 @@ void PatchProcessObject(const FunctionCallbackInfo<Value>& args) {
230235#undef V
231236
232237 // process.execPath
233- process
234- ->Set (context,
235- FIXED_ONE_BYTE_STRING (isolate, " execPath" ),
236- String::NewFromUtf8 (isolate,
237- env->exec_path ().c_str (),
238- NewStringType::kInternalized ,
239- env->exec_path ().size ())
240- .ToLocalChecked ())
241- .Check ();
238+ if (!ToV8Value (context, env->exec_path (), isolate).ToLocal (&val) ||
239+ !process->Set (context, FIXED_ONE_BYTE_STRING (isolate, " execPath" ), val)
240+ .IsJust ()) {
241+ return ;
242+ }
242243
243244 // process.debugPort
244- CHECK (process
245- ->SetNativeDataProperty (
246- context,
247- FIXED_ONE_BYTE_STRING (isolate, " debugPort" ),
248- DebugPortGetter,
249- env->owns_process_state () ? DebugPortSetter : nullptr ,
250- Local<Value>(),
251- None,
252- SideEffectType::kHasNoSideEffect )
253- .FromJust ());
245+ if (!process
246+ ->SetNativeDataProperty (
247+ context,
248+ FIXED_ONE_BYTE_STRING (isolate, " debugPort" ),
249+ DebugPortGetter,
250+ env->owns_process_state () ? DebugPortSetter : nullptr ,
251+ Local<Value>(),
252+ None,
253+ SideEffectType::kHasNoSideEffect )
254+ .IsJust ()) {
255+ return ;
256+ }
254257
255258 // process.versions
256259 Local<Object> versions = Object::New (isolate);
0 commit comments