Chromium Code Reviews| 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 var objToString = GetPropertyWithoutInvokingMonkeyGetters(obj, "toString"); |
|
Michael Starzinger
2013/08/02 12:16:02
Yep, better, final nit: Can we move this into the
| |
| 232 if (IsNativeErrorObject(obj) || | |
| 233 (obj instanceof $Error && objToString === ErrorToString)) { | |
| 234 return %_CallFunction(obj, ErrorToString); | |
| 235 } | |
| 232 return %_CallFunction(obj, ObjectToString); | 236 return %_CallFunction(obj, ObjectToString); |
| 233 } | 237 } |
| 234 | 238 |
| 235 | 239 |
| 236 // To check if something is a native error we need to check the | 240 // 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 | 241 // concrete native error types. It is not sufficient to use instanceof |
| 238 // since it possible to create an object that has Error.prototype on | 242 // since it possible to create an object that has Error.prototype on |
| 239 // its prototype chain. This is the case for DOMException for example. | 243 // its prototype chain. This is the case for DOMException for example. |
| 240 function IsNativeErrorObject(obj) { | 244 function IsNativeErrorObject(obj) { |
| 241 switch (%_ClassOf(obj)) { | 245 switch (%_ClassOf(obj)) { |
| 242 case 'Error': | 246 case 'Error': |
| 243 case 'EvalError': | 247 case 'EvalError': |
| 244 case 'RangeError': | 248 case 'RangeError': |
| 245 case 'ReferenceError': | 249 case 'ReferenceError': |
| 246 case 'SyntaxError': | 250 case 'SyntaxError': |
| 247 case 'TypeError': | 251 case 'TypeError': |
| 248 case 'URIError': | 252 case 'URIError': |
| 249 return true; | 253 return true; |
| 250 } | 254 } |
| 251 return false; | 255 return false; |
| 252 } | 256 } |
| 253 | 257 |
| 254 | 258 |
| 255 // When formatting internally created error messages, do not | 259 // When formatting internally created error messages, do not |
| 256 // invoke overwritten error toString methods but explicitly use | 260 // invoke overwritten error toString methods but explicitly use |
| 257 // the error to string method. This is to avoid leaking error | 261 // the error to string method. This is to avoid leaking error |
| 258 // objects between script tags in a browser setting. | 262 // objects between script tags in a browser setting. |
| 259 function ToStringCheckErrorObject(obj) { | 263 function ToStringCheckErrorObject(obj) { |
| 260 if (IsNativeErrorObject(obj)) { | 264 var objToString = GetPropertyWithoutInvokingMonkeyGetters(obj, "toString"); |
| 265 if (IsNativeErrorObject(obj) || | |
| 266 (obj instanceof $Error && objToString === ErrorToString)) { | |
| 261 return %_CallFunction(obj, ErrorToString); | 267 return %_CallFunction(obj, ErrorToString); |
| 262 } else { | 268 } else { |
| 263 return ToString(obj); | 269 return ToString(obj); |
| 264 } | 270 } |
| 265 } | 271 } |
| 266 | 272 |
| 267 | 273 |
| 268 function ToDetailString(obj) { | 274 function ToDetailString(obj) { |
| 269 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { | 275 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { |
| 270 var constructor = obj.constructor; | 276 var constructor = obj.constructor; |
| (...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1337 %GetAndClearOverflowedStackTrace(this); | 1343 %GetAndClearOverflowedStackTrace(this); |
| 1338 }; | 1344 }; |
| 1339 | 1345 |
| 1340 %DefineOrRedefineAccessorProperty( | 1346 %DefineOrRedefineAccessorProperty( |
| 1341 boilerplate, 'stack', getter, setter, DONT_ENUM); | 1347 boilerplate, 'stack', getter, setter, DONT_ENUM); |
| 1342 | 1348 |
| 1343 return boilerplate; | 1349 return boilerplate; |
| 1344 } | 1350 } |
| 1345 | 1351 |
| 1346 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1352 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
| OLD | NEW |