Skip to content

Commit

Permalink
Factor out TryCatch in ReallyEmit
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Mar 12, 2010
1 parent 2c7cbbc commit d7efb0f
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/node_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ static bool ReallyEmit(Handle<Object> self,
Handle<String> event,
int argc,
Handle<Value> argv[]) {
HandleScope scope;

// HandleScope not needed here because only called from one of the two
// functions below
Local<Value> events_v = self->Get(events_symbol);
if (!events_v->IsObject()) return false;
Local<Object> events = events_v->ToObject();

Local<Value> listeners_v = events->Get(event);
Local<Function> listener;

TryCatch try_catch;

if (listeners_v->IsFunction()) {
// Optimized one-listener case
Local<Function> listener = Local<Function>::Cast(listeners_v);

TryCatch try_catch;

listener->Call(self, argc, argv);

if (try_catch.HasCaught()) {
Expand All @@ -68,15 +68,11 @@ static bool ReallyEmit(Handle<Object> self,
} else if (listeners_v->IsArray()) {
Local<Array> listeners = Local<Array>::Cast(listeners_v);

for (unsigned int i = 0; i < listeners->Length(); i++) {
HandleScope scope;

Local<Value> listener_v = listeners->Get(Integer::New(i));
for (uint32_t i = 0; i < listeners->Length(); i++) {
Local<Value> listener_v = listeners->Get(i);
if (!listener_v->IsFunction()) continue;
Local<Function> listener = Local<Function>::Cast(listener_v);

TryCatch try_catch;

listener->Call(self, argc, argv);

if (try_catch.HasCaught()) {
Expand Down

0 comments on commit d7efb0f

Please sign in to comment.