OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 var result = ""; | 160 var result = ""; |
161 var arg_num = 0; | 161 var arg_num = 0; |
162 for (var i = 0; i < format.length; i++) { | 162 for (var i = 0; i < format.length; i++) { |
163 var str = format[i]; | 163 var str = format[i]; |
164 if (str.length == 2 && %_StringCharCodeAt(str, 0) == 0x25) { | 164 if (str.length == 2 && %_StringCharCodeAt(str, 0) == 0x25) { |
165 // Two-char string starts with "%". | 165 // Two-char string starts with "%". |
166 var arg_num = (%_StringCharCodeAt(str, 1) - 0x30) >>> 0; | 166 var arg_num = (%_StringCharCodeAt(str, 1) - 0x30) >>> 0; |
167 if (arg_num < 4) { | 167 if (arg_num < 4) { |
168 // str is one of %0, %1, %2 or %3. | 168 // str is one of %0, %1, %2 or %3. |
169 try { | 169 try { |
170 str = ToDetailString(args[arg_num]); | 170 str = NoSideEffectToString(args[arg_num]); |
171 } catch (e) { | 171 } catch (e) { |
172 if (%IsJSModule(args[arg_num])) | 172 if (%IsJSModule(args[arg_num])) |
173 str = "module"; | 173 str = "module"; |
174 else if (IS_SPEC_OBJECT(args[arg_num])) | 174 else if (IS_SPEC_OBJECT(args[arg_num])) |
175 str = "object"; | 175 str = "object"; |
176 else | 176 else |
177 str = "#<error>"; | 177 str = "#<error>"; |
178 } | 178 } |
179 } | 179 } |
180 } | 180 } |
181 result += str; | 181 result += str; |
182 } | 182 } |
183 return result; | 183 return result; |
184 } | 184 } |
185 | 185 |
186 | 186 |
| 187 function NoSideEffectToString(obj) { |
| 188 if (IS_STRING(obj)) return obj; |
| 189 if (IS_NUMBER(obj)) return %_NumberToString(obj); |
| 190 if (IS_BOOLEAN(obj)) return x ? 'true' : 'false'; |
| 191 if (IS_UNDEFINED(obj)) return 'undefined'; |
| 192 if (IS_NULL(obj)) return 'null'; |
| 193 if (IS_OBJECT(obj) && %GetDataProperty(obj, "toString") === ObjectToString) { |
| 194 var constructor = obj.constructor; |
| 195 if (typeof constructor == "function") { |
| 196 var constructorName = constructor.name; |
| 197 if (IS_STRING(constructorName) && constructorName !== "") { |
| 198 return "#<" + constructorName + ">"; |
| 199 } |
| 200 } |
| 201 } |
| 202 if (IsNativeErrorObject(obj)) return %_CallFunction(obj, ErrorToString); |
| 203 return %_CallFunction(obj, ObjectToString); |
| 204 } |
| 205 |
| 206 |
187 // To check if something is a native error we need to check the | 207 // To check if something is a native error we need to check the |
188 // concrete native error types. It is not sufficient to use instanceof | 208 // concrete native error types. It is not sufficient to use instanceof |
189 // since it possible to create an object that has Error.prototype on | 209 // since it possible to create an object that has Error.prototype on |
190 // its prototype chain. This is the case for DOMException for example. | 210 // its prototype chain. This is the case for DOMException for example. |
191 function IsNativeErrorObject(obj) { | 211 function IsNativeErrorObject(obj) { |
192 switch (%_ClassOf(obj)) { | 212 switch (%_ClassOf(obj)) { |
193 case 'Error': | 213 case 'Error': |
194 case 'EvalError': | 214 case 'EvalError': |
195 case 'RangeError': | 215 case 'RangeError': |
196 case 'ReferenceError': | 216 case 'ReferenceError': |
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 throw e; | 1243 throw e; |
1224 } | 1244 } |
1225 } | 1245 } |
1226 | 1246 |
1227 | 1247 |
1228 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); | 1248 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); |
1229 | 1249 |
1230 // Boilerplate for exceptions for stack overflows. Used from | 1250 // Boilerplate for exceptions for stack overflows. Used from |
1231 // Isolate::StackOverflow(). | 1251 // Isolate::StackOverflow(). |
1232 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1252 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |