Commit c6b35d03 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Correctly handle uncaught exception objects.

R=jkummerow@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/11365200

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12939 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent acd3013d
......@@ -1228,18 +1228,22 @@ void Isolate::DoThrow(Object* exception, MessageLocation* location) {
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;
......
......@@ -2554,6 +2554,18 @@ THREADED_TEST(ScriptException) {
}
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment