Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-04-13 03:03:47 +0400
committerisaacs <i@izs.me>2012-04-18 00:14:54 +0400
commita26bee8fa16bcbdaafdee516288c6f59a43376f5 (patch)
tree33bdf31ce9891151c4d77ef785b86efb843b3d9e /src
parentdb45b2ca02dc23278a477625a8698ce136eb8807 (diff)
MakeCallback: Consistent symbol usage
Diffstat (limited to 'src')
-rw-r--r--src/cares_wrap.cc10
-rw-r--r--src/fs_event_wrap.cc8
-rw-r--r--src/node.cc9
-rw-r--r--src/node_buffer.cc4
-rw-r--r--src/node_crypto.cc18
-rw-r--r--src/node_file.cc5
-rw-r--r--src/node_io_watcher.cc2
-rw-r--r--src/node_stat_watcher.cc12
-rw-r--r--src/node_zlib.cc4
-rw-r--r--src/pipe_wrap.cc13
-rw-r--r--src/process_wrap.cc6
-rw-r--r--src/stream_wrap.cc17
-rw-r--r--src/tcp_wrap.cc8
-rw-r--r--src/timer_wrap.cc5
-rw-r--r--src/udp_wrap.cc10
15 files changed, 93 insertions, 38 deletions
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<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) {
@@ -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.
@@ -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<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");
}
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<String> 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<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);
}
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<String>::New(String::NewSymbol("_tickCallback"));
+ tick_callback_sym = NODE_PSYMBOL("_tickCallback");
}
Local<Value> cb_v = process->Get(tick_callback_sym);
@@ -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>
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<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);
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<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;
@@ -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)) {
@@ -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);
}
}
@@ -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<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);
}
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<FunctionTemplate> StatWatcher::constructor_template;
+static Persistent<String> onchange_sym;
+static Persistent<String> onstop_sym;
void StatWatcher::Initialize(Handle<Object> target) {
HandleScope scope;
@@ -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);
}
@@ -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();
}
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<Value> 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<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();
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<Function> pipeConstructor;
+static Persistent<String> onconnection_sym;
+static Persistent<String> oncomplete_sym;
+
// TODO share with TCPWrap?
typedef class ReqWrap<uv_connect_t> ConnectWrap;
@@ -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?
@@ -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;
}
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<String> 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<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;
@@ -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");
}
@@ -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<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;
}
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<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;
@@ -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);
}
@@ -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);
}
@@ -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;
}
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<String> 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<Value> 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<Object> AddressToJS(const sockaddr* addr);
static Persistent<String> address_symbol;
static Persistent<String> port_symbol;
static Persistent<String> buffer_sym;
+static Persistent<String> oncomplete_sym;
+static Persistent<String> onmessage_sym;
static SlabAllocator slab_allocator(SLAB_SIZE);
@@ -130,6 +132,8 @@ void UDPWrap::Initialize(Handle<Object> 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<FunctionTemplate> 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<Value> argv[] = { Local<Object>::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);
}