Index: src/messages.cc |
diff --git a/src/messages.cc b/src/messages.cc |
index cab982cecc5d9f82632218278ed032264809de1f..5e15b93193db06b483f5a80f0beef2a908d37409 100644 |
--- a/src/messages.cc |
+++ b/src/messages.cc |
@@ -106,14 +106,34 @@ Handle<JSMessageObject> MessageHandler::MakeMessageObject( |
} |
-void MessageHandler::ReportMessage(MessageLocation* loc, |
+void MessageHandler::ReportMessage(Isolate* isolate, |
+ MessageLocation* loc, |
Handle<Object> message) { |
+ // If we are in process of message reporting, just ignore all other requests |
+ // to report a message as they are due to unhandled exceptions thrown in |
+ // message callbacks. |
+ if (isolate->in_exception_reporting()) { |
+ ReportMessage("uncaught exception thrown while reporting"); |
+ return; |
+ } |
+ isolate->set_in_exception_reporting(true); |
+ |
+ // We are calling into embedder's code which can throw exceptions. |
+ // Thus we need to save current exception state, reset it to the clean one |
+ // and ignore scheduled exceptions callbacks can throw. |
+ Isolate::ExceptionScope exception_scope(isolate); |
+ isolate->clear_pending_exception(); |
+ isolate->set_external_caught_exception(false); |
+ |
v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); |
v8::NeanderArray global_listeners(FACTORY->message_listeners()); |
int global_length = global_listeners.length(); |
if (global_length == 0) { |
DefaultMessageReport(loc, message); |
+ if (isolate->has_scheduled_exception()) { |
+ isolate->clear_scheduled_exception(); |
+ } |
} else { |
for (int i = 0; i < global_length; i++) { |
HandleScope scope; |
@@ -124,8 +144,13 @@ void MessageHandler::ReportMessage(MessageLocation* loc, |
FUNCTION_CAST<v8::MessageCallback>(callback_obj->proxy()); |
Handle<Object> callback_data(listener.get(1)); |
callback(api_message_obj, v8::Utils::ToLocal(callback_data)); |
+ if (isolate->has_scheduled_exception()) { |
+ isolate->clear_scheduled_exception(); |
+ } |
} |
} |
+ |
+ isolate->set_in_exception_reporting(false); |
} |