Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

EventEmitter constructor should not be in C++ #1335

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

EventEmitter constructor should not be in C++ #1335

ry opened this issue Jul 15, 2011 · 5 comments

Comments

@ry
Copy link

ry commented Jul 15, 2011

cc @hij1nx

@ghost ghost assigned ry Jul 15, 2011
@jamesonjlee
Copy link

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
Copy link
Author

ry commented Jul 19, 2011

complete in 4ef8f06

@ry ry closed this as completed Jul 19, 2011
@heapwolf
Copy link

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

@mscdex
Copy link

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?

@bnoordhuis
Copy link
Member

@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.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants