From 12798c620d61a2e67f4cd76b774d4000affa43b0 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 18 Sep 2011 13:20:16 -0700 Subject: [PATCH] dns callbacks should go through MakeCallback --- src/cares_wrap.cc | 50 ++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index ac4f6107de8..01d7662e82c 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -63,7 +63,7 @@ using v8::Persistent; using v8::String; using v8::Value; -static Persistent onanswer_sym; +static Persistent oncomplete_sym; static ares_channel ares_channel; @@ -152,7 +152,7 @@ class QueryWrap { ~QueryWrap() { assert(!object_.IsEmpty()); - object_->DeleteHiddenValue(onanswer_sym); + object_->Delete(oncomplete_sym); object_.Dispose(); object_.Clear(); @@ -162,9 +162,9 @@ class QueryWrap { return object_; } - void SetOnAnswer(Handle onanswer) { - assert(onanswer->IsFunction()); - object_->SetHiddenValue(onanswer_sym, onanswer); + void SetOnComplete(Handle oncomplete) { + assert(oncomplete->IsFunction()); + object_->Set(oncomplete_sym, oncomplete); } // Subclasses should implement the appropriate Send method. @@ -209,24 +209,16 @@ class QueryWrap { delete wrap; } - Handle GetOnAnswer() { - HandleScope scope; - assert(!object_.IsEmpty()); - Handle onanswer = object_->GetHiddenValue(onanswer_sym); - assert(onanswer->IsFunction()); - return scope.Close(Handle::Cast(onanswer)); - } - - void CallOnAnswer(Local answer) { + void CallOnComplete(Local answer) { HandleScope scope; Local argv[2] = { Integer::New(0), answer }; - GetOnAnswer()->Call(this->object_, 2, argv); + MakeCallback(object_, "oncomplete", 2, argv); } - void CallOnAnswer(Local answer, Local family) { + void CallOnComplete(Local answer, Local family) { HandleScope scope; Local argv[3] = { Integer::New(0), answer, family }; - GetOnAnswer()->Call(this->object_, 3, argv); + MakeCallback(object_, "oncomplete", 3, argv); } void ParseError(int status) { @@ -235,7 +227,7 @@ class QueryWrap { HandleScope scope; Local argv[1] = { Integer::New(-1) }; - GetOnAnswer()->Call(this->object_, 1, argv); + MakeCallback(object_, "oncomplete", 1, argv); } // Subclasses should implement the appropriate Parse method. @@ -274,7 +266,7 @@ class QueryAWrap: public QueryWrap { Local addresses = HostentToAddresses(host); ares_free_hostent(host); - this->CallOnAnswer(addresses); + this->CallOnComplete(addresses); } }; @@ -306,7 +298,7 @@ class QueryAaaaWrap: public QueryWrap { Local addresses = HostentToAddresses(host); ares_free_hostent(host); - this->CallOnAnswer(addresses); + this->CallOnComplete(addresses); } }; @@ -341,7 +333,7 @@ class QueryCnameWrap: public QueryWrap { result->Set(0, String::New(host->h_name)); ares_free_hostent(host); - this->CallOnAnswer(result); + this->CallOnComplete(result); } }; @@ -379,7 +371,7 @@ class QueryMxWrap: public QueryWrap { ares_free_data(mx_start); - this->CallOnAnswer(mx_records); + this->CallOnComplete(mx_records); } }; @@ -404,7 +396,7 @@ class QueryNsWrap: public QueryWrap { Local names = HostentToNames(host); ares_free_hostent(host); - this->CallOnAnswer(names); + this->CallOnComplete(names); } }; @@ -451,7 +443,7 @@ class QuerySrvWrap: public QueryWrap { ares_free_data(srv_start); - this->CallOnAnswer(srv_records); + this->CallOnComplete(srv_records); } }; @@ -485,7 +477,7 @@ class GetHostByAddrWrap: public QueryWrap { void Parse(struct hostent* host) { HandleScope scope; - this->CallOnAnswer(HostentToNames(host)); + this->CallOnComplete(HostentToNames(host)); } }; @@ -504,7 +496,7 @@ class GetHostByNameWrap: public QueryWrap { Local addresses = HostentToAddresses(host); Local family = Integer::New(host->h_addrtype); - this->CallOnAnswer(addresses, family); + this->CallOnComplete(addresses, family); } }; @@ -518,7 +510,7 @@ static Handle Query(const Arguments& args) { assert(args[1]->IsFunction()); Wrap* wrap = new Wrap(); - wrap->SetOnAnswer(args[1]); + wrap->SetOnComplete(args[1]); // We must cache the wrap's js object here, because cares might make the // callback from the wrap->Send stack. This will destroy the wrap's internal @@ -547,7 +539,7 @@ static Handle QueryWithFamily(const Arguments& args) { assert(args[2]->IsFunction()); Wrap* wrap = new Wrap(); - wrap->SetOnAnswer(args[2]); + wrap->SetOnComplete(args[2]); // We must cache the wrap's js object here, because cares might make the // callback from the wrap->Send stack. This will destroy the wrap's internal @@ -592,7 +584,7 @@ static void Initialize(Handle target) { target->Set(String::NewSymbol("AF_INET6"), Integer::New(AF_INET6)); target->Set(String::NewSymbol("AF_UNSPEC"), Integer::New(AF_UNSPEC)); - onanswer_sym = Persistent::New(String::NewSymbol("onanswer")); + oncomplete_sym = Persistent::New(String::NewSymbol("oncomplete")); }