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.
This commit is contained in:
Trevor Norris 2013-03-18 13:54:00 -07:00 committed by Ben Noordhuis
parent 06bec0e087
commit 0bba590283
29 changed files with 139 additions and 118 deletions

View File

@ -63,7 +63,8 @@ function rethrow() {
var backtrace = new Error; var backtrace = new Error;
return function(err) { return function(err) {
if (err) { if (err) {
backtrace.message = err.message; backtrace.stack = err.name + ': ' + err.message +
backtrace.stack.substr(backtrace.name.length);
err = backtrace; err = backtrace;
throw err; throw err;
} }

View File

@ -272,7 +272,7 @@ class QueryWrap {
QueryWrap() { QueryWrap() {
HandleScope scope; HandleScope scope;
object_ = Persistent<Object>::New(Object::New()); object_ = Persistent<Object>::New(node_isolate, Object::New());
} }
virtual ~QueryWrap() { virtual ~QueryWrap() {
@ -280,7 +280,7 @@ class QueryWrap {
object_->Delete(oncomplete_sym); object_->Delete(oncomplete_sym);
object_.Dispose(); object_.Dispose(node_isolate);
object_.Clear(); object_.Clear();
} }

View File

@ -74,7 +74,8 @@ void FSEventWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "close", Close); NODE_SET_PROTOTYPE_METHOD(t, "close", Close);
target->Set(String::NewSymbol("FSEvent"), target->Set(String::NewSymbol("FSEvent"),
Persistent<FunctionTemplate>::New(t)->GetFunction()); Persistent<FunctionTemplate>::New(node_isolate,
t)->GetFunction());
} }
@ -172,7 +173,7 @@ Handle<Value> FSEventWrap::Close(const Arguments& args) {
// and legal, HandleWrap::Close() deals with them the same way. // and legal, HandleWrap::Close() deals with them the same way.
assert(!args.Holder().IsEmpty()); assert(!args.Holder().IsEmpty());
assert(args.Holder()->InternalFieldCount() > 0); assert(args.Holder()->InternalFieldCount() > 0);
void* ptr = args.Holder()->GetPointerFromInternalField(0); void* ptr = args.Holder()->GetAlignedPointerFromInternalField(0);
FSEventWrap* wrap = static_cast<FSEventWrap*>(ptr); FSEventWrap* wrap = static_cast<FSEventWrap*>(ptr);
if (wrap == NULL || wrap->initialized_ == false) { if (wrap == NULL || wrap->initialized_ == false) {

View File

@ -84,7 +84,7 @@ Handle<Value> HandleWrap::Close(const Arguments& args) {
HandleScope scope; HandleScope scope;
HandleWrap *wrap = static_cast<HandleWrap*>( HandleWrap *wrap = static_cast<HandleWrap*>(
args.Holder()->GetPointerFromInternalField(0)); args.Holder()->GetAlignedPointerFromInternalField(0));
// guard against uninitialized handle or double close // guard against uninitialized handle or double close
if (wrap == NULL || wrap->handle__ == NULL) { if (wrap == NULL || wrap->handle__ == NULL) {
@ -115,8 +115,8 @@ HandleWrap::HandleWrap(Handle<Object> object, uv_handle_t* h) {
HandleScope scope; HandleScope scope;
assert(object_.IsEmpty()); assert(object_.IsEmpty());
assert(object->InternalFieldCount() > 0); assert(object->InternalFieldCount() > 0);
object_ = v8::Persistent<v8::Object>::New(object); object_ = v8::Persistent<v8::Object>::New(node_isolate, object);
object_->SetPointerInInternalField(0, this); object_->SetAlignedPointerInInternalField(0, this);
ngx_queue_insert_tail(&handle_wrap_queue, &handle_wrap_queue_); 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); MakeCallback(wrap->object_, close_sym, 0, NULL);
} }
wrap->object_->SetPointerInInternalField(0, NULL); wrap->object_->SetAlignedPointerInInternalField(0, NULL);
wrap->object_.Dispose(); wrap->object_.Dispose(node_isolate);
wrap->object_.Clear(); wrap->object_.Clear();
delete wrap; delete wrap;

View File

@ -50,7 +50,7 @@ namespace node {
assert(!args.Holder().IsEmpty()); \ assert(!args.Holder().IsEmpty()); \
assert(args.Holder()->InternalFieldCount() > 0); \ assert(args.Holder()->InternalFieldCount() > 0); \
type* wrap = static_cast<type*>( \ type* wrap = static_cast<type*>( \
args.Holder()->GetPointerFromInternalField(0)); args.Holder()->GetAlignedPointerFromInternalField(0));
class HandleWrap { class HandleWrap {
public: public:

View File

@ -195,7 +195,7 @@ static void Spin(uv_idle_t* handle, int status) {
abort(); abort();
} }
Local<Function> cb = cb_v.As<Function>(); Local<Function> cb = cb_v.As<Function>();
process_tickFromSpinner = Persistent<Function>::New(cb); process_tickFromSpinner = Persistent<Function>::New(node_isolate, cb);
} }
TryCatch try_catch; TryCatch try_catch;
@ -912,7 +912,7 @@ MakeDomainCallback(const Handle<Object> object,
abort(); abort();
} }
Local<Function> cb = cb_v.As<Function>(); Local<Function> cb = cb_v.As<Function>();
process_tickDomainCallback = Persistent<Function>::New(cb); process_tickDomainCallback = Persistent<Function>::New(node_isolate, cb);
} }
// lazy load domain specific symbols // lazy load domain specific symbols
@ -1002,7 +1002,7 @@ MakeCallback(const Handle<Object> object,
abort(); abort();
} }
Local<Function> cb = cb_v.As<Function>(); Local<Function> cb = cb_v.As<Function>();
process_tickCallback = Persistent<Function>::New(cb); process_tickCallback = Persistent<Function>::New(node_isolate, cb);
} }
TryCatch try_catch; TryCatch try_catch;
@ -1802,7 +1802,7 @@ v8::Handle<v8::Value> MemoryUsage(const v8::Arguments& args) {
// V8 memory usage // V8 memory usage
HeapStatistics v8_heap_stats; HeapStatistics v8_heap_stats;
V8::GetHeapStatistics(&v8_heap_stats); node_isolate->GetHeapStatistics(&v8_heap_stats);
info->Set(heap_total_symbol, info->Set(heap_total_symbol,
Integer::NewFromUnsigned(v8_heap_stats.total_heap_size())); Integer::NewFromUnsigned(v8_heap_stats.total_heap_size()));
info->Set(heap_used_symbol, info->Set(heap_used_symbol,
@ -2021,7 +2021,7 @@ static Handle<Value> Binding(const Arguments& args) {
node_module_struct* modp; node_module_struct* modp;
if (binding_cache.IsEmpty()) { if (binding_cache.IsEmpty()) {
binding_cache = Persistent<Object>::New(Object::New()); binding_cache = Persistent<Object>::New(node_isolate, Object::New());
} }
Local<Object> exports; Local<Object> exports;
@ -2307,7 +2307,8 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
process_template->SetClassName(String::NewSymbol("process")); process_template->SetClassName(String::NewSymbol("process"));
process = Persistent<Object>::New(process_template->GetFunction()->NewInstance()); process = Persistent<Object>::New(node_isolate,
process_template->GetFunction()->NewInstance());
process->SetAccessor(String::New("title"), process->SetAccessor(String::New("title"),
ProcessTitleGetter, ProcessTitleGetter,
@ -2317,7 +2318,7 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
process->Set(String::NewSymbol("version"), String::New(NODE_VERSION)); process->Set(String::NewSymbol("version"), String::New(NODE_VERSION));
// process.moduleLoadList // process.moduleLoadList
module_load_list = Persistent<Array>::New(Array::New()); module_load_list = Persistent<Array>::New(node_isolate, Array::New());
process->Set(String::NewSymbol("moduleLoadList"), module_load_list); process->Set(String::NewSymbol("moduleLoadList"), module_load_list);
// process.versions // process.versions
@ -2984,6 +2985,10 @@ char** Init(int argc, char *argv[]) {
} }
V8::SetFlagsFromCommandLine(&v8argc, v8argv, false); 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__ #ifdef __POSIX__
// Ignore SIGPIPE // Ignore SIGPIPE
RegisterSignalHandler(SIGPIPE, SIG_IGN); RegisterSignalHandler(SIGPIPE, SIG_IGN);
@ -2999,10 +3004,6 @@ char** Init(int argc, char *argv[]) {
V8::SetFatalErrorHandler(node::OnFatalError); 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 the --debug flag was specified then initialize the debug thread.
if (use_debug_agent) { if (use_debug_agent) {
EnableDebug(debug_wait_connect); EnableDebug(debug_wait_connect);
@ -3111,7 +3112,7 @@ int Start(int argc, char *argv[]) {
V8::Initialize(); V8::Initialize();
{ {
Locker locker; Locker locker(node_isolate);
HandleScope handle_scope; HandleScope handle_scope;
// Create the one and only Context. // Create the one and only Context.
@ -3137,7 +3138,7 @@ int Start(int argc, char *argv[]) {
RunAtExit(); RunAtExit();
#ifndef NDEBUG #ifndef NDEBUG
context.Dispose(); context.Dispose(node_isolate);
#endif #endif
} }

View File

@ -86,6 +86,8 @@
namespace node { namespace node {
extern v8::Isolate* node_isolate;
NODE_EXTERN extern bool no_deprecation; NODE_EXTERN extern bool no_deprecation;
NODE_EXTERN int Start(int argc, char *argv[]); NODE_EXTERN int Start(int argc, char *argv[]);
@ -96,7 +98,7 @@ void Load(v8::Handle<v8::Object> process);
void EmitExit(v8::Handle<v8::Object> process); void EmitExit(v8::Handle<v8::Object> process);
#define NODE_PSYMBOL(s) \ #define NODE_PSYMBOL(s) \
v8::Persistent<v8::String>::New(v8::String::NewSymbol(s)) v8::Persistent<v8::String>::New(node_isolate, v8::String::NewSymbol(s))
/* Converts a unixtime to V8 Date */ /* Converts a unixtime to V8 Date */
#define NODE_UNIXTIME_V8(t) v8::Date::New(1000*static_cast<double>(t)) #define NODE_UNIXTIME_V8(t) v8::Date::New(1000*static_cast<double>(t))
@ -153,7 +155,7 @@ v8::Local<v8::Object> BuildStatsObject(const uv_statbuf_t* s);
static inline v8::Persistent<v8::Function>* cb_persist( static inline v8::Persistent<v8::Function>* cb_persist(
const v8::Local<v8::Value> &v) { const v8::Local<v8::Value> &v) {
v8::Persistent<v8::Function> *fn = new v8::Persistent<v8::Function>(); v8::Persistent<v8::Function> *fn = new v8::Persistent<v8::Function>();
*fn = v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(v)); *fn = v8::Persistent<v8::Function>::New(node_isolate, v8::Local<v8::Function>::Cast(v));
return fn; return fn;
} }
@ -165,7 +167,7 @@ static inline v8::Persistent<v8::Function>* cb_unwrap(void *data) {
} }
static inline void cb_destroy(v8::Persistent<v8::Function> * cb) { static inline void cb_destroy(v8::Persistent<v8::Function> * cb) {
cb->Dispose(); cb->Dispose(node_isolate);
delete cb; delete cb;
} }

View File

@ -187,7 +187,7 @@ Buffer::Buffer(Handle<Object> wrapper, size_t length) : ObjectWrap() {
length_ = 0; length_ = 0;
callback_ = NULL; callback_ = NULL;
handle_.SetWrapperClassId(BUFFER_CLASS_ID); handle_.SetWrapperClassId(node_isolate, BUFFER_CLASS_ID);
Replace(NULL, length, NULL, NULL); Replace(NULL, length, NULL, NULL);
} }
@ -208,7 +208,7 @@ void Buffer::Replace(char *data, size_t length,
callback_(data_, callback_hint_); callback_(data_, callback_hint_);
} else if (length_) { } else if (length_) {
delete [] data_; delete [] data_;
V8::AdjustAmountOfExternalAllocatedMemory( node_isolate->AdjustAmountOfExternalAllocatedMemory(
-static_cast<intptr_t>(sizeof(Buffer) + length_)); -static_cast<intptr_t>(sizeof(Buffer) + length_));
} }
@ -222,7 +222,8 @@ void Buffer::Replace(char *data, size_t length,
data_ = new char[length_]; data_ = new char[length_];
if (data) if (data)
memcpy(data_, data, length_); memcpy(data_, data, length_);
V8::AdjustAmountOfExternalAllocatedMemory(sizeof(Buffer) + length_); node_isolate->AdjustAmountOfExternalAllocatedMemory(sizeof(Buffer) +
length_);
} else { } else {
data_ = NULL; data_ = NULL;
} }
@ -1039,7 +1040,8 @@ bool Buffer::HasInstance(Handle<Value> val) {
Handle<Value> SetFastBufferConstructor(const Arguments& args) { Handle<Value> SetFastBufferConstructor(const Arguments& args) {
assert(args[0]->IsFunction()); assert(args[0]->IsFunction());
fast_buffer_constructor = Persistent<Function>::New(args[0].As<Function>()); fast_buffer_constructor = Persistent<Function>::New(node_isolate,
args[0].As<Function>());
return Undefined(); return Undefined();
} }
@ -1117,7 +1119,7 @@ void Buffer::Initialize(Handle<Object> target) {
chars_written_sym = NODE_PSYMBOL("_charsWritten"); chars_written_sym = NODE_PSYMBOL("_charsWritten");
Local<FunctionTemplate> t = FunctionTemplate::New(Buffer::New); Local<FunctionTemplate> t = FunctionTemplate::New(Buffer::New);
constructor_template = Persistent<FunctionTemplate>::New(t); constructor_template = Persistent<FunctionTemplate>::New(node_isolate, t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("SlowBuffer")); constructor_template->SetClassName(String::NewSymbol("SlowBuffer"));

View File

@ -122,7 +122,7 @@ void InitPerfCounters(Handle<Object> target) {
}; };
for (int i = 0; i < ARRAY_SIZE(tab); i++) { for (int i = 0; i < ARRAY_SIZE(tab); i++) {
tab[i].templ = Persistent<FunctionTemplate>::New( tab[i].templ = Persistent<FunctionTemplate>::New(node_isolate,
FunctionTemplate::New(tab[i].func)); FunctionTemplate::New(tab[i].func));
target->Set(String::NewSymbol(tab[i].name), tab[i].templ->GetFunction()); target->Set(String::NewSymbol(tab[i].name), tab[i].templ->GetFunction());
} }

View File

@ -141,7 +141,8 @@ void SecureContext::Initialize(Handle<Object> target) {
HandleScope scope; HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(SecureContext::New); Local<FunctionTemplate> t = FunctionTemplate::New(SecureContext::New);
secure_context_constructor = Persistent<FunctionTemplate>::New(t); secure_context_constructor = Persistent<FunctionTemplate>::New(node_isolate,
t);
t->InstanceTemplate()->SetInternalFieldCount(1); t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(String::NewSymbol("SecureContext")); t->SetClassName(String::NewSymbol("SecureContext"));
@ -1094,7 +1095,7 @@ int Connection::SelectNextProtoCallback_(SSL *s,
// Release old protocol handler if present // Release old protocol handler if present
if (!p->selectedNPNProto_.IsEmpty()) { if (!p->selectedNPNProto_.IsEmpty()) {
p->selectedNPNProto_.Dispose(); p->selectedNPNProto_.Dispose(node_isolate);
} }
if (p->npnProtos_.IsEmpty()) { if (p->npnProtos_.IsEmpty()) {
@ -1104,7 +1105,7 @@ int Connection::SelectNextProtoCallback_(SSL *s,
*outlen = 8; *outlen = 8;
// set status unsupported // set status unsupported
p->selectedNPNProto_ = Persistent<Value>::New(False()); p->selectedNPNProto_ = Persistent<Value>::New(node_isolate, False());
return SSL_TLSEXT_ERR_OK; return SSL_TLSEXT_ERR_OK;
} }
@ -1117,15 +1118,15 @@ int Connection::SelectNextProtoCallback_(SSL *s,
switch (status) { switch (status) {
case OPENSSL_NPN_UNSUPPORTED: case OPENSSL_NPN_UNSUPPORTED:
p->selectedNPNProto_ = Persistent<Value>::New(Null()); p->selectedNPNProto_ = Persistent<Value>::New(node_isolate, Null());
break; break;
case OPENSSL_NPN_NEGOTIATED: case OPENSSL_NPN_NEGOTIATED:
p->selectedNPNProto_ = Persistent<Value>::New(String::New( p->selectedNPNProto_ = Persistent<Value>::New(node_isolate, String::New(
reinterpret_cast<const char*>(*out), *outlen reinterpret_cast<const char*>(*out), *outlen
)); ));
break; break;
case OPENSSL_NPN_NO_OVERLAP: case OPENSSL_NPN_NO_OVERLAP:
p->selectedNPNProto_ = Persistent<Value>::New(False()); p->selectedNPNProto_ = Persistent<Value>::New(node_isolate, False());
break; break;
default: default:
break; break;
@ -1145,14 +1146,15 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) {
if (servername) { if (servername) {
if (!p->servername_.IsEmpty()) { if (!p->servername_.IsEmpty()) {
p->servername_.Dispose(); p->servername_.Dispose(node_isolate);
} }
p->servername_ = Persistent<String>::New(String::New(servername)); p->servername_ = Persistent<String>::New(node_isolate,
String::New(servername));
// Call the SNI callback and use its return value as context // Call the SNI callback and use its return value as context
if (!p->sniObject_.IsEmpty()) { if (!p->sniObject_.IsEmpty()) {
if (!p->sniContext_.IsEmpty()) { if (!p->sniContext_.IsEmpty()) {
p->sniContext_.Dispose(); p->sniContext_.Dispose(node_isolate);
} }
// Get callback init args // Get callback init args
@ -1166,7 +1168,7 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) {
// If ret is SecureContext // If ret is SecureContext
if (secure_context_constructor->HasInstance(ret)) { if (secure_context_constructor->HasInstance(ret)) {
p->sniContext_ = Persistent<Value>::New(ret); p->sniContext_ = Persistent<Value>::New(node_isolate, ret);
SecureContext *sc = ObjectWrap::Unwrap<SecureContext>( SecureContext *sc = ObjectWrap::Unwrap<SecureContext>(
Local<Object>::Cast(ret)); Local<Object>::Cast(ret));
SSL_set_SSL_CTX(s, sc->ctx_); SSL_set_SSL_CTX(s, sc->ctx_);
@ -1993,9 +1995,9 @@ Handle<Value> Connection::SetNPNProtocols(const Arguments& args) {
// Release old handle // Release old handle
if (!ss->npnProtos_.IsEmpty()) { if (!ss->npnProtos_.IsEmpty()) {
ss->npnProtos_.Dispose(); ss->npnProtos_.Dispose(node_isolate);
} }
ss->npnProtos_ = Persistent<Object>::New(args[0]->ToObject()); ss->npnProtos_ = Persistent<Object>::New(node_isolate, args[0]->ToObject());
return True(); return True();
}; };
@ -2026,9 +2028,9 @@ Handle<Value> Connection::SetSNICallback(const Arguments& args) {
// Release old handle // Release old handle
if (!ss->sniObject_.IsEmpty()) { if (!ss->sniObject_.IsEmpty()) {
ss->sniObject_.Dispose(); ss->sniObject_.Dispose(node_isolate);
} }
ss->sniObject_ = Persistent<Object>::New(Object::New()); ss->sniObject_ = Persistent<Object>::New(node_isolate, Object::New());
ss->sniObject_->Set(String::New("onselect"), args[0]); ss->sniObject_->Set(String::New("onselect"), args[0]);
return True(); return True();
@ -3294,7 +3296,7 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) {
Persistent<Object> obj = req->obj; Persistent<Object> obj = req->obj;
EIO_PBKDF2After(req, argv); EIO_PBKDF2After(req, argv);
MakeCallback(obj, "ondone", ARRAY_SIZE(argv), argv); MakeCallback(obj, "ondone", ARRAY_SIZE(argv), argv);
obj.Dispose(); obj.Dispose(node_isolate);
} }
@ -3372,7 +3374,7 @@ Handle<Value> PBKDF2(const Arguments& args) {
req->keylen = keylen; req->keylen = keylen;
if (args[4]->IsFunction()) { if (args[4]->IsFunction()) {
req->obj = Persistent<Object>::New(Object::New()); req->obj = Persistent<Object>::New(node_isolate, Object::New());
req->obj->Set(String::New("ondone"), args[4]); req->obj->Set(String::New("ondone"), args[4]);
uv_queue_work(uv_default_loop(), uv_queue_work(uv_default_loop(),
&req->work_req, &req->work_req,
@ -3406,7 +3408,7 @@ struct RandomBytesRequest {
RandomBytesRequest::~RandomBytesRequest() { RandomBytesRequest::~RandomBytesRequest() {
if (obj_.IsEmpty()) return; if (obj_.IsEmpty()) return;
obj_.Dispose(); obj_.Dispose(node_isolate);
obj_.Clear(); obj_.Clear();
} }
@ -3492,7 +3494,7 @@ Handle<Value> RandomBytes(const Arguments& args) {
req->size_ = size; req->size_ = size;
if (args[1]->IsFunction()) { if (args[1]->IsFunction()) {
req->obj_ = Persistent<Object>::New(Object::New()); req->obj_ = Persistent<Object>::New(node_isolate, Object::New());
req->obj_->Set(String::New("ondone"), args[1]); req->obj_->Set(String::New("ondone"), args[1]);
uv_queue_work(uv_default_loop(), uv_queue_work(uv_default_loop(),

View File

@ -249,14 +249,14 @@ class Connection : ObjectWrap {
} }
#ifdef OPENSSL_NPN_NEGOTIATED #ifdef OPENSSL_NPN_NEGOTIATED
if (!npnProtos_.IsEmpty()) npnProtos_.Dispose(); if (!npnProtos_.IsEmpty()) npnProtos_.Dispose(node_isolate);
if (!selectedNPNProto_.IsEmpty()) selectedNPNProto_.Dispose(); if (!selectedNPNProto_.IsEmpty()) selectedNPNProto_.Dispose(node_isolate);
#endif #endif
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
if (!sniObject_.IsEmpty()) sniObject_.Dispose(); if (!sniObject_.IsEmpty()) sniObject_.Dispose(node_isolate);
if (!sniContext_.IsEmpty()) sniContext_.Dispose(); if (!sniContext_.IsEmpty()) sniContext_.Dispose(node_isolate);
if (!servername_.IsEmpty()) servername_.Dispose(); if (!servername_.IsEmpty()) servername_.Dispose(node_isolate);
#endif #endif
} }

View File

@ -373,7 +373,7 @@ void InitDTrace(Handle<Object> target) {
}; };
for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) { for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) {
tab[i].templ = Persistent<FunctionTemplate>::New( tab[i].templ = Persistent<FunctionTemplate>::New(node_isolate,
FunctionTemplate::New(tab[i].func)); FunctionTemplate::New(tab[i].func));
target->Set(String::NewSymbol(tab[i].name), tab[i].templ->GetFunction()); target->Set(String::NewSymbol(tab[i].name), tab[i].templ->GetFunction());
} }

View File

@ -954,7 +954,8 @@ void InitFs(Handle<Object> target) {
HandleScope scope; HandleScope scope;
// Initialize the stats object // Initialize the stats object
Local<FunctionTemplate> stat_templ = FunctionTemplate::New(); Local<FunctionTemplate> stat_templ = FunctionTemplate::New();
stats_constructor_template = Persistent<FunctionTemplate>::New(stat_templ); stats_constructor_template = Persistent<FunctionTemplate>::New(node_isolate,
stat_templ);
target->Set(String::NewSymbol("Stats"), target->Set(String::NewSymbol("Stats"),
stats_constructor_template->GetFunction()); stats_constructor_template->GetFunction());
File::Initialize(target); File::Initialize(target);

View File

@ -99,7 +99,7 @@ inline static v8::Handle<v8::Value> ThrowRangeError(const char* errmsg) {
assert(!args.Holder().IsEmpty()); \ assert(!args.Holder().IsEmpty()); \
assert(args.Holder()->InternalFieldCount() > 0); \ assert(args.Holder()->InternalFieldCount() > 0); \
type* wrap = static_cast<type*>( \ type* wrap = static_cast<type*>( \
args.Holder()->GetPointerFromInternalField(0)); \ args.Holder()->GetAlignedPointerFromInternalField(0)); \
if (!wrap) { \ if (!wrap) { \
fprintf(stderr, #type ": Aborting due to unwrap failure at %s:%d\n", \ fprintf(stderr, #type ": Aborting due to unwrap failure at %s:%d\n", \
__FILE__, __LINE__); \ __FILE__, __LINE__); \

View File

@ -37,6 +37,8 @@
namespace node { namespace node {
extern v8::Isolate* node_isolate;
class NODE_EXTERN ObjectWrap { class NODE_EXTERN ObjectWrap {
public: public:
ObjectWrap ( ) { ObjectWrap ( ) {
@ -46,10 +48,10 @@ class NODE_EXTERN ObjectWrap {
virtual ~ObjectWrap ( ) { virtual ~ObjectWrap ( ) {
if (!handle_.IsEmpty()) { if (!handle_.IsEmpty()) {
assert(handle_.IsNearDeath()); assert(handle_.IsNearDeath(node_isolate));
handle_.ClearWeak(); handle_.ClearWeak(node_isolate);
handle_->SetInternalField(0, v8::Undefined()); handle_->SetInternalField(0, v8::Undefined());
handle_.Dispose(); handle_.Dispose(node_isolate);
handle_.Clear(); handle_.Clear();
} }
} }
@ -59,7 +61,7 @@ class NODE_EXTERN ObjectWrap {
static inline T* Unwrap (v8::Handle<v8::Object> handle) { static inline T* Unwrap (v8::Handle<v8::Object> handle) {
assert(!handle.IsEmpty()); assert(!handle.IsEmpty());
assert(handle->InternalFieldCount() > 0); assert(handle->InternalFieldCount() > 0);
return static_cast<T*>(handle->GetPointerFromInternalField(0)); return static_cast<T*>(handle->GetAlignedPointerFromInternalField(0));
} }
@ -69,15 +71,15 @@ class NODE_EXTERN ObjectWrap {
inline void Wrap (v8::Handle<v8::Object> handle) { inline void Wrap (v8::Handle<v8::Object> handle) {
assert(handle_.IsEmpty()); assert(handle_.IsEmpty());
assert(handle->InternalFieldCount() > 0); assert(handle->InternalFieldCount() > 0);
handle_ = v8::Persistent<v8::Object>::New(handle); handle_ = v8::Persistent<v8::Object>::New(node_isolate, handle);
handle_->SetPointerInInternalField(0, this); handle_->SetAlignedPointerInInternalField(0, this);
MakeWeak(); MakeWeak();
} }
inline void MakeWeak (void) { inline void MakeWeak (void) {
handle_.MakeWeak(this, WeakCallback); handle_.MakeWeak(node_isolate, this, WeakCallback);
handle_.MarkIndependent(); handle_.MarkIndependent(node_isolate);
} }
/* Ref() marks the object as being attached to an event loop. /* Ref() marks the object as being attached to an event loop.
@ -87,7 +89,7 @@ class NODE_EXTERN ObjectWrap {
virtual void Ref() { virtual void Ref() {
assert(!handle_.IsEmpty()); assert(!handle_.IsEmpty());
refs_++; refs_++;
handle_.ClearWeak(); handle_.ClearWeak(node_isolate);
} }
/* Unref() marks an object as detached from the event loop. This is its /* Unref() marks an object as detached from the event loop. This is its
@ -101,7 +103,7 @@ class NODE_EXTERN ObjectWrap {
*/ */
virtual void Unref() { virtual void Unref() {
assert(!handle_.IsEmpty()); assert(!handle_.IsEmpty());
assert(!handle_.IsWeak()); assert(!handle_.IsWeak(node_isolate));
assert(refs_ > 0); assert(refs_ > 0);
if (--refs_ == 0) { MakeWeak(); } if (--refs_ == 0) { MakeWeak(); }
} }
@ -111,13 +113,15 @@ class NODE_EXTERN ObjectWrap {
private: private:
static void WeakCallback (v8::Persistent<v8::Value> value, void *data) { static void WeakCallback(v8::Isolate* env,
v8::Persistent<v8::Value> value,
void* data) {
v8::HandleScope scope; v8::HandleScope scope;
ObjectWrap *obj = static_cast<ObjectWrap*>(data); ObjectWrap *obj = static_cast<ObjectWrap*>(data);
assert(value == obj->handle_); assert(value == obj->handle_);
assert(!obj->refs_); assert(!obj->refs_);
assert(value.IsNearDeath()); assert(value.IsNearDeath(env));
delete obj; delete obj;
} }
}; };

View File

@ -124,7 +124,8 @@ void CloneObject(Handle<Object> recv,
})" })"
), String::New("binding:script"))->Run() ), String::New("binding:script"))->Run()
); );
cloneObjectMethod = Persistent<Function>::New(cloneObjectMethod_); cloneObjectMethod = Persistent<Function>::New(node_isolate,
cloneObjectMethod_);
} }
cloneObjectMethod->Call(recv, 2, args); cloneObjectMethod->Call(recv, 2, args);
@ -135,7 +136,7 @@ void WrappedContext::Initialize(Handle<Object> target) {
HandleScope scope; HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(WrappedContext::New); Local<FunctionTemplate> t = FunctionTemplate::New(WrappedContext::New);
constructor_template = Persistent<FunctionTemplate>::New(t); constructor_template = Persistent<FunctionTemplate>::New(node_isolate, t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("Context")); constructor_template->SetClassName(String::NewSymbol("Context"));
@ -165,7 +166,7 @@ WrappedContext::WrappedContext() : ObjectWrap() {
WrappedContext::~WrappedContext() { WrappedContext::~WrappedContext() {
context_.Dispose(); context_.Dispose(node_isolate);
} }
@ -187,7 +188,7 @@ void WrappedScript::Initialize(Handle<Object> target) {
HandleScope scope; HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(WrappedScript::New); Local<FunctionTemplate> t = FunctionTemplate::New(WrappedScript::New);
constructor_template = Persistent<FunctionTemplate>::New(t); constructor_template = Persistent<FunctionTemplate>::New(node_isolate, t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
// Note: We use 'NodeScript' instead of 'Script' so that we do not // Note: We use 'NodeScript' instead of 'Script' so that we do not
// conflict with V8's Script class defined in v8/src/messages.js // conflict with V8's Script class defined in v8/src/messages.js
@ -247,7 +248,7 @@ Handle<Value> WrappedScript::New(const Arguments& args) {
WrappedScript::~WrappedScript() { WrappedScript::~WrappedScript() {
script_.Dispose(); script_.Dispose(node_isolate);
} }
@ -364,7 +365,7 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) {
// that when this function exits the context will be disposed. // that when this function exits the context will be disposed.
Persistent<Context> tmp = Context::New(); Persistent<Context> tmp = Context::New();
context = Local<Context>::New(tmp); context = Local<Context>::New(tmp);
tmp.Dispose(); tmp.Dispose(node_isolate);
} else if (context_flag == userContext) { } else if (context_flag == userContext) {
// Use the passed in context // Use the passed in context

View File

@ -38,7 +38,7 @@ void StatWatcher::Initialize(Handle<Object> target) {
HandleScope scope; HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(StatWatcher::New); Local<FunctionTemplate> t = FunctionTemplate::New(StatWatcher::New);
constructor_template = Persistent<FunctionTemplate>::New(t); constructor_template = Persistent<FunctionTemplate>::New(node_isolate, t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("StatWatcher")); constructor_template->SetClassName(String::NewSymbol("StatWatcher"));

View File

@ -89,11 +89,11 @@ class ZCtx : public ObjectWrap {
if (mode_ == DEFLATE || mode_ == GZIP || mode_ == DEFLATERAW) { if (mode_ == DEFLATE || mode_ == GZIP || mode_ == DEFLATERAW) {
(void)deflateEnd(&strm_); (void)deflateEnd(&strm_);
V8::AdjustAmountOfExternalAllocatedMemory(-kDeflateContextSize); node_isolate->AdjustAmountOfExternalAllocatedMemory(-kDeflateContextSize);
} else if (mode_ == INFLATE || mode_ == GUNZIP || mode_ == INFLATERAW || } else if (mode_ == INFLATE || mode_ == GUNZIP || mode_ == INFLATERAW ||
mode_ == UNZIP) { mode_ == UNZIP) {
(void)inflateEnd(&strm_); (void)inflateEnd(&strm_);
V8::AdjustAmountOfExternalAllocatedMemory(-kInflateContextSize); node_isolate->AdjustAmountOfExternalAllocatedMemory(-kInflateContextSize);
} }
mode_ = NONE; mode_ = NONE;
@ -406,14 +406,16 @@ class ZCtx : public ObjectWrap {
ctx->windowBits_, ctx->windowBits_,
ctx->memLevel_, ctx->memLevel_,
ctx->strategy_); ctx->strategy_);
V8::AdjustAmountOfExternalAllocatedMemory(kDeflateContextSize); node_isolate->
AdjustAmountOfExternalAllocatedMemory(kDeflateContextSize);
break; break;
case INFLATE: case INFLATE:
case GUNZIP: case GUNZIP:
case INFLATERAW: case INFLATERAW:
case UNZIP: case UNZIP:
ctx->err_ = inflateInit2(&ctx->strm_, ctx->windowBits_); ctx->err_ = inflateInit2(&ctx->strm_, ctx->windowBits_);
V8::AdjustAmountOfExternalAllocatedMemory(kInflateContextSize); node_isolate->
AdjustAmountOfExternalAllocatedMemory(kInflateContextSize);
break; break;
default: default:
assert(0 && "wtf?"); assert(0 && "wtf?");

View File

@ -69,7 +69,7 @@ Local<Object> PipeWrap::Instantiate() {
PipeWrap* PipeWrap::Unwrap(Local<Object> obj) { PipeWrap* PipeWrap::Unwrap(Local<Object> obj) {
assert(!obj.IsEmpty()); assert(!obj.IsEmpty());
assert(obj->InternalFieldCount() > 0); assert(obj->InternalFieldCount() > 0);
return static_cast<PipeWrap*>(obj->GetPointerFromInternalField(0)); return static_cast<PipeWrap*>(obj->GetAlignedPointerFromInternalField(0));
} }
@ -114,7 +114,7 @@ void PipeWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "setPendingInstances", SetPendingInstances); NODE_SET_PROTOTYPE_METHOD(t, "setPendingInstances", SetPendingInstances);
#endif #endif
pipeConstructor = Persistent<Function>::New(t->GetFunction()); pipeConstructor = Persistent<Function>::New(node_isolate, t->GetFunction());
target->Set(String::NewSymbol("Pipe"), pipeConstructor); target->Set(String::NewSymbol("Pipe"), pipeConstructor);
} }
@ -214,7 +214,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
// Unwrap the client javascript object. // Unwrap the client javascript object.
assert(client_obj->InternalFieldCount() > 0); assert(client_obj->InternalFieldCount() > 0);
PipeWrap* client_wrap = PipeWrap* client_wrap =
static_cast<PipeWrap*>(client_obj->GetPointerFromInternalField(0)); static_cast<PipeWrap*>(client_obj->GetAlignedPointerFromInternalField(0));
if (uv_accept(handle, (uv_stream_t*)&client_wrap->handle_)) return; if (uv_accept(handle, (uv_stream_t*)&client_wrap->handle_)) return;

View File

@ -36,7 +36,7 @@ class ReqWrap {
public: public:
ReqWrap() { ReqWrap() {
v8::HandleScope scope; v8::HandleScope scope;
object_ = v8::Persistent<v8::Object>::New(v8::Object::New()); object_ = v8::Persistent<v8::Object>::New(node_isolate, v8::Object::New());
v8::Local<v8::Value> domain = v8::Context::GetCurrent() v8::Local<v8::Value> domain = v8::Context::GetCurrent()
->Global() ->Global()
@ -58,7 +58,7 @@ class ReqWrap {
// Assert that someone has called Dispatched() // Assert that someone has called Dispatched()
assert(req_.data == this); assert(req_.data == this);
assert(!object_.IsEmpty()); assert(!object_.IsEmpty());
object_.Dispose(); object_.Dispose(node_isolate);
object_.Clear(); object_.Clear();
} }

View File

@ -51,9 +51,9 @@ SlabAllocator::SlabAllocator(unsigned int size) {
SlabAllocator::~SlabAllocator() { SlabAllocator::~SlabAllocator() {
if (!initialized_) return; if (!initialized_) return;
if (V8::IsDead()) return; if (V8::IsDead()) return;
slab_sym_.Dispose(); slab_sym_.Dispose(node_isolate);
slab_sym_.Clear(); slab_sym_.Clear();
slab_.Dispose(); slab_.Dispose(node_isolate);
slab_.Clear(); slab_.Clear();
} }
@ -65,7 +65,7 @@ void SlabAllocator::Initialize() {
offset_ = 0; offset_ = 0;
last_ptr_ = NULL; last_ptr_ = NULL;
initialized_ = true; initialized_ = true;
slab_sym_ = Persistent<String>::New(String::New(sym)); slab_sym_ = Persistent<String>::New(node_isolate, String::New(sym));
} }
@ -94,9 +94,9 @@ char* SlabAllocator::Allocate(Handle<Object> obj, unsigned int size) {
} }
if (slab_.IsEmpty() || offset_ + size > size_) { if (slab_.IsEmpty() || offset_ + size > size_) {
slab_.Dispose(); slab_.Dispose(node_isolate);
slab_.Clear(); slab_.Clear();
slab_ = Persistent<Object>::New(NewSlab(size_)); slab_ = Persistent<Object>::New(node_isolate, NewSlab(size_));
offset_ = 0; offset_ = 0;
last_ptr_ = NULL; last_ptr_ = NULL;
} }

View File

@ -199,7 +199,7 @@ static Local<Object> AcceptHandle(uv_stream_t* pipe) {
return Local<Object>(); return Local<Object>();
wrap = static_cast<WrapType*>( wrap = static_cast<WrapType*>(
wrap_obj->GetPointerFromInternalField(0)); wrap_obj->GetAlignedPointerFromInternalField(0));
handle = wrap->UVHandle(); handle = wrap->UVHandle();
if (uv_accept(pipe, reinterpret_cast<uv_stream_t*>(handle))) if (uv_accept(pipe, reinterpret_cast<uv_stream_t*>(handle)))
@ -436,7 +436,7 @@ Handle<Value> StreamWrap::WriteStringImpl(const Arguments& args) {
Local<Object> send_handle_obj = args[1]->ToObject(); Local<Object> send_handle_obj = args[1]->ToObject();
assert(send_handle_obj->InternalFieldCount() > 0); assert(send_handle_obj->InternalFieldCount() > 0);
HandleWrap* send_handle_wrap = static_cast<HandleWrap*>( HandleWrap* send_handle_wrap = static_cast<HandleWrap*>(
send_handle_obj->GetPointerFromInternalField(0)); send_handle_obj->GetAlignedPointerFromInternalField(0));
send_handle = send_handle_wrap->GetHandle(); send_handle = send_handle_wrap->GetHandle();
// Reference StreamWrap instance to prevent it from being garbage // Reference StreamWrap instance to prevent it from being garbage

View File

@ -118,7 +118,7 @@ void TCPWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "setSimultaneousAccepts", SetSimultaneousAccepts); NODE_SET_PROTOTYPE_METHOD(t, "setSimultaneousAccepts", SetSimultaneousAccepts);
#endif #endif
tcpConstructor = Persistent<Function>::New(t->GetFunction()); tcpConstructor = Persistent<Function>::New(node_isolate, t->GetFunction());
onconnection_sym = NODE_PSYMBOL("onconnection"); onconnection_sym = NODE_PSYMBOL("onconnection");
oncomplete_sym = NODE_PSYMBOL("oncomplete"); oncomplete_sym = NODE_PSYMBOL("oncomplete");
@ -130,7 +130,7 @@ void TCPWrap::Initialize(Handle<Object> target) {
TCPWrap* TCPWrap::Unwrap(Local<Object> obj) { TCPWrap* TCPWrap::Unwrap(Local<Object> obj) {
assert(!obj.IsEmpty()); assert(!obj.IsEmpty());
assert(obj->InternalFieldCount() > 0); assert(obj->InternalFieldCount() > 0);
return static_cast<TCPWrap*>(obj->GetPointerFromInternalField(0)); return static_cast<TCPWrap*>(obj->GetAlignedPointerFromInternalField(0));
} }
@ -327,7 +327,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
// Unwrap the client javascript object. // Unwrap the client javascript object.
assert(client_obj->InternalFieldCount() > 0); assert(client_obj->InternalFieldCount() > 0);
TCPWrap* client_wrap = static_cast<TCPWrap*>( TCPWrap* client_wrap = static_cast<TCPWrap*>(
client_obj->GetPointerFromInternalField(0)); client_obj->GetAlignedPointerFromInternalField(0));
if (uv_accept(handle, (uv_stream_t*)&client_wrap->handle_)) return; if (uv_accept(handle, (uv_stream_t*)&client_wrap->handle_)) return;

View File

@ -88,7 +88,7 @@ void TTYWrap::Initialize(Handle<Object> target) {
TTYWrap* TTYWrap::Unwrap(Local<Object> obj) { TTYWrap* TTYWrap::Unwrap(Local<Object> obj) {
assert(!obj.IsEmpty()); assert(!obj.IsEmpty());
assert(obj->InternalFieldCount() > 0); assert(obj->InternalFieldCount() > 0);
return static_cast<TTYWrap*>(obj->GetPointerFromInternalField(0)); return static_cast<TTYWrap*>(obj->GetAlignedPointerFromInternalField(0));
} }

View File

@ -123,8 +123,8 @@ void UDPWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "ref", HandleWrap::Ref); NODE_SET_PROTOTYPE_METHOD(t, "ref", HandleWrap::Ref);
NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref); NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref);
constructor = Persistent<Function>::New( constructor = Persistent<Function>::New(node_isolate,
Persistent<FunctionTemplate>::New(t)->GetFunction()); Persistent<FunctionTemplate>::New(node_isolate, t)->GetFunction());
target->Set(String::NewSymbol("UDP"), constructor); target->Set(String::NewSymbol("UDP"), constructor);
} }
@ -427,7 +427,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
UDPWrap* UDPWrap::Unwrap(Local<Object> obj) { UDPWrap* UDPWrap::Unwrap(Local<Object> obj) {
assert(!obj.IsEmpty()); assert(!obj.IsEmpty());
assert(obj->InternalFieldCount() > 0); assert(obj->InternalFieldCount() > 0);
return static_cast<UDPWrap*>(obj->GetPointerFromInternalField(0)); return static_cast<UDPWrap*>(obj->GetAlignedPointerFromInternalField(0));
} }

View File

@ -48,7 +48,7 @@ class ArrayBuffer {
return ft_cache; return ft_cache;
v8::HandleScope scope; v8::HandleScope scope;
ft_cache = v8::Persistent<v8::FunctionTemplate>::New( ft_cache = v8::Persistent<v8::FunctionTemplate>::New(node::node_isolate,
v8::FunctionTemplate::New(&ArrayBuffer::V8New)); v8::FunctionTemplate::New(&ArrayBuffer::V8New));
ft_cache->SetClassName(v8::String::New("ArrayBuffer")); ft_cache->SetClassName(v8::String::New("ArrayBuffer"));
v8::Local<v8::ObjectTemplate> instance = ft_cache->InstanceTemplate(); v8::Local<v8::ObjectTemplate> instance = ft_cache->InstanceTemplate();
@ -69,7 +69,9 @@ class ArrayBuffer {
} }
private: private:
static void WeakCallback(v8::Persistent<v8::Value> value, void* data) { static void WeakCallback(v8::Isolate* env,
v8::Persistent<v8::Value> value,
void* data) {
v8::Object* obj = v8::Object::Cast(*value); v8::Object* obj = v8::Object::Cast(*value);
void* ptr = obj->GetIndexedPropertiesExternalArrayData(); void* ptr = obj->GetIndexedPropertiesExternalArrayData();
@ -78,10 +80,10 @@ class ArrayBuffer {
int size = int size =
obj->GetIndexedPropertiesExternalArrayDataLength() * element_size; obj->GetIndexedPropertiesExternalArrayDataLength() * element_size;
v8::V8::AdjustAmountOfExternalAllocatedMemory(-size); node::node_isolate->AdjustAmountOfExternalAllocatedMemory(-size);
value.ClearWeak(); value.ClearWeak(env);
value.Dispose(); value.Dispose(env);
free(ptr); free(ptr);
} }
@ -108,7 +110,7 @@ class ArrayBuffer {
if (!buf) if (!buf)
return ThrowError("Unable to allocate ArrayBuffer."); return ThrowError("Unable to allocate ArrayBuffer.");
args.This()->SetPointerInInternalField(0, buf); args.This()->SetAlignedPointerInInternalField(0, buf);
args.This()->Set(v8::String::New("byteLength"), args.This()->Set(v8::String::New("byteLength"),
v8::Integer::NewFromUnsigned(num_bytes), v8::Integer::NewFromUnsigned(num_bytes),
@ -121,11 +123,11 @@ class ArrayBuffer {
args.This()->SetIndexedPropertiesToExternalArrayData( args.This()->SetIndexedPropertiesToExternalArrayData(
buf, v8::kExternalUnsignedByteArray, num_bytes); buf, v8::kExternalUnsignedByteArray, num_bytes);
v8::V8::AdjustAmountOfExternalAllocatedMemory(num_bytes); node::node_isolate->AdjustAmountOfExternalAllocatedMemory(num_bytes);
v8::Persistent<v8::Object> persistent = v8::Persistent<v8::Object> persistent =
v8::Persistent<v8::Object>::New(args.This()); v8::Persistent<v8::Object>::New(node::node_isolate, args.This());
persistent.MakeWeak(NULL, &ArrayBuffer::WeakCallback); persistent.MakeWeak(node::node_isolate, NULL, &ArrayBuffer::WeakCallback);
return args.This(); return args.This();
} }
@ -159,8 +161,8 @@ class ArrayBuffer {
if (buffer.IsEmpty()) return v8::Undefined(); // constructor failed if (buffer.IsEmpty()) return v8::Undefined(); // constructor failed
void* src = args.This()->GetPointerFromInternalField(0); void* src = args.This()->GetAlignedPointerFromInternalField(0);
void* dest = buffer->GetPointerFromInternalField(0); void* dest = buffer->GetAlignedPointerFromInternalField(0);
memcpy(dest, static_cast<char*>(src) + begin, slice_length); memcpy(dest, static_cast<char*>(src) + begin, slice_length);
return buffer; return buffer;
@ -204,7 +206,7 @@ class TypedArray {
return ft_cache; return ft_cache;
v8::HandleScope scope; v8::HandleScope scope;
ft_cache = v8::Persistent<v8::FunctionTemplate>::New( ft_cache = v8::Persistent<v8::FunctionTemplate>::New(node::node_isolate,
v8::FunctionTemplate::New(&TypedArray<TBytes, TEAType>::V8New)); v8::FunctionTemplate::New(&TypedArray<TBytes, TEAType>::V8New));
ft_cache->SetClassName(v8::String::New(TEANameTrait<TEAType>::name)); ft_cache->SetClassName(v8::String::New(TEANameTrait<TEAType>::name));
v8::Local<v8::ObjectTemplate> instance = ft_cache->InstanceTemplate(); v8::Local<v8::ObjectTemplate> instance = ft_cache->InstanceTemplate();
@ -298,7 +300,7 @@ class TypedArray {
GetFunction()->NewInstance(1, argv); GetFunction()->NewInstance(1, argv);
if (buffer.IsEmpty()) return v8::Undefined(); // constructor failed if (buffer.IsEmpty()) return v8::Undefined(); // constructor failed
void* buf = buffer->GetPointerFromInternalField(0); void* buf = buffer->GetAlignedPointerFromInternalField(0);
args.This()->SetIndexedPropertiesToExternalArrayData( args.This()->SetIndexedPropertiesToExternalArrayData(
buf, TEAType, length); buf, TEAType, length);
// TODO(deanm): check for failure. // TODO(deanm): check for failure.
@ -327,7 +329,7 @@ class TypedArray {
GetFunction()->NewInstance(1, argv); GetFunction()->NewInstance(1, argv);
if (buffer.IsEmpty()) return v8::Undefined(); // constructor failed if (buffer.IsEmpty()) return v8::Undefined(); // constructor failed
void* buf = buffer->GetPointerFromInternalField(0); void* buf = buffer->GetAlignedPointerFromInternalField(0);
args.This()->SetIndexedPropertiesToExternalArrayData( args.This()->SetIndexedPropertiesToExternalArrayData(
buf, TEAType, length); buf, TEAType, length);
// TODO(deanm): check for failure. // TODO(deanm): check for failure.
@ -569,7 +571,7 @@ class DataView {
return ft_cache; return ft_cache;
v8::HandleScope scope; v8::HandleScope scope;
ft_cache = v8::Persistent<v8::FunctionTemplate>::New( ft_cache = v8::Persistent<v8::FunctionTemplate>::New(node::node_isolate,
v8::FunctionTemplate::New(&DataView::V8New)); v8::FunctionTemplate::New(&DataView::V8New));
ft_cache->SetClassName(v8::String::New("DataView")); ft_cache->SetClassName(v8::String::New("DataView"));
v8::Local<v8::ObjectTemplate> instance = ft_cache->InstanceTemplate(); v8::Local<v8::ObjectTemplate> instance = ft_cache->InstanceTemplate();

View File

@ -3,7 +3,7 @@ Exiting with code=1
assert.js:* assert.js:*
throw new assert.AssertionError({ throw new assert.AssertionError({
^ ^
AssertionError: 1 == 2 AssertionError
at Object.<anonymous> (*test*message*error_exit.js:*:*) at Object.<anonymous> (*test*message*error_exit.js:*:*)
at Module._compile (module.js:*:*) at Module._compile (module.js:*:*)
at Object.Module._extensions..js (module.js:*:*) at Object.Module._extensions..js (module.js:*:*)

View File

@ -25,6 +25,8 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
Error.stackTraceLimit = 0;
common.error('before'); common.error('before');
// stack overflow // stack overflow

View File

@ -1,6 +1,6 @@
before before
*test*message*stack_overflow.js:31 *test*message*stack_overflow.js:*
function stackOverflow() { function stackOverflow() {
^ ^
RangeError: Maximum call stack size exceeded RangeError: Maximum call stack size exceeded