MakeCallback: Consistent symbol usage
This commit is contained in:
parent
db45b2ca02
commit
a26bee8fa1
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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_;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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_;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user