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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 if (IS_FUNCTION(obj)) return %_CallFunction(obj, FunctionToString); | 221 if (IS_FUNCTION(obj)) return %_CallFunction(obj, FunctionToString); |
222 if (IS_OBJECT(obj) && %GetDataProperty(obj, "toString") === ObjectToString) { | 222 if (IS_OBJECT(obj) && %GetDataProperty(obj, "toString") === ObjectToString) { |
223 var constructor = %GetDataProperty(obj, "constructor"); | 223 var constructor = %GetDataProperty(obj, "constructor"); |
224 if (typeof constructor == "function") { | 224 if (typeof constructor == "function") { |
225 var constructorName = constructor.name; | 225 var constructorName = constructor.name; |
226 if (IS_STRING(constructorName) && constructorName !== "") { | 226 if (IS_STRING(constructorName) && constructorName !== "") { |
227 return "#<" + constructorName + ">"; | 227 return "#<" + constructorName + ">"; |
228 } | 228 } |
229 } | 229 } |
230 } | 230 } |
231 if (IsNativeErrorObject(obj)) return %_CallFunction(obj, ErrorToString); | 231 if (IsNativeErrorObject(obj) || |
232 (obj instanceof $Error && obj.toString === $Error.prototype.toString)) { | |
Michael Starzinger
2013/08/02 11:47:04
As discussed offline: I am a little bit worried th
Mike West
2013/08/02 12:04:50
Both these suggestions make sense, and are in the
| |
233 return %_CallFunction(obj, ErrorToString); | |
234 } | |
232 return %_CallFunction(obj, ObjectToString); | 235 return %_CallFunction(obj, ObjectToString); |
233 } | 236 } |
234 | 237 |
235 | 238 |
236 // To check if something is a native error we need to check the | 239 // To check if something is a native error we need to check the |
237 // concrete native error types. It is not sufficient to use instanceof | 240 // concrete native error types. It is not sufficient to use instanceof |
238 // since it possible to create an object that has Error.prototype on | 241 // since it possible to create an object that has Error.prototype on |
239 // its prototype chain. This is the case for DOMException for example. | 242 // its prototype chain. This is the case for DOMException for example. |
240 function IsNativeErrorObject(obj) { | 243 function IsNativeErrorObject(obj) { |
241 switch (%_ClassOf(obj)) { | 244 switch (%_ClassOf(obj)) { |
242 case 'Error': | 245 case 'Error': |
243 case 'EvalError': | 246 case 'EvalError': |
244 case 'RangeError': | 247 case 'RangeError': |
245 case 'ReferenceError': | 248 case 'ReferenceError': |
246 case 'SyntaxError': | 249 case 'SyntaxError': |
247 case 'TypeError': | 250 case 'TypeError': |
248 case 'URIError': | 251 case 'URIError': |
249 return true; | 252 return true; |
250 } | 253 } |
251 return false; | 254 return false; |
252 } | 255 } |
253 | 256 |
254 | 257 |
255 // When formatting internally created error messages, do not | 258 // When formatting internally created error messages, do not |
256 // invoke overwritten error toString methods but explicitly use | 259 // invoke overwritten error toString methods but explicitly use |
257 // the error to string method. This is to avoid leaking error | 260 // the error to string method. This is to avoid leaking error |
258 // objects between script tags in a browser setting. | 261 // objects between script tags in a browser setting. |
259 function ToStringCheckErrorObject(obj) { | 262 function ToStringCheckErrorObject(obj) { |
260 if (IsNativeErrorObject(obj)) { | 263 if (IsNativeErrorObject(obj) || |
264 (obj instanceof $Error && obj.toString === $Error.prototype.toString)) { | |
261 return %_CallFunction(obj, ErrorToString); | 265 return %_CallFunction(obj, ErrorToString); |
262 } else { | 266 } else { |
263 return ToString(obj); | 267 return ToString(obj); |
264 } | 268 } |
265 } | 269 } |
266 | 270 |
267 | 271 |
268 function ToDetailString(obj) { | 272 function ToDetailString(obj) { |
269 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { | 273 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { |
270 var constructor = obj.constructor; | 274 var constructor = obj.constructor; |
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1337 %GetAndClearOverflowedStackTrace(this); | 1341 %GetAndClearOverflowedStackTrace(this); |
1338 }; | 1342 }; |
1339 | 1343 |
1340 %DefineOrRedefineAccessorProperty( | 1344 %DefineOrRedefineAccessorProperty( |
1341 boilerplate, 'stack', getter, setter, DONT_ENUM); | 1345 boilerplate, 'stack', getter, setter, DONT_ENUM); |
1342 | 1346 |
1343 return boilerplate; | 1347 return boilerplate; |
1344 } | 1348 } |
1345 | 1349 |
1346 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1350 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
OLD | NEW |