| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 illegal_continue: "Illegal continue statement", | 202 illegal_continue: "Illegal continue statement", |
| 196 illegal_return: "Illegal return statement", | 203 illegal_return: "Illegal return statement", |
| 197 error_loading_debugger: "Error loading debugger", | 204 error_loading_debugger: "Error loading debugger", |
| 198 no_input_to_regexp: "No input to %0", | 205 no_input_to_regexp: "No input to %0", |
| 199 invalid_json: "String '%0' is not valid JSON", | 206 invalid_json: "String '%0' is not valid JSON", |
| 200 circular_structure: "Converting circular structure to JSON", | 207 circular_structure: "Converting circular structure to JSON", |
| 201 obj_ctor_property_non_object: "Object.%0 called on non-object", | 208 obj_ctor_property_non_object: "Object.%0 called on non-object", |
| 202 array_indexof_not_defined: "Array.getIndexOf: Argument undefined", | 209 array_indexof_not_defined: "Array.getIndexOf: Argument undefined", |
| 203 object_not_extensible: "Can't add property %0, object is not extens
ible", | 210 object_not_extensible: "Can't add property %0, object is not extens
ible", |
| 204 illegal_access: "Illegal access", | 211 illegal_access: "Illegal access", |
| 205 invalid_preparser_data: "Invalid preparser data for function %0" | 212 invalid_preparser_data: "Invalid preparser data for function %0", |
| 213 strict_mode_with: "Strict mode code may not include a with sta
tement", |
| 214 strict_catch_variable: "Catch variable may not be eval or arguments
in strict mode", |
| 215 strict_param_name: "Parameter name eval or arguments is not all
owed in strict mode", |
| 216 strict_param_dupe: "Strict mode function may not have duplicate
parameter names", |
| 217 strict_var_name: "Variable name may not be eval or arguments
in strict mode", |
| 218 strict_function_name: "Function name may not be eval or arguments
in strict mode", |
| 206 }; | 219 }; |
| 207 } | 220 } |
| 208 var format = kMessages[message.type]; | 221 var format = kMessages[message.type]; |
| 209 if (!format) return "<unknown message " + message.type + ">"; | 222 if (!format) return "<unknown message " + message.type + ">"; |
| 210 return FormatString(format, message.args); | 223 return FormatString(format, message.args); |
| 211 } | 224 } |
| 212 | 225 |
| 213 | 226 |
| 214 function GetLineNumber(message) { | 227 function GetLineNumber(message) { |
| 215 if (message.startPos == -1) return kNoLineNumberInfo; | 228 if (message.startPos == -1) return kNoLineNumberInfo; |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 DefineError(function SyntaxError() { }); | 1012 DefineError(function SyntaxError() { }); |
| 1000 DefineError(function ReferenceError() { }); | 1013 DefineError(function ReferenceError() { }); |
| 1001 DefineError(function EvalError() { }); | 1014 DefineError(function EvalError() { }); |
| 1002 DefineError(function URIError() { }); | 1015 DefineError(function URIError() { }); |
| 1003 | 1016 |
| 1004 $Error.captureStackTrace = captureStackTrace; | 1017 $Error.captureStackTrace = captureStackTrace; |
| 1005 | 1018 |
| 1006 // Setup extra properties of the Error.prototype object. | 1019 // Setup extra properties of the Error.prototype object. |
| 1007 $Error.prototype.message = ''; | 1020 $Error.prototype.message = ''; |
| 1008 | 1021 |
| 1022 // Global list of error objects visited during errorToString. This is |
| 1023 // used to detect cycles in error toString formatting. |
| 1024 var visited_errors = new $Array(); |
| 1025 var cyclic_error_marker = new $Object(); |
| 1026 |
| 1027 function errorToStringDetectCycle() { |
| 1028 if (!%PushIfAbsent(visited_errors, this)) throw cyclic_error_marker; |
| 1029 try { |
| 1030 var type = this.type; |
| 1031 if (type && !this.hasOwnProperty("message")) { |
| 1032 var formatted = FormatMessage({ type: type, args: this.arguments }); |
| 1033 return this.name + ": " + formatted; |
| 1034 } |
| 1035 var message = this.hasOwnProperty("message") ? (": " + this.message) : ""; |
| 1036 return this.name + message; |
| 1037 } finally { |
| 1038 visited_errors.pop(); |
| 1039 } |
| 1040 } |
| 1041 |
| 1009 function errorToString() { | 1042 function errorToString() { |
| 1010 var type = this.type; | 1043 // This helper function is needed because access to properties on |
| 1011 if (type && !this.hasOwnProperty("message")) { | 1044 // the builtins object do not work inside of a catch clause. |
| 1012 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); | 1045 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } |
| 1046 |
| 1047 try { |
| 1048 return %_CallFunction(this, errorToStringDetectCycle); |
| 1049 } catch(e) { |
| 1050 // If this error message was encountered already return the empty |
| 1051 // string for it instead of recursively formatting it. |
| 1052 if (isCyclicErrorMarker(e)) return ''; |
| 1053 else throw e; |
| 1013 } | 1054 } |
| 1014 var message = this.hasOwnProperty("message") ? (": " + this.message) : ""; | |
| 1015 return this.name + message; | |
| 1016 } | 1055 } |
| 1017 | 1056 |
| 1018 %FunctionSetName(errorToString, 'toString'); | 1057 %FunctionSetName(errorToString, 'toString'); |
| 1019 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM); | 1058 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM); |
| 1020 | 1059 |
| 1021 | |
| 1022 // Boilerplate for exceptions for stack overflows. Used from | 1060 // Boilerplate for exceptions for stack overflows. Used from |
| 1023 // Top::StackOverflow(). | 1061 // Top::StackOverflow(). |
| 1024 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1062 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
| OLD | NEW |