Permalink
Browse files

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.
  • Loading branch information...
trevnorris authored and bnoordhuis committed Mar 18, 2013
1 parent 06bec0e commit 0bba59028381c146b90411d43425a18415d85f98
View
@@ -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;
}
View
@@ -272,15 +272,15 @@ class QueryWrap {
QueryWrap() {
HandleScope scope;
- object_ = Persistent<Object>::New(Object::New());
+ object_ = Persistent<Object>::New(node_isolate, Object::New());
}
virtual ~QueryWrap() {
assert(!object_.IsEmpty());
object_->Delete(oncomplete_sym);
- object_.Dispose();
+ object_.Dispose(node_isolate);
object_.Clear();
}
View
@@ -74,7 +74,8 @@ void FSEventWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "close", Close);
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.
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<FSEventWrap*>(ptr);
if (wrap == NULL || wrap->initialized_ == false) {
View
@@ -84,7 +84,7 @@ Handle<Value> HandleWrap::Close(const Arguments& args) {
HandleScope scope;
HandleWrap *wrap = static_cast<HandleWrap*>(
- 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> object, uv_handle_t* h) {
HandleScope scope;
assert(object_.IsEmpty());
assert(object->InternalFieldCount() > 0);
- object_ = v8::Persistent<v8::Object>::New(object);
- object_->SetPointerInInternalField(0, this);
+ object_ = v8::Persistent<v8::Object>::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;
View
@@ -50,7 +50,7 @@ namespace node {
assert(!args.Holder().IsEmpty()); \
assert(args.Holder()->InternalFieldCount() > 0); \
type* wrap = static_cast<type*>( \
- args.Holder()->GetPointerFromInternalField(0));
+ args.Holder()->GetAlignedPointerFromInternalField(0));
class HandleWrap {
public:
View
@@ -195,7 +195,7 @@ static void Spin(uv_idle_t* handle, int status) {
abort();
}
Local<Function> cb = cb_v.As<Function>();
- process_tickFromSpinner = Persistent<Function>::New(cb);
+ process_tickFromSpinner = Persistent<Function>::New(node_isolate, cb);
}
TryCatch try_catch;
@@ -912,7 +912,7 @@ MakeDomainCallback(const Handle<Object> object,
abort();
}
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
@@ -1002,7 +1002,7 @@ MakeCallback(const Handle<Object> object,
abort();
}
Local<Function> cb = cb_v.As<Function>();
- process_tickCallback = Persistent<Function>::New(cb);
+ process_tickCallback = Persistent<Function>::New(node_isolate, cb);
}
TryCatch try_catch;
@@ -1802,7 +1802,7 @@ v8::Handle<v8::Value> 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<Value> Binding(const Arguments& args) {
node_module_struct* modp;
if (binding_cache.IsEmpty()) {
- binding_cache = Persistent<Object>::New(Object::New());
+ binding_cache = Persistent<Object>::New(node_isolate, Object::New());
}
Local<Object> exports;
@@ -2307,7 +2307,8 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
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"),
ProcessTitleGetter,
@@ -2317,7 +2318,7 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
process->Set(String::NewSymbol("version"), String::New(NODE_VERSION));
// 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.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
}
View
@@ -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<v8::Object> process);
void EmitExit(v8::Handle<v8::Object> process);
#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 */
#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(
const v8::Local<v8::Value> &v) {
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;
}
@@ -165,7 +167,7 @@ static inline v8::Persistent<v8::Function>* cb_unwrap(void *data) {
}
static inline void cb_destroy(v8::Persistent<v8::Function> * cb) {
- cb->Dispose();
+ cb->Dispose(node_isolate);
delete cb;
}
View
@@ -187,7 +187,7 @@ Buffer::Buffer(Handle<Object> 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<intptr_t>(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<Value> val) {
Handle<Value> SetFastBufferConstructor(const Arguments& args) {
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();
}
@@ -1117,7 +1119,7 @@ void Buffer::Initialize(Handle<Object> target) {
chars_written_sym = NODE_PSYMBOL("_charsWritten");
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->SetClassName(String::NewSymbol("SlowBuffer"));
View
@@ -122,7 +122,7 @@ void InitPerfCounters(Handle<Object> target) {
};
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));
target->Set(String::NewSymbol(tab[i].name), tab[i].templ->GetFunction());
}
Oops, something went wrong.

0 comments on commit 0bba590

Please sign in to comment.