From: Fedor Indutny Date: Thu, 13 Mar 2014 16:38:14 +0000 (+0400) Subject: src: update to v8 3.24 APIs X-Git-Tag: v0.11.13~77 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ce04c726a31cd13be131915b1c8b8bc7a00a4d24;p=platform%2Fupstream%2Fnodejs.git src: update to v8 3.24 APIs --- diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 567b159..1b99869 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 HostentToAddresses(Environment* env, struct hostent* host) { - HandleScope scope(env->isolate()); - Local addresses = Array::New(); + EscapableHandleScope scope(env->isolate()); + Local 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 HostentToAddresses(Environment* env, struct hostent* host) { addresses->Set(i, address); } - return scope.Close(addresses); + return scope.Escape(addresses); } static Local HostentToNames(Environment* env, struct hostent* host) { - HandleScope scope(env->isolate()); - Local names = Array::New(); + EscapableHandleScope scope(env->isolate()); + Local names = Array::New(env->isolate()); for (uint32_t i = 0; host->h_aliases[i] != NULL; ++i) { Local 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 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 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 result = Array::New(1); + Local 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 mx_records = Array::New(); + Local mx_records = Array::New(env()->isolate()); Local exchange_symbol = env()->exchange_string(); Local priority_symbol = env()->priority_string(); ares_mx_reply* current = mx_start; for (uint32_t i = 0; current != NULL; ++i, current = current->next) { - Local mx_record = Object::New(); + Local 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 txt_records = Array::New(); + Local 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 srv_records = Array::New(); + Local srv_records = Array::New(env()->isolate()); Local name_symbol = env()->name_string(); Local port_symbol = env()->port_string(); Local 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 srv_record = Object::New(); + Local 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 naptr_records = Array::New(); + Local naptr_records = Array::New(env()->isolate()); Local flags_symbol = env()->flags_string(); Local service_symbol = env()->service_string(); Local 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 naptr_record = Object::New(); + Local 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 soa_record = Object::New(); + Local 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 addresses = HostentToAddresses(env(), host); - Local family = Integer::New(host->h_addrtype, env()->isolate()); + Local 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 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 results = Array::New(n); + Local results = Array::New(env->isolate(), n); char ip[INET6_ADDRSTRLEN]; const char *addr; @@ -947,7 +948,7 @@ static void IsIP(const FunctionCallbackInfo& 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& args) { HandleScope handle_scope(args.GetIsolate()); Environment* env = Environment::GetCurrent(args.GetIsolate()); - Local server_array = Array::New(); + Local server_array = Array::New(env->isolate()); ares_addr_node* servers; @@ -1160,11 +1161,11 @@ static void Initialize(Handle 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 bcc7995..9a6199d 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(isolate->GetData()); + return static_cast(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 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)); } diff --git a/src/env.h b/src/env.h index 73a810d..6a3b594 100644 --- a/src/env.h +++ b/src/env.h @@ -422,6 +422,8 @@ class Environment { #undef V private: + static const int kIsolateSlot = 0; + class GCInfo; class IsolateData; inline explicit Environment(v8::Local context); diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index ee28c44..9c1a2b6 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -83,7 +83,7 @@ void FSEventWrap::Initialize(Handle target, Handle context) { Environment* env = Environment::GetCurrent(context); - Local t = FunctionTemplate::New(New); + Local 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 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 3df1e49..245c0e1 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 0acdd22..61041ae 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 ErrnoException(Isolate* isolate, } Local 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 UVException(Isolate* isolate, Local 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 WinapiErrnoException(Isolate* isolate, } Local 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 MakeCallback(Isolate* isolate, const char* method, int argc, Handle argv[]) { - HandleScope handle_scope(isolate); + EscapableHandleScope handle_scope(isolate); Local 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::New(isolate, MakeCallback(env, recv, method, argc, argv))); } @@ -1163,11 +1164,12 @@ Handle MakeCallback(Isolate* isolate, Handle symbol, int argc, Handle argv[]) { - HandleScope handle_scope(isolate); + EscapableHandleScope handle_scope(isolate); Local 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::New(isolate, MakeCallback(env, recv, symbol, argc, argv))); } @@ -1176,12 +1178,13 @@ Handle MakeCallback(Isolate* isolate, Handle callback, int argc, Handle argv[]) { - HandleScope handle_scope(isolate); + EscapableHandleScope handle_scope(isolate); Local context = recv->CreationContext(); Environment* env = Environment::GetCurrent(context); Context::Scope context_scope(context); - return handle_scope.Close( - MakeCallback(env, recv.As(), callback, argc, argv)); + return handle_scope.Escape(Local::New( + isolate, + MakeCallback(env, recv.As(), callback, argc, argv))); } @@ -1192,9 +1195,10 @@ Handle MakeDomainCallback(Handle recv, Local 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::New( + env->isolate(), + MakeDomainCallback(env, recv, callback, argc, argv))); } @@ -1446,7 +1450,7 @@ static void ReportException(Environment* env, const TryCatch& try_catch) { static Local ExecuteString(Environment* env, Handle source, Handle 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 ExecuteString(Environment* env, exit(4); } - return scope.Close(result); + return scope.Escape(result); } static void GetActiveRequests(const FunctionCallbackInfo& args) { HandleScope scope(args.GetIsolate()); - Local ary = Array::New(); + Local ary = Array::New(args.GetIsolate()); QUEUE* q = NULL; int i = 0; @@ -1493,7 +1497,7 @@ void GetActiveHandles(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope scope(env->isolate()); - Local ary = Array::New(); + Local ary = Array::New(env->isolate()); QUEUE* q = NULL; int i = 0; @@ -1774,12 +1778,12 @@ static void GetGroups(const FunctionCallbackInfo& args) { return env->ThrowErrnoException(errno, "getgroups"); } - Local groups_list = Array::New(ngroups); + Local 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& 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& args) { env->isolate()->GetHeapStatistics(&v8_heap_stats); Local heap_total = - Integer::NewFromUnsigned(v8_heap_stats.total_heap_size(), env->isolate()); + Integer::NewFromUnsigned(env->isolate(), v8_heap_stats.total_heap_size()); Local heap_used = - Integer::NewFromUnsigned(v8_heap_stats.used_heap_size(), env->isolate()); + Integer::NewFromUnsigned(env->isolate(), v8_heap_stats.used_heap_size()); - Local info = Object::New(); + Local 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& args) { t -= (seconds * NANOS_PER_SEC) + nanos; } - Local 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 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& 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& 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& info) { while (environ[size]) size++; - Local envarr = Array::New(size); + Local 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& info) { WCHAR* environment = GetEnvironmentStringsW(); if (environment == NULL) return; // This should not happen. - Local envarr = Array::New(); + Local envarr = Array::New(env->isolate()); WCHAR* p = environment; int i = 0; while (*p != NULL) { @@ -2378,9 +2382,9 @@ static void EnvEnumerator(const PropertyCallbackInfo& info) { static Handle GetFeatures(Environment* env) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); - Local obj = Object::New(); + Local obj = Object::New(env->isolate()); #if defined(DEBUG) && DEBUG Local debug = True(env->isolate()); #else @@ -2408,9 +2412,9 @@ static Handle 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 versions = Object::New(); + Local 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 arguments = Array::New(argc); + Local 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 exec_arguments = Array::New(exec_argc); + Local 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 process_env_template = ObjectTemplate::New(); + Local process_env_template = + ObjectTemplate::New(env->isolate()); process_env_template->SetNamedPropertyHandler(EnvGetter, EnvSetter, EnvQuery, EnvDeleter, EnvEnumerator, - Object::New()); + Object::New(env->isolate())); Local 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 tick_info_obj = Object::New(); + Local 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 message = Object::New(); + Local message = Object::New(env->isolate()); message->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "cmd"), FIXED_ONE_BYTE_STRING(env->isolate(), "NODE_DEBUG_ENABLED")); Local argv[] = { @@ -3448,7 +3453,7 @@ int EmitExit(Environment* env) { Local 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 process_template = FunctionTemplate::New(); + Local process_template = FunctionTemplate::New(isolate); process_template->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "process")); Local 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 03cf155..417d1d8 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 t = v8::FunctionTemplate::New(callback); + v8::Local t = v8::FunctionTemplate::New(isolate, + callback); v8::Local fn = t->GetFunction(); v8::Local fn_name = v8::String::NewFromUtf8(isolate, name); fn->SetName(fn_name); @@ -208,7 +209,8 @@ inline void NODE_SET_PROTOTYPE_METHOD(v8::Handle recv, v8::FunctionCallback callback) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handle_scope(isolate); - v8::Local t = v8::FunctionTemplate::New(callback); + v8::Local 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 8304c4f..b1d63ad 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 obj) { Local New(Isolate* isolate, Handle string, enum encoding enc) { - HandleScope scope(isolate); + EscapableHandleScope scope(isolate); size_t length = StringBytes::Size(isolate, string, enc); @@ -125,25 +126,25 @@ Local New(Isolate* isolate, Handle 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 New(Isolate* isolate, size_t length) { - HandleScope handle_scope(isolate); + EscapableHandleScope handle_scope(isolate); Local 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 New(Environment* env, size_t length) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); assert(length <= kMaxLength); - Local arg = Uint32::NewFromUnsigned(length, env->isolate()); + Local arg = Uint32::NewFromUnsigned(env->isolate(), length); Local obj = env->buffer_constructor_function()->NewInstance(1, &arg); // TODO(trevnorris): done like this to handle HasInstance since only checks @@ -159,15 +160,15 @@ Local New(Environment* env, size_t length) { } smalloc::Alloc(env, obj, data, length); - return scope.Close(obj); + return scope.Escape(obj); } Local 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 obj = Buffer::New(env, data, length); - return handle_scope.Close(obj); + return handle_scope.Escape(obj); } @@ -175,11 +176,11 @@ Local 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 New(Environment* env, const char* data, size_t length) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); assert(length <= kMaxLength); - Local arg = Uint32::NewFromUnsigned(length, env->isolate()); + Local arg = Uint32::NewFromUnsigned(env->isolate(), length); Local obj = env->buffer_constructor_function()->NewInstance(1, &arg); // TODO(trevnorris): done like this to handle HasInstance since only checks @@ -197,7 +198,7 @@ Local 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 New(Isolate* isolate, smalloc::FreeCallback callback, void* hint) { Environment* env = Environment::GetCurrent(isolate); - HandleScope handle_scope(env->isolate()); + EscapableHandleScope handle_scope(env->isolate()); Local obj = Buffer::New(env, data, length, callback, hint); - return handle_scope.Close(obj); + return handle_scope.Escape(obj); } @@ -218,38 +219,38 @@ Local New(Environment* env, size_t length, smalloc::FreeCallback callback, void* hint) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); assert(length <= kMaxLength); - Local arg = Uint32::NewFromUnsigned(length, env->isolate()); + Local arg = Uint32::NewFromUnsigned(env->isolate(), length); Local 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 Use(Isolate* isolate, char* data, uint32_t length) { Environment* env = Environment::GetCurrent(isolate); - HandleScope handle_scope(env->isolate()); + EscapableHandleScope handle_scope(env->isolate()); Local obj = Buffer::Use(env, data, length); - return handle_scope.Close(obj); + return handle_scope.Escape(obj); } Local Use(Environment* env, char* data, uint32_t length) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); assert(length <= kMaxLength); - Local arg = Uint32::NewFromUnsigned(length, env->isolate()); + Local arg = Uint32::NewFromUnsigned(env->isolate(), length); Local 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& args) { memcpy(adata, obj_data, obj_length); - Local abuf = ArrayBuffer::New(adata, obj_length); + Local abuf = ArrayBuffer::New(env->isolate(), adata, obj_length); args.GetReturnValue().Set(abuf); } @@ -652,7 +653,7 @@ void SetupBufferJS(const FunctionCallbackInfo& 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& args) { Local internal = args[1].As(); internal->Set(env->byte_length_string(), - FunctionTemplate::New(ByteLength)->GetFunction()); + FunctionTemplate::New( + env->isolate(), ByteLength)->GetFunction()); } @@ -669,7 +671,8 @@ void Initialize(Handle target, Handle 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 05d2b11..df63ed4 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 sandbox_; Persistent 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); sandbox_.MarkIndependent(); references_++; // Allocation failure or maximum call stack size reached if (context_.IsEmpty()) return; - context_.MakeWeak(this, WeakCallback); + context_.SetWeak(this, WeakCallback); context_.MarkIndependent(); references_++; proxy_global_.Reset(env->isolate(), context()->Global()); - proxy_global_.MakeWeak(this, WeakCallback); + proxy_global_.SetWeak(this, WeakCallback); 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 CreateDataWrapper(Environment* env) { - HandleScope scope(env->isolate()); + EscapableHandleScope scope(env->isolate()); Local wrapper = env->script_data_constructor_function()->NewInstance(); if (wrapper.IsEmpty()) - return scope.Close(Handle()); + return scope.Escape(Local::New(env->isolate(), Handle())); Wrap(wrapper, this); - return scope.Close(wrapper); + return scope.Escape(wrapper); } Local CreateV8Context(Environment* env) { - HandleScope scope(env->isolate()); - Local function_template = FunctionTemplate::New(); + EscapableHandleScope scope(env->isolate()); + Local function_template = + FunctionTemplate::New(env->isolate()); function_template->SetHiddenPrototype(true); Local 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 target) { - Local function_template = FunctionTemplate::New(); + Local 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 hidden_context = External::New(context); + Local hidden_context = External::New(env->isolate(), context); sandbox->SetHiddenValue(hidden_name, hidden_context); } @@ -277,11 +287,16 @@ class ContextifyContext { } - template - static void WeakCallback(Isolate* isolate, - Persistent* target, - ContextifyContext* context) { - target->ClearWeak(); + template + static void WeakCallback(const WeakCallbackData& 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 class_name = FIXED_ONE_BYTE_STRING(env->isolate(), "ContextifyScript"); - Local script_tmpl = FunctionTemplate::New(New); + Local 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::GetCurrent(); + Local context = env->context(); Context::Scope context_scope(context); Local