Skip to content

Commit

Permalink
test: fix v8 Set/Get compiler warnings
Browse files Browse the repository at this point in the history
PR-URL: #24246
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
danbev authored and codebytere committed Jan 12, 2019
1 parent 90f3f5e commit 4d1a803
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
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
3 changes: 2 additions & 1 deletion test/addons/async-hello-world/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void AfterAsync(uv_work_t* r) {
// This should be changed to an empty handle.
assert(!ret.IsEmpty());
} else {
callback->Call(global, 2, argv);
callback->Call(isolate->GetCurrentContext(),
global, 2, argv).ToLocalChecked();
}

// cleanup
Expand Down
4 changes: 2 additions & 2 deletions test/addons/heap-profiler/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ inline void Test(const v8::FunctionCallbackInfo<v8::Value>& args) {
inline void Initialize(v8::Local<v8::Object> binding) {
v8::Isolate* const isolate = binding->GetIsolate();
v8::Local<v8::Context> context = isolate->GetCurrentContext();
binding->Set(v8::String::NewFromUtf8(
binding->Set(context, v8::String::NewFromUtf8(
isolate, "test", v8::NewStringType::kNormal).ToLocalChecked(),
v8::FunctionTemplate::New(isolate, Test)
->GetFunction(context)
.ToLocalChecked());
.ToLocalChecked()).FromJust();
}

NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
Expand Down
4 changes: 2 additions & 2 deletions test/addons/new-target/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ inline void NewClass(const v8::FunctionCallbackInfo<v8::Value>& args) {
inline void Initialize(v8::Local<v8::Object> binding) {
auto isolate = binding->GetIsolate();
auto context = isolate->GetCurrentContext();
binding->Set(v8::String::NewFromUtf8(
binding->Set(context, v8::String::NewFromUtf8(
isolate, "Class", v8::NewStringType::kNormal).ToLocalChecked(),
v8::FunctionTemplate::New(isolate, NewClass)
->GetFunction(context)
.ToLocalChecked());
.ToLocalChecked()).FromJust();
}

NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
Expand Down

0 comments on commit 4d1a803

Please sign in to comment.