Browse files

Templatize ObjectWrap::Unwrap. Remove NODE_UNWRAP macro.

  • Loading branch information...
1 parent 1fc4dce commit 22c3a1e2a5cb9b6fa06e822af74f54c39e4eb61c @ry ry committed Jul 10, 2009
Showing with 26 additions and 27 deletions.
  1. +1 −1 src/http.cc
  2. +10 −10 src/net.cc
  3. +6 −7 src/object_wrap.h
  4. +5 −5 src/process.cc
  5. +4 −4 src/timer.cc
View
2 src/http.cc
@@ -256,6 +256,6 @@ Connection*
HTTPServer::UnwrapConnection (Local<Object> connection)
{
HandleScope scope;
- return NODE_UNWRAP(HTTPConnection, connection);
+ return ObjectWrap::Unwrap<HTTPConnection>(connection);
}
View
20 src/net.cc
@@ -77,7 +77,7 @@ Connection::Initialize (v8::Handle<v8::Object> target)
Handle<Value>
Connection::ReadyStateGetter (Local<String> property, const AccessorInfo& info)
{
- Connection *connection = NODE_UNWRAP(Connection, info.This());
+ Connection *connection = ObjectWrap::Unwrap<Connection>(info.This());
if (!connection) return Handle<Value>();
HandleScope scope;
@@ -159,7 +159,7 @@ Connection::ReadyState (void)
Handle<Value>
Connection::Connect (const Arguments& args)
{
- Connection *connection = NODE_UNWRAP(Connection, args.Holder());
+ Connection *connection = ObjectWrap::Unwrap<Connection>(args.Holder());
if (!connection) return Handle<Value>();
HandleScope scope;
@@ -295,7 +295,7 @@ Connection::SetEncoding (const Arguments& args)
{
HandleScope scope;
- Connection *connection = NODE_UNWRAP(Connection, args.This());
+ Connection *connection = ObjectWrap::Unwrap<Connection>(args.This());
if (!connection) return Handle<Value>();
if (!args[0]->IsString()) {
@@ -323,7 +323,7 @@ Handle<Value>
Connection::Close (const Arguments& args)
{
HandleScope scope;
- Connection *connection = NODE_UNWRAP(Connection, args.Holder());
+ Connection *connection = ObjectWrap::Unwrap<Connection>(args.Holder());
if (!connection) return Handle<Value>();
connection->Close();
@@ -334,7 +334,7 @@ Handle<Value>
Connection::FullClose (const Arguments& args)
{
HandleScope scope;
- Connection *connection = NODE_UNWRAP(Connection, args.Holder());
+ Connection *connection = ObjectWrap::Unwrap<Connection>(args.Holder());
if (!connection) return Handle<Value>();
connection->FullClose();
@@ -345,7 +345,7 @@ Handle<Value>
Connection::ForceClose (const Arguments& args)
{
HandleScope scope;
- Connection *connection = NODE_UNWRAP(Connection, args.Holder());
+ Connection *connection = ObjectWrap::Unwrap<Connection>(args.Holder());
if (!connection) return Handle<Value>();
connection->ForceClose();
@@ -358,7 +358,7 @@ Handle<Value>
Connection::Send (const Arguments& args)
{
HandleScope scope;
- Connection *connection = NODE_UNWRAP(Connection, args.Holder());
+ Connection *connection = ObjectWrap::Unwrap<Connection>(args.Holder());
if (!connection) return Handle<Value>();
if ( connection->ReadyState() != OPEN
@@ -513,7 +513,7 @@ Connection*
Server::UnwrapConnection (Local<Object> connection)
{
HandleScope scope;
- return NODE_UNWRAP(Connection, connection);
+ return ObjectWrap::Unwrap<Connection>(connection);
}
Connection*
@@ -566,7 +566,7 @@ Server::New (const Arguments& args)
Handle<Value>
Server::Listen (const Arguments& args)
{
- Server *server = NODE_UNWRAP(Server, args.Holder());
+ Server *server = ObjectWrap::Unwrap<Server>(args.Holder());
if (!server) return Handle<Value>();
if (args.Length() == 0)
@@ -603,7 +603,7 @@ Server::Listen (const Arguments& args)
Handle<Value>
Server::Close (const Arguments& args)
{
- Server *server = NODE_UNWRAP(Server, args.Holder());
+ Server *server = ObjectWrap::Unwrap<Server>(args.Holder());
if (!server) return Handle<Value>();
server->Close();
View
13 src/object_wrap.h
@@ -6,10 +6,8 @@
namespace node {
-#define NODE_UNWRAP(type, value) static_cast<type*>(node::ObjectWrap::Unwrap(value))
-
class ObjectWrap {
-public:
+ public:
ObjectWrap ( ) {
weak_ = false;
attached_ = false;
@@ -24,12 +22,13 @@ class ObjectWrap {
}
protected:
- static inline void* Unwrap (v8::Handle<v8::Object> handle)
+ template <class T>
+ static inline T* Unwrap (v8::Handle<v8::Object> handle)
{
assert(!handle.IsEmpty());
- assert(handle->InternalFieldCount() == 1);
- return v8::Handle<v8::External>::Cast(
- handle->GetInternalField(0))->Value();
+ assert(handle->InternalFieldCount() > 0);
+ return static_cast<T*>(v8::Handle<v8::External>::Cast(
+ handle->GetInternalField(0))->Value());
}
inline void Wrap(v8::Handle<v8::Object> handle)
View
10 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<Process>(args.Holder());
String::Utf8Value command(args[0]->ToString());
@@ -80,7 +80,7 @@ Handle<Value>
Process::PIDGetter (Local<String> property, const AccessorInfo& info)
{
HandleScope scope;
- Process *process = NODE_UNWRAP(Process, info.This());
+ Process *process = ObjectWrap::Unwrap<Process>(info.This());
assert(process);
assert(property == PID_SYMBOL);
@@ -95,7 +95,7 @@ Handle<Value>
Process::Write (const Arguments& args)
{
HandleScope scope;
- Process *process = NODE_UNWRAP(Process, args.Holder());
+ Process *process = ObjectWrap::Unwrap<Process>(args.Holder());
assert(process);
// XXX
@@ -146,7 +146,7 @@ Handle<Value>
Process::Kill (const Arguments& args)
{
HandleScope scope;
- Process *process = NODE_UNWRAP(Process, args.Holder());
+ Process *process = ObjectWrap::Unwrap<Process>(args.Holder());
assert(process);
int sig = SIGTERM;
@@ -163,7 +163,7 @@ Handle<Value>
Process::Close (const Arguments& args)
{
HandleScope scope;
- Process *process = NODE_UNWRAP(Process, args.Holder());
+ Process *process = ObjectWrap::Unwrap<Process>(args.Holder());
assert(process);
return process->Close() == 0 ? True() : False();
}
View
8 src/timer.cc
@@ -32,7 +32,7 @@ Handle<Value>
Timer::RepeatGetter (Local<String> property, const AccessorInfo& info)
{
HandleScope scope;
- Timer *timer = NODE_UNWRAP(Timer, info.This());
+ Timer *timer = ObjectWrap::Unwrap<Timer>(info.This());
assert(timer);
assert (property == REPEAT_SYMBOL);
@@ -46,7 +46,7 @@ void
Timer::RepeatSetter (Local<String> property, Local<Value> value, const AccessorInfo& info)
{
HandleScope scope;
- Timer *timer = NODE_UNWRAP(Timer, info.This());
+ Timer *timer = ObjectWrap::Unwrap<Timer>(info.This());
assert(timer);
assert(property == REPEAT_SYMBOL);
@@ -90,7 +90,7 @@ Timer::New (const Arguments& args)
Handle<Value>
Timer::Start (const Arguments& args)
{
- Timer *timer = NODE_UNWRAP(Timer, args.Holder());
+ Timer *timer = ObjectWrap::Unwrap<Timer>(args.Holder());
HandleScope scope;
if (args.Length() != 2)
@@ -111,7 +111,7 @@ Timer::Start (const Arguments& args)
Handle<Value>
Timer::Stop (const Arguments& args)
{
- Timer *timer = NODE_UNWRAP(Timer, args.Holder());
+ Timer *timer = ObjectWrap::Unwrap<Timer>(args.Holder());
ev_timer_stop(EV_DEFAULT_UC_ &timer->watcher_);
timer->Detach();
return Undefined();

0 comments on commit 22c3a1e

Please sign in to comment.