This repository has been archived by the owner. It is now read-only.

EventEmitter constructor should not be in C++ #1335

Closed
ry opened this Issue Jul 15, 2011 · 5 comments

Comments

Projects
None yet
5 participants

ry commented Jul 15, 2011

cc @hij1nx

@ghost ghost assigned ry Jul 15, 2011

was there a purpose of this beyond that if EventEmitter's constructor/emit not existing in C++, that other c-bindings wont have access to EventEmitter?

ry commented Jul 19, 2011

complete in 4ef8f06

@ry ry closed this Jul 19, 2011

0x00A commented Jul 19, 2011

@ry ETA for complete EE2 with tests is ~Friday Jul 22

mscdex commented Jul 31, 2011

So how are we supposed to be able to emit events from C++ land? Or is that no longer possible at all?

Member

bnoordhuis commented Aug 1, 2011

@mscdex: this is how you would (approximately) go about it. obj is the object that should receive the event.

Local<Object> obj = /* ... */;
Local<Value> val = obj->Get(String::NewSymbol("emit"));
if (val->IsFunction()) {
  Local<Function> fun = val.As<Function>();

  Local<Value> argv[2] = {
    String::New("event_name"),
    String::New("argument")
  };

  TryCatch tc;
  fun->Call(obj, 2, argv);
  if (tc.HasCaught()) {
    // handle exception
  }
}

@ry ry removed their assignment Aug 31, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.