| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 for (var i = 0; i < args.length; i++) { | 83 for (var i = 0; i < args.length; i++) { |
| 84 var str; | 84 var str; |
| 85 try { str = ToDetailString(args[i]); } | 85 try { str = ToDetailString(args[i]); } |
| 86 catch (e) { str = "#<error>"; } | 86 catch (e) { str = "#<error>"; } |
| 87 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); | 87 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); |
| 88 } | 88 } |
| 89 return result; | 89 return result; |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 // When formatting internally created error messages, do not |
| 94 // invoke overwritten error toString methods but explicitly use |
| 95 // the error to string method. This is to avoid leaking error |
| 96 // objects between script tags in a browser setting. |
| 97 function ToStringCheckErrorObject(obj) { |
| 98 if (obj instanceof $Error) { |
| 99 return %_CallFunction(obj, errorToString); |
| 100 } else { |
| 101 return ToString(obj); |
| 102 } |
| 103 } |
| 104 |
| 105 |
| 93 function ToDetailString(obj) { | 106 function ToDetailString(obj) { |
| 94 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri
ng) { | 107 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri
ng) { |
| 95 var constructor = obj.constructor; | 108 var constructor = obj.constructor; |
| 96 if (!constructor) return ToString(obj); | 109 if (!constructor) return ToStringCheckErrorObject(obj); |
| 97 var constructorName = constructor.name; | 110 var constructorName = constructor.name; |
| 98 if (!constructorName) return ToString(obj); | 111 if (!constructorName) return ToStringCheckErrorObject(obj); |
| 99 return "#<" + GetInstanceName(constructorName) + ">"; | 112 return "#<" + GetInstanceName(constructorName) + ">"; |
| 100 } else if (obj instanceof $Error) { | |
| 101 // When formatting internally created error messages, do not | |
| 102 // invoke overwritten error toString methods but explicitly use | |
| 103 // the error to string method. This is to avoid leaking error | |
| 104 // objects between script tags in a browser setting. | |
| 105 return %_CallFunction(obj, errorToString); | |
| 106 } else { | 113 } else { |
| 107 return ToString(obj); | 114 return ToStringCheckErrorObject(obj); |
| 108 } | 115 } |
| 109 } | 116 } |
| 110 | 117 |
| 111 | 118 |
| 112 function MakeGenericError(constructor, type, args) { | 119 function MakeGenericError(constructor, type, args) { |
| 113 if (IS_UNDEFINED(args)) { | 120 if (IS_UNDEFINED(args)) { |
| 114 args = []; | 121 args = []; |
| 115 } | 122 } |
| 116 var e = new constructor(kAddMessageAccessorsMarker); | 123 var e = new constructor(kAddMessageAccessorsMarker); |
| 117 e.type = type; | 124 e.type = type; |
| (...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 else throw e; | 1053 else throw e; |
| 1047 } | 1054 } |
| 1048 } | 1055 } |
| 1049 | 1056 |
| 1050 %FunctionSetName(errorToString, 'toString'); | 1057 %FunctionSetName(errorToString, 'toString'); |
| 1051 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM); | 1058 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM); |
| 1052 | 1059 |
| 1053 // Boilerplate for exceptions for stack overflows. Used from | 1060 // Boilerplate for exceptions for stack overflows. Used from |
| 1054 // Top::StackOverflow(). | 1061 // Top::StackOverflow(). |
| 1055 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1062 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
| OLD | NEW |