🎨 Experimental new CPP on()
This commit is contained in:
parent
75d6f468f1
commit
06e148c2d7
|
@ -122,21 +122,19 @@ public:
|
||||||
|
|
||||||
|
|
||||||
// C++ side on() method
|
// C++ side on() method
|
||||||
void on(const std::string &name, V8_VAR_VAL that, const std::string &method) {
|
void on(const std::string &name, V8_VAR_FUNC cb) {
|
||||||
|
|
||||||
V8_VAR_STR code = JS_STR(
|
V8_VAR_OBJ me = handle();
|
||||||
"((emitter, name, that, method) => emitter.on(name, that[method]))"
|
|
||||||
);
|
|
||||||
|
|
||||||
V8_VAR_FUNC connector = V8_VAR_FUNC::Cast(v8::Script::Compile(code)->Run());
|
V8_VAR_VAL onVal = Nan::Get(me, JS_STR("on")).ToLocalChecked();
|
||||||
Nan::Callback connectorCb(connector);
|
V8_VAR_FUNC onFunc = V8_VAR_FUNC::Cast(onVal);
|
||||||
|
|
||||||
V8_VAR_OBJ emitter = Nan::New<v8::Object>();
|
Nan::Callback onCb(onFunc);
|
||||||
this->Wrap(emitter);
|
|
||||||
|
|
||||||
V8_VAR_VAL argv[] = { emitter, JS_STR(name.c_str()), that, JS_STR(method.c_str()) };
|
V8_VAR_VAL argv[] = { JS_STR(name.c_str()), cb };
|
||||||
Nan::AsyncResource async("EventEmitter::cpp_on()");
|
Nan::AsyncResource async("EventEmitter::cpp_on()");
|
||||||
connectorCb.Call(4, argv, &async);
|
|
||||||
|
onCb.Call(me, 2, argv, &async);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,6 +305,7 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void _reportListeners(
|
static inline void _reportListeners(
|
||||||
const std::string &name,
|
const std::string &name,
|
||||||
int numListeners,
|
int numListeners,
|
||||||
|
@ -325,9 +324,7 @@ private:
|
||||||
V8_VAR_STR code = JS_STR(
|
V8_VAR_STR code = JS_STR(
|
||||||
"(new Error()).stack.split('\\n').slice(2).join('\\n')"
|
"(new Error()).stack.split('\\n').slice(2).join('\\n')"
|
||||||
);
|
);
|
||||||
V8_VAR_STR stack = V8_VAR_STR::Cast(
|
V8_VAR_STR stack = V8_VAR_STR::Cast(v8::Script::Compile(code)->Run());
|
||||||
v8::Script::Compile(code)->Run()
|
|
||||||
);
|
|
||||||
Nan::Utf8String stackStr(stack);
|
Nan::Utf8String stackStr(stack);
|
||||||
msg += *stackStr;
|
msg += *stackStr;
|
||||||
|
|
||||||
|
@ -335,6 +332,7 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void _addListener(
|
static inline void _addListener(
|
||||||
const Nan::FunctionCallbackInfo<v8::Value> &info,
|
const Nan::FunctionCallbackInfo<v8::Value> &info,
|
||||||
const std::string &name,
|
const std::string &name,
|
||||||
|
|
Loading…
Reference in New Issue