From d44b1a29250a594222f4e51f234311a0f485e97d Mon Sep 17 00:00:00 2001 From: Jason Stallings Date: Fri, 30 Jan 2015 09:38:12 -0600 Subject: [PATCH] Converted rest of code to nan. --- src/robotjs.cc | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/robotjs.cc b/src/robotjs.cc index 2a2ce519..34c15759 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -17,13 +17,12 @@ using namespace v8; */ -Handle moveMouse(const Arguments& args) +NAN_METHOD(moveMouse) { - HandleScope scope; + NanScope(); if (args.Length() < 2) { - ThrowException(Exception::TypeError(String::New("Wrong number of arguments"))); - return scope.Close(Undefined()); + return NanThrowError("Invalid number of arguments"); } size_t x = args[0]->Int32Value(); size_t y = args[1]->Int32Value(); @@ -31,20 +30,20 @@ Handle moveMouse(const Arguments& args) MMPoint point; point = MMPointMake(x, y); moveMouse(point); - return scope.Close(String::New("1")); + NanReturnValue(NanNew("1")); } -Handle getMousePos(const Arguments& args) +NAN_METHOD(getMousePos) { - HandleScope scope; + NanScope(); MMPoint pos = getMousePos(); //Return object with .x and .y. - Local obj = Object::New(); - obj->Set(String::NewSymbol("x"), Number::New(pos.x)); - obj->Set(String::NewSymbol("y"), Number::New(pos.y)); - return scope.Close(obj); + Local obj = NanNew(); + obj->Set(NanNew("x"), NanNew(pos.x)); + obj->Set(NanNew("y"), NanNew(pos.y)); + NanReturnValue(obj); } NAN_METHOD(mouseClick) @@ -81,31 +80,28 @@ char *get(v8::Local value, const char *fallback = "") return str; } -Handle keyTap(const Arguments& args) +NAN_METHOD (keyTap) { - HandleScope scope; + NanScope(); MMKeyFlags flags = MOD_NONE; + + const char c = (*v8::String::Utf8Value(args[0]->ToString()))[0]; - char c = get(args[0])[0]; - - if (strlen(&c)==1) - { - tapKey(c, flags); - } + tapKey(c, flags); - return scope.Close(String::New("1")); + NanReturnValue(NanNew("1")); } -Handle typeString(const Arguments& args) +NAN_METHOD (typeString) { - HandleScope scope; + NanScope(); - char *str = get(args[0]); + char *str = get(args[0]->ToString()); typeString(str); - return scope.Close(String::New("1")); + NanReturnValue(NanNew("1")); } void init(Handle target)