summaryrefslogtreecommitdiff
path: root/src/pipe_wrap.cc
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2013-08-05 17:58:29 -0700
committerTrevor Norris <trev.norris@gmail.com>2013-08-12 11:49:53 -0700
commit756ae2c5360b7ab64649cb7587242a2fbd8dc95d (patch)
treea6152c93769e654073dc9128864677a22ec41007 /src/pipe_wrap.cc
parente0a8e1bf77e561ec6894540ea2aae6a52fb1d7e0 (diff)
downloadandroid-node-v8-756ae2c5360b7ab64649cb7587242a2fbd8dc95d.tar.gz
android-node-v8-756ae2c5360b7ab64649cb7587242a2fbd8dc95d.tar.bz2
android-node-v8-756ae2c5360b7ab64649cb7587242a2fbd8dc95d.zip
src: centralize class wrap/unwrap
While almost all cases were handled by simple WRAP/UNWRAP macros, this extends those to cover all known occurrences.
Diffstat (limited to 'src/pipe_wrap.cc')
-rw-r--r--src/pipe_wrap.cc42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc
index 1aa90e14c3..8c28357e00 100644
--- a/src/pipe_wrap.cc
+++ b/src/pipe_wrap.cc
@@ -66,9 +66,9 @@ Local<Object> PipeWrap::Instantiate() {
PipeWrap* PipeWrap::Unwrap(Local<Object> obj) {
- assert(!obj.IsEmpty());
- assert(obj->InternalFieldCount() > 0);
- return static_cast<PipeWrap*>(obj->GetAlignedPointerFromInternalField(0));
+ PipeWrap* wrap;
+ UNWRAP(obj, PipeWrap, wrap);
+ return wrap;
}
@@ -145,7 +145,8 @@ PipeWrap::PipeWrap(Handle<Object> object, bool ipc)
void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
- UNWRAP(PipeWrap)
+ PipeWrap* wrap;
+ UNWRAP(args.This(), PipeWrap, wrap);
String::AsciiValue name(args[0]);
int err = uv_pipe_bind(&wrap->handle_, *name);
@@ -157,7 +158,8 @@ void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
void PipeWrap::SetPendingInstances(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
- UNWRAP(PipeWrap)
+ PipeWrap* wrap;
+ UNWRAP(args.This(), PipeWrap, wrap);
int instances = args[0]->Int32Value();
@@ -169,7 +171,8 @@ void PipeWrap::SetPendingInstances(const FunctionCallbackInfo<Value>& args) {
void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
- UNWRAP(PipeWrap)
+ PipeWrap* wrap;
+ UNWRAP(args.This(), PipeWrap, wrap);
int backlog = args[0]->Int32Value();
int err = uv_listen(reinterpret_cast<uv_stream_t*>(&wrap->handle_),
@@ -183,12 +186,12 @@ void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
HandleScope scope(node_isolate);
- PipeWrap* wrap = static_cast<PipeWrap*>(handle->data);
- assert(&wrap->handle_ == reinterpret_cast<uv_pipe_t*>(handle));
+ PipeWrap* pipe_wrap = static_cast<PipeWrap*>(handle->data);
+ assert(&pipe_wrap->handle_ == reinterpret_cast<uv_pipe_t*>(handle));
// We should not be getting this callback if someone as already called
// uv_close() on the handle.
- assert(wrap->persistent().IsEmpty() == false);
+ assert(pipe_wrap->persistent().IsEmpty() == false);
Local<Value> argv[] = {
Integer::New(status, node_isolate),
@@ -196,7 +199,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
};
if (status != 0) {
- MakeCallback(wrap->object(), "onconnection", ARRAY_SIZE(argv), argv);
+ MakeCallback(pipe_wrap->object(), "onconnection", ARRAY_SIZE(argv), argv);
return;
}
@@ -204,19 +207,18 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
Local<Object> client_obj = NewInstance(pipeConstructor);
// Unwrap the client javascript object.
- assert(client_obj->InternalFieldCount() > 0);
- PipeWrap* client_wrap =
- static_cast<PipeWrap*>(client_obj->GetAlignedPointerFromInternalField(0));
- uv_stream_t* client_handle =
- reinterpret_cast<uv_stream_t*>(&client_wrap->handle_);
- if (uv_accept(handle, client_handle)) return;
+ PipeWrap* wrap;
+ UNWRAP(client_obj, PipeWrap, wrap);
+ uv_stream_t* client_handle = reinterpret_cast<uv_stream_t*>(&wrap->handle_);
+ if (uv_accept(handle, client_handle))
+ return;
// Successful accept. Call the onconnection callback in JavaScript land.
argv[1] = client_obj;
if (onconnection_sym.IsEmpty()) {
onconnection_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onconnection");
}
- MakeCallback(wrap->object(), onconnection_sym, ARRAY_SIZE(argv), argv);
+ MakeCallback(pipe_wrap->object(), onconnection_sym, ARRAY_SIZE(argv), argv);
}
// TODO(bnoordhuis) Maybe share this with TCPWrap?
@@ -260,7 +262,8 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
- UNWRAP(PipeWrap)
+ PipeWrap* wrap;
+ UNWRAP(args.This(), PipeWrap, wrap);
int fd = args[0]->IntegerValue();
@@ -271,7 +274,8 @@ void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {
void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
- UNWRAP(PipeWrap)
+ PipeWrap* wrap;
+ UNWRAP(args.This(), PipeWrap, wrap);
assert(args[0]->IsObject());
assert(args[1]->IsString());