Skip to content

Commit d44b1a2

Browse files
committed
Converted rest of code to nan.
1 parent b4f2085 commit d44b1a2

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

src/robotjs.cc

+20-24
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,33 @@ using namespace v8;
1717
1818
*/
1919

20-
Handle<Value> moveMouse(const Arguments& args)
20+
NAN_METHOD(moveMouse)
2121
{
22-
HandleScope scope;
22+
NanScope();
2323
if (args.Length() < 2)
2424
{
25-
ThrowException(Exception::TypeError(String::New("Wrong number of arguments")));
26-
return scope.Close(Undefined());
25+
return NanThrowError("Invalid number of arguments");
2726
}
2827
size_t x = args[0]->Int32Value();
2928
size_t y = args[1]->Int32Value();
3029

3130
MMPoint point;
3231
point = MMPointMake(x, y);
3332
moveMouse(point);
34-
return scope.Close(String::New("1"));
33+
NanReturnValue(NanNew("1"));
3534
}
3635

37-
Handle<Value> getMousePos(const Arguments& args)
36+
NAN_METHOD(getMousePos)
3837
{
39-
HandleScope scope;
38+
NanScope();
4039

4140
MMPoint pos = getMousePos();
4241

4342
//Return object with .x and .y.
44-
Local<Object> obj = Object::New();
45-
obj->Set(String::NewSymbol("x"), Number::New(pos.x));
46-
obj->Set(String::NewSymbol("y"), Number::New(pos.y));
47-
return scope.Close(obj);
43+
Local<Object> obj = NanNew<Object>();
44+
obj->Set(NanNew<String>("x"), NanNew<Number>(pos.x));
45+
obj->Set(NanNew<String>("y"), NanNew<Number>(pos.y));
46+
NanReturnValue(obj);
4847
}
4948

5049
NAN_METHOD(mouseClick)
@@ -81,31 +80,28 @@ char *get(v8::Local<v8::Value> value, const char *fallback = "")
8180
return str;
8281
}
8382

84-
Handle<Value> keyTap(const Arguments& args)
83+
NAN_METHOD (keyTap)
8584
{
86-
HandleScope scope;
85+
NanScope();
8786

8887
MMKeyFlags flags = MOD_NONE;
88+
89+
const char c = (*v8::String::Utf8Value(args[0]->ToString()))[0];
8990

90-
char c = get(args[0])[0];
91-
92-
if (strlen(&c)==1)
93-
{
94-
tapKey(c, flags);
95-
}
91+
tapKey(c, flags);
9692

97-
return scope.Close(String::New("1"));
93+
NanReturnValue(NanNew("1"));
9894
}
9995

100-
Handle<Value> typeString(const Arguments& args)
96+
NAN_METHOD (typeString)
10197
{
102-
HandleScope scope;
98+
NanScope();
10399

104-
char *str = get(args[0]);
100+
char *str = get(args[0]->ToString());
105101

106102
typeString(str);
107103

108-
return scope.Close(String::New("1"));
104+
NanReturnValue(NanNew("1"));
109105
}
110106

111107
void init(Handle<Object> target)

0 commit comments

Comments
 (0)