diff --git a/src/main.js b/src/main.js index 95b25999a6..b9c8051a74 100644 --- a/src/main.js +++ b/src/main.js @@ -35,13 +35,13 @@ node.path = new function () { // Timers function setTimeout (callback, delay) { - var timer = new Timer(callback, delay, 0); + var timer = new node.Timer(callback, delay, 0); timer.start(); return timer; }; function setInterval (callback, delay) { - var timer = new Timer(callback, delay, delay); + var timer = new node.Timer(callback, delay, delay); timer.start(); return timer; }; diff --git a/src/node.cc b/src/node.cc index 36d8bebbde..7bcdc1bc46 100644 --- a/src/node.cc +++ b/src/node.cc @@ -266,7 +266,7 @@ main (int argc, char *argv[]) // BUILT-IN MODULES - node::Init_timer(g); + Timer::Initialize(node); File::Initialize(g); diff --git a/src/timer.cc b/src/timer.cc index 21553f1b6f..518259559d 100644 --- a/src/timer.cc +++ b/src/timer.cc @@ -5,19 +5,18 @@ using namespace v8; using namespace node; -class Timer : ObjectWrap { - public: - Timer(Handle handle, Handle callback, ev_tstamp after, ev_tstamp repeat); - ~Timer(); +void +Timer::Initialize (Handle target) +{ + HandleScope scope; - static Handle New (const Arguments& args); - static Handle Start (const Arguments& args); - static Handle Stop (const Arguments& args); + Local timer_template = FunctionTemplate::New(Timer::New); + timer_template->InstanceTemplate()->SetInternalFieldCount(1); + target->Set(String::NewSymbol("Timer"), timer_template->GetFunction()); - private: - static void OnTimeout (EV_P_ ev_timer *watcher, int revents); - ev_timer watcher_; -}; + NODE_SET_METHOD(timer_template->InstanceTemplate(), "start", Timer::Start); + NODE_SET_METHOD(timer_template->InstanceTemplate(), "stop", Timer::Stop); +} void Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents) @@ -99,16 +98,3 @@ Timer::Stop (const Arguments& args) timer->Detach(); return Undefined(); } - -void -node::Init_timer (Handle target) -{ - HandleScope scope; - - Local timer_template = FunctionTemplate::New(Timer::New); - timer_template->InstanceTemplate()->SetInternalFieldCount(1); - target->Set(String::NewSymbol("Timer"), timer_template->GetFunction()); - - NODE_SET_METHOD(timer_template->InstanceTemplate(), "start", Timer::Start); - NODE_SET_METHOD(timer_template->InstanceTemplate(), "stop", Timer::Stop); -} diff --git a/src/timer.h b/src/timer.h index ab64c27ae2..cee3be4da0 100644 --- a/src/timer.h +++ b/src/timer.h @@ -1,11 +1,31 @@ #ifndef node_timer_h #define node_timer_h +#include "node.h" #include +#include namespace node { -void Init_timer (v8::Handle target); +class Timer : ObjectWrap { + public: + static void Initialize (v8::Handle target); + + protected: + Timer(v8::Handle handle, + v8::Handle callback, + ev_tstamp after, + ev_tstamp repeat); + ~Timer(); + + static v8::Handle New (const v8::Arguments& args); + static v8::Handle Start (const v8::Arguments& args); + static v8::Handle Stop (const v8::Arguments& args); + + private: + static void OnTimeout (EV_P_ ev_timer *watcher, int revents); + ev_timer watcher_; +}; } // namespace node #endif // node_timer_h