@@ -45,9 +45,9 @@ namespace node {
4545
4646namespace cares_wrap {
4747
48- using v8::Arguments;
4948using v8::Array;
5049using v8::Function;
50+ using v8::FunctionCallbackInfo;
5151using v8::Handle;
5252using v8::HandleScope;
5353using v8::Integer;
@@ -69,7 +69,7 @@ struct ares_task_t {
6969};
7070
7171
72- static Persistent <String> oncomplete_sym;
72+ static Cached <String> oncomplete_sym;
7373static ares_channel ares_channel;
7474static uv_timer_t ares_timer;
7575static RB_HEAD (ares_task_list, ares_task_t ) ares_tasks;
@@ -268,34 +268,27 @@ static void SetAresErrno(int errorno) {
268268 HandleScope scope (node_isolate);
269269 Local<Value> key = String::NewSymbol (" _errno" );
270270 Local<Value> value = String::NewSymbol (AresErrnoString (errorno));
271- node::process->Set (key, value);
271+ Local<Object> process = Local<Object>::New (node_isolate, process_p);
272+ process->Set (key, value);
272273}
273274
274275
275276class QueryWrap {
276277 public:
277278 QueryWrap () {
278279 HandleScope scope (node_isolate);
279-
280- object_ = Persistent<Object>::New (node_isolate, Object::New ());
280+ persistent ().Reset (node_isolate, Object::New ());
281281 }
282282
283283 virtual ~QueryWrap () {
284- assert (!object_.IsEmpty ());
285-
286- object_->Delete (oncomplete_sym);
287-
288- object_.Dispose (node_isolate);
289- object_.Clear ();
290- }
291-
292- Handle<Object> GetObject () {
293- return object_;
284+ assert (!persistent ().IsEmpty ());
285+ object ()->Delete (oncomplete_sym);
286+ persistent ().Dispose ();
294287 }
295288
296289 void SetOnComplete (Handle<Value> oncomplete) {
297290 assert (oncomplete->IsFunction ());
298- object_ ->Set (oncomplete_sym, oncomplete);
291+ object () ->Set (oncomplete_sym, oncomplete);
299292 }
300293
301294 // Subclasses should implement the appropriate Send method.
@@ -309,6 +302,14 @@ class QueryWrap {
309302 return 0 ;
310303 }
311304
305+ inline Persistent<Object>& persistent () {
306+ return object_;
307+ }
308+
309+ inline Local<Object> object () {
310+ return Local<Object>::New (node_isolate, persistent ());
311+ }
312+
312313 protected:
313314 void * GetQueryArg () {
314315 return static_cast <void *>(this );
@@ -343,13 +344,13 @@ class QueryWrap {
343344 void CallOnComplete (Local<Value> answer) {
344345 HandleScope scope (node_isolate);
345346 Local<Value> argv[2 ] = { Integer::New (0 , node_isolate), answer };
346- MakeCallback (object_ , oncomplete_sym, ARRAY_SIZE (argv), argv);
347+ MakeCallback (object () , oncomplete_sym, ARRAY_SIZE (argv), argv);
347348 }
348349
349350 void CallOnComplete (Local<Value> answer, Local<Value> family) {
350351 HandleScope scope (node_isolate);
351352 Local<Value> argv[3 ] = { Integer::New (0 , node_isolate), answer, family };
352- MakeCallback (object_ , oncomplete_sym, ARRAY_SIZE (argv), argv);
353+ MakeCallback (object () , oncomplete_sym, ARRAY_SIZE (argv), argv);
353354 }
354355
355356 void ParseError (int status) {
@@ -358,7 +359,7 @@ class QueryWrap {
358359
359360 HandleScope scope (node_isolate);
360361 Local<Value> argv[1 ] = { Integer::New (-1 , node_isolate) };
361- MakeCallback (object_ , oncomplete_sym, ARRAY_SIZE (argv), argv);
362+ MakeCallback (object () , oncomplete_sym, ARRAY_SIZE (argv), argv);
362363 }
363364
364365 // Subclasses should implement the appropriate Parse method.
@@ -730,7 +731,7 @@ class GetHostByNameWrap: public QueryWrap {
730731
731732
732733template <class Wrap >
733- static Handle<Value> Query (const Arguments & args) {
734+ static void Query (const FunctionCallbackInfo<Value> & args) {
734735 HandleScope scope (node_isolate);
735736
736737 assert (!args.IsConstructCall ());
@@ -742,24 +743,23 @@ static Handle<Value> Query(const Arguments& args) {
742743
743744 // We must cache the wrap's js object here, because cares might make the
744745 // callback from the wrap->Send stack. This will destroy the wrap's internal
745- // object reference, causing wrap->GetObject () to return undefined .
746- Local<Object> object = Local<Object>:: New (node_isolate, wrap->GetObject () );
746+ // object reference, causing wrap->object () to return an empty handle .
747+ Local<Object> object = wrap->object ( );
747748
748749 String::Utf8Value name (args[0 ]);
749750
750751 int r = wrap->Send (*name);
751752 if (r) {
752753 SetAresErrno (r);
753754 delete wrap;
754- return scope.Close (v8::Null (node_isolate));
755755 } else {
756- return scope. Close (object);
756+ args. GetReturnValue (). Set (object);
757757 }
758758}
759759
760760
761761template <class Wrap >
762- static Handle<Value> QueryWithFamily (const Arguments & args) {
762+ static void QueryWithFamily (const FunctionCallbackInfo<Value> & args) {
763763 HandleScope scope (node_isolate);
764764
765765 assert (!args.IsConstructCall ());
@@ -771,8 +771,8 @@ static Handle<Value> QueryWithFamily(const Arguments& args) {
771771
772772 // We must cache the wrap's js object here, because cares might make the
773773 // callback from the wrap->Send stack. This will destroy the wrap's internal
774- // object reference, causing wrap->GetObject () to return undefined .
775- Local<Object> object = Local<Object>:: New (node_isolate, wrap->GetObject () );
774+ // object reference, causing wrap->object () to return an empty handle .
775+ Local<Object> object = wrap->object ( );
776776
777777 String::Utf8Value name (args[0 ]);
778778 int family = args[1 ]->Int32Value ();
@@ -781,9 +781,8 @@ static Handle<Value> QueryWithFamily(const Arguments& args) {
781781 if (r) {
782782 SetAresErrno (r);
783783 delete wrap;
784- return scope.Close (v8::Null (node_isolate));
785784 } else {
786- return scope. Close (object);
785+ args. GetReturnValue (). Set (object);
787786 }
788787}
789788
@@ -877,31 +876,29 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
877876 uv_freeaddrinfo (res);
878877
879878 // Make the callback into JavaScript
880- MakeCallback (req_wrap->object_ , oncomplete_sym, ARRAY_SIZE (argv), argv);
879+ MakeCallback (req_wrap->object () , oncomplete_sym, ARRAY_SIZE (argv), argv);
881880
882881 delete req_wrap;
883882}
884883
885884
886- static Handle<Value> IsIP (const Arguments & args) {
885+ static void IsIP (const FunctionCallbackInfo<Value> & args) {
887886 HandleScope scope (node_isolate);
888887
889888 String::AsciiValue ip (args[0 ]);
890889 char address_buffer[sizeof (struct in6_addr )];
891890
892- if (uv_inet_pton (AF_INET, *ip, &address_buffer).code == UV_OK) {
893- return scope.Close (v8::Integer::New (4 , node_isolate));
894- }
895-
896- if (uv_inet_pton (AF_INET6, *ip, &address_buffer).code == UV_OK) {
897- return scope.Close (v8::Integer::New (6 , node_isolate));
898- }
891+ int rc = 0 ;
892+ if (uv_inet_pton (AF_INET, *ip, &address_buffer).code == UV_OK)
893+ rc = 4 ;
894+ else if (uv_inet_pton (AF_INET6, *ip, &address_buffer).code == UV_OK)
895+ rc = 6 ;
899896
900- return scope. Close ( v8::Integer::New ( 0 , node_isolate) );
897+ args. GetReturnValue (). Set (rc );
901898}
902899
903900
904- static Handle<Value> GetAddrInfo (const Arguments & args) {
901+ static void GetAddrInfo (const FunctionCallbackInfo<Value> & args) {
905902 HandleScope scope (node_isolate);
906903
907904 String::Utf8Value hostname (args[0 ]);
@@ -937,14 +934,13 @@ static Handle<Value> GetAddrInfo(const Arguments& args) {
937934 if (r) {
938935 SetErrno (uv_last_error (uv_default_loop ()));
939936 delete req_wrap;
940- return scope.Close (v8::Null (node_isolate));
941937 } else {
942- return scope. Close ( req_wrap->object_ );
938+ args. GetReturnValue (). Set ( req_wrap->persistent () );
943939 }
944940}
945941
946942
947- static Handle<Value> GetServers (const Arguments & args) {
943+ static void GetServers (const FunctionCallbackInfo<Value> & args) {
948944 HandleScope scope (node_isolate);
949945
950946 Local<Array> server_array = Array::New ();
@@ -969,11 +965,11 @@ static Handle<Value> GetServers(const Arguments& args) {
969965
970966 ares_free_data (servers);
971967
972- return scope. Close (server_array);
968+ args. GetReturnValue (). Set (server_array);
973969}
974970
975971
976- static Handle<Value> SetServers (const Arguments & args) {
972+ static void SetServers (const FunctionCallbackInfo<Value> & args) {
977973 HandleScope scope (node_isolate);
978974
979975 assert (args[0 ]->IsArray ());
@@ -984,7 +980,7 @@ static Handle<Value> SetServers(const Arguments& args) {
984980
985981 if (len == 0 ) {
986982 int rv = ares_set_servers (ares_channel, NULL );
987- return scope. Close ( Integer::New (rv) );
983+ return args. GetReturnValue (). Set (rv);
988984 }
989985
990986 ares_addr_node* servers = new ares_addr_node[len];
@@ -1039,16 +1035,14 @@ static Handle<Value> SetServers(const Arguments& args) {
10391035
10401036 delete[] servers;
10411037
1042- return scope. Close ( Integer::New (r) );
1038+ args. GetReturnValue (). Set (r );
10431039}
10441040
10451041
1046- static Handle<Value> StrError (const Arguments& args) {
1047- HandleScope scope;
1048-
1049- int r = args[0 ]->Int32Value ();
1050-
1051- return scope.Close (String::New (ares_strerror (r)));
1042+ static void StrError (const FunctionCallbackInfo<Value>& args) {
1043+ HandleScope scope (node_isolate);
1044+ const char * errmsg = ares_strerror (args[0 ]->Int32Value ());
1045+ args.GetReturnValue ().Set (String::New (errmsg));
10521046}
10531047
10541048
@@ -1100,7 +1094,7 @@ static void Initialize(Handle<Object> target) {
11001094 target->Set (String::NewSymbol (" AF_UNSPEC" ),
11011095 Integer::New (AF_UNSPEC, node_isolate));
11021096
1103- oncomplete_sym = NODE_PSYMBOL (" oncomplete" );
1097+ oncomplete_sym = String::New (" oncomplete" );
11041098}
11051099
11061100
0 commit comments