v8::Local<v8::Object> BuildStatsObject(struct stat * s);
+static inline v8::Persistent<v8::Function>* cb_persist(
+ const v8::Local<v8::Value> &v) {
+ v8::Persistent<v8::Function> *fn = new v8::Persistent<v8::Function>();
+ *fn = v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(v));
+ 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();
+ delete cb;
+}
+
} // namespace node
#endif // SRC_NODE_H_
// Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#include <node_dns.h>
+#include <node.h>
#include <stdlib.h> /* exit() */
#include <sys/types.h>
static Persistent<String> errno_symbol;
-static inline Persistent<Function>* cb_persist(const Local<Value> &v) {
- Persistent<Function> *fn = new Persistent<Function>();
- *fn = Persistent<Function>::New(Local<Function>::Cast(v));
- return fn;
-}
-
-static inline Persistent<Function>* cb_unwrap(void *data) {
- Persistent<Function> *cb =
- reinterpret_cast<Persistent<Function>*>(data);
- assert((*cb)->IsFunction());
- return cb;
-}
-
-static inline void cb_destroy(Persistent<Function> * cb) {
- cb->Dispose();
- delete cb;
-}
-
static inline void set_timeout() {
int maxwait = 20;
int wait = dns_timeouts(NULL, maxwait, ev_now(EV_DEFAULT_UC));
static int After(eio_req *req) {
HandleScope scope;
- Persistent<Function> *callback =
- reinterpret_cast<Persistent<Function>*>(req->data);
- assert((*callback)->IsFunction());
+ Persistent<Function> *callback = cb_unwrap(req->data);
ev_unref(EV_DEFAULT_UC);
}
// Dispose of the persistent handle
- callback->Dispose();
- delete callback;
+ cb_destroy(callback);
return 0;
}
-static Persistent<Function>* persistent_callback(const Local<Value> &v) {
- Persistent<Function> *fn = new Persistent<Function>();
- *fn = Persistent<Function>::New(Local<Function>::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();