Revision: 6435
Author: [email protected]
Date: Sun Jan 23 23:59:40 2011
Log: Avoid calling overwritten toString methods for internal error
formatting. I missed a couple of places. Extracting the error object
check to a separate function.

Review URL: http://codereview.chromium.org/6304015
http://code.google.com/p/v8/source/detail?r=6435

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

=======================================
--- /branches/bleeding_edge/src/messages.js     Fri Jan 21 06:11:35 2011
+++ /branches/bleeding_edge/src/messages.js     Sun Jan 23 23:59:40 2011
@@ -88,23 +88,30 @@
   }
   return result;
 }
+
+
+// When formatting internally created error messages, do not
+// invoke overwritten error toString methods but explicitly use
+// the error to string method. This is to avoid leaking error
+// objects between script tags in a browser setting.
+function ToStringCheckErrorObject(obj) {
+  if (obj instanceof $Error) {
+    return %_CallFunction(obj, errorToString);
+  } else {
+    return ToString(obj);
+  }
+}


 function ToDetailString(obj) {
if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toString) {
     var constructor = obj.constructor;
-    if (!constructor) return ToString(obj);
+    if (!constructor) return ToStringCheckErrorObject(obj);
     var constructorName = constructor.name;
-    if (!constructorName) return ToString(obj);
+    if (!constructorName) return ToStringCheckErrorObject(obj);
     return "#<" + GetInstanceName(constructorName) + ">";
-  } else if (obj instanceof $Error) {
-    // When formatting internally created error messages, do not
-    // invoke overwritten error toString methods but explicitly use
-    // the error to string method. This is to avoid leaking error
-    // objects between script tags in a browser setting.
-    return %_CallFunction(obj, errorToString);
   } else {
-    return ToString(obj);
+    return ToStringCheckErrorObject(obj);
   }
 }

=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Fri Jan 21 15:58:00 2011
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Sun Jan 23 23:59:40 2011
@@ -2379,6 +2379,10 @@
   CompileRun("ReferenceError.prototype.toString ="
              "  function() { return 'Whoops' }");
   CompileRun("asdf;");
+  CompileRun("ReferenceError.prototype.constructor.name = void 0;");
+  CompileRun("asdf;");
+  CompileRun("ReferenceError.prototype.constructor = void 0;");
+  CompileRun("asdf;");
v8::Handle<Value> string = CompileRun("try { asdf; } catch(e) { e + ''; }");
   CHECK(string->Equals(v8_str("Whoops")));
   v8::V8::RemoveMessageListeners(check_message);

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

Reply via email to