🎨 Refactor for next release
This commit is contained in:
parent
63e78bac9a
commit
601ef54410
|
@ -4,10 +4,6 @@
|
||||||
|
|
||||||
#include "example.hpp"
|
#include "example.hpp"
|
||||||
|
|
||||||
using namespace v8;
|
|
||||||
using namespace node;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
|
@ -15,6 +11,7 @@ extern "C" {
|
||||||
void init(V8_VAR_OBJ target) {
|
void init(V8_VAR_OBJ target) {
|
||||||
|
|
||||||
EventEmitter::init(target);
|
EventEmitter::init(target);
|
||||||
|
|
||||||
Example::init(target);
|
Example::init(target);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "example.hpp"
|
#include "example.hpp"
|
||||||
|
|
||||||
|
|
|
@ -20,23 +20,19 @@ protected:
|
||||||
|
|
||||||
void _destroy();
|
void _destroy();
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
static NAN_METHOD(newCtor);
|
|
||||||
|
|
||||||
static NAN_METHOD(destroy);
|
|
||||||
|
|
||||||
static NAN_METHOD(cppOn);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
static V8_STORE_FT _protoExample;
|
static V8_STORE_FT _protoExample;
|
||||||
static V8_STORE_FUNC _ctorExample;
|
static V8_STORE_FUNC _ctorExample;
|
||||||
|
|
||||||
bool _isDestroyed;
|
bool _isDestroyed;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static NAN_METHOD(newCtor);
|
||||||
|
static NAN_METHOD(destroy);
|
||||||
|
|
||||||
|
static NAN_METHOD(cppOn);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,21 @@ typedef Nan::Persistent<v8::Value> V8_STORE_VAL;
|
||||||
#define JS_OBJ(val) Nan::New<v8::Object>(val)
|
#define JS_OBJ(val) Nan::New<v8::Object>(val)
|
||||||
|
|
||||||
|
|
||||||
|
#define RET_STR(...) RET_VALUE(JS_STR(__VA_ARGS__))
|
||||||
|
#define RET_UTF8(...) RET_VALUE(JS_UTF8(__VA_ARGS__))
|
||||||
|
#define RET_INT(val) RET_VALUE(JS_INT(val))
|
||||||
|
#define RET_INT32(val) RET_VALUE(JS_INT32(val))
|
||||||
|
#define RET_UINT32(val) RET_VALUE(JS_UINT32(val))
|
||||||
|
#define RET_NUM(val) RET_VALUE(JS_NUM(val))
|
||||||
|
#define RET_OFFS(val) RET_VALUE(JS_OFFS(val))
|
||||||
|
#define RET_FLOAT(val) RET_VALUE(JS_FLOAT(val))
|
||||||
|
#define RET_DOUBLE(val) RET_VALUE(JS_DOUBLE(val))
|
||||||
|
#define RET_EXT(val) RET_VALUE(JS_EXT(val))
|
||||||
|
#define RET_BOOL(val) RET_VALUE(JS_BOOL(val))
|
||||||
|
#define RET_FUN(val) RET_VALUE(JS_FUN(val))
|
||||||
|
#define RET_OBJ(val) RET_VALUE(JS_OBJ(val))
|
||||||
|
|
||||||
|
|
||||||
#define REQ_ARGS(N) \
|
#define REQ_ARGS(N) \
|
||||||
if (info.Length() < (N)) \
|
if (info.Length() < (N)) \
|
||||||
return Nan::ThrowTypeError("Expected at least " #N " arguments");
|
return Nan::ThrowTypeError("Expected at least " #N " arguments");
|
||||||
|
|
|
@ -63,6 +63,7 @@ public:
|
||||||
Nan::SetPrototypeMethod(proto, "eventNames", jsEventNames);
|
Nan::SetPrototypeMethod(proto, "eventNames", jsEventNames);
|
||||||
Nan::SetPrototypeMethod(proto, "getMaxListeners", jsGetMaxListeners);
|
Nan::SetPrototypeMethod(proto, "getMaxListeners", jsGetMaxListeners);
|
||||||
Nan::SetPrototypeMethod(proto, "listeners", jsListeners);
|
Nan::SetPrototypeMethod(proto, "listeners", jsListeners);
|
||||||
|
Nan::SetPrototypeMethod(proto, "off", jsRemoveListener);
|
||||||
Nan::SetPrototypeMethod(proto, "on", jsAddListener);
|
Nan::SetPrototypeMethod(proto, "on", jsAddListener);
|
||||||
Nan::SetPrototypeMethod(proto, "once", jsAddListener);
|
Nan::SetPrototypeMethod(proto, "once", jsAddListener);
|
||||||
Nan::SetPrototypeMethod(proto, "prependListener", jsPrependListener);
|
Nan::SetPrototypeMethod(proto, "prependListener", jsPrependListener);
|
||||||
|
@ -179,14 +180,7 @@ private:
|
||||||
|
|
||||||
static NAN_GETTER(isDestroyedGetter) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
static NAN_GETTER(isDestroyedGetter) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
||||||
|
|
||||||
RET_VALUE(JS_BOOL(eventEmitter->_isDestroyed));
|
RET_BOOL(eventEmitter->_isDestroyed);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NAN_METHOD(destroy) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
|
||||||
|
|
||||||
eventEmitter->_destroy();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,12 +194,18 @@ private:
|
||||||
|
|
||||||
const VEC_TYPE &list = eventEmitter->_listeners[*name];
|
const VEC_TYPE &list = eventEmitter->_listeners[*name];
|
||||||
|
|
||||||
RET_VALUE(JS_INT(static_cast<int>(list.size())));
|
RET_INT(static_cast<int>(list.size()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static NAN_METHOD(jsAddListener) { _wrapListener(info); }
|
static NAN_METHOD(jsAddListener) {
|
||||||
|
|
||||||
|
_wrapListener(info);
|
||||||
|
|
||||||
|
RET_VALUE(info.This());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static NAN_METHOD(jsDispatchEvent) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
static NAN_METHOD(jsDispatchEvent) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
||||||
|
@ -222,6 +222,8 @@ private:
|
||||||
|
|
||||||
eventEmitter->emit(*name, 1, &args);
|
eventEmitter->emit(*name, 1, &args);
|
||||||
|
|
||||||
|
RET_BOOL(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -239,6 +241,12 @@ private:
|
||||||
|
|
||||||
eventEmitter->emit(*name, length - 1, &args[0]);
|
eventEmitter->emit(*name, length - 1, &args[0]);
|
||||||
|
|
||||||
|
if ( _listeners.find(name) == _listeners.end() ) {
|
||||||
|
RET_BOOL(false);
|
||||||
|
} else {
|
||||||
|
RET_BOOL(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -265,7 +273,7 @@ private:
|
||||||
|
|
||||||
static NAN_METHOD(jsGetMaxListeners) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
static NAN_METHOD(jsGetMaxListeners) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
||||||
|
|
||||||
RET_VALUE(JS_INT(eventEmitter->_maxListeners));
|
RET_INT(eventEmitter->_maxListeners);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +284,7 @@ private:
|
||||||
|
|
||||||
const VEC_TYPE &list = eventEmitter->_listeners[*name];
|
const VEC_TYPE &list = eventEmitter->_listeners[*name];
|
||||||
|
|
||||||
RET_VALUE(JS_INT(static_cast<int>(list.size())));
|
RET_INT(static_cast<int>(list.size()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,16 +453,36 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static NAN_METHOD(jsOnce) { _wrapOnceListener(info); }
|
static NAN_METHOD(jsOnce) {
|
||||||
|
|
||||||
|
_wrapOnceListener(info);
|
||||||
|
|
||||||
|
RET_VALUE(info.This());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static NAN_METHOD(jsPrependListener) { _wrapListener(info, true); }
|
static NAN_METHOD(jsPrependListener) {
|
||||||
|
|
||||||
|
_wrapListener(info, true);
|
||||||
|
|
||||||
|
RET_VALUE(info.This());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static NAN_METHOD(jsPrependOnceListener) { _wrapOnceListener(info, true); }
|
static NAN_METHOD(jsPrependOnceListener) {
|
||||||
|
|
||||||
|
_wrapOnceListener(info, true);
|
||||||
|
|
||||||
|
RET_VALUE(info.This());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static NAN_METHOD(jsRemoveAllListeners) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
static NAN_METHOD(jsRemoveAllListeners) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
||||||
|
|
||||||
if (info.Length() > 0 && info[0]->IsString()) {
|
RET_VALUE(info.This());
|
||||||
|
|
||||||
|
if (info.Length() == 0) {
|
||||||
|
|
||||||
MAP_TYPE tmpMap = eventEmitter->_raw;
|
MAP_TYPE tmpMap = eventEmitter->_raw;
|
||||||
|
|
||||||
|
@ -535,6 +563,8 @@ private:
|
||||||
|
|
||||||
static NAN_METHOD(jsRemoveListener) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
static NAN_METHOD(jsRemoveListener) { THIS_EVENT_EMITTER; EVENT_EMITTER_THIS_CHECK;
|
||||||
|
|
||||||
|
RET_VALUE(info.This());
|
||||||
|
|
||||||
REQ_UTF8_ARG(0, n);
|
REQ_UTF8_ARG(0, n);
|
||||||
REQ_FUN_ARG(1, raw);
|
REQ_FUN_ARG(1, raw);
|
||||||
|
|
||||||
|
@ -624,6 +654,8 @@ private:
|
||||||
|
|
||||||
eventEmitter->_maxListeners = value;
|
eventEmitter->_maxListeners = value;
|
||||||
|
|
||||||
|
RET_VALUE(info.This());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"author": "Luis Blanco <luisblanco1337@gmail.com>",
|
"author": "Luis Blanco <luisblanco1337@gmail.com>",
|
||||||
"name": "addon-tools-raub",
|
"name": "addon-tools-raub",
|
||||||
"version": "2.0.1",
|
"version": "3.0.0",
|
||||||
"description": "Helpers for Node.js addons and dependency packages",
|
"description": "Helpers for Node.js addons and dependency packages",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
|
Loading…
Reference in New Issue