From 448adaa4563fb035c5fccfe4a9a0cc74b5ca5ba0 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 26 May 2013 20:04:17 +0200 Subject: [PATCH] src: simplify HandleWrap initialization --- src/fs_event_wrap.cc | 1 - src/handle_wrap.cc | 10 +--------- src/handle_wrap.h | 2 -- src/pipe_wrap.cc | 1 - src/process_wrap.cc | 9 ++++++--- src/stream_wrap.cc | 10 ---------- src/stream_wrap.h | 1 - src/timer_wrap.cc | 1 - src/udp_wrap.cc | 1 - 9 files changed, 7 insertions(+), 29 deletions(-) diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 69d3b155e6..f767db037c 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -53,7 +53,6 @@ private: FSEventWrap::FSEventWrap(Handle object) : HandleWrap(object, reinterpret_cast(&handle_)) { - handle_.data = static_cast(this); initialized_ = false; } diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 07f19ad222..390f686425 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -108,9 +108,7 @@ Handle HandleWrap::Close(const Arguments& args) { HandleWrap::HandleWrap(Handle object, uv_handle_t* h) { flags_ = 0; handle__ = h; - if (h) { - h->data = this; - } + handle__->data = this; HandleScope scope(node_isolate); assert(object_.IsEmpty()); @@ -121,12 +119,6 @@ HandleWrap::HandleWrap(Handle object, uv_handle_t* h) { } -void HandleWrap::SetHandle(uv_handle_t* h) { - handle__ = h; - h->data = this; -} - - HandleWrap::~HandleWrap() { assert(object_.IsEmpty()); ngx_queue_remove(&handle_wrap_queue_); diff --git a/src/handle_wrap.h b/src/handle_wrap.h index fcd9fb2cc7..d77485cdf6 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -65,8 +65,6 @@ class HandleWrap { HandleWrap(v8::Handle object, uv_handle_t* handle); virtual ~HandleWrap(); - virtual void SetHandle(uv_handle_t* h); - v8::Persistent object_; private: diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index dd2cbd6fb1..6449eebab9 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -139,7 +139,6 @@ PipeWrap::PipeWrap(Handle object, bool ipc) int r = uv_pipe_init(uv_default_loop(), &handle_, ipc); assert(r == 0); // How do we proxy this error up to javascript? // Suggestion: uv_pipe_init() returns void. - handle_.data = static_cast(this); UpdateWriteQueueSize(); } diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 8ed8976f77..02984976d2 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -87,8 +87,12 @@ class ProcessWrap : public HandleWrap { return scope.Close(args.This()); } - ProcessWrap(Handle object) : HandleWrap(object, NULL) { } - ~ProcessWrap() { } + ProcessWrap(Handle object) + : HandleWrap(object, reinterpret_cast(&process_)) { + } + + ~ProcessWrap() { + } static void ParseStdioOptions(Local js_options, uv_process_options_t* options) { @@ -248,7 +252,6 @@ class ProcessWrap : public HandleWrap { SetErrno(uv_last_error(uv_default_loop())); } else { - wrap->SetHandle(reinterpret_cast(&wrap->process_)); assert(wrap->process_.data == wrap); wrap->object_->Set(String::New("pid"), Integer::New(wrap->process_.pid, node_isolate)); diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index aaf4491c4e..61527ed0a3 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -112,9 +112,6 @@ void StreamWrap::Initialize(Handle target) { StreamWrap::StreamWrap(Handle object, uv_stream_t* stream) : HandleWrap(object, reinterpret_cast(stream)) { stream_ = stream; - if (stream) { - stream->data = this; - } } @@ -131,13 +128,6 @@ Handle StreamWrap::GetFD(Local, const AccessorInfo& args) { } -void StreamWrap::SetHandle(uv_handle_t* h) { - HandleWrap::SetHandle(h); - stream_ = reinterpret_cast(h); - stream_->data = this; -} - - void StreamWrap::UpdateWriteQueueSize() { HandleScope scope(node_isolate); object_->Set(write_queue_size_sym, diff --git a/src/stream_wrap.h b/src/stream_wrap.h index ff355ed00b..8b58c8af68 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -57,7 +57,6 @@ class StreamWrap : public HandleWrap { static size_t WriteBuffer(v8::Handle val, uv_buf_t* buf); StreamWrap(v8::Handle object, uv_stream_t* stream); - virtual void SetHandle(uv_handle_t* h); void StateChange() { } void UpdateWriteQueueSize(); diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 5e8ab051a6..a36cdabacd 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -86,7 +86,6 @@ class TimerWrap : public HandleWrap { : HandleWrap(object, reinterpret_cast(&handle_)) { int r = uv_timer_init(uv_default_loop(), &handle_); assert(r == 0); - handle_.data = this; } ~TimerWrap() { diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index f014a62cc6..b463a75c83 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -69,7 +69,6 @@ UDPWrap::UDPWrap(Handle object) : HandleWrap(object, reinterpret_cast(&handle_)) { int r = uv_udp_init(uv_default_loop(), &handle_); assert(r == 0); // can't fail anyway - handle_.data = reinterpret_cast(this); }