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 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 return this.name + ": " + formatted; | 1026 return this.name + ": " + formatted; |
1027 } | 1027 } |
1028 var message = this.hasOwnProperty("message") ? (": " + this.message) : ""; | 1028 var message = this.hasOwnProperty("message") ? (": " + this.message) : ""; |
1029 return this.name + message; | 1029 return this.name + message; |
1030 } finally { | 1030 } finally { |
1031 visited_errors.pop(); | 1031 visited_errors.pop(); |
1032 } | 1032 } |
1033 } | 1033 } |
1034 | 1034 |
1035 function errorToString() { | 1035 function errorToString() { |
1036 // These helper functions are needed because access to properties on | 1036 // This helper function is needed because access to properties on |
1037 // the builtins object do not work inside of a catch clause. | 1037 // the builtins object do not work inside of a catch clause. |
1038 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } | 1038 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } |
1039 function isVisitedErrorsEmpty() { return visited_errors.length === 0; } | |
1040 | 1039 |
1041 try { | 1040 try { |
1042 return %_CallFunction(this, errorToStringDetectCycle); | 1041 return %_CallFunction(this, errorToStringDetectCycle); |
1043 } catch(e) { | 1042 } catch(e) { |
1044 // Propagate cyclic_error_marker exception until all error | 1043 // If this error message was encountered already return the empty |
1045 // formatting is finished and then return the empty string. Safari | 1044 // string for it instead of recursively formatting it. |
1046 // and Firefox also returns the empty string when converting a | 1045 if (isCyclicErrorMarker(e)) return ''; |
1047 // cyclic error to a string. | |
1048 if (isCyclicErrorMarker(e) && isVisitedErrorsEmpty()) return ''; | |
1049 else throw e; | 1046 else throw e; |
1050 } | 1047 } |
1051 } | 1048 } |
1052 | 1049 |
1053 %FunctionSetName(errorToString, 'toString'); | 1050 %FunctionSetName(errorToString, 'toString'); |
1054 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM); | 1051 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM); |
1055 | 1052 |
1056 // Boilerplate for exceptions for stack overflows. Used from | 1053 // Boilerplate for exceptions for stack overflows. Used from |
1057 // Top::StackOverflow(). | 1054 // Top::StackOverflow(). |
1058 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1055 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |