Index: src/messages.js |
diff --git a/src/messages.js b/src/messages.js |
index 58f0db09f3741f68213139f446284ad951861b7a..f04bed962d604bc45adaba1f0aec89c6240a6ec7 100644 |
--- a/src/messages.js |
+++ b/src/messages.js |
@@ -167,7 +167,7 @@ function FormatString(format, args) { |
if (arg_num < 4) { |
// str is one of %0, %1, %2 or %3. |
try { |
- str = ToDetailString(args[arg_num]); |
+ str = NoSideEffectToString(args[arg_num]); |
} catch (e) { |
if (%IsJSModule(args[arg_num])) |
str = "module"; |
@@ -184,6 +184,26 @@ function FormatString(format, args) { |
} |
+function NoSideEffectToString(obj) { |
+ if (IS_STRING(obj)) return obj; |
+ if (IS_NUMBER(obj)) return %_NumberToString(obj); |
+ if (IS_BOOLEAN(obj)) return x ? 'true' : 'false'; |
+ if (IS_UNDEFINED(obj)) return 'undefined'; |
+ if (IS_NULL(obj)) return 'null'; |
+ if (IS_OBJECT(obj) && %GetDataProperty(obj, "toString") === ObjectToString) { |
+ var constructor = obj.constructor; |
+ if (typeof constructor == "function") { |
+ var constructorName = constructor.name; |
+ if (IS_STRING(constructorName) && constructorName !== "") { |
+ return "#<" + constructorName + ">"; |
+ } |
+ } |
+ } |
+ if (IsNativeErrorObject(obj)) return %_CallFunction(obj, ErrorToString); |
+ return %_CallFunction(obj, ObjectToString); |
+} |
+ |
+ |
// To check if something is a native error we need to check the |
// concrete native error types. It is not sufficient to use instanceof |
// since it possible to create an object that has Error.prototype on |