src: use function to get internal pointer
authorTrevor Norris <trev.norris@gmail.com>
Tue, 29 Oct 2013 19:27:24 +0000 (12:27 -0700)
committerTrevor Norris <trev.norris@gmail.com>
Tue, 29 Oct 2013 22:09:44 +0000 (15:09 -0700)
Remove the NODE_{WRAP,UNWRAP} macros and instead use template functions.

17 files changed:
src/fs_event_wrap.cc
src/handle_wrap.cc
src/node_contextify.cc
src/node_crypto.cc
src/node_internals.h
src/node_stat_watcher.h
src/pipe_wrap.cc
src/process_wrap.cc
src/signal_wrap.cc
src/stream_wrap.cc
src/tcp_wrap.cc
src/timer_wrap.cc
src/tls_wrap.cc
src/tty_wrap.cc
src/udp_wrap.cc
src/util-inl.h
src/util.h

index 63912f4..b663184 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "env.h"
 #include "env-inl.h"
+#include "util.h"
+#include "util-inl.h"
 #include "node.h"
 #include "handle_wrap.h"
 
@@ -98,8 +100,7 @@ void FSEventWrap::New(const FunctionCallbackInfo<Value>& args) {
 void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  FSEventWrap* wrap;
-  NODE_UNWRAP(args.This(), FSEventWrap, wrap);
+  FSEventWrap* wrap = UnwrapObject<FSEventWrap>(args.This());
 
   if (args.Length() < 1 || !args[0]->IsString()) {
     return ThrowTypeError("Bad arguments");
@@ -178,8 +179,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
 void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  FSEventWrap* wrap;
-  NODE_UNWRAP_NO_ABORT(args.This(), FSEventWrap, wrap);
+  FSEventWrap* wrap = UnwrapObject<FSEventWrap>(args.This());
 
   if (wrap == NULL || wrap->initialized_ == false)
     return;
index 9fa2962..71e3953 100644 (file)
@@ -22,6 +22,8 @@
 #include "handle_wrap.h"
 #include "env.h"
 #include "env-inl.h"
+#include "util.h"
+#include "util-inl.h"
 #include "node.h"
 #include "queue.h"
 
@@ -42,8 +44,7 @@ extern QUEUE handle_wrap_queue;
 void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  HandleWrap* wrap;
-  NODE_UNWRAP_NO_ABORT(args.This(), HandleWrap, wrap);
+  HandleWrap* wrap = UnwrapObject<HandleWrap>(args.This());
 
   if (wrap != NULL && wrap->handle__ != NULL) {
     uv_ref(wrap->handle__);
@@ -55,8 +56,7 @@ void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
 void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  HandleWrap* wrap;
-  NODE_UNWRAP_NO_ABORT(args.This(), HandleWrap, wrap);
+  HandleWrap* wrap = UnwrapObject<HandleWrap>(args.This());
 
   if (wrap != NULL && wrap->handle__ != NULL) {
     uv_unref(wrap->handle__);
@@ -68,8 +68,7 @@ void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
 void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  HandleWrap* wrap;
-  NODE_UNWRAP_NO_ABORT(args.This(), HandleWrap, wrap);
+  HandleWrap* wrap = UnwrapObject<HandleWrap>(args.This());
 
   // guard against uninitialized handle or double close
   if (wrap == NULL || wrap->handle__ == NULL)
@@ -96,7 +95,7 @@ HandleWrap::HandleWrap(Environment* env,
   handle__->data = this;
   HandleScope scope(node_isolate);
   persistent().Reset(node_isolate, object);
-  NODE_WRAP(object, this);
+  WrapObject<HandleWrap>(object, this);
   QUEUE_INSERT_TAIL(&handle_wrap_queue, &handle_wrap_queue_);
 }
 
index 80a2ada..1c7484f 100644 (file)
@@ -24,6 +24,8 @@
 #include "node_watchdog.h"
 #include "env.h"
 #include "env-inl.h"
+#include "util.h"
+#include "util-inl.h"
 #include "weak-object.h"
 #include "weak-object-inl.h"
 
@@ -178,7 +180,7 @@ class ContextifyContext {
     HandleScope scope(node_isolate);
     Local<Object> wrapper =
         env->script_data_constructor_function()->NewInstance();
-    NODE_WRAP(wrapper, this);
+    WrapObject<ContextifyContext>(wrapper, this);
     return scope.Close(wrapper);
   }
 
@@ -297,8 +299,8 @@ class ContextifyContext {
       const PropertyCallbackInfo<Value>& args) {
     HandleScope scope(node_isolate);
 
-    ContextifyContext* ctx = NULL;
-    NODE_UNWRAP(args.Data().As<Object>(), ContextifyContext, ctx);
+    ContextifyContext* ctx =
+        UnwrapObject<ContextifyContext>(args.Data().As<Object>());
 
     Local<Object> sandbox = PersistentToLocal(node_isolate, ctx->sandbox_);
     Local<Value> rv = sandbox->GetRealNamedProperty(property);
@@ -321,8 +323,8 @@ class ContextifyContext {
       const PropertyCallbackInfo<Value>& args) {
     HandleScope scope(node_isolate);
 
-    ContextifyContext* ctx = NULL;
-    NODE_UNWRAP(args.Data().As<Object>(), ContextifyContext, ctx);
+    ContextifyContext* ctx =
+        UnwrapObject<ContextifyContext>(args.Data().As<Object>());
 
     PersistentToLocal(node_isolate, ctx->sandbox_)->Set(property, value);
   }
@@ -333,8 +335,8 @@ class ContextifyContext {
       const PropertyCallbackInfo<Integer>& args) {
     HandleScope scope(node_isolate);
 
-    ContextifyContext* ctx = NULL;
-    NODE_UNWRAP(args.Data().As<Object>(), ContextifyContext, ctx);
+    ContextifyContext* ctx =
+        UnwrapObject<ContextifyContext>(args.Data().As<Object>());
 
     Local<Object> sandbox = PersistentToLocal(node_isolate, ctx->sandbox_);
     Local<Object> proxy_global = PersistentToLocal(node_isolate,
@@ -354,8 +356,8 @@ class ContextifyContext {
       const PropertyCallbackInfo<Boolean>& args) {
     HandleScope scope(node_isolate);
 
-    ContextifyContext* ctx = NULL;
-    NODE_UNWRAP(args.Data().As<Object>(), ContextifyContext, ctx);
+    ContextifyContext* ctx =
+        UnwrapObject<ContextifyContext>(args.Data().As<Object>());
 
     bool success = PersistentToLocal(node_isolate,
                                      ctx->sandbox_)->Delete(property);
@@ -371,8 +373,8 @@ class ContextifyContext {
       const PropertyCallbackInfo<Array>& args) {
     HandleScope scope(node_isolate);
 
-    ContextifyContext* ctx = NULL;
-    NODE_UNWRAP(args.Data().As<Object>(), ContextifyContext, ctx);
+    ContextifyContext* ctx =
+        UnwrapObject<ContextifyContext>(args.Data().As<Object>());
 
     Local<Object> sandbox = PersistentToLocal(node_isolate, ctx->sandbox_);
     args.GetReturnValue().Set(sandbox->GetPropertyNames());
index 5051c84..6f1d232 100644 (file)
@@ -30,6 +30,8 @@
 #include "env.h"
 #include "env-inl.h"
 #include "string_bytes.h"
+#include "util.h"
+#include "util-inl.h"
 #include "v8.h"
 
 #include <errno.h>
@@ -761,8 +763,7 @@ void SecureContext::GetTicketKeys(const FunctionCallbackInfo<Value>& args) {
 #if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_CTX_get_tlsext_ticket_keys)
   HandleScope handle_scope(args.GetIsolate());
 
-  SecureContext* wrap;
-  NODE_UNWRAP(args.This(), SecureContext, wrap);
+  SecureContext* wrap = UnwrapObject<SecureContext>(args.This());
 
   Local<Object> buff = Buffer::New(wrap->env(), 48);
   if (SSL_CTX_get_tlsext_ticket_keys(wrap->ctx_,
@@ -786,8 +787,7 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) {
     return ThrowTypeError("Bad argument");
   }
 
-  SecureContext* wrap;
-  NODE_UNWRAP(args.This(), SecureContext, wrap);
+  SecureContext* wrap = UnwrapObject<SecureContext>(args.This());
 
   if (SSL_CTX_set_tlsext_ticket_keys(wrap->ctx_,
                                      Buffer::Data(args[0]),
@@ -915,8 +915,7 @@ void SSLWrap<Base>::GetPeerCertificate(
     const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
   Environment* env = w->env();
 
   Local<Object> info = Object::New();
@@ -1050,8 +1049,7 @@ template <class Base>
 void SSLWrap<Base>::GetSession(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
 
   SSL_SESSION* sess = SSL_get_session(w->ssl_);
   if (sess == NULL)
@@ -1072,8 +1070,7 @@ template <class Base>
 void SSLWrap<Base>::SetSession(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
 
   if (args.Length() < 1 ||
       (!args[0]->IsString() && !Buffer::HasInstance(args[0]))) {
@@ -1111,8 +1108,7 @@ template <class Base>
 void SSLWrap<Base>::LoadSession(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
   Environment* env = w->env();
 
   if (args.Length() >= 1 && Buffer::HasInstance(args[0])) {
@@ -1144,8 +1140,7 @@ void SSLWrap<Base>::LoadSession(const FunctionCallbackInfo<Value>& args) {
 template <class Base>
 void SSLWrap<Base>::IsSessionReused(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
   bool yes = SSL_session_reused(w->ssl_);
   args.GetReturnValue().Set(yes);
 }
@@ -1154,8 +1149,7 @@ void SSLWrap<Base>::IsSessionReused(const FunctionCallbackInfo<Value>& args) {
 template <class Base>
 void SSLWrap<Base>::ReceivedShutdown(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
   bool yes = SSL_get_shutdown(w->ssl_) == SSL_RECEIVED_SHUTDOWN;
   args.GetReturnValue().Set(yes);
 }
@@ -1164,8 +1158,7 @@ void SSLWrap<Base>::ReceivedShutdown(const FunctionCallbackInfo<Value>& args) {
 template <class Base>
 void SSLWrap<Base>::EndParser(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
   w->hello_parser_.End();
 }
 
@@ -1174,8 +1167,7 @@ template <class Base>
 void SSLWrap<Base>::Renegotiate(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
 
   ClearErrorOnReturn clear_error_on_return;
   (void) &clear_error_on_return;  // Silence unused variable warning.
@@ -1188,8 +1180,7 @@ void SSLWrap<Base>::Renegotiate(const FunctionCallbackInfo<Value>& args) {
 template <class Base>
 void SSLWrap<Base>::IsInitFinished(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
   bool yes = SSL_is_init_finished(w->ssl_);
   args.GetReturnValue().Set(yes);
 }
@@ -1200,8 +1191,7 @@ template <class Base>
 void SSLWrap<Base>::VerifyError(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
 
   // XXX(indutny) Do this check in JS land?
   X509* peer_cert = SSL_get_peer_certificate(w->ssl_);
@@ -1267,8 +1257,7 @@ template <class Base>
 void SSLWrap<Base>::GetCurrentCipher(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
   Environment* env = w->env();
 
   OPENSSL_CONST SSL_CIPHER* c = SSL_get_current_cipher(w->ssl_);
@@ -1363,8 +1352,7 @@ void SSLWrap<Base>::GetNegotiatedProto(
     const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
 
   if (w->is_client()) {
     if (w->selected_npn_proto_.IsEmpty() == false) {
@@ -1390,8 +1378,7 @@ template <class Base>
 void SSLWrap<Base>::SetNPNProtocols(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  Base* w = NULL;
-  NODE_UNWRAP(args.This(), Base, w);
+  Base* w = UnwrapObject<Base>(args.This());
 
   if (args.Length() < 1 || !Buffer::HasInstance(args[0]))
     return ThrowTypeError("Must give a Buffer as first argument");
index fa3b5d7..a484779 100644 (file)
@@ -173,37 +173,6 @@ NO_RETURN void FatalError(const char* location, const char* message);
 
 v8::Local<v8::Object> BuildStatsObject(Environment* env, const uv_stat_t* s);
 
-#define NODE_WRAP(Object, Pointer)                                             \
-  do {                                                                         \
-    assert(!Object.IsEmpty());                                                 \
-    assert(Object->InternalFieldCount() > 0);                                  \
-    Object->SetAlignedPointerInInternalField(0, Pointer);                      \
-  }                                                                            \
-  while (0)
-
-#define NODE_UNWRAP(Object, TypeName, Var)                                     \
-  do {                                                                         \
-    assert(!Object.IsEmpty());                                                 \
-    assert(Object->InternalFieldCount() > 0);                                  \
-    Var = static_cast<TypeName*>(                                              \
-        Object->GetAlignedPointerFromInternalField(0));                        \
-    if (!Var) {                                                                \
-      fprintf(stderr, #TypeName ": Aborting due to unwrap failure at %s:%d\n", \
-              __FILE__, __LINE__);                                             \
-      abort();                                                                 \
-    }                                                                          \
-  }                                                                            \
-  while (0)
-
-#define NODE_UNWRAP_NO_ABORT(Object, TypeName, Var)                            \
-  do {                                                                         \
-    assert(!Object.IsEmpty());                                                 \
-    assert(Object->InternalFieldCount() > 0);                                  \
-    Var = static_cast<TypeName*>(                                              \
-        Object->GetAlignedPointerFromInternalField(0));                        \
-  }                                                                            \
-  while (0)
-
 enum Endianness {
   kLittleEndian,  // _Not_ LITTLE_ENDIAN, clashes with endian.h.
   kBigEndian
index ace2296..233c137 100644 (file)
 #ifndef SRC_NODE_STAT_WATCHER_H_
 #define SRC_NODE_STAT_WATCHER_H_
 
-#include "env.h"
 #include "node.h"
+#include "env.h"
+#include "weak-object.h"
 #include "uv.h"
 #include "v8.h"
-#include "weak-object.h"
 
 namespace node {
 
index b0bd28d..4b195fd 100644 (file)
@@ -70,9 +70,7 @@ Local<Object> PipeWrap::Instantiate(Environment* env) {
 
 
 PipeWrap* PipeWrap::Unwrap(Local<Object> obj) {
-  PipeWrap* wrap;
-  NODE_UNWRAP(obj, PipeWrap, wrap);
-  return wrap;
+  return UnwrapObject<PipeWrap>(obj);
 }
 
 
@@ -146,8 +144,7 @@ PipeWrap::PipeWrap(Environment* env, Handle<Object> object, bool ipc)
 void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  PipeWrap* wrap;
-  NODE_UNWRAP(args.This(), PipeWrap, wrap);
+  PipeWrap* wrap = UnwrapObject<PipeWrap>(args.This());
 
   String::AsciiValue name(args[0]);
   int err = uv_pipe_bind(&wrap->handle_, *name);
@@ -159,8 +156,7 @@ void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
 void PipeWrap::SetPendingInstances(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  PipeWrap* wrap;
-  NODE_UNWRAP(args.This(), PipeWrap, wrap);
+  PipeWrap* wrap = UnwrapObject<PipeWrap>(args.This());
 
   int instances = args[0]->Int32Value();
 
@@ -172,8 +168,7 @@ void PipeWrap::SetPendingInstances(const FunctionCallbackInfo<Value>& args) {
 void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  PipeWrap* wrap;
-  NODE_UNWRAP(args.This(), PipeWrap, wrap);
+  PipeWrap* wrap = UnwrapObject<PipeWrap>(args.This());
 
   int backlog = args[0]->Int32Value();
   int err = uv_listen(reinterpret_cast<uv_stream_t*>(&wrap->handle_),
@@ -215,8 +210,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
       env->pipe_constructor_template()->GetFunction()->NewInstance();
 
   // Unwrap the client javascript object.
-  PipeWrap* wrap;
-  NODE_UNWRAP(client_obj, PipeWrap, wrap);
+  PipeWrap* wrap = UnwrapObject<PipeWrap>(client_obj);
   uv_stream_t* client_handle = reinterpret_cast<uv_stream_t*>(&wrap->handle_);
   if (uv_accept(handle, client_handle))
     return;
@@ -275,8 +269,7 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
 void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  PipeWrap* wrap;
-  NODE_UNWRAP(args.This(), PipeWrap, wrap);
+  PipeWrap* wrap = UnwrapObject<PipeWrap>(args.This());
 
   int fd = args[0]->Int32Value();
 
@@ -291,8 +284,7 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope scope(args.GetIsolate());
 
-  PipeWrap* wrap;
-  NODE_UNWRAP(args.This(), PipeWrap, wrap);
+  PipeWrap* wrap = UnwrapObject<PipeWrap>(args.This());
 
   assert(args[0]->IsObject());
   assert(args[1]->IsString());
index bff4e0b..0a4029c 100644 (file)
@@ -23,6 +23,8 @@
 #include "env-inl.h"
 #include "handle_wrap.h"
 #include "node_wrap.h"
+#include "util.h"
+#include "util-inl.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -131,8 +133,7 @@ class ProcessWrap : public HandleWrap {
     Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
 
-    ProcessWrap* wrap;
-    NODE_UNWRAP(args.This(), ProcessWrap, wrap);
+    ProcessWrap* wrap = UnwrapObject<ProcessWrap>(args.This());
 
     Local<Object> js_options = args[0]->ToObject();
 
@@ -260,8 +261,7 @@ class ProcessWrap : public HandleWrap {
 
   static void Kill(const FunctionCallbackInfo<Value>& args) {
     HandleScope scope(node_isolate);
-    ProcessWrap* wrap;
-    NODE_UNWRAP(args.This(), ProcessWrap, wrap);
+    ProcessWrap* wrap = UnwrapObject<ProcessWrap>(args.This());
 
     int signal = args[0]->Int32Value();
     int err = uv_process_kill(&wrap->process_, signal);
index a0d62e8..bcc355f 100644 (file)
@@ -22,6 +22,8 @@
 #include "env.h"
 #include "env-inl.h"
 #include "handle_wrap.h"
+#include "util.h"
+#include "util-inl.h"
 #include "v8.h"
 
 namespace node {
@@ -78,8 +80,7 @@ class SignalWrap : public HandleWrap {
 
   static void Start(const FunctionCallbackInfo<Value>& args) {
     HandleScope scope(node_isolate);
-    SignalWrap* wrap;
-    NODE_UNWRAP(args.This(), SignalWrap, wrap);
+    SignalWrap* wrap = UnwrapObject<SignalWrap>(args.This());
 
     int signum = args[0]->Int32Value();
     int err = uv_signal_start(&wrap->handle_, OnSignal, signum);
@@ -88,8 +89,7 @@ class SignalWrap : public HandleWrap {
 
   static void Stop(const FunctionCallbackInfo<Value>& args) {
     HandleScope scope(node_isolate);
-    SignalWrap* wrap;
-    NODE_UNWRAP(args.This(), SignalWrap, wrap);
+    SignalWrap* wrap = UnwrapObject<SignalWrap>(args.This());
 
     int err = uv_signal_stop(&wrap->handle_);
     args.GetReturnValue().Set(err);
index f268bde..85a12f2 100644 (file)
@@ -29,6 +29,8 @@
 #include "req_wrap.h"
 #include "tcp_wrap.h"
 #include "udp_wrap.h"
+#include "util.h"
+#include "util-inl.h"
 
 #include <stdlib.h>  // abort()
 #include <limits.h>  // INT_MAX
@@ -64,8 +66,7 @@ StreamWrap::StreamWrap(Environment* env,
 void StreamWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) {
 #if !defined(_WIN32)
   HandleScope scope(node_isolate);
-  StreamWrap* wrap;
-  NODE_UNWRAP_NO_ABORT(args.This(), StreamWrap, wrap);
+  StreamWrap* wrap = UnwrapObject<StreamWrap>(args.This());
   int fd = -1;
   if (wrap != NULL && wrap->stream() != NULL) {
     fd = wrap->stream()->io_watcher.fd;
@@ -86,8 +87,7 @@ void StreamWrap::UpdateWriteQueueSize() {
 void StreamWrap::ReadStart(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  StreamWrap* wrap;
-  NODE_UNWRAP(args.This(), StreamWrap, wrap);
+  StreamWrap* wrap = UnwrapObject<StreamWrap>(args.This());
 
   int err;
   if (wrap->is_named_pipe_ipc()) {
@@ -103,8 +103,7 @@ void StreamWrap::ReadStart(const FunctionCallbackInfo<Value>& args) {
 void StreamWrap::ReadStop(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  StreamWrap* wrap;
-  NODE_UNWRAP(args.This(), StreamWrap, wrap);
+  StreamWrap* wrap = UnwrapObject<StreamWrap>(args.This());
 
   int err = uv_read_stop(wrap->stream());
   args.GetReturnValue().Set(err);
@@ -130,8 +129,7 @@ static Local<Object> AcceptHandle(Environment* env, uv_stream_t* pipe) {
   if (wrap_obj.IsEmpty())
     return Local<Object>();
 
-  WrapType* wrap;
-  NODE_UNWRAP(wrap_obj, WrapType, wrap);
+  WrapType* wrap = UnwrapObject<WrapType>(wrap_obj);
   handle = wrap->UVHandle();
 
   if (uv_accept(pipe, reinterpret_cast<uv_stream_t*>(handle)))
@@ -195,8 +193,7 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
 
-  StreamWrap* wrap;
-  NODE_UNWRAP(args.This(), StreamWrap, wrap);
+  StreamWrap* wrap = UnwrapObject<StreamWrap>(args.This());
 
   assert(args[0]->IsObject());
   assert(Buffer::HasInstance(args[1]));
@@ -236,8 +233,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
   HandleScope handle_scope(args.GetIsolate());
   int err;
 
-  StreamWrap* wrap;
-  NODE_UNWRAP(args.This(), StreamWrap, wrap);
+  StreamWrap* wrap = UnwrapObject<StreamWrap>(args.This());
 
   assert(args[0]->IsObject());
   assert(args[1]->IsString());
@@ -287,8 +283,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
 
     if (args[2]->IsObject()) {
       Local<Object> send_handle_obj = args[2].As<Object>();
-      HandleWrap* wrap;
-      NODE_UNWRAP(send_handle_obj, HandleWrap, wrap);
+      HandleWrap* wrap = UnwrapObject<HandleWrap>(send_handle_obj);
       send_handle = wrap->GetHandle();
       // Reference StreamWrap instance to prevent it from being garbage
       // collected before `AfterWrite` is called.
@@ -321,8 +316,7 @@ void StreamWrap::Writev(const FunctionCallbackInfo<Value>& args) {
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
 
-  StreamWrap* wrap;
-  NODE_UNWRAP(args.This(), StreamWrap, wrap);
+  StreamWrap* wrap = UnwrapObject<StreamWrap>(args.This());
 
   assert(args[0]->IsObject());
   assert(args[1]->IsArray());
@@ -472,8 +466,7 @@ void StreamWrap::Shutdown(const FunctionCallbackInfo<Value>& args) {
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
 
-  StreamWrap* wrap;
-  NODE_UNWRAP(args.This(), StreamWrap, wrap);
+  StreamWrap* wrap = UnwrapObject<StreamWrap>(args.This());
 
   assert(args[0]->IsObject());
   Local<Object> req_wrap_obj = args[0].As<Object>();
index e0cab70..b719fbe 100644 (file)
@@ -28,6 +28,8 @@
 #include "node_wrap.h"
 #include "req_wrap.h"
 #include "stream_wrap.h"
+#include "util.h"
+#include "util-inl.h"
 
 #include <stdlib.h>
 
@@ -120,9 +122,7 @@ void TCPWrap::Initialize(Handle<Object> target,
 
 
 TCPWrap* TCPWrap::Unwrap(Local<Object> obj) {
-  TCPWrap* wrap;
-  NODE_UNWRAP(obj, TCPWrap, wrap);
-  return wrap;
+  return UnwrapObject<TCPWrap>(obj);
 }
 
 
@@ -162,8 +162,7 @@ void TCPWrap::GetSockName(const FunctionCallbackInfo<Value>& args) {
   HandleScope handle_scope(args.GetIsolate());
   struct sockaddr_storage address;
 
-  TCPWrap* wrap;
-  NODE_UNWRAP(args.This(), TCPWrap, wrap);
+  TCPWrap* wrap = UnwrapObject<TCPWrap>(args.This());
 
   assert(args[0]->IsObject());
   Local<Object> out = args[0].As<Object>();
@@ -186,8 +185,7 @@ void TCPWrap::GetPeerName(const FunctionCallbackInfo<Value>& args) {
   HandleScope handle_scope(args.GetIsolate());
   struct sockaddr_storage address;
 
-  TCPWrap* wrap;
-  NODE_UNWRAP(args.This(), TCPWrap, wrap);
+  TCPWrap* wrap = UnwrapObject<TCPWrap>(args.This());
 
   assert(args[0]->IsObject());
   Local<Object> out = args[0].As<Object>();
@@ -208,8 +206,7 @@ void TCPWrap::GetPeerName(const FunctionCallbackInfo<Value>& args) {
 void TCPWrap::SetNoDelay(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TCPWrap* wrap;
-  NODE_UNWRAP(args.This(), TCPWrap, wrap);
+  TCPWrap* wrap = UnwrapObject<TCPWrap>(args.This());
 
   int enable = static_cast<int>(args[0]->BooleanValue());
   int err = uv_tcp_nodelay(&wrap->handle_, enable);
@@ -220,8 +217,7 @@ void TCPWrap::SetNoDelay(const FunctionCallbackInfo<Value>& args) {
 void TCPWrap::SetKeepAlive(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TCPWrap* wrap;
-  NODE_UNWRAP(args.This(), TCPWrap, wrap);
+  TCPWrap* wrap = UnwrapObject<TCPWrap>(args.This());
 
   int enable = args[0]->Int32Value();
   unsigned int delay = args[1]->Uint32Value();
@@ -235,8 +231,7 @@ void TCPWrap::SetKeepAlive(const FunctionCallbackInfo<Value>& args) {
 void TCPWrap::SetSimultaneousAccepts(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TCPWrap* wrap;
-  NODE_UNWRAP(args.This(), TCPWrap, wrap);
+  TCPWrap* wrap = UnwrapObject<TCPWrap>(args.This());
 
   bool enable = args[0]->BooleanValue();
   int err = uv_tcp_simultaneous_accepts(&wrap->handle_, enable);
@@ -247,8 +242,7 @@ void TCPWrap::SetSimultaneousAccepts(const FunctionCallbackInfo<Value>& args) {
 
 void TCPWrap::Open(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
-  TCPWrap* wrap;
-  NODE_UNWRAP(args.This(), TCPWrap, wrap);
+  TCPWrap* wrap = UnwrapObject<TCPWrap>(args.This());
   int fd = args[0]->IntegerValue();
   uv_tcp_open(&wrap->handle_, fd);
 }
@@ -257,8 +251,7 @@ void TCPWrap::Open(const FunctionCallbackInfo<Value>& args) {
 void TCPWrap::Bind(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TCPWrap* wrap;
-  NODE_UNWRAP(args.This(), TCPWrap, wrap);
+  TCPWrap* wrap = UnwrapObject<TCPWrap>(args.This());
 
   String::AsciiValue ip_address(args[0]);
   int port = args[1]->Int32Value();
@@ -275,8 +268,7 @@ void TCPWrap::Bind(const FunctionCallbackInfo<Value>& args) {
 void TCPWrap::Bind6(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TCPWrap* wrap;
-  NODE_UNWRAP(args.This(), TCPWrap, wrap);
+  TCPWrap* wrap = UnwrapObject<TCPWrap>(args.This());
 
   String::AsciiValue ip6_address(args[0]);
   int port = args[1]->Int32Value();
@@ -293,8 +285,7 @@ void TCPWrap::Bind6(const FunctionCallbackInfo<Value>& args) {
 void TCPWrap::Listen(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TCPWrap* wrap;
-  NODE_UNWRAP(args.This(), TCPWrap, wrap);
+  TCPWrap* wrap = UnwrapObject<TCPWrap>(args.This());
 
   int backlog = args[0]->Int32Value();
   int err = uv_listen(reinterpret_cast<uv_stream_t*>(&wrap->handle_),
@@ -326,8 +317,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
     Local<Object> client_obj = Instantiate(env);
 
     // Unwrap the client javascript object.
-    TCPWrap* wrap;
-    NODE_UNWRAP(client_obj, TCPWrap, wrap);
+    TCPWrap* wrap = UnwrapObject<TCPWrap>(client_obj);
     uv_stream_t* client_handle = reinterpret_cast<uv_stream_t*>(&wrap->handle_);
     if (uv_accept(handle, client_handle))
       return;
@@ -379,8 +369,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
 
-  TCPWrap* wrap;
-  NODE_UNWRAP(args.This(), TCPWrap, wrap);
+  TCPWrap* wrap = UnwrapObject<TCPWrap>(args.This());
 
   assert(args[0]->IsObject());
   assert(args[1]->IsString());
@@ -412,8 +401,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
 
-  TCPWrap* wrap;
-  NODE_UNWRAP(args.This(), TCPWrap, wrap);
+  TCPWrap* wrap = UnwrapObject<TCPWrap>(args.This());
 
   assert(args[0]->IsObject());
   assert(args[1]->IsString());
index 76b9554..7a7ca26 100644 (file)
@@ -22,6 +22,8 @@
 #include "env.h"
 #include "env-inl.h"
 #include "handle_wrap.h"
+#include "util.h"
+#include "util-inl.h"
 
 #include <stdint.h>
 
@@ -89,8 +91,7 @@ class TimerWrap : public HandleWrap {
 
   static void Start(const FunctionCallbackInfo<Value>& args) {
     HandleScope scope(node_isolate);
-    TimerWrap* wrap;
-    NODE_UNWRAP(args.This(), TimerWrap, wrap);
+    TimerWrap* wrap = UnwrapObject<TimerWrap>(args.This());
 
     int64_t timeout = args[0]->IntegerValue();
     int64_t repeat = args[1]->IntegerValue();
@@ -100,8 +101,7 @@ class TimerWrap : public HandleWrap {
 
   static void Stop(const FunctionCallbackInfo<Value>& args) {
     HandleScope scope(node_isolate);
-    TimerWrap* wrap;
-    NODE_UNWRAP(args.This(), TimerWrap, wrap);
+    TimerWrap* wrap = UnwrapObject<TimerWrap>(args.This());
 
     int err = uv_timer_stop(&wrap->handle_);
     args.GetReturnValue().Set(err);
@@ -109,8 +109,7 @@ class TimerWrap : public HandleWrap {
 
   static void Again(const FunctionCallbackInfo<Value>& args) {
     HandleScope scope(node_isolate);
-    TimerWrap* wrap;
-    NODE_UNWRAP(args.This(), TimerWrap, wrap);
+    TimerWrap* wrap = UnwrapObject<TimerWrap>(args.This());
 
     int err = uv_timer_again(&wrap->handle_);
     args.GetReturnValue().Set(err);
@@ -118,8 +117,7 @@ class TimerWrap : public HandleWrap {
 
   static void SetRepeat(const FunctionCallbackInfo<Value>& args) {
     HandleScope scope(node_isolate);
-    TimerWrap* wrap;
-    NODE_UNWRAP(args.This(), TimerWrap, wrap);
+    TimerWrap* wrap = UnwrapObject<TimerWrap>(args.This());
 
     int64_t repeat = args[0]->IntegerValue();
     uv_timer_set_repeat(&wrap->handle_, repeat);
@@ -128,8 +126,7 @@ class TimerWrap : public HandleWrap {
 
   static void GetRepeat(const FunctionCallbackInfo<Value>& args) {
     HandleScope scope(node_isolate);
-    TimerWrap* wrap;
-    NODE_UNWRAP(args.This(), TimerWrap, wrap);
+    TimerWrap* wrap = UnwrapObject<TimerWrap>(args.This());
 
     int64_t repeat = uv_timer_get_repeat(&wrap->handle_);
     args.GetReturnValue().Set(static_cast<double>(repeat));
index 6986e5a..3b22ce5 100644 (file)
@@ -28,6 +28,8 @@
 #include "node_wrap.h"  // WithGenericStream
 #include "node_counters.h"
 #include "node_internals.h"
+#include "util.h"
+#include "util-inl.h"
 
 namespace node {
 
@@ -74,8 +76,8 @@ TLSCallbacks::TLSCallbacks(Environment* env,
   sc_handle_.Reset(node_isolate, sc);
 
   Local<Object> object = env->tls_wrap_constructor_function()->NewInstance();
-  NODE_WRAP(object, this);
   persistent().Reset(node_isolate, object);
+  WrapObject<TLSCallbacks>(object, this);
 
   // Initialize queue for clearIn writes
   QUEUE_INIT(&write_item_queue_);
@@ -210,8 +212,7 @@ void TLSCallbacks::Wrap(const FunctionCallbackInfo<Value>& args) {
 void TLSCallbacks::Start(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TLSCallbacks* wrap;
-  NODE_UNWRAP(args.This(), TLSCallbacks, wrap);
+  TLSCallbacks* wrap = UnwrapObject<TLSCallbacks>(args.This());
 
   if (wrap->started_)
     return ThrowError("Already started.");
@@ -582,8 +583,7 @@ int TLSCallbacks::DoShutdown(ShutdownWrap* req_wrap, uv_shutdown_cb cb) {
 void TLSCallbacks::SetVerifyMode(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TLSCallbacks* wrap;
-  NODE_UNWRAP(args.This(), TLSCallbacks, wrap);
+  TLSCallbacks* wrap = UnwrapObject<TLSCallbacks>(args.This());
 
   if (args.Length() < 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean())
     return ThrowTypeError("Bad arguments, expected two booleans");
@@ -614,8 +614,7 @@ void TLSCallbacks::EnableSessionCallbacks(
     const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TLSCallbacks* wrap;
-  NODE_UNWRAP(args.This(), TLSCallbacks, wrap);
+  TLSCallbacks* wrap = UnwrapObject<TLSCallbacks>(args.This());
 
   wrap->enable_session_callbacks();
   EnableHelloParser(args);
@@ -625,8 +624,7 @@ void TLSCallbacks::EnableSessionCallbacks(
 void TLSCallbacks::EnableHelloParser(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TLSCallbacks* wrap;
-  NODE_UNWRAP(args.This(), TLSCallbacks, wrap);
+  TLSCallbacks* wrap = UnwrapObject<TLSCallbacks>(args.This());
 
   wrap->hello_parser_.Start(SSLWrap<TLSCallbacks>::OnClientHello,
                             OnClientHelloParseEnd,
@@ -644,8 +642,7 @@ void TLSCallbacks::OnClientHelloParseEnd(void* arg) {
 void TLSCallbacks::GetServername(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TLSCallbacks* wrap;
-  NODE_UNWRAP(args.This(), TLSCallbacks, wrap);
+  TLSCallbacks* wrap = UnwrapObject<TLSCallbacks>(args.This());
 
   const char* servername = SSL_get_servername(wrap->ssl_,
                                               TLSEXT_NAMETYPE_host_name);
@@ -660,8 +657,7 @@ void TLSCallbacks::GetServername(const FunctionCallbackInfo<Value>& args) {
 void TLSCallbacks::SetServername(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TLSCallbacks* wrap;
-  NODE_UNWRAP(args.This(), TLSCallbacks, wrap);
+  TLSCallbacks* wrap = UnwrapObject<TLSCallbacks>(args.This());
 
   if (args.Length() < 1 || !args[0]->IsString())
     return ThrowTypeError("First argument should be a string");
index aad19a7..bf94309 100644 (file)
@@ -28,6 +28,8 @@
 #include "node_wrap.h"
 #include "req_wrap.h"
 #include "stream_wrap.h"
+#include "util.h"
+#include "util-inl.h"
 
 namespace node {
 
@@ -89,9 +91,7 @@ void TTYWrap::Initialize(Handle<Object> target,
 
 
 TTYWrap* TTYWrap::Unwrap(Local<Object> obj) {
-  TTYWrap* wrap;
-  NODE_UNWRAP(obj, TTYWrap, wrap);
-  return wrap;
+  return UnwrapObject<TTYWrap>(obj);
 }
 
 
@@ -135,8 +135,7 @@ void TTYWrap::IsTTY(const FunctionCallbackInfo<Value>& args) {
 void TTYWrap::GetWindowSize(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TTYWrap* wrap;
-  NODE_UNWRAP(args.This(), TTYWrap, wrap);
+  TTYWrap* wrap = UnwrapObject<TTYWrap>(args.This());
   assert(args[0]->IsArray());
 
   int width, height;
@@ -155,8 +154,7 @@ void TTYWrap::GetWindowSize(const FunctionCallbackInfo<Value>& args) {
 void TTYWrap::SetRawMode(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
 
-  TTYWrap* wrap;
-  NODE_UNWRAP(args.This(), TTYWrap, wrap);
+  TTYWrap* wrap = UnwrapObject<TTYWrap>(args.This());
 
   int err = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue());
   args.GetReturnValue().Set(err);
index 1093576..0d72ffe 100644 (file)
@@ -25,6 +25,8 @@
 #include "node_buffer.h"
 #include "handle_wrap.h"
 #include "req_wrap.h"
+#include "util.h"
+#include "util-inl.h"
 
 #include <stdlib.h>
 
@@ -133,8 +135,7 @@ void UDPWrap::New(const FunctionCallbackInfo<Value>& args) {
 void UDPWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) {
 #if !defined(_WIN32)
   HandleScope scope(node_isolate);
-  UDPWrap* wrap;
-  NODE_UNWRAP(args.This(), UDPWrap, wrap);
+  UDPWrap* wrap = UnwrapObject<UDPWrap>(args.This());
   int fd = (wrap == NULL) ? -1 : wrap->handle_.io_watcher.fd;
   args.GetReturnValue().Set(fd);
 #endif
@@ -144,8 +145,7 @@ void UDPWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) {
 void UDPWrap::DoBind(const FunctionCallbackInfo<Value>& args, int family) {
   HandleScope scope(node_isolate);
 
-  UDPWrap* wrap;
-  NODE_UNWRAP(args.This(), UDPWrap, wrap);
+  UDPWrap* wrap = UnwrapObject<UDPWrap>(args.This());
 
   // bind(ip, port, flags)
   assert(args.Length() == 3);
@@ -191,8 +191,7 @@ void UDPWrap::Bind6(const FunctionCallbackInfo<Value>& args) {
 #define X(name, fn)                                                           \
   void UDPWrap::name(const FunctionCallbackInfo<Value>& args) {               \
     HandleScope scope(node_isolate);                                          \
-    UDPWrap* wrap;                                                            \
-    NODE_UNWRAP(args.This(), UDPWrap, wrap);                                  \
+    UDPWrap* wrap = UnwrapObject<UDPWrap>(args.This());                       \
     assert(args.Length() == 1);                                               \
     int flag = args[0]->Int32Value();                                         \
     int err = fn(&wrap->handle_, flag);                                       \
@@ -210,8 +209,7 @@ X(SetMulticastLoopback, uv_udp_set_multicast_loop)
 void UDPWrap::SetMembership(const FunctionCallbackInfo<Value>& args,
                             uv_membership membership) {
   HandleScope scope(node_isolate);
-  UDPWrap* wrap;
-  NODE_UNWRAP(args.This(), UDPWrap, wrap);
+  UDPWrap* wrap = UnwrapObject<UDPWrap>(args.This());
 
   assert(args.Length() == 2);
 
@@ -245,8 +243,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
 
-  UDPWrap* wrap;
-  NODE_UNWRAP(args.This(), UDPWrap, wrap);
+  UDPWrap* wrap = UnwrapObject<UDPWrap>(args.This());
 
   // send(req, buffer, offset, length, port, address)
   assert(args[0]->IsObject());
@@ -316,8 +313,7 @@ void UDPWrap::Send6(const FunctionCallbackInfo<Value>& args) {
 
 void UDPWrap::RecvStart(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
-  UDPWrap* wrap;
-  NODE_UNWRAP(args.This(), UDPWrap, wrap);
+  UDPWrap* wrap = UnwrapObject<UDPWrap>(args.This());
 
   int err = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv);
   // UV_EALREADY means that the socket is already bound but that's okay
@@ -329,8 +325,7 @@ void UDPWrap::RecvStart(const FunctionCallbackInfo<Value>& args) {
 
 void UDPWrap::RecvStop(const FunctionCallbackInfo<Value>& args) {
   HandleScope scope(node_isolate);
-  UDPWrap* wrap;
-  NODE_UNWRAP(args.This(), UDPWrap, wrap);
+  UDPWrap* wrap = UnwrapObject<UDPWrap>(args.This());
 
   int r = uv_udp_recv_stop(&wrap->handle_);
   args.GetReturnValue().Set(r);
@@ -342,8 +337,7 @@ void UDPWrap::GetSockName(const FunctionCallbackInfo<Value>& args) {
   HandleScope handle_scope(args.GetIsolate());
 
   struct sockaddr_storage address;
-  UDPWrap* wrap;
-  NODE_UNWRAP(args.This(), UDPWrap, wrap);
+  UDPWrap* wrap = UnwrapObject<UDPWrap>(args.This());
 
   assert(args[0]->IsObject());
   Local<Object> obj = args[0].As<Object>();
@@ -434,9 +428,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
 
 
 UDPWrap* UDPWrap::Unwrap(Local<Object> obj) {
-  UDPWrap* wrap;
-  NODE_UNWRAP(obj, UDPWrap, wrap);
-  return wrap;
+  return UnwrapObject<UDPWrap>(obj);
 }
 
 
index 1ea31d9..8257e5a 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "util.h"
 
+#include <assert.h>
+
 namespace node {
 
 template <class TypeName>
@@ -78,6 +80,21 @@ inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
                                     length);
 }
 
+template <typename TypeName>
+void WrapObject(v8::Local<v8::Object> object, TypeName* pointer) {
+  assert(!object.IsEmpty());
+  assert(object->InternalFieldCount() > 0);
+  object->SetAlignedPointerInInternalField(0, pointer);
+}
+
+template <typename TypeName>
+TypeName* UnwrapObject(v8::Local<v8::Object> object) {
+  assert(!object.IsEmpty());
+  assert(object->InternalFieldCount() > 0);
+  void* pointer = object->GetAlignedPointerFromInternalField(0);
+  return static_cast<TypeName*>(pointer);
+}
+
 }  // namespace node
 
 #endif  // SRC_UTIL_INL_H_
index 7e71f36..466635b 100644 (file)
@@ -77,6 +77,11 @@ inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
                                            const unsigned char* data,
                                            int length = -1);
 
+inline static void WrapObject(v8::Local<v8::Object> object, void* pointer);
+
+template <typename TypeName>
+inline static TypeName* UnwrapObject(v8::Local<v8::Object> object);
+
 }  // namespace node
 
 #endif  // SRC_UTIL_H_