test: fix v8 Set/Get compiler warnings
PR-URL: https://github.com/nodejs/node/pull/24246 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
parent
344d33eef1
commit
faa584ab22
@ -33,7 +33,8 @@ void CallWithArray(const FunctionCallbackInfo<Value>& args) {
|
|||||||
uint32_t length = array->Length();
|
uint32_t length = array->Length();
|
||||||
for (uint32_t i = 0; i < length; ++ i) {
|
for (uint32_t i = 0; i < length; ++ i) {
|
||||||
Local<Value> v;
|
Local<Value> v;
|
||||||
v = array->Get(i);
|
v = array->Get(args.GetIsolate()->GetCurrentContext(),
|
||||||
|
i).ToLocalChecked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -537,6 +537,7 @@ to invoke such callbacks:
|
|||||||
|
|
||||||
namespace demo {
|
namespace demo {
|
||||||
|
|
||||||
|
using v8::Context;
|
||||||
using v8::Function;
|
using v8::Function;
|
||||||
using v8::FunctionCallbackInfo;
|
using v8::FunctionCallbackInfo;
|
||||||
using v8::Isolate;
|
using v8::Isolate;
|
||||||
@ -549,13 +550,14 @@ using v8::Value;
|
|||||||
|
|
||||||
void RunCallback(const FunctionCallbackInfo<Value>& args) {
|
void RunCallback(const FunctionCallbackInfo<Value>& args) {
|
||||||
Isolate* isolate = args.GetIsolate();
|
Isolate* isolate = args.GetIsolate();
|
||||||
|
Local<Context> context = isolate->GetCurrentContext();
|
||||||
Local<Function> cb = Local<Function>::Cast(args[0]);
|
Local<Function> cb = Local<Function>::Cast(args[0]);
|
||||||
const unsigned argc = 1;
|
const unsigned argc = 1;
|
||||||
Local<Value> argv[argc] = {
|
Local<Value> argv[argc] = {
|
||||||
String::NewFromUtf8(isolate,
|
String::NewFromUtf8(isolate,
|
||||||
"hello world",
|
"hello world",
|
||||||
NewStringType::kNormal).ToLocalChecked() };
|
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) {
|
void Init(Local<Object> exports, Local<Object> module) {
|
||||||
@ -612,10 +614,12 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {
|
|||||||
Local<Context> context = isolate->GetCurrentContext();
|
Local<Context> context = isolate->GetCurrentContext();
|
||||||
|
|
||||||
Local<Object> obj = Object::New(isolate);
|
Local<Object> obj = Object::New(isolate);
|
||||||
obj->Set(String::NewFromUtf8(isolate,
|
obj->Set(context,
|
||||||
|
String::NewFromUtf8(isolate,
|
||||||
"msg",
|
"msg",
|
||||||
NewStringType::kNormal).ToLocalChecked(),
|
NewStringType::kNormal).ToLocalChecked(),
|
||||||
args[0]->ToString(context).ToLocalChecked());
|
args[0]->ToString(context).ToLocalChecked())
|
||||||
|
.FromJust();
|
||||||
|
|
||||||
args.GetReturnValue().Set(obj);
|
args.GetReturnValue().Set(obj);
|
||||||
}
|
}
|
||||||
@ -803,9 +807,9 @@ void MyObject::Init(Local<Object> exports) {
|
|||||||
|
|
||||||
Local<Context> context = isolate->GetCurrentContext();
|
Local<Context> context = isolate->GetCurrentContext();
|
||||||
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
|
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
|
||||||
exports->Set(String::NewFromUtf8(
|
exports->Set(context, String::NewFromUtf8(
|
||||||
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked(),
|
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked(),
|
||||||
tpl->GetFunction(context).ToLocalChecked());
|
tpl->GetFunction(context).ToLocalChecked()).FromJust();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
|
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
|
||||||
|
@ -53,7 +53,8 @@ void AfterAsync(uv_work_t* r) {
|
|||||||
// This should be changed to an empty handle.
|
// This should be changed to an empty handle.
|
||||||
assert(!ret.IsEmpty());
|
assert(!ret.IsEmpty());
|
||||||
} else {
|
} else {
|
||||||
callback->Call(global, 2, argv);
|
callback->Call(isolate->GetCurrentContext(),
|
||||||
|
global, 2, argv).ToLocalChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
|
@ -19,11 +19,11 @@ inline void Test(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
inline void Initialize(v8::Local<v8::Object> binding) {
|
inline void Initialize(v8::Local<v8::Object> binding) {
|
||||||
v8::Isolate* const isolate = binding->GetIsolate();
|
v8::Isolate* const isolate = binding->GetIsolate();
|
||||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||||
binding->Set(v8::String::NewFromUtf8(
|
binding->Set(context, v8::String::NewFromUtf8(
|
||||||
isolate, "test", v8::NewStringType::kNormal).ToLocalChecked(),
|
isolate, "test", v8::NewStringType::kNormal).ToLocalChecked(),
|
||||||
v8::FunctionTemplate::New(isolate, Test)
|
v8::FunctionTemplate::New(isolate, Test)
|
||||||
->GetFunction(context)
|
->GetFunction(context)
|
||||||
.ToLocalChecked());
|
.ToLocalChecked()).FromJust();
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
|
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
|
||||||
|
@ -12,11 +12,11 @@ inline void NewClass(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
inline void Initialize(v8::Local<v8::Object> binding) {
|
inline void Initialize(v8::Local<v8::Object> binding) {
|
||||||
auto isolate = binding->GetIsolate();
|
auto isolate = binding->GetIsolate();
|
||||||
auto context = isolate->GetCurrentContext();
|
auto context = isolate->GetCurrentContext();
|
||||||
binding->Set(v8::String::NewFromUtf8(
|
binding->Set(context, v8::String::NewFromUtf8(
|
||||||
isolate, "Class", v8::NewStringType::kNormal).ToLocalChecked(),
|
isolate, "Class", v8::NewStringType::kNormal).ToLocalChecked(),
|
||||||
v8::FunctionTemplate::New(isolate, NewClass)
|
v8::FunctionTemplate::New(isolate, NewClass)
|
||||||
->GetFunction(context)
|
->GetFunction(context)
|
||||||
.ToLocalChecked());
|
.ToLocalChecked()).FromJust();
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
|
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user