Remove the NODE_{WRAP,UNWRAP} macros and instead use template functions.
#include "env.h"
#include "env-inl.h"
+#include "util.h"
+#include "util-inl.h"
#include "node.h"
#include "handle_wrap.h"
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");
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;
#include "handle_wrap.h"
#include "env.h"
#include "env-inl.h"
+#include "util.h"
+#include "util-inl.h"
#include "node.h"
#include "queue.h"
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__);
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__);
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)
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_);
}
#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"
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);
}
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);
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);
}
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,
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);
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());
#include "env.h"
#include "env-inl.h"
#include "string_bytes.h"
+#include "util.h"
+#include "util-inl.h"
#include "v8.h"
#include <errno.h>
#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_,
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]),
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();
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)
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]))) {
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])) {
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);
}
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);
}
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();
}
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.
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);
}
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_);
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_);
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) {
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");
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
#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 {
PipeWrap* PipeWrap::Unwrap(Local<Object> obj) {
- PipeWrap* wrap;
- NODE_UNWRAP(obj, PipeWrap, wrap);
- return wrap;
+ return UnwrapObject<PipeWrap>(obj);
}
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);
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();
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_),
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;
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();
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());
#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>
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();
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);
#include "env.h"
#include "env-inl.h"
#include "handle_wrap.h"
+#include "util.h"
+#include "util-inl.h"
#include "v8.h"
namespace node {
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);
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);
#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
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;
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()) {
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);
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)))
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]));
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());
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.
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());
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>();
#include "node_wrap.h"
#include "req_wrap.h"
#include "stream_wrap.h"
+#include "util.h"
+#include "util-inl.h"
#include <stdlib.h>
TCPWrap* TCPWrap::Unwrap(Local<Object> obj) {
- TCPWrap* wrap;
- NODE_UNWRAP(obj, TCPWrap, wrap);
- return wrap;
+ return UnwrapObject<TCPWrap>(obj);
}
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>();
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>();
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);
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();
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);
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);
}
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();
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();
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_),
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;
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());
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());
#include "env.h"
#include "env-inl.h"
#include "handle_wrap.h"
+#include "util.h"
+#include "util-inl.h"
#include <stdint.h>
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();
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);
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);
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);
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));
#include "node_wrap.h" // WithGenericStream
#include "node_counters.h"
#include "node_internals.h"
+#include "util.h"
+#include "util-inl.h"
namespace node {
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_);
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.");
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");
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);
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,
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);
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");
#include "node_wrap.h"
#include "req_wrap.h"
#include "stream_wrap.h"
+#include "util.h"
+#include "util-inl.h"
namespace node {
TTYWrap* TTYWrap::Unwrap(Local<Object> obj) {
- TTYWrap* wrap;
- NODE_UNWRAP(obj, TTYWrap, wrap);
- return wrap;
+ return UnwrapObject<TTYWrap>(obj);
}
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;
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);
#include "node_buffer.h"
#include "handle_wrap.h"
#include "req_wrap.h"
+#include "util.h"
+#include "util-inl.h"
#include <stdlib.h>
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
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);
#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); \
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);
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());
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
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);
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>();
UDPWrap* UDPWrap::Unwrap(Local<Object> obj) {
- UDPWrap* wrap;
- NODE_UNWRAP(obj, UDPWrap, wrap);
- return wrap;
+ return UnwrapObject<UDPWrap>(obj);
}
#include "util.h"
+#include <assert.h>
+
namespace node {
template <class TypeName>
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_
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_