Revision: 12939
Author:   [email protected]
Date:     Mon Nov 12 09:32:30 2012
Log:      Correctly handle uncaught exception objects.

[email protected]
BUG=

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

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

=======================================
--- /branches/bleeding_edge/src/isolate.cc      Mon Nov 12 06:54:29 2012
+++ /branches/bleeding_edge/src/isolate.cc      Mon Nov 12 09:32:30 2012
@@ -1228,18 +1228,22 @@
               stack_trace_for_uncaught_exceptions_options_);
         }
       }
-      // Stringify custom error objects for the message object.
- if (exception_handle->IsJSObject() && !IsErrorObject(exception_handle)) {
+
+      Handle<Object> exception_arg = exception_handle;
+ // If the exception argument is a custom object, turn it into a string
+      // before throwing as uncaught exception.  Note that the pending
+      // exception object to be set later must not be turned into a string.
+      if (exception_arg->IsJSObject() && !IsErrorObject(exception_arg)) {
         bool failed = false;
-        exception_handle = Execution::ToString(exception_handle, &failed);
+        exception_arg = Execution::ToString(exception_arg, &failed);
         if (failed) {
-          exception_handle = factory()->LookupAsciiSymbol("exception");
+          exception_arg = factory()->LookupAsciiSymbol("exception");
         }
       }
       Handle<Object> message_obj = MessageHandler::MakeMessageObject(
           "uncaught_exception",
           location,
-          HandleVector<Object>(&exception_handle, 1),
+          HandleVector<Object>(&exception_arg, 1),
           stack_trace,
           stack_trace_object);
       thread_local_top()->pending_message_obj_ = *message_obj;
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Fri Nov  9 02:07:54 2012
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Mon Nov 12 09:32:30 2012
@@ -2552,6 +2552,18 @@
   String::AsciiValue exception_value(try_catch.Exception());
   CHECK_EQ(*exception_value, "panama!");
 }
+
+
+TEST(TryCatchCustomException) {
+  v8::HandleScope scope;
+  LocalContext env;
+  v8::TryCatch try_catch;
+  CompileRun("function CustomError() { this.a = 'b'; }"
+             "(function f() { throw new CustomError(); })();");
+  CHECK(try_catch.HasCaught());
+  CHECK(try_catch.Exception()->ToObject()->
+            Get(v8_str("a"))->Equals(v8_str("b")));
+}


 bool message_received;

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

Reply via email to