diff options
author | Fedor Indutny <fedor.indutny@gmail.com> | 2014-03-13 20:38:14 +0400 |
---|---|---|
committer | Fedor Indutny <fedor.indutny@gmail.com> | 2014-03-13 20:56:55 +0400 |
commit | ce04c726a31cd13be131915b1c8b8bc7a00a4d24 (patch) | |
tree | b309f6f42362231f54825586b9d79bd6163bb985 /src | |
parent | 1c7bf245dc2d520c005e01bcb56ecb3275971395 (diff) | |
download | android-node-v8-ce04c726a31cd13be131915b1c8b8bc7a00a4d24.tar.gz android-node-v8-ce04c726a31cd13be131915b1c8b8bc7a00a4d24.tar.bz2 android-node-v8-ce04c726a31cd13be131915b1c8b8bc7a00a4d24.zip |
src: update to v8 3.24 APIs
Diffstat (limited to 'src')
35 files changed, 436 insertions, 372 deletions
diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 567b159807..1b998694a9 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -50,6 +50,7 @@ namespace cares_wrap { using v8::Array; using v8::Context; +using v8::EscapableHandleScope; using v8::Function; using v8::FunctionCallbackInfo; using v8::Handle; @@ -194,8 +195,8 @@ static void ares_sockstate_cb(void* data, static Local<Array> HostentToAddresses(Environment* env, struct hostent* host) { - HandleScope scope(env->isolate()); - Local<Array> addresses = Array::New(); + EscapableHandleScope scope(env->isolate()); + Local<Array> addresses = Array::New(env->isolate()); char ip[INET6_ADDRSTRLEN]; 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) { addresses->Set(i, address); } - return scope.Close(addresses); + return scope.Escape(addresses); } static Local<Array> HostentToNames(Environment* env, struct hostent* host) { - HandleScope scope(env->isolate()); - Local<Array> names = Array::New(); + EscapableHandleScope scope(env->isolate()); + Local<Array> names = Array::New(env->isolate()); for (uint32_t i = 0; host->h_aliases[i] != NULL; ++i) { Local<String> address = OneByteString(env->isolate(), host->h_aliases[i]); names->Set(i, address); } - return scope.Close(names); + return scope.Escape(names); } @@ -229,7 +230,7 @@ class QueryWrap : public AsyncWrap { virtual ~QueryWrap() { assert(!persistent().IsEmpty()); - persistent().Dispose(); + persistent().Reset(); } // Subclasses should implement the appropriate Send method. @@ -278,7 +279,7 @@ class QueryWrap : public AsyncWrap { HandleScope handle_scope(env()->isolate()); Context::Scope context_scope(env()->context()); Local<Value> argv[] = { - Integer::New(0, env()->isolate()), + Integer::New(env()->isolate(), 0), answer }; MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv); @@ -288,7 +289,7 @@ class QueryWrap : public AsyncWrap { HandleScope handle_scope(env()->isolate()); Context::Scope context_scope(env()->context()); Local<Value> argv[] = { - Integer::New(0, env()->isolate()), + Integer::New(env()->isolate(), 0), answer, family }; @@ -452,7 +453,7 @@ class QueryCnameWrap: public QueryWrap { // A cname lookup always returns a single record but we follow the // common API here. - Local<Array> result = Array::New(1); + Local<Array> result = Array::New(env()->isolate(), 1); result->Set(0, OneByteString(env()->isolate(), host->h_name)); ares_free_hostent(host); @@ -489,17 +490,17 @@ class QueryMxWrap: public QueryWrap { return; } - Local<Array> mx_records = Array::New(); + Local<Array> mx_records = Array::New(env()->isolate()); Local<String> exchange_symbol = env()->exchange_string(); Local<String> priority_symbol = env()->priority_string(); ares_mx_reply* current = mx_start; for (uint32_t i = 0; current != NULL; ++i, current = current->next) { - Local<Object> mx_record = Object::New(); + Local<Object> mx_record = Object::New(env()->isolate()); mx_record->Set(exchange_symbol, OneByteString(env()->isolate(), current->host)); mx_record->Set(priority_symbol, - Integer::New(current->priority, env()->isolate())); + Integer::New(env()->isolate(), current->priority)); mx_records->Set(i, mx_record); } @@ -574,7 +575,7 @@ class QueryTxtWrap: public QueryWrap { return; } - Local<Array> txt_records = Array::New(); + Local<Array> txt_records = Array::New(env()->isolate()); ares_txt_reply* current = txt_out; for (uint32_t i = 0; current != NULL; ++i, current = current->next) { @@ -617,7 +618,7 @@ class QuerySrvWrap: public QueryWrap { return; } - Local<Array> srv_records = Array::New(); + Local<Array> srv_records = Array::New(env()->isolate()); Local<String> name_symbol = env()->name_string(); Local<String> port_symbol = env()->port_string(); Local<String> priority_symbol = env()->priority_string(); @@ -625,15 +626,15 @@ class QuerySrvWrap: public QueryWrap { ares_srv_reply* current = srv_start; for (uint32_t i = 0; current != NULL; ++i, current = current->next) { - Local<Object> srv_record = Object::New(); + Local<Object> srv_record = Object::New(env()->isolate()); srv_record->Set(name_symbol, OneByteString(env()->isolate(), current->host)); srv_record->Set(port_symbol, - Integer::New(current->port, env()->isolate())); + Integer::New(env()->isolate(), current->port)); srv_record->Set(priority_symbol, - Integer::New(current->priority, env()->isolate())); + Integer::New(env()->isolate(), current->priority)); srv_record->Set(weight_symbol, - Integer::New(current->weight, env()->isolate())); + Integer::New(env()->isolate(), current->weight)); srv_records->Set(i, srv_record); } @@ -672,7 +673,7 @@ class QueryNaptrWrap: public QueryWrap { return; } - Local<Array> naptr_records = Array::New(); + Local<Array> naptr_records = Array::New(env()->isolate()); Local<String> flags_symbol = env()->flags_string(); Local<String> service_symbol = env()->service_string(); Local<String> regexp_symbol = env()->regexp_string(); @@ -682,7 +683,7 @@ class QueryNaptrWrap: public QueryWrap { ares_naptr_reply* current = naptr_start; for (uint32_t i = 0; current != NULL; ++i, current = current->next) { - Local<Object> naptr_record = Object::New(); + Local<Object> naptr_record = Object::New(env()->isolate()); naptr_record->Set(flags_symbol, OneByteString(env()->isolate(), current->flags)); naptr_record->Set(service_symbol, @@ -692,9 +693,9 @@ class QueryNaptrWrap: public QueryWrap { naptr_record->Set(replacement_symbol, OneByteString(env()->isolate(), current->replacement)); naptr_record->Set(order_symbol, - Integer::New(current->order, env()->isolate())); + Integer::New(env()->isolate(), current->order)); naptr_record->Set(preference_symbol, - Integer::New(current->preference, env()->isolate())); + Integer::New(env()->isolate(), current->preference)); naptr_records->Set(i, naptr_record); } @@ -734,22 +735,22 @@ class QuerySoaWrap: public QueryWrap { return; } - Local<Object> soa_record = Object::New(); + Local<Object> soa_record = Object::New(env()->isolate()); soa_record->Set(env()->nsname_string(), OneByteString(env()->isolate(), soa_out->nsname)); soa_record->Set(env()->hostmaster_string(), OneByteString(env()->isolate(), soa_out->hostmaster)); soa_record->Set(env()->serial_string(), - Integer::New(soa_out->serial, env()->isolate())); + Integer::New(env()->isolate(), soa_out->serial)); soa_record->Set(env()->refresh_string(), - Integer::New(soa_out->refresh, env()->isolate())); + Integer::New(env()->isolate(), soa_out->refresh)); soa_record->Set(env()->retry_string(), - Integer::New(soa_out->retry, env()->isolate())); + Integer::New(env()->isolate(), soa_out->retry)); soa_record->Set(env()->expire_string(), - Integer::New(soa_out->expire, env()->isolate())); + Integer::New(env()->isolate(), soa_out->expire)); soa_record->Set(env()->minttl_string(), - Integer::New(soa_out->minttl, env()->isolate())); + Integer::New(env()->isolate(), soa_out->minttl)); ares_free_data(soa_out); @@ -816,7 +817,7 @@ class GetHostByNameWrap: public QueryWrap { HandleScope scope(env()->isolate()); Local<Array> addresses = HostentToAddresses(env(), host); - Local<Integer> family = Integer::New(host->h_addrtype, env()->isolate()); + Local<Integer> family = Integer::New(env()->isolate(), host->h_addrtype); this->CallOnComplete(addresses, family); } @@ -853,7 +854,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { Context::Scope context_scope(env->context()); Local<Value> argv[] = { - Integer::New(status, env->isolate()), + Integer::New(env->isolate(), status), Null(env->isolate()) }; @@ -868,7 +869,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { } // Create the response array. - Local<Array> results = Array::New(n); + Local<Array> results = Array::New(env->isolate(), n); char ip[INET6_ADDRSTRLEN]; const char *addr; @@ -947,7 +948,7 @@ static void IsIP(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope scope(env->isolate()); - String::AsciiValue ip(args[0]); + String::Utf8Value ip(args[0]); char address_buffer[sizeof(struct in6_addr)]; int rc = 0; @@ -1014,7 +1015,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) { HandleScope handle_scope(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate()); - Local<Array> server_array = Array::New(); + Local<Array> server_array = Array::New(env->isolate()); ares_addr_node* servers; @@ -1160,11 +1161,11 @@ static void Initialize(Handle<Object> target, NODE_SET_METHOD(target, "setServers", SetServers); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"), - Integer::New(AF_INET, env->isolate())); + Integer::New(env->isolate(), AF_INET)); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET6"), - Integer::New(AF_INET6, env->isolate())); + Integer::New(env->isolate(), AF_INET6)); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "AF_UNSPEC"), - Integer::New(AF_UNSPEC, env->isolate())); + Integer::New(env->isolate(), AF_UNSPEC)); } } // namespace cares_wrap diff --git a/src/env-inl.h b/src/env-inl.h index bcc7995fa3..9a6199da2f 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -70,7 +70,7 @@ inline uint64_t Environment::GCInfo::timestamp() const { inline Environment::IsolateData* Environment::IsolateData::Get( v8::Isolate* isolate) { - return static_cast<IsolateData*>(isolate->GetData()); + return static_cast<IsolateData*>(isolate->GetData(kIsolateSlot)); } inline Environment::IsolateData* Environment::IsolateData::GetOrCreate( @@ -78,7 +78,7 @@ inline Environment::IsolateData* Environment::IsolateData::GetOrCreate( IsolateData* isolate_data = Get(isolate); if (isolate_data == NULL) { isolate_data = new IsolateData(isolate); - isolate->SetData(isolate_data); + isolate->SetData(kIsolateSlot, isolate_data); } isolate_data->ref_count_ += 1; return isolate_data; @@ -86,7 +86,7 @@ inline Environment::IsolateData* Environment::IsolateData::GetOrCreate( inline void Environment::IsolateData::Put() { if (--ref_count_ == 0) { - isolate()->SetData(NULL); + isolate()->SetData(kIsolateSlot, NULL); delete this; } } @@ -230,8 +230,8 @@ inline Environment::Environment(v8::Local<v8::Context> context) // We'll be creating new objects so make sure we've entered the context. v8::HandleScope handle_scope(isolate()); v8::Context::Scope context_scope(context); - set_binding_cache_object(v8::Object::New()); - set_module_load_list_array(v8::Array::New()); + set_binding_cache_object(v8::Object::New(isolate())); + set_module_load_list_array(v8::Array::New(isolate())); RB_INIT(&cares_task_list_); QUEUE_INIT(&gc_tracker_queue_); } @@ -240,7 +240,7 @@ inline Environment::~Environment() { v8::HandleScope handle_scope(isolate()); context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, NULL); -#define V(PropertyName, TypeName) PropertyName ## _.Dispose(); +#define V(PropertyName, TypeName) PropertyName ## _.Reset(); ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) #undef V isolate_data()->Put(); @@ -370,7 +370,7 @@ inline Environment::IsolateData* Environment::isolate_data() const { #define THROW_ERROR(fun) \ do { \ v8::HandleScope scope(isolate); \ - v8::ThrowException(fun(OneByteString(isolate, errmsg))); \ + isolate->ThrowException(fun(OneByteString(isolate, errmsg))); \ } \ while (0) @@ -404,7 +404,7 @@ inline void Environment::ThrowErrnoException(int errorno, const char* syscall, const char* message, const char* path) { - v8::ThrowException( + isolate()->ThrowException( ErrnoException(isolate(), errorno, syscall, message, path)); } @@ -412,7 +412,7 @@ inline void Environment::ThrowUVException(int errorno, const char* syscall, const char* message, const char* path) { - v8::ThrowException( + isolate()->ThrowException( UVException(isolate(), errorno, syscall, message, path)); } @@ -422,6 +422,8 @@ class Environment { #undef V private: + static const int kIsolateSlot = 0; + class GCInfo; class IsolateData; inline explicit Environment(v8::Local<v8::Context> context); diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index ee28c44afb..9c1a2b6c6f 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -83,7 +83,7 @@ void FSEventWrap::Initialize(Handle<Object> target, Handle<Context> context) { Environment* env = Environment::GetCurrent(context); - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(env->fsevent_string()); @@ -172,7 +172,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, } Local<Value> argv[] = { - Integer::New(status, env->isolate()), + Integer::New(env->isolate(), status), event_string, Null(env->isolate()) }; diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 3df1e497d3..245c0e10ad 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -130,7 +130,7 @@ void HandleWrap::OnClose(uv_handle_t* handle) { } object->SetAlignedPointerInInternalField(0, NULL); - wrap->persistent().Dispose(); + wrap->persistent().Reset(); delete wrap; } diff --git a/src/node.cc b/src/node.cc index 0acdd22ad3..61041aeb42 100644 --- a/src/node.cc +++ b/src/node.cc @@ -93,6 +93,7 @@ using v8::Array; using v8::ArrayBuffer; using v8::Boolean; using v8::Context; +using v8::EscapableHandleScope; using v8::Exception; using v8::Function; using v8::FunctionCallbackInfo; @@ -110,7 +111,6 @@ using v8::Object; using v8::ObjectTemplate; using v8::PropertyCallbackInfo; using v8::String; -using v8::ThrowException; using v8::TryCatch; using v8::Uint32; using v8::V8; @@ -707,7 +707,7 @@ Local<Value> ErrnoException(Isolate* isolate, } Local<Object> obj = e->ToObject(); - obj->Set(env->errno_string(), Integer::New(errorno, env->isolate())); + obj->Set(env->errno_string(), Integer::New(env->isolate(), errorno)); obj->Set(env->code_string(), estring); if (path != NULL) { @@ -770,7 +770,7 @@ Local<Value> UVException(Isolate* isolate, Local<Object> obj = e->ToObject(); // TODO(piscisaureus) errno should probably go - obj->Set(env->errno_string(), Integer::New(errorno, env->isolate())); + obj->Set(env->errno_string(), Integer::New(env->isolate(), errorno)); obj->Set(env->code_string(), estring); if (path != NULL) { @@ -835,7 +835,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate, } Local<Object> obj = e->ToObject(); - obj->Set(env->errno_string(), Integer::New(errorno, isolate)); + obj->Set(env->errno_string(), Integer::New(isolate, errorno)); if (path != NULL) { obj->Set(env->path_string(), String::NewFromUtf8(isolate, path)); @@ -1150,11 +1150,12 @@ Handle<Value> MakeCallback(Isolate* isolate, const char* method, int argc, Handle<Value> argv[]) { - HandleScope handle_scope(isolate); + EscapableHandleScope handle_scope(isolate); Local<Context> context = recv->CreationContext(); Environment* env = Environment::GetCurrent(context); Context::Scope context_scope(context); - return handle_scope.Close(MakeCallback(env, recv, method, argc, argv)); + return handle_scope.Escape( + Local<Value>::New(isolate, MakeCallback(env, recv, method, argc, argv))); } @@ -1163,11 +1164,12 @@ Handle<Value> MakeCallback(Isolate* isolate, Handle<String> symbol, int argc, Handle<Value> argv[]) { - HandleScope handle_scope(isolate); + EscapableHandleScope handle_scope(isolate); Local<Context> context = recv->CreationContext(); Environment* env = Environment::GetCurrent(context); Context::Scope context_scope(context); - return handle_scope.Close(MakeCallback(env, recv, symbol, argc, argv)); + return handle_scope.Escape( + Local<Value>::New(isolate, MakeCallback(env, recv, symbol, argc, argv))); } @@ -1176,12 +1178,13 @@ Handle<Value> MakeCallback(Isolate* isolate, Handle<Function> callback, int argc, Handle<Value> argv[]) { - HandleScope handle_scope(isolate); + EscapableHandleScope handle_scope(isolate); Local<Context> context = recv->CreationContext(); Environment* env = Environment::GetCurrent(context); Context::Scope context_scope(context); - return handle_scope.Close( - MakeCallback(env, recv.As<Value>(), callback, argc, argv)); + return handle_scope.Escape(Local<Value>::New( + isolate, + MakeCallback(env, recv.As<Value>(), callback, argc, argv))); } @@ -1192,9 +1195,10 @@ Handle<Value> MakeDomainCallback(Handle<Object> recv, Local<Context> context = recv->CreationContext(); Environment* env = Environment::GetCurrent(context); Context::Scope context_scope(context); - HandleScope handle_scope(env->isolate()); - return handle_scope.Close( - MakeDomainCallback(env, recv, callback, argc, argv)); + EscapableHandleScope handle_scope(env->isolate()); + return handle_scope.Escape(Local<Value>::New( + env->isolate(), + MakeDomainCallback(env, recv, callback, argc, argv))); } @@ -1446,7 +1450,7 @@ static void ReportException(Environment* env, const TryCatch& try_catch) { static Local<Value> ExecuteString(Environment* env, Handle<String> source, Handle<Value> filename) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); TryCatch try_catch; // try_catch must be nonverbose to disable FatalException() handler, @@ -1465,14 +1469,14 @@ static Local<Value> ExecuteString(Environment* env, exit(4); } - return scope.Close(result); + return scope.Escape(result); } static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) { HandleScope scope(args.GetIsolate()); - Local<Array> ary = Array::New(); + Local<Array> ary = Array::New(args.GetIsolate()); QUEUE* q = NULL; int i = 0; @@ -1493,7 +1497,7 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope scope(env->isolate()); - Local<Array> ary = Array::New(); + Local<Array> ary = Array::New(env->isolate()); QUEUE* q = NULL; int i = 0; @@ -1774,12 +1778,12 @@ static void GetGroups(const FunctionCallbackInfo<Value>& args) { return env->ThrowErrnoException(errno, "getgroups"); } - Local<Array> groups_list = Array::New(ngroups); + Local<Array> groups_list = Array::New(env->isolate(), ngroups); bool seen_egid = false; gid_t egid = getegid(); for (int i = 0; i < ngroups; i++) { - groups_list->Set(i, Integer::New(groups[i], env->isolate())); + groups_list->Set(i, Integer::New(env->isolate(), groups[i])); if (groups[i] == egid) seen_egid = true; } @@ -1787,7 +1791,7 @@ static void GetGroups(const FunctionCallbackInfo<Value>& args) { delete[] groups; if (seen_egid == false) { - groups_list->Set(ngroups, Integer::New(egid, env->isolate())); + groups_list->Set(ngroups, Integer::New(env->isolate(), egid)); } args.GetReturnValue().Set(groups_list); @@ -1909,11 +1913,11 @@ void MemoryUsage(const FunctionCallbackInfo<Value>& args) { env->isolate()->GetHeapStatistics(&v8_heap_stats); Local<Integer> heap_total = - Integer::NewFromUnsigned(v8_heap_stats.total_heap_size(), env->isolate()); + Integer::NewFromUnsigned(env->isolate(), v8_heap_stats.total_heap_size()); Local<Integer> heap_used = - Integer::NewFromUnsigned(v8_heap_stats.used_heap_size(), env->isolate()); + Integer::NewFromUnsigned(env->isolate(), v8_heap_stats.used_heap_size()); - Local<Object> info = Object::New(); + Local<Object> info = Object::New(env->isolate()); info->Set(env->rss_string(), Number::New(env->isolate(), rss)); info->Set(env->heap_total_string(), heap_total); info->Set(env->heap_used_string(), heap_used); @@ -1962,9 +1966,9 @@ void Hrtime(const FunctionCallbackInfo<Value>& args) { t -= (seconds * NANOS_PER_SEC) + nanos; } - Local<Array> tuple = Array::New(2); - tuple->Set(0, Integer::NewFromUnsigned(t / NANOS_PER_SEC, env->isolate())); - tuple->Set(1, Integer::NewFromUnsigned(t % NANOS_PER_SEC, env->isolate())); + Local<Array> tuple = Array::New(env->isolate(), 2); + tuple->Set(0, Integer::NewFromUnsigned(env->isolate(), t / NANOS_PER_SEC)); + tuple->Set(1, Integer::NewFromUnsigned(env->isolate(), t % NANOS_PER_SEC)); args.GetReturnValue().Set(tuple); } @@ -2170,7 +2174,7 @@ static void Binding(const FunctionCallbackInfo<Value>& args) { node_module* mod = get_builtin_module(*module_v); if (mod != NULL) { - exports = Object::New(); + exports = Object::New(env->isolate()); // Internal bindings don't have a "module" object, only exports. assert(mod->nm_register_func == NULL); assert(mod->nm_context_register_func != NULL); @@ -2179,11 +2183,11 @@ static void Binding(const FunctionCallbackInfo<Value>& args) { env->context(), mod->nm_priv); cache->Set(module, exports); } else if (!strcmp(*module_v, "constants")) { - exports = Object::New(); + exports = Object::New(env->isolate()); DefineConstants(exports); cache->Set(module, exports); } else if (!strcmp(*module_v, "natives")) { - exports = Object::New(); + exports = Object::New(env->isolate()); DefineJavaScript(env, exports); cache->Set(module, exports); } else { @@ -2330,7 +2334,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) { while (environ[size]) size++; - Local<Array> envarr = Array::New(size); + Local<Array> envarr = Array::New(env->isolate(), size); for (int i = 0; i < size; ++i) { const char* var = environ[i]; @@ -2346,7 +2350,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) { WCHAR* environment = GetEnvironmentStringsW(); if (environment == NULL) return; // This should not happen. - Local<Array> envarr = Array::New(); + Local<Array> envarr = Array::New(env->isolate()); WCHAR* p = environment; int i = 0; while (*p != NULL) { @@ -2378,9 +2382,9 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) { static Handle<Object> GetFeatures(Environment* env) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); - Local<Object> obj = Object::New(); + Local<Object> obj = Object::New(env->isolate()); #if defined(DEBUG) && DEBUG Local<Value> debug = True(env->isolate()); #else @@ -2408,9 +2412,9 @@ static Handle<Object> GetFeatures(Environment* env) { obj->Set(env->tls_sni_string(), tls_sni); obj->Set(env->tls_string(), - Boolean::New(get_builtin_module("crypto") != NULL)); + Boolean::New(env->isolate(), get_builtin_module("crypto") != NULL)); - return scope.Close(obj); + return scope.Escape(obj); } @@ -2542,7 +2546,7 @@ void SetupProcessObject(Environment* env, env->module_load_list_array()); // process.versions - Local<Object> versions = Object::New(); + Local<Object> versions = Object::New(env->isolate()); READONLY_PROPERTY(process, "versions", versions); const char http_parser_version[] = NODE_STRINGIFY(HTTP_PARSER_VERSION_MAJOR) @@ -2604,31 +2608,32 @@ void SetupProcessObject(Environment* env, OneByteString(env->isolate(), PLATFORM)); // process.argv - Local<Array> arguments = Array::New(argc); + Local<Array> arguments = Array::New(env->isolate(), argc); for (int i = 0; i < argc; ++i) { arguments->Set(i, String::NewFromUtf8(env->isolate(), argv[i])); } process->Set(env->argv_string(), arguments); // process.execArgv - Local<Array> exec_arguments = Array::New(exec_argc); + Local<Array> exec_arguments = Array::New(env->isolate(), exec_argc); for (int i = 0; i < exec_argc; ++i) { exec_arguments->Set(i, String::NewFromUtf8(env->isolate(), exec_argv[i])); } process->Set(env->exec_argv_string(), exec_arguments); // create process.env - Local<ObjectTemplate> process_env_template = ObjectTemplate::New(); + Local<ObjectTemplate> process_env_template = + ObjectTemplate::New(env->isolate()); process_env_template->SetNamedPropertyHandler(EnvGetter, EnvSetter, EnvQuery, EnvDeleter, EnvEnumerator, - Object::New()); + Object::New(env->isolate())); Local<Object> process_env = process_env_template->NewInstance(); process->Set(env->env_string(), process_env); - READONLY_PROPERTY(process, "pid", Integer::New(getpid(), env->isolate())); + READONLY_PROPERTY(process, "pid", Integer::New(env->isolate(), getpid())); READONLY_PROPERTY(process, "features", GetFeatures(env)); process->SetAccessor(env->need_imm_cb_string(), NeedImmediateCallbackGetter, @@ -2732,7 +2737,7 @@ void SetupProcessObject(Environment* env, NODE_SET_METHOD(process, "_setupDomainUse", SetupDomainUse); // values use to cross communicate with processNextTick - Local<Object> tick_info_obj = Object::New(); + Local<Object> tick_info_obj = Object::New(env->isolate()); tick_info_obj->SetIndexedPropertiesToExternalArrayData( env->tick_info()->fields(), kExternalUnsignedIntArray, @@ -2740,7 +2745,7 @@ void SetupProcessObject(Environment* env, process->Set(env->tick_info_string(), tick_info_obj); // pre-set _events object for faster emit checks - process->Set(env->events_string(), Object::New()); + process->Set(env->events_string(), Object::New(env->isolate())); } @@ -3044,7 +3049,7 @@ static void EnableDebug(Isolate* isolate, bool wait_connect) { return; // Still starting up. Context::Scope context_scope(env->context()); - Local<Object> message = Object::New(); + Local<Object> message = Object::New(env->isolate()); message->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "cmd"), FIXED_ONE_BYTE_STRING(env->isolate(), "NODE_DEBUG_ENABLED")); Local<Value> argv[] = { @@ -3448,7 +3453,7 @@ int EmitExit(Environment* env) { Local<Value> args[] = { env->exit_string(), - Integer::New(code, env->isolate()) + Integer::New(env->isolate(), code) }; MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args); @@ -3492,7 +3497,7 @@ Environment* CreateEnvironment(Isolate* isolate, StartProfilerIdleNotifier(env); } - Local<FunctionTemplate> process_template = FunctionTemplate::New(); + Local<FunctionTemplate> process_template = FunctionTemplate::New(isolate); process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "process")); Local<Object> process_object = process_template->GetFunction()->NewInstance(); @@ -3538,22 +3543,24 @@ int Start(int argc, char** argv) { // environment with Environment::GetCurrentChecked(). // TODO(bnoordhuis) Reorder the debugger initialization logic so it can // be removed. - Context::Scope context_scope(env->context()); - bool more; - do { - more = uv_run(env->event_loop(), UV_RUN_ONCE); - if (more == false) { - EmitBeforeExit(env); - - // Emit `beforeExit` if the loop became alive either after emitting - // event, or after running some callbacks. - more = uv_loop_alive(env->event_loop()); - if (uv_run(env->event_loop(), UV_RUN_NOWAIT) != 0) - more = true; - } - } while (more == true); - code = EmitExit(env); - RunAtExit(env); + { + Context::Scope context_scope(env->context()); + bool more; + do { + more = uv_run(env->event_loop(), UV_RUN_ONCE); + if (more == false) { + EmitBeforeExit(env); + + // Emit `beforeExit` if the loop became alive either after emitting + // event, or after running some callbacks. + more = uv_loop_alive(env->event_loop()); + if (uv_run(env->event_loop(), UV_RUN_NOWAIT) != 0) + more = true; + } + } while (more == true); + code = EmitExit(env); + RunAtExit(env); + } env->Dispose(); env = NULL; } diff --git a/src/node.h b/src/node.h index 03cf155af1..417d1d8e35 100644 --- a/src/node.h +++ b/src/node.h @@ -193,7 +193,8 @@ inline void NODE_SET_METHOD(const TypeName& recv, v8::FunctionCallback callback) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handle_scope(isolate); - v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(callback); + v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate, + callback); v8::Local<v8::Function> fn = t->GetFunction(); v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name); fn->SetName(fn_name); @@ -208,7 +209,8 @@ inline void NODE_SET_PROTOTYPE_METHOD(v8::Handle<v8::FunctionTemplate> recv, v8::FunctionCallback callback) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handle_scope(isolate); - v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(callback); + v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate, + callback); recv->PrototypeTemplate()->Set(v8::String::NewFromUtf8(isolate, name), t->GetFunction()); } diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 8304c4f02f..b1d63ad045 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -63,6 +63,7 @@ namespace Buffer { using v8::ArrayBuffer; using v8::Context; +using v8::EscapableHandleScope; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -117,7 +118,7 @@ size_t Length(Handle<Object> obj) { Local<Object> New(Isolate* isolate, Handle<String> string, enum encoding enc) { - HandleScope scope(isolate); + EscapableHandleScope scope(isolate); size_t length = StringBytes::Size(isolate, string, enc); @@ -125,25 +126,25 @@ Local<Object> New(Isolate* isolate, Handle<String> string, enum encoding enc) { char* data = Buffer::Data(buf); StringBytes::Write(isolate, data, length, string, enc); - return scope.Close(buf); + return scope.Escape(buf); } Local<Object> New(Isolate* isolate, size_t length) { - HandleScope handle_scope(isolate); + EscapableHandleScope handle_scope(isolate); Local<Object> obj = Buffer::New(Environment::GetCurrent(isolate), length); - return handle_scope.Close(obj); + return handle_scope.Escape(obj); } // TODO(trevnorris): these have a flaw by needing to call the Buffer inst then // Alloc. continue to look for a better architecture. Local<Object> New(Environment* env, size_t length) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); assert(length <= kMaxLength); - Local<Value> arg = Uint32::NewFromUnsigned(length, env->isolate()); + Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length); Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg); // TODO(trevnorris): done like this to handle HasInstance since only checks @@ -159,15 +160,15 @@ Local<Object> New(Environment* env, size_t length) { } smalloc::Alloc(env, obj, data, length); - return scope.Close(obj); + return scope.Escape(obj); } Local<Object> New(Isolate* isolate, const char* data, size_t length) { Environment* env = Environment::GetCurrent(isolate); - HandleScope handle_scope(env->isolate()); + EscapableHandleScope handle_scope(env->isolate()); Local<Object> obj = Buffer::New(env, data, length); - return handle_scope.Close(obj); + return handle_scope.Escape(obj); } @@ -175,11 +176,11 @@ Local<Object> New(Isolate* isolate, const char* data, size_t length) { // but for consistency w/ the other should use data. And a copy version renamed // to something else. Local<Object> New(Environment* env, const char* data, size_t length) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); assert(length <= kMaxLength); - Local<Value> arg = Uint32::NewFromUnsigned(length, env->isolate()); + Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length); Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg); // TODO(trevnorris): done like this to handle HasInstance since only checks @@ -197,7 +198,7 @@ Local<Object> New(Environment* env, const char* data, size_t length) { smalloc::Alloc(env, obj, new_data, length); - return scope.Close(obj); + return scope.Escape(obj); } @@ -207,9 +208,9 @@ Local<Object> New(Isolate* isolate, smalloc::FreeCallback callback, void* hint) { Environment* env = Environment::GetCurrent(isolate); - HandleScope handle_scope(env->isolate()); + EscapableHandleScope handle_scope(env->isolate()); Local<Object> obj = Buffer::New(env, data, length, callback, hint); - return handle_scope.Close(obj); + return handle_scope.Escape(obj); } @@ -218,38 +219,38 @@ Local<Object> New(Environment* env, size_t length, smalloc::FreeCallback callback, void* hint) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); assert(length <= kMaxLength); - Local<Value> arg = Uint32::NewFromUnsigned(length, env->isolate()); + Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length); Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg); smalloc::Alloc(env, obj, data, length, callback, hint); - return scope.Close(obj); + return scope.Escape(obj); } Local<Object> Use(Isolate* isolate, char* data, uint32_t length) { Environment* env = Environment::GetCurrent(isolate); - HandleScope handle_scope(env->isolate()); + EscapableHandleScope handle_scope(env->isolate()); Local<Object> obj = Buffer::Use(env, data, length); - return handle_scope.Close(obj); + return handle_scope.Escape(obj); } Local<Object> Use(Environment* env, char* data, uint32_t length) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); assert(length <= kMaxLength); - Local<Value> arg = Uint32::NewFromUnsigned(length, env->isolate()); + Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length); Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg); smalloc::Alloc(env, obj, data, length); - return scope.Close(obj); + return scope.Escape(obj); } @@ -586,7 +587,7 @@ void ToArrayBuffer(const FunctionCallbackInfo<Value>& args) { memcpy(adata, obj_data, obj_length); - Local<ArrayBuffer> abuf = ArrayBuffer::New(adata, obj_length); + Local<ArrayBuffer> abuf = ArrayBuffer::New(env->isolate(), adata, obj_length); args.GetReturnValue().Set(abuf); } @@ -652,7 +653,7 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) { // for backwards compatibility proto->Set(env->offset_string(), - Uint32::New(0, env->isolate()), + Uint32::New(env->isolate(), 0), v8::ReadOnly); assert(args[1]->IsObject()); @@ -660,7 +661,8 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) { Local<Object> internal = args[1].As<Object>(); internal->Set(env->byte_length_string(), - FunctionTemplate::New(ByteLength)->GetFunction()); + FunctionTemplate::New( + env->isolate(), ByteLength)->GetFunction()); } @@ -669,7 +671,8 @@ void Initialize(Handle<Object> target, Handle<Context> context) { Environment* env = Environment::GetCurrent(context); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "setupBufferJS"), - FunctionTemplate::New(SetupBufferJS)->GetFunction()); + FunctionTemplate::New(env->isolate(), SetupBufferJS) + ->GetFunction()); } diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 05d2b11c3f..df63ed4f07 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -35,6 +35,7 @@ using v8::AccessType; using v8::Array; using v8::Boolean; using v8::Context; +using v8::EscapableHandleScope; using v8::External; using v8::Function; using v8::FunctionCallbackInfo; @@ -54,10 +55,17 @@ using v8::String; using v8::TryCatch; using v8::V8; using v8::Value; +using v8::WeakCallbackData; class ContextifyContext { - private: + protected: + enum Kind { + kSandbox, + kContext, + kProxyGlobal + }; + Environment* const env_; Persistent<Object> sandbox_; Persistent<Context> context_; @@ -71,28 +79,28 @@ class ContextifyContext { context_(env->isolate(), CreateV8Context(env)), // Wait for sandbox_, proxy_global_, and context_ to die references_(0) { - sandbox_.MakeWeak(this, WeakCallback); + sandbox_.SetWeak(this, WeakCallback<Object, kSandbox>); sandbox_.MarkIndependent(); references_++; // Allocation failure or maximum call stack size reached if (context_.IsEmpty()) return; - context_.MakeWeak(this, WeakCallback); + context_.SetWeak(this, WeakCallback<Context, kContext>); context_.MarkIndependent(); references_++; proxy_global_.Reset(env->isolate(), context()->Global()); - proxy_global_.MakeWeak(this, WeakCallback); + proxy_global_.SetWeak(this, WeakCallback<Object, kProxyGlobal>); proxy_global_.MarkIndependent(); references_++; } ~ContextifyContext() { - context_.Dispose(); - proxy_global_.Dispose(); - sandbox_.Dispose(); + context_.Reset(); + proxy_global_.Reset(); + sandbox_.Reset(); } @@ -186,20 +194,21 @@ class ContextifyContext { // NamedPropertyHandler will store a reference to it forever and keep it // from getting gc'd. Local<Value> CreateDataWrapper(Environment* env) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); Local<Object> wrapper = env->script_data_constructor_function()->NewInstance(); if (wrapper.IsEmpty()) - return scope.Close(Handle<Value>()); + return scope.Escape(Local<Value>::New(env->isolate(), Handle<Value>())); Wrap<ContextifyContext>(wrapper, this); - return scope.Close(wrapper); + return scope.Escape(wrapper); } Local<Context> CreateV8Context(Environment* env) { - HandleScope scope(env->isolate()); - Local<FunctionTemplate> function_template = FunctionTemplate::New(); + EscapableHandleScope scope(env->isolate()); + Local<FunctionTemplate> function_template = + FunctionTemplate::New(env->isolate()); function_template->SetHiddenPrototype(true); Local<Object> sandbox = PersistentToLocal(env->isolate(), sandbox_); @@ -215,12 +224,13 @@ class ContextifyContext { CreateDataWrapper(env)); object_template->SetAccessCheckCallbacks(GlobalPropertyNamedAccessCheck, GlobalPropertyIndexedAccessCheck); - return scope.Close(Context::New(env->isolate(), NULL, object_template)); + return scope.Escape(Context::New(env->isolate(), NULL, object_template)); } static void Init(Environment* env, Local<Object> target) { - Local<FunctionTemplate> function_template = FunctionTemplate::New(); + Local<FunctionTemplate> function_template = + FunctionTemplate::New(env->isolate()); function_template->InstanceTemplate()->SetInternalFieldCount(1); env->set_script_data_constructor_function(function_template->GetFunction()); @@ -255,7 +265,7 @@ class ContextifyContext { if (context->context().IsEmpty()) return; - Local<External> hidden_context = External::New(context); + Local<External> hidden_context = External::New(env->isolate(), context); sandbox->SetHiddenValue(hidden_name, hidden_context); } @@ -277,11 +287,16 @@ class ContextifyContext { } - template <class T> - static void WeakCallback(Isolate* isolate, - Persistent<T>* target, - ContextifyContext* context) { - target->ClearWeak(); + template <class T, Kind kind> + static void WeakCallback(const WeakCallbackData<T, ContextifyContext>& data) { + ContextifyContext* context = data.GetParameter(); + if (kind == kSandbox) + context->sandbox_.ClearWeak(); + else if (kind == kContext) + context->context_.ClearWeak(); + else + context->proxy_global_.ClearWeak(); + if (--context->references_ == 0) delete context; } @@ -419,7 +434,8 @@ class ContextifyScript : public BaseObject { Local<String> class_name = FIXED_ONE_BYTE_STRING(env->isolate(), "ContextifyScript"); - Local<FunctionTemplate> script_tmpl = FunctionTemplate::New(New); + Local<FunctionTemplate> script_tmpl = FunctionTemplate::New(env->isolate(), + New); script_tmpl->InstanceTemplate()->SetInternalFieldCount(1); script_tmpl->SetClassName(class_name); NODE_SET_PROTOTYPE_METHOD(script_tmpl, "runInContext", RunInContext); @@ -453,7 +469,7 @@ class ContextifyScript : public BaseObject { return; } - Local<Context> context = Context::GetCurrent(); + Local<Context> context = env->context(); Context::Scope context_scope(context); Local<Script> v8_script = Script::New(code, filename); @@ -657,7 +673,7 @@ class ContextifyScript : public BaseObject { ~ContextifyScript() { - script_.Dispose(); + script_.Reset(); } }; diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 5ae45d8540..eed43fd787 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -91,7 +91,6 @@ using v8::Persistent; using v8::PropertyAttribute; using v8::PropertyCallbackInfo; using v8::String; -using v8::ThrowException; using v8::V8; using v8::Value; @@ -226,7 +225,8 @@ bool EntropySource(unsigned char* buffer, size_t length) { void SecureContext::Initialize(Environment* env, Handle<Object> target) { - Local<FunctionTemplate> t = FunctionTemplate::New(SecureContext::New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), + SecureContext::New); t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext")); @@ -713,7 +713,7 @@ void SecureContext::SetSessionIdContext( BIO_free_all(bio); } - ThrowException(Exception::TypeError(message)); + args.GetIsolate()->ThrowException(Exception::TypeError(message)); } @@ -960,7 +960,7 @@ void SSLWrap<Base>::OnClientHello(void* arg, HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); - Local<Object> hello_obj = Object::New(); + Local<Object> hello_obj = Object::New(env->isolate()); Local<Object> buff = Buffer::New( env, reinterpret_cast<const char*>(hello.session_id()), @@ -974,7 +974,8 @@ void SSLWrap<Base>::OnClientHello(void* arg, hello.servername_size()); hello_obj->Set(env->servername_string(), servername); } - hello_obj->Set(env->tls_ticket_string(), Boolean::New(hello.has_ticket())); + hello_obj->Set(env->tls_ticket_string(), + Boolean::New(env->isolate(), hello.has_ticket())); Local<Value> argv[] = { hello_obj }; w->MakeCallback(env->onclienthello_string(), ARRAY_SIZE(argv), argv); @@ -993,7 +994,7 @@ void SSLWrap<Base>::GetPeerCertificate( ClearErrorOnReturn clear_error_on_return; (void) &clear_error_on_return; // Silence unused variable warning. - Local<Object> info = Object::New(); + Local<Object> info = Object::New(env->isolate()); X509* peer_cert = SSL_get_peer_certificate(w->ssl_); if (peer_cert != NULL) { BIO* bio = BIO_new(BIO_s_mem()); @@ -1100,7 +1101,7 @@ void SSLWrap<Base>::GetPeerCertificate( STACK_OF(ASN1_OBJECT)* eku = static_cast<STACK_OF(ASN1_OBJECT)*>( X509_get_ext_d2i(peer_cert, NID_ext_key_usage, NULL, NULL)); if (eku != NULL) { - Local<Array> ext_key_usage = Array::New(); + Local<Array> ext_key_usage = Array::New(env->isolate()); char buf[256]; int j = 0; @@ -1211,7 +1212,7 @@ void SSLWrap<Base>::LoadSession(const FunctionCallbackInfo<Value>& args) { SSL_SESSION_free(w->next_sess_); w->next_sess_ = sess; - Local<Object> info = Object::New(); + Local<Object> info = Object::New(env->isolate()); #ifndef OPENSSL_NO_TLSEXT if (sess->tlsext_hostname == NULL) { info->Set(env->servername_string(), False(args.GetIsolate())); @@ -1396,7 +1397,7 @@ void SSLWrap<Base>::GetCurrentCipher(const FunctionCallbackInfo<Value>& args) { if (c == NULL) return; - Local<Object> info = Object::New(); + Local<Object> info = Object::New(env->isolate()); const char* cipher_name = SSL_CIPHER_get_name(c); info->Set(env->name_string(), OneByteString(args.GetIsolate(), cipher_name)); const char* cipher_version = SSL_CIPHER_get_version(c); @@ -1444,7 +1445,7 @@ int SSLWrap<Base>::SelectNextProtoCallback(SSL* s, Context::Scope context_scope(env->context()); // Release old protocol handler if present - w->selected_npn_proto_.Dispose(); + w->selected_npn_proto_.Reset(); if (w->npn_protos_.IsEmpty()) { // We should at least select one protocol @@ -1690,7 +1691,8 @@ void Connection::NewSessionDoneCb() { void Connection::Initialize(Environment* env, Handle<Object> target) { - Local<FunctionTemplate> t = FunctionTemplate::New(Connection::New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), + Connection::New); t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Connection")); @@ -1785,7 +1787,7 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) { // Call the SNI callback and use its return value as context if (!conn->sniObject_.IsEmpty()) { - conn->sniContext_.Dispose(); + conn->sniContext_.Reset(); Local<Value> arg = PersistentToLocal(env->isolate(), conn->servername_); Local<Value> ret = conn->MakeCallback(env->onselect_string(), 1, &arg); @@ -2175,7 +2177,7 @@ void Connection::SetSNICallback(const FunctionCallbackInfo<Value>& args) { return env->ThrowError("Must give a Function as first argument"); } - Local<Object> obj = Object::New(); + Local<Object> obj = Object::New(env->isolate()); obj->Set(FIXED_ONE_BYTE_STRING(args.GetIsolate(), "onselect"), args[0]); conn->sniObject_.Reset(args.GetIsolate(), obj); } @@ -2183,7 +2185,7 @@ void Connection::SetSNICallback(const FunctionCallbackInfo<Value>& args) { void CipherBase::Initialize(Environment* env, Handle<Object> target) { - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -2557,7 +2559,7 @@ void CipherBase::Final(const FunctionCallbackInfo<Value>& args) { void Hmac::Initialize(Environment* env, v8::Handle<v8::Object> target) { - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -2698,7 +2700,7 @@ void Hmac::HmacDigest(const FunctionCallbackInfo<Value>& args) { void Hash::Initialize(Environment* env, v8::Handle<v8::Object> target) { - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -2853,7 +2855,7 @@ void SignBase::CheckThrow(SignBase::Error error) { void Sign::Initialize(Environment* env, v8::Handle<v8::Object> target) { - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -3037,7 +3039,7 @@ void Sign::SignFinal(const FunctionCallbackInfo<Value>& args) { void Verify::Initialize(Environment* env, v8::Handle<v8::Object> target) { - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -3252,7 +3254,7 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) { void DiffieHellman::Initialize(Environment* env, Handle<Object> target) { - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); static enum PropertyAttribute attributes = static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete); @@ -3278,7 +3280,8 @@ void DiffieHellman::Initialize(Environment* env, Handle<Object> target) { target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "DiffieHellman"), t->GetFunction()); - Local<FunctionTemplate> t2 = FunctionTemplate::New(DiffieHellmanGroup); + Local<FunctionTemplate> t2 = FunctionTemplate::New(env->isolate(), + DiffieHellmanGroup); t2->InstanceTemplate()->SetInternalFieldCount(1); NODE_SET_PROTOTYPE_METHOD(t2, "generateKeys", GenerateKeys); @@ -3677,7 +3680,7 @@ class PBKDF2Request : public AsyncWrap { } ~PBKDF2Request() { - persistent().Dispose(); + persistent().Reset(); } uv_work_t* work_req() { @@ -3881,7 +3884,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) { digest = EVP_sha1(); } - obj = Object::New(); + obj = Object::New(env->isolate()); req = new PBKDF2Request(env, obj, digest, @@ -3906,7 +3909,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) { EIO_PBKDF2(req); EIO_PBKDF2After(req, argv); if (argv[0]->IsObject()) - ThrowException(argv[0]); + env->isolate()->ThrowException(argv[0]); else args.GetReturnValue().Set(argv[1]); } @@ -3932,7 +3935,7 @@ class RandomBytesRequest : public AsyncWrap { } ~RandomBytesRequest() { - persistent().Dispose(); + persistent().Reset(); } uv_work_t* work_req() { @@ -4053,7 +4056,7 @@ void RandomBytes(const FunctionCallbackInfo<Value>& args) { return env->ThrowTypeError("size > Buffer::kMaxLength"); } - Local<Object> obj = Object::New(); + Local<Object> obj = Object::New(env->isolate()); RandomBytesRequest* req = new RandomBytesRequest(env, obj, size); if (args[1]->IsFunction()) { @@ -4073,7 +4076,7 @@ void RandomBytes(const FunctionCallbackInfo<Value>& args) { delete req; if (!argv[0]->IsNull()) - ThrowException(argv[0]); + env->isolate()->ThrowException(argv[0]); else args.GetReturnValue().Set(argv[1]); } @@ -4095,7 +4098,7 @@ void GetSSLCiphers(const FunctionCallbackInfo<Value>& args) { return env->ThrowError("SSL_new() failed."); } - Local<Array> arr = Array::New(); + Local<Array> arr = Array::New(env->isolate()); STACK_OF(SSL_CIPHER)* ciphers = SSL_get_ciphers(ssl); for (int i = 0; i < sk_SSL_CIPHER_num(ciphers); ++i) { @@ -4112,7 +4115,9 @@ void GetSSLCiphers(const FunctionCallbackInfo<Value>& args) { class CipherPushContext { public: - explicit CipherPushContext(Environment* env) : arr(Array::New()), env_(env) { + explicit CipherPushContext(Environment* env) + : arr(Array::New(env->isolate())), + env_(env) { } inline Environment* env() const { return env_; } @@ -4155,7 +4160,7 @@ void GetHashes(const FunctionCallbackInfo<Value>& args) { void Certificate::Initialize(Environment* env, Handle<Object> target) { HandleScope scope(env->isolate()); - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); t->InstanceTemplate()->SetInternalFieldCount(1); diff --git a/src/node_crypto.h b/src/node_crypto.h index cc67061735..6605dfdf69 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -154,8 +154,8 @@ class SSLWrap { } #ifdef OPENSSL_NPN_NEGOTIATED - npn_protos_.Dispose(); - selected_npn_proto_.Dispose(); + npn_protos_.Reset(); + selected_npn_proto_.Reset(); #endif } @@ -240,9 +240,9 @@ class Connection : public SSLWrap<Connection>, public AsyncWrap { public: ~Connection() { #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB - sniObject_.Dispose(); - sniContext_.Dispose(); - servername_.Dispose(); + sniObject_.Reset(); + sniContext_.Reset(); + servername_.Reset(); #endif } diff --git a/src/node_dtrace.cc b/src/node_dtrace.cc index a4b5645d15..f0575b3890 100644 --- a/src/node_dtrace.cc +++ b/src/node_dtrace.cc @@ -324,7 +324,8 @@ void InitDTrace(Environment* env, Handle<Object> target) { for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) { Local<String> key = OneByteString(env->isolate(), tab[i].name); - Local<Value> val = FunctionTemplate::New(tab[i].func)->GetFunction(); + Local<Value> val = FunctionTemplate::New(env->isolate(), tab[i].func) + ->GetFunction(); target->Set(key, val); } diff --git a/src/node_file.cc b/src/node_file.cc index c860950e34..1d454abb3b 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -46,6 +46,7 @@ namespace node { using v8::Array; using v8::Context; +using v8::EscapableHandleScope; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -70,7 +71,7 @@ class FSReqWrap: public ReqWrap<uv_fs_t> { void* operator new(size_t size, char* storage) { return storage; } FSReqWrap(Environment* env, const char* syscall, char* data = NULL) - : ReqWrap<uv_fs_t>(env, Object::New()), + : ReqWrap<uv_fs_t>(env, Object::New(env->isolate())), syscall_(syscall), data_(data), dest_len_(0) { @@ -179,11 +180,11 @@ static void After(uv_fs_t *req) { break; case UV_FS_OPEN: - argv[1] = Integer::New(req->result, env->isolate()); + argv[1] = Integer::New(env->isolate(), req->result); break; case UV_FS_WRITE: - argv[1] = Integer::New(req->result, env->isolate()); + argv[1] = Integer::New(env->isolate(), req->result); break; case UV_FS_STAT: @@ -200,7 +201,7 @@ static void After(uv_fs_t *req) { case UV_FS_READ: // Buffer interface - argv[1] = Integer::New(req->result, env->isolate()); + argv[1] = Integer::New(env->isolate(), req->result); break; case UV_FS_READDIR: @@ -208,7 +209,7 @@ static void After(uv_fs_t *req) { char *namebuf = static_cast<char*>(req->ptr); int nnames = req->result; - Local<Array> names = Array::New(nnames); + Local<Array> names = Array::New(env->isolate(), nnames); for (int i = 0; i < nnames; i++) { Local<String> name = String::NewFromUtf8(env->isolate(), namebuf); @@ -326,11 +327,11 @@ Local<Object> BuildStatsObject(Environment* env, const uv_stat_t* s) { // If you hit this assertion, you forgot to enter the v8::Context first. assert(env->context() == env->isolate()->GetCurrentContext()); - HandleScope handle_scope(env->isolate()); + EscapableHandleScope handle_scope(env->isolate()); Local<Object> stats = env->stats_constructor_function()->NewInstance(); if (stats.IsEmpty()) { - return Local<Object>(); + return handle_scope.Escape(Local<Object>()); } // The code below is very nasty-looking but it prevents a segmentation fault @@ -346,9 +347,9 @@ Local<Object> BuildStatsObject(Environment* env, const uv_stat_t* s) { // and make sure that we bail out when V8 returns an empty handle. #define X(name) \ { \ - Local<Value> val = Integer::New(s->st_##name, env->isolate()); \ + Local<Value> val = Integer::New(env->isolate(), s->st_##name); \ if (val.IsEmpty()) \ - return Local<Object>(); \ + return handle_scope.Escape(Local<Object>()); \ stats->Set(env->name ## _string(), val); \ } X(dev) @@ -364,9 +365,10 @@ Local<Object> BuildStatsObject(Environment* env, const uv_stat_t* s) { #define X(name) \ { \ - Local<Value> val = Number::New(static_cast<double>(s->st_##name)); \ + Local<Value> val = Number::New(env->isolate(), \ + static_cast<double>(s->st_##name)); \ if (val.IsEmpty()) \ - return Local<Object>(); \ + return handle_scope.Escape(Local<Object>()); \ stats->Set(env->name ## _string(), val); \ } X(ino) @@ -380,9 +382,9 @@ Local<Object> BuildStatsObject(Environment* env, const uv_stat_t* s) { { \ double msecs = static_cast<double>(s->st_##rec.tv_sec) * 1000; \ msecs += static_cast<double>(s->st_##rec.tv_nsec / 1000000); \ - Local<Value> val = v8::Date::New(msecs); \ + Local<Value> val = v8::Date::New(env->isolate(), msecs); \ if (val.IsEmpty()) \ - return Local<Object>(); \ + return handle_scope.Escape(Local<Object>()); \ stats->Set(env->name ## _string(), val); \ } X(atime, atim) @@ -391,7 +393,7 @@ Local<Object> BuildStatsObject(Environment* env, const uv_stat_t* s) { X(birthtime, birthtim) #undef X - return handle_scope.Close(stats); + return handle_scope.Escape(stats); } static void Stat(const FunctionCallbackInfo<Value>& args) { @@ -685,7 +687,7 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) { assert(SYNC_REQ.result >= 0); char* namebuf = static_cast<char*>(SYNC_REQ.ptr); uint32_t nnames = SYNC_REQ.result; - Local<Array> names = Array::New(nnames); + Local<Array> names = Array::New(env->isolate(), nnames); for (uint32_t i = 0; i < nnames; ++i) { names->Set(i, String::NewFromUtf8(env->isolate(), namebuf)); @@ -1087,7 +1089,8 @@ void InitFs(Handle<Object> target, Environment* env = Environment::GetCurrent(context); // Initialize the stats object - Local<Function> constructor = FunctionTemplate::New()->GetFunction(); + Local<Function> constructor = + FunctionTemplate::New(env->isolate())->GetFunction(); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Stats"), constructor); env->set_stats_constructor_function(constructor); diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 7424f4b8bc..5fe4448cd0 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -243,7 +243,7 @@ class Parser : public BaseObject { if (!cb->IsFunction()) return 0; - Local<Object> message_info = Object::New(); + Local<Object> message_info = Object::New(env()->isolate()); if (have_flushed_) { // Slow case, flush remaining headers. @@ -259,22 +259,23 @@ class Parser : public BaseObject { // METHOD if (parser_.type == HTTP_REQUEST) { message_info->Set(env()->method_string(), - Uint32::NewFromUnsigned(parser_.method)); + Uint32::NewFromUnsigned(env()->isolate(), + parser_.method)); } // STATUS if (parser_.type == HTTP_RESPONSE) { message_info->Set(env()->status_code_string(), - Integer::New(parser_.status_code, env()->isolate())); + Integer::New(env()->isolate(), parser_.status_code)); message_info->Set(env()->status_message_string(), status_message_.ToString(env())); } // VERSION message_info->Set(env()->version_major_string(), - Integer::New(parser_.http_major, env()->isolate())); + Integer::New(env()->isolate(), parser_.http_major)); message_info->Set(env()->version_minor_string(), - Integer::New(parser_.http_minor, env()->isolate())); + Integer::New(env()->isolate(), parser_.http_minor)); message_info->Set(env()->should_keep_alive_string(), http_should_keep_alive(&parser_) ? @@ -308,8 +309,8 @@ class Parser : public BaseObject { Local<Value> argv[3] = { current_buffer_, - Integer::NewFromUnsigned(at - current_buffer_data_, env()->isolate()), - Integer::NewFromUnsigned(length, env()->isolate()) + Integer::NewFromUnsigned(env()->isolate(), at - current_buffer_data_), + Integer::NewFromUnsigned(env()->isolate(), length) }; Local<Value> r = cb.As<Function>()->Call(obj, ARRAY_SIZE(argv), argv); @@ -407,7 +408,7 @@ class Parser : public BaseObject { if (parser->got_exception_) return; - Local<Integer> nparsed_obj = Integer::New(nparsed, env->isolate()); + Local<Integer> nparsed_obj = Integer::New(env->isolate(), nparsed); // If there was a parse error in one of the callbacks // TODO(bnoordhuis) What if there is an error on EOF? if (!parser->parser_.upgrade && nparsed != buffer_len) { @@ -445,7 +446,7 @@ class Parser : public BaseObject { Local<Value> e = env->parse_error_string(); Local<Object> obj = e->ToObject(); - obj->Set(env->bytes_parsed_string(), Integer::New(0, env->isolate())); + obj->Set(env->bytes_parsed_string(), Integer::New(env->isolate(), 0)); obj->Set(env->code_string(), OneByteString(env->isolate(), http_errno_name(err))); @@ -485,7 +486,7 @@ class Parser : public BaseObject { Local<Array> CreateHeaders() { // num_values_ is either -1 or the entry # of the last header // so num_values_ == 0 means there's a single header - Local<Array> headers = Array::New(2 * num_values_); + Local<Array> headers = Array::New(env()->isolate(), 2 * num_values_); for (int i = 0; i < num_values_; ++i) { headers->Set(2 * i, fields_[i].ToString(env())); @@ -565,24 +566,25 @@ void InitHttpParser(Handle<Object> target, Handle<Context> context, void* priv) { Environment* env = Environment::GetCurrent(context); - Local<FunctionTemplate> t = FunctionTemplate::New(Parser::New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), + Parser::New); t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "HTTPParser")); t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "REQUEST"), - Integer::New(HTTP_REQUEST, env->isolate())); + Integer::New(env->isolate(), HTTP_REQUEST)); t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "RESPONSE"), - Integer::New(HTTP_RESPONSE, env->isolate())); + Integer::New(env->isolate(), HTTP_RESPONSE)); t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnHeaders"), - Integer::NewFromUnsigned(kOnHeaders, env->isolate())); + Integer::NewFromUnsigned(env->isolate(), kOnHeaders)); t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnHeadersComplete"), - Integer::NewFromUnsigned(kOnHeadersComplete, env->isolate())); + Integer::NewFromUnsigned(env->isolate(), kOnHeadersComplete)); t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnBody"), - Integer::NewFromUnsigned(kOnBody, env->isolate())); + Integer::NewFromUnsigned(env->isolate(), kOnBody)); t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnMessageComplete"), - Integer::NewFromUnsigned(kOnMessageComplete, env->isolate())); + Integer::NewFromUnsigned(env->isolate(), kOnMessageComplete)); - Local<Array> methods = Array::New(); + Local<Array> methods = Array::New(env->isolate()); #define V(num, name, string) \ methods->Set(num, FIXED_ONE_BYTE_STRING(env->isolate(), #string)); HTTP_METHOD_MAP(V) diff --git a/src/node_internals.h b/src/node_internals.h index 604f512f4a..9a6956f957 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -38,7 +38,7 @@ struct sockaddr; namespace node { -// If persistent.IsWeak() == false, then do not call persistent.Dispose() +// If persistent.IsWeak() == false, then do not call persistent.Reset() // while the returned Local<T> is still in scope, it will destroy the // reference to the object. template <class TypeName> diff --git a/src/node_object_wrap.h b/src/node_object_wrap.h index d387a2679c..445a9e66c3 100644 --- a/src/node_object_wrap.h +++ b/src/node_object_wrap.h @@ -40,7 +40,7 @@ class ObjectWrap { return; assert(persistent().IsNearDeath()); persistent().ClearWeak(); - persistent().Dispose(); + persistent().Reset(); } diff --git a/src/node_os.cc b/src/node_os.cc index 5de6049296..a7041aed7a 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -148,11 +148,11 @@ static void GetCPUInfo(const FunctionCallbackInfo<Value>& args) { if (err) return; - Local<Array> cpus = Array::New(); + Local<Array> cpus = Array::New(env->isolate()); for (i = 0; i < count; i++) { uv_cpu_info_t* ci = cpu_infos + i; - Local<Object> times_info = Object::New(); + Local<Object> times_info = Object::New(env->isolate()); times_info->Set(env->user_string(), Number::New(env->isolate(), ci->cpu_times.user)); times_info->Set(env->nice_string(), @@ -164,7 +164,7 @@ static void GetCPUInfo(const FunctionCallbackInfo<Value>& args) { times_info->Set(env->irq_string(), Number::New(env->isolate(), ci->cpu_times.irq)); - Local<Object> cpu_info = Object::New(); + Local<Object> cpu_info = Object::New(env->isolate()); cpu_info->Set(env->model_string(), OneByteString(env->isolate(), ci->model)); cpu_info->Set(env->speed_string(), @@ -214,10 +214,10 @@ static void GetLoadAvg(const FunctionCallbackInfo<Value>& args) { HandleScope scope(env->isolate()); double loadavg[3]; uv_loadavg(loadavg); - Local<Array> loads = Array::New(3); - loads->Set(0, Number::New(loadavg[0])); - loads->Set(1, Number::New(loadavg[1])); - loads->Set(2, Number::New(loadavg[2])); + Local<Array> loads = Array::New(env->isolate(), 3); + loads->Set(0, Number::New(env->isolate(), loadavg[0])); + loads->Set(1, Number::New(env->isolate(), loadavg[1])); + loads->Set(2, Number::New(env->isolate(), loadavg[2])); args.GetReturnValue().Set(loads); } @@ -236,7 +236,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) { int err = uv_interface_addresses(&interfaces, &count); - ret = Object::New(); + ret = Object::New(env->isolate()); if (err == UV_ENOSYS) { args.GetReturnValue().Set(ret); @@ -249,7 +249,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) { if (ret->Has(name)) { ifarr = Local<Array>::Cast(ret->Get(name)); } else { - ifarr = Array::New(); + ifarr = Array::New(env->isolate()); ret->Set(name, ifarr); } @@ -276,7 +276,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) { family = env->unknown_string(); } - o = Object::New(); + o = Object::New(env->isolate()); o->Set(env->address_string(), OneByteString(env->isolate(), ip)); o->Set(env->netmask_string(), OneByteString(env->isolate(), netmask)); o->Set(env->family_string(), family); @@ -284,7 +284,8 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) { if (interfaces[i].address.address4.sin_family == AF_INET6) { uint32_t scopeid = interfaces[i].address.address6.sin6_scope_id; - o->Set(env->scopeid_string(), Integer::NewFromUnsigned(scopeid)); + o->Set(env->scopeid_string(), + Integer::NewFromUnsigned(env->isolate(), scopeid)); } const bool internal = interfaces[i].is_internal; diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index 5d72d7c244..f88b422f4a 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -48,7 +48,8 @@ using v8::Value; void StatWatcher::Initialize(Environment* env, Handle<Object> target) { HandleScope scope(env->isolate()); - Local<FunctionTemplate> t = FunctionTemplate::New(StatWatcher::New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), + StatWatcher::New); t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "StatWatcher")); @@ -92,7 +93,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle, Local<Value> argv[] = { BuildStatsObject(env, curr), BuildStatsObject(env, prev), - Integer::New(status, env->isolate()) + Integer::New(env->isolate(), status) }; wrap->MakeCallback(env->onchange_string(), ARRAY_SIZE(argv), argv); } diff --git a/src/node_v8.cc b/src/node_v8.cc index 25f73d6183..6652f6176a 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -117,7 +117,7 @@ void Environment::AfterGarbageCollectionCallback(const GCInfo* before, const GCInfo* after) { HandleScope handle_scope(isolate()); Context::Scope context_scope(context()); - Local<Value> argv[] = { Object::New(), Object::New() }; + Local<Value> argv[] = { Object::New(isolate()), Object::New(isolate()) }; const GCInfo* infov[] = { before, after }; for (unsigned i = 0; i < ARRAY_SIZE(argv); i += 1) { Local<Object> obj = argv[i].As<Object>(); @@ -132,7 +132,7 @@ void Environment::AfterGarbageCollectionCallback(const GCInfo* before, default: UNREACHABLE(); } - obj->Set(flags_string(), Uint32::NewFromUnsigned(info->flags(), isolate())); + obj->Set(flags_string(), Uint32::NewFromUnsigned(isolate(), info->flags())); obj->Set(timestamp_string(), Number::New(isolate(), info->timestamp())); // TODO(trevnorris): Setting many object properties in C++ is a significant // performance hit. Redo this to pass the results to JS and create/set the @@ -140,7 +140,7 @@ void Environment::AfterGarbageCollectionCallback(const GCInfo* before, #define V(name) \ do { \ obj->Set(name ## _string(), \ - Uint32::NewFromUnsigned(info->stats()->name(), isolate())); \ + Uint32::NewFromUnsigned(isolate(), info->stats()->name())); \ } while (0) V(total_heap_size); V(total_heap_size_executable); @@ -185,12 +185,12 @@ void GetHeapStatistics(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(isolate); HeapStatistics s; isolate->GetHeapStatistics(&s); - Local<Object> info = Object::New(); + Local<Object> info = Object::New(isolate); // TODO(trevnorris): Setting many object properties in C++ is a significant // performance hit. Redo this to pass the results to JS and create/set the // properties there. #define V(name) \ - info->Set(env->name ## _string(), Uint32::NewFromUnsigned(s.name(), isolate)) + info->Set(env->name ## _string(), Uint32::NewFromUnsigned(isolate, s.name())) V(total_heap_size); V(total_heap_size_executable); V(total_physical_size); diff --git a/src/node_zlib.cc b/src/node_zlib.cc index db789e2132..81d98d17c9 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -225,14 +225,14 @@ class ZCtx : public AsyncWrap { static void AfterSync(ZCtx* ctx, const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope scope(env->isolate()); - Local<Integer> avail_out = Integer::New(ctx->strm_.avail_out, - env->isolate()); - Local<Integer> avail_in = Integer::New(ctx->strm_.avail_in, - env->isolate()); + Local<Integer> avail_out = Integer::New(env->isolate(), + ctx->strm_.avail_out); + Local<Integer> avail_in = Integer::New(env->isolate(), + ctx->strm_.avail_in); ctx->write_in_progress_ = false; - Local<Array> result = Array::New(2); + Local<Array> result = Array::New(env->isolate(), 2); result->Set(0, avail_in); result->Set(1, avail_out); args.GetReturnValue().Set(result); @@ -329,10 +329,10 @@ class ZCtx : public AsyncWrap { if (!CheckError(ctx)) return; - Local<Integer> avail_out = Integer::New(ctx->strm_.avail_out, - env->isolate()); - Local<Integer> avail_in = Integer::New(ctx->strm_.avail_in, - env->isolate()); + Local<Integer> avail_out = Integer::New(env->isolate(), + ctx->strm_.avail_out); + Local<Integer> avail_in = Integer::New(env->isolate(), + ctx->strm_.avail_in); ctx->write_in_progress_ = false; @@ -358,7 +358,7 @@ class ZCtx : public AsyncWrap { HandleScope scope(env->isolate()); Local<Value> args[2] = { OneByteString(env->isolate(), message), - Number::New(ctx->err_) + Number::New(env->isolate(), ctx->err_) }; ctx->MakeCallback(env->onerror_string(), ARRAY_SIZE(args), args); @@ -613,7 +613,7 @@ void InitZlib(Handle<Object> target, Handle<Context> context, void* priv) { Environment* env = Environment::GetCurrent(context); - Local<FunctionTemplate> z = FunctionTemplate::New(ZCtx::New); + Local<FunctionTemplate> z = FunctionTemplate::New(env->isolate(), ZCtx::New); z->InstanceTemplate()->SetInternalFieldCount(1); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 3f19601789..e8bfadb0fa 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -36,6 +36,7 @@ namespace node { using v8::Boolean; using v8::Context; +using v8::EscapableHandleScope; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -59,13 +60,13 @@ uv_pipe_t* PipeWrap::UVHandle() { Local<Object> PipeWrap::Instantiate(Environment* env) { - HandleScope handle_scope(env->isolate()); + EscapableHandleScope handle_scope(env->isolate()); assert(!env->pipe_constructor_template().IsEmpty()); Local<Function> constructor = env->pipe_constructor_template()->GetFunction(); assert(!constructor.IsEmpty()); Local<Object> instance = constructor->NewInstance(); assert(!instance.IsEmpty()); - return handle_scope.Close(instance); + return handle_scope.Escape(instance); } @@ -74,7 +75,7 @@ void PipeWrap::Initialize(Handle<Object> target, Handle<Context> context) { Environment* env = Environment::GetCurrent(context); - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Pipe")); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -147,7 +148,7 @@ void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) { PipeWrap* wrap = Unwrap<PipeWrap>(args.This()); - String::AsciiValue name(args[0]); + String::Utf8Value name(args[0]); int err = uv_pipe_bind(&wrap->handle_, *name); args.GetReturnValue().Set(err); } @@ -195,8 +196,8 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) { assert(pipe_wrap->persistent().IsEmpty() == false); Local<Value> argv[] = { - Integer::New(status, env->isolate()), - Undefined() + Integer::New(env->isolate(), status), + Undefined(env->isolate()) }; if (status != 0) { @@ -244,11 +245,11 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) { Local<Object> req_wrap_obj = req_wrap->object(); Local<Value> argv[5] = { - Integer::New(status, env->isolate()), + Integer::New(env->isolate(), status), wrap->object(), req_wrap_obj, - Boolean::New(readable), - Boolean::New(writable) + Boolean::New(env->isolate(), readable), + Boolean::New(env->isolate(), writable) }; req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); @@ -268,7 +269,7 @@ void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) { int err = uv_pipe_open(&wrap->handle_, fd); if (err != 0) - ThrowException(UVException(err, "uv_pipe_open")); + env->isolate()->ThrowException(UVException(err, "uv_pipe_open")); } @@ -282,7 +283,7 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) { assert(args[1]->IsString()); Local<Object> req_wrap_obj = args[0].As<Object>(); - String::AsciiValue name(args[1]); + String::Utf8Value name(args[1]); ConnectWrap* req_wrap = new ConnectWrap(env, req_wrap_obj, diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 31d0432e41..b1a34f6692 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -51,7 +51,8 @@ class ProcessWrap : public HandleWrap { Handle<Value> unused, Handle<Context> context) { Environment* env = Environment::GetCurrent(context); - Local<FunctionTemplate> constructor = FunctionTemplate::New(New); + Local<FunctionTemplate> constructor = FunctionTemplate::New(env->isolate(), + New); constructor->InstanceTemplate()->SetInternalFieldCount(1); constructor->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Process")); @@ -234,7 +235,7 @@ class ProcessWrap : public HandleWrap { if (err == 0) { assert(wrap->process_.data == wrap); wrap->object()->Set(env->pid_string(), - Integer::New(wrap->process_.pid, env->isolate())); + Integer::New(env->isolate(), wrap->process_.pid)); } if (options.args) { diff --git a/src/req_wrap.h b/src/req_wrap.h index 304b1a49a9..56d63eb711 100644 --- a/src/req_wrap.h +++ b/src/req_wrap.h @@ -53,7 +53,7 @@ class ReqWrap : public AsyncWrap { // Assert that someone has called Dispatched() assert(req_.data == this); assert(!persistent().IsEmpty()); - persistent().Dispose(); + persistent().Reset(); } // Call this after the req has been dispatched. diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc index 0e61ba63ea..4f69fc4bee 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -47,7 +47,8 @@ class SignalWrap : public HandleWrap { Handle<Value> unused, Handle<Context> context) { Environment* env = Environment::GetCurrent(context); - Local<FunctionTemplate> constructor = FunctionTemplate::New(New); + Local<FunctionTemplate> constructor = FunctionTemplate::New(env->isolate(), + New); constructor->InstanceTemplate()->SetInternalFieldCount(1); constructor->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Signal")); @@ -109,7 +110,7 @@ class SignalWrap : public HandleWrap { HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); - Local<Value> arg = Integer::New(signum, env->isolate()); + Local<Value> arg = Integer::New(env->isolate(), signum); wrap->MakeCallback(env->onsignal_string(), 1, &arg); } diff --git a/src/smalloc.cc b/src/smalloc.cc index 347d7035b9..6a812be51e 100644 --- a/src/smalloc.cc +++ b/src/smalloc.cc @@ -50,6 +50,7 @@ using v8::Persistent; using v8::RetainedObjectInfo; using v8::Uint32; using v8::Value; +using v8::WeakCallbackData; using v8::kExternalUnsignedByteArray; @@ -59,12 +60,11 @@ struct CallbackInfo { Persistent<Object> p_obj; }; -void TargetCallback(Isolate* isolate, - Persistent<Object>* target, - char* arg); +void TargetCallback(const WeakCallbackData<Object, char>& data); void TargetFreeCallback(Isolate* isolate, Persistent<Object>* target, - CallbackInfo* arg); + CallbackInfo* cb_info); +void TargetFreeCallback(const WeakCallbackData<Object, CallbackInfo>& data); // return size of external array type, or 0 if unrecognized @@ -270,7 +270,7 @@ void Alloc(Environment* env, assert(!obj->HasIndexedPropertiesInExternalArrayData()); Persistent<Object> p_obj(env->isolate(), obj); env->isolate()->AdjustAmountOfExternalAllocatedMemory(length); - p_obj.MakeWeak(data, TargetCallback); + p_obj.SetWeak(data, TargetCallback); p_obj.MarkIndependent(); p_obj.SetWrapperClassId(ALLOC_ID); size_t size = length / ExternalArraySize(type); @@ -278,11 +278,11 @@ void Alloc(Environment* env, } -void TargetCallback(Isolate* isolate, - Persistent<Object>* target, - char* data) { - HandleScope handle_scope(isolate); - Local<Object> obj = PersistentToLocal(isolate, *target); +void TargetCallback(const WeakCallbackData<Object, char>& data) { + HandleScope handle_scope(data.GetIsolate()); + char* info = data.GetParameter(); + + Local<Object> obj = data.GetValue(); size_t len = obj->GetIndexedPropertiesExternalArrayDataLength(); enum ExternalArrayType array_type = obj->GetIndexedPropertiesExternalArrayDataType(); @@ -290,11 +290,13 @@ void TargetCallback(Isolate* isolate, assert(array_size > 0); assert(array_size * len >= len); len *= array_size; - if (data != NULL && len > 0) { - isolate->AdjustAmountOfExternalAllocatedMemory(-len); - free(data); + if (info != NULL && len > 0) { + data.GetIsolate()->AdjustAmountOfExternalAllocatedMemory(-len); + free(info); } - (*target).Dispose(); + + // XXX: Persistent is no longer passed here + // persistent.Reset(); } @@ -377,11 +379,12 @@ void Alloc(Environment* env, cb_info->cb = fn; cb_info->hint = hint; cb_info->p_obj.Reset(env->isolate(), obj); - obj->SetHiddenValue(env->smalloc_p_string(), External::New(cb_info)); + obj->SetHiddenValue(env->smalloc_p_string(), + External::New(env->isolate(), cb_info)); env->isolate()->AdjustAmountOfExternalAllocatedMemory(length + sizeof(*cb_info)); - cb_info->p_obj.MakeWeak(cb_info, TargetFreeCallback); + cb_info->p_obj.SetWeak(cb_info, TargetFreeCallback); cb_info->p_obj.MarkIndependent(); cb_info->p_obj.SetWrapperClassId(ALLOC_ID); size_t size = length / ExternalArraySize(type); @@ -405,12 +408,18 @@ void TargetFreeCallback(Isolate* isolate, len *= array_size; } isolate->AdjustAmountOfExternalAllocatedMemory(-(len + sizeof(*cb_info))); - cb_info->p_obj.Dispose(); + cb_info->p_obj.Reset(); cb_info->cb(data, cb_info->hint); delete cb_info; } +void TargetFreeCallback(const WeakCallbackData<Object, CallbackInfo>& data) { + CallbackInfo* cb_info = data.GetParameter(); + TargetFreeCallback(data.GetIsolate(), &cb_info->p_obj, cb_info); +} + + void HasExternalData(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); args.GetReturnValue().Set(args[0]->IsObject() && @@ -495,7 +504,7 @@ void Initialize(Handle<Object> exports, NODE_SET_METHOD(exports, "hasExternalData", HasExternalData); exports->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kMaxLength"), - Uint32::NewFromUnsigned(kMaxLength, env->isolate())); + Uint32::NewFromUnsigned(env->isolate(), kMaxLength)); HeapProfiler* heap_profiler = env->isolate()->GetHeapProfiler(); heap_profiler->SetWrapperClassInfoProvider(ALLOC_ID, WrapperInfo); diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 9b67a602c3..73d821ae75 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -32,6 +32,7 @@ namespace node { using v8::Array; using v8::Context; +using v8::EscapableHandleScope; using v8::FunctionCallbackInfo; using v8::Handle; using v8::HandleScope; @@ -430,7 +431,7 @@ Environment* SyncProcessRunner::env() const { Local<Object> SyncProcessRunner::Run(Local<Value> options) { - HandleScope scope(env()->isolate()); + EscapableHandleScope scope(env()->isolate()); assert(lifecycle_ == kUninitialized); @@ -439,7 +440,7 @@ Local<Object> SyncProcessRunner::Run(Local<Value> options) { Local<Object> result = BuildResultObject(); - return scope.Close(result); + return scope.Escape(result); } @@ -644,12 +645,14 @@ void SyncProcessRunner::SetPipeError(int pipe_error) { Local<Object> SyncProcessRunner::BuildResultObject() { - HandleScope scope(env()->isolate()); + EscapableHandleScope scope(env()->isolate()); - Local<Object> js_result = Object::New(); + Local<Object> js_result = Object::New(env()->isolate()); - if (GetError() != 0) - js_result->Set(env()->error_string(), Integer::New(GetError())); + if (GetError() != 0) { + js_result->Set(env()->error_string(), + Integer::New(env()->isolate(), GetError())); + } if (exit_status_ >= 0) js_result->Set(env()->status_string(), @@ -662,7 +665,7 @@ Local<Object> SyncProcessRunner::BuildResultObject() { js_result->Set(env()->signal_string(), String::NewFromUtf8(env()->isolate(), signo_string(term_signal_))); else - js_result->Set(env()->signal_string(), Null()); + js_result->Set(env()->signal_string(), Null(env()->isolate())); if (exit_status_ >= 0) js_result->Set(env()->output_string(), BuildOutputArray()); @@ -672,7 +675,7 @@ Local<Object> SyncProcessRunner::BuildResultObject() { js_result->Set(env()->pid_string(), Number::New(env()->isolate(), uv_process_.pid)); - return scope.Close(js_result); + return scope.Escape(js_result); } @@ -680,18 +683,18 @@ Local<Array> SyncProcessRunner::BuildOutputArray() { assert(lifecycle_ >= kInitialized); assert(stdio_pipes_ != NULL); - HandleScope scope(env()->isolate()); - Local<Array> js_output = Array::New(stdio_count_); + EscapableHandleScope scope(env()->isolate()); + Local<Array> js_output = Array::New(env()->isolate(), stdio_count_); for (uint32_t i = 0; i < stdio_count_; i++) { SyncProcessStdioPipe* h = stdio_pipes_[i]; if (h != NULL && h->writable()) js_output->Set(i, h->GetOutputAsBuffer()); else - js_output->Set(i, Null()); + js_output->Set(i, Null(env()->isolate())); } - return scope.Close(js_output); + return scope.Escape(js_output); } diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 349b098b68..2ead49a4fb 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -41,6 +41,7 @@ namespace node { using v8::Array; using v8::Context; +using v8::EscapableHandleScope; using v8::FunctionCallbackInfo; using v8::Handle; using v8::HandleScope; @@ -83,7 +84,7 @@ void StreamWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) { void StreamWrap::UpdateWriteQueueSize() { HandleScope scope(env()->isolate()); Local<Integer> write_queue_size = - Integer::NewFromUnsigned(stream()->write_queue_size, env()->isolate()); + Integer::NewFromUnsigned(env()->isolate(), stream()->write_queue_size); object()->Set(env()->write_queue_size_string(), write_queue_size); } @@ -121,7 +122,7 @@ void StreamWrap::OnAlloc(uv_handle_t* handle, template <class WrapType, class UVType> static Local<Object> AcceptHandle(Environment* env, uv_stream_t* pipe) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); Local<Object> wrap_obj; UVType* handle; @@ -135,7 +136,7 @@ static Local<Object> AcceptHandle(Environment* env, uv_stream_t* pipe) { if (uv_accept(pipe, reinterpret_cast<uv_stream_t*>(handle))) abort(); - return scope.Close(wrap_obj); + return scope.Escape(wrap_obj); } @@ -238,7 +239,7 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) { if (msg != NULL) req_wrap_obj->Set(env->error_string(), OneByteString(env->isolate(), msg)); req_wrap_obj->Set(env->bytes_string(), - Integer::NewFromUnsigned(length, env->isolate())); + Integer::NewFromUnsigned(env->isolate(), length)); args.GetReturnValue().Set(err); } @@ -368,7 +369,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) { if (msg != NULL) req_wrap_obj->Set(env->error_string(), OneByteString(env->isolate(), msg)); req_wrap_obj->Set(env->bytes_string(), - Integer::NewFromUnsigned(data_size, env->isolate())); + Integer::NewFromUnsigned(env->isolate(), data_size)); args.GetReturnValue().Set(err); } @@ -526,10 +527,10 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) { wrap->callbacks()->AfterWrite(req_wrap); Local<Value> argv[] = { - Integer::New(status, env->isolate()), + Integer::New(env->isolate(), status), wrap->object(), req_wrap_obj, - Undefined() + Undefined(env->isolate()) }; const char* msg = wrap->callbacks()->Error(); @@ -577,7 +578,7 @@ void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) { Local<Object> req_wrap_obj = req_wrap->object(); Local<Value> argv[3] = { - Integer::New(status, env->isolate()), + Integer::New(env->isolate(), status), wrap->object(), req_wrap_obj }; @@ -690,9 +691,9 @@ void StreamWrapCallbacks::DoRead(uv_stream_t* handle, Context::Scope context_scope(env->context()); Local<Value> argv[] = { - Integer::New(nread, env->isolate()), - Undefined(), - Undefined() + Integer::New(env->isolate(), nread), + Undefined(env->isolate()), + Undefined(env->isolate()) }; if (nread < 0) { diff --git a/src/string_bytes.cc b/src/string_bytes.cc index cb8a537c71..a00abbf3bf 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -36,6 +36,7 @@ namespace node { +using v8::EscapableHandleScope; using v8::Handle; using v8::HandleScope; using v8::Isolate; @@ -66,35 +67,35 @@ class ExternString: public ResourceType { static Local<String> NewFromCopy(Isolate* isolate, const TypeName* data, size_t length) { - HandleScope scope(isolate); + EscapableHandleScope scope(isolate); if (length == 0) - return scope.Close(String::Empty(isolate)); + return scope.Escape(String::Empty(isolate)); TypeName* new_data = new TypeName[length]; memcpy(new_data, data, length * sizeof(*new_data)); - return scope.Close(ExternString<ResourceType, TypeName>::New(isolate, - new_data, - length)); + return scope.Escape(ExternString<ResourceType, TypeName>::New(isolate, + new_data, + length)); } // uses "data" for external resource, and will be free'd on gc static Local<String> New(Isolate* isolate, const TypeName* data, size_t length) { - HandleScope scope(isolate); + EscapableHandleScope scope(isolate); if (length == 0) - return scope.Close(String::Empty(isolate)); + return scope.Escape(String::Empty(isolate)); ExternString* h_str = new ExternString<ResourceType, TypeName>(isolate, data, length); - Local<String> str = String::NewExternal(h_str); + Local<String> str = String::NewExternal(isolate, h_str); isolate->AdjustAmountOfExternalAllocatedMemory(length); - return scope.Close(str); + return scope.Escape(str); } inline Isolate* isolate() const { return isolate_; } @@ -676,16 +677,16 @@ Local<Value> StringBytes::Encode(Isolate* isolate, const char* buf, size_t buflen, enum encoding encoding) { - HandleScope scope(isolate); + EscapableHandleScope scope(isolate); assert(buflen <= Buffer::kMaxLength); if (!buflen && encoding != BUFFER) - return scope.Close(String::Empty(isolate)); + return scope.Escape(String::Empty(isolate)); Local<String> val; switch (encoding) { case BUFFER: - return scope.Close(Buffer::New(buf, buflen)); + return scope.Escape(Buffer::New(buf, buflen)); case ASCII: if (contains_non_ascii(buf, buflen)) { @@ -767,7 +768,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate, break; } - return scope.Close(val); + return scope.Escape(val); } } // namespace node diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 66935e6b60..2ffe9cb465 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -37,6 +37,7 @@ namespace node { using v8::Context; +using v8::EscapableHandleScope; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -54,13 +55,13 @@ typedef class ReqWrap<uv_connect_t> ConnectWrap; Local<Object> TCPWrap::Instantiate(Environment* env) { - HandleScope handle_scope(env->isolate()); + EscapableHandleScope handle_scope(env->isolate()); assert(env->tcp_constructor_template().IsEmpty() == false); Local<Function> constructor = env->tcp_constructor_template()->GetFunction(); assert(constructor.IsEmpty() == false); Local<Object> instance = constructor->NewInstance(); assert(instance.IsEmpty() == false); - return handle_scope.Close(instance); + return handle_scope.Escape(instance); } @@ -69,7 +70,7 @@ void TCPWrap::Initialize(Handle<Object> target, Handle<Context> context) { Environment* env = Environment::GetCurrent(context); - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "TCP")); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -256,7 +257,7 @@ void TCPWrap::Bind(const FunctionCallbackInfo<Value>& args) { TCPWrap* wrap = Unwrap<TCPWrap>(args.This()); - String::AsciiValue ip_address(args[0]); + String::Utf8Value ip_address(args[0]); int port = args[1]->Int32Value(); sockaddr_in addr; @@ -277,7 +278,7 @@ void TCPWrap::Bind6(const FunctionCallbackInfo<Value>& args) { TCPWrap* wrap = Unwrap<TCPWrap>(args.This()); - String::AsciiValue ip6_address(args[0]); + String::Utf8Value ip6_address(args[0]); int port = args[1]->Int32Value(); sockaddr_in6 addr; @@ -319,8 +320,8 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) { assert(tcp_wrap->persistent().IsEmpty() == false); Local<Value> argv[2] = { - Integer::New(status, env->isolate()), - Undefined() + Integer::New(env->isolate(), status), + Undefined(env->isolate()) }; if (status == 0) { @@ -356,7 +357,7 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) { Local<Object> req_wrap_obj = req_wrap->object(); Local<Value> argv[5] = { - Integer::New(status, env->isolate()), + Integer::New(env->isolate(), status), wrap->object(), req_wrap_obj, v8::True(env->isolate()), @@ -380,7 +381,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) { assert(args[2]->Uint32Value()); Local<Object> req_wrap_obj = args[0].As<Object>(); - String::AsciiValue ip_address(args[1]); + String::Utf8Value ip_address(args[1]); int port = args[2]->Uint32Value(); sockaddr_in addr; @@ -414,7 +415,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) { assert(args[2]->Uint32Value()); Local<Object> req_wrap_obj = args[0].As<Object>(); - String::AsciiValue ip_address(args[1]); + String::Utf8Value ip_address(args[1]); int port = args[2]->Int32Value(); sockaddr_in6 addr; @@ -441,14 +442,14 @@ void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) { Local<Object> AddressToJS(Environment* env, const sockaddr* addr, Local<Object> info) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); char ip[INET6_ADDRSTRLEN]; const sockaddr_in *a4; const sockaddr_in6 *a6; int port; if (info.IsEmpty()) - info = Object::New(); + info = Object::New(env->isolate()); switch (addr->sa_family) { case AF_INET6: @@ -457,7 +458,7 @@ Local<Object> AddressToJS(Environment* env, port = ntohs(a6->sin6_port); info->Set(env->address_string(), OneByteString(env->isolate(), ip)); info->Set(env->family_string(), env->ipv6_string()); - info->Set(env->port_string(), Integer::New(port, env->isolate())); + info->Set(env->port_string(), Integer::New(env->isolate(), port)); break; case AF_INET: @@ -466,14 +467,14 @@ Local<Object> AddressToJS(Environment* env, port = ntohs(a4->sin_port); info->Set(env->address_string(), OneByteString(env->isolate(), ip)); info->Set(env->family_string(), env->ipv4_string()); - info->Set(env->port_string(), Integer::New(port, env->isolate())); + info->Set(env->port_string(), Integer::New(env->isolate(), port)); break; default: info->Set(env->address_string(), String::Empty(env->isolate())); } - return scope.Close(info); + return scope.Escape(info); } diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 13527433b1..a9d642461f 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -50,11 +50,12 @@ class TimerWrap : public HandleWrap { Handle<Value> unused, Handle<Context> context) { Environment* env = Environment::GetCurrent(context); - Local<FunctionTemplate> constructor = FunctionTemplate::New(New); + Local<FunctionTemplate> constructor = FunctionTemplate::New(env->isolate(), + New); constructor->InstanceTemplate()->SetInternalFieldCount(1); constructor->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "Timer")); constructor->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnTimeout"), - Integer::New(kOnTimeout, env->isolate())); + Integer::New(env->isolate(), kOnTimeout)); NODE_SET_METHOD(constructor, "now", Now); @@ -148,7 +149,7 @@ class TimerWrap : public HandleWrap { Environment* env = wrap->env(); HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); - Local<Value> argv[1] = { Integer::New(status, env->isolate()) }; + Local<Value> argv[1] = { Integer::New(env->isolate(), status) }; wrap->MakeCallback(kOnTimeout, ARRAY_SIZE(argv), argv); } diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index d3768e5185..fdc5a935af 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -39,6 +39,7 @@ using crypto::SSLWrap; using crypto::SecureContext; using v8::Boolean; using v8::Context; +using v8::EscapableHandleScope; using v8::Exception; using v8::Function; using v8::FunctionCallbackInfo; @@ -104,11 +105,11 @@ TLSCallbacks::~TLSCallbacks() { clear_in_ = NULL; sc_ = NULL; - sc_handle_.Dispose(); - persistent().Dispose(); + sc_handle_.Reset(); + persistent().Reset(); #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB - sni_context_.Dispose(); + sni_context_.Reset(); #endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB // Move all writes to pending @@ -408,7 +409,7 @@ const char* TLSCallbacks::PrintErrors() { Local<Value> TLSCallbacks::GetSSLError(int status, int* err, const char** msg) { - HandleScope scope(env()->isolate()); + EscapableHandleScope scope(env()->isolate()); *err = SSL_get_error(ssl_, status); switch (*err) { @@ -417,7 +418,7 @@ Local<Value> TLSCallbacks::GetSSLError(int status, int* err, const char** msg) { case SSL_ERROR_WANT_WRITE: break; case SSL_ERROR_ZERO_RETURN: - return scope.Close(env()->zero_return_string()); + return scope.Escape(env()->zero_return_string()); break; default: { @@ -434,7 +435,7 @@ Local<Value> TLSCallbacks::GetSSLError(int status, int* err, const char** msg) { *msg = buf; } - return scope.Close(exception); + return scope.Escape(exception); } } return Local<Value>(); @@ -457,7 +458,7 @@ void TLSCallbacks::ClearOut() { read = SSL_read(ssl_, out, sizeof(out)); if (read > 0) { Local<Value> argv[] = { - Integer::New(read, env()->isolate()), + Integer::New(env()->isolate(), read), Buffer::New(env(), out, read) }; wrap()->MakeCallback(env()->onread_string(), ARRAY_SIZE(argv), argv); @@ -467,7 +468,7 @@ void TLSCallbacks::ClearOut() { int flags = SSL_get_shutdown(ssl_); if (!eof_ && flags & SSL_RECEIVED_SHUTDOWN) { eof_ = true; - Local<Value> arg = Integer::New(UV_EOF, env()->isolate()); + Local<Value> arg = Integer::New(env()->isolate(), UV_EOF); wrap()->MakeCallback(env()->onread_string(), 1, &arg); } @@ -634,7 +635,7 @@ void TLSCallbacks::DoRead(uv_stream_t* handle, HandleScope handle_scope(env()->isolate()); Context::Scope context_scope(env()->context()); - Local<Value> arg = Integer::New(nread, env()->isolate()); + Local<Value> arg = Integer::New(env()->isolate(), nread); wrap()->MakeCallback(env()->onread_string(), 1, &arg); return; } @@ -794,7 +795,7 @@ int TLSCallbacks::SelectSNIContextCallback(SSL* s, int* ad, void* arg) { return SSL_TLSEXT_ERR_NOACK; } - p->sni_context_.Dispose(); + p->sni_context_.Reset(); p->sni_context_.Reset(env->isolate(), ctx); SecureContext* sc = Unwrap<SecureContext>(ctx.As<Object>()); @@ -812,7 +813,7 @@ void TLSCallbacks::Initialize(Handle<Object> target, NODE_SET_METHOD(target, "wrap", TLSCallbacks::Wrap); - Local<FunctionTemplate> t = FunctionTemplate::New(); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate()); t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap")); diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index cd6e319fc0..a3957bea23 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -53,7 +53,7 @@ void TTYWrap::Initialize(Handle<Object> target, Handle<Context> context) { Environment* env = Environment::GetCurrent(context); - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "TTY")); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -141,8 +141,8 @@ void TTYWrap::GetWindowSize(const FunctionCallbackInfo<Value>& args) { if (err == 0) { Local<v8::Array> a = args[0].As<Array>(); - a->Set(0, Integer::New(width, env->isolate())); - a->Set(1, Integer::New(height, env->isolate())); + a->Set(0, Integer::New(env->isolate(), width)); + a->Set(1, Integer::New(env->isolate(), height)); } args.GetReturnValue().Set(err); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 36ce93d63b..01ec324eb6 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -91,7 +91,7 @@ void UDPWrap::Initialize(Handle<Object> target, Handle<Context> context) { Environment* env = Environment::GetCurrent(context); - Local<FunctionTemplate> t = FunctionTemplate::New(New); + Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New); t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "UDP")); @@ -371,7 +371,7 @@ void UDPWrap::OnSend(uv_udp_send_t* req, int status) { Environment* env = req_wrap->env(); HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); - Local<Value> arg = Integer::New(status, env->isolate()); + Local<Value> arg = Integer::New(env->isolate(), status); req_wrap->MakeCallback(env->oncomplete_string(), 1, &arg); } delete req_wrap; @@ -410,7 +410,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle, Local<Object> wrap_obj = wrap->object(); Local<Value> argv[] = { - Integer::New(nread, env->isolate()), + Integer::New(env->isolate(), nread), wrap_obj, Undefined(env->isolate()), Undefined(env->isolate()) diff --git a/src/util.h b/src/util.h index 9545475cc4..e9634ce3d1 100644 --- a/src/util.h +++ b/src/util.h @@ -60,7 +60,7 @@ namespace node { #define UNREACHABLE() abort() -// If persistent.IsWeak() == false, then do not call persistent.Dispose() +// If persistent.IsWeak() == false, then do not call persistent.Reset() // while the returned Local<T> is still in scope, it will destroy the // reference to the object. template <class TypeName> @@ -71,7 +71,7 @@ inline v8::Local<TypeName> PersistentToLocal( // Unchecked conversion from a non-weak Persistent<T> to Local<TLocal<T>, // use with care! // -// Do not call persistent.Dispose() while the returned Local<T> is still in +// Do not call persistent.Reset() while the returned Local<T> is still in // scope, it will destroy the reference to the object. template <class TypeName> inline v8::Local<TypeName> StrongPersistentToLocal( @@ -54,10 +54,10 @@ void Initialize(Handle<Object> target, Handle<Context> context) { Environment* env = Environment::GetCurrent(context); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "errname"), - FunctionTemplate::New(ErrName)->GetFunction()); + FunctionTemplate::New(env->isolate(), ErrName)->GetFunction()); #define V(name, _) \ target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UV_" # name), \ - Integer::New(UV_ ## name, env->isolate())); + Integer::New(env->isolate(), UV_ ## name)); UV_ERRNO_MAP(V) #undef V } |