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: pass context to Get() operations for cares_wrap #16641

Closed
wants to merge 1 commit into from
Closed
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
55 changes: 38 additions & 17 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,9 @@ class QueryAnyWrap: public QueryWrap {
CHECK_EQ(naddrttls, a_count);
for (int i = 0; i < a_count; i++) {
Local<Object> obj = Object::New(env()->isolate());
obj->Set(context, env()->address_string(), ret->Get(i)).FromJust();
obj->Set(context,
env()->address_string(),
ret->Get(context, i).ToLocalChecked()).FromJust();
obj->Set(context,
env()->ttl_string(),
Integer::New(env()->isolate(), addrttls[i].ttl)).FromJust();
Expand All @@ -1239,7 +1241,9 @@ class QueryAnyWrap: public QueryWrap {
} else {
for (int i = 0; i < a_count; i++) {
Local<Object> obj = Object::New(env()->isolate());
obj->Set(context, env()->value_string(), ret->Get(i)).FromJust();
obj->Set(context,
env()->value_string(),
ret->Get(context, i).ToLocalChecked()).FromJust();
obj->Set(context,
env()->type_string(),
env()->dns_cname_string()).FromJust();
Expand Down Expand Up @@ -1268,7 +1272,9 @@ class QueryAnyWrap: public QueryWrap {
CHECK_EQ(aaaa_count, naddr6ttls);
for (uint32_t i = a_count; i < ret->Length(); i++) {
Local<Object> obj = Object::New(env()->isolate());
obj->Set(context, env()->address_string(), ret->Get(i)).FromJust();
obj->Set(context,
env()->address_string(),
ret->Get(context, i).ToLocalChecked()).FromJust();
obj->Set(context,
env()->ttl_string(),
Integer::New(env()->isolate(), addr6ttls[i].ttl)).FromJust();
Expand All @@ -1295,7 +1301,9 @@ class QueryAnyWrap: public QueryWrap {
}
for (uint32_t i = old_count; i < ret->Length(); i++) {
Local<Object> obj = Object::New(env()->isolate());
obj->Set(context, env()->value_string(), ret->Get(i)).FromJust();
obj->Set(context,
env()->value_string(),
ret->Get(context, i).ToLocalChecked()).FromJust();
obj->Set(context,
env()->type_string(),
env()->dns_ns_string()).FromJust();
Expand All @@ -1321,7 +1329,9 @@ class QueryAnyWrap: public QueryWrap {
status = ParseGeneralReply(env(), buf, len, &type, ret);
for (uint32_t i = old_count; i < ret->Length(); i++) {
Local<Object> obj = Object::New(env()->isolate());
obj->Set(context, env()->value_string(), ret->Get(i)).FromJust();
obj->Set(context,
env()->value_string(),
ret->Get(context, i).ToLocalChecked()).FromJust();
obj->Set(context,
env()->type_string(),
env()->dns_ptr_string()).FromJust();
Expand Down Expand Up @@ -1941,10 +1951,14 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
Local<Object> req_wrap_obj = args[0].As<Object>();
node::Utf8Value hostname(env->isolate(), args[1]);

int32_t flags = (args[3]->IsInt32()) ? args[3]->Int32Value() : 0;
int32_t flags = 0;
if (args[3]->IsInt32()) {
flags = args[3]->Int32Value(env->context()).FromJust();
}

int family;

switch (args[2]->Int32Value()) {
switch (args[2]->Int32Value(env->context()).FromJust()) {
case 0:
family = AF_UNSPEC;
break;
Expand Down Expand Up @@ -1988,7 +2002,7 @@ void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
CHECK(args[2]->IsUint32());
Local<Object> req_wrap_obj = args[0].As<Object>();
node::Utf8Value ip(env->isolate(), args[1]);
const unsigned port = args[2]->Uint32Value();
const unsigned port = args[2]->Uint32Value(env->context()).FromJust();
struct sockaddr_storage addr;

CHECK(uv_ip4_addr(*ip, port, reinterpret_cast<sockaddr_in*>(&addr)) == 0 ||
Expand Down Expand Up @@ -2065,17 +2079,23 @@ void SetServers(const FunctionCallbackInfo<Value>& args) {
int err;

for (uint32_t i = 0; i < len; i++) {
CHECK(arr->Get(i)->IsArray());
CHECK(arr->Get(env->context(), i).ToLocalChecked()->IsArray());

Local<Array> elm = Local<Array>::Cast(arr->Get(i));
Local<Array> elm =
Local<Array>::Cast(arr->Get(env->context(), i).ToLocalChecked());

CHECK(elm->Get(0)->Int32Value());
CHECK(elm->Get(1)->IsString());
CHECK(elm->Get(2)->Int32Value());
CHECK(elm->Get(env->context(),
0).ToLocalChecked()->Int32Value(env->context()).FromJust());
CHECK(elm->Get(env->context(), 1).ToLocalChecked()->IsString());
CHECK(elm->Get(env->context(),
2).ToLocalChecked()->Int32Value(env->context()).FromJust());

int fam = elm->Get(0)->Int32Value();
node::Utf8Value ip(env->isolate(), elm->Get(1));
int port = elm->Get(2)->Int32Value();
int fam = elm->Get(env->context(), 0)
.ToLocalChecked()->Int32Value(env->context()).FromJust();
node::Utf8Value ip(env->isolate(),
elm->Get(env->context(), 1).ToLocalChecked());
int port = elm->Get(env->context(), 2)
.ToLocalChecked()->Int32Value(env->context()).FromJust();

ares_addr_port_node* cur = &servers[i];

Expand Down Expand Up @@ -2125,7 +2145,8 @@ void Cancel(const FunctionCallbackInfo<Value>& args) {

void StrError(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
const char* errmsg = ares_strerror(args[0]->Int32Value());
const char* errmsg = ares_strerror(args[0]->Int32Value(env->context())
.FromJust());
args.GetReturnValue().Set(OneByteString(env->isolate(), errmsg));
}

Expand Down