Revision: 22963
Author:   [email protected]
Date:     Thu Aug  7 08:55:49 2014 UTC
Log:      v8::TryCatch should cancel the scheduled exception on Reset.

v8::TryCatch cancels the scheduled exception on destruction if |Rethrow|
was never called.
It is reasonable to do the same in |Reset|.

BUG=362388, 359386
LOG=
[email protected]

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

Patch from Yutaka Hirano <[email protected]>.
http://code.google.com/p/v8/source/detail?r=22963

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Tue Aug  5 11:27:44 2014 UTC
+++ /branches/bleeding_edge/include/v8.h        Thu Aug  7 08:55:49 2014 UTC
@@ -5114,7 +5114,8 @@

   /**
* Clears any exceptions that may have been caught by this try/catch block.
-   * After this method has been called, HasCaught() will return false.
+ * After this method has been called, HasCaught() will return false. Cancels + * the scheduled exception if it is caught and ReThrow() is not called before.
    *
* It is not necessary to clear a try/catch block before using it again; if * another exception is thrown the previously caught exception will just be
@@ -5157,6 +5158,8 @@
   }

  private:
+  void ResetInternal();
+
   // Make it hard to create heap-allocated TryCatch blocks.
   TryCatch(const TryCatch&);
   void operator=(const TryCatch&);
=======================================
--- /branches/bleeding_edge/src/api.cc  Tue Aug  5 11:27:44 2014 UTC
+++ /branches/bleeding_edge/src/api.cc  Thu Aug  7 08:55:49 2014 UTC
@@ -1823,7 +1823,7 @@
       capture_message_(true),
       rethrow_(false),
       has_terminated_(false) {
-  Reset();
+  ResetInternal();
   // Special handling for simulators which have a separate JS stack.
   js_stack_comparable_address_ =
reinterpret_cast<void*>(v8::internal::SimulatorStack::RegisterCTryCatch(
@@ -1935,6 +1935,17 @@

 void v8::TryCatch::Reset() {
   DCHECK(isolate_ == i::Isolate::Current());
+  if (!rethrow_ && HasCaught() && isolate_->has_scheduled_exception()) {
+ // If an exception was caught but is still scheduled because no API call + // promoted it, then it is canceled to prevent it from being propagated.
+    // Note that this will not cancel termination exceptions.
+    isolate_->CancelScheduledExceptionFromTryCatch(this);
+  }
+  ResetInternal();
+}
+
+
+void v8::TryCatch::ResetInternal() {
   i::Object* the_hole = isolate_->heap()->the_hole_value();
   exception_ = the_hole;
   message_obj_ = the_hole;
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Tue Aug 5 19:37:32 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-api.cc Thu Aug 7 08:55:49 2014 UTC
@@ -5419,6 +5419,31 @@
   CompileRun("TryCatchNativeHelper();");
   CHECK(!try_catch.HasCaught());
 }
+
+
+void TryCatchNativeResetHelper(
+    const v8::FunctionCallbackInfo<v8::Value>& args) {
+  ApiTestFuzzer::Fuzz();
+  v8::TryCatch try_catch;
+  args.GetIsolate()->ThrowException(v8_str("boom"));
+  CHECK(try_catch.HasCaught());
+  try_catch.Reset();
+  CHECK(!try_catch.HasCaught());
+}
+
+
+TEST(TryCatchNativeReset) {
+  v8::Isolate* isolate = CcTest::isolate();
+  v8::HandleScope scope(isolate);
+  v8::V8::Initialize();
+  v8::TryCatch try_catch;
+  Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
+  templ->Set(v8_str("TryCatchNativeResetHelper"),
+ v8::FunctionTemplate::New(isolate, TryCatchNativeResetHelper));
+  LocalContext context(0, templ);
+  CompileRun("TryCatchNativeResetHelper();");
+  CHECK(!try_catch.HasCaught());
+}


 THREADED_TEST(Equality) {

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to