Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Unified Diff: src/messages.js

Issue 11359130: Make formatting error message side-effect-free. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/isolate.cc ('k') | src/runtime.h » ('j') | src/runtime.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « src/isolate.cc ('k') | src/runtime.h » ('j') | src/runtime.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698