Skip to content

Commit a26bee8

Browse files
committed
MakeCallback: Consistent symbol usage
1 parent db45b2c commit a26bee8

15 files changed

Lines changed: 93 additions & 38 deletions

src/cares_wrap.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ class QueryWrap {
218218
void CallOnComplete(Local<Value> answer) {
219219
HandleScope scope;
220220
Local<Value> argv[2] = { Integer::New(0), answer };
221-
MakeCallback(object_, "oncomplete", 2, argv);
221+
MakeCallback(object_, oncomplete_sym, ARRAY_SIZE(argv), argv);
222222
}
223223

224224
void CallOnComplete(Local<Value> answer, Local<Value> family) {
225225
HandleScope scope;
226226
Local<Value> argv[3] = { Integer::New(0), answer, family };
227-
MakeCallback(object_, "oncomplete", 3, argv);
227+
MakeCallback(object_, oncomplete_sym, ARRAY_SIZE(argv), argv);
228228
}
229229

230230
void ParseError(int status) {
@@ -233,7 +233,7 @@ class QueryWrap {
233233

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

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

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

684684
delete req_wrap;
685685
}
@@ -755,7 +755,7 @@ static void Initialize(Handle<Object> target) {
755755
target->Set(String::NewSymbol("AF_INET6"), Integer::New(AF_INET6));
756756
target->Set(String::NewSymbol("AF_UNSPEC"), Integer::New(AF_UNSPEC));
757757

758-
oncomplete_sym = Persistent<String>::New(String::NewSymbol("oncomplete"));
758+
oncomplete_sym = NODE_PSYMBOL("oncomplete");
759759
}
760760

761761

src/fs_event_wrap.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ using namespace v8;
2828

2929
namespace node {
3030

31+
static Persistent<String> onchange_sym;
32+
3133
#define UNWRAP \
3234
assert(!args.Holder().IsEmpty()); \
3335
assert(args.Holder()->InternalFieldCount() > 0); \
@@ -165,7 +167,11 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
165167
filename ? (Local<Value>)String::New(filename) : Local<Value>::New(v8::Null())
166168
};
167169

168-
MakeCallback(wrap->object_, "onchange", 3, argv);
170+
if (onchange_sym.IsEmpty()) {
171+
onchange_sym = NODE_PSYMBOL("onchange");
172+
}
173+
174+
MakeCallback(wrap->object_, onchange_sym, ARRAY_SIZE(argv), argv);
169175
}
170176

171177

src/node.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ static void Tick(void) {
231231

232232
if (tick_callback_sym.IsEmpty()) {
233233
// Lazily set the symbol
234-
tick_callback_sym =
235-
Persistent<String>::New(String::NewSymbol("_tickCallback"));
234+
tick_callback_sym = NODE_PSYMBOL("_tickCallback");
236235
}
237236

238237
Local<Value> cb_v = process->Get(tick_callback_sym);
@@ -978,7 +977,11 @@ MakeCallback(const Handle<Object> object,
978977
int argc,
979978
Handle<Value> argv[]) {
980979
HandleScope scope;
981-
return scope.Close(MakeCallback(object, String::NewSymbol(method), argc, argv));
980+
981+
Handle<Value> ret =
982+
MakeCallback(object, String::NewSymbol(method), argc, argv);
983+
984+
return scope.Close(ret);
982985
}
983986

984987
Handle<Value>

src/node_buffer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,8 @@ void Buffer::Initialize(Handle<Object> target) {
741741
assert(unbase64('\n') == -2);
742742
assert(unbase64('\r') == -2);
743743

744-
length_symbol = Persistent<String>::New(String::NewSymbol("length"));
745-
chars_written_sym = Persistent<String>::New(String::NewSymbol("_charsWritten"));
744+
length_symbol = NODE_PSYMBOL("length");
745+
chars_written_sym = NODE_PSYMBOL("_charsWritten");
746746

747747
Local<FunctionTemplate> t = FunctionTemplate::New(Buffer::New);
748748
constructor_template = Persistent<FunctionTemplate>::New(t);

src/node_crypto.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ static Persistent<String> fingerprint_symbol;
8282
static Persistent<String> name_symbol;
8383
static Persistent<String> version_symbol;
8484
static Persistent<String> ext_key_usage_symbol;
85+
static Persistent<String> onhandshakestart_sym;
86+
static Persistent<String> onhandshakedone_sym;
8587

8688
static Persistent<FunctionTemplate> secure_context_constructor;
8789

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

869871
// If ret is SecureContext
870872
if (secure_context_constructor->HasInstance(ret)) {
@@ -971,12 +973,18 @@ void Connection::SSLInfoCallback(const SSL *ssl, int where, int ret) {
971973
if (where & SSL_CB_HANDSHAKE_START) {
972974
HandleScope scope;
973975
Connection* c = static_cast<Connection*>(SSL_get_app_data(ssl));
974-
MakeCallback(c->handle_, "onhandshakestart", 0, NULL);
976+
if (onhandshakestart_sym.IsEmpty()) {
977+
onhandshakestart_sym = NODE_PSYMBOL("onhandshakestart");
978+
}
979+
MakeCallback(c->handle_, onhandshakestart_sym, 0, NULL);
975980
}
976981
if (where & SSL_CB_HANDSHAKE_DONE) {
977982
HandleScope scope;
978983
Connection* c = static_cast<Connection*>(SSL_get_app_data(ssl));
979-
MakeCallback(c->handle_, "onhandshakedone", 0, NULL);
984+
if (onhandshakedone_sym.IsEmpty()) {
985+
onhandshakedone_sym = NODE_PSYMBOL("onhandshakedone");
986+
}
987+
MakeCallback(c->handle_, onhandshakedone_sym, 0, NULL);
980988
}
981989
}
982990

@@ -4117,7 +4125,7 @@ EIO_PBKDF2After(uv_work_t* req) {
41174125

41184126
MakeCallback(Context::GetCurrent()->Global(),
41194127
request->callback,
4120-
2, argv);
4128+
ARRAY_SIZE(argv), argv);
41214129

41224130
delete[] request->pass;
41234131
delete[] request->salt;
@@ -4307,7 +4315,7 @@ void RandomBytesAfter(uv_work_t* work_req) {
43074315

43084316
MakeCallback(Context::GetCurrent()->Global(),
43094317
req->callback_,
4310-
2, argv);
4318+
ARRAY_SIZE(argv), argv);
43114319

43124320
delete req;
43134321
}

src/node_file.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ static void After(uv_fs_t *req) {
193193
}
194194
}
195195

196-
MakeCallback(req_wrap->object_, "oncomplete", argc, argv);
196+
if (oncomplete_sym.IsEmpty()) {
197+
oncomplete_sym = NODE_PSYMBOL("oncomplete");
198+
}
199+
MakeCallback(req_wrap->object_, oncomplete_sym, argc, argv);
197200

198201
uv_fs_req_cleanup(&req_wrap->req_);
199202
delete req_wrap;

src/node_io_watcher.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void IOWatcher::Callback(EV_P_ ev_io *w, int revents) {
6969
argv[0] = Local<Value>::New(revents & EV_READ ? True() : False());
7070
argv[1] = Local<Value>::New(revents & EV_WRITE ? True() : False());
7171

72-
MakeCallback(io->handle_, callback, 2, argv);
72+
MakeCallback(io->handle_, callback, ARRAY_SIZE(argv), argv);
7373
}
7474

7575

src/node_stat_watcher.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ namespace node {
3030
using namespace v8;
3131

3232
Persistent<FunctionTemplate> StatWatcher::constructor_template;
33+
static Persistent<String> onchange_sym;
34+
static Persistent<String> onstop_sym;
3335

3436
void StatWatcher::Initialize(Handle<Object> target) {
3537
HandleScope scope;
@@ -54,7 +56,10 @@ void StatWatcher::Callback(EV_P_ ev_stat *watcher, int revents) {
5456
Local<Value> argv[2];
5557
argv[0] = BuildStatsObject(&watcher->attr);
5658
argv[1] = BuildStatsObject(&watcher->prev);
57-
MakeCallback(handler->handle_, "onchange", 2, argv);
59+
if (onchange_sym.IsEmpty()) {
60+
onchange_sym = NODE_PSYMBOL("onchange");
61+
}
62+
MakeCallback(handler->handle_, onchange_sym, ARRAY_SIZE(argv), argv);
5863
}
5964

6065

@@ -106,7 +111,10 @@ Handle<Value> StatWatcher::Start(const Arguments& args) {
106111
Handle<Value> StatWatcher::Stop(const Arguments& args) {
107112
HandleScope scope;
108113
StatWatcher *handler = ObjectWrap::Unwrap<StatWatcher>(args.Holder());
109-
MakeCallback(handler->handle_, "onstop", 0, NULL);
114+
if (onstop_sym.IsEmpty()) {
115+
onstop_sym = NODE_PSYMBOL("onstop");
116+
}
117+
MakeCallback(handler->handle_, onstop_sym, 0, NULL);
110118
handler->Stop();
111119
return Undefined();
112120
}

src/node_zlib.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class ZCtx : public ObjectWrap {
211211
assert(ctx->handle_->Get(callback_sym)->IsFunction() &&
212212
"Invalid callback");
213213
Local<Value> args[2] = { avail_in, avail_out };
214-
MakeCallback(ctx->handle_, "callback", 2, args);
214+
MakeCallback(ctx->handle_, callback_sym, ARRAY_SIZE(args), args);
215215

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

234234
// no hope of rescue.
235235
ctx->Unref();

src/pipe_wrap.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ using v8::Boolean;
5757

5858
Persistent<Function> pipeConstructor;
5959

60+
static Persistent<String> onconnection_sym;
61+
static Persistent<String> oncomplete_sym;
62+
6063

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

216219
// Successful accept. Call the onconnection callback in JavaScript land.
217220
Local<Value> argv[1] = { client_obj };
218-
MakeCallback(wrap->object_, "onconnection", 1, argv);
221+
if (onconnection_sym.IsEmpty()) {
222+
onconnection_sym = NODE_PSYMBOL("onconnection");
223+
}
224+
MakeCallback(wrap->object_, onconnection_sym, ARRAY_SIZE(argv), argv);
219225
}
220226

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

250-
MakeCallback(req_wrap->object_, "oncomplete", 5, argv);
256+
if (oncomplete_sym.IsEmpty()) {
257+
oncomplete_sym = NODE_PSYMBOL("oncomplete");
258+
}
259+
MakeCallback(req_wrap->object_, oncomplete_sym, ARRAY_SIZE(argv), argv);
251260

252261
delete req_wrap;
253262
}

0 commit comments

Comments
 (0)