Reviewers: Michael Starzinger,

Description:
Do not observably convert exception to string when capturing a message.

[email protected]
BUG=chromium:490680
LOG=Y

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

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+19, -25 lines):
  M src/isolate.cc
  M src/messages.cc
  M test/cctest/test-api.cc


Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 1b031f8a937559306d048d616e59f9955170ce2e..ca396278efbb4b99dbdb45e334454c502e7752c1 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -1377,17 +1377,6 @@ Handle<JSMessageObject> Isolate::CreateMessage(Handle<Object> exception,
     location = &potential_computed_location;
   }

-  // 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->IsJSObject() && !IsErrorObject(exception)) {
-    MaybeHandle<Object> maybe_exception =
-        Execution::ToDetailString(this, exception);
-    if (!maybe_exception.ToHandle(&exception)) {
-      exception =
- factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("exception"));
-    }
-  }
   return MessageHandler::MakeMessageObject(
       this, MessageTemplate::kUncaughtException, location, exception,
       stack_trace_object);
Index: src/messages.cc
diff --git a/src/messages.cc b/src/messages.cc
index c21f96c0187a91370c44f0b948a27fbaf68b6da9..bd2792ec25f490a668e66678e658951d54d25e1c 100644
--- a/src/messages.cc
+++ b/src/messages.cc
@@ -280,22 +280,27 @@ Handle<String> MessageTemplate::FormatMessage(Isolate* isolate,
                                               int template_index,
                                               Handle<Object> arg) {
   Factory* factory = isolate->factory();
-  Handle<String> fmt_str = factory->InternalizeOneByteString(
-      STATIC_CHAR_VECTOR("$noSideEffectToString"));
-  Handle<JSFunction> fun = Handle<JSFunction>::cast(
-      Object::GetProperty(isolate->js_builtins_object(), fmt_str)
-          .ToHandleChecked());
-
-  MaybeHandle<Object> maybe_result =
-      Execution::TryCall(fun, isolate->js_builtins_object(), 1, &arg);
-  Handle<Object> result;
-  if (!maybe_result.ToHandle(&result) || !result->IsString()) {
- return factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("<error>"));
+  Handle<String> result_string;
+  if (arg->IsString()) {
+    result_string = Handle<String>::cast(arg);
+  } else {
+    Handle<String> fmt_str = factory->InternalizeOneByteString(
+        STATIC_CHAR_VECTOR("$noSideEffectToString"));
+    Handle<JSFunction> fun = Handle<JSFunction>::cast(
+        Object::GetProperty(isolate->js_builtins_object(), fmt_str)
+            .ToHandleChecked());
+
+    MaybeHandle<Object> maybe_result =
+        Execution::TryCall(fun, isolate->js_builtins_object(), 1, &arg);
+    Handle<Object> result;
+    if (!maybe_result.ToHandle(&result) || !result->IsString()) {
+ return factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("<error>"));
+    }
+    result_string = Handle<String>::cast(result);
   }
   MaybeHandle<String> maybe_result_string = MessageTemplate::FormatMessage(
- template_index, Handle<String>::cast(result), factory->empty_string(),
+      template_index, result_string, factory->empty_string(),
       factory->empty_string());
-  Handle<String> result_string;
   if (!maybe_result_string.ToHandle(&result_string)) {
return factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("<error>"));
   }
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index e6c83849ae4881400eddc34ec268e0e51423c773..8be43313b4b9c85f2119f4483791a8c5946cb84c 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -4798,7 +4798,7 @@ TEST(APIThrowMessageOverwrittenToString) {

 static void check_custom_error_tostring(v8::Handle<v8::Message> message,
                                         v8::Handle<v8::Value> data) {
-  const char* uncaught_error = "Uncaught MyError toString";
+  const char* uncaught_error = "[object Object]";
   CHECK(message->Get()->Equals(v8_str(uncaught_error)));
 }



--
--
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