Skip to content

Commit

Permalink
MakeCallback: Consistent symbol usage
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 17, 2012
1 parent db45b2c commit a26bee8
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 38 deletions.
10 changes: 5 additions & 5 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ class QueryWrap {
void CallOnComplete(Local<Value> answer) {
HandleScope scope;
Local<Value> argv[2] = { Integer::New(0), answer };
MakeCallback(object_, "oncomplete", 2, argv);
MakeCallback(object_, oncomplete_sym, ARRAY_SIZE(argv), argv);
}

void CallOnComplete(Local<Value> answer, Local<Value> family) {
HandleScope scope;
Local<Value> argv[3] = { Integer::New(0), answer, family };
MakeCallback(object_, "oncomplete", 3, argv);
MakeCallback(object_, oncomplete_sym, ARRAY_SIZE(argv), argv);
}

void ParseError(int status) {
Expand All @@ -233,7 +233,7 @@ class QueryWrap {

HandleScope scope;
Local<Value> argv[1] = { Integer::New(-1) };
MakeCallback(object_, "oncomplete", 1, argv);
MakeCallback(object_, oncomplete_sym, ARRAY_SIZE(argv), argv);
}

// Subclasses should implement the appropriate Parse method.
Expand Down Expand Up @@ -679,7 +679,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
uv_freeaddrinfo(res);

// Make the callback into JavaScript
MakeCallback(req_wrap->object_, "oncomplete", 1, argv);
MakeCallback(req_wrap->object_, oncomplete_sym, ARRAY_SIZE(argv), argv);

delete req_wrap;
}
Expand Down Expand Up @@ -755,7 +755,7 @@ static void Initialize(Handle<Object> target) {
target->Set(String::NewSymbol("AF_INET6"), Integer::New(AF_INET6));
target->Set(String::NewSymbol("AF_UNSPEC"), Integer::New(AF_UNSPEC));

oncomplete_sym = Persistent<String>::New(String::NewSymbol("oncomplete"));
oncomplete_sym = NODE_PSYMBOL("oncomplete");
}


Expand Down
8 changes: 7 additions & 1 deletion src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ using namespace v8;

namespace node {

static Persistent<String> onchange_sym;

#define UNWRAP \
assert(!args.Holder().IsEmpty()); \
assert(args.Holder()->InternalFieldCount() > 0); \
Expand Down Expand Up @@ -165,7 +167,11 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
filename ? (Local<Value>)String::New(filename) : Local<Value>::New(v8::Null())
};

MakeCallback(wrap->object_, "onchange", 3, argv);
if (onchange_sym.IsEmpty()) {
onchange_sym = NODE_PSYMBOL("onchange");
}

MakeCallback(wrap->object_, onchange_sym, ARRAY_SIZE(argv), argv);
}


Expand Down
9 changes: 6 additions & 3 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ static void Tick(void) {

if (tick_callback_sym.IsEmpty()) {
// Lazily set the symbol
tick_callback_sym =
Persistent<String>::New(String::NewSymbol("_tickCallback"));
tick_callback_sym = NODE_PSYMBOL("_tickCallback");
}

Local<Value> cb_v = process->Get(tick_callback_sym);
Expand Down Expand Up @@ -978,7 +977,11 @@ MakeCallback(const Handle<Object> object,
int argc,
Handle<Value> argv[]) {
HandleScope scope;
return scope.Close(MakeCallback(object, String::NewSymbol(method), argc, argv));

Handle<Value> ret =
MakeCallback(object, String::NewSymbol(method), argc, argv);

return scope.Close(ret);
}

Handle<Value>
Expand Down
4 changes: 2 additions & 2 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,8 @@ void Buffer::Initialize(Handle<Object> target) {
assert(unbase64('\n') == -2);
assert(unbase64('\r') == -2);

length_symbol = Persistent<String>::New(String::NewSymbol("length"));
chars_written_sym = Persistent<String>::New(String::NewSymbol("_charsWritten"));
length_symbol = NODE_PSYMBOL("length");
chars_written_sym = NODE_PSYMBOL("_charsWritten");

Local<FunctionTemplate> t = FunctionTemplate::New(Buffer::New);
constructor_template = Persistent<FunctionTemplate>::New(t);
Expand Down
18 changes: 13 additions & 5 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ static Persistent<String> fingerprint_symbol;
static Persistent<String> name_symbol;
static Persistent<String> version_symbol;
static Persistent<String> ext_key_usage_symbol;
static Persistent<String> onhandshakestart_sym;
static Persistent<String> onhandshakedone_sym;

static Persistent<FunctionTemplate> secure_context_constructor;

Expand Down Expand Up @@ -864,7 +866,7 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) {
// Call it
Local<Value> ret;
ret = Local<Value>::New(MakeCallback(Context::GetCurrent()->Global(),
callback, 1, argv));
callback, ARRAY_SIZE(argv), argv));

// If ret is SecureContext
if (secure_context_constructor->HasInstance(ret)) {
Expand Down Expand Up @@ -971,12 +973,18 @@ void Connection::SSLInfoCallback(const SSL *ssl, int where, int ret) {
if (where & SSL_CB_HANDSHAKE_START) {
HandleScope scope;
Connection* c = static_cast<Connection*>(SSL_get_app_data(ssl));
MakeCallback(c->handle_, "onhandshakestart", 0, NULL);
if (onhandshakestart_sym.IsEmpty()) {
onhandshakestart_sym = NODE_PSYMBOL("onhandshakestart");
}
MakeCallback(c->handle_, onhandshakestart_sym, 0, NULL);
}
if (where & SSL_CB_HANDSHAKE_DONE) {
HandleScope scope;
Connection* c = static_cast<Connection*>(SSL_get_app_data(ssl));
MakeCallback(c->handle_, "onhandshakedone", 0, NULL);
if (onhandshakedone_sym.IsEmpty()) {
onhandshakedone_sym = NODE_PSYMBOL("onhandshakedone");
}
MakeCallback(c->handle_, onhandshakedone_sym, 0, NULL);
}
}

Expand Down Expand Up @@ -4117,7 +4125,7 @@ EIO_PBKDF2After(uv_work_t* req) {

MakeCallback(Context::GetCurrent()->Global(),
request->callback,
2, argv);
ARRAY_SIZE(argv), argv);

delete[] request->pass;
delete[] request->salt;
Expand Down Expand Up @@ -4307,7 +4315,7 @@ void RandomBytesAfter(uv_work_t* work_req) {

MakeCallback(Context::GetCurrent()->Global(),
req->callback_,
2, argv);
ARRAY_SIZE(argv), argv);

delete req;
}
Expand Down
5 changes: 4 additions & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ static void After(uv_fs_t *req) {
}
}

MakeCallback(req_wrap->object_, "oncomplete", argc, argv);
if (oncomplete_sym.IsEmpty()) {
oncomplete_sym = NODE_PSYMBOL("oncomplete");
}
MakeCallback(req_wrap->object_, oncomplete_sym, argc, argv);

uv_fs_req_cleanup(&req_wrap->req_);
delete req_wrap;
Expand Down
2 changes: 1 addition & 1 deletion src/node_io_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void IOWatcher::Callback(EV_P_ ev_io *w, int revents) {
argv[0] = Local<Value>::New(revents & EV_READ ? True() : False());
argv[1] = Local<Value>::New(revents & EV_WRITE ? True() : False());

MakeCallback(io->handle_, callback, 2, argv);
MakeCallback(io->handle_, callback, ARRAY_SIZE(argv), argv);
}


Expand Down
12 changes: 10 additions & 2 deletions src/node_stat_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace node {
using namespace v8;

Persistent<FunctionTemplate> StatWatcher::constructor_template;
static Persistent<String> onchange_sym;
static Persistent<String> onstop_sym;

void StatWatcher::Initialize(Handle<Object> target) {
HandleScope scope;
Expand All @@ -54,7 +56,10 @@ void StatWatcher::Callback(EV_P_ ev_stat *watcher, int revents) {
Local<Value> argv[2];
argv[0] = BuildStatsObject(&watcher->attr);
argv[1] = BuildStatsObject(&watcher->prev);
MakeCallback(handler->handle_, "onchange", 2, argv);
if (onchange_sym.IsEmpty()) {
onchange_sym = NODE_PSYMBOL("onchange");
}
MakeCallback(handler->handle_, onchange_sym, ARRAY_SIZE(argv), argv);
}


Expand Down Expand Up @@ -106,7 +111,10 @@ Handle<Value> StatWatcher::Start(const Arguments& args) {
Handle<Value> StatWatcher::Stop(const Arguments& args) {
HandleScope scope;
StatWatcher *handler = ObjectWrap::Unwrap<StatWatcher>(args.Holder());
MakeCallback(handler->handle_, "onstop", 0, NULL);
if (onstop_sym.IsEmpty()) {
onstop_sym = NODE_PSYMBOL("onstop");
}
MakeCallback(handler->handle_, onstop_sym, 0, NULL);
handler->Stop();
return Undefined();
}
Expand Down
4 changes: 2 additions & 2 deletions src/node_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class ZCtx : public ObjectWrap {
assert(ctx->handle_->Get(callback_sym)->IsFunction() &&
"Invalid callback");
Local<Value> args[2] = { avail_in, avail_out };
MakeCallback(ctx->handle_, "callback", 2, args);
MakeCallback(ctx->handle_, callback_sym, ARRAY_SIZE(args), args);

ctx->Unref();
}
Expand All @@ -229,7 +229,7 @@ class ZCtx : public ObjectWrap {
HandleScope scope;
Local<Value> args[2] = { String::New(msg),
Local<Value>::New(Number::New(ctx->err_)) };
MakeCallback(ctx->handle_, "onerror", ARRAY_SIZE(args), args);
MakeCallback(ctx->handle_, onerror_sym, ARRAY_SIZE(args), args);

// no hope of rescue.
ctx->Unref();
Expand Down
13 changes: 11 additions & 2 deletions src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ using v8::Boolean;

Persistent<Function> pipeConstructor;

static Persistent<String> onconnection_sym;
static Persistent<String> oncomplete_sym;


// TODO share with TCPWrap?
typedef class ReqWrap<uv_connect_t> ConnectWrap;
Expand Down Expand Up @@ -215,7 +218,10 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {

// Successful accept. Call the onconnection callback in JavaScript land.
Local<Value> argv[1] = { client_obj };
MakeCallback(wrap->object_, "onconnection", 1, argv);
if (onconnection_sym.IsEmpty()) {
onconnection_sym = NODE_PSYMBOL("onconnection");
}
MakeCallback(wrap->object_, onconnection_sym, ARRAY_SIZE(argv), argv);
}

// TODO Maybe share this with TCPWrap?
Expand Down Expand Up @@ -247,7 +253,10 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
Local<Value>::New(Boolean::New(writable))
};

MakeCallback(req_wrap->object_, "oncomplete", 5, argv);
if (oncomplete_sym.IsEmpty()) {
oncomplete_sym = NODE_PSYMBOL("oncomplete");
}
MakeCallback(req_wrap->object_, oncomplete_sym, ARRAY_SIZE(argv), argv);

delete req_wrap;
}
Expand Down
6 changes: 5 additions & 1 deletion src/process_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ using v8::Context;
using v8::Arguments;
using v8::Integer;

static Persistent<String> onexit_sym;

class ProcessWrap : public HandleWrap {
public:
Expand Down Expand Up @@ -223,7 +224,10 @@ class ProcessWrap : public HandleWrap {
String::New(signo_string(term_signal))
};

MakeCallback(wrap->object_, "onexit", 2, argv);
if (onexit_sym.IsEmpty()) {
onexit_sym = NODE_PSYMBOL("onexit");
}
MakeCallback(wrap->object_, onexit_sym, ARRAY_SIZE(argv), argv);
}

uv_process_t process_;
Expand Down
17 changes: 10 additions & 7 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ typedef class ReqWrap<uv_write_t> WriteWrap;

static Persistent<String> buffer_sym;
static Persistent<String> write_queue_size_sym;
static Persistent<String> onread_sym;
static Persistent<String> oncomplete_sym;
static SlabAllocator slab_allocator(SLAB_SIZE);
static bool initialized;

Expand All @@ -81,9 +83,10 @@ void StreamWrap::Initialize(Handle<Object> target) {

HandleWrap::Initialize(target);

buffer_sym = Persistent<String>::New(String::NewSymbol("buffer"));
write_queue_size_sym =
Persistent<String>::New(String::NewSymbol("writeQueueSize"));
buffer_sym = NODE_PSYMBOL("buffer");
write_queue_size_sym = NODE_PSYMBOL("writeQueueSize");
onread_sym = NODE_PSYMBOL("onread");
oncomplete_sym = NODE_PSYMBOL("oncomplete");
}


Expand Down Expand Up @@ -170,7 +173,7 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread,
}

SetErrno(uv_last_error(uv_default_loop()));
MakeCallback(wrap->object_, "onread", 0, NULL);
MakeCallback(wrap->object_, onread_sym, 0, NULL);
return;
}

Expand Down Expand Up @@ -208,7 +211,7 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread,
argc++;
}

MakeCallback(wrap->object_, "onread", argc, argv);
MakeCallback(wrap->object_, onread_sym, argc, argv);
}


Expand Down Expand Up @@ -313,7 +316,7 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) {
req_wrap->object_->GetHiddenValue(buffer_sym),
};

MakeCallback(req_wrap->object_, "oncomplete", 4, argv);
MakeCallback(req_wrap->object_, oncomplete_sym, ARRAY_SIZE(argv), argv);

delete req_wrap;
}
Expand Down Expand Up @@ -360,7 +363,7 @@ void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) {
Local<Value>::New(req_wrap->object_)
};

MakeCallback(req_wrap->object_, "oncomplete", 3, argv);
MakeCallback(req_wrap->object_, oncomplete_sym, ARRAY_SIZE(argv), argv);

delete req_wrap;
}
Expand Down
8 changes: 6 additions & 2 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ static Persistent<Function> tcpConstructor;
static Persistent<String> family_symbol;
static Persistent<String> address_symbol;
static Persistent<String> port_symbol;
static Persistent<String> oncomplete_sym;
static Persistent<String> onconnection_sym;


typedef class ReqWrap<uv_connect_t> ConnectWrap;
Expand Down Expand Up @@ -131,6 +133,8 @@ void TCPWrap::Initialize(Handle<Object> target) {
family_symbol = NODE_PSYMBOL("family");
address_symbol = NODE_PSYMBOL("address");
port_symbol = NODE_PSYMBOL("port");
onconnection_sym = NODE_PSYMBOL("onconnection");
oncomplete_sym = NODE_PSYMBOL("oncomplete");

target->Set(String::NewSymbol("TCP"), tcpConstructor);
}
Expand Down Expand Up @@ -380,7 +384,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
argv[0] = Local<Value>::New(Null());
}

MakeCallback(wrap->object_, "onconnection", 1, argv);
MakeCallback(wrap->object_, onconnection_sym, ARRAY_SIZE(argv), argv);
}


Expand All @@ -406,7 +410,7 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
Local<Value>::New(v8::True())
};

MakeCallback(req_wrap->object_, "oncomplete", 5, argv);
MakeCallback(req_wrap->object_, oncomplete_sym, ARRAY_SIZE(argv), argv);

delete req_wrap;
}
Expand Down
Loading

0 comments on commit a26bee8

Please sign in to comment.