Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src, test: fix V8 compiler warnings #24246

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion benchmark/napi/function_args/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ void CallWithArray(const FunctionCallbackInfo<Value>& args) {
uint32_t length = array->Length();
for (uint32_t i = 0; i < length; ++ i) {
Local<Value> v;
v = array->Get(i);
v = array->Get(args.GetIsolate()->GetCurrentContext(),
i).ToLocalChecked();
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions doc/api/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ to invoke such callbacks:

namespace demo {

using v8::Context;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::Isolate;
Expand All @@ -549,13 +550,14 @@ using v8::Value;

void RunCallback(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
Local<Function> cb = Local<Function>::Cast(args[0]);
const unsigned argc = 1;
Local<Value> argv[argc] = {
String::NewFromUtf8(isolate,
"hello world",
NewStringType::kNormal).ToLocalChecked() };
cb->Call(Null(isolate), argc, argv);
cb->Call(context, Null(isolate), argc, argv).ToLocalChecked();
}

void Init(Local<Object> exports, Local<Object> module) {
Expand Down Expand Up @@ -612,10 +614,12 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {
Local<Context> context = isolate->GetCurrentContext();

Local<Object> obj = Object::New(isolate);
obj->Set(String::NewFromUtf8(isolate,
obj->Set(context,
String::NewFromUtf8(isolate,
"msg",
NewStringType::kNormal).ToLocalChecked(),
args[0]->ToString(context).ToLocalChecked());
args[0]->ToString(context).ToLocalChecked())
.FromJust();

args.GetReturnValue().Set(obj);
}
Expand Down Expand Up @@ -803,9 +807,9 @@ void MyObject::Init(Local<Object> exports) {

Local<Context> context = isolate->GetCurrentContext();
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
exports->Set(String::NewFromUtf8(
exports->Set(context, String::NewFromUtf8(
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked(),
tpl->GetFunction(context).ToLocalChecked());
tpl->GetFunction(context).ToLocalChecked()).FromJust();
}

void MyObject::New(const FunctionCallbackInfo<Value>& args) {
Expand Down
49 changes: 30 additions & 19 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,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 @@ -2053,10 +2053,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 @@ -2179,40 +2181,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 @@ -2239,8 +2250,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 @@ -755,7 +755,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
Loading