inherit ptr wip
This commit is contained in:
parent
e7a197232f
commit
e773b03e93
|
@ -2,12 +2,14 @@
|
|||
|
||||
const util = require('util');
|
||||
|
||||
const { Example } = require('./binary/addon');
|
||||
const core = require('./binary/addon');
|
||||
|
||||
|
||||
const { Example } = core;
|
||||
|
||||
Example.prototype[util.inspect.custom] = function() {
|
||||
return `Example { listeners: [${this.eventNames()}] }`;
|
||||
};
|
||||
|
||||
|
||||
module.exports = Example;
|
||||
module.exports = core;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <cstdlib>
|
||||
|
||||
#include <event-emitter.hpp>
|
||||
|
||||
#include "example.hpp"
|
||||
|
||||
using namespace v8;
|
||||
|
@ -12,6 +14,7 @@ extern "C" {
|
|||
|
||||
void init(Handle<Object> target) {
|
||||
|
||||
EventEmitter::init(target);
|
||||
Example::init(target);
|
||||
|
||||
}
|
||||
|
|
|
@ -56,12 +56,13 @@ void Example::init(Handle<Object> target) {
|
|||
|
||||
NAN_METHOD(Example::newCtor) {
|
||||
|
||||
std::cout << "Example() 1" << std::endl;
|
||||
v8::Local<v8::Function> superCtor = Nan::New(EventEmitter::_constructor);
|
||||
superCtor->Call(info.This(), 0, nullptr);
|
||||
|
||||
std::cout << "Example() 2" << std::endl;
|
||||
Example *example = new Example();
|
||||
example->Wrap(info.This());
|
||||
|
||||
std::cout << "Example() 3 @" << example << std::endl;
|
||||
RET_VALUE(info.This());
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const Example = require('./core');
|
||||
const { Example, EventEmitter } = require('./core');
|
||||
|
||||
console.log('Example', Example);
|
||||
|
||||
|
@ -9,7 +9,7 @@ const example = new Example();
|
|||
|
||||
console.log('example 0', example);
|
||||
|
||||
console.log('static listenerCount', Example.listenerCount);
|
||||
console.log('static listenerCount', EventEmitter.listenerCount);
|
||||
|
||||
console.log('listenerCount', example.listenerCount);
|
||||
console.log('addListener', example.addListener);
|
||||
|
@ -27,11 +27,11 @@ console.log('setMaxListeners', example.setMaxListeners);
|
|||
console.log('rawListeners', example.rawListeners);
|
||||
console.log('destroy', example.destroy);
|
||||
|
||||
|
||||
console.log('index.js', 'ON1');
|
||||
example.on('evt1', (arg1, arg2) => {
|
||||
console.log('EVT1', arg1, arg2, example.eventNames());
|
||||
});
|
||||
|
||||
console.log('index.js', 'ON2');
|
||||
example.once('evt2', (arg1, arg2) => {
|
||||
console.log('EVT2', arg1, arg2, example.eventNames());
|
||||
});
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
#define THIS_EVENT_EMITTER \
|
||||
EventEmitter *eventEmitter = ObjectWrap::Unwrap<EventEmitter>(info.This());
|
||||
|
||||
#define EVENT_EMITTER_THIS_CHECK \
|
||||
#define EVENT_EMITTER_THIS_CHECK \
|
||||
if (eventEmitter->_isDestroyed) return;
|
||||
|
||||
#define EVENT_EMITTER_DES_CHECK \
|
||||
#define EVENT_EMITTER_DES_CHECK \
|
||||
if (_isDestroyed) return;
|
||||
|
||||
|
||||
|
@ -154,10 +154,10 @@ private:
|
|||
|
||||
|
||||
static NAN_METHOD(newCtor) {
|
||||
|
||||
std::cout << "EventEmitter() 1" << std::endl;
|
||||
EventEmitter *eventEmitter = new EventEmitter();
|
||||
eventEmitter->Wrap(info.This());
|
||||
|
||||
std::cout << "EventEmitter() 2 : @" << eventEmitter << std::endl;
|
||||
RET_VALUE(info.This());
|
||||
|
||||
}
|
||||
|
@ -213,8 +213,10 @@ private:
|
|||
|
||||
static NAN_METHOD(jsEventNames) { THIS_EVENT_EMITTER;
|
||||
|
||||
v8::Local<v8::Array> jsNames = Nan::New<v8::Array>(eventEmitter->_raw.size());
|
||||
std::cout << "jsEventNames() 1: @" << eventEmitter << " x " << eventEmitter->_raw.size() << std::endl;
|
||||
|
||||
v8::Local<v8::Array> jsNames = Nan::New<v8::Array>(eventEmitter->_raw.size());
|
||||
std::cout << "jsEventNames() 2" << std::endl;
|
||||
if (eventEmitter->_raw.empty()) {
|
||||
RET_VALUE(jsNames);
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue