@@ -193,27 +193,27 @@ static void ares_sockstate_cb(void* data,
193193}
194194
195195
196- static Local<Array> HostentToAddresses (struct hostent * host) {
197- HandleScope scope (node_isolate );
196+ static Local<Array> HostentToAddresses (Environment* env, struct hostent * host) {
197+ HandleScope scope (env-> isolate () );
198198 Local<Array> addresses = Array::New ();
199199
200200 char ip[INET6_ADDRSTRLEN];
201201 for (uint32_t i = 0 ; host->h_addr_list [i] != NULL ; ++i) {
202202 uv_inet_ntop (host->h_addrtype , host->h_addr_list [i], ip, sizeof (ip));
203- Local<String> address = OneByteString (node_isolate , ip);
203+ Local<String> address = OneByteString (env-> isolate () , ip);
204204 addresses->Set (i, address);
205205 }
206206
207207 return scope.Close (addresses);
208208}
209209
210210
211- static Local<Array> HostentToNames (struct hostent * host) {
212- HandleScope scope (node_isolate );
211+ static Local<Array> HostentToNames (Environment* env, struct hostent * host) {
212+ HandleScope scope (env-> isolate () );
213213 Local<Array> names = Array::New ();
214214
215215 for (uint32_t i = 0 ; host->h_aliases [i] != NULL ; ++i) {
216- Local<String> address = OneByteString (node_isolate , host->h_aliases [i]);
216+ Local<String> address = OneByteString (env-> isolate () , host->h_aliases [i]);
217217 names->Set (i, address);
218218 }
219219
@@ -377,7 +377,7 @@ class QueryAWrap: public QueryWrap {
377377 return ;
378378 }
379379
380- Local<Array> addresses = HostentToAddresses (host);
380+ Local<Array> addresses = HostentToAddresses (env (), host);
381381 ares_free_hostent (host);
382382
383383 this ->CallOnComplete (addresses);
@@ -414,7 +414,7 @@ class QueryAaaaWrap: public QueryWrap {
414414 return ;
415415 }
416416
417- Local<Array> addresses = HostentToAddresses (host);
417+ Local<Array> addresses = HostentToAddresses (env (), host);
418418 ares_free_hostent (host);
419419
420420 this ->CallOnComplete (addresses);
@@ -453,7 +453,7 @@ class QueryCnameWrap: public QueryWrap {
453453 // A cname lookup always returns a single record but we follow the
454454 // common API here.
455455 Local<Array> result = Array::New (1 );
456- result->Set (0 , OneByteString (node_isolate , host->h_name ));
456+ result->Set (0 , OneByteString (env ()-> isolate () , host->h_name ));
457457 ares_free_hostent (host);
458458
459459 this ->CallOnComplete (result);
@@ -490,18 +490,16 @@ class QueryMxWrap: public QueryWrap {
490490 }
491491
492492 Local<Array> mx_records = Array::New ();
493- Local<String> exchange_symbol =
494- FIXED_ONE_BYTE_STRING (node_isolate, " exchange" );
495- Local<String> priority_symbol =
496- FIXED_ONE_BYTE_STRING (node_isolate, " priority" );
493+ Local<String> exchange_symbol = env ()->exchange_string ();
494+ Local<String> priority_symbol = env ()->priority_string ();
497495
498496 ares_mx_reply* current = mx_start;
499497 for (uint32_t i = 0 ; current != NULL ; ++i, current = current->next ) {
500498 Local<Object> mx_record = Object::New ();
501499 mx_record->Set (exchange_symbol,
502- OneByteString (node_isolate , current->host ));
500+ OneByteString (env ()-> isolate () , current->host ));
503501 mx_record->Set (priority_symbol,
504- Integer::New (current->priority , node_isolate ));
502+ Integer::New (current->priority , env ()-> isolate () ));
505503 mx_records->Set (i, mx_record);
506504 }
507505
@@ -540,7 +538,7 @@ class QueryNsWrap: public QueryWrap {
540538 return ;
541539 }
542540
543- Local<Array> names = HostentToNames (host);
541+ Local<Array> names = HostentToNames (env (), host);
544542 ares_free_hostent (host);
545543
546544 this ->CallOnComplete (names);
@@ -580,7 +578,7 @@ class QueryTxtWrap: public QueryWrap {
580578
581579 ares_txt_reply* current = txt_out;
582580 for (uint32_t i = 0 ; current != NULL ; ++i, current = current->next ) {
583- Local<String> txt = OneByteString (node_isolate , current->txt );
581+ Local<String> txt = OneByteString (env ()-> isolate () , current->txt );
584582 txt_records->Set (i, txt);
585583 }
586584
@@ -620,26 +618,22 @@ class QuerySrvWrap: public QueryWrap {
620618 }
621619
622620 Local<Array> srv_records = Array::New ();
623- Local<String> name_symbol =
624- FIXED_ONE_BYTE_STRING (node_isolate, " name" );
625- Local<String> port_symbol =
626- FIXED_ONE_BYTE_STRING (node_isolate, " port" );
627- Local<String> priority_symbol =
628- FIXED_ONE_BYTE_STRING (node_isolate, " priority" );
629- Local<String> weight_symbol =
630- FIXED_ONE_BYTE_STRING (node_isolate, " weight" );
621+ Local<String> name_symbol = env ()->name_string ();
622+ Local<String> port_symbol = env ()->port_string ();
623+ Local<String> priority_symbol = env ()->priority_string ();
624+ Local<String> weight_symbol = env ()->weight_string ();
631625
632626 ares_srv_reply* current = srv_start;
633627 for (uint32_t i = 0 ; current != NULL ; ++i, current = current->next ) {
634628 Local<Object> srv_record = Object::New ();
635629 srv_record->Set (name_symbol,
636- OneByteString (node_isolate , current->host ));
630+ OneByteString (env ()-> isolate () , current->host ));
637631 srv_record->Set (port_symbol,
638- Integer::New (current->port , node_isolate ));
632+ Integer::New (current->port , env ()-> isolate () ));
639633 srv_record->Set (priority_symbol,
640- Integer::New (current->priority , node_isolate ));
634+ Integer::New (current->priority , env ()-> isolate () ));
641635 srv_record->Set (weight_symbol,
642- Integer::New (current->weight , node_isolate ));
636+ Integer::New (current->weight , env ()-> isolate () ));
643637 srv_records->Set (i, srv_record);
644638 }
645639
@@ -679,34 +673,28 @@ class QueryNaptrWrap: public QueryWrap {
679673 }
680674
681675 Local<Array> naptr_records = Array::New ();
682- Local<String> flags_symbol =
683- FIXED_ONE_BYTE_STRING (node_isolate, " flags" );
684- Local<String> service_symbol =
685- FIXED_ONE_BYTE_STRING (node_isolate, " service" );
686- Local<String> regexp_symbol =
687- FIXED_ONE_BYTE_STRING (node_isolate, " regexp" );
688- Local<String> replacement_symbol =
689- FIXED_ONE_BYTE_STRING (node_isolate, " replacement" );
690- Local<String> order_symbol =
691- FIXED_ONE_BYTE_STRING (node_isolate, " order" );
692- Local<String> preference_symbol =
693- FIXED_ONE_BYTE_STRING (node_isolate, " preference" );
676+ Local<String> flags_symbol = env ()->flags_string ();
677+ Local<String> service_symbol = env ()->service_string ();
678+ Local<String> regexp_symbol = env ()->regexp_string ();
679+ Local<String> replacement_symbol = env ()->replacement_string ();
680+ Local<String> order_symbol = env ()->order_string ();
681+ Local<String> preference_symbol = env ()->preference_string ();
694682
695683 ares_naptr_reply* current = naptr_start;
696684 for (uint32_t i = 0 ; current != NULL ; ++i, current = current->next ) {
697685 Local<Object> naptr_record = Object::New ();
698686 naptr_record->Set (flags_symbol,
699- OneByteString (node_isolate , current->flags ));
687+ OneByteString (env ()-> isolate () , current->flags ));
700688 naptr_record->Set (service_symbol,
701- OneByteString (node_isolate , current->service ));
689+ OneByteString (env ()-> isolate () , current->service ));
702690 naptr_record->Set (regexp_symbol,
703- OneByteString (node_isolate , current->regexp ));
691+ OneByteString (env ()-> isolate () , current->regexp ));
704692 naptr_record->Set (replacement_symbol,
705- OneByteString (node_isolate , current->replacement ));
693+ OneByteString (env ()-> isolate () , current->replacement ));
706694 naptr_record->Set (order_symbol,
707- Integer::New (current->order , node_isolate ));
695+ Integer::New (current->order , env ()-> isolate () ));
708696 naptr_record->Set (preference_symbol,
709- Integer::New (current->preference , node_isolate ));
697+ Integer::New (current->preference , env ()-> isolate () ));
710698 naptr_records->Set (i, naptr_record);
711699 }
712700
@@ -748,20 +736,20 @@ class QuerySoaWrap: public QueryWrap {
748736
749737 Local<Object> soa_record = Object::New ();
750738
751- soa_record->Set (FIXED_ONE_BYTE_STRING (node_isolate, " nsname " ),
752- OneByteString (node_isolate , soa_out->nsname ));
753- soa_record->Set (FIXED_ONE_BYTE_STRING (node_isolate, " hostmaster " ),
754- OneByteString (node_isolate , soa_out->hostmaster ));
755- soa_record->Set (FIXED_ONE_BYTE_STRING (node_isolate, " serial " ),
756- Integer::New (soa_out->serial , node_isolate ));
757- soa_record->Set (FIXED_ONE_BYTE_STRING (node_isolate, " refresh " ),
758- Integer::New (soa_out->refresh , node_isolate ));
759- soa_record->Set (FIXED_ONE_BYTE_STRING (node_isolate, " retry " ),
760- Integer::New (soa_out->retry , node_isolate ));
761- soa_record->Set (FIXED_ONE_BYTE_STRING (node_isolate, " expire " ),
762- Integer::New (soa_out->expire , node_isolate ));
763- soa_record->Set (FIXED_ONE_BYTE_STRING (node_isolate, " minttl " ),
764- Integer::New (soa_out->minttl , node_isolate ));
739+ soa_record->Set (env ()-> nsname_string ( ),
740+ OneByteString (env ()-> isolate () , soa_out->nsname ));
741+ soa_record->Set (env ()-> hostmaster_string ( ),
742+ OneByteString (env ()-> isolate () , soa_out->hostmaster ));
743+ soa_record->Set (env ()-> serial_string ( ),
744+ Integer::New (soa_out->serial , env ()-> isolate () ));
745+ soa_record->Set (env ()-> refresh_string ( ),
746+ Integer::New (soa_out->refresh , env ()-> isolate () ));
747+ soa_record->Set (env ()-> retry_string ( ),
748+ Integer::New (soa_out->retry , env ()-> isolate () ));
749+ soa_record->Set (env ()-> expire_string ( ),
750+ Integer::New (soa_out->expire , env ()-> isolate () ));
751+ soa_record->Set (env ()-> minttl_string ( ),
752+ Integer::New (soa_out->minttl , env ()-> isolate () ));
765753
766754 ares_free_data (soa_out);
767755
@@ -803,7 +791,7 @@ class GetHostByAddrWrap: public QueryWrap {
803791 void Parse (struct hostent * host) {
804792 HandleScope handle_scope (env ()->isolate ());
805793 Context::Scope context_scope (env ()->context ());
806- this ->CallOnComplete (HostentToNames (host));
794+ this ->CallOnComplete (HostentToNames (env (), host));
807795 }
808796};
809797
@@ -825,10 +813,10 @@ class GetHostByNameWrap: public QueryWrap {
825813
826814 protected:
827815 void Parse (struct hostent * host) {
828- HandleScope scope (node_isolate );
816+ HandleScope scope (env ()-> isolate () );
829817
830- Local<Array> addresses = HostentToAddresses (host);
831- Local<Integer> family = Integer::New (host->h_addrtype , node_isolate );
818+ Local<Array> addresses = HostentToAddresses (env (), host);
819+ Local<Integer> family = Integer::New (host->h_addrtype , env ()-> isolate () );
832820
833821 this ->CallOnComplete (addresses, family);
834822 }
@@ -865,8 +853,8 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
865853 Context::Scope context_scope (env->context ());
866854
867855 Local<Value> argv[] = {
868- Integer::New (status, node_isolate ),
869- Null (node_isolate )
856+ Integer::New (status, env-> isolate () ),
857+ Null (env-> isolate () )
870858 };
871859
872860 if (status == 0 ) {
@@ -906,7 +894,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
906894 continue ;
907895
908896 // Create JavaScript string
909- Local<String> s = OneByteString (node_isolate , ip);
897+ Local<String> s = OneByteString (env-> isolate () , ip);
910898 results->Set (n, s);
911899 n++;
912900 }
@@ -933,7 +921,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
933921 continue ;
934922
935923 // Create JavaScript string
936- Local<String> s = OneByteString (node_isolate , ip);
924+ Local<String> s = OneByteString (env-> isolate () , ip);
937925 results->Set (n, s);
938926 n++;
939927 }
@@ -956,7 +944,8 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
956944
957945
958946static void IsIP (const FunctionCallbackInfo<Value>& args) {
959- HandleScope scope (node_isolate);
947+ Environment* env = Environment::GetCurrent (args.GetIsolate ());
948+ HandleScope scope (env->isolate ());
960949
961950 String::AsciiValue ip (args[0 ]);
962951 char address_buffer[sizeof (struct in6_addr )];
@@ -1041,7 +1030,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
10411030 int err = uv_inet_ntop (cur->family , caddr, ip, sizeof (ip));
10421031 assert (err == 0 );
10431032
1044- Local<String> addr = OneByteString (node_isolate , ip);
1033+ Local<String> addr = OneByteString (env-> isolate () , ip);
10451034 server_array->Set (i, addr);
10461035 }
10471036
@@ -1121,9 +1110,10 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
11211110
11221111
11231112static void StrError (const FunctionCallbackInfo<Value>& args) {
1124- HandleScope scope (node_isolate);
1113+ Environment* env = Environment::GetCurrent (args.GetIsolate ());
1114+ HandleScope scope (env->isolate ());
11251115 const char * errmsg = ares_strerror (args[0 ]->Int32Value ());
1126- args.GetReturnValue ().Set (OneByteString (node_isolate , errmsg));
1116+ args.GetReturnValue ().Set (OneByteString (env-> isolate () , errmsg));
11271117}
11281118
11291119
@@ -1169,12 +1159,12 @@ static void Initialize(Handle<Object> target,
11691159 NODE_SET_METHOD (target, " getServers" , GetServers);
11701160 NODE_SET_METHOD (target, " setServers" , SetServers);
11711161
1172- target->Set (FIXED_ONE_BYTE_STRING (node_isolate , " AF_INET" ),
1173- Integer::New (AF_INET, node_isolate ));
1174- target->Set (FIXED_ONE_BYTE_STRING (node_isolate , " AF_INET6" ),
1175- Integer::New (AF_INET6, node_isolate ));
1176- target->Set (FIXED_ONE_BYTE_STRING (node_isolate , " AF_UNSPEC" ),
1177- Integer::New (AF_UNSPEC, node_isolate ));
1162+ target->Set (FIXED_ONE_BYTE_STRING (env-> isolate () , " AF_INET" ),
1163+ Integer::New (AF_INET, env-> isolate () ));
1164+ target->Set (FIXED_ONE_BYTE_STRING (env-> isolate () , " AF_INET6" ),
1165+ Integer::New (AF_INET6, env-> isolate () ));
1166+ target->Set (FIXED_ONE_BYTE_STRING (env-> isolate () , " AF_UNSPEC" ),
1167+ Integer::New (AF_UNSPEC, env-> isolate () ));
11781168}
11791169
11801170} // namespace cares_wrap
0 commit comments