Fix external exceptions in external try-catch handlers.
authormstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 4 Dec 2012 10:45:59 +0000 (10:45 +0000)
committermstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 4 Dec 2012 10:45:59 +0000 (10:45 +0000)
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.

This just relands r11834.

R=svenpanne@chromium.org
BUG=v8:2166
TEST=cctest/test-api/TryCatchNested

Review URL: https://codereview.chromium.org/11299329

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13129 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/isolate.cc
test/cctest/test-api.cc

index 7a761b6..57809ce 100644 (file)
@@ -1062,9 +1062,12 @@ void Isolate::ScheduleThrow(Object* exception) {
   // 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();
+  }
 }
 
 
index aa85e2a..1dbc399 100644 (file)
@@ -3720,6 +3720,30 @@ THREADED_TEST(TryCatchAndFinally) {
 }
 
 
+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::HandleScope scope;
   LocalContext context;