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:
authorRoman Shtylman <shtylman@gmail.com>2012-01-30 20:58:08 +0400
committerBen Noordhuis <info@bnoordhuis.nl>2012-01-30 23:22:38 +0400
commite97b961815b8804e17d6793101960db53e4c32a2 (patch)
tree352c7550b8ffdf6b7046cf4a203915ad7806cc34 /src
parent836344c90ed139f2e18bbcfb18d0ff2e2e42da81 (diff)
add node::SetMethod and node::SetPrototypeMethod
defines cannot be used if the callback is a templated and has multiple template arguments. The comma separating the arguments breaks the preprocessor argument handling. Using a templated function is clearer and more idiomatic in c++.
Diffstat (limited to 'src')
-rw-r--r--src/node.h32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/node.h b/src/node.h
index f17c3fcf815..9acc75c32d2 100644
--- a/src/node.h
+++ b/src/node.h
@@ -101,19 +101,25 @@ uv_loop_t* Loop();
static_cast<v8::PropertyAttribute>( \
v8::ReadOnly|v8::DontDelete))
-#define NODE_SET_METHOD(obj, name, callback) \
- obj->Set(v8::String::NewSymbol(name), \
- v8::FunctionTemplate::New(callback)->GetFunction())
-
-#define NODE_SET_PROTOTYPE_METHOD(templ, name, callback) \
-do { \
- v8::Local<v8::Signature> __callback##_SIG = v8::Signature::New(templ); \
- v8::Local<v8::FunctionTemplate> __callback##_TEM = \
- v8::FunctionTemplate::New(callback, v8::Handle<v8::Value>(), \
- __callback##_SIG); \
- templ->PrototypeTemplate()->Set(v8::String::NewSymbol(name), \
- __callback##_TEM); \
-} while (0)
+template <typename target_t>
+void SetMethod(target_t obj, const char* name,
+ v8::InvocationCallback callback)
+{
+ obj->Set(v8::String::NewSymbol(name),
+ v8::FunctionTemplate::New(callback)->GetFunction());
+}
+
+template <typename target_t>
+void SetPrototypeMethod(target_t target,
+ const char* name, v8::InvocationCallback callback)
+{
+ v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(callback);
+ target->PrototypeTemplate()->Set(v8::String::NewSymbol(name), templ);
+}
+
+// for backwards compatibility
+#define NODE_SET_METHOD node::SetMethod
+#define NODE_SET_PROTOTYPE_METHOD node::SetPrototypeMethod
enum encoding {ASCII, UTF8, BASE64, UCS2, BINARY, HEX};
enum encoding ParseEncoding(v8::Handle<v8::Value> encoding_v,