Author: olehougaard
Date: Tue Dec  9 02:16:38 2008
New Revision: 945

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

Log:
Fixing a bug where a try-finally block obscured a try-catch block when  
registering an external try-catch handler.
Review URL: http://codereview.chromium.org/13658

Modified: branches/bleeding_edge/src/top.cc
==============================================================================
--- branches/bleeding_edge/src/top.cc   (original)
+++ branches/bleeding_edge/src/top.cc   Tue Dec  9 02:16:38 2008
@@ -280,7 +280,15 @@
  // is on the top. Otherwise, it means the C try-catch handler is on the  
top.
  //
  void Top::RegisterTryCatchHandler(v8::TryCatch* that) {
-  that->js_handler_ = thread_local_.handler_;  // casted to void*
+  StackHandler* handler =
+    reinterpret_cast<StackHandler*>(thread_local_.handler_);
+
+  // Find the top-most try-catch handler.
+  while (handler != NULL && !handler->is_try_catch()) {
+    handler = handler->next();
+  }
+
+  that->js_handler_ = handler;  // casted to void*
    thread_local_.try_catch_handler_ = that;
  }


Modified: branches/bleeding_edge/test/cctest/test-api.cc
==============================================================================
--- branches/bleeding_edge/test/cctest/test-api.cc      (original)
+++ branches/bleeding_edge/test/cctest/test-api.cc      Tue Dec  9 02:16:38 2008
@@ -1648,6 +1648,15 @@
  }


+v8::Handle<Value> CCatcher(const v8::Arguments& args) {
+  if (args.Length() < 1) return v8::Boolean::New(false);
+  v8::HandleScope scope;
+  v8::TryCatch try_catch;
+  v8::Script::Compile(args[0]->ToString())->Run();
+  return v8::Boolean::New(try_catch.HasCaught());
+}
+
+
  THREADED_TEST(APICatch) {
    v8::HandleScope scope;
    Local<ObjectTemplate> templ = ObjectTemplate::New();
@@ -1675,6 +1684,25 @@
    v8::TryCatch try_catch;
    CompileRun("ThrowFromC();");
    CHECK(try_catch.HasCaught());
+}
+
+
+// Test that a try-finally block doesn't shadow a try-catch block
+// when setting up an external handler.
+THREADED_TEST(TryCatchInTryFinally) {
+  v8::HandleScope scope;
+  Local<ObjectTemplate> templ = ObjectTemplate::New();
+  templ->Set(v8_str("CCatcher"),
+             v8::FunctionTemplate::New(CCatcher));
+  LocalContext context(0, templ);
+  Local<Value> result = CompileRun("try {"
+                                   "  try {"
+                                   "    CCatcher('throw 7;');"
+                                   "  } finally {"
+                                   "  }"
+                                   "} catch (e) {"
+                                   "}");
+  CHECK(result->IsTrue());
  }



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

Reply via email to