mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 07:00:59 +01:00
Move Timer class into node namespace.
This commit is contained in:
parent
d64a78ac46
commit
f6c955b7f4
@ -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;
|
||||
};
|
||||
|
@ -266,7 +266,7 @@ main (int argc, char *argv[])
|
||||
|
||||
|
||||
// BUILT-IN MODULES
|
||||
node::Init_timer(g);
|
||||
Timer::Initialize(node);
|
||||
|
||||
File::Initialize(g);
|
||||
|
||||
|
34
src/timer.cc
34
src/timer.cc
@ -5,19 +5,18 @@
|
||||
using namespace v8;
|
||||
using namespace node;
|
||||
|
||||
class Timer : ObjectWrap {
|
||||
public:
|
||||
Timer(Handle<Object> handle, Handle<Function> callback, ev_tstamp after, ev_tstamp repeat);
|
||||
~Timer();
|
||||
void
|
||||
Timer::Initialize (Handle<Object> target)
|
||||
{
|
||||
HandleScope scope;
|
||||
|
||||
static Handle<Value> New (const Arguments& args);
|
||||
static Handle<Value> Start (const Arguments& args);
|
||||
static Handle<Value> Stop (const Arguments& args);
|
||||
Local<FunctionTemplate> 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<Object> target)
|
||||
{
|
||||
HandleScope scope;
|
||||
|
||||
Local<FunctionTemplate> 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);
|
||||
}
|
||||
|
22
src/timer.h
22
src/timer.h
@ -1,11 +1,31 @@
|
||||
#ifndef node_timer_h
|
||||
#define node_timer_h
|
||||
|
||||
#include "node.h"
|
||||
#include <v8.h>
|
||||
#include <ev.h>
|
||||
|
||||
namespace node {
|
||||
|
||||
void Init_timer (v8::Handle<v8::Object> target);
|
||||
class Timer : ObjectWrap {
|
||||
public:
|
||||
static void Initialize (v8::Handle<v8::Object> target);
|
||||
|
||||
protected:
|
||||
Timer(v8::Handle<v8::Object> handle,
|
||||
v8::Handle<v8::Function> callback,
|
||||
ev_tstamp after,
|
||||
ev_tstamp repeat);
|
||||
~Timer();
|
||||
|
||||
static v8::Handle<v8::Value> New (const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> Start (const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> 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
|
||||
|
Loading…
Reference in New Issue
Block a user