Reviewers: Sven Panne,

Description:
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.

This just relands r11834.

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


Please review this at https://codereview.chromium.org/11299329/

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

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


Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 7a761b68a5e1a86c618ed02bbc6bde1ac674922f..57809ce4f9b598116641fabb1947a685956458f7 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -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: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index aa85e2a899e35f6bd0d2e201816f48d1af7956db..1dbc399479ed02dc2a7183a88b5bec1d32b97729 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -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;


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

Reply via email to