From a26bee8fa16bcbdaafdee516288c6f59a43376f5 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 12 Apr 2012 16:03:47 -0700 Subject: MakeCallback: Consistent symbol usage --- src/cares_wrap.cc | 10 +++++----- src/fs_event_wrap.cc | 8 +++++++- src/node.cc | 9 ++++++--- src/node_buffer.cc | 4 ++-- src/node_crypto.cc | 18 +++++++++++++----- src/node_file.cc | 5 ++++- src/node_io_watcher.cc | 2 +- src/node_stat_watcher.cc | 12 ++++++++++-- src/node_zlib.cc | 4 ++-- src/pipe_wrap.cc | 13 +++++++++++-- src/process_wrap.cc | 6 +++++- src/stream_wrap.cc | 17 ++++++++++------- src/tcp_wrap.cc | 8 ++++++-- src/timer_wrap.cc | 5 ++++- src/udp_wrap.cc | 10 +++++++--- 15 files changed, 93 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 5c5e030c3f5..30d72387167 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -218,13 +218,13 @@ class QueryWrap { void CallOnComplete(Local answer) { HandleScope scope; Local argv[2] = { Integer::New(0), answer }; - MakeCallback(object_, "oncomplete", 2, argv); + MakeCallback(object_, oncomplete_sym, ARRAY_SIZE(argv), argv); } void CallOnComplete(Local answer, Local family) { HandleScope scope; Local argv[3] = { Integer::New(0), answer, family }; - MakeCallback(object_, "oncomplete", 3, argv); + MakeCallback(object_, oncomplete_sym, ARRAY_SIZE(argv), argv); } void ParseError(int status) { @@ -233,7 +233,7 @@ class QueryWrap { HandleScope scope; Local 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. @@ -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; } @@ -755,7 +755,7 @@ static void Initialize(Handle target) { target->Set(String::NewSymbol("AF_INET6"), Integer::New(AF_INET6)); target->Set(String::NewSymbol("AF_UNSPEC"), Integer::New(AF_UNSPEC)); - oncomplete_sym = Persistent::New(String::NewSymbol("oncomplete")); + oncomplete_sym = NODE_PSYMBOL("oncomplete"); } diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 2e66d29494e..34bb9dfd6de 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -28,6 +28,8 @@ using namespace v8; namespace node { +static Persistent onchange_sym; + #define UNWRAP \ assert(!args.Holder().IsEmpty()); \ assert(args.Holder()->InternalFieldCount() > 0); \ @@ -165,7 +167,11 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, filename ? (Local)String::New(filename) : Local::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); } diff --git a/src/node.cc b/src/node.cc index 818c1a46bc8..c5e15161b40 100644 --- a/src/node.cc +++ b/src/node.cc @@ -231,8 +231,7 @@ static void Tick(void) { if (tick_callback_sym.IsEmpty()) { // Lazily set the symbol - tick_callback_sym = - Persistent::New(String::NewSymbol("_tickCallback")); + tick_callback_sym = NODE_PSYMBOL("_tickCallback"); } Local cb_v = process->Get(tick_callback_sym); @@ -978,7 +977,11 @@ MakeCallback(const Handle object, int argc, Handle argv[]) { HandleScope scope; - return scope.Close(MakeCallback(object, String::NewSymbol(method), argc, argv)); + + Handle ret = + MakeCallback(object, String::NewSymbol(method), argc, argv); + + return scope.Close(ret); } Handle diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 7253662d606..35ddde531bc 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -741,8 +741,8 @@ void Buffer::Initialize(Handle target) { assert(unbase64('\n') == -2); assert(unbase64('\r') == -2); - length_symbol = Persistent::New(String::NewSymbol("length")); - chars_written_sym = Persistent::New(String::NewSymbol("_charsWritten")); + length_symbol = NODE_PSYMBOL("length"); + chars_written_sym = NODE_PSYMBOL("_charsWritten"); Local t = FunctionTemplate::New(Buffer::New); constructor_template = Persistent::New(t); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 8646fea21c7..5f6594b8e55 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -82,6 +82,8 @@ static Persistent fingerprint_symbol; static Persistent name_symbol; static Persistent version_symbol; static Persistent ext_key_usage_symbol; +static Persistent onhandshakestart_sym; +static Persistent onhandshakedone_sym; static Persistent secure_context_constructor; @@ -864,7 +866,7 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) { // Call it Local ret; ret = Local::New(MakeCallback(Context::GetCurrent()->Global(), - callback, 1, argv)); + callback, ARRAY_SIZE(argv), argv)); // If ret is SecureContext if (secure_context_constructor->HasInstance(ret)) { @@ -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(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(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); } } @@ -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; @@ -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; } diff --git a/src/node_file.cc b/src/node_file.cc index 099669c9d2c..f4b53a1b2fc 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -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; diff --git a/src/node_io_watcher.cc b/src/node_io_watcher.cc index feb2b640112..ad9a7b63fc2 100644 --- a/src/node_io_watcher.cc +++ b/src/node_io_watcher.cc @@ -69,7 +69,7 @@ void IOWatcher::Callback(EV_P_ ev_io *w, int revents) { argv[0] = Local::New(revents & EV_READ ? True() : False()); argv[1] = Local::New(revents & EV_WRITE ? True() : False()); - MakeCallback(io->handle_, callback, 2, argv); + MakeCallback(io->handle_, callback, ARRAY_SIZE(argv), argv); } diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index e38d581113e..efe3939e9bb 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -30,6 +30,8 @@ namespace node { using namespace v8; Persistent StatWatcher::constructor_template; +static Persistent onchange_sym; +static Persistent onstop_sym; void StatWatcher::Initialize(Handle target) { HandleScope scope; @@ -54,7 +56,10 @@ void StatWatcher::Callback(EV_P_ ev_stat *watcher, int revents) { Local 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); } @@ -106,7 +111,10 @@ Handle StatWatcher::Start(const Arguments& args) { Handle StatWatcher::Stop(const Arguments& args) { HandleScope scope; StatWatcher *handler = ObjectWrap::Unwrap(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(); } diff --git a/src/node_zlib.cc b/src/node_zlib.cc index e34c5ce1a0e..9a53df235d0 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -211,7 +211,7 @@ class ZCtx : public ObjectWrap { assert(ctx->handle_->Get(callback_sym)->IsFunction() && "Invalid callback"); Local args[2] = { avail_in, avail_out }; - MakeCallback(ctx->handle_, "callback", 2, args); + MakeCallback(ctx->handle_, callback_sym, ARRAY_SIZE(args), args); ctx->Unref(); } @@ -229,7 +229,7 @@ class ZCtx : public ObjectWrap { HandleScope scope; Local args[2] = { String::New(msg), Local::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(); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 45902d4a883..8065461c69e 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -57,6 +57,9 @@ using v8::Boolean; Persistent pipeConstructor; +static Persistent onconnection_sym; +static Persistent oncomplete_sym; + // TODO share with TCPWrap? typedef class ReqWrap ConnectWrap; @@ -215,7 +218,10 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) { // Successful accept. Call the onconnection callback in JavaScript land. Local 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? @@ -247,7 +253,10 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) { Local::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; } diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 159473b42f4..aee9a01501a 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -54,6 +54,7 @@ using v8::Context; using v8::Arguments; using v8::Integer; +static Persistent onexit_sym; class ProcessWrap : public HandleWrap { public: @@ -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_; diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 234aa3dc2f7..9fcb5b1b954 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -69,6 +69,8 @@ typedef class ReqWrap WriteWrap; static Persistent buffer_sym; static Persistent write_queue_size_sym; +static Persistent onread_sym; +static Persistent oncomplete_sym; static SlabAllocator slab_allocator(SLAB_SIZE); static bool initialized; @@ -81,9 +83,10 @@ void StreamWrap::Initialize(Handle target) { HandleWrap::Initialize(target); - buffer_sym = Persistent::New(String::NewSymbol("buffer")); - write_queue_size_sym = - Persistent::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"); } @@ -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; } @@ -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); } @@ -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; } @@ -360,7 +363,7 @@ void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) { Local::New(req_wrap->object_) }; - MakeCallback(req_wrap->object_, "oncomplete", 3, argv); + MakeCallback(req_wrap->object_, oncomplete_sym, ARRAY_SIZE(argv), argv); delete req_wrap; } diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index e571bc51246..6aee0c9093e 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -77,6 +77,8 @@ static Persistent tcpConstructor; static Persistent family_symbol; static Persistent address_symbol; static Persistent port_symbol; +static Persistent oncomplete_sym; +static Persistent onconnection_sym; typedef class ReqWrap ConnectWrap; @@ -131,6 +133,8 @@ void TCPWrap::Initialize(Handle 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); } @@ -380,7 +384,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) { argv[0] = Local::New(Null()); } - MakeCallback(wrap->object_, "onconnection", 1, argv); + MakeCallback(wrap->object_, onconnection_sym, ARRAY_SIZE(argv), argv); } @@ -406,7 +410,7 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) { Local::New(v8::True()) }; - MakeCallback(req_wrap->object_, "oncomplete", 5, argv); + MakeCallback(req_wrap->object_, oncomplete_sym, ARRAY_SIZE(argv), argv); delete req_wrap; } diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 273f8265f4c..89ebf46bb0f 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -50,6 +50,7 @@ using v8::Context; using v8::Arguments; using v8::Integer; +static Persistent ontimeout_sym; class TimerWrap : public HandleWrap { public: @@ -70,6 +71,8 @@ class TimerWrap : public HandleWrap { NODE_SET_PROTOTYPE_METHOD(constructor, "getRepeat", GetRepeat); NODE_SET_PROTOTYPE_METHOD(constructor, "again", Again); + ontimeout_sym = NODE_PSYMBOL("ontimeout"); + target->Set(String::NewSymbol("Timer"), constructor->GetFunction()); } @@ -200,7 +203,7 @@ class TimerWrap : public HandleWrap { wrap->StateChange(); Local argv[1] = { Integer::New(status) }; - MakeCallback(wrap->object_, "ontimeout", 1, argv); + MakeCallback(wrap->object_, ontimeout_sym, ARRAY_SIZE(argv), argv); } uv_timer_t handle_; diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 5ed91253eec..50f5d64c082 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -68,6 +68,8 @@ Local AddressToJS(const sockaddr* addr); static Persistent address_symbol; static Persistent port_symbol; static Persistent buffer_sym; +static Persistent oncomplete_sym; +static Persistent onmessage_sym; static SlabAllocator slab_allocator(SLAB_SIZE); @@ -130,6 +132,8 @@ void UDPWrap::Initialize(Handle target) { buffer_sym = NODE_PSYMBOL("buffer"); port_symbol = NODE_PSYMBOL("port"); address_symbol = NODE_PSYMBOL("address"); + oncomplete_sym = NODE_PSYMBOL("oncomplete"); + onmessage_sym = NODE_PSYMBOL("onmessage"); Local t = FunctionTemplate::New(New); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -394,7 +398,7 @@ void UDPWrap::OnSend(uv_udp_send_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; } @@ -422,7 +426,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle, if (nread < 0) { Local argv[] = { Local::New(wrap->object_) }; SetErrno(uv_last_error(uv_default_loop())); - MakeCallback(wrap->object_, "onmessage", ARRAY_SIZE(argv), argv); + MakeCallback(wrap->object_, onmessage_sym, ARRAY_SIZE(argv), argv); return; } @@ -433,7 +437,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle, Integer::NewFromUnsigned(nread), AddressToJS(addr) }; - MakeCallback(wrap->object_, "onmessage", ARRAY_SIZE(argv), argv); + MakeCallback(wrap->object_, onmessage_sym, ARRAY_SIZE(argv), argv); } -- cgit v1.2.3