diff --git a/src/node.h b/src/node.h index fd872a0960..44cf0dbd53 100644 --- a/src/node.h +++ b/src/node.h @@ -58,5 +58,24 @@ ssize_t DecodeWrite(char *buf, v8::Local BuildStatsObject(struct stat * s); +static inline v8::Persistent* cb_persist( + const v8::Local &v) { + v8::Persistent *fn = new v8::Persistent(); + *fn = v8::Persistent::New(v8::Local::Cast(v)); + return fn; +} + +static inline v8::Persistent* cb_unwrap(void *data) { + v8::Persistent *cb = + reinterpret_cast*>(data); + assert((*cb)->IsFunction()); + return cb; +} + +static inline void cb_destroy(v8::Persistent * cb) { + cb->Dispose(); + delete cb; +} + } // namespace node #endif // SRC_NODE_H_ diff --git a/src/node_dns.cc b/src/node_dns.cc index 1dadab268f..f173e7e32c 100644 --- a/src/node_dns.cc +++ b/src/node_dns.cc @@ -1,5 +1,6 @@ // Copyright 2009 Ryan Dahl #include +#include #include /* exit() */ #include @@ -21,24 +22,6 @@ static ev_timer timer_watcher; static Persistent errno_symbol; -static inline Persistent* cb_persist(const Local &v) { - Persistent *fn = new Persistent(); - *fn = Persistent::New(Local::Cast(v)); - return fn; -} - -static inline Persistent* cb_unwrap(void *data) { - Persistent *cb = - reinterpret_cast*>(data); - assert((*cb)->IsFunction()); - return cb; -} - -static inline void cb_destroy(Persistent * cb) { - cb->Dispose(); - delete cb; -} - static inline void set_timeout() { int maxwait = 20; int wait = dns_timeouts(NULL, maxwait, ev_now(EV_DEFAULT_UC)); diff --git a/src/node_file.cc b/src/node_file.cc index 1289064323..c378cabb29 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -30,9 +30,7 @@ static inline Local errno_exception(int errorno) { static int After(eio_req *req) { HandleScope scope; - Persistent *callback = - reinterpret_cast*>(req->data); - assert((*callback)->IsFunction()); + Persistent *callback = cb_unwrap(req->data); ev_unref(EV_DEFAULT_UC); @@ -124,21 +122,14 @@ static int After(eio_req *req) { } // Dispose of the persistent handle - callback->Dispose(); - delete callback; + cb_destroy(callback); return 0; } -static Persistent* persistent_callback(const Local &v) { - Persistent *fn = new Persistent(); - *fn = Persistent::New(Local::Cast(v)); - return fn; -} - #define ASYNC_CALL(func, callback, ...) \ eio_req *req = eio_##func(__VA_ARGS__, EIO_PRI_DEFAULT, After, \ - persistent_callback(callback)); \ + cb_persist(callback)); \ assert(req); \ ev_ref(EV_DEFAULT_UC); \ return Undefined();