@@ -193,27 +193,27 @@ static void ares_sockstate_cb(void* data,
193
193
}
194
194
195
195
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 () );
198
198
Local<Array> addresses = Array::New ();
199
199
200
200
char ip[INET6_ADDRSTRLEN];
201
201
for (uint32_t i = 0 ; host->h_addr_list [i] != NULL ; ++i) {
202
202
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);
204
204
addresses->Set (i, address);
205
205
}
206
206
207
207
return scope.Close (addresses);
208
208
}
209
209
210
210
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 () );
213
213
Local<Array> names = Array::New ();
214
214
215
215
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]);
217
217
names->Set (i, address);
218
218
}
219
219
@@ -377,7 +377,7 @@ class QueryAWrap: public QueryWrap {
377
377
return ;
378
378
}
379
379
380
- Local<Array> addresses = HostentToAddresses (host);
380
+ Local<Array> addresses = HostentToAddresses (env (), host);
381
381
ares_free_hostent (host);
382
382
383
383
this ->CallOnComplete (addresses);
@@ -414,7 +414,7 @@ class QueryAaaaWrap: public QueryWrap {
414
414
return ;
415
415
}
416
416
417
- Local<Array> addresses = HostentToAddresses (host);
417
+ Local<Array> addresses = HostentToAddresses (env (), host);
418
418
ares_free_hostent (host);
419
419
420
420
this ->CallOnComplete (addresses);
@@ -453,7 +453,7 @@ class QueryCnameWrap: public QueryWrap {
453
453
// A cname lookup always returns a single record but we follow the
454
454
// common API here.
455
455
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 ));
457
457
ares_free_hostent (host);
458
458
459
459
this ->CallOnComplete (result);
@@ -490,18 +490,16 @@ class QueryMxWrap: public QueryWrap {
490
490
}
491
491
492
492
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 ();
497
495
498
496
ares_mx_reply* current = mx_start;
499
497
for (uint32_t i = 0 ; current != NULL ; ++i, current = current->next ) {
500
498
Local<Object> mx_record = Object::New ();
501
499
mx_record->Set (exchange_symbol,
502
- OneByteString (node_isolate , current->host ));
500
+ OneByteString (env ()-> isolate () , current->host ));
503
501
mx_record->Set (priority_symbol,
504
- Integer::New (current->priority , node_isolate ));
502
+ Integer::New (current->priority , env ()-> isolate () ));
505
503
mx_records->Set (i, mx_record);
506
504
}
507
505
@@ -540,7 +538,7 @@ class QueryNsWrap: public QueryWrap {
540
538
return ;
541
539
}
542
540
543
- Local<Array> names = HostentToNames (host);
541
+ Local<Array> names = HostentToNames (env (), host);
544
542
ares_free_hostent (host);
545
543
546
544
this ->CallOnComplete (names);
@@ -580,7 +578,7 @@ class QueryTxtWrap: public QueryWrap {
580
578
581
579
ares_txt_reply* current = txt_out;
582
580
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 );
584
582
txt_records->Set (i, txt);
585
583
}
586
584
@@ -620,26 +618,22 @@ class QuerySrvWrap: public QueryWrap {
620
618
}
621
619
622
620
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 ();
631
625
632
626
ares_srv_reply* current = srv_start;
633
627
for (uint32_t i = 0 ; current != NULL ; ++i, current = current->next ) {
634
628
Local<Object> srv_record = Object::New ();
635
629
srv_record->Set (name_symbol,
636
- OneByteString (node_isolate , current->host ));
630
+ OneByteString (env ()-> isolate () , current->host ));
637
631
srv_record->Set (port_symbol,
638
- Integer::New (current->port , node_isolate ));
632
+ Integer::New (current->port , env ()-> isolate () ));
639
633
srv_record->Set (priority_symbol,
640
- Integer::New (current->priority , node_isolate ));
634
+ Integer::New (current->priority , env ()-> isolate () ));
641
635
srv_record->Set (weight_symbol,
642
- Integer::New (current->weight , node_isolate ));
636
+ Integer::New (current->weight , env ()-> isolate () ));
643
637
srv_records->Set (i, srv_record);
644
638
}
645
639
@@ -679,34 +673,28 @@ class QueryNaptrWrap: public QueryWrap {
679
673
}
680
674
681
675
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 ();
694
682
695
683
ares_naptr_reply* current = naptr_start;
696
684
for (uint32_t i = 0 ; current != NULL ; ++i, current = current->next ) {
697
685
Local<Object> naptr_record = Object::New ();
698
686
naptr_record->Set (flags_symbol,
699
- OneByteString (node_isolate , current->flags ));
687
+ OneByteString (env ()-> isolate () , current->flags ));
700
688
naptr_record->Set (service_symbol,
701
- OneByteString (node_isolate , current->service ));
689
+ OneByteString (env ()-> isolate () , current->service ));
702
690
naptr_record->Set (regexp_symbol,
703
- OneByteString (node_isolate , current->regexp ));
691
+ OneByteString (env ()-> isolate () , current->regexp ));
704
692
naptr_record->Set (replacement_symbol,
705
- OneByteString (node_isolate , current->replacement ));
693
+ OneByteString (env ()-> isolate () , current->replacement ));
706
694
naptr_record->Set (order_symbol,
707
- Integer::New (current->order , node_isolate ));
695
+ Integer::New (current->order , env ()-> isolate () ));
708
696
naptr_record->Set (preference_symbol,
709
- Integer::New (current->preference , node_isolate ));
697
+ Integer::New (current->preference , env ()-> isolate () ));
710
698
naptr_records->Set (i, naptr_record);
711
699
}
712
700
@@ -748,20 +736,20 @@ class QuerySoaWrap: public QueryWrap {
748
736
749
737
Local<Object> soa_record = Object::New ();
750
738
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 () ));
765
753
766
754
ares_free_data (soa_out);
767
755
@@ -803,7 +791,7 @@ class GetHostByAddrWrap: public QueryWrap {
803
791
void Parse (struct hostent * host) {
804
792
HandleScope handle_scope (env ()->isolate ());
805
793
Context::Scope context_scope (env ()->context ());
806
- this ->CallOnComplete (HostentToNames (host));
794
+ this ->CallOnComplete (HostentToNames (env (), host));
807
795
}
808
796
};
809
797
@@ -825,10 +813,10 @@ class GetHostByNameWrap: public QueryWrap {
825
813
826
814
protected:
827
815
void Parse (struct hostent * host) {
828
- HandleScope scope (node_isolate );
816
+ HandleScope scope (env ()-> isolate () );
829
817
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 () );
832
820
833
821
this ->CallOnComplete (addresses, family);
834
822
}
@@ -865,8 +853,8 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
865
853
Context::Scope context_scope (env->context ());
866
854
867
855
Local<Value> argv[] = {
868
- Integer::New (status, node_isolate ),
869
- Null (node_isolate )
856
+ Integer::New (status, env-> isolate () ),
857
+ Null (env-> isolate () )
870
858
};
871
859
872
860
if (status == 0 ) {
@@ -906,7 +894,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
906
894
continue ;
907
895
908
896
// Create JavaScript string
909
- Local<String> s = OneByteString (node_isolate , ip);
897
+ Local<String> s = OneByteString (env-> isolate () , ip);
910
898
results->Set (n, s);
911
899
n++;
912
900
}
@@ -933,7 +921,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
933
921
continue ;
934
922
935
923
// Create JavaScript string
936
- Local<String> s = OneByteString (node_isolate , ip);
924
+ Local<String> s = OneByteString (env-> isolate () , ip);
937
925
results->Set (n, s);
938
926
n++;
939
927
}
@@ -956,7 +944,8 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
956
944
957
945
958
946
static void IsIP (const FunctionCallbackInfo<Value>& args) {
959
- HandleScope scope (node_isolate);
947
+ Environment* env = Environment::GetCurrent (args.GetIsolate ());
948
+ HandleScope scope (env->isolate ());
960
949
961
950
String::AsciiValue ip (args[0 ]);
962
951
char address_buffer[sizeof (struct in6_addr )];
@@ -1041,7 +1030,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
1041
1030
int err = uv_inet_ntop (cur->family , caddr, ip, sizeof (ip));
1042
1031
assert (err == 0 );
1043
1032
1044
- Local<String> addr = OneByteString (node_isolate , ip);
1033
+ Local<String> addr = OneByteString (env-> isolate () , ip);
1045
1034
server_array->Set (i, addr);
1046
1035
}
1047
1036
@@ -1121,9 +1110,10 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
1121
1110
1122
1111
1123
1112
static void StrError (const FunctionCallbackInfo<Value>& args) {
1124
- HandleScope scope (node_isolate);
1113
+ Environment* env = Environment::GetCurrent (args.GetIsolate ());
1114
+ HandleScope scope (env->isolate ());
1125
1115
const char * errmsg = ares_strerror (args[0 ]->Int32Value ());
1126
- args.GetReturnValue ().Set (OneByteString (node_isolate , errmsg));
1116
+ args.GetReturnValue ().Set (OneByteString (env-> isolate () , errmsg));
1127
1117
}
1128
1118
1129
1119
@@ -1169,12 +1159,12 @@ static void Initialize(Handle<Object> target,
1169
1159
NODE_SET_METHOD (target, " getServers" , GetServers);
1170
1160
NODE_SET_METHOD (target, " setServers" , SetServers);
1171
1161
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 () ));
1178
1168
}
1179
1169
1180
1170
} // namespace cares_wrap
0 commit comments