diff options
Diffstat (limited to 'src/node.h')
-rw-r--r-- | src/node.h | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/src/node.h b/src/node.h index 59d03a355ae..16bfec56d82 100644 --- a/src/node.h +++ b/src/node.h @@ -95,10 +95,6 @@ v8::Handle<v8::Object> SetupProcessObject(int argc, char *argv[]); void Load(v8::Handle<v8::Object> process); void EmitExit(v8::Handle<v8::Object> process); -#define NODE_PSYMBOL(s) \ - v8::Persistent<v8::String>::New(v8::Isolate::GetCurrent(), \ - v8::String::NewSymbol(s)) - /* Converts a unixtime to V8 Date */ #define NODE_UNIXTIME_V8(t) v8::Date::New(1000*static_cast<double>(t)) #define NODE_V8_UNIXTIME(v) (static_cast<double>((v)->NumberValue())/1000.0); @@ -109,25 +105,25 @@ void EmitExit(v8::Handle<v8::Object> process); static_cast<v8::PropertyAttribute>( \ v8::ReadOnly|v8::DontDelete)) -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()); +// Used to be a macro, hence the uppercase name. +template <typename TypeName> +inline void NODE_SET_METHOD(TypeName& recv, + const char* name, + v8::FunctionCallback callback) { + v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(callback); + recv->Set(v8::String::New(name), t->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); +#define NODE_SET_METHOD node::NODE_SET_METHOD + +// Used to be a macro, hence the uppercase name. +// Not a template because it only makes sense for FunctionTemplates. +inline void NODE_SET_PROTOTYPE_METHOD(v8::Handle<v8::FunctionTemplate> recv, + const char* name, + v8::FunctionCallback callback) { + v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(callback); + recv->PrototypeTemplate()->Set(v8::String::New(name), t->GetFunction()); } - -// for backwards compatibility -#define NODE_SET_METHOD node::SetMethod -#define NODE_SET_PROTOTYPE_METHOD node::SetPrototypeMethod +#define NODE_SET_PROTOTYPE_METHOD node::NODE_SET_PROTOTYPE_METHOD enum encoding {ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER}; enum encoding ParseEncoding(v8::Handle<v8::Value> encoding_v, @@ -151,25 +147,6 @@ NODE_EXTERN ssize_t DecodeWrite(char *buf, v8::Local<v8::Object> BuildStatsObject(const uv_stat_t* s); -static inline v8::Persistent<v8::Function>* cb_persist(v8::Local<v8::Value> v) { - v8::Persistent<v8::Function>* fn = new v8::Persistent<v8::Function>(); - *fn = v8::Persistent<v8::Function>::New(v8::Isolate::GetCurrent(), - v.As<v8::Function>()); - return fn; -} - -static inline v8::Persistent<v8::Function>* cb_unwrap(void *data) { - v8::Persistent<v8::Function> *cb = - reinterpret_cast<v8::Persistent<v8::Function>*>(data); - assert((*cb)->IsFunction()); - return cb; -} - -static inline void cb_destroy(v8::Persistent<v8::Function> * cb) { - cb->Dispose(v8::Isolate::GetCurrent()); - delete cb; -} - NODE_EXTERN v8::Local<v8::Value> ErrnoException(int errorno, const char *syscall = NULL, const char *msg = "", |