Reviewers: Mads Ager, Vitaly Repeshko, Yury Semikhatsky,

Message:
Guys,

may you have a look?

Regression was detected by layout tests (but it wasn't for some reasonable
before :(

Many thanks to Yury for help!

Description:
Allow recursive messages reporting as it is already used.

Instead discard unhandled exceptions thown while running
message listeners.


Please review this at http://codereview.chromium.org/6820003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/isolate.h
  M src/messages.cc
  M src/top.cc
  M test/cctest/test-api.cc


Index: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index dd0a1fe51e2fbb319abdf2ea42c8c757327ed086..c29131477c7b317e6faac14ada4f04557e76e2c0 100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -188,9 +188,6 @@ class ThreadLocalTop BASE_EMBEDDED {
   // unify them later.
   MaybeObject* scheduled_exception_;
   bool external_caught_exception_;
-  // True if unhandled message is being currently reported by
-  // MessageHandler::ReportMessage.
-  bool in_exception_reporting_;
   SaveContext* save_context_;
   v8::TryCatch* catcher_;

@@ -526,12 +523,6 @@ class Isolate {
   bool* external_caught_exception_address() {
     return &thread_local_top_.external_caught_exception_;
   }
-  bool in_exception_reporting() {
-    return thread_local_top_.in_exception_reporting_;
-  }
-  void set_in_exception_reporting(bool value) {
-    thread_local_top_.in_exception_reporting_ = value;
-  }
   v8::TryCatch* catcher() {
     return thread_local_top_.catcher_;
   }
Index: src/messages.cc
diff --git a/src/messages.cc b/src/messages.cc
index 0cc82512c42842166fc24c92c8c1faf9e50b6d9c..abc25377851b5c4a76a404b5519edf75adc70226 100644
--- a/src/messages.cc
+++ b/src/messages.cc
@@ -104,15 +104,6 @@ Handle<JSMessageObject> MessageHandler::MakeMessageObject(
 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()) {
-    PrintF("uncaught exception thrown while reporting\n");
-    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.
@@ -138,14 +129,16 @@ void MessageHandler::ReportMessage(Isolate* isolate,
       v8::MessageCallback callback =
           FUNCTION_CAST<v8::MessageCallback>(callback_obj->proxy());
       Handle<Object> callback_data(listener.get(1));
-      callback(api_message_obj, v8::Utils::ToLocal(callback_data));
+      {
+        // Do not allow exceptions to propagate.
+        v8::TryCatch tryCatch;
+        callback(api_message_obj, v8::Utils::ToLocal(callback_data));
+      }
       if (isolate->has_scheduled_exception()) {
         isolate->clear_scheduled_exception();
       }
     }
   }
-
-  isolate->set_in_exception_reporting(false);
 }


Index: src/top.cc
diff --git a/src/top.cc b/src/top.cc
index 8611a3165c385b76b765257e9c86166af85dde9f..6771f3814af94eae8fa9e743cdc4c93a57d0e3c3 100644
--- a/src/top.cc
+++ b/src/top.cc
@@ -72,7 +72,6 @@ void ThreadLocalTop::Initialize() {
   int id = Isolate::Current()->thread_manager()->CurrentId();
   thread_id_ = (id == 0) ? ThreadManager::kInvalidId : id;
   external_caught_exception_ = false;
-  in_exception_reporting_ = false;
   failed_access_check_callback_ = NULL;
   save_context_ = NULL;
   catcher_ = NULL;
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index a9051c2d68da516bbb8d47e1cf66b82ac6e0d521..0f08554f09598f5c397c757caa817f2c9217ea88 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -8676,16 +8676,6 @@ static void WithTryCatch(Handle<Message> message, Handle<Value> data) {
 }


-static void ThrowFromJS(Handle<Message> message, Handle<Value> data) {
-  CompileRun("throw 'ThrowInJS';");
-}
-
-
-static void ThrowViaApi(Handle<Message> message, Handle<Value> data) {
-  ThrowException(v8_str("ThrowViaApi"));
-}
-
-
 static void WebKitLike(Handle<Message> message, Handle<Value> data) {
   Handle<String> errorMessageString = message->Get();
   CHECK(!errorMessageString.IsEmpty());
@@ -8702,7 +8692,7 @@ THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) {
   context->Global()->Set(v8_str("func"), func);

   MessageCallback callbacks[] =
-      { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch };
+      { NULL, WebKitLike, WithTryCatch };
   for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) {
     MessageCallback callback = callbacks[i];
     if (callback != NULL) {


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to