Skip to content

Commit 344d33e

Browse files
committed
src: fix v8 compiler warnings in src
This commit changes the code to use the maybe version. PR-URL: #24246 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 19e5e78 commit 344d33e

34 files changed

+414
-213
lines changed

src/cares_wrap.cc

+30-19
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
18511851
continue;
18521852

18531853
Local<String> s = OneByteString(env->isolate(), ip);
1854-
results->Set(n, s);
1854+
results->Set(env->context(), n, s).FromJust();
18551855
n++;
18561856
}
18571857
};
@@ -2053,10 +2053,12 @@ void GetServers(const FunctionCallbackInfo<Value>& args) {
20532053
CHECK_EQ(err, 0);
20542054

20552055
Local<Array> ret = Array::New(env->isolate(), 2);
2056-
ret->Set(0, OneByteString(env->isolate(), ip));
2057-
ret->Set(1, Integer::New(env->isolate(), cur->udp_port));
2056+
ret->Set(env->context(), 0, OneByteString(env->isolate(), ip)).FromJust();
2057+
ret->Set(env->context(),
2058+
1,
2059+
Integer::New(env->isolate(), cur->udp_port)).FromJust();
20582060

2059-
server_array->Set(i, ret);
2061+
server_array->Set(env->context(), i, ret).FromJust();
20602062
}
20612063

20622064
ares_free_data(servers);
@@ -2179,40 +2181,49 @@ void Initialize(Local<Object> target,
21792181

21802182
env->SetMethod(target, "strerror", StrError);
21812183

2182-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"),
2183-
Integer::New(env->isolate(), AF_INET));
2184-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET6"),
2185-
Integer::New(env->isolate(), AF_INET6));
2186-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_UNSPEC"),
2187-
Integer::New(env->isolate(), AF_UNSPEC));
2188-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AI_ADDRCONFIG"),
2189-
Integer::New(env->isolate(), AI_ADDRCONFIG));
2190-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AI_V4MAPPED"),
2191-
Integer::New(env->isolate(), AI_V4MAPPED));
2184+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"),
2185+
Integer::New(env->isolate(), AF_INET)).FromJust();
2186+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET6"),
2187+
Integer::New(env->isolate(), AF_INET6)).FromJust();
2188+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
2189+
"AF_UNSPEC"),
2190+
Integer::New(env->isolate(), AF_UNSPEC)).FromJust();
2191+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
2192+
"AI_ADDRCONFIG"),
2193+
Integer::New(env->isolate(), AI_ADDRCONFIG)).FromJust();
2194+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
2195+
"AI_V4MAPPED"),
2196+
Integer::New(env->isolate(), AI_V4MAPPED)).FromJust();
21922197

21932198
Local<FunctionTemplate> aiw =
21942199
BaseObject::MakeLazilyInitializedJSTemplate(env);
21952200
aiw->Inherit(AsyncWrap::GetConstructorTemplate(env));
21962201
Local<String> addrInfoWrapString =
21972202
FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap");
21982203
aiw->SetClassName(addrInfoWrapString);
2199-
target->Set(addrInfoWrapString, aiw->GetFunction(context).ToLocalChecked());
2204+
target->Set(env->context(),
2205+
addrInfoWrapString,
2206+
aiw->GetFunction(context).ToLocalChecked()).FromJust();
22002207

22012208
Local<FunctionTemplate> niw =
22022209
BaseObject::MakeLazilyInitializedJSTemplate(env);
22032210
niw->Inherit(AsyncWrap::GetConstructorTemplate(env));
22042211
Local<String> nameInfoWrapString =
22052212
FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap");
22062213
niw->SetClassName(nameInfoWrapString);
2207-
target->Set(nameInfoWrapString, niw->GetFunction(context).ToLocalChecked());
2214+
target->Set(env->context(),
2215+
nameInfoWrapString,
2216+
niw->GetFunction(context).ToLocalChecked()).FromJust();
22082217

22092218
Local<FunctionTemplate> qrw =
22102219
BaseObject::MakeLazilyInitializedJSTemplate(env);
22112220
qrw->Inherit(AsyncWrap::GetConstructorTemplate(env));
22122221
Local<String> queryWrapString =
22132222
FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap");
22142223
qrw->SetClassName(queryWrapString);
2215-
target->Set(queryWrapString, qrw->GetFunction(context).ToLocalChecked());
2224+
target->Set(env->context(),
2225+
queryWrapString,
2226+
qrw->GetFunction(context).ToLocalChecked()).FromJust();
22162227

22172228
Local<FunctionTemplate> channel_wrap =
22182229
env->NewFunctionTemplate(ChannelWrap::New);
@@ -2239,8 +2250,8 @@ void Initialize(Local<Object> target,
22392250
Local<String> channelWrapString =
22402251
FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap");
22412252
channel_wrap->SetClassName(channelWrapString);
2242-
target->Set(channelWrapString,
2243-
channel_wrap->GetFunction(context).ToLocalChecked());
2253+
target->Set(env->context(), channelWrapString,
2254+
channel_wrap->GetFunction(context).ToLocalChecked()).FromJust();
22442255
}
22452256

22462257
} // anonymous namespace

src/env.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,9 @@ void CollectExceptionInfo(Environment* env,
755755
const char* message,
756756
const char* path,
757757
const char* dest) {
758-
obj->Set(env->errno_string(), v8::Integer::New(env->isolate(), errorno));
758+
obj->Set(env->context(),
759+
env->errno_string(),
760+
v8::Integer::New(env->isolate(), errorno)).FromJust();
759761

760762
obj->Set(env->context(), env->code_string(),
761763
OneByteString(env->isolate(), err_string)).FromJust();

src/exceptions.cc

+15-9
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,19 @@ Local<Value> ErrnoException(Isolate* isolate,
5151
e = Exception::Error(cons);
5252

5353
Local<Object> obj = e.As<Object>();
54-
obj->Set(env->errno_string(), Integer::New(isolate, errorno));
55-
obj->Set(env->code_string(), estring);
54+
obj->Set(env->context(),
55+
env->errno_string(),
56+
Integer::New(isolate, errorno)).FromJust();
57+
obj->Set(env->context(), env->code_string(), estring).FromJust();
5658

5759
if (path_string.IsEmpty() == false) {
58-
obj->Set(env->path_string(), path_string);
60+
obj->Set(env->context(), env->path_string(), path_string).FromJust();
5961
}
6062

6163
if (syscall != nullptr) {
62-
obj->Set(env->syscall_string(), OneByteString(isolate, syscall));
64+
obj->Set(env->context(),
65+
env->syscall_string(),
66+
OneByteString(isolate, syscall)).FromJust();
6367
}
6468

6569
return e;
@@ -132,13 +136,15 @@ Local<Value> UVException(Isolate* isolate,
132136
Exception::Error(js_msg)->ToObject(isolate->GetCurrentContext())
133137
.ToLocalChecked();
134138

135-
e->Set(env->errno_string(), Integer::New(isolate, errorno));
136-
e->Set(env->code_string(), js_code);
137-
e->Set(env->syscall_string(), js_syscall);
139+
e->Set(env->context(),
140+
env->errno_string(),
141+
Integer::New(isolate, errorno)).FromJust();
142+
e->Set(env->context(), env->code_string(), js_code).FromJust();
143+
e->Set(env->context(), env->syscall_string(), js_syscall).FromJust();
138144
if (!js_path.IsEmpty())
139-
e->Set(env->path_string(), js_path);
145+
e->Set(env->context(), env->path_string(), js_path).FromJust();
140146
if (!js_dest.IsEmpty())
141-
e->Set(env->dest_string(), js_dest);
147+
e->Set(env->context(), env->dest_string(), js_dest).FromJust();
142148

143149
return e;
144150
}

src/fs_event_wrap.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ void FSEventWrap::Initialize(Local<Object> target,
119119
Local<FunctionTemplate>(),
120120
static_cast<PropertyAttribute>(ReadOnly | DontDelete | v8::DontEnum));
121121

122-
target->Set(fsevent_string, t->GetFunction(context).ToLocalChecked());
122+
target->Set(env->context(),
123+
fsevent_string,
124+
t->GetFunction(context).ToLocalChecked()).FromJust();
123125
}
124126

125127

src/js_stream.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int JSStream::DoWrite(WriteWrap* w,
118118
Local<Object> buf;
119119
for (size_t i = 0; i < count; i++) {
120120
buf = Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocalChecked();
121-
bufs_arr->Set(i, buf);
121+
bufs_arr->Set(env()->context(), i, buf).FromJust();
122122
}
123123

124124
Local<Value> argv[] = {
@@ -210,7 +210,9 @@ void JSStream::Initialize(Local<Object> target,
210210
env->SetProtoMethod(t, "emitEOF", EmitEOF);
211211

212212
StreamBase::AddMethods<JSStream>(env, t);
213-
target->Set(jsStreamString, t->GetFunction(context).ToLocalChecked());
213+
target->Set(env->context(),
214+
jsStreamString,
215+
t->GetFunction(context).ToLocalChecked()).FromJust();
214216
}
215217

216218
} // namespace node

src/module_wrap.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,8 @@ void ModuleWrap::Initialize(Local<Object> target,
837837
env->SetProtoMethodNoSideEffect(tpl, "getStaticDependencySpecifiers",
838838
GetStaticDependencySpecifiers);
839839

840-
target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"),
841-
tpl->GetFunction(context).ToLocalChecked());
840+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"),
841+
tpl->GetFunction(context).ToLocalChecked()).FromJust();
842842
env->SetMethod(target, "resolve", Resolve);
843843
env->SetMethod(target,
844844
"setImportModuleDynamicallyCallback",

src/node.cc

+45-20
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,8 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
690690
int argc,
691691
Local<Value> argv[],
692692
async_context asyncContext) {
693-
Local<Value> callback_v = recv->Get(symbol);
693+
Local<Value> callback_v = recv->Get(isolate->GetCurrentContext(),
694+
symbol).ToLocalChecked();
694695
if (callback_v.IsEmpty()) return Local<Value>();
695696
if (!callback_v->IsFunction()) return Local<Value>();
696697
Local<Function> callback = callback_v.As<Function>();
@@ -1264,7 +1265,7 @@ static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
12641265
Local<Object> exports = Object::New(env->isolate());
12651266
Local<String> exports_prop = String::NewFromUtf8(env->isolate(), "exports",
12661267
NewStringType::kNormal).ToLocalChecked();
1267-
module->Set(exports_prop, exports);
1268+
module->Set(env->context(), exports_prop, exports).FromJust();
12681269

12691270
if (mod->nm_context_register_func != nullptr) {
12701271
mod->nm_context_register_func(exports,
@@ -1277,7 +1278,8 @@ static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
12771278
return env->ThrowError("Linked module has no declared entry point.");
12781279
}
12791280

1280-
auto effective_exports = module->Get(exports_prop);
1281+
auto effective_exports = module->Get(env->context(),
1282+
exports_prop).ToLocalChecked();
12811283

12821284
args.GetReturnValue().Set(effective_exports);
12831285
}
@@ -1292,21 +1294,35 @@ static Local<Object> GetFeatures(Environment* env) {
12921294
Local<Value> debug = False(env->isolate());
12931295
#endif // defined(DEBUG) && DEBUG
12941296

1295-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "debug"), debug);
1296-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "uv"), True(env->isolate()));
1297+
obj->Set(env->context(),
1298+
FIXED_ONE_BYTE_STRING(env->isolate(), "debug"),
1299+
debug).FromJust();
1300+
obj->Set(env->context(),
1301+
FIXED_ONE_BYTE_STRING(env->isolate(), "uv"),
1302+
True(env->isolate())).FromJust();
12971303
// TODO(bnoordhuis) ping libuv
1298-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"), True(env->isolate()));
1304+
obj->Set(env->context(),
1305+
FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"),
1306+
True(env->isolate())).FromJust();
12991307

13001308
#ifdef HAVE_OPENSSL
13011309
Local<Boolean> have_openssl = True(env->isolate());
13021310
#else
13031311
Local<Boolean> have_openssl = False(env->isolate());
13041312
#endif
13051313

1306-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"), have_openssl);
1307-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"), have_openssl);
1308-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"), have_openssl);
1309-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls"), have_openssl);
1314+
obj->Set(env->context(),
1315+
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"),
1316+
have_openssl).FromJust();
1317+
obj->Set(env->context(),
1318+
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"),
1319+
have_openssl).FromJust();
1320+
obj->Set(env->context(),
1321+
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"),
1322+
have_openssl).FromJust();
1323+
obj->Set(env->context(),
1324+
FIXED_ONE_BYTE_STRING(env->isolate(), "tls"),
1325+
have_openssl).FromJust();
13101326

13111327
return scope.Escape(obj);
13121328
}
@@ -1468,7 +1484,9 @@ void SetupProcessObject(Environment* env,
14681484
NewStringType::kNormal).ToLocalChecked())
14691485
.FromJust();
14701486
}
1471-
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "argv"), arguments);
1487+
process->Set(env->context(),
1488+
FIXED_ONE_BYTE_STRING(env->isolate(), "argv"),
1489+
arguments).FromJust();
14721490

14731491
// process.execArgv
14741492
Local<Array> exec_arguments = Array::New(env->isolate(), exec_args.size());
@@ -1478,8 +1496,9 @@ void SetupProcessObject(Environment* env,
14781496
NewStringType::kNormal).ToLocalChecked())
14791497
.FromJust();
14801498
}
1481-
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
1482-
exec_arguments);
1499+
process->Set(env->context(),
1500+
FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
1501+
exec_arguments).FromJust();
14831502

14841503
// create process.env
14851504
Local<ObjectTemplate> process_env_template =
@@ -1494,7 +1513,9 @@ void SetupProcessObject(Environment* env,
14941513

14951514
Local<Object> process_env =
14961515
process_env_template->NewInstance(env->context()).ToLocalChecked();
1497-
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), process_env);
1516+
process->Set(env->context(),
1517+
FIXED_ONE_BYTE_STRING(env->isolate(), "env"),
1518+
process_env).FromJust();
14981519

14991520
READONLY_PROPERTY(process, "pid",
15001521
Integer::New(env->isolate(), uv_os_getpid()));
@@ -1539,7 +1560,7 @@ void SetupProcessObject(Environment* env,
15391560
preload_modules[i].c_str(),
15401561
NewStringType::kNormal)
15411562
.ToLocalChecked();
1542-
array->Set(i, module);
1563+
array->Set(env->context(), i, module).FromJust();
15431564
}
15441565
READONLY_PROPERTY(process,
15451566
"_preload_modules",
@@ -1629,8 +1650,9 @@ void SetupProcessObject(Environment* env,
16291650
exec_path_value = String::NewFromUtf8(env->isolate(), args[0].c_str(),
16301651
NewStringType::kInternalized).ToLocalChecked();
16311652
}
1632-
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
1633-
exec_path_value);
1653+
process->Set(env->context(),
1654+
FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
1655+
exec_path_value).FromJust();
16341656
delete[] exec_path;
16351657

16361658
auto debug_port_string = FIXED_ONE_BYTE_STRING(env->isolate(), "debugPort");
@@ -1783,7 +1805,9 @@ void LoadEnvironment(Environment* env) {
17831805

17841806
// Expose the global object as a property on itself
17851807
// (Allows you to set stuff on `global` from anywhere in JavaScript.)
1786-
global->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "global"), global);
1808+
global->Set(env->context(),
1809+
FIXED_ONE_BYTE_STRING(env->isolate(), "global"),
1810+
global).FromJust();
17871811

17881812
// Create binding loaders
17891813
Local<Function> get_binding_fn =
@@ -2344,8 +2368,9 @@ int EmitExit(Environment* env) {
23442368
HandleScope handle_scope(env->isolate());
23452369
Context::Scope context_scope(env->context());
23462370
Local<Object> process_object = env->process_object();
2347-
process_object->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "_exiting"),
2348-
True(env->isolate()));
2371+
process_object->Set(env->context(),
2372+
FIXED_ONE_BYTE_STRING(env->isolate(), "_exiting"),
2373+
True(env->isolate())).FromJust();
23492374

23502375
Local<String> exit_code = env->exit_code_string();
23512376
int code = process_object->Get(env->context(), exit_code).ToLocalChecked()

src/node_constants.cc

+27-9
Original file line numberDiff line numberDiff line change
@@ -1347,15 +1347,33 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
13471347
// Define libuv constants.
13481348
NODE_DEFINE_CONSTANT(os_constants, UV_UDP_REUSEADDR);
13491349

1350-
os_constants->Set(OneByteString(isolate, "dlopen"), dlopen_constants);
1351-
os_constants->Set(OneByteString(isolate, "errno"), err_constants);
1352-
os_constants->Set(OneByteString(isolate, "signals"), sig_constants);
1353-
os_constants->Set(OneByteString(isolate, "priority"), priority_constants);
1354-
target->Set(OneByteString(isolate, "os"), os_constants);
1355-
target->Set(OneByteString(isolate, "fs"), fs_constants);
1356-
target->Set(OneByteString(isolate, "crypto"), crypto_constants);
1357-
target->Set(OneByteString(isolate, "zlib"), zlib_constants);
1358-
target->Set(OneByteString(isolate, "trace"), trace_constants);
1350+
os_constants->Set(env->context(),
1351+
OneByteString(isolate, "dlopen"),
1352+
dlopen_constants).FromJust();
1353+
os_constants->Set(env->context(),
1354+
OneByteString(isolate, "errno"),
1355+
err_constants).FromJust();
1356+
os_constants->Set(env->context(),
1357+
OneByteString(isolate, "signals"),
1358+
sig_constants).FromJust();
1359+
os_constants->Set(env->context(),
1360+
OneByteString(isolate, "priority"),
1361+
priority_constants).FromJust();
1362+
target->Set(env->context(),
1363+
OneByteString(isolate, "os"),
1364+
os_constants).FromJust();
1365+
target->Set(env->context(),
1366+
OneByteString(isolate, "fs"),
1367+
fs_constants).FromJust();
1368+
target->Set(env->context(),
1369+
OneByteString(isolate, "crypto"),
1370+
crypto_constants).FromJust();
1371+
target->Set(env->context(),
1372+
OneByteString(isolate, "zlib"),
1373+
zlib_constants).FromJust();
1374+
target->Set(env->context(),
1375+
OneByteString(isolate, "trace"),
1376+
trace_constants).FromJust();
13591377
}
13601378

13611379
} // namespace node

0 commit comments

Comments
 (0)