diff --git a/src/node_timer.cc b/src/node_timer.cc index 5918feb6b8d..f7dfafe9718 100644 --- a/src/node_timer.cc +++ b/src/node_timer.cc @@ -2,18 +2,19 @@ #include #include +namespace node { + using namespace v8; -using namespace node; Persistent Timer::constructor_template; + static Persistent timeout_symbol; static Persistent repeat_symbol; static Persistent callback_symbol; -void -Timer::Initialize (Handle target) -{ + +void Timer::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(Timer::New); @@ -35,23 +36,23 @@ Timer::Initialize (Handle target) target->Set(String::NewSymbol("Timer"), constructor_template->GetFunction()); } -Handle -Timer::RepeatGetter (Local property, const AccessorInfo& info) -{ + +Handle Timer::RepeatGetter(Local property, + const AccessorInfo& info) { HandleScope scope; Timer *timer = ObjectWrap::Unwrap(info.This()); assert(timer); - assert (property == repeat_symbol); + assert(property == repeat_symbol); Local v = Integer::New(timer->watcher_.repeat); return scope.Close(v); } -void -Timer::RepeatSetter (Local property, Local value, const AccessorInfo& info) -{ +void Timer::RepeatSetter(Local property, + Local value, + const AccessorInfo& info) { HandleScope scope; Timer *timer = ObjectWrap::Unwrap(info.This()); @@ -61,9 +62,7 @@ Timer::RepeatSetter (Local property, Local value, const AccessorI timer->watcher_.repeat = NODE_V8_UNIXTIME(value); } -void -Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents) -{ +void Timer::OnTimeout(EV_P_ ev_timer *watcher, int revents) { Timer *timer = static_cast(watcher->data); assert(revents == EV_TIMEOUT); @@ -89,14 +88,13 @@ Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents) if (timer->watcher_.repeat == 0) timer->Unref(); } -Timer::~Timer () -{ + +Timer::~Timer() { ev_timer_stop(EV_DEFAULT_UC_ &watcher_); } -Handle -Timer::New (const Arguments& args) -{ + +Handle Timer::New(const Arguments& args) { if (!args.IsConstructCall()) { return FromConstructorTemplate(constructor_template, args); } @@ -109,9 +107,7 @@ Timer::New (const Arguments& args) return args.This(); } -Handle -Timer::Start (const Arguments& args) -{ +Handle Timer::Start(const Arguments& args) { HandleScope scope; Timer *timer = ObjectWrap::Unwrap(args.Holder()); @@ -145,7 +141,7 @@ Handle Timer::Stop(const Arguments& args) { } -void Timer::Stop () { +void Timer::Stop() { if (watcher_.active) { ev_timer_stop(EV_DEFAULT_UC_ &watcher_); Unref(); @@ -178,3 +174,6 @@ Handle Timer::Again(const Arguments& args) { return Undefined(); } + + +} // namespace node diff --git a/src/node_timer.h b/src/node_timer.h index 5af52728969..e945cb6bcf1 100644 --- a/src/node_timer.h +++ b/src/node_timer.h @@ -1,5 +1,5 @@ -#ifndef node_timer_h -#define node_timer_h +#ifndef SRC_NODE_TIMER_H_ +#define SRC_NODE_TIMER_H_ #include #include @@ -10,30 +10,34 @@ namespace node { class Timer : ObjectWrap { public: - static void Initialize (v8::Handle target); + static void Initialize(v8::Handle target); protected: static v8::Persistent constructor_template; - Timer () : ObjectWrap () { + Timer() : ObjectWrap() { // dummy timeout values ev_timer_init(&watcher_, OnTimeout, 0., 1.); watcher_.data = this; } + ~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); - static v8::Handle Again (const v8::Arguments& args); - static v8::Handle RepeatGetter (v8::Local property, const v8::AccessorInfo& info); - static void RepeatSetter (v8::Local property, v8::Local value, const v8::AccessorInfo& info); + static v8::Handle New(const v8::Arguments& args); + static v8::Handle Start(const v8::Arguments& args); + static v8::Handle Stop(const v8::Arguments& args); + static v8::Handle Again(const v8::Arguments& args); + static v8::Handle RepeatGetter(v8::Local property, + const v8::AccessorInfo& info); + static void RepeatSetter(v8::Local property, + v8::Local value, + const v8::AccessorInfo& info); private: - static void OnTimeout (EV_P_ ev_timer *watcher, int revents); - void Stop (); + static void OnTimeout(EV_P_ ev_timer *watcher, int revents); + void Stop(); ev_timer watcher_; }; -} // namespace node -#endif // node_timer_h +} // namespace node +#endif // SRC_NODE_TIMER_H_