From f7a524bf7a9d347af27a8cf3979d113687190848 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 5 Jan 2025 12:58:28 -0800 Subject: [PATCH] src: make some minor ToLocalChecked cleanups --- src/cares_wrap.cc | 48 ++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index a19e8221f34eba..e79f43d1824b60 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -1580,15 +1580,16 @@ void ConvertIpv6StringToBuffer(const FunctionCallbackInfo& args) { if (uv_inet_pton(AF_INET6, *ip, dst) != 0) { isolate->ThrowException(Exception::Error( - String::NewFromUtf8(isolate, "Invalid IPv6 address").ToLocalChecked())); + FIXED_ONE_BYTE_STRING(isolate, "Invalid IPv6 address"))); return; } - Local buffer = - node::Buffer::Copy( + Local buffer; + if (node::Buffer::Copy( isolate, reinterpret_cast(dst), sizeof(dst)) - .ToLocalChecked(); - args.GetReturnValue().Set(buffer); + .ToLocal(&buffer)) { + args.GetReturnValue().Set(buffer); + } } void GetAddrInfo(const FunctionCallbackInfo& args) { @@ -1750,22 +1751,27 @@ void SetServers(const FunctionCallbackInfo& args) { int err; for (uint32_t i = 0; i < len; i++) { - CHECK(arr->Get(env->context(), i).ToLocalChecked()->IsArray()); - - Local elm = arr->Get(env->context(), i).ToLocalChecked().As(); - - 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(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(); + Local val; + if (!arr->Get(env->context(), i).ToLocal(&val)) return; + CHECK(val->IsArray()); + + Local elm = val.As(); + + Local familyValue; + Local ipValue; + Local portValue; + + if (!elm->Get(env->context(), 0).ToLocal(&familyValue)) return; + if (!elm->Get(env->context(), 1).ToLocal(&ipValue)) return; + if (!elm->Get(env->context(), 2).ToLocal(&portValue)) return; + + CHECK(familyValue->Int32Value(env->context()).FromJust()); + CHECK(ipValue->IsString()); + CHECK(portValue->Int32Value(env->context()).FromJust()); + + int fam = familyValue->Int32Value(env->context()).FromJust(); + node::Utf8Value ip(env->isolate(), ipValue); + int port = portValue->Int32Value(env->context()).FromJust(); ares_addr_port_node* cur = &servers[i];