diff options
Diffstat (limited to 'src/timer_wrap.cc')
-rw-r--r-- | src/timer_wrap.cc | 58 |
1 files changed, 18 insertions, 40 deletions
diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 23abc5c4186..40bc3edd49c 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -24,19 +24,18 @@ namespace node { -using v8::Arguments; using v8::Function; +using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Handle; using v8::HandleScope; using v8::Integer; using v8::Local; using v8::Object; -using v8::Persistent; using v8::String; using v8::Value; -static Persistent<String> ontimeout_sym; +static Cached<String> ontimeout_sym; class TimerWrap : public HandleWrap { public: @@ -61,23 +60,19 @@ class TimerWrap : public HandleWrap { NODE_SET_PROTOTYPE_METHOD(constructor, "getRepeat", GetRepeat); NODE_SET_PROTOTYPE_METHOD(constructor, "again", Again); - ontimeout_sym = NODE_PSYMBOL("ontimeout"); + ontimeout_sym = String::New("ontimeout"); target->Set(String::NewSymbol("Timer"), constructor->GetFunction()); } private: - static Handle<Value> New(const Arguments& args) { + static void New(const FunctionCallbackInfo<Value>& args) { // This constructor should not be exposed to public javascript. // Therefore we assert that we are not trying to call this as a // normal function. assert(args.IsConstructCall()); - HandleScope scope(node_isolate); - TimerWrap *wrap = new TimerWrap(args.This()); - assert(wrap); - - return scope.Close(args.This()); + new TimerWrap(args.This()); } TimerWrap(Handle<Object> object) @@ -89,67 +84,51 @@ class TimerWrap : public HandleWrap { ~TimerWrap() { } - static Handle<Value> Start(const Arguments& args) { + static void Start(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - UNWRAP(TimerWrap) int64_t timeout = args[0]->IntegerValue(); int64_t repeat = args[1]->IntegerValue(); - int r = uv_timer_start(&wrap->handle_, OnTimeout, timeout, repeat); - if (r) SetErrno(uv_last_error(uv_default_loop())); - - return scope.Close(Integer::New(r, node_isolate)); + args.GetReturnValue().Set(r); } - static Handle<Value> Stop(const Arguments& args) { + static void Stop(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - UNWRAP(TimerWrap) int r = uv_timer_stop(&wrap->handle_); - if (r) SetErrno(uv_last_error(uv_default_loop())); - - return scope.Close(Integer::New(r, node_isolate)); + args.GetReturnValue().Set(r); } - static Handle<Value> Again(const Arguments& args) { + static void Again(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - UNWRAP(TimerWrap) int r = uv_timer_again(&wrap->handle_); - if (r) SetErrno(uv_last_error(uv_default_loop())); - - return scope.Close(Integer::New(r, node_isolate)); + args.GetReturnValue().Set(r); } - static Handle<Value> SetRepeat(const Arguments& args) { + static void SetRepeat(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - UNWRAP(TimerWrap) int64_t repeat = args[0]->IntegerValue(); - uv_timer_set_repeat(&wrap->handle_, repeat); - - return scope.Close(Integer::New(0, node_isolate)); + args.GetReturnValue().Set(0); } - static Handle<Value> GetRepeat(const Arguments& args) { + static void GetRepeat(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - UNWRAP(TimerWrap) int64_t repeat = uv_timer_get_repeat(&wrap->handle_); - if (repeat < 0) SetErrno(uv_last_error(uv_default_loop())); - - return scope.Close(Integer::New(repeat, node_isolate)); + args.GetReturnValue().Set(static_cast<double>(repeat)); } static void OnTimeout(uv_timer_t* handle, int status) { @@ -159,14 +138,13 @@ class TimerWrap : public HandleWrap { assert(wrap); Local<Value> argv[1] = { Integer::New(status, node_isolate) }; - MakeCallback(wrap->object_, ontimeout_sym, ARRAY_SIZE(argv), argv); + MakeCallback(wrap->object(), ontimeout_sym, ARRAY_SIZE(argv), argv); } - static Handle<Value> Now(const Arguments& args) { + static void Now(const FunctionCallbackInfo<Value>& args) { HandleScope scope(node_isolate); - double now = static_cast<double>(uv_now(uv_default_loop())); - return scope.Close(v8::Number::New(now)); + args.GetReturnValue().Set(now); } uv_timer_t handle_; |