refactor and fixes
This commit is contained in:
parent
3dd198aea8
commit
e709bdc813
|
@ -12,10 +12,10 @@
|
|||
#define RET_UNDEFINED RET_VALUE(Nan::Undefined());
|
||||
|
||||
|
||||
#define JS_STR(...) Nan::New<String>(__VA_ARGS__).ToLocalChecked()
|
||||
#define JS_INT(val) Nan::New<Integer>(val)
|
||||
#define JS_NUM(val) Nan::New<Number>(val)
|
||||
#define JS_EXT(val) Nan::New<External>(reinterpret_cast<void*>(val))
|
||||
#define JS_STR(...) Nan::New<v8::String>(__VA_ARGS__).ToLocalChecked()
|
||||
#define JS_INT(val) Nan::New<v8::Integer>(val)
|
||||
#define JS_NUM(val) Nan::New<v8::Number>(val)
|
||||
#define JS_EXT(val) Nan::New<v8::External>(reinterpret_cast<void*>(val))
|
||||
#define JS_BOOL(val) (val) ? Nan::True() : Nan::False()
|
||||
|
||||
|
||||
|
@ -55,11 +55,11 @@
|
|||
|
||||
#define REQ_BOOL_ARG(I, VAR) \
|
||||
CHECK_REQ_ARG(I, IsBoolean(), "bool"); \
|
||||
int VAR = info[I]->BooleanValue();
|
||||
bool VAR = info[I]->BooleanValue();
|
||||
|
||||
#define LET_BOOL_ARG(I, VAR) \
|
||||
CHECK_LET_ARG(I, IsBoolean(), "bool"); \
|
||||
int VAR = IS_ARG_EMPTY(I) ? false : info[I]->BooleanValue();
|
||||
bool VAR = IS_ARG_EMPTY(I) ? false : info[I]->BooleanValue();
|
||||
|
||||
|
||||
#define REQ_UINT32_ARG(I, VAR) \
|
||||
|
@ -100,28 +100,29 @@
|
|||
|
||||
#define REQ_EXT_ARG(I, VAR) \
|
||||
CHECK_REQ_ARG(I, IsExternal(), "void*"); \
|
||||
Local<External> VAR = Local<External>::Cast(info[I]);
|
||||
v8::Local<v8::External> VAR = v8::Local<v8::External>::Cast(info[I]);
|
||||
|
||||
#define LET_EXT_ARG(I, VAR) \
|
||||
CHECK_LET_ARG(I, IsExternal(), "number"); \
|
||||
Local<External> VAR = IS_ARG_EMPTY(I) ? JS_EXT(NULL) : Local<External>::Cast(info[I]);
|
||||
v8::Local<v8::External> VAR = IS_ARG_EMPTY(I) ? JS_EXT(NULL) : \
|
||||
v8::Local<v8::External>::Cast(info[I]);
|
||||
|
||||
|
||||
#define REQ_FUN_ARG(I, VAR) \
|
||||
CHECK_REQ_ARG(I, IsFunction(), "function"); \
|
||||
Local<Function> VAR = Local<Function>::Cast(info[I]);
|
||||
v8::Local<v8::Function> VAR = v8::Local<v8::Function>::Cast(info[I]);
|
||||
|
||||
|
||||
#define REQ_OBJ_ARG(I, VAR) \
|
||||
CHECK_REQ_ARG(I, IsObject(), "object"); \
|
||||
Local<Object> VAR = Local<Object>::Cast(info[I]);
|
||||
v8::Local<v8::Object> VAR = v8::Local<v8::Object>::Cast(info[I]);
|
||||
|
||||
|
||||
#define REQ_ARRV_ARG(I, VAR) \
|
||||
REQ_OBJ_ARG(I, _obj_##VAR); \
|
||||
if( ! _obj_##VAR->IsArrayBufferView() ) \
|
||||
if( ! _obj_##VAR->Isv8::ArrayBufferView() ) \
|
||||
return Nan::ThrowTypeError("Argument " #I " must be an array buffer");\
|
||||
Local<ArrayBufferView> VAR = Local<ArrayBufferView>::Cast(_obj_##VAR);
|
||||
v8::Local<v8::ArrayBufferView> VAR = v8::Local<v8::ArrayBufferView>::Cast(_obj_##VAR);
|
||||
|
||||
|
||||
#define SET_PROP(OBJ, KEY, VAL) OBJ->Set(JS_STR(KEY), VAL);
|
||||
|
@ -154,7 +155,7 @@
|
|||
|
||||
#define SETTER_BOOL_ARG \
|
||||
SETTER_CHECK(IsBoolean(), "bool"); \
|
||||
bool v = value->BooleanValue(); // TODO APPLY bool TO REQ_BOOL_ARG
|
||||
bool v = value->BooleanValue();
|
||||
|
||||
#define SETTER_UINT32_ARG \
|
||||
SETTER_CHECK(IsUint32(), "uint32"); \
|
||||
|
@ -174,19 +175,19 @@
|
|||
|
||||
#define SETTER_EXT_ARG \
|
||||
SETTER_CHECK(IsExternal(), "void*"); \
|
||||
Local<External> v = Local<External>::Cast(value);
|
||||
v8::Local<v8::External> v = v8::Local<v8::External>::Cast(value);
|
||||
|
||||
#define SETTER_FUN_ARG \
|
||||
SETTER_CHECK(IsFunction(), "function"); \
|
||||
Local<Function> v = Local<Function>::Cast(value);
|
||||
v8::Local<v8::Function> v = v8::Local<v8::Function>::Cast(value);
|
||||
|
||||
#define SETTER_OBJ_ARG \
|
||||
SETTER_CHECK(IsObject(), "object"); \
|
||||
Local<Object> v = Local<Object>::Cast(value);
|
||||
v8::Local<v8::Object> v = v8::Local<v8::Object>::Cast(value);
|
||||
|
||||
|
||||
template<typename Type>
|
||||
inline Type* getArrayData(Local<Value> arg, int *num = NULL) {
|
||||
inline Type* getArrayData(v8::Local<v8::Value> arg, int *num = NULL) {
|
||||
|
||||
Type *data = NULL;
|
||||
|
||||
|
@ -195,7 +196,7 @@ inline Type* getArrayData(Local<Value> arg, int *num = NULL) {
|
|||
}
|
||||
|
||||
if (arg->IsNull() || arg->IsUndefined()) {
|
||||
return pixels;
|
||||
return data;
|
||||
}
|
||||
|
||||
if (arg->IsArray()) {
|
||||
|
@ -208,7 +209,7 @@ inline Type* getArrayData(Local<Value> arg, int *num = NULL) {
|
|||
return data;
|
||||
}
|
||||
|
||||
Local<ArrayBufferView> arr = Local<ArrayBufferView>::Cast(arg);
|
||||
v8::Local<v8::ArrayBufferView> arr = v8::Local<v8::ArrayBufferView>::Cast(arg);
|
||||
if (num) {
|
||||
*num = arr->ByteLength() / sizeof(Type);
|
||||
}
|
||||
|
@ -219,7 +220,7 @@ inline Type* getArrayData(Local<Value> arg, int *num = NULL) {
|
|||
}
|
||||
|
||||
|
||||
inline void *getImageData(Local<Value> arg) {
|
||||
inline void *getImageData(v8::Local<v8::Value> arg) {
|
||||
|
||||
void *pixels = NULL;
|
||||
|
||||
|
@ -227,7 +228,7 @@ inline void *getImageData(Local<Value> arg) {
|
|||
return pixels;
|
||||
}
|
||||
|
||||
Local<Object> obj = Local<Object>::Cast(arg);
|
||||
v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(arg);
|
||||
|
||||
if ( ! obj->IsObject() ) {
|
||||
Nan::ThrowError("Bad Image argument");
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"name": "node-addon-tools-raub",
|
||||
"author": "Luis Blanco <raubtierxxx@gmail.com>",
|
||||
"description": "A set of extra tools for Node.js addons.",
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.7",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"node",
|
||||
|
|
Loading…
Reference in New Issue