diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 63912f4358..b6631844b4 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -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& args) { void FSEventWrap::Start(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - FSEventWrap* wrap; - NODE_UNWRAP(args.This(), FSEventWrap, wrap); + FSEventWrap* wrap = UnwrapObject(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& args) { HandleScope scope(node_isolate); - FSEventWrap* wrap; - NODE_UNWRAP_NO_ABORT(args.This(), FSEventWrap, wrap); + FSEventWrap* wrap = UnwrapObject(args.This()); if (wrap == NULL || wrap->initialized_ == false) return; diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 9fa29623bb..71e395340c 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -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& args) { HandleScope scope(node_isolate); - HandleWrap* wrap; - NODE_UNWRAP_NO_ABORT(args.This(), HandleWrap, wrap); + HandleWrap* wrap = UnwrapObject(args.This()); if (wrap != NULL && wrap->handle__ != NULL) { uv_ref(wrap->handle__); @@ -55,8 +56,7 @@ void HandleWrap::Ref(const FunctionCallbackInfo& args) { void HandleWrap::Unref(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - HandleWrap* wrap; - NODE_UNWRAP_NO_ABORT(args.This(), HandleWrap, wrap); + HandleWrap* wrap = UnwrapObject(args.This()); if (wrap != NULL && wrap->handle__ != NULL) { uv_unref(wrap->handle__); @@ -68,8 +68,7 @@ void HandleWrap::Unref(const FunctionCallbackInfo& args) { void HandleWrap::Close(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - HandleWrap* wrap; - NODE_UNWRAP_NO_ABORT(args.This(), HandleWrap, wrap); + HandleWrap* wrap = UnwrapObject(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(object, this); QUEUE_INSERT_TAIL(&handle_wrap_queue, &handle_wrap_queue_); } diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 80a2adab1f..1c7484fb63 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -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 wrapper = env->script_data_constructor_function()->NewInstance(); - NODE_WRAP(wrapper, this); + WrapObject(wrapper, this); return scope.Close(wrapper); } @@ -297,8 +299,8 @@ class ContextifyContext { const PropertyCallbackInfo& args) { HandleScope scope(node_isolate); - ContextifyContext* ctx = NULL; - NODE_UNWRAP(args.Data().As(), ContextifyContext, ctx); + ContextifyContext* ctx = + UnwrapObject(args.Data().As()); Local sandbox = PersistentToLocal(node_isolate, ctx->sandbox_); Local rv = sandbox->GetRealNamedProperty(property); @@ -321,8 +323,8 @@ class ContextifyContext { const PropertyCallbackInfo& args) { HandleScope scope(node_isolate); - ContextifyContext* ctx = NULL; - NODE_UNWRAP(args.Data().As(), ContextifyContext, ctx); + ContextifyContext* ctx = + UnwrapObject(args.Data().As()); PersistentToLocal(node_isolate, ctx->sandbox_)->Set(property, value); } @@ -333,8 +335,8 @@ class ContextifyContext { const PropertyCallbackInfo& args) { HandleScope scope(node_isolate); - ContextifyContext* ctx = NULL; - NODE_UNWRAP(args.Data().As(), ContextifyContext, ctx); + ContextifyContext* ctx = + UnwrapObject(args.Data().As()); Local sandbox = PersistentToLocal(node_isolate, ctx->sandbox_); Local proxy_global = PersistentToLocal(node_isolate, @@ -354,8 +356,8 @@ class ContextifyContext { const PropertyCallbackInfo& args) { HandleScope scope(node_isolate); - ContextifyContext* ctx = NULL; - NODE_UNWRAP(args.Data().As(), ContextifyContext, ctx); + ContextifyContext* ctx = + UnwrapObject(args.Data().As()); bool success = PersistentToLocal(node_isolate, ctx->sandbox_)->Delete(property); @@ -371,8 +373,8 @@ class ContextifyContext { const PropertyCallbackInfo& args) { HandleScope scope(node_isolate); - ContextifyContext* ctx = NULL; - NODE_UNWRAP(args.Data().As(), ContextifyContext, ctx); + ContextifyContext* ctx = + UnwrapObject(args.Data().As()); Local sandbox = PersistentToLocal(node_isolate, ctx->sandbox_); args.GetReturnValue().Set(sandbox->GetPropertyNames()); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 5051c84a79..6f1d232436 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -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 @@ -761,8 +763,7 @@ void SecureContext::GetTicketKeys(const FunctionCallbackInfo& 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(args.This()); Local buff = Buffer::New(wrap->env(), 48); if (SSL_CTX_get_tlsext_ticket_keys(wrap->ctx_, @@ -786,8 +787,7 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo& args) { return ThrowTypeError("Bad argument"); } - SecureContext* wrap; - NODE_UNWRAP(args.This(), SecureContext, wrap); + SecureContext* wrap = UnwrapObject(args.This()); if (SSL_CTX_set_tlsext_ticket_keys(wrap->ctx_, Buffer::Data(args[0]), @@ -915,8 +915,7 @@ void SSLWrap::GetPeerCertificate( const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); Environment* env = w->env(); Local info = Object::New(); @@ -1050,8 +1049,7 @@ template void SSLWrap::GetSession(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); SSL_SESSION* sess = SSL_get_session(w->ssl_); if (sess == NULL) @@ -1072,8 +1070,7 @@ template void SSLWrap::SetSession(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); if (args.Length() < 1 || (!args[0]->IsString() && !Buffer::HasInstance(args[0]))) { @@ -1111,8 +1108,7 @@ template void SSLWrap::LoadSession(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); Environment* env = w->env(); if (args.Length() >= 1 && Buffer::HasInstance(args[0])) { @@ -1144,8 +1140,7 @@ void SSLWrap::LoadSession(const FunctionCallbackInfo& args) { template void SSLWrap::IsSessionReused(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); bool yes = SSL_session_reused(w->ssl_); args.GetReturnValue().Set(yes); } @@ -1154,8 +1149,7 @@ void SSLWrap::IsSessionReused(const FunctionCallbackInfo& args) { template void SSLWrap::ReceivedShutdown(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); bool yes = SSL_get_shutdown(w->ssl_) == SSL_RECEIVED_SHUTDOWN; args.GetReturnValue().Set(yes); } @@ -1164,8 +1158,7 @@ void SSLWrap::ReceivedShutdown(const FunctionCallbackInfo& args) { template void SSLWrap::EndParser(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); w->hello_parser_.End(); } @@ -1174,8 +1167,7 @@ template void SSLWrap::Renegotiate(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); ClearErrorOnReturn clear_error_on_return; (void) &clear_error_on_return; // Silence unused variable warning. @@ -1188,8 +1180,7 @@ void SSLWrap::Renegotiate(const FunctionCallbackInfo& args) { template void SSLWrap::IsInitFinished(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); bool yes = SSL_is_init_finished(w->ssl_); args.GetReturnValue().Set(yes); } @@ -1200,8 +1191,7 @@ template void SSLWrap::VerifyError(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); // XXX(indutny) Do this check in JS land? X509* peer_cert = SSL_get_peer_certificate(w->ssl_); @@ -1267,8 +1257,7 @@ template void SSLWrap::GetCurrentCipher(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); Environment* env = w->env(); OPENSSL_CONST SSL_CIPHER* c = SSL_get_current_cipher(w->ssl_); @@ -1363,8 +1352,7 @@ void SSLWrap::GetNegotiatedProto( const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); if (w->is_client()) { if (w->selected_npn_proto_.IsEmpty() == false) { @@ -1390,8 +1378,7 @@ template void SSLWrap::SetNPNProtocols(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - Base* w = NULL; - NODE_UNWRAP(args.This(), Base, w); + Base* w = UnwrapObject(args.This()); if (args.Length() < 1 || !Buffer::HasInstance(args[0])) return ThrowTypeError("Must give a Buffer as first argument"); diff --git a/src/node_internals.h b/src/node_internals.h index fa3b5d763d..a484779243 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -173,37 +173,6 @@ NO_RETURN void FatalError(const char* location, const char* message); v8::Local 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( \ - 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( \ - Object->GetAlignedPointerFromInternalField(0)); \ - } \ - while (0) - enum Endianness { kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h. kBigEndian diff --git a/src/node_stat_watcher.h b/src/node_stat_watcher.h index ace229618f..233c137baa 100644 --- a/src/node_stat_watcher.h +++ b/src/node_stat_watcher.h @@ -22,11 +22,11 @@ #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 { diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index b0bd28dd82..4b195fda4a 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -70,9 +70,7 @@ Local PipeWrap::Instantiate(Environment* env) { PipeWrap* PipeWrap::Unwrap(Local obj) { - PipeWrap* wrap; - NODE_UNWRAP(obj, PipeWrap, wrap); - return wrap; + return UnwrapObject(obj); } @@ -146,8 +144,7 @@ PipeWrap::PipeWrap(Environment* env, Handle object, bool ipc) void PipeWrap::Bind(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - PipeWrap* wrap; - NODE_UNWRAP(args.This(), PipeWrap, wrap); + PipeWrap* wrap = UnwrapObject(args.This()); String::AsciiValue name(args[0]); int err = uv_pipe_bind(&wrap->handle_, *name); @@ -159,8 +156,7 @@ void PipeWrap::Bind(const FunctionCallbackInfo& args) { void PipeWrap::SetPendingInstances(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - PipeWrap* wrap; - NODE_UNWRAP(args.This(), PipeWrap, wrap); + PipeWrap* wrap = UnwrapObject(args.This()); int instances = args[0]->Int32Value(); @@ -172,8 +168,7 @@ void PipeWrap::SetPendingInstances(const FunctionCallbackInfo& args) { void PipeWrap::Listen(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - PipeWrap* wrap; - NODE_UNWRAP(args.This(), PipeWrap, wrap); + PipeWrap* wrap = UnwrapObject(args.This()); int backlog = args[0]->Int32Value(); int err = uv_listen(reinterpret_cast(&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(client_obj); uv_stream_t* client_handle = reinterpret_cast(&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& args) { HandleScope scope(node_isolate); - PipeWrap* wrap; - NODE_UNWRAP(args.This(), PipeWrap, wrap); + PipeWrap* wrap = UnwrapObject(args.This()); int fd = args[0]->Int32Value(); @@ -291,8 +284,7 @@ void PipeWrap::Connect(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope scope(args.GetIsolate()); - PipeWrap* wrap; - NODE_UNWRAP(args.This(), PipeWrap, wrap); + PipeWrap* wrap = UnwrapObject(args.This()); assert(args[0]->IsObject()); assert(args[1]->IsString()); diff --git a/src/process_wrap.cc b/src/process_wrap.cc index bff4e0ba86..0a4029c185 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -23,6 +23,8 @@ #include "env-inl.h" #include "handle_wrap.h" #include "node_wrap.h" +#include "util.h" +#include "util-inl.h" #include #include @@ -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(args.This()); Local js_options = args[0]->ToObject(); @@ -260,8 +261,7 @@ class ProcessWrap : public HandleWrap { static void Kill(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - ProcessWrap* wrap; - NODE_UNWRAP(args.This(), ProcessWrap, wrap); + ProcessWrap* wrap = UnwrapObject(args.This()); int signal = args[0]->Int32Value(); int err = uv_process_kill(&wrap->process_, signal); diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc index a0d62e84a9..bcc355fc99 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -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& args) { HandleScope scope(node_isolate); - SignalWrap* wrap; - NODE_UNWRAP(args.This(), SignalWrap, wrap); + SignalWrap* wrap = UnwrapObject(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& args) { HandleScope scope(node_isolate); - SignalWrap* wrap; - NODE_UNWRAP(args.This(), SignalWrap, wrap); + SignalWrap* wrap = UnwrapObject(args.This()); int err = uv_signal_stop(&wrap->handle_); args.GetReturnValue().Set(err); diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index f268bde3b6..85a12f221f 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -29,6 +29,8 @@ #include "req_wrap.h" #include "tcp_wrap.h" #include "udp_wrap.h" +#include "util.h" +#include "util-inl.h" #include // abort() #include // INT_MAX @@ -64,8 +66,7 @@ StreamWrap::StreamWrap(Environment* env, void StreamWrap::GetFD(Local, const PropertyCallbackInfo& args) { #if !defined(_WIN32) HandleScope scope(node_isolate); - StreamWrap* wrap; - NODE_UNWRAP_NO_ABORT(args.This(), StreamWrap, wrap); + StreamWrap* wrap = UnwrapObject(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& args) { HandleScope scope(node_isolate); - StreamWrap* wrap; - NODE_UNWRAP(args.This(), StreamWrap, wrap); + StreamWrap* wrap = UnwrapObject(args.This()); int err; if (wrap->is_named_pipe_ipc()) { @@ -103,8 +103,7 @@ void StreamWrap::ReadStart(const FunctionCallbackInfo& args) { void StreamWrap::ReadStop(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - StreamWrap* wrap; - NODE_UNWRAP(args.This(), StreamWrap, wrap); + StreamWrap* wrap = UnwrapObject(args.This()); int err = uv_read_stop(wrap->stream()); args.GetReturnValue().Set(err); @@ -130,8 +129,7 @@ static Local AcceptHandle(Environment* env, uv_stream_t* pipe) { if (wrap_obj.IsEmpty()) return Local(); - WrapType* wrap; - NODE_UNWRAP(wrap_obj, WrapType, wrap); + WrapType* wrap = UnwrapObject(wrap_obj); handle = wrap->UVHandle(); if (uv_accept(pipe, reinterpret_cast(handle))) @@ -195,8 +193,7 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope handle_scope(args.GetIsolate()); - StreamWrap* wrap; - NODE_UNWRAP(args.This(), StreamWrap, wrap); + StreamWrap* wrap = UnwrapObject(args.This()); assert(args[0]->IsObject()); assert(Buffer::HasInstance(args[1])); @@ -236,8 +233,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo& args) { HandleScope handle_scope(args.GetIsolate()); int err; - StreamWrap* wrap; - NODE_UNWRAP(args.This(), StreamWrap, wrap); + StreamWrap* wrap = UnwrapObject(args.This()); assert(args[0]->IsObject()); assert(args[1]->IsString()); @@ -287,8 +283,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo& args) { if (args[2]->IsObject()) { Local send_handle_obj = args[2].As(); - HandleWrap* wrap; - NODE_UNWRAP(send_handle_obj, HandleWrap, wrap); + HandleWrap* wrap = UnwrapObject(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& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope handle_scope(args.GetIsolate()); - StreamWrap* wrap; - NODE_UNWRAP(args.This(), StreamWrap, wrap); + StreamWrap* wrap = UnwrapObject(args.This()); assert(args[0]->IsObject()); assert(args[1]->IsArray()); @@ -472,8 +466,7 @@ void StreamWrap::Shutdown(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope handle_scope(args.GetIsolate()); - StreamWrap* wrap; - NODE_UNWRAP(args.This(), StreamWrap, wrap); + StreamWrap* wrap = UnwrapObject(args.This()); assert(args[0]->IsObject()); Local req_wrap_obj = args[0].As(); diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index e0cab70e7f..b719fbe912 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -28,6 +28,8 @@ #include "node_wrap.h" #include "req_wrap.h" #include "stream_wrap.h" +#include "util.h" +#include "util-inl.h" #include @@ -120,9 +122,7 @@ void TCPWrap::Initialize(Handle target, TCPWrap* TCPWrap::Unwrap(Local obj) { - TCPWrap* wrap; - NODE_UNWRAP(obj, TCPWrap, wrap); - return wrap; + return UnwrapObject(obj); } @@ -162,8 +162,7 @@ void TCPWrap::GetSockName(const FunctionCallbackInfo& args) { HandleScope handle_scope(args.GetIsolate()); struct sockaddr_storage address; - TCPWrap* wrap; - NODE_UNWRAP(args.This(), TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(args.This()); assert(args[0]->IsObject()); Local out = args[0].As(); @@ -186,8 +185,7 @@ void TCPWrap::GetPeerName(const FunctionCallbackInfo& args) { HandleScope handle_scope(args.GetIsolate()); struct sockaddr_storage address; - TCPWrap* wrap; - NODE_UNWRAP(args.This(), TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(args.This()); assert(args[0]->IsObject()); Local out = args[0].As(); @@ -208,8 +206,7 @@ void TCPWrap::GetPeerName(const FunctionCallbackInfo& args) { void TCPWrap::SetNoDelay(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TCPWrap* wrap; - NODE_UNWRAP(args.This(), TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(args.This()); int enable = static_cast(args[0]->BooleanValue()); int err = uv_tcp_nodelay(&wrap->handle_, enable); @@ -220,8 +217,7 @@ void TCPWrap::SetNoDelay(const FunctionCallbackInfo& args) { void TCPWrap::SetKeepAlive(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TCPWrap* wrap; - NODE_UNWRAP(args.This(), TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(args.This()); int enable = args[0]->Int32Value(); unsigned int delay = args[1]->Uint32Value(); @@ -235,8 +231,7 @@ void TCPWrap::SetKeepAlive(const FunctionCallbackInfo& args) { void TCPWrap::SetSimultaneousAccepts(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TCPWrap* wrap; - NODE_UNWRAP(args.This(), TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(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& args) { void TCPWrap::Open(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TCPWrap* wrap; - NODE_UNWRAP(args.This(), TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(args.This()); int fd = args[0]->IntegerValue(); uv_tcp_open(&wrap->handle_, fd); } @@ -257,8 +251,7 @@ void TCPWrap::Open(const FunctionCallbackInfo& args) { void TCPWrap::Bind(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TCPWrap* wrap; - NODE_UNWRAP(args.This(), TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(args.This()); String::AsciiValue ip_address(args[0]); int port = args[1]->Int32Value(); @@ -275,8 +268,7 @@ void TCPWrap::Bind(const FunctionCallbackInfo& args) { void TCPWrap::Bind6(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TCPWrap* wrap; - NODE_UNWRAP(args.This(), TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(args.This()); String::AsciiValue ip6_address(args[0]); int port = args[1]->Int32Value(); @@ -293,8 +285,7 @@ void TCPWrap::Bind6(const FunctionCallbackInfo& args) { void TCPWrap::Listen(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TCPWrap* wrap; - NODE_UNWRAP(args.This(), TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(args.This()); int backlog = args[0]->Int32Value(); int err = uv_listen(reinterpret_cast(&wrap->handle_), @@ -326,8 +317,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) { Local client_obj = Instantiate(env); // Unwrap the client javascript object. - TCPWrap* wrap; - NODE_UNWRAP(client_obj, TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(client_obj); uv_stream_t* client_handle = reinterpret_cast(&wrap->handle_); if (uv_accept(handle, client_handle)) return; @@ -379,8 +369,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope handle_scope(args.GetIsolate()); - TCPWrap* wrap; - NODE_UNWRAP(args.This(), TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(args.This()); assert(args[0]->IsObject()); assert(args[1]->IsString()); @@ -412,8 +401,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args.GetIsolate()); HandleScope handle_scope(args.GetIsolate()); - TCPWrap* wrap; - NODE_UNWRAP(args.This(), TCPWrap, wrap); + TCPWrap* wrap = UnwrapObject(args.This()); assert(args[0]->IsObject()); assert(args[1]->IsString()); diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 76b95540f2..7a7ca26e41 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -22,6 +22,8 @@ #include "env.h" #include "env-inl.h" #include "handle_wrap.h" +#include "util.h" +#include "util-inl.h" #include @@ -89,8 +91,7 @@ class TimerWrap : public HandleWrap { static void Start(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TimerWrap* wrap; - NODE_UNWRAP(args.This(), TimerWrap, wrap); + TimerWrap* wrap = UnwrapObject(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& args) { HandleScope scope(node_isolate); - TimerWrap* wrap; - NODE_UNWRAP(args.This(), TimerWrap, wrap); + TimerWrap* wrap = UnwrapObject(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& args) { HandleScope scope(node_isolate); - TimerWrap* wrap; - NODE_UNWRAP(args.This(), TimerWrap, wrap); + TimerWrap* wrap = UnwrapObject(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& args) { HandleScope scope(node_isolate); - TimerWrap* wrap; - NODE_UNWRAP(args.This(), TimerWrap, wrap); + TimerWrap* wrap = UnwrapObject(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& args) { HandleScope scope(node_isolate); - TimerWrap* wrap; - NODE_UNWRAP(args.This(), TimerWrap, wrap); + TimerWrap* wrap = UnwrapObject(args.This()); int64_t repeat = uv_timer_get_repeat(&wrap->handle_); args.GetReturnValue().Set(static_cast(repeat)); diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 6986e5a3c1..3b22ce50b1 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -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 = env->tls_wrap_constructor_function()->NewInstance(); - NODE_WRAP(object, this); persistent().Reset(node_isolate, object); + WrapObject(object, this); // Initialize queue for clearIn writes QUEUE_INIT(&write_item_queue_); @@ -210,8 +212,7 @@ void TLSCallbacks::Wrap(const FunctionCallbackInfo& args) { void TLSCallbacks::Start(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TLSCallbacks* wrap; - NODE_UNWRAP(args.This(), TLSCallbacks, wrap); + TLSCallbacks* wrap = UnwrapObject(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& args) { HandleScope scope(node_isolate); - TLSCallbacks* wrap; - NODE_UNWRAP(args.This(), TLSCallbacks, wrap); + TLSCallbacks* wrap = UnwrapObject(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& args) { HandleScope scope(node_isolate); - TLSCallbacks* wrap; - NODE_UNWRAP(args.This(), TLSCallbacks, wrap); + TLSCallbacks* wrap = UnwrapObject(args.This()); wrap->enable_session_callbacks(); EnableHelloParser(args); @@ -625,8 +624,7 @@ void TLSCallbacks::EnableSessionCallbacks( void TLSCallbacks::EnableHelloParser(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TLSCallbacks* wrap; - NODE_UNWRAP(args.This(), TLSCallbacks, wrap); + TLSCallbacks* wrap = UnwrapObject(args.This()); wrap->hello_parser_.Start(SSLWrap::OnClientHello, OnClientHelloParseEnd, @@ -644,8 +642,7 @@ void TLSCallbacks::OnClientHelloParseEnd(void* arg) { void TLSCallbacks::GetServername(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TLSCallbacks* wrap; - NODE_UNWRAP(args.This(), TLSCallbacks, wrap); + TLSCallbacks* wrap = UnwrapObject(args.This()); const char* servername = SSL_get_servername(wrap->ssl_, TLSEXT_NAMETYPE_host_name); @@ -660,8 +657,7 @@ void TLSCallbacks::GetServername(const FunctionCallbackInfo& args) { void TLSCallbacks::SetServername(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TLSCallbacks* wrap; - NODE_UNWRAP(args.This(), TLSCallbacks, wrap); + TLSCallbacks* wrap = UnwrapObject(args.This()); if (args.Length() < 1 || !args[0]->IsString()) return ThrowTypeError("First argument should be a string"); diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index aad19a7e60..bf94309cda 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -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 target, TTYWrap* TTYWrap::Unwrap(Local obj) { - TTYWrap* wrap; - NODE_UNWRAP(obj, TTYWrap, wrap); - return wrap; + return UnwrapObject(obj); } @@ -135,8 +135,7 @@ void TTYWrap::IsTTY(const FunctionCallbackInfo& args) { void TTYWrap::GetWindowSize(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TTYWrap* wrap; - NODE_UNWRAP(args.This(), TTYWrap, wrap); + TTYWrap* wrap = UnwrapObject(args.This()); assert(args[0]->IsArray()); int width, height; @@ -155,8 +154,7 @@ void TTYWrap::GetWindowSize(const FunctionCallbackInfo& args) { void TTYWrap::SetRawMode(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - TTYWrap* wrap; - NODE_UNWRAP(args.This(), TTYWrap, wrap); + TTYWrap* wrap = UnwrapObject(args.This()); int err = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue()); args.GetReturnValue().Set(err); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 10935768bf..0d72ffe0b5 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -25,6 +25,8 @@ #include "node_buffer.h" #include "handle_wrap.h" #include "req_wrap.h" +#include "util.h" +#include "util-inl.h" #include @@ -133,8 +135,7 @@ void UDPWrap::New(const FunctionCallbackInfo& args) { void UDPWrap::GetFD(Local, const PropertyCallbackInfo& args) { #if !defined(_WIN32) HandleScope scope(node_isolate); - UDPWrap* wrap; - NODE_UNWRAP(args.This(), UDPWrap, wrap); + UDPWrap* wrap = UnwrapObject(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, const PropertyCallbackInfo& args) { void UDPWrap::DoBind(const FunctionCallbackInfo& args, int family) { HandleScope scope(node_isolate); - UDPWrap* wrap; - NODE_UNWRAP(args.This(), UDPWrap, wrap); + UDPWrap* wrap = UnwrapObject(args.This()); // bind(ip, port, flags) assert(args.Length() == 3); @@ -191,8 +191,7 @@ void UDPWrap::Bind6(const FunctionCallbackInfo& args) { #define X(name, fn) \ void UDPWrap::name(const FunctionCallbackInfo& args) { \ HandleScope scope(node_isolate); \ - UDPWrap* wrap; \ - NODE_UNWRAP(args.This(), UDPWrap, wrap); \ + UDPWrap* wrap = UnwrapObject(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& args, uv_membership membership) { HandleScope scope(node_isolate); - UDPWrap* wrap; - NODE_UNWRAP(args.This(), UDPWrap, wrap); + UDPWrap* wrap = UnwrapObject(args.This()); assert(args.Length() == 2); @@ -245,8 +243,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo& 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(args.This()); // send(req, buffer, offset, length, port, address) assert(args[0]->IsObject()); @@ -316,8 +313,7 @@ void UDPWrap::Send6(const FunctionCallbackInfo& args) { void UDPWrap::RecvStart(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - UDPWrap* wrap; - NODE_UNWRAP(args.This(), UDPWrap, wrap); + UDPWrap* wrap = UnwrapObject(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& args) { void UDPWrap::RecvStop(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - UDPWrap* wrap; - NODE_UNWRAP(args.This(), UDPWrap, wrap); + UDPWrap* wrap = UnwrapObject(args.This()); int r = uv_udp_recv_stop(&wrap->handle_); args.GetReturnValue().Set(r); @@ -342,8 +337,7 @@ void UDPWrap::GetSockName(const FunctionCallbackInfo& args) { HandleScope handle_scope(args.GetIsolate()); struct sockaddr_storage address; - UDPWrap* wrap; - NODE_UNWRAP(args.This(), UDPWrap, wrap); + UDPWrap* wrap = UnwrapObject(args.This()); assert(args[0]->IsObject()); Local obj = args[0].As(); @@ -434,9 +428,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle, UDPWrap* UDPWrap::Unwrap(Local obj) { - UDPWrap* wrap; - NODE_UNWRAP(obj, UDPWrap, wrap); - return wrap; + return UnwrapObject(obj); } diff --git a/src/util-inl.h b/src/util-inl.h index 1ea31d94db..8257e5a9e1 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -24,6 +24,8 @@ #include "util.h" +#include + namespace node { template @@ -78,6 +80,21 @@ inline v8::Local OneByteString(v8::Isolate* isolate, length); } +template +void WrapObject(v8::Local object, TypeName* pointer) { + assert(!object.IsEmpty()); + assert(object->InternalFieldCount() > 0); + object->SetAlignedPointerInInternalField(0, pointer); +} + +template +TypeName* UnwrapObject(v8::Local object) { + assert(!object.IsEmpty()); + assert(object->InternalFieldCount() > 0); + void* pointer = object->GetAlignedPointerFromInternalField(0); + return static_cast(pointer); +} + } // namespace node #endif // SRC_UTIL_INL_H_ diff --git a/src/util.h b/src/util.h index 7e71f36c70..466635b11e 100644 --- a/src/util.h +++ b/src/util.h @@ -77,6 +77,11 @@ inline v8::Local OneByteString(v8::Isolate* isolate, const unsigned char* data, int length = -1); +inline static void WrapObject(v8::Local object, void* pointer); + +template +inline static TypeName* UnwrapObject(v8::Local object); + } // namespace node #endif // SRC_UTIL_H_