From 47fad676b44976b2e8fc23450eaed4a538cc5c7a Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 21 Apr 2009 15:55:11 +0200 Subject: [PATCH] Rename JS_ to NODE_ for method macros. add marcos to timers.cc --- src/file.cc | 40 ++++++++++++++++++++-------------------- src/node.cc | 8 ++++---- src/node.h | 8 ++++---- src/timers.cc | 34 +++++++++------------------------- 4 files changed, 37 insertions(+), 53 deletions(-) diff --git a/src/file.cc b/src/file.cc index b7a6579a6c1..60e503ad78e 100644 --- a/src/file.cc +++ b/src/file.cc @@ -155,31 +155,31 @@ FileSystem::AfterStat (eio_req *req) struct stat *s = static_cast(req->ptr2); /* ID of device containing file */ - stats->Set(JS_SYMBOL("dev"), Integer::New(s->st_dev)); + stats->Set(NODE_SYMBOL("dev"), Integer::New(s->st_dev)); /* inode number */ - stats->Set(JS_SYMBOL("ino"), Integer::New(s->st_ino)); + stats->Set(NODE_SYMBOL("ino"), Integer::New(s->st_ino)); /* protection */ - stats->Set(JS_SYMBOL("mode"), Integer::New(s->st_mode)); + stats->Set(NODE_SYMBOL("mode"), Integer::New(s->st_mode)); /* number of hard links */ - stats->Set(JS_SYMBOL("nlink"), Integer::New(s->st_nlink)); + stats->Set(NODE_SYMBOL("nlink"), Integer::New(s->st_nlink)); /* user ID of owner */ - stats->Set(JS_SYMBOL("uid"), Integer::New(s->st_uid)); + stats->Set(NODE_SYMBOL("uid"), Integer::New(s->st_uid)); /* group ID of owner */ - stats->Set(JS_SYMBOL("gid"), Integer::New(s->st_gid)); + stats->Set(NODE_SYMBOL("gid"), Integer::New(s->st_gid)); /* device ID (if special file) */ - stats->Set(JS_SYMBOL("rdev"), Integer::New(s->st_rdev)); + stats->Set(NODE_SYMBOL("rdev"), Integer::New(s->st_rdev)); /* total size, in bytes */ - stats->Set(JS_SYMBOL("size"), Integer::New(s->st_size)); + stats->Set(NODE_SYMBOL("size"), Integer::New(s->st_size)); /* blocksize for filesystem I/O */ - stats->Set(JS_SYMBOL("blksize"), Integer::New(s->st_blksize)); + stats->Set(NODE_SYMBOL("blksize"), Integer::New(s->st_blksize)); /* number of blocks allocated */ - stats->Set(JS_SYMBOL("blocks"), Integer::New(s->st_blocks)); + stats->Set(NODE_SYMBOL("blocks"), Integer::New(s->st_blocks)); /* time of last access */ - stats->Set(JS_SYMBOL("atime"), Date::New(1000*static_cast(s->st_atime))); + stats->Set(NODE_SYMBOL("atime"), Date::New(1000*static_cast(s->st_atime))); /* time of last modification */ - stats->Set(JS_SYMBOL("mtime"), Date::New(1000*static_cast(s->st_mtime))); + stats->Set(NODE_SYMBOL("mtime"), Date::New(1000*static_cast(s->st_mtime))); /* time of last status change */ - stats->Set(JS_SYMBOL("ctime"), Date::New(1000*static_cast(s->st_ctime))); + stats->Set(NODE_SYMBOL("ctime"), Date::New(1000*static_cast(s->st_ctime))); } CallTopCallback(fs, argc, argv); @@ -499,16 +499,16 @@ NodeInit_file (Handle target) target->Set(String::NewSymbol("File"), fs); // file system methods - JS_SET_METHOD(fs, "_ffi_rename", FileSystem::Rename); - JS_SET_METHOD(fs, "_ffi_stat", FileSystem::Stat); - JS_SET_METHOD(fs, "strerror", FileSystem::StrError); + NODE_SET_METHOD(fs, "_ffi_rename", FileSystem::Rename); + NODE_SET_METHOD(fs, "_ffi_stat", FileSystem::Stat); + NODE_SET_METHOD(fs, "strerror", FileSystem::StrError); fs->Set(String::NewSymbol("STDIN_FILENO"), Integer::New(STDIN_FILENO)); fs->Set(String::NewSymbol("STDOUT_FILENO"), Integer::New(STDOUT_FILENO)); fs->Set(String::NewSymbol("STDERR_FILENO"), Integer::New(STDERR_FILENO)); // file methods - JS_SET_METHOD(file_template->InstanceTemplate(), "_ffi_open", File::Open); - JS_SET_METHOD(file_template->InstanceTemplate(), "_ffi_close", File::Close); - JS_SET_METHOD(file_template->InstanceTemplate(), "_ffi_write", File::Write); - JS_SET_METHOD(file_template->InstanceTemplate(), "_ffi_read", File::Read); + NODE_SET_METHOD(file_template->InstanceTemplate(), "_ffi_open", File::Open); + NODE_SET_METHOD(file_template->InstanceTemplate(), "_ffi_close", File::Close); + NODE_SET_METHOD(file_template->InstanceTemplate(), "_ffi_write", File::Write); + NODE_SET_METHOD(file_template->InstanceTemplate(), "_ffi_read", File::Read); } diff --git a/src/node.cc b/src/node.cc index 96578393cbe..e6c296dc196 100644 --- a/src/node.cc +++ b/src/node.cc @@ -87,7 +87,7 @@ ExecuteString(v8::Handle source, return scope.Close(result); } -JS_METHOD(compile) +NODE_METHOD(compile) { if (args.Length() < 2) return Undefined(); @@ -102,7 +102,7 @@ JS_METHOD(compile) return scope.Close(result); } -JS_METHOD(debug) +NODE_METHOD(debug) { if (args.Length() < 1) return Undefined(); @@ -194,8 +194,8 @@ main (int argc, char *argv[]) Local node = Object::New(); g->Set(String::New("node"), node); - JS_SET_METHOD(node, "compile", compile); - JS_SET_METHOD(node, "debug", debug); + NODE_SET_METHOD(node, "compile", compile); + NODE_SET_METHOD(node, "debug", debug); Local arguments = Array::New(argc); for (int i = 0; i < argc; i++) { diff --git a/src/node.h b/src/node.h index eabf7bd8540..04f1bb4feb2 100644 --- a/src/node.h +++ b/src/node.h @@ -5,10 +5,10 @@ #include #include -#define JS_SYMBOL(name) v8::String::NewSymbol(name) -#define JS_METHOD(name) v8::Handle name (const v8::Arguments& args) -#define JS_SET_METHOD(obj, name, callback) \ - obj->Set(JS_SYMBOL(name), v8::FunctionTemplate::New(callback)->GetFunction()) +#define NODE_SYMBOL(name) v8::String::NewSymbol(name) +#define NODE_METHOD(name) v8::Handle name (const v8::Arguments& args) +#define NODE_SET_METHOD(obj, name, callback) \ + obj->Set(NODE_SYMBOL(name), v8::FunctionTemplate::New(callback)->GetFunction()) enum encoding {UTF8, RAW}; diff --git a/src/timers.cc b/src/timers.cc index 90b0cdcf396..88154ed81dc 100644 --- a/src/timers.cc +++ b/src/timers.cc @@ -99,8 +99,7 @@ UnwrapTimeoutID (Handle timeoutID) // // * delay is the number of milliseconds (thousandths of a second) that the // function call should be delayed by. -static Handle -setTimeout(const Arguments& args) +NODE_METHOD(setTimeout) { if (args.Length() < 2) return Undefined(); @@ -108,7 +107,7 @@ setTimeout(const Arguments& args) HandleScope scope; Local callback = Local::Cast(args[0]); - uint32_t delay = args[1]->Uint32Value(); + int delay = args[1]->IntegerValue(); ev_tstamp after = (double)delay / 1000.0; @@ -132,9 +131,7 @@ setTimeout(const Arguments& args) } // clearTimeout(timeoutID) -static Handle clearTimeout - ( const Arguments& args - ) +NODE_METHOD(clearTimeout) { if (args.Length() < 1) return Undefined(); @@ -161,9 +158,7 @@ static Handle clearTimeout // // * delay is the number of milliseconds (thousandths of a second) that the // setInterval() function should wait before each call to func. -static Handle setInterval - ( const Arguments& args - ) +NODE_METHOD(setInterval) { if (args.Length() < 2) return Undefined(); @@ -171,7 +166,7 @@ static Handle setInterval HandleScope scope; Local callback = Local::Cast(args[0]); - uint32_t delay = args[1]->Uint32Value(); + int delay = args[1]->IntegerValue(); ev_tstamp after = (double)delay / 1000.0; @@ -192,19 +187,8 @@ NodeInit_timers (Handle target) { HandleScope scope; - target->Set ( String::New("setTimeout") - , FunctionTemplate::New(setTimeout)->GetFunction() - ); - - target->Set ( String::New("clearTimeout") - , FunctionTemplate::New(clearTimeout)->GetFunction() - ); - - target->Set ( String::New("setInterval") - , FunctionTemplate::New(setInterval)->GetFunction() - ); - - target->Set ( String::New("clearInterval") - , FunctionTemplate::New(clearTimeout)->GetFunction() - ); + NODE_SET_METHOD(target, "setTimeout", setTimeout); + NODE_SET_METHOD(target, "clearTimeout", clearTimeout); + NODE_SET_METHOD(target, "setInterval", setInterval); + NODE_SET_METHOD(target, "clearInterval", clearTimeout); }