From 0bba59028381c146b90411d43425a18415d85f98 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Mon, 18 Mar 2013 13:54:00 -0700 Subject: [PATCH] bindings: update api All compile time warnings about using deprecated APIs have been suppressed by updating node's API. Though there are still many function calls that can accept Isolate, and still need to be updated. node_isolate had to be added as an extern variable in node.h and node_object_wrap.h Also a couple small fixes for Error handling. Before v8 3.16.6 the error stack message was lazily written when it was needed, which allowed you to change the message after instantiation. Then the stack would be written with the new message the first time it was accessed. Though that has changed. Now it creates the stack message on instantiation. So setting a different message afterwards won't be displayed. This is not a complete fix for the problem. Getting error without any message isn't very useful. --- lib/fs.js | 3 ++- src/cares_wrap.cc | 4 ++-- src/fs_event_wrap.cc | 5 +++-- src/handle_wrap.cc | 10 ++++----- src/handle_wrap.h | 2 +- src/node.cc | 27 ++++++++++++----------- src/node.h | 8 ++++--- src/node_buffer.cc | 12 ++++++----- src/node_counters.cc | 2 +- src/node_crypto.cc | 38 +++++++++++++++++---------------- src/node_crypto.h | 10 ++++----- src/node_dtrace.cc | 2 +- src/node_file.cc | 3 ++- src/node_internals.h | 2 +- src/node_object_wrap.h | 28 +++++++++++++----------- src/node_script.cc | 13 +++++------ src/node_stat_watcher.cc | 2 +- src/node_zlib.cc | 10 +++++---- src/pipe_wrap.cc | 6 +++--- src/req_wrap.h | 4 ++-- src/slab_allocator.cc | 10 ++++----- src/stream_wrap.cc | 4 ++-- src/tcp_wrap.cc | 6 +++--- src/tty_wrap.cc | 2 +- src/udp_wrap.cc | 6 +++--- src/v8_typed_array.cc | 32 ++++++++++++++------------- test/message/error_exit.out | 2 +- test/message/stack_overflow.js | 2 ++ test/message/stack_overflow.out | 2 +- 29 files changed, 139 insertions(+), 118 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 3d37a648a7..e637e03f6d 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -63,7 +63,8 @@ function rethrow() { var backtrace = new Error; return function(err) { if (err) { - backtrace.message = err.message; + backtrace.stack = err.name + ': ' + err.message + + backtrace.stack.substr(backtrace.name.length); err = backtrace; throw err; } diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index b7ba82870f..fa6302b1b2 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -272,7 +272,7 @@ class QueryWrap { QueryWrap() { HandleScope scope; - object_ = Persistent::New(Object::New()); + object_ = Persistent::New(node_isolate, Object::New()); } virtual ~QueryWrap() { @@ -280,7 +280,7 @@ class QueryWrap { object_->Delete(oncomplete_sym); - object_.Dispose(); + object_.Dispose(node_isolate); object_.Clear(); } diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 7e3eb8c529..f85f12c812 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -74,7 +74,8 @@ void FSEventWrap::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "close", Close); target->Set(String::NewSymbol("FSEvent"), - Persistent::New(t)->GetFunction()); + Persistent::New(node_isolate, + t)->GetFunction()); } @@ -172,7 +173,7 @@ Handle FSEventWrap::Close(const Arguments& args) { // and legal, HandleWrap::Close() deals with them the same way. assert(!args.Holder().IsEmpty()); assert(args.Holder()->InternalFieldCount() > 0); - void* ptr = args.Holder()->GetPointerFromInternalField(0); + void* ptr = args.Holder()->GetAlignedPointerFromInternalField(0); FSEventWrap* wrap = static_cast(ptr); if (wrap == NULL || wrap->initialized_ == false) { diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 3f05c7d81b..99fb6bf853 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -84,7 +84,7 @@ Handle HandleWrap::Close(const Arguments& args) { HandleScope scope; HandleWrap *wrap = static_cast( - args.Holder()->GetPointerFromInternalField(0)); + args.Holder()->GetAlignedPointerFromInternalField(0)); // guard against uninitialized handle or double close if (wrap == NULL || wrap->handle__ == NULL) { @@ -115,8 +115,8 @@ HandleWrap::HandleWrap(Handle object, uv_handle_t* h) { HandleScope scope; assert(object_.IsEmpty()); assert(object->InternalFieldCount() > 0); - object_ = v8::Persistent::New(object); - object_->SetPointerInInternalField(0, this); + object_ = v8::Persistent::New(node_isolate, object); + object_->SetAlignedPointerInInternalField(0, this); ngx_queue_insert_tail(&handle_wrap_queue, &handle_wrap_queue_); } @@ -147,8 +147,8 @@ void HandleWrap::OnClose(uv_handle_t* handle) { MakeCallback(wrap->object_, close_sym, 0, NULL); } - wrap->object_->SetPointerInInternalField(0, NULL); - wrap->object_.Dispose(); + wrap->object_->SetAlignedPointerInInternalField(0, NULL); + wrap->object_.Dispose(node_isolate); wrap->object_.Clear(); delete wrap; diff --git a/src/handle_wrap.h b/src/handle_wrap.h index dbefc2a114..7c88a61d87 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -50,7 +50,7 @@ namespace node { assert(!args.Holder().IsEmpty()); \ assert(args.Holder()->InternalFieldCount() > 0); \ type* wrap = static_cast( \ - args.Holder()->GetPointerFromInternalField(0)); + args.Holder()->GetAlignedPointerFromInternalField(0)); class HandleWrap { public: diff --git a/src/node.cc b/src/node.cc index e17baec825..a8587deb5a 100644 --- a/src/node.cc +++ b/src/node.cc @@ -195,7 +195,7 @@ static void Spin(uv_idle_t* handle, int status) { abort(); } Local cb = cb_v.As(); - process_tickFromSpinner = Persistent::New(cb); + process_tickFromSpinner = Persistent::New(node_isolate, cb); } TryCatch try_catch; @@ -912,7 +912,7 @@ MakeDomainCallback(const Handle object, abort(); } Local cb = cb_v.As(); - process_tickDomainCallback = Persistent::New(cb); + process_tickDomainCallback = Persistent::New(node_isolate, cb); } // lazy load domain specific symbols @@ -1002,7 +1002,7 @@ MakeCallback(const Handle object, abort(); } Local cb = cb_v.As(); - process_tickCallback = Persistent::New(cb); + process_tickCallback = Persistent::New(node_isolate, cb); } TryCatch try_catch; @@ -1802,7 +1802,7 @@ v8::Handle MemoryUsage(const v8::Arguments& args) { // V8 memory usage HeapStatistics v8_heap_stats; - V8::GetHeapStatistics(&v8_heap_stats); + node_isolate->GetHeapStatistics(&v8_heap_stats); info->Set(heap_total_symbol, Integer::NewFromUnsigned(v8_heap_stats.total_heap_size())); info->Set(heap_used_symbol, @@ -2021,7 +2021,7 @@ static Handle Binding(const Arguments& args) { node_module_struct* modp; if (binding_cache.IsEmpty()) { - binding_cache = Persistent::New(Object::New()); + binding_cache = Persistent::New(node_isolate, Object::New()); } Local exports; @@ -2307,7 +2307,8 @@ Handle SetupProcessObject(int argc, char *argv[]) { process_template->SetClassName(String::NewSymbol("process")); - process = Persistent::New(process_template->GetFunction()->NewInstance()); + process = Persistent::New(node_isolate, + process_template->GetFunction()->NewInstance()); process->SetAccessor(String::New("title"), ProcessTitleGetter, @@ -2317,7 +2318,7 @@ Handle SetupProcessObject(int argc, char *argv[]) { process->Set(String::NewSymbol("version"), String::New(NODE_VERSION)); // process.moduleLoadList - module_load_list = Persistent::New(Array::New()); + module_load_list = Persistent::New(node_isolate, Array::New()); process->Set(String::NewSymbol("moduleLoadList"), module_load_list); // process.versions @@ -2984,6 +2985,10 @@ char** Init(int argc, char *argv[]) { } V8::SetFlagsFromCommandLine(&v8argc, v8argv, false); + // Fetch a reference to the main isolate, so we have a reference to it + // even when we need it to access it from another (debugger) thread. + node_isolate = Isolate::GetCurrent(); + #ifdef __POSIX__ // Ignore SIGPIPE RegisterSignalHandler(SIGPIPE, SIG_IGN); @@ -2999,10 +3004,6 @@ char** Init(int argc, char *argv[]) { V8::SetFatalErrorHandler(node::OnFatalError); - // Fetch a reference to the main isolate, so we have a reference to it - // even when we need it to access it from another (debugger) thread. - node_isolate = Isolate::GetCurrent(); - // If the --debug flag was specified then initialize the debug thread. if (use_debug_agent) { EnableDebug(debug_wait_connect); @@ -3111,7 +3112,7 @@ int Start(int argc, char *argv[]) { V8::Initialize(); { - Locker locker; + Locker locker(node_isolate); HandleScope handle_scope; // Create the one and only Context. @@ -3137,7 +3138,7 @@ int Start(int argc, char *argv[]) { RunAtExit(); #ifndef NDEBUG - context.Dispose(); + context.Dispose(node_isolate); #endif } diff --git a/src/node.h b/src/node.h index 5769a7b9ce..d01dc40adc 100644 --- a/src/node.h +++ b/src/node.h @@ -86,6 +86,8 @@ namespace node { +extern v8::Isolate* node_isolate; + NODE_EXTERN extern bool no_deprecation; NODE_EXTERN int Start(int argc, char *argv[]); @@ -96,7 +98,7 @@ void Load(v8::Handle process); void EmitExit(v8::Handle process); #define NODE_PSYMBOL(s) \ - v8::Persistent::New(v8::String::NewSymbol(s)) + v8::Persistent::New(node_isolate, v8::String::NewSymbol(s)) /* Converts a unixtime to V8 Date */ #define NODE_UNIXTIME_V8(t) v8::Date::New(1000*static_cast(t)) @@ -153,7 +155,7 @@ v8::Local BuildStatsObject(const uv_statbuf_t* s); static inline v8::Persistent* cb_persist( const v8::Local &v) { v8::Persistent *fn = new v8::Persistent(); - *fn = v8::Persistent::New(v8::Local::Cast(v)); + *fn = v8::Persistent::New(node_isolate, v8::Local::Cast(v)); return fn; } @@ -165,7 +167,7 @@ static inline v8::Persistent* cb_unwrap(void *data) { } static inline void cb_destroy(v8::Persistent * cb) { - cb->Dispose(); + cb->Dispose(node_isolate); delete cb; } diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 21960f8852..55cf91d1cb 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -187,7 +187,7 @@ Buffer::Buffer(Handle wrapper, size_t length) : ObjectWrap() { length_ = 0; callback_ = NULL; - handle_.SetWrapperClassId(BUFFER_CLASS_ID); + handle_.SetWrapperClassId(node_isolate, BUFFER_CLASS_ID); Replace(NULL, length, NULL, NULL); } @@ -208,7 +208,7 @@ void Buffer::Replace(char *data, size_t length, callback_(data_, callback_hint_); } else if (length_) { delete [] data_; - V8::AdjustAmountOfExternalAllocatedMemory( + node_isolate->AdjustAmountOfExternalAllocatedMemory( -static_cast(sizeof(Buffer) + length_)); } @@ -222,7 +222,8 @@ void Buffer::Replace(char *data, size_t length, data_ = new char[length_]; if (data) memcpy(data_, data, length_); - V8::AdjustAmountOfExternalAllocatedMemory(sizeof(Buffer) + length_); + node_isolate->AdjustAmountOfExternalAllocatedMemory(sizeof(Buffer) + + length_); } else { data_ = NULL; } @@ -1039,7 +1040,8 @@ bool Buffer::HasInstance(Handle val) { Handle SetFastBufferConstructor(const Arguments& args) { assert(args[0]->IsFunction()); - fast_buffer_constructor = Persistent::New(args[0].As()); + fast_buffer_constructor = Persistent::New(node_isolate, + args[0].As()); return Undefined(); } @@ -1117,7 +1119,7 @@ void Buffer::Initialize(Handle target) { chars_written_sym = NODE_PSYMBOL("_charsWritten"); Local t = FunctionTemplate::New(Buffer::New); - constructor_template = Persistent::New(t); + constructor_template = Persistent::New(node_isolate, t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("SlowBuffer")); diff --git a/src/node_counters.cc b/src/node_counters.cc index 3c8d49c00b..c5726842a6 100644 --- a/src/node_counters.cc +++ b/src/node_counters.cc @@ -122,7 +122,7 @@ void InitPerfCounters(Handle target) { }; for (int i = 0; i < ARRAY_SIZE(tab); i++) { - tab[i].templ = Persistent::New( + tab[i].templ = Persistent::New(node_isolate, FunctionTemplate::New(tab[i].func)); target->Set(String::NewSymbol(tab[i].name), tab[i].templ->GetFunction()); } diff --git a/src/node_crypto.cc b/src/node_crypto.cc index bc8d6db3b2..ff5848fac7 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -141,7 +141,8 @@ void SecureContext::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(SecureContext::New); - secure_context_constructor = Persistent::New(t); + secure_context_constructor = Persistent::New(node_isolate, + t); t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(String::NewSymbol("SecureContext")); @@ -1094,7 +1095,7 @@ int Connection::SelectNextProtoCallback_(SSL *s, // Release old protocol handler if present if (!p->selectedNPNProto_.IsEmpty()) { - p->selectedNPNProto_.Dispose(); + p->selectedNPNProto_.Dispose(node_isolate); } if (p->npnProtos_.IsEmpty()) { @@ -1104,7 +1105,7 @@ int Connection::SelectNextProtoCallback_(SSL *s, *outlen = 8; // set status unsupported - p->selectedNPNProto_ = Persistent::New(False()); + p->selectedNPNProto_ = Persistent::New(node_isolate, False()); return SSL_TLSEXT_ERR_OK; } @@ -1117,15 +1118,15 @@ int Connection::SelectNextProtoCallback_(SSL *s, switch (status) { case OPENSSL_NPN_UNSUPPORTED: - p->selectedNPNProto_ = Persistent::New(Null()); + p->selectedNPNProto_ = Persistent::New(node_isolate, Null()); break; case OPENSSL_NPN_NEGOTIATED: - p->selectedNPNProto_ = Persistent::New(String::New( + p->selectedNPNProto_ = Persistent::New(node_isolate, String::New( reinterpret_cast(*out), *outlen )); break; case OPENSSL_NPN_NO_OVERLAP: - p->selectedNPNProto_ = Persistent::New(False()); + p->selectedNPNProto_ = Persistent::New(node_isolate, False()); break; default: break; @@ -1145,14 +1146,15 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) { if (servername) { if (!p->servername_.IsEmpty()) { - p->servername_.Dispose(); + p->servername_.Dispose(node_isolate); } - p->servername_ = Persistent::New(String::New(servername)); + p->servername_ = Persistent::New(node_isolate, + String::New(servername)); // Call the SNI callback and use its return value as context if (!p->sniObject_.IsEmpty()) { if (!p->sniContext_.IsEmpty()) { - p->sniContext_.Dispose(); + p->sniContext_.Dispose(node_isolate); } // Get callback init args @@ -1166,7 +1168,7 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) { // If ret is SecureContext if (secure_context_constructor->HasInstance(ret)) { - p->sniContext_ = Persistent::New(ret); + p->sniContext_ = Persistent::New(node_isolate, ret); SecureContext *sc = ObjectWrap::Unwrap( Local::Cast(ret)); SSL_set_SSL_CTX(s, sc->ctx_); @@ -1993,9 +1995,9 @@ Handle Connection::SetNPNProtocols(const Arguments& args) { // Release old handle if (!ss->npnProtos_.IsEmpty()) { - ss->npnProtos_.Dispose(); + ss->npnProtos_.Dispose(node_isolate); } - ss->npnProtos_ = Persistent::New(args[0]->ToObject()); + ss->npnProtos_ = Persistent::New(node_isolate, args[0]->ToObject()); return True(); }; @@ -2026,9 +2028,9 @@ Handle Connection::SetSNICallback(const Arguments& args) { // Release old handle if (!ss->sniObject_.IsEmpty()) { - ss->sniObject_.Dispose(); + ss->sniObject_.Dispose(node_isolate); } - ss->sniObject_ = Persistent::New(Object::New()); + ss->sniObject_ = Persistent::New(node_isolate, Object::New()); ss->sniObject_->Set(String::New("onselect"), args[0]); return True(); @@ -3294,7 +3296,7 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) { Persistent obj = req->obj; EIO_PBKDF2After(req, argv); MakeCallback(obj, "ondone", ARRAY_SIZE(argv), argv); - obj.Dispose(); + obj.Dispose(node_isolate); } @@ -3372,7 +3374,7 @@ Handle PBKDF2(const Arguments& args) { req->keylen = keylen; if (args[4]->IsFunction()) { - req->obj = Persistent::New(Object::New()); + req->obj = Persistent::New(node_isolate, Object::New()); req->obj->Set(String::New("ondone"), args[4]); uv_queue_work(uv_default_loop(), &req->work_req, @@ -3406,7 +3408,7 @@ struct RandomBytesRequest { RandomBytesRequest::~RandomBytesRequest() { if (obj_.IsEmpty()) return; - obj_.Dispose(); + obj_.Dispose(node_isolate); obj_.Clear(); } @@ -3492,7 +3494,7 @@ Handle RandomBytes(const Arguments& args) { req->size_ = size; if (args[1]->IsFunction()) { - req->obj_ = Persistent::New(Object::New()); + req->obj_ = Persistent::New(node_isolate, Object::New()); req->obj_->Set(String::New("ondone"), args[1]); uv_queue_work(uv_default_loop(), diff --git a/src/node_crypto.h b/src/node_crypto.h index 825823e854..0ceb1f69c9 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -249,14 +249,14 @@ class Connection : ObjectWrap { } #ifdef OPENSSL_NPN_NEGOTIATED - if (!npnProtos_.IsEmpty()) npnProtos_.Dispose(); - if (!selectedNPNProto_.IsEmpty()) selectedNPNProto_.Dispose(); + if (!npnProtos_.IsEmpty()) npnProtos_.Dispose(node_isolate); + if (!selectedNPNProto_.IsEmpty()) selectedNPNProto_.Dispose(node_isolate); #endif #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB - if (!sniObject_.IsEmpty()) sniObject_.Dispose(); - if (!sniContext_.IsEmpty()) sniContext_.Dispose(); - if (!servername_.IsEmpty()) servername_.Dispose(); + if (!sniObject_.IsEmpty()) sniObject_.Dispose(node_isolate); + if (!sniContext_.IsEmpty()) sniContext_.Dispose(node_isolate); + if (!servername_.IsEmpty()) servername_.Dispose(node_isolate); #endif } diff --git a/src/node_dtrace.cc b/src/node_dtrace.cc index df42af2a97..534b3b9670 100644 --- a/src/node_dtrace.cc +++ b/src/node_dtrace.cc @@ -373,7 +373,7 @@ void InitDTrace(Handle target) { }; for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) { - tab[i].templ = Persistent::New( + tab[i].templ = Persistent::New(node_isolate, FunctionTemplate::New(tab[i].func)); target->Set(String::NewSymbol(tab[i].name), tab[i].templ->GetFunction()); } diff --git a/src/node_file.cc b/src/node_file.cc index c4441bd125..52a300a18c 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -954,7 +954,8 @@ void InitFs(Handle target) { HandleScope scope; // Initialize the stats object Local stat_templ = FunctionTemplate::New(); - stats_constructor_template = Persistent::New(stat_templ); + stats_constructor_template = Persistent::New(node_isolate, + stat_templ); target->Set(String::NewSymbol("Stats"), stats_constructor_template->GetFunction()); File::Initialize(target); diff --git a/src/node_internals.h b/src/node_internals.h index 10b1742fb5..794770874e 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -99,7 +99,7 @@ inline static v8::Handle ThrowRangeError(const char* errmsg) { assert(!args.Holder().IsEmpty()); \ assert(args.Holder()->InternalFieldCount() > 0); \ type* wrap = static_cast( \ - args.Holder()->GetPointerFromInternalField(0)); \ + args.Holder()->GetAlignedPointerFromInternalField(0)); \ if (!wrap) { \ fprintf(stderr, #type ": Aborting due to unwrap failure at %s:%d\n", \ __FILE__, __LINE__); \ diff --git a/src/node_object_wrap.h b/src/node_object_wrap.h index c7fa3eb9ba..4f86da3f3a 100644 --- a/src/node_object_wrap.h +++ b/src/node_object_wrap.h @@ -37,6 +37,8 @@ namespace node { +extern v8::Isolate* node_isolate; + class NODE_EXTERN ObjectWrap { public: ObjectWrap ( ) { @@ -46,10 +48,10 @@ class NODE_EXTERN ObjectWrap { virtual ~ObjectWrap ( ) { if (!handle_.IsEmpty()) { - assert(handle_.IsNearDeath()); - handle_.ClearWeak(); + assert(handle_.IsNearDeath(node_isolate)); + handle_.ClearWeak(node_isolate); handle_->SetInternalField(0, v8::Undefined()); - handle_.Dispose(); + handle_.Dispose(node_isolate); handle_.Clear(); } } @@ -59,7 +61,7 @@ class NODE_EXTERN ObjectWrap { static inline T* Unwrap (v8::Handle handle) { assert(!handle.IsEmpty()); assert(handle->InternalFieldCount() > 0); - return static_cast(handle->GetPointerFromInternalField(0)); + return static_cast(handle->GetAlignedPointerFromInternalField(0)); } @@ -69,15 +71,15 @@ class NODE_EXTERN ObjectWrap { inline void Wrap (v8::Handle handle) { assert(handle_.IsEmpty()); assert(handle->InternalFieldCount() > 0); - handle_ = v8::Persistent::New(handle); - handle_->SetPointerInInternalField(0, this); + handle_ = v8::Persistent::New(node_isolate, handle); + handle_->SetAlignedPointerInInternalField(0, this); MakeWeak(); } inline void MakeWeak (void) { - handle_.MakeWeak(this, WeakCallback); - handle_.MarkIndependent(); + handle_.MakeWeak(node_isolate, this, WeakCallback); + handle_.MarkIndependent(node_isolate); } /* Ref() marks the object as being attached to an event loop. @@ -87,7 +89,7 @@ class NODE_EXTERN ObjectWrap { virtual void Ref() { assert(!handle_.IsEmpty()); refs_++; - handle_.ClearWeak(); + handle_.ClearWeak(node_isolate); } /* Unref() marks an object as detached from the event loop. This is its @@ -101,7 +103,7 @@ class NODE_EXTERN ObjectWrap { */ virtual void Unref() { assert(!handle_.IsEmpty()); - assert(!handle_.IsWeak()); + assert(!handle_.IsWeak(node_isolate)); assert(refs_ > 0); if (--refs_ == 0) { MakeWeak(); } } @@ -111,13 +113,15 @@ class NODE_EXTERN ObjectWrap { private: - static void WeakCallback (v8::Persistent value, void *data) { + static void WeakCallback(v8::Isolate* env, + v8::Persistent value, + void* data) { v8::HandleScope scope; ObjectWrap *obj = static_cast(data); assert(value == obj->handle_); assert(!obj->refs_); - assert(value.IsNearDeath()); + assert(value.IsNearDeath(env)); delete obj; } }; diff --git a/src/node_script.cc b/src/node_script.cc index 15c56122c7..ca7b9404a7 100644 --- a/src/node_script.cc +++ b/src/node_script.cc @@ -124,7 +124,8 @@ void CloneObject(Handle recv, })" ), String::New("binding:script"))->Run() ); - cloneObjectMethod = Persistent::New(cloneObjectMethod_); + cloneObjectMethod = Persistent::New(node_isolate, + cloneObjectMethod_); } cloneObjectMethod->Call(recv, 2, args); @@ -135,7 +136,7 @@ void WrappedContext::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(WrappedContext::New); - constructor_template = Persistent::New(t); + constructor_template = Persistent::New(node_isolate, t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("Context")); @@ -165,7 +166,7 @@ WrappedContext::WrappedContext() : ObjectWrap() { WrappedContext::~WrappedContext() { - context_.Dispose(); + context_.Dispose(node_isolate); } @@ -187,7 +188,7 @@ void WrappedScript::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(WrappedScript::New); - constructor_template = Persistent::New(t); + constructor_template = Persistent::New(node_isolate, t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); // Note: We use 'NodeScript' instead of 'Script' so that we do not // conflict with V8's Script class defined in v8/src/messages.js @@ -247,7 +248,7 @@ Handle WrappedScript::New(const Arguments& args) { WrappedScript::~WrappedScript() { - script_.Dispose(); + script_.Dispose(node_isolate); } @@ -364,7 +365,7 @@ Handle WrappedScript::EvalMachine(const Arguments& args) { // that when this function exits the context will be disposed. Persistent tmp = Context::New(); context = Local::New(tmp); - tmp.Dispose(); + tmp.Dispose(node_isolate); } else if (context_flag == userContext) { // Use the passed in context diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index c3f668c086..4eaad499de 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -38,7 +38,7 @@ void StatWatcher::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(StatWatcher::New); - constructor_template = Persistent::New(t); + constructor_template = Persistent::New(node_isolate, t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("StatWatcher")); diff --git a/src/node_zlib.cc b/src/node_zlib.cc index ebaba6bb11..d15f371b54 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -89,11 +89,11 @@ class ZCtx : public ObjectWrap { if (mode_ == DEFLATE || mode_ == GZIP || mode_ == DEFLATERAW) { (void)deflateEnd(&strm_); - V8::AdjustAmountOfExternalAllocatedMemory(-kDeflateContextSize); + node_isolate->AdjustAmountOfExternalAllocatedMemory(-kDeflateContextSize); } else if (mode_ == INFLATE || mode_ == GUNZIP || mode_ == INFLATERAW || mode_ == UNZIP) { (void)inflateEnd(&strm_); - V8::AdjustAmountOfExternalAllocatedMemory(-kInflateContextSize); + node_isolate->AdjustAmountOfExternalAllocatedMemory(-kInflateContextSize); } mode_ = NONE; @@ -406,14 +406,16 @@ class ZCtx : public ObjectWrap { ctx->windowBits_, ctx->memLevel_, ctx->strategy_); - V8::AdjustAmountOfExternalAllocatedMemory(kDeflateContextSize); + node_isolate-> + AdjustAmountOfExternalAllocatedMemory(kDeflateContextSize); break; case INFLATE: case GUNZIP: case INFLATERAW: case UNZIP: ctx->err_ = inflateInit2(&ctx->strm_, ctx->windowBits_); - V8::AdjustAmountOfExternalAllocatedMemory(kInflateContextSize); + node_isolate-> + AdjustAmountOfExternalAllocatedMemory(kInflateContextSize); break; default: assert(0 && "wtf?"); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 3952a0799c..6d651b8820 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -69,7 +69,7 @@ Local PipeWrap::Instantiate() { PipeWrap* PipeWrap::Unwrap(Local obj) { assert(!obj.IsEmpty()); assert(obj->InternalFieldCount() > 0); - return static_cast(obj->GetPointerFromInternalField(0)); + return static_cast(obj->GetAlignedPointerFromInternalField(0)); } @@ -114,7 +114,7 @@ void PipeWrap::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "setPendingInstances", SetPendingInstances); #endif - pipeConstructor = Persistent::New(t->GetFunction()); + pipeConstructor = Persistent::New(node_isolate, t->GetFunction()); target->Set(String::NewSymbol("Pipe"), pipeConstructor); } @@ -214,7 +214,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) { // Unwrap the client javascript object. assert(client_obj->InternalFieldCount() > 0); PipeWrap* client_wrap = - static_cast(client_obj->GetPointerFromInternalField(0)); + static_cast(client_obj->GetAlignedPointerFromInternalField(0)); if (uv_accept(handle, (uv_stream_t*)&client_wrap->handle_)) return; diff --git a/src/req_wrap.h b/src/req_wrap.h index ba56821bbe..1251cea6db 100644 --- a/src/req_wrap.h +++ b/src/req_wrap.h @@ -36,7 +36,7 @@ class ReqWrap { public: ReqWrap() { v8::HandleScope scope; - object_ = v8::Persistent::New(v8::Object::New()); + object_ = v8::Persistent::New(node_isolate, v8::Object::New()); v8::Local domain = v8::Context::GetCurrent() ->Global() @@ -58,7 +58,7 @@ class ReqWrap { // Assert that someone has called Dispatched() assert(req_.data == this); assert(!object_.IsEmpty()); - object_.Dispose(); + object_.Dispose(node_isolate); object_.Clear(); } diff --git a/src/slab_allocator.cc b/src/slab_allocator.cc index e0d7b13132..6af7215302 100644 --- a/src/slab_allocator.cc +++ b/src/slab_allocator.cc @@ -51,9 +51,9 @@ SlabAllocator::SlabAllocator(unsigned int size) { SlabAllocator::~SlabAllocator() { if (!initialized_) return; if (V8::IsDead()) return; - slab_sym_.Dispose(); + slab_sym_.Dispose(node_isolate); slab_sym_.Clear(); - slab_.Dispose(); + slab_.Dispose(node_isolate); slab_.Clear(); } @@ -65,7 +65,7 @@ void SlabAllocator::Initialize() { offset_ = 0; last_ptr_ = NULL; initialized_ = true; - slab_sym_ = Persistent::New(String::New(sym)); + slab_sym_ = Persistent::New(node_isolate, String::New(sym)); } @@ -94,9 +94,9 @@ char* SlabAllocator::Allocate(Handle obj, unsigned int size) { } if (slab_.IsEmpty() || offset_ + size > size_) { - slab_.Dispose(); + slab_.Dispose(node_isolate); slab_.Clear(); - slab_ = Persistent::New(NewSlab(size_)); + slab_ = Persistent::New(node_isolate, NewSlab(size_)); offset_ = 0; last_ptr_ = NULL; } diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index fb6edbc3a3..50497140b0 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -199,7 +199,7 @@ static Local AcceptHandle(uv_stream_t* pipe) { return Local(); wrap = static_cast( - wrap_obj->GetPointerFromInternalField(0)); + wrap_obj->GetAlignedPointerFromInternalField(0)); handle = wrap->UVHandle(); if (uv_accept(pipe, reinterpret_cast(handle))) @@ -436,7 +436,7 @@ Handle StreamWrap::WriteStringImpl(const Arguments& args) { Local send_handle_obj = args[1]->ToObject(); assert(send_handle_obj->InternalFieldCount() > 0); HandleWrap* send_handle_wrap = static_cast( - send_handle_obj->GetPointerFromInternalField(0)); + send_handle_obj->GetAlignedPointerFromInternalField(0)); send_handle = send_handle_wrap->GetHandle(); // Reference StreamWrap instance to prevent it from being garbage diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 4c55f2eff5..34ee8a0638 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -118,7 +118,7 @@ void TCPWrap::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "setSimultaneousAccepts", SetSimultaneousAccepts); #endif - tcpConstructor = Persistent::New(t->GetFunction()); + tcpConstructor = Persistent::New(node_isolate, t->GetFunction()); onconnection_sym = NODE_PSYMBOL("onconnection"); oncomplete_sym = NODE_PSYMBOL("oncomplete"); @@ -130,7 +130,7 @@ void TCPWrap::Initialize(Handle target) { TCPWrap* TCPWrap::Unwrap(Local obj) { assert(!obj.IsEmpty()); assert(obj->InternalFieldCount() > 0); - return static_cast(obj->GetPointerFromInternalField(0)); + return static_cast(obj->GetAlignedPointerFromInternalField(0)); } @@ -327,7 +327,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) { // Unwrap the client javascript object. assert(client_obj->InternalFieldCount() > 0); TCPWrap* client_wrap = static_cast( - client_obj->GetPointerFromInternalField(0)); + client_obj->GetAlignedPointerFromInternalField(0)); if (uv_accept(handle, (uv_stream_t*)&client_wrap->handle_)) return; diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 4be53c8e7b..5ad6106c09 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -88,7 +88,7 @@ void TTYWrap::Initialize(Handle target) { TTYWrap* TTYWrap::Unwrap(Local obj) { assert(!obj.IsEmpty()); assert(obj->InternalFieldCount() > 0); - return static_cast(obj->GetPointerFromInternalField(0)); + return static_cast(obj->GetAlignedPointerFromInternalField(0)); } diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 73b722f675..d3e49e0e2e 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -123,8 +123,8 @@ void UDPWrap::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "ref", HandleWrap::Ref); NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref); - constructor = Persistent::New( - Persistent::New(t)->GetFunction()); + constructor = Persistent::New(node_isolate, + Persistent::New(node_isolate, t)->GetFunction()); target->Set(String::NewSymbol("UDP"), constructor); } @@ -427,7 +427,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle, UDPWrap* UDPWrap::Unwrap(Local obj) { assert(!obj.IsEmpty()); assert(obj->InternalFieldCount() > 0); - return static_cast(obj->GetPointerFromInternalField(0)); + return static_cast(obj->GetAlignedPointerFromInternalField(0)); } diff --git a/src/v8_typed_array.cc b/src/v8_typed_array.cc index 012fb706c1..3eaf19dca8 100644 --- a/src/v8_typed_array.cc +++ b/src/v8_typed_array.cc @@ -48,7 +48,7 @@ class ArrayBuffer { return ft_cache; v8::HandleScope scope; - ft_cache = v8::Persistent::New( + ft_cache = v8::Persistent::New(node::node_isolate, v8::FunctionTemplate::New(&ArrayBuffer::V8New)); ft_cache->SetClassName(v8::String::New("ArrayBuffer")); v8::Local instance = ft_cache->InstanceTemplate(); @@ -69,7 +69,9 @@ class ArrayBuffer { } private: - static void WeakCallback(v8::Persistent value, void* data) { + static void WeakCallback(v8::Isolate* env, + v8::Persistent value, + void* data) { v8::Object* obj = v8::Object::Cast(*value); void* ptr = obj->GetIndexedPropertiesExternalArrayData(); @@ -78,10 +80,10 @@ class ArrayBuffer { int size = obj->GetIndexedPropertiesExternalArrayDataLength() * element_size; - v8::V8::AdjustAmountOfExternalAllocatedMemory(-size); + node::node_isolate->AdjustAmountOfExternalAllocatedMemory(-size); - value.ClearWeak(); - value.Dispose(); + value.ClearWeak(env); + value.Dispose(env); free(ptr); } @@ -108,7 +110,7 @@ class ArrayBuffer { if (!buf) return ThrowError("Unable to allocate ArrayBuffer."); - args.This()->SetPointerInInternalField(0, buf); + args.This()->SetAlignedPointerInInternalField(0, buf); args.This()->Set(v8::String::New("byteLength"), v8::Integer::NewFromUnsigned(num_bytes), @@ -121,11 +123,11 @@ class ArrayBuffer { args.This()->SetIndexedPropertiesToExternalArrayData( buf, v8::kExternalUnsignedByteArray, num_bytes); - v8::V8::AdjustAmountOfExternalAllocatedMemory(num_bytes); + node::node_isolate->AdjustAmountOfExternalAllocatedMemory(num_bytes); v8::Persistent persistent = - v8::Persistent::New(args.This()); - persistent.MakeWeak(NULL, &ArrayBuffer::WeakCallback); + v8::Persistent::New(node::node_isolate, args.This()); + persistent.MakeWeak(node::node_isolate, NULL, &ArrayBuffer::WeakCallback); return args.This(); } @@ -159,8 +161,8 @@ class ArrayBuffer { if (buffer.IsEmpty()) return v8::Undefined(); // constructor failed - void* src = args.This()->GetPointerFromInternalField(0); - void* dest = buffer->GetPointerFromInternalField(0); + void* src = args.This()->GetAlignedPointerFromInternalField(0); + void* dest = buffer->GetAlignedPointerFromInternalField(0); memcpy(dest, static_cast(src) + begin, slice_length); return buffer; @@ -204,7 +206,7 @@ class TypedArray { return ft_cache; v8::HandleScope scope; - ft_cache = v8::Persistent::New( + ft_cache = v8::Persistent::New(node::node_isolate, v8::FunctionTemplate::New(&TypedArray::V8New)); ft_cache->SetClassName(v8::String::New(TEANameTrait::name)); v8::Local instance = ft_cache->InstanceTemplate(); @@ -298,7 +300,7 @@ class TypedArray { GetFunction()->NewInstance(1, argv); if (buffer.IsEmpty()) return v8::Undefined(); // constructor failed - void* buf = buffer->GetPointerFromInternalField(0); + void* buf = buffer->GetAlignedPointerFromInternalField(0); args.This()->SetIndexedPropertiesToExternalArrayData( buf, TEAType, length); // TODO(deanm): check for failure. @@ -327,7 +329,7 @@ class TypedArray { GetFunction()->NewInstance(1, argv); if (buffer.IsEmpty()) return v8::Undefined(); // constructor failed - void* buf = buffer->GetPointerFromInternalField(0); + void* buf = buffer->GetAlignedPointerFromInternalField(0); args.This()->SetIndexedPropertiesToExternalArrayData( buf, TEAType, length); // TODO(deanm): check for failure. @@ -569,7 +571,7 @@ class DataView { return ft_cache; v8::HandleScope scope; - ft_cache = v8::Persistent::New( + ft_cache = v8::Persistent::New(node::node_isolate, v8::FunctionTemplate::New(&DataView::V8New)); ft_cache->SetClassName(v8::String::New("DataView")); v8::Local instance = ft_cache->InstanceTemplate(); diff --git a/test/message/error_exit.out b/test/message/error_exit.out index 11ea76fd72..bef1586e08 100644 --- a/test/message/error_exit.out +++ b/test/message/error_exit.out @@ -3,7 +3,7 @@ Exiting with code=1 assert.js:* throw new assert.AssertionError({ ^ -AssertionError: 1 == 2 +AssertionError at Object. (*test*message*error_exit.js:*:*) at Module._compile (module.js:*:*) at Object.Module._extensions..js (module.js:*:*) diff --git a/test/message/stack_overflow.js b/test/message/stack_overflow.js index 91974bee1e..0066313084 100644 --- a/test/message/stack_overflow.js +++ b/test/message/stack_overflow.js @@ -25,6 +25,8 @@ var common = require('../common'); var assert = require('assert'); +Error.stackTraceLimit = 0; + common.error('before'); // stack overflow diff --git a/test/message/stack_overflow.out b/test/message/stack_overflow.out index 72dc019ff1..4f7b8b132f 100644 --- a/test/message/stack_overflow.out +++ b/test/message/stack_overflow.out @@ -1,6 +1,6 @@ before -*test*message*stack_overflow.js:31 +*test*message*stack_overflow.js:* function stackOverflow() { ^ RangeError: Maximum call stack size exceeded