3 #if !NODE_VERSION_AT_LEAST(0, 5, 0)
4 v8::Persistent<v8::String> nodejs_db::EventEmitter::syEmit;
7 nodejs_db::EventEmitter::EventEmitter() : node::ObjectWrap() {
10 void nodejs_db::EventEmitter::Init() {
11 #if !NODE_VERSION_AT_LEAST(0, 5, 0)
12 syEmit = NODE_PERSISTENT_SYMBOL(
"emit");
16 bool nodejs_db::EventEmitter::Emit(
const char* event,
int argc, v8::Handle<v8::Value> argv[]) {
17 v8::HandleScope scope;
20 v8::Handle<v8::Value>* nArgv =
new v8::Handle<v8::Value>[nArgc];
25 nArgv[0] = v8::String::New(event);
26 for (
int i=0; i < argc; i++) {
27 nArgv[i + 1] = argv[i];
30 #if NODE_VERSION_AT_LEAST(0, 5, 0)
31 node::MakeCallback(this->handle_,
"emit", nArgc, nArgv);
33 v8::Local<v8::Value> emit_v = this->handle_->Get(syEmit);
34 if (!emit_v->IsFunction()) {
37 v8::Local<v8::Function> emit = v8::Local<v8::Function>::Cast(emit_v);
39 v8::TryCatch try_catch;
40 emit->Call(this->handle_, nArgc, nArgv);
45 #if !NODE_VERSION_AT_LEAST(0, 5, 0)
46 if (try_catch.HasCaught()) {
47 node::FatalException(try_catch);