From f3a65a85d9c92391ec8d1c571bcecdb12a31a1d3 Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Tue, 31 Oct 2017 08:31:50 -0500 Subject: [PATCH] src: pass context to Get() operations for cares_wrap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using Get() without the context argument will soon be deprecated. This also passed context to Int32Value() operations as well. PR-URL: https://github.com/nodejs/node/pull/16641 Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: Anatoli Papirovski Reviewed-By: Tobias Nießen Reviewed-By: James M Snell --- src/cares_wrap.cc | 55 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 77426c4acd4c44..2cd494fca81a13 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -1231,7 +1231,9 @@ class QueryAnyWrap: public QueryWrap { CHECK_EQ(naddrttls, a_count); for (int i = 0; i < a_count; i++) { Local 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(); @@ -1243,7 +1245,9 @@ class QueryAnyWrap: public QueryWrap { } else { for (int i = 0; i < a_count; i++) { Local 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(); @@ -1272,7 +1276,9 @@ class QueryAnyWrap: public QueryWrap { CHECK_EQ(aaaa_count, naddr6ttls); for (uint32_t i = a_count; i < ret->Length(); i++) { Local 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(); @@ -1299,7 +1305,9 @@ class QueryAnyWrap: public QueryWrap { } for (uint32_t i = old_count; i < ret->Length(); i++) { Local 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(); @@ -1325,7 +1333,9 @@ class QueryAnyWrap: public QueryWrap { status = ParseGeneralReply(env(), buf, len, &type, ret); for (uint32_t i = old_count; i < ret->Length(); i++) { Local 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(); @@ -1945,10 +1955,14 @@ void GetAddrInfo(const FunctionCallbackInfo& args) { Local req_wrap_obj = args[0].As(); 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; @@ -1992,7 +2006,7 @@ void GetNameInfo(const FunctionCallbackInfo& args) { CHECK(args[2]->IsUint32()); Local req_wrap_obj = args[0].As(); 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(&addr)) == 0 || @@ -2069,17 +2083,23 @@ void SetServers(const FunctionCallbackInfo& 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 elm = Local::Cast(arr->Get(i)); + Local elm = + Local::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]; @@ -2129,7 +2149,8 @@ void Cancel(const FunctionCallbackInfo& args) { void StrError(const FunctionCallbackInfo& 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)); }