Index: src/messages.cc |
diff --git a/src/messages.cc b/src/messages.cc |
index 990000a32ea84aa4d605562912afb3440c871354..18dec54cf052f03eedf3272c722f91a7819eb1a3 100644 |
--- a/src/messages.cc |
+++ b/src/messages.cc |
@@ -109,12 +109,32 @@ Handle<JSMessageObject> MessageHandler::MakeMessageObject( |
void MessageHandler::ReportMessage(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. |
+ static int in_process = false; |
Mads Ager (chromium)
2011/03/21 10:33:22
This will not work with isolates. You need this to
antonm
2011/03/21 18:15:48
Done.
|
+ if (in_process) { |
+ ReportMessage("uncaught exception thrown while reporting"); |
+ return; |
+ } |
+ in_process = 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. |
+ Top::ExceptionScope exception_scope; |
+ Top::clear_pending_exception(); |
+ Top::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 (Top::has_scheduled_exception()) { |
+ Top::clear_scheduled_exception(); |
+ } |
} else { |
for (int i = 0; i < global_length; i++) { |
HandleScope scope; |
@@ -125,8 +145,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 (Top::has_scheduled_exception()) { |
+ Top::clear_scheduled_exception(); |
+ } |
} |
} |
+ |
+ in_process = false; |
} |