diff --git a/src/node_events.cc b/src/node_events.cc index 9630aa6d9ab6f6..d88229fe8adb0b 100644 --- a/src/node_events.cc +++ b/src/node_events.cc @@ -43,8 +43,8 @@ static bool ReallyEmit(Handle self, Handle event, int argc, Handle argv[]) { - HandleScope scope; - + // HandleScope not needed here because only called from one of the two + // functions below Local events_v = self->Get(events_symbol); if (!events_v->IsObject()) return false; Local events = events_v->ToObject(); @@ -52,12 +52,12 @@ static bool ReallyEmit(Handle self, Local listeners_v = events->Get(event); Local listener; + TryCatch try_catch; + if (listeners_v->IsFunction()) { // Optimized one-listener case Local listener = Local::Cast(listeners_v); - TryCatch try_catch; - listener->Call(self, argc, argv); if (try_catch.HasCaught()) { @@ -68,15 +68,11 @@ static bool ReallyEmit(Handle self, } else if (listeners_v->IsArray()) { Local listeners = Local::Cast(listeners_v); - for (unsigned int i = 0; i < listeners->Length(); i++) { - HandleScope scope; - - Local listener_v = listeners->Get(Integer::New(i)); + for (uint32_t i = 0; i < listeners->Length(); i++) { + Local listener_v = listeners->Get(i); if (!listener_v->IsFunction()) continue; Local listener = Local::Cast(listener_v); - TryCatch try_catch; - listener->Call(self, argc, argv); if (try_catch.HasCaught()) {