Factor out TryCatch in ReallyEmit
This commit is contained in:
parent
2c7cbbc1b0
commit
d7efb0fdb2
@ -43,8 +43,8 @@ static bool ReallyEmit(Handle<Object> self,
|
|||||||
Handle<String> event,
|
Handle<String> event,
|
||||||
int argc,
|
int argc,
|
||||||
Handle<Value> argv[]) {
|
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);
|
Local<Value> events_v = self->Get(events_symbol);
|
||||||
if (!events_v->IsObject()) return false;
|
if (!events_v->IsObject()) return false;
|
||||||
Local<Object> events = events_v->ToObject();
|
Local<Object> events = events_v->ToObject();
|
||||||
@ -52,12 +52,12 @@ static bool ReallyEmit(Handle<Object> self,
|
|||||||
Local<Value> listeners_v = events->Get(event);
|
Local<Value> listeners_v = events->Get(event);
|
||||||
Local<Function> listener;
|
Local<Function> listener;
|
||||||
|
|
||||||
|
TryCatch try_catch;
|
||||||
|
|
||||||
if (listeners_v->IsFunction()) {
|
if (listeners_v->IsFunction()) {
|
||||||
// Optimized one-listener case
|
// Optimized one-listener case
|
||||||
Local<Function> listener = Local<Function>::Cast(listeners_v);
|
Local<Function> listener = Local<Function>::Cast(listeners_v);
|
||||||
|
|
||||||
TryCatch try_catch;
|
|
||||||
|
|
||||||
listener->Call(self, argc, argv);
|
listener->Call(self, argc, argv);
|
||||||
|
|
||||||
if (try_catch.HasCaught()) {
|
if (try_catch.HasCaught()) {
|
||||||
@ -68,15 +68,11 @@ static bool ReallyEmit(Handle<Object> self,
|
|||||||
} else if (listeners_v->IsArray()) {
|
} else if (listeners_v->IsArray()) {
|
||||||
Local<Array> listeners = Local<Array>::Cast(listeners_v);
|
Local<Array> listeners = Local<Array>::Cast(listeners_v);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < listeners->Length(); i++) {
|
for (uint32_t i = 0; i < listeners->Length(); i++) {
|
||||||
HandleScope scope;
|
Local<Value> listener_v = listeners->Get(i);
|
||||||
|
|
||||||
Local<Value> listener_v = listeners->Get(Integer::New(i));
|
|
||||||
if (!listener_v->IsFunction()) continue;
|
if (!listener_v->IsFunction()) continue;
|
||||||
Local<Function> listener = Local<Function>::Cast(listener_v);
|
Local<Function> listener = Local<Function>::Cast(listener_v);
|
||||||
|
|
||||||
TryCatch try_catch;
|
|
||||||
|
|
||||||
listener->Call(self, argc, argv);
|
listener->Call(self, argc, argv);
|
||||||
|
|
||||||
if (try_catch.HasCaught()) {
|
if (try_catch.HasCaught()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user