diff options
Diffstat (limited to 'src/handle_wrap.cc')
-rw-r--r-- | src/handle_wrap.cc | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index cf3768ace..6860231ca 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -25,20 +25,17 @@ namespace node { -using v8::Arguments; -using v8::Function; +using v8::FunctionCallbackInfo; using v8::Handle; using v8::HandleScope; +using v8::Local; using v8::Object; -using v8::Persistent; using v8::String; -using v8::Undefined; using v8::Value; - // defined in node.cc extern QUEUE handle_wrap_queue; -static Persistent<String> close_sym; +static Cached<String> close_sym; void HandleWrap::Initialize(Handle<Object> target) { @@ -46,7 +43,7 @@ void HandleWrap::Initialize(Handle<Object> target) { } -Handle<Value> HandleWrap::Ref(const Arguments& args) { +void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); UNWRAP_NO_ABORT(HandleWrap) @@ -55,12 +52,10 @@ Handle<Value> HandleWrap::Ref(const Arguments& args) { uv_ref(wrap->handle__); wrap->flags_ &= ~kUnref; } - - return v8::Undefined(node_isolate); } -Handle<Value> HandleWrap::Unref(const Arguments& args) { +void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); UNWRAP_NO_ABORT(HandleWrap) @@ -69,33 +64,27 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) { uv_unref(wrap->handle__); wrap->flags_ |= kUnref; } - - return v8::Undefined(node_isolate); } -Handle<Value> HandleWrap::Close(const Arguments& args) { +void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); HandleWrap *wrap = static_cast<HandleWrap*>( args.This()->GetAlignedPointerFromInternalField(0)); // guard against uninitialized handle or double close - if (wrap == NULL || wrap->handle__ == NULL) { - return Undefined(node_isolate); - } + if (wrap == NULL || wrap->handle__ == NULL) return; - assert(!wrap->object_.IsEmpty()); + assert(!wrap->persistent().IsEmpty()); uv_close(wrap->handle__, OnClose); wrap->handle__ = NULL; if (args[0]->IsFunction()) { - if (close_sym.IsEmpty() == true) close_sym = NODE_PSYMBOL("close"); - wrap->object_->Set(close_sym, args[0]); + if (close_sym.IsEmpty() == true) close_sym = String::New("close"); + wrap->object()->Set(close_sym, args[0]); wrap->flags_ |= kCloseCallback; } - - return Undefined(node_isolate); } @@ -105,16 +94,16 @@ HandleWrap::HandleWrap(Handle<Object> object, uv_handle_t* h) { handle__->data = this; HandleScope scope(node_isolate); - assert(object_.IsEmpty()); + assert(persistent().IsEmpty()); assert(object->InternalFieldCount() > 0); - object_ = v8::Persistent<v8::Object>::New(node_isolate, object); - object_->SetAlignedPointerInInternalField(0, this); + persistent().Reset(node_isolate, object); + object->SetAlignedPointerInInternalField(0, this); QUEUE_INSERT_TAIL(&handle_wrap_queue, &handle_wrap_queue_); } HandleWrap::~HandleWrap() { - assert(object_.IsEmpty()); + assert(persistent().IsEmpty()); QUEUE_REMOVE(&handle_wrap_queue_); } @@ -123,20 +112,21 @@ void HandleWrap::OnClose(uv_handle_t* handle) { HandleWrap* wrap = static_cast<HandleWrap*>(handle->data); // The wrap object should still be there. - assert(wrap->object_.IsEmpty() == false); + assert(wrap->persistent().IsEmpty() == false); // But the handle pointer should be gone. assert(wrap->handle__ == NULL); + HandleScope scope(node_isolate); + Local<Object> object = wrap->object(); + if (wrap->flags_ & kCloseCallback) { assert(close_sym.IsEmpty() == false); - MakeCallback(wrap->object_, close_sym, 0, NULL); + MakeCallback(object, close_sym, 0, NULL); } - wrap->object_->SetAlignedPointerInInternalField(0, NULL); - wrap->object_.Dispose(node_isolate); - wrap->object_.Clear(); - + object->SetAlignedPointerInInternalField(0, NULL); + wrap->persistent().Dispose(); delete wrap; } |