@@ -50,6 +50,7 @@ using v8::Isolate;
50
50
using v8::Local;
51
51
using v8::LocalVector;
52
52
using v8::MaybeLocal;
53
+ using v8::Name;
53
54
using v8::NewStringType;
54
55
using v8::Null;
55
56
using v8::Number;
@@ -71,8 +72,10 @@ static void GetHostname(const FunctionCallbackInfo<Value>& args) {
71
72
return args.GetReturnValue ().SetUndefined ();
72
73
}
73
74
74
- args.GetReturnValue ().Set (
75
- String::NewFromUtf8 (env->isolate (), buf).ToLocalChecked ());
75
+ Local<Value> ret;
76
+ if (String::NewFromUtf8 (env->isolate (), buf).ToLocal (&ret)) {
77
+ args.GetReturnValue ().Set (ret);
78
+ }
76
79
}
77
80
78
81
static void GetOSInformation (const FunctionCallbackInfo<Value>& args) {
@@ -87,15 +90,18 @@ static void GetOSInformation(const FunctionCallbackInfo<Value>& args) {
87
90
}
88
91
89
92
// [sysname, version, release, machine]
90
- Local<Value> osInformation[] = {
91
- String::NewFromUtf8 (env->isolate (), info.sysname ).ToLocalChecked (),
92
- String::NewFromUtf8 (env->isolate (), info.version ).ToLocalChecked (),
93
- String::NewFromUtf8 (env->isolate (), info.release ).ToLocalChecked (),
94
- String::NewFromUtf8 (env->isolate (), info.machine ).ToLocalChecked ()};
95
-
96
- args.GetReturnValue ().Set (Array::New (env->isolate (),
97
- osInformation,
98
- arraysize (osInformation)));
93
+ Local<Value> osInformation[4 ];
94
+ if (String::NewFromUtf8 (env->isolate (), info.sysname )
95
+ .ToLocal (&osInformation[0 ]) &&
96
+ String::NewFromUtf8 (env->isolate (), info.version )
97
+ .ToLocal (&osInformation[1 ]) &&
98
+ String::NewFromUtf8 (env->isolate (), info.release )
99
+ .ToLocal (&osInformation[2 ]) &&
100
+ String::NewFromUtf8 (env->isolate (), info.machine )
101
+ .ToLocal (&osInformation[3 ])) {
102
+ args.GetReturnValue ().Set (
103
+ Array::New (env->isolate (), osInformation, arraysize (osInformation)));
104
+ }
99
105
}
100
106
101
107
static void GetCPUInfo (const FunctionCallbackInfo<Value>& args) {
@@ -204,7 +210,10 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
204
210
// to assume UTF8 as the default as well. It’s what people will expect if
205
211
// they name the interface from any input that uses UTF-8, which should be
206
212
// the most frequent case by far these days.)
207
- name = String::NewFromUtf8 (isolate, raw_name).ToLocalChecked ();
213
+ if (!String::NewFromUtf8 (isolate, raw_name).ToLocal (&name)) {
214
+ // Error occurred creating the string.
215
+ return ;
216
+ }
208
217
209
218
snprintf (mac.data (),
210
219
mac.size (),
@@ -262,11 +271,11 @@ static void GetHomeDirectory(const FunctionCallbackInfo<Value>& args) {
262
271
return args.GetReturnValue ().SetUndefined ();
263
272
}
264
273
265
- Local<String> home = String::NewFromUtf8 (env-> isolate (),
266
- buf,
267
- NewStringType:: kNormal ,
268
- len). ToLocalChecked ( );
269
- args. GetReturnValue (). Set (home);
274
+ Local<String> home;
275
+ if ( String::NewFromUtf8 (env-> isolate (), buf, NewStringType:: kNormal , len)
276
+ . ToLocal (&home)) {
277
+ args. GetReturnValue (). Set (home );
278
+ }
270
279
}
271
280
272
281
@@ -311,43 +320,41 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
311
320
Local<Value> gid = Number::New (env->isolate (), pwd.gid );
312
321
#endif
313
322
314
- MaybeLocal<Value> username = StringBytes::Encode (env->isolate (),
315
- pwd.username ,
316
- encoding,
317
- &error);
318
- MaybeLocal<Value> homedir = StringBytes::Encode (env->isolate (),
319
- pwd.homedir ,
320
- encoding,
321
- &error);
322
- MaybeLocal<Value> shell;
323
-
324
- if (pwd.shell == nullptr )
325
- shell = Null (env->isolate ());
326
- else
327
- shell = StringBytes::Encode (env->isolate (), pwd.shell , encoding, &error);
328
-
329
- if (username.IsEmpty () || homedir.IsEmpty () || shell.IsEmpty ()) {
323
+ Local<Value> username;
324
+ if (!StringBytes::Encode (env->isolate (), pwd.username , encoding, &error)
325
+ .ToLocal (&username)) {
326
+ CHECK (!error.IsEmpty ());
327
+ env->isolate ()->ThrowException (error);
328
+ return ;
329
+ }
330
+
331
+ Local<Value> homedir;
332
+ if (!StringBytes::Encode (env->isolate (), pwd.homedir , encoding, &error)
333
+ .ToLocal (&homedir)) {
334
+ CHECK (!error.IsEmpty ());
335
+ env->isolate ()->ThrowException (error);
336
+ return ;
337
+ }
338
+
339
+ Local<Value> shell = Null (env->isolate ());
340
+ if (pwd.shell != nullptr &&
341
+ !StringBytes::Encode (env->isolate (), pwd.shell , encoding, &error)
342
+ .ToLocal (&shell)) {
330
343
CHECK (!error.IsEmpty ());
331
344
env->isolate ()->ThrowException (error);
332
345
return ;
333
346
}
334
347
335
348
constexpr size_t kRetLength = 5 ;
336
- std::array<Local<v8::Name>, kRetLength > names = {env->uid_string (),
337
- env->gid_string (),
338
- env->username_string (),
339
- env->homedir_string (),
340
- env->shell_string ()};
341
- std::array values = {uid,
342
- gid,
343
- username.ToLocalChecked (),
344
- homedir.ToLocalChecked (),
345
- shell.ToLocalChecked ()};
346
- args.GetReturnValue ().Set (Object::New (env->isolate (),
347
- Null (env->isolate ()),
348
- names.data (),
349
- values.data (),
350
- kRetLength ));
349
+ Local<Name> names[kRetLength ] = {env->uid_string (),
350
+ env->gid_string (),
351
+ env->username_string (),
352
+ env->homedir_string (),
353
+ env->shell_string ()};
354
+ Local<Value> values[kRetLength ] = {uid, gid, username, homedir, shell};
355
+
356
+ args.GetReturnValue ().Set (Object::New (
357
+ env->isolate (), Null (env->isolate ()), &names[0 ], &values[0 ], kRetLength ));
351
358
}
352
359
353
360
0 commit comments