Skip to content

Commit ce04c72

Browse files
committed
src: update to v8 3.24 APIs
1 parent 1c7bf24 commit ce04c72

37 files changed

+438
-374
lines changed

src/cares_wrap.cc

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace cares_wrap {
5050

5151
using v8::Array;
5252
using v8::Context;
53+
using v8::EscapableHandleScope;
5354
using v8::Function;
5455
using v8::FunctionCallbackInfo;
5556
using v8::Handle;
@@ -194,8 +195,8 @@ static void ares_sockstate_cb(void* data,
194195

195196

196197
static Local<Array> HostentToAddresses(Environment* env, struct hostent* host) {
197-
HandleScope scope(env->isolate());
198-
Local<Array> addresses = Array::New();
198+
EscapableHandleScope scope(env->isolate());
199+
Local<Array> addresses = Array::New(env->isolate());
199200

200201
char ip[INET6_ADDRSTRLEN];
201202
for (uint32_t i = 0; host->h_addr_list[i] != NULL; ++i) {
@@ -204,20 +205,20 @@ static Local<Array> HostentToAddresses(Environment* env, struct hostent* host) {
204205
addresses->Set(i, address);
205206
}
206207

207-
return scope.Close(addresses);
208+
return scope.Escape(addresses);
208209
}
209210

210211

211212
static Local<Array> HostentToNames(Environment* env, struct hostent* host) {
212-
HandleScope scope(env->isolate());
213-
Local<Array> names = Array::New();
213+
EscapableHandleScope scope(env->isolate());
214+
Local<Array> names = Array::New(env->isolate());
214215

215216
for (uint32_t i = 0; host->h_aliases[i] != NULL; ++i) {
216217
Local<String> address = OneByteString(env->isolate(), host->h_aliases[i]);
217218
names->Set(i, address);
218219
}
219220

220-
return scope.Close(names);
221+
return scope.Escape(names);
221222
}
222223

223224

@@ -229,7 +230,7 @@ class QueryWrap : public AsyncWrap {
229230

230231
virtual ~QueryWrap() {
231232
assert(!persistent().IsEmpty());
232-
persistent().Dispose();
233+
persistent().Reset();
233234
}
234235

235236
// Subclasses should implement the appropriate Send method.
@@ -278,7 +279,7 @@ class QueryWrap : public AsyncWrap {
278279
HandleScope handle_scope(env()->isolate());
279280
Context::Scope context_scope(env()->context());
280281
Local<Value> argv[] = {
281-
Integer::New(0, env()->isolate()),
282+
Integer::New(env()->isolate(), 0),
282283
answer
283284
};
284285
MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv);
@@ -288,7 +289,7 @@ class QueryWrap : public AsyncWrap {
288289
HandleScope handle_scope(env()->isolate());
289290
Context::Scope context_scope(env()->context());
290291
Local<Value> argv[] = {
291-
Integer::New(0, env()->isolate()),
292+
Integer::New(env()->isolate(), 0),
292293
answer,
293294
family
294295
};
@@ -452,7 +453,7 @@ class QueryCnameWrap: public QueryWrap {
452453

453454
// A cname lookup always returns a single record but we follow the
454455
// common API here.
455-
Local<Array> result = Array::New(1);
456+
Local<Array> result = Array::New(env()->isolate(), 1);
456457
result->Set(0, OneByteString(env()->isolate(), host->h_name));
457458
ares_free_hostent(host);
458459

@@ -489,17 +490,17 @@ class QueryMxWrap: public QueryWrap {
489490
return;
490491
}
491492

492-
Local<Array> mx_records = Array::New();
493+
Local<Array> mx_records = Array::New(env()->isolate());
493494
Local<String> exchange_symbol = env()->exchange_string();
494495
Local<String> priority_symbol = env()->priority_string();
495496

496497
ares_mx_reply* current = mx_start;
497498
for (uint32_t i = 0; current != NULL; ++i, current = current->next) {
498-
Local<Object> mx_record = Object::New();
499+
Local<Object> mx_record = Object::New(env()->isolate());
499500
mx_record->Set(exchange_symbol,
500501
OneByteString(env()->isolate(), current->host));
501502
mx_record->Set(priority_symbol,
502-
Integer::New(current->priority, env()->isolate()));
503+
Integer::New(env()->isolate(), current->priority));
503504
mx_records->Set(i, mx_record);
504505
}
505506

@@ -574,7 +575,7 @@ class QueryTxtWrap: public QueryWrap {
574575
return;
575576
}
576577

577-
Local<Array> txt_records = Array::New();
578+
Local<Array> txt_records = Array::New(env()->isolate());
578579

579580
ares_txt_reply* current = txt_out;
580581
for (uint32_t i = 0; current != NULL; ++i, current = current->next) {
@@ -617,23 +618,23 @@ class QuerySrvWrap: public QueryWrap {
617618
return;
618619
}
619620

620-
Local<Array> srv_records = Array::New();
621+
Local<Array> srv_records = Array::New(env()->isolate());
621622
Local<String> name_symbol = env()->name_string();
622623
Local<String> port_symbol = env()->port_string();
623624
Local<String> priority_symbol = env()->priority_string();
624625
Local<String> weight_symbol = env()->weight_string();
625626

626627
ares_srv_reply* current = srv_start;
627628
for (uint32_t i = 0; current != NULL; ++i, current = current->next) {
628-
Local<Object> srv_record = Object::New();
629+
Local<Object> srv_record = Object::New(env()->isolate());
629630
srv_record->Set(name_symbol,
630631
OneByteString(env()->isolate(), current->host));
631632
srv_record->Set(port_symbol,
632-
Integer::New(current->port, env()->isolate()));
633+
Integer::New(env()->isolate(), current->port));
633634
srv_record->Set(priority_symbol,
634-
Integer::New(current->priority, env()->isolate()));
635+
Integer::New(env()->isolate(), current->priority));
635636
srv_record->Set(weight_symbol,
636-
Integer::New(current->weight, env()->isolate()));
637+
Integer::New(env()->isolate(), current->weight));
637638
srv_records->Set(i, srv_record);
638639
}
639640

@@ -672,7 +673,7 @@ class QueryNaptrWrap: public QueryWrap {
672673
return;
673674
}
674675

675-
Local<Array> naptr_records = Array::New();
676+
Local<Array> naptr_records = Array::New(env()->isolate());
676677
Local<String> flags_symbol = env()->flags_string();
677678
Local<String> service_symbol = env()->service_string();
678679
Local<String> regexp_symbol = env()->regexp_string();
@@ -682,7 +683,7 @@ class QueryNaptrWrap: public QueryWrap {
682683

683684
ares_naptr_reply* current = naptr_start;
684685
for (uint32_t i = 0; current != NULL; ++i, current = current->next) {
685-
Local<Object> naptr_record = Object::New();
686+
Local<Object> naptr_record = Object::New(env()->isolate());
686687
naptr_record->Set(flags_symbol,
687688
OneByteString(env()->isolate(), current->flags));
688689
naptr_record->Set(service_symbol,
@@ -692,9 +693,9 @@ class QueryNaptrWrap: public QueryWrap {
692693
naptr_record->Set(replacement_symbol,
693694
OneByteString(env()->isolate(), current->replacement));
694695
naptr_record->Set(order_symbol,
695-
Integer::New(current->order, env()->isolate()));
696+
Integer::New(env()->isolate(), current->order));
696697
naptr_record->Set(preference_symbol,
697-
Integer::New(current->preference, env()->isolate()));
698+
Integer::New(env()->isolate(), current->preference));
698699
naptr_records->Set(i, naptr_record);
699700
}
700701

@@ -734,22 +735,22 @@ class QuerySoaWrap: public QueryWrap {
734735
return;
735736
}
736737

737-
Local<Object> soa_record = Object::New();
738+
Local<Object> soa_record = Object::New(env()->isolate());
738739

739740
soa_record->Set(env()->nsname_string(),
740741
OneByteString(env()->isolate(), soa_out->nsname));
741742
soa_record->Set(env()->hostmaster_string(),
742743
OneByteString(env()->isolate(), soa_out->hostmaster));
743744
soa_record->Set(env()->serial_string(),
744-
Integer::New(soa_out->serial, env()->isolate()));
745+
Integer::New(env()->isolate(), soa_out->serial));
745746
soa_record->Set(env()->refresh_string(),
746-
Integer::New(soa_out->refresh, env()->isolate()));
747+
Integer::New(env()->isolate(), soa_out->refresh));
747748
soa_record->Set(env()->retry_string(),
748-
Integer::New(soa_out->retry, env()->isolate()));
749+
Integer::New(env()->isolate(), soa_out->retry));
749750
soa_record->Set(env()->expire_string(),
750-
Integer::New(soa_out->expire, env()->isolate()));
751+
Integer::New(env()->isolate(), soa_out->expire));
751752
soa_record->Set(env()->minttl_string(),
752-
Integer::New(soa_out->minttl, env()->isolate()));
753+
Integer::New(env()->isolate(), soa_out->minttl));
753754

754755
ares_free_data(soa_out);
755756

@@ -816,7 +817,7 @@ class GetHostByNameWrap: public QueryWrap {
816817
HandleScope scope(env()->isolate());
817818

818819
Local<Array> addresses = HostentToAddresses(env(), host);
819-
Local<Integer> family = Integer::New(host->h_addrtype, env()->isolate());
820+
Local<Integer> family = Integer::New(env()->isolate(), host->h_addrtype);
820821

821822
this->CallOnComplete(addresses, family);
822823
}
@@ -853,7 +854,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
853854
Context::Scope context_scope(env->context());
854855

855856
Local<Value> argv[] = {
856-
Integer::New(status, env->isolate()),
857+
Integer::New(env->isolate(), status),
857858
Null(env->isolate())
858859
};
859860

@@ -868,7 +869,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
868869
}
869870

870871
// Create the response array.
871-
Local<Array> results = Array::New(n);
872+
Local<Array> results = Array::New(env->isolate(), n);
872873

873874
char ip[INET6_ADDRSTRLEN];
874875
const char *addr;
@@ -947,7 +948,7 @@ static void IsIP(const FunctionCallbackInfo<Value>& args) {
947948
Environment* env = Environment::GetCurrent(args.GetIsolate());
948949
HandleScope scope(env->isolate());
949950

950-
String::AsciiValue ip(args[0]);
951+
String::Utf8Value ip(args[0]);
951952
char address_buffer[sizeof(struct in6_addr)];
952953

953954
int rc = 0;
@@ -1014,7 +1015,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
10141015
HandleScope handle_scope(args.GetIsolate());
10151016
Environment* env = Environment::GetCurrent(args.GetIsolate());
10161017

1017-
Local<Array> server_array = Array::New();
1018+
Local<Array> server_array = Array::New(env->isolate());
10181019

10191020
ares_addr_node* servers;
10201021

@@ -1160,11 +1161,11 @@ static void Initialize(Handle<Object> target,
11601161
NODE_SET_METHOD(target, "setServers", SetServers);
11611162

11621163
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"),
1163-
Integer::New(AF_INET, env->isolate()));
1164+
Integer::New(env->isolate(), AF_INET));
11641165
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET6"),
1165-
Integer::New(AF_INET6, env->isolate()));
1166+
Integer::New(env->isolate(), AF_INET6));
11661167
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_UNSPEC"),
1167-
Integer::New(AF_UNSPEC, env->isolate()));
1168+
Integer::New(env->isolate(), AF_UNSPEC));
11681169
}
11691170

11701171
} // namespace cares_wrap

src/env-inl.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,23 @@ inline uint64_t Environment::GCInfo::timestamp() const {
7070

7171
inline Environment::IsolateData* Environment::IsolateData::Get(
7272
v8::Isolate* isolate) {
73-
return static_cast<IsolateData*>(isolate->GetData());
73+
return static_cast<IsolateData*>(isolate->GetData(kIsolateSlot));
7474
}
7575

7676
inline Environment::IsolateData* Environment::IsolateData::GetOrCreate(
7777
v8::Isolate* isolate) {
7878
IsolateData* isolate_data = Get(isolate);
7979
if (isolate_data == NULL) {
8080
isolate_data = new IsolateData(isolate);
81-
isolate->SetData(isolate_data);
81+
isolate->SetData(kIsolateSlot, isolate_data);
8282
}
8383
isolate_data->ref_count_ += 1;
8484
return isolate_data;
8585
}
8686

8787
inline void Environment::IsolateData::Put() {
8888
if (--ref_count_ == 0) {
89-
isolate()->SetData(NULL);
89+
isolate()->SetData(kIsolateSlot, NULL);
9090
delete this;
9191
}
9292
}
@@ -230,8 +230,8 @@ inline Environment::Environment(v8::Local<v8::Context> context)
230230
// We'll be creating new objects so make sure we've entered the context.
231231
v8::HandleScope handle_scope(isolate());
232232
v8::Context::Scope context_scope(context);
233-
set_binding_cache_object(v8::Object::New());
234-
set_module_load_list_array(v8::Array::New());
233+
set_binding_cache_object(v8::Object::New(isolate()));
234+
set_module_load_list_array(v8::Array::New(isolate()));
235235
RB_INIT(&cares_task_list_);
236236
QUEUE_INIT(&gc_tracker_queue_);
237237
}
@@ -240,7 +240,7 @@ inline Environment::~Environment() {
240240
v8::HandleScope handle_scope(isolate());
241241

242242
context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, NULL);
243-
#define V(PropertyName, TypeName) PropertyName ## _.Dispose();
243+
#define V(PropertyName, TypeName) PropertyName ## _.Reset();
244244
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
245245
#undef V
246246
isolate_data()->Put();
@@ -370,7 +370,7 @@ inline Environment::IsolateData* Environment::isolate_data() const {
370370
#define THROW_ERROR(fun) \
371371
do { \
372372
v8::HandleScope scope(isolate); \
373-
v8::ThrowException(fun(OneByteString(isolate, errmsg))); \
373+
isolate->ThrowException(fun(OneByteString(isolate, errmsg))); \
374374
} \
375375
while (0)
376376

@@ -404,15 +404,15 @@ inline void Environment::ThrowErrnoException(int errorno,
404404
const char* syscall,
405405
const char* message,
406406
const char* path) {
407-
v8::ThrowException(
407+
isolate()->ThrowException(
408408
ErrnoException(isolate(), errorno, syscall, message, path));
409409
}
410410

411411
inline void Environment::ThrowUVException(int errorno,
412412
const char* syscall,
413413
const char* message,
414414
const char* path) {
415-
v8::ThrowException(
415+
isolate()->ThrowException(
416416
UVException(isolate(), errorno, syscall, message, path));
417417
}
418418

src/env.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ class Environment {
422422
#undef V
423423

424424
private:
425+
static const int kIsolateSlot = 0;
426+
425427
class GCInfo;
426428
class IsolateData;
427429
inline explicit Environment(v8::Local<v8::Context> context);

src/fs_event_wrap.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void FSEventWrap::Initialize(Handle<Object> target,
8383
Handle<Context> context) {
8484
Environment* env = Environment::GetCurrent(context);
8585

86-
Local<FunctionTemplate> t = FunctionTemplate::New(New);
86+
Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New);
8787
t->InstanceTemplate()->SetInternalFieldCount(1);
8888
t->SetClassName(env->fsevent_string());
8989

@@ -172,7 +172,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
172172
}
173173

174174
Local<Value> argv[] = {
175-
Integer::New(status, env->isolate()),
175+
Integer::New(env->isolate(), status),
176176
event_string,
177177
Null(env->isolate())
178178
};

src/handle_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
130130
}
131131

132132
object->SetAlignedPointerInInternalField(0, NULL);
133-
wrap->persistent().Dispose();
133+
wrap->persistent().Reset();
134134
delete wrap;
135135
}
136136

0 commit comments

Comments
 (0)