Revision: 11834
Author:   [email protected]
Date:     Fri Jun 15 06:34:39 2012
Log:      Fix external exceptions in external try-catch handlers.

This tries to propagate exceptions which are externally thrown into
external try-catch handlers before scheduling them. This also allows
embedders to nest external try-catch handlers.

[email protected]
BUG=v8:2166
TEST=cctest/test-api/TryCatchNested

Review URL: https://chromiumcodereview.appspot.com/10555004
http://code.google.com/p/v8/source/detail?r=11834

Modified:
 /branches/bleeding_edge/src/isolate.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/src/isolate.cc      Mon Jun 11 06:18:05 2012
+++ /branches/bleeding_edge/src/isolate.cc      Fri Jun 15 06:34:39 2012
@@ -945,9 +945,12 @@
   // When scheduling a throw we first throw the exception to get the
   // error reporting if it is uncaught before rescheduling it.
   Throw(exception);
-  thread_local_top()->scheduled_exception_ = pending_exception();
-  thread_local_top()->external_caught_exception_ = false;
-  clear_pending_exception();
+  PropagatePendingExceptionToExternalTryCatch();
+  if (has_pending_exception()) {
+    thread_local_top()->scheduled_exception_ = pending_exception();
+    thread_local_top()->external_caught_exception_ = false;
+    clear_pending_exception();
+  }
 }


=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Thu Jun 14 06:52:58 2012
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Fri Jun 15 06:34:39 2012
@@ -3361,6 +3361,30 @@
       "}\n");
   CHECK(try_catch.HasCaught());
 }
+
+
+static void TryCatchNestedHelper(int depth) {
+  if (depth > 0) {
+    v8::TryCatch try_catch;
+    try_catch.SetVerbose(true);
+    TryCatchNestedHelper(depth - 1);
+    CHECK(try_catch.HasCaught());
+    try_catch.ReThrow();
+  } else {
+    v8::ThrowException(v8_str("back"));
+  }
+}
+
+
+TEST(TryCatchNested) {
+  v8::V8::Initialize();
+  v8::HandleScope scope;
+  LocalContext context;
+  v8::TryCatch try_catch;
+  TryCatchNestedHelper(5);
+  CHECK(try_catch.HasCaught());
+ CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "back"));
+}


 THREADED_TEST(Equality) {

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

Reply via email to