Skip to content

Commit e1c7929

Browse files
danbevBridgeAR
authored andcommitted
src: fix v8 compiler warnings in src
This commit changes the code to use the maybe version. PR-URL: #24246 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 70699ee commit e1c7929

34 files changed

+414
-213
lines changed

src/cares_wrap.cc

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

18501850
Local<String> s = OneByteString(env->isolate(), ip);
1851-
results->Set(n, s);
1851+
results->Set(env->context(), n, s).FromJust();
18521852
n++;
18531853
}
18541854
};
@@ -2049,10 +2049,12 @@ void GetServers(const FunctionCallbackInfo<Value>& args) {
20492049
CHECK_EQ(err, 0);
20502050

20512051
Local<Array> ret = Array::New(env->isolate(), 2);
2052-
ret->Set(0, OneByteString(env->isolate(), ip));
2053-
ret->Set(1, Integer::New(env->isolate(), cur->udp_port));
2052+
ret->Set(env->context(), 0, OneByteString(env->isolate(), ip)).FromJust();
2053+
ret->Set(env->context(),
2054+
1,
2055+
Integer::New(env->isolate(), cur->udp_port)).FromJust();
20542056

2055-
server_array->Set(i, ret);
2057+
server_array->Set(env->context(), i, ret).FromJust();
20562058
}
20572059

20582060
ares_free_data(servers);
@@ -2175,40 +2177,49 @@ void Initialize(Local<Object> target,
21752177

21762178
env->SetMethod(target, "strerror", StrError);
21772179

2178-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"),
2179-
Integer::New(env->isolate(), AF_INET));
2180-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET6"),
2181-
Integer::New(env->isolate(), AF_INET6));
2182-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_UNSPEC"),
2183-
Integer::New(env->isolate(), AF_UNSPEC));
2184-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AI_ADDRCONFIG"),
2185-
Integer::New(env->isolate(), AI_ADDRCONFIG));
2186-
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AI_V4MAPPED"),
2187-
Integer::New(env->isolate(), AI_V4MAPPED));
2180+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"),
2181+
Integer::New(env->isolate(), AF_INET)).FromJust();
2182+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET6"),
2183+
Integer::New(env->isolate(), AF_INET6)).FromJust();
2184+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
2185+
"AF_UNSPEC"),
2186+
Integer::New(env->isolate(), AF_UNSPEC)).FromJust();
2187+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
2188+
"AI_ADDRCONFIG"),
2189+
Integer::New(env->isolate(), AI_ADDRCONFIG)).FromJust();
2190+
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
2191+
"AI_V4MAPPED"),
2192+
Integer::New(env->isolate(), AI_V4MAPPED)).FromJust();
21882193

21892194
Local<FunctionTemplate> aiw =
21902195
BaseObject::MakeLazilyInitializedJSTemplate(env);
21912196
aiw->Inherit(AsyncWrap::GetConstructorTemplate(env));
21922197
Local<String> addrInfoWrapString =
21932198
FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap");
21942199
aiw->SetClassName(addrInfoWrapString);
2195-
target->Set(addrInfoWrapString, aiw->GetFunction(context).ToLocalChecked());
2200+
target->Set(env->context(),
2201+
addrInfoWrapString,
2202+
aiw->GetFunction(context).ToLocalChecked()).FromJust();
21962203

21972204
Local<FunctionTemplate> niw =
21982205
BaseObject::MakeLazilyInitializedJSTemplate(env);
21992206
niw->Inherit(AsyncWrap::GetConstructorTemplate(env));
22002207
Local<String> nameInfoWrapString =
22012208
FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap");
22022209
niw->SetClassName(nameInfoWrapString);
2203-
target->Set(nameInfoWrapString, niw->GetFunction(context).ToLocalChecked());
2210+
target->Set(env->context(),
2211+
nameInfoWrapString,
2212+
niw->GetFunction(context).ToLocalChecked()).FromJust();
22042213

22052214
Local<FunctionTemplate> qrw =
22062215
BaseObject::MakeLazilyInitializedJSTemplate(env);
22072216
qrw->Inherit(AsyncWrap::GetConstructorTemplate(env));
22082217
Local<String> queryWrapString =
22092218
FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap");
22102219
qrw->SetClassName(queryWrapString);
2211-
target->Set(queryWrapString, qrw->GetFunction(context).ToLocalChecked());
2220+
target->Set(env->context(),
2221+
queryWrapString,
2222+
qrw->GetFunction(context).ToLocalChecked()).FromJust();
22122223

22132224
Local<FunctionTemplate> channel_wrap =
22142225
env->NewFunctionTemplate(ChannelWrap::New);
@@ -2235,8 +2246,8 @@ void Initialize(Local<Object> target,
22352246
Local<String> channelWrapString =
22362247
FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap");
22372248
channel_wrap->SetClassName(channelWrapString);
2238-
target->Set(channelWrapString,
2239-
channel_wrap->GetFunction(context).ToLocalChecked());
2249+
target->Set(env->context(), channelWrapString,
2250+
channel_wrap->GetFunction(context).ToLocalChecked()).FromJust();
22402251
}
22412252

22422253
} // anonymous namespace

src/env.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,9 @@ void CollectExceptionInfo(Environment* env,
746746
const char* message,
747747
const char* path,
748748
const char* dest) {
749-
obj->Set(env->errno_string(), v8::Integer::New(env->isolate(), errorno));
749+
obj->Set(env->context(),
750+
env->errno_string(),
751+
v8::Integer::New(env->isolate(), errorno)).FromJust();
750752

751753
obj->Set(env->context(), env->code_string(),
752754
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
@@ -686,7 +686,8 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
686686
int argc,
687687
Local<Value> argv[],
688688
async_context asyncContext) {
689-
Local<Value> callback_v = recv->Get(symbol);
689+
Local<Value> callback_v = recv->Get(isolate->GetCurrentContext(),
690+
symbol).ToLocalChecked();
690691
if (callback_v.IsEmpty()) return Local<Value>();
691692
if (!callback_v->IsFunction()) return Local<Value>();
692693
Local<Function> callback = callback_v.As<Function>();
@@ -1260,7 +1261,7 @@ static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
12601261
Local<Object> exports = Object::New(env->isolate());
12611262
Local<String> exports_prop = String::NewFromUtf8(env->isolate(), "exports",
12621263
NewStringType::kNormal).ToLocalChecked();
1263-
module->Set(exports_prop, exports);
1264+
module->Set(env->context(), exports_prop, exports).FromJust();
12641265

12651266
if (mod->nm_context_register_func != nullptr) {
12661267
mod->nm_context_register_func(exports,
@@ -1273,7 +1274,8 @@ static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
12731274
return env->ThrowError("Linked module has no declared entry point.");
12741275
}
12751276

1276-
auto effective_exports = module->Get(exports_prop);
1277+
auto effective_exports = module->Get(env->context(),
1278+
exports_prop).ToLocalChecked();
12771279

12781280
args.GetReturnValue().Set(effective_exports);
12791281
}
@@ -1288,21 +1290,35 @@ static Local<Object> GetFeatures(Environment* env) {
12881290
Local<Value> debug = False(env->isolate());
12891291
#endif // defined(DEBUG) && DEBUG
12901292

1291-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "debug"), debug);
1292-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "uv"), True(env->isolate()));
1293+
obj->Set(env->context(),
1294+
FIXED_ONE_BYTE_STRING(env->isolate(), "debug"),
1295+
debug).FromJust();
1296+
obj->Set(env->context(),
1297+
FIXED_ONE_BYTE_STRING(env->isolate(), "uv"),
1298+
True(env->isolate())).FromJust();
12931299
// TODO(bnoordhuis) ping libuv
1294-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"), True(env->isolate()));
1300+
obj->Set(env->context(),
1301+
FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"),
1302+
True(env->isolate())).FromJust();
12951303

12961304
#ifdef HAVE_OPENSSL
12971305
Local<Boolean> have_openssl = True(env->isolate());
12981306
#else
12991307
Local<Boolean> have_openssl = False(env->isolate());
13001308
#endif
13011309

1302-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"), have_openssl);
1303-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"), have_openssl);
1304-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"), have_openssl);
1305-
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls"), have_openssl);
1310+
obj->Set(env->context(),
1311+
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"),
1312+
have_openssl).FromJust();
1313+
obj->Set(env->context(),
1314+
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"),
1315+
have_openssl).FromJust();
1316+
obj->Set(env->context(),
1317+
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"),
1318+
have_openssl).FromJust();
1319+
obj->Set(env->context(),
1320+
FIXED_ONE_BYTE_STRING(env->isolate(), "tls"),
1321+
have_openssl).FromJust();
13061322

13071323
return scope.Escape(obj);
13081324
}
@@ -1464,7 +1480,9 @@ void SetupProcessObject(Environment* env,
14641480
NewStringType::kNormal).ToLocalChecked())
14651481
.FromJust();
14661482
}
1467-
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "argv"), arguments);
1483+
process->Set(env->context(),
1484+
FIXED_ONE_BYTE_STRING(env->isolate(), "argv"),
1485+
arguments).FromJust();
14681486

14691487
// process.execArgv
14701488
Local<Array> exec_arguments = Array::New(env->isolate(), exec_args.size());
@@ -1474,8 +1492,9 @@ void SetupProcessObject(Environment* env,
14741492
NewStringType::kNormal).ToLocalChecked())
14751493
.FromJust();
14761494
}
1477-
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
1478-
exec_arguments);
1495+
process->Set(env->context(),
1496+
FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
1497+
exec_arguments).FromJust();
14791498

14801499
// create process.env
14811500
Local<ObjectTemplate> process_env_template =
@@ -1490,7 +1509,9 @@ void SetupProcessObject(Environment* env,
14901509

14911510
Local<Object> process_env =
14921511
process_env_template->NewInstance(env->context()).ToLocalChecked();
1493-
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), process_env);
1512+
process->Set(env->context(),
1513+
FIXED_ONE_BYTE_STRING(env->isolate(), "env"),
1514+
process_env).FromJust();
14941515

14951516
READONLY_PROPERTY(process, "pid",
14961517
Integer::New(env->isolate(), uv_os_getpid()));
@@ -1535,7 +1556,7 @@ void SetupProcessObject(Environment* env,
15351556
preload_modules[i].c_str(),
15361557
NewStringType::kNormal)
15371558
.ToLocalChecked();
1538-
array->Set(i, module);
1559+
array->Set(env->context(), i, module).FromJust();
15391560
}
15401561
READONLY_PROPERTY(process,
15411562
"_preload_modules",
@@ -1625,8 +1646,9 @@ void SetupProcessObject(Environment* env,
16251646
exec_path_value = String::NewFromUtf8(env->isolate(), args[0].c_str(),
16261647
NewStringType::kInternalized).ToLocalChecked();
16271648
}
1628-
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
1629-
exec_path_value);
1649+
process->Set(env->context(),
1650+
FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
1651+
exec_path_value).FromJust();
16301652
delete[] exec_path;
16311653

16321654
auto debug_port_string = FIXED_ONE_BYTE_STRING(env->isolate(), "debugPort");
@@ -1779,7 +1801,9 @@ void LoadEnvironment(Environment* env) {
17791801

17801802
// Expose the global object as a property on itself
17811803
// (Allows you to set stuff on `global` from anywhere in JavaScript.)
1782-
global->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "global"), global);
1804+
global->Set(env->context(),
1805+
FIXED_ONE_BYTE_STRING(env->isolate(), "global"),
1806+
global).FromJust();
17831807

17841808
// Create binding loaders
17851809
Local<Function> get_binding_fn =
@@ -2340,8 +2364,9 @@ int EmitExit(Environment* env) {
23402364
HandleScope handle_scope(env->isolate());
23412365
Context::Scope context_scope(env->context());
23422366
Local<Object> process_object = env->process_object();
2343-
process_object->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "_exiting"),
2344-
True(env->isolate()));
2367+
process_object->Set(env->context(),
2368+
FIXED_ONE_BYTE_STRING(env->isolate(), "_exiting"),
2369+
True(env->isolate())).FromJust();
23452370

23462371
Local<String> exit_code = env->exit_code_string();
23472372
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)