Skip to content

Commit

Permalink
src: fix v8 compiler warnings in src
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
danbev authored and BridgeAR committed Nov 13, 2018
1 parent 70699ee commit e1c7929
Show file tree
Hide file tree
Showing 34 changed files with 414 additions and 213 deletions.
49 changes: 30 additions & 19 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
continue;

Local<String> s = OneByteString(env->isolate(), ip);
results->Set(n, s);
results->Set(env->context(), n, s).FromJust();
n++;
}
};
Expand Down Expand Up @@ -2049,10 +2049,12 @@ void GetServers(const FunctionCallbackInfo<Value>& args) {
CHECK_EQ(err, 0);

Local<Array> ret = Array::New(env->isolate(), 2);
ret->Set(0, OneByteString(env->isolate(), ip));
ret->Set(1, Integer::New(env->isolate(), cur->udp_port));
ret->Set(env->context(), 0, OneByteString(env->isolate(), ip)).FromJust();
ret->Set(env->context(),
1,
Integer::New(env->isolate(), cur->udp_port)).FromJust();

server_array->Set(i, ret);
server_array->Set(env->context(), i, ret).FromJust();
}

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

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

target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"),
Integer::New(env->isolate(), AF_INET));
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET6"),
Integer::New(env->isolate(), AF_INET6));
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_UNSPEC"),
Integer::New(env->isolate(), AF_UNSPEC));
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AI_ADDRCONFIG"),
Integer::New(env->isolate(), AI_ADDRCONFIG));
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AI_V4MAPPED"),
Integer::New(env->isolate(), AI_V4MAPPED));
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"),
Integer::New(env->isolate(), AF_INET)).FromJust();
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET6"),
Integer::New(env->isolate(), AF_INET6)).FromJust();
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
"AF_UNSPEC"),
Integer::New(env->isolate(), AF_UNSPEC)).FromJust();
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
"AI_ADDRCONFIG"),
Integer::New(env->isolate(), AI_ADDRCONFIG)).FromJust();
target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(),
"AI_V4MAPPED"),
Integer::New(env->isolate(), AI_V4MAPPED)).FromJust();

Local<FunctionTemplate> aiw =
BaseObject::MakeLazilyInitializedJSTemplate(env);
aiw->Inherit(AsyncWrap::GetConstructorTemplate(env));
Local<String> addrInfoWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "GetAddrInfoReqWrap");
aiw->SetClassName(addrInfoWrapString);
target->Set(addrInfoWrapString, aiw->GetFunction(context).ToLocalChecked());
target->Set(env->context(),
addrInfoWrapString,
aiw->GetFunction(context).ToLocalChecked()).FromJust();

Local<FunctionTemplate> niw =
BaseObject::MakeLazilyInitializedJSTemplate(env);
niw->Inherit(AsyncWrap::GetConstructorTemplate(env));
Local<String> nameInfoWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "GetNameInfoReqWrap");
niw->SetClassName(nameInfoWrapString);
target->Set(nameInfoWrapString, niw->GetFunction(context).ToLocalChecked());
target->Set(env->context(),
nameInfoWrapString,
niw->GetFunction(context).ToLocalChecked()).FromJust();

Local<FunctionTemplate> qrw =
BaseObject::MakeLazilyInitializedJSTemplate(env);
qrw->Inherit(AsyncWrap::GetConstructorTemplate(env));
Local<String> queryWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "QueryReqWrap");
qrw->SetClassName(queryWrapString);
target->Set(queryWrapString, qrw->GetFunction(context).ToLocalChecked());
target->Set(env->context(),
queryWrapString,
qrw->GetFunction(context).ToLocalChecked()).FromJust();

Local<FunctionTemplate> channel_wrap =
env->NewFunctionTemplate(ChannelWrap::New);
Expand All @@ -2235,8 +2246,8 @@ void Initialize(Local<Object> target,
Local<String> channelWrapString =
FIXED_ONE_BYTE_STRING(env->isolate(), "ChannelWrap");
channel_wrap->SetClassName(channelWrapString);
target->Set(channelWrapString,
channel_wrap->GetFunction(context).ToLocalChecked());
target->Set(env->context(), channelWrapString,
channel_wrap->GetFunction(context).ToLocalChecked()).FromJust();
}

} // anonymous namespace
Expand Down
4 changes: 3 additions & 1 deletion src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,9 @@ void CollectExceptionInfo(Environment* env,
const char* message,
const char* path,
const char* dest) {
obj->Set(env->errno_string(), v8::Integer::New(env->isolate(), errorno));
obj->Set(env->context(),
env->errno_string(),
v8::Integer::New(env->isolate(), errorno)).FromJust();

obj->Set(env->context(), env->code_string(),
OneByteString(env->isolate(), err_string)).FromJust();
Expand Down
24 changes: 15 additions & 9 deletions src/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,19 @@ Local<Value> ErrnoException(Isolate* isolate,
e = Exception::Error(cons);

Local<Object> obj = e.As<Object>();
obj->Set(env->errno_string(), Integer::New(isolate, errorno));
obj->Set(env->code_string(), estring);
obj->Set(env->context(),
env->errno_string(),
Integer::New(isolate, errorno)).FromJust();
obj->Set(env->context(), env->code_string(), estring).FromJust();

if (path_string.IsEmpty() == false) {
obj->Set(env->path_string(), path_string);
obj->Set(env->context(), env->path_string(), path_string).FromJust();
}

if (syscall != nullptr) {
obj->Set(env->syscall_string(), OneByteString(isolate, syscall));
obj->Set(env->context(),
env->syscall_string(),
OneByteString(isolate, syscall)).FromJust();
}

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

e->Set(env->errno_string(), Integer::New(isolate, errorno));
e->Set(env->code_string(), js_code);
e->Set(env->syscall_string(), js_syscall);
e->Set(env->context(),
env->errno_string(),
Integer::New(isolate, errorno)).FromJust();
e->Set(env->context(), env->code_string(), js_code).FromJust();
e->Set(env->context(), env->syscall_string(), js_syscall).FromJust();
if (!js_path.IsEmpty())
e->Set(env->path_string(), js_path);
e->Set(env->context(), env->path_string(), js_path).FromJust();
if (!js_dest.IsEmpty())
e->Set(env->dest_string(), js_dest);
e->Set(env->context(), env->dest_string(), js_dest).FromJust();

return e;
}
Expand Down
4 changes: 3 additions & 1 deletion src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ void FSEventWrap::Initialize(Local<Object> target,
Local<FunctionTemplate>(),
static_cast<PropertyAttribute>(ReadOnly | DontDelete | v8::DontEnum));

target->Set(fsevent_string, t->GetFunction(context).ToLocalChecked());
target->Set(env->context(),
fsevent_string,
t->GetFunction(context).ToLocalChecked()).FromJust();
}


Expand Down
6 changes: 4 additions & 2 deletions src/js_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int JSStream::DoWrite(WriteWrap* w,
Local<Object> buf;
for (size_t i = 0; i < count; i++) {
buf = Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocalChecked();
bufs_arr->Set(i, buf);
bufs_arr->Set(env()->context(), i, buf).FromJust();
}

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

StreamBase::AddMethods<JSStream>(env, t);
target->Set(jsStreamString, t->GetFunction(context).ToLocalChecked());
target->Set(env->context(),
jsStreamString,
t->GetFunction(context).ToLocalChecked()).FromJust();
}

} // namespace node
Expand Down
4 changes: 2 additions & 2 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,8 @@ void ModuleWrap::Initialize(Local<Object> target,
env->SetProtoMethodNoSideEffect(tpl, "getStaticDependencySpecifiers",
GetStaticDependencySpecifiers);

target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"),
tpl->GetFunction(context).ToLocalChecked());
target->Set(env->context(), FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"),
tpl->GetFunction(context).ToLocalChecked()).FromJust();
env->SetMethod(target, "resolve", Resolve);
env->SetMethod(target,
"setImportModuleDynamicallyCallback",
Expand Down
65 changes: 45 additions & 20 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,8 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
int argc,
Local<Value> argv[],
async_context asyncContext) {
Local<Value> callback_v = recv->Get(symbol);
Local<Value> callback_v = recv->Get(isolate->GetCurrentContext(),
symbol).ToLocalChecked();
if (callback_v.IsEmpty()) return Local<Value>();
if (!callback_v->IsFunction()) return Local<Value>();
Local<Function> callback = callback_v.As<Function>();
Expand Down Expand Up @@ -1260,7 +1261,7 @@ static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
Local<Object> exports = Object::New(env->isolate());
Local<String> exports_prop = String::NewFromUtf8(env->isolate(), "exports",
NewStringType::kNormal).ToLocalChecked();
module->Set(exports_prop, exports);
module->Set(env->context(), exports_prop, exports).FromJust();

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

auto effective_exports = module->Get(exports_prop);
auto effective_exports = module->Get(env->context(),
exports_prop).ToLocalChecked();

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

obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "debug"), debug);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "uv"), True(env->isolate()));
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "debug"),
debug).FromJust();
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "uv"),
True(env->isolate())).FromJust();
// TODO(bnoordhuis) ping libuv
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"), True(env->isolate()));
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "ipv6"),
True(env->isolate())).FromJust();

#ifdef HAVE_OPENSSL
Local<Boolean> have_openssl = True(env->isolate());
#else
Local<Boolean> have_openssl = False(env->isolate());
#endif

obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"), have_openssl);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"), have_openssl);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"), have_openssl);
obj->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "tls"), have_openssl);
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_alpn"),
have_openssl).FromJust();
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_sni"),
have_openssl).FromJust();
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "tls_ocsp"),
have_openssl).FromJust();
obj->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "tls"),
have_openssl).FromJust();

return scope.Escape(obj);
}
Expand Down Expand Up @@ -1464,7 +1480,9 @@ void SetupProcessObject(Environment* env,
NewStringType::kNormal).ToLocalChecked())
.FromJust();
}
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "argv"), arguments);
process->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "argv"),
arguments).FromJust();

// process.execArgv
Local<Array> exec_arguments = Array::New(env->isolate(), exec_args.size());
Expand All @@ -1474,8 +1492,9 @@ void SetupProcessObject(Environment* env,
NewStringType::kNormal).ToLocalChecked())
.FromJust();
}
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
exec_arguments);
process->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
exec_arguments).FromJust();

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

Local<Object> process_env =
process_env_template->NewInstance(env->context()).ToLocalChecked();
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), process_env);
process->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "env"),
process_env).FromJust();

READONLY_PROPERTY(process, "pid",
Integer::New(env->isolate(), uv_os_getpid()));
Expand Down Expand Up @@ -1535,7 +1556,7 @@ void SetupProcessObject(Environment* env,
preload_modules[i].c_str(),
NewStringType::kNormal)
.ToLocalChecked();
array->Set(i, module);
array->Set(env->context(), i, module).FromJust();
}
READONLY_PROPERTY(process,
"_preload_modules",
Expand Down Expand Up @@ -1625,8 +1646,9 @@ void SetupProcessObject(Environment* env,
exec_path_value = String::NewFromUtf8(env->isolate(), args[0].c_str(),
NewStringType::kInternalized).ToLocalChecked();
}
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
exec_path_value);
process->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
exec_path_value).FromJust();
delete[] exec_path;

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

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

// Create binding loaders
Local<Function> get_binding_fn =
Expand Down Expand Up @@ -2340,8 +2364,9 @@ int EmitExit(Environment* env) {
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
Local<Object> process_object = env->process_object();
process_object->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "_exiting"),
True(env->isolate()));
process_object->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "_exiting"),
True(env->isolate())).FromJust();

Local<String> exit_code = env->exit_code_string();
int code = process_object->Get(env->context(), exit_code).ToLocalChecked()
Expand Down
36 changes: 27 additions & 9 deletions src/node_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1347,15 +1347,33 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
// Define libuv constants.
NODE_DEFINE_CONSTANT(os_constants, UV_UDP_REUSEADDR);

os_constants->Set(OneByteString(isolate, "dlopen"), dlopen_constants);
os_constants->Set(OneByteString(isolate, "errno"), err_constants);
os_constants->Set(OneByteString(isolate, "signals"), sig_constants);
os_constants->Set(OneByteString(isolate, "priority"), priority_constants);
target->Set(OneByteString(isolate, "os"), os_constants);
target->Set(OneByteString(isolate, "fs"), fs_constants);
target->Set(OneByteString(isolate, "crypto"), crypto_constants);
target->Set(OneByteString(isolate, "zlib"), zlib_constants);
target->Set(OneByteString(isolate, "trace"), trace_constants);
os_constants->Set(env->context(),
OneByteString(isolate, "dlopen"),
dlopen_constants).FromJust();
os_constants->Set(env->context(),
OneByteString(isolate, "errno"),
err_constants).FromJust();
os_constants->Set(env->context(),
OneByteString(isolate, "signals"),
sig_constants).FromJust();
os_constants->Set(env->context(),
OneByteString(isolate, "priority"),
priority_constants).FromJust();
target->Set(env->context(),
OneByteString(isolate, "os"),
os_constants).FromJust();
target->Set(env->context(),
OneByteString(isolate, "fs"),
fs_constants).FromJust();
target->Set(env->context(),
OneByteString(isolate, "crypto"),
crypto_constants).FromJust();
target->Set(env->context(),
OneByteString(isolate, "zlib"),
zlib_constants).FromJust();
target->Set(env->context(),
OneByteString(isolate, "trace"),
trace_constants).FromJust();
}

} // namespace node
Loading

0 comments on commit e1c7929

Please sign in to comment.