From 22c3a1e2a5cb9b6fa06e822af74f54c39e4eb61c Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 10 Jul 2009 13:57:05 +0200 Subject: [PATCH] Templatize ObjectWrap::Unwrap. Remove NODE_UNWRAP macro. --- src/http.cc | 2 +- src/net.cc | 20 ++++++++++---------- src/object_wrap.h | 13 ++++++------- src/process.cc | 10 +++++----- src/timer.cc | 8 ++++---- 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/http.cc b/src/http.cc index 6261a90a6a..958ff991ef 100644 --- a/src/http.cc +++ b/src/http.cc @@ -256,6 +256,6 @@ Connection* HTTPServer::UnwrapConnection (Local connection) { HandleScope scope; - return NODE_UNWRAP(HTTPConnection, connection); + return ObjectWrap::Unwrap(connection); } diff --git a/src/net.cc b/src/net.cc index 61bcbb4abe..4118db1f62 100644 --- a/src/net.cc +++ b/src/net.cc @@ -77,7 +77,7 @@ Connection::Initialize (v8::Handle target) Handle Connection::ReadyStateGetter (Local property, const AccessorInfo& info) { - Connection *connection = NODE_UNWRAP(Connection, info.This()); + Connection *connection = ObjectWrap::Unwrap(info.This()); if (!connection) return Handle(); HandleScope scope; @@ -159,7 +159,7 @@ Connection::ReadyState (void) Handle Connection::Connect (const Arguments& args) { - Connection *connection = NODE_UNWRAP(Connection, args.Holder()); + Connection *connection = ObjectWrap::Unwrap(args.Holder()); if (!connection) return Handle(); HandleScope scope; @@ -295,7 +295,7 @@ Connection::SetEncoding (const Arguments& args) { HandleScope scope; - Connection *connection = NODE_UNWRAP(Connection, args.This()); + Connection *connection = ObjectWrap::Unwrap(args.This()); if (!connection) return Handle(); if (!args[0]->IsString()) { @@ -323,7 +323,7 @@ Handle Connection::Close (const Arguments& args) { HandleScope scope; - Connection *connection = NODE_UNWRAP(Connection, args.Holder()); + Connection *connection = ObjectWrap::Unwrap(args.Holder()); if (!connection) return Handle(); connection->Close(); @@ -334,7 +334,7 @@ Handle Connection::FullClose (const Arguments& args) { HandleScope scope; - Connection *connection = NODE_UNWRAP(Connection, args.Holder()); + Connection *connection = ObjectWrap::Unwrap(args.Holder()); if (!connection) return Handle(); connection->FullClose(); @@ -345,7 +345,7 @@ Handle Connection::ForceClose (const Arguments& args) { HandleScope scope; - Connection *connection = NODE_UNWRAP(Connection, args.Holder()); + Connection *connection = ObjectWrap::Unwrap(args.Holder()); if (!connection) return Handle(); connection->ForceClose(); @@ -358,7 +358,7 @@ Handle Connection::Send (const Arguments& args) { HandleScope scope; - Connection *connection = NODE_UNWRAP(Connection, args.Holder()); + Connection *connection = ObjectWrap::Unwrap(args.Holder()); if (!connection) return Handle(); if ( connection->ReadyState() != OPEN @@ -513,7 +513,7 @@ Connection* Server::UnwrapConnection (Local connection) { HandleScope scope; - return NODE_UNWRAP(Connection, connection); + return ObjectWrap::Unwrap(connection); } Connection* @@ -566,7 +566,7 @@ Server::New (const Arguments& args) Handle Server::Listen (const Arguments& args) { - Server *server = NODE_UNWRAP(Server, args.Holder()); + Server *server = ObjectWrap::Unwrap(args.Holder()); if (!server) return Handle(); if (args.Length() == 0) @@ -603,7 +603,7 @@ Server::Listen (const Arguments& args) Handle Server::Close (const Arguments& args) { - Server *server = NODE_UNWRAP(Server, args.Holder()); + Server *server = ObjectWrap::Unwrap(args.Holder()); if (!server) return Handle(); server->Close(); diff --git a/src/object_wrap.h b/src/object_wrap.h index 619cda151b..b96fc364a6 100644 --- a/src/object_wrap.h +++ b/src/object_wrap.h @@ -6,10 +6,8 @@ namespace node { -#define NODE_UNWRAP(type, value) static_cast(node::ObjectWrap::Unwrap(value)) - class ObjectWrap { -public: + public: ObjectWrap ( ) { weak_ = false; attached_ = false; @@ -24,12 +22,13 @@ public: } protected: - static inline void* Unwrap (v8::Handle handle) + template + static inline T* Unwrap (v8::Handle handle) { assert(!handle.IsEmpty()); - assert(handle->InternalFieldCount() == 1); - return v8::Handle::Cast( - handle->GetInternalField(0))->Value(); + assert(handle->InternalFieldCount() > 0); + return static_cast(v8::Handle::Cast( + handle->GetInternalField(0))->Value()); } inline void Wrap(v8::Handle handle) diff --git a/src/process.cc b/src/process.cc index de930813cf..db0735a209 100644 --- a/src/process.cc +++ b/src/process.cc @@ -64,7 +64,7 @@ Process::Spawn (const Arguments& args) } HandleScope scope; - Process *process = NODE_UNWRAP(Process, args.Holder()); + Process *process = ObjectWrap::Unwrap(args.Holder()); String::Utf8Value command(args[0]->ToString()); @@ -80,7 +80,7 @@ Handle Process::PIDGetter (Local property, const AccessorInfo& info) { HandleScope scope; - Process *process = NODE_UNWRAP(Process, info.This()); + Process *process = ObjectWrap::Unwrap(info.This()); assert(process); assert(property == PID_SYMBOL); @@ -95,7 +95,7 @@ Handle Process::Write (const Arguments& args) { HandleScope scope; - Process *process = NODE_UNWRAP(Process, args.Holder()); + Process *process = ObjectWrap::Unwrap(args.Holder()); assert(process); // XXX @@ -146,7 +146,7 @@ Handle Process::Kill (const Arguments& args) { HandleScope scope; - Process *process = NODE_UNWRAP(Process, args.Holder()); + Process *process = ObjectWrap::Unwrap(args.Holder()); assert(process); int sig = SIGTERM; @@ -163,7 +163,7 @@ Handle Process::Close (const Arguments& args) { HandleScope scope; - Process *process = NODE_UNWRAP(Process, args.Holder()); + Process *process = ObjectWrap::Unwrap(args.Holder()); assert(process); return process->Close() == 0 ? True() : False(); } diff --git a/src/timer.cc b/src/timer.cc index 0f60fb6c14..14be30dea2 100644 --- a/src/timer.cc +++ b/src/timer.cc @@ -32,7 +32,7 @@ Handle Timer::RepeatGetter (Local property, const AccessorInfo& info) { HandleScope scope; - Timer *timer = NODE_UNWRAP(Timer, info.This()); + Timer *timer = ObjectWrap::Unwrap(info.This()); assert(timer); assert (property == REPEAT_SYMBOL); @@ -46,7 +46,7 @@ void Timer::RepeatSetter (Local property, Local value, const AccessorInfo& info) { HandleScope scope; - Timer *timer = NODE_UNWRAP(Timer, info.This()); + Timer *timer = ObjectWrap::Unwrap(info.This()); assert(timer); assert(property == REPEAT_SYMBOL); @@ -90,7 +90,7 @@ Timer::New (const Arguments& args) Handle Timer::Start (const Arguments& args) { - Timer *timer = NODE_UNWRAP(Timer, args.Holder()); + Timer *timer = ObjectWrap::Unwrap(args.Holder()); HandleScope scope; if (args.Length() != 2) @@ -111,7 +111,7 @@ Timer::Start (const Arguments& args) Handle Timer::Stop (const Arguments& args) { - Timer *timer = NODE_UNWRAP(Timer, args.Holder()); + Timer *timer = ObjectWrap::Unwrap(args.Holder()); ev_timer_stop(EV_DEFAULT_UC_ &timer->watcher_); timer->Detach(); return Undefined();