wip debug
This commit is contained in:
parent
448c524af7
commit
f4ca876cc2
|
@ -26,21 +26,28 @@ console.log('setMaxListeners', example.setMaxListeners);
|
||||||
console.log('rawListeners', example.rawListeners);
|
console.log('rawListeners', example.rawListeners);
|
||||||
console.log('destroy', example.destroy);
|
console.log('destroy', example.destroy);
|
||||||
|
|
||||||
|
// console.log('example.eventNames -2', example.eventNames());
|
||||||
example.on('evt1', (arg1, arg2) => {
|
example.on('evt1', (arg1, arg2) => {
|
||||||
console.log('EVT1', arg1, arg2);
|
console.log('EVT1', arg1, arg2, example.eventNames());
|
||||||
});
|
});
|
||||||
|
// console.log('example.eventNames -1', example.eventNames());
|
||||||
example.once('evt2', (arg1, arg2) => {
|
example.once('evt2', (arg1, arg2) => {
|
||||||
console.log('EVT2', arg1, arg2);
|
console.log('EVT2', arg1, arg2, example.eventNames());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// console.log('example.eventNames 0', example.eventNames());
|
||||||
|
|
||||||
example.emit('evt1', 111, '221');
|
example.emit('evt1', 111, '221');
|
||||||
example.emit('evt1', 112, '222');
|
example.emit('evt1', 112, '222');
|
||||||
|
|
||||||
|
console.log('example.eventNames 1', example.eventNames());
|
||||||
|
|
||||||
example.emit('evt2', 111, '221');
|
example.emit('evt2', 111, '221');
|
||||||
|
|
||||||
|
console.log('example.eventNames 2', example.eventNames());
|
||||||
|
|
||||||
example.emit('evt2', 112, '222');
|
example.emit('evt2', 112, '222');
|
||||||
|
|
||||||
|
// console.log('example.eventNames 3', example.eventNames());
|
||||||
|
|
||||||
module.exports = Example;
|
module.exports = Example;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
#define THIS_EMITTER \
|
#define THIS_EMITTER \
|
||||||
|
@ -161,38 +162,48 @@ protected:
|
||||||
|
|
||||||
|
|
||||||
static NAN_METHOD(jsEmit) { THIS_EMITTER;
|
static NAN_METHOD(jsEmit) { THIS_EMITTER;
|
||||||
|
std::cout << "emit 0 " << emitter->_listeners.size() << std::endl;
|
||||||
|
for (MAP_IT_TYPE it = emitter->_listeners.begin(); it != emitter->_listeners.end(); ++it) {
|
||||||
|
|
||||||
|
std::cout << "emit 0 _listeners " << it->first << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
for (MAP_IT_TYPE it = emitter->_raw.begin(); it != emitter->_raw.end(); ++it) {
|
||||||
|
|
||||||
|
std::cout << "emit 0 _raw " << it->first << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
REQ_UTF8_ARG(0, name);
|
REQ_UTF8_ARG(0, name);
|
||||||
|
|
||||||
int length = info.Length();
|
int length = info.Length();
|
||||||
|
|
||||||
std::vector< v8::Local<v8::Value> > args;
|
std::vector< v8::Local<v8::Value> > args;
|
||||||
|
std::cout << "emit 1 " << emitter->_listeners.size() << std::endl;
|
||||||
for (int i = 1; i < length; i++) {
|
for (int i = 1; i < length; i++) {
|
||||||
args.push_back(info[i]);
|
args.push_back(info[i]);
|
||||||
}
|
}
|
||||||
|
std::cout << "emit 2 " << emitter->_listeners.size() << std::endl;
|
||||||
emitter->emit(*name, length - 1, &args[0]);
|
emitter->emit(*name, length - 1, &args[0]);
|
||||||
|
std::cout << "emit 3 " << emitter->_listeners.size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static NAN_METHOD(jsEventNames) { THIS_EMITTER;
|
static NAN_METHOD(jsEventNames) { THIS_EMITTER;
|
||||||
|
std::cout << "jsEventNames 0 " << emitter->_raw.size() << std::endl;
|
||||||
|
v8::Local<v8::Array> jsNames = Nan::New<v8::Array>(emitter->_raw.size());
|
||||||
|
|
||||||
v8::Local<v8::Array> jsNames = Nan::New<v8::Array>(emitter->_listeners.size());
|
if (emitter->_raw.empty()) {
|
||||||
|
|
||||||
if (emitter->_listeners.empty()) {
|
|
||||||
RET_VALUE(jsNames);
|
RET_VALUE(jsNames);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
std::cout << "jsEventNames 1 " << emitter->_raw.size() << std::endl;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (MAP_IT_TYPE it = emitter->_listeners.begin(); it != emitter->_listeners.end(); ++it, i++) {
|
for (MAP_IT_TYPE it = emitter->_raw.begin(); it != emitter->_raw.end(); ++it, i++) {
|
||||||
|
|
||||||
jsNames->Set(JS_INT(i), JS_STR(it->first));
|
jsNames->Set(JS_INT(i), JS_STR(it->first));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
std::cout << "jsEventNames 2 " << emitter->_raw.size() << std::endl;
|
||||||
RET_VALUE(jsNames);
|
RET_VALUE(jsNames);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -447,6 +458,9 @@ protected:
|
||||||
|
|
||||||
if (*it == persistentRaw) {
|
if (*it == persistentRaw) {
|
||||||
rawList.erase(it);
|
rawList.erase(it);
|
||||||
|
if (rawList.empty()) {
|
||||||
|
emitter->_raw.erase(name);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,6 +475,9 @@ protected:
|
||||||
|
|
||||||
if (*it == persistentRaw) {
|
if (*it == persistentRaw) {
|
||||||
wrapList.erase(it);
|
wrapList.erase(it);
|
||||||
|
if (wrapList.empty()) {
|
||||||
|
emitter->_listeners.erase(name);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,6 +499,9 @@ protected:
|
||||||
|
|
||||||
if (*it == fn) {
|
if (*it == fn) {
|
||||||
wrapList.erase(it);
|
wrapList.erase(it);
|
||||||
|
if (wrapList.empty()) {
|
||||||
|
emitter->_listeners.erase(name);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue