Permalink
Browse files

MakeCallback: Accept Function or Symbol argument

  • Loading branch information...
1 parent 80a55e9 commit 7407be896ef4cacaa96b383cb24b692c47debf62 @isaacs isaacs committed Apr 13, 2012
Showing with 36 additions and 7 deletions.
  1. +26 −6 src/node.cc
  2. +10 −1 src/node.h
View
32 src/node.cc
@@ -972,19 +972,39 @@ Handle<Value> FromConstructorTemplate(Persistent<FunctionTemplate>& t,
//
// Maybe make this a method of a node::Handle super class
//
-void MakeCallback(Handle<Object> object,
- const char* method,
- int argc,
- Handle<Value> argv[]) {
+void
+MakeCallback(const Handle<Object> object,
+ const char* method,
+ int argc,
+ Handle<Value> argv[]) {
+ HandleScope scope;
+ return scope.Close(MakeCallback(object, String::NewSymbol(method), argc, argv));
+}
+
+void
+MakeCallback(const Handle<Object> object,
+ const Handle<String> symbol,
+ int argc,
+ Handle<Value> argv[]) {
HandleScope scope;
- Local<Value> callback_v = object->Get(String::New(method));
+ Local<Value> callback_v = object->Get(symbol);
if (!callback_v->IsFunction()) {
- fprintf(stderr, "method = %s", method);
+ String::Utf8Value method(symbol);
+ fprintf(stderr, "method = %s", *method);
}
assert(callback_v->IsFunction());
Local<Function> callback = Local<Function>::Cast(callback_v);
+}
+
+void
+MakeCallback(const Handle<Object> object,
+ const Handle<Function> callback,
+ int argc,
+ Handle<Value> argv[]) {
+ HandleScope scope;
+
// TODO Hook for long stack traces to be made here.
TryCatch try_catch;
View
11 src/node.h
@@ -243,10 +243,19 @@ node_module_struct* get_builtin_module(const char *name);
extern "C" node::node_module_struct modname ## _module;
NODE_EXTERN void SetErrno(uv_err_t err);
-NODE_EXTERN void MakeCallback(v8::Handle<v8::Object> object,
+NODE_EXTERN void MakeCallback(const v8::Handle<v8::Object> object,
const char* method,
int argc,
v8::Handle<v8::Value> argv[]);
+NODE_EXTERN void MakeCallback(const v8::Handle<v8::Object> object,
+ const v8::Handle<v8::String> symbol,
+ int argc,
+ v8::Handle<v8::Value> argv[]);
+
+NODE_EXTERN void MakeCallback(const v8::Handle<v8::Object> object,
+ const v8::Handle<v8::Function> callback,
+ int argc,
+ v8::Handle<v8::Value> argv[]);
} // namespace node
#endif // SRC_NODE_H_

0 comments on commit 7407be8

Please sign in to comment.