Index: src/messages.js |
diff --git a/src/messages.js b/src/messages.js |
index 4a89647577b05b205b62ebc30f65d365d271f1c2..932d64d2eac398298855555827f1643c135221e4 100644 |
--- a/src/messages.js |
+++ b/src/messages.js |
@@ -90,21 +90,28 @@ function FormatString(format, args) { |
} |
+// 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); |
} |
} |