new macros
This commit is contained in:
parent
082b8b3f5f
commit
3256bf8c30
|
@ -12,6 +12,7 @@
|
||||||
#define JS_STR(...) Nan::New<String>(__VA_ARGS__).ToLocalChecked()
|
#define JS_STR(...) Nan::New<String>(__VA_ARGS__).ToLocalChecked()
|
||||||
#define JS_INT(val) Nan::New<v8::Integer>(val)
|
#define JS_INT(val) Nan::New<v8::Integer>(val)
|
||||||
#define JS_NUM(val) Nan::New<v8::Number>(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()
|
#define JS_BOOL(val) (val) ? Nan::True() : Nan::False()
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,18 +21,18 @@
|
||||||
|
|
||||||
#define REQ_ARGS(N) \
|
#define REQ_ARGS(N) \
|
||||||
if (info.Length() < (N)) \
|
if (info.Length() < (N)) \
|
||||||
Nan::ThrowTypeError("Expected at least " #N " arguments");
|
return Nan::ThrowTypeError("Expected at least " #N " arguments");
|
||||||
|
|
||||||
|
|
||||||
#define IS_ARG_EMPTY(I) (info[I]->IsNull() || info[I]->IsUndefined())
|
#define IS_ARG_EMPTY(I) (info[I]->IsNull() || info[I]->IsUndefined())
|
||||||
|
|
||||||
#define CHECK_REQ_ARG(I, C, T) \
|
#define CHECK_REQ_ARG(I, C, T) \
|
||||||
if (info.Length() <= (I) || ! info[I]->C) \
|
if (info.Length() <= (I) || ! info[I]->C) \
|
||||||
Nan::ThrowTypeError("Argument " #I " must be " T);
|
return Nan::ThrowTypeError("Argument " #I " must be " T);
|
||||||
|
|
||||||
#define CHECK_LET_ARG(I, C, T) \
|
#define CHECK_LET_ARG(I, C, T) \
|
||||||
if ( ! (IS_ARG_EMPTY(I) || info[I]->C) ) \
|
if ( ! (IS_ARG_EMPTY(I) || info[I]->C) ) \
|
||||||
Nan::ThrowTypeError("Argument " #I " must be " T " or null");
|
return Nan::ThrowTypeError("Argument " #I " must be " T " or null");
|
||||||
|
|
||||||
|
|
||||||
#define REQ_UTF8_ARG(I, VAR) \
|
#define REQ_UTF8_ARG(I, VAR) \
|
||||||
|
@ -101,6 +102,10 @@
|
||||||
CHECK_REQ_ARG(I, IsExternal(), "void*"); \
|
CHECK_REQ_ARG(I, IsExternal(), "void*"); \
|
||||||
Local<External> VAR = Local<External>::Cast(info[I]);
|
Local<External> VAR = Local<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]);
|
||||||
|
|
||||||
|
|
||||||
#define REQ_FUN_ARG(I, VAR) \
|
#define REQ_FUN_ARG(I, VAR) \
|
||||||
CHECK_REQ_ARG(I, IsFunction(), "function"); \
|
CHECK_REQ_ARG(I, IsFunction(), "function"); \
|
||||||
|
@ -115,11 +120,70 @@
|
||||||
#define REQ_ARRV_ARG(I, VAR) \
|
#define REQ_ARRV_ARG(I, VAR) \
|
||||||
REQ_OBJ_ARG(I, _obj_##VAR); \
|
REQ_OBJ_ARG(I, _obj_##VAR); \
|
||||||
if( ! _obj_##VAR->IsArrayBufferView() ) \
|
if( ! _obj_##VAR->IsArrayBufferView() ) \
|
||||||
Nan::ThrowTypeError("Argument " #I " must be an array buffer"); \
|
return Nan::ThrowTypeError("Argument " #I " must be an array buffer"); \
|
||||||
Local<ArrayBufferView> VAR = Local<ArrayBufferView>::Cast(_obj_##VAR);
|
Local<ArrayBufferView> VAR = Local<ArrayBufferView>::Cast(_obj_##VAR);
|
||||||
|
|
||||||
|
|
||||||
#define SET_PROP(OBJ, KEY, VAL) OBJ->Set(JS_STR(KEY), VAL);
|
#define SET_PROP(OBJ, KEY, VAL) OBJ->Set(JS_STR(KEY), VAL);
|
||||||
|
|
||||||
|
|
||||||
|
#define CTOR_CHECK(T) \
|
||||||
|
if ( ! info.IsConstructCall() ) \
|
||||||
|
return Nan::ThrowTypeError(T " must be called with the 'new' keyword.");
|
||||||
|
|
||||||
|
#define ACCESSOR_RW(OBJ, NAME) \
|
||||||
|
Nan::SetAccessor(OBJ, JS_STR(#NAME), NAME ## Getter, NAME ## Setter);
|
||||||
|
|
||||||
|
#define ACCESSOR_R(OBJ, NAME) \
|
||||||
|
Nan::SetAccessor(OBJ, JS_STR(#NAME), NAME ## Getter);
|
||||||
|
|
||||||
|
#define SET_I(ARR, I, VAL) ARR->Set(I, VAL);
|
||||||
|
|
||||||
|
|
||||||
|
#define SETTER_CHECK(C, T) \
|
||||||
|
if ( ! value->C ) \
|
||||||
|
return Nan::ThrowTypeError("Value must be " T);
|
||||||
|
|
||||||
|
|
||||||
|
#define SETTER_UTF8_ARG \
|
||||||
|
SETTER_CHECK(IsString(), "string"); \
|
||||||
|
Nan::Utf8String v(value);
|
||||||
|
|
||||||
|
#define SETTER_INT32_ARG \
|
||||||
|
SETTER_CHECK(IsInt32(), "int32"); \
|
||||||
|
int v = value->Int32Value();
|
||||||
|
|
||||||
|
#define SETTER_BOOL_ARG \
|
||||||
|
SETTER_CHECK(IsBoolean(), "bool"); \
|
||||||
|
bool v = value->BooleanValue(); // TODO APPLY bool TO REQ_BOOL_ARG
|
||||||
|
|
||||||
|
#define SETTER_UINT32_ARG \
|
||||||
|
SETTER_CHECK(IsUint32(), "uint32"); \
|
||||||
|
unsigned int v = value->Uint32Value();
|
||||||
|
|
||||||
|
#define SETTER_OFFS_ARG \
|
||||||
|
SETTER_CHECK(IsNumber(), "number"); \
|
||||||
|
size_t v = static_cast<size_t>(value->IntegerValue());
|
||||||
|
|
||||||
|
#define SETTER_DOUBLE_ARG \
|
||||||
|
SETTER_CHECK(IsNumber(), "number"); \
|
||||||
|
double v = value->NumberValue();
|
||||||
|
|
||||||
|
#define SETTER_FLOAT_ARG \
|
||||||
|
SETTER_CHECK(IsNumber(), "number"); \
|
||||||
|
float v = static_cast<float>(value->NumberValue());
|
||||||
|
|
||||||
|
#define SETTER_EXT_ARG \
|
||||||
|
SETTER_CHECK(IsExternal(), "void*"); \
|
||||||
|
Local<External> v = Local<External>::Cast(value);
|
||||||
|
|
||||||
|
#define SETTER_FUN_ARG \
|
||||||
|
SETTER_CHECK(IsFunction(), "function"); \
|
||||||
|
Local<Function> v = Local<Function>::Cast(value);
|
||||||
|
|
||||||
|
#define SETTER_OBJ_ARG \
|
||||||
|
SETTER_CHECK(IsObject(), "object"); \
|
||||||
|
Local<Object> v = Local<Object>::Cast(value);
|
||||||
|
|
||||||
|
|
||||||
#endif // _ADDON_TOOLS_HPP_
|
#endif // _ADDON_TOOLS_HPP_
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "node-addon-tools-raub",
|
"name": "node-addon-tools-raub",
|
||||||
"author": "Luis Blanco <raubtierxxx@gmail.com>",
|
"author": "Luis Blanco <raubtierxxx@gmail.com>",
|
||||||
"description": "A set of extra macros for node addons, shipped as C++ header file.",
|
"description": "A set of extra macros for node addons, shipped as C++ header file.",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"node",
|
"node",
|
||||||
|
|
Loading…
Reference in New Issue