OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 (obj instanceof $URIError); | 76 (obj instanceof $URIError); |
77 } | 77 } |
78 | 78 |
79 | 79 |
80 // When formatting internally created error messages, do not | 80 // When formatting internally created error messages, do not |
81 // invoke overwritten error toString methods but explicitly use | 81 // invoke overwritten error toString methods but explicitly use |
82 // the error to string method. This is to avoid leaking error | 82 // the error to string method. This is to avoid leaking error |
83 // objects between script tags in a browser setting. | 83 // objects between script tags in a browser setting. |
84 function ToStringCheckErrorObject(obj) { | 84 function ToStringCheckErrorObject(obj) { |
85 if (IsNativeErrorObject(obj)) { | 85 if (IsNativeErrorObject(obj)) { |
86 return %_CallFunction(obj, errorToString); | 86 return %_CallFunction(obj, ErrorToString); |
87 } else { | 87 } else { |
88 return ToString(obj); | 88 return ToString(obj); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 | 92 |
93 function ToDetailString(obj) { | 93 function ToDetailString(obj) { |
94 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { | 94 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { |
95 var constructor = obj.constructor; | 95 var constructor = obj.constructor; |
96 if (typeof constructor == "function") { | 96 if (typeof constructor == "function") { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 "reduce_no_initial", ["Reduce of empty array with no initial va
lue"], | 178 "reduce_no_initial", ["Reduce of empty array with no initial va
lue"], |
179 "getter_must_be_callable", ["Getter must be a function: ", "%0"], | 179 "getter_must_be_callable", ["Getter must be a function: ", "%0"], |
180 "setter_must_be_callable", ["Setter must be a function: ", "%0"], | 180 "setter_must_be_callable", ["Setter must be a function: ", "%0"], |
181 "value_and_accessor", ["Invalid property. A property cannot bot
h have accessors and be writable or have a value, ", "%0"], | 181 "value_and_accessor", ["Invalid property. A property cannot bot
h have accessors and be writable or have a value, ", "%0"], |
182 "proto_object_or_null", ["Object prototype may only be an Object o
r null"], | 182 "proto_object_or_null", ["Object prototype may only be an Object o
r null"], |
183 "property_desc_object", ["Property description must be an object:
", "%0"], | 183 "property_desc_object", ["Property description must be an object:
", "%0"], |
184 "redefine_disallowed", ["Cannot redefine property: ", "%0"], | 184 "redefine_disallowed", ["Cannot redefine property: ", "%0"], |
185 "define_disallowed", ["Cannot define property:", "%0", ", objec
t is not extensible."], | 185 "define_disallowed", ["Cannot define property:", "%0", ", objec
t is not extensible."], |
186 "non_extensible_proto", ["%0", " is not extensible"], | 186 "non_extensible_proto", ["%0", " is not extensible"], |
187 "handler_non_object", ["Proxy.", "%0", " called with non-object
as handler"], | 187 "handler_non_object", ["Proxy.", "%0", " called with non-object
as handler"], |
188 "trap_function_expected", ["Proxy.", "%0", " called with non-functio
n for ", "%1", " trap"], | 188 "proto_non_object", ["Proxy.", "%0", " called with non-object
as prototype"], |
| 189 "trap_function_expected", ["Proxy.", "%0", " called with non-functio
n for '", "%1", "' trap"], |
189 "handler_trap_missing", ["Proxy handler ", "%0", " has no '", "%1"
, "' trap"], | 190 "handler_trap_missing", ["Proxy handler ", "%0", " has no '", "%1"
, "' trap"], |
190 "handler_trap_must_be_callable", ["Proxy handler ", "%0", " has non-callab
le '", "%1", "' trap"], | 191 "handler_trap_must_be_callable", ["Proxy handler ", "%0", " has non-callab
le '", "%1", "' trap"], |
191 "handler_returned_false", ["Proxy handler ", "%0", " returned false
for '", "%1", "' trap"], | 192 "handler_returned_false", ["Proxy handler ", "%0", " returned false
from '", "%1", "' trap"], |
192 "handler_returned_undefined", ["Proxy handler ", "%0", " returned undefi
ned for '", "%1", "' trap"], | 193 "handler_returned_undefined", ["Proxy handler ", "%0", " returned undefi
ned from '", "%1", "' trap"], |
193 "proxy_prop_not_configurable", ["Trap ", "%1", " of proxy handler ", "%0"
, " returned non-configurable descriptor for property ", "%2"], | 194 "proxy_prop_not_configurable", ["Proxy handler ", "%0", " returned non-co
nfigurable descriptor for property '", "%2", "' from '", "%1", "' trap"], |
194 "proxy_non_object_prop_names", ["Trap ", "%1", " returned non-object ", "
%0"], | 195 "proxy_non_object_prop_names", ["Trap '", "%1", "' returned non-object ",
"%0"], |
195 "proxy_repeated_prop_name", ["Trap ", "%1", " returned repeated proper
ty name ", "%2"], | 196 "proxy_repeated_prop_name", ["Trap '", "%1", "' returned repeated prop
erty name '", "%2", "'"], |
196 "invalid_weakmap_key", ["Invalid value used as weak map key"], | 197 "invalid_weakmap_key", ["Invalid value used as weak map key"], |
197 // RangeError | 198 // RangeError |
198 "invalid_array_length", ["Invalid array length"], | 199 "invalid_array_length", ["Invalid array length"], |
199 "stack_overflow", ["Maximum call stack size exceeded"], | 200 "stack_overflow", ["Maximum call stack size exceeded"], |
200 // SyntaxError | 201 // SyntaxError |
201 "unable_to_parse", ["Parse error"], | 202 "unable_to_parse", ["Parse error"], |
202 "invalid_regexp_flags", ["Invalid flags supplied to RegExp constru
ctor '", "%0", "'"], | 203 "invalid_regexp_flags", ["Invalid flags supplied to RegExp constru
ctor '", "%0", "'"], |
203 "invalid_regexp", ["Invalid RegExp pattern /", "%0", "/"], | 204 "invalid_regexp", ["Invalid RegExp pattern /", "%0", "/"], |
204 "illegal_break", ["Illegal break statement"], | 205 "illegal_break", ["Illegal break statement"], |
205 "illegal_continue", ["Illegal continue statement"], | 206 "illegal_continue", ["Illegal continue statement"], |
(...skipping 27 matching lines...) Expand all Loading... |
233 "strict_reserved_word", ["Use of future reserved word in strict mo
de"], | 234 "strict_reserved_word", ["Use of future reserved word in strict mo
de"], |
234 "strict_delete", ["Delete of an unqualified identifier in s
trict mode."], | 235 "strict_delete", ["Delete of an unqualified identifier in s
trict mode."], |
235 "strict_delete_property", ["Cannot delete property '", "%0", "' of "
, "%1"], | 236 "strict_delete_property", ["Cannot delete property '", "%0", "' of "
, "%1"], |
236 "strict_const", ["Use of const in strict mode."], | 237 "strict_const", ["Use of const in strict mode."], |
237 "strict_function", ["In strict mode code, functions can only
be declared at top level or immediately within another function." ], | 238 "strict_function", ["In strict mode code, functions can only
be declared at top level or immediately within another function." ], |
238 "strict_read_only_property", ["Cannot assign to read only property '",
"%0", "' of ", "%1"], | 239 "strict_read_only_property", ["Cannot assign to read only property '",
"%0", "' of ", "%1"], |
239 "strict_cannot_assign", ["Cannot assign to read only '", "%0", "'
in strict mode"], | 240 "strict_cannot_assign", ["Cannot assign to read only '", "%0", "'
in strict mode"], |
240 "strict_poison_pill", ["'caller', 'callee', and 'arguments' prop
erties may not be accessed on strict mode functions or the arguments objects for
calls to them"], | 241 "strict_poison_pill", ["'caller', 'callee', and 'arguments' prop
erties may not be accessed on strict mode functions or the arguments objects for
calls to them"], |
241 "strict_caller", ["Illegal access to a strict mode caller f
unction."], | 242 "strict_caller", ["Illegal access to a strict mode caller f
unction."], |
242 "unprotected_let", ["Illegal let declaration in unprotected s
tatement context."], | 243 "unprotected_let", ["Illegal let declaration in unprotected s
tatement context."], |
| 244 "unprotected_const", ["Illegal const declaration in unprotected
statement context."], |
243 "cant_prevent_ext_external_array_elements", ["Cannot prevent extension of
an object with external array elements"], | 245 "cant_prevent_ext_external_array_elements", ["Cannot prevent extension of
an object with external array elements"], |
244 "redef_external_array_element", ["Cannot redefine a property of an object
with external array elements"], | 246 "redef_external_array_element", ["Cannot redefine a property of an object
with external array elements"], |
245 ]; | 247 ]; |
246 var messages = { __proto__ : null }; | 248 var messages = { __proto__ : null }; |
247 var desc = new PropertyDescriptor(); | 249 var desc = new PropertyDescriptor(); |
248 desc.setConfigurable(false); | 250 desc.setConfigurable(false); |
249 desc.setEnumerable(false); | 251 desc.setEnumerable(false); |
250 desc.setWritable(false); | 252 desc.setWritable(false); |
251 for (var i = 0; i < messagesDictionary.length; i += 2) { | 253 for (var i = 0; i < messagesDictionary.length; i += 2) { |
252 var key = messagesDictionary[i]; | 254 var key = messagesDictionary[i]; |
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 %IgnoreAttributesAndSetProperty(this, | 1121 %IgnoreAttributesAndSetProperty(this, |
1120 'message', | 1122 'message', |
1121 ToString(m), | 1123 ToString(m), |
1122 DONT_ENUM); | 1124 DONT_ENUM); |
1123 } | 1125 } |
1124 captureStackTrace(this, f); | 1126 captureStackTrace(this, f); |
1125 } else { | 1127 } else { |
1126 return new f(m); | 1128 return new f(m); |
1127 } | 1129 } |
1128 }); | 1130 }); |
| 1131 %SetNativeFlag(f); |
1129 } | 1132 } |
1130 | 1133 |
1131 DefineError(function Error() { }); | 1134 DefineError(function Error() { }); |
1132 DefineError(function TypeError() { }); | 1135 DefineError(function TypeError() { }); |
1133 DefineError(function RangeError() { }); | 1136 DefineError(function RangeError() { }); |
1134 DefineError(function SyntaxError() { }); | 1137 DefineError(function SyntaxError() { }); |
1135 DefineError(function ReferenceError() { }); | 1138 DefineError(function ReferenceError() { }); |
1136 DefineError(function EvalError() { }); | 1139 DefineError(function EvalError() { }); |
1137 DefineError(function URIError() { }); | 1140 DefineError(function URIError() { }); |
1138 } | 1141 } |
1139 | 1142 |
1140 SetUpError(); | 1143 SetUpError(); |
1141 | 1144 |
1142 $Error.captureStackTrace = captureStackTrace; | 1145 $Error.captureStackTrace = captureStackTrace; |
1143 | 1146 |
1144 %SetProperty($Error.prototype, 'message', '', DONT_ENUM); | 1147 %SetProperty($Error.prototype, 'message', '', DONT_ENUM); |
1145 | 1148 |
1146 // Global list of error objects visited during errorToString. This is | 1149 // Global list of error objects visited during ErrorToString. This is |
1147 // used to detect cycles in error toString formatting. | 1150 // used to detect cycles in error toString formatting. |
1148 const visited_errors = new InternalArray(); | 1151 const visited_errors = new InternalArray(); |
1149 const cyclic_error_marker = new $Object(); | 1152 const cyclic_error_marker = new $Object(); |
1150 | 1153 |
1151 function errorToStringDetectCycle(error) { | 1154 function ErrorToStringDetectCycle(error) { |
1152 if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker; | 1155 if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker; |
1153 try { | 1156 try { |
1154 var type = error.type; | 1157 var type = error.type; |
| 1158 var name = error.name |
| 1159 name = IS_UNDEFINED(name) ? "Error" : TO_STRING_INLINE(name); |
| 1160 var message = error.message; |
1155 var hasMessage = %_CallFunction(error, "message", ObjectHasOwnProperty); | 1161 var hasMessage = %_CallFunction(error, "message", ObjectHasOwnProperty); |
1156 if (type && !hasMessage) { | 1162 if (type && !hasMessage) { |
1157 var formatted = FormatMessage(%NewMessageObject(type, error.arguments)); | 1163 message = FormatMessage(%NewMessageObject(type, error.arguments)); |
1158 return error.name + ": " + formatted; | |
1159 } | 1164 } |
1160 var message = hasMessage ? (": " + error.message) : ""; | 1165 message = IS_UNDEFINED(message) ? "" : TO_STRING_INLINE(message); |
1161 return error.name + message; | 1166 if (name === "") return message; |
| 1167 if (message === "") return name; |
| 1168 return name + ": " + message; |
1162 } finally { | 1169 } finally { |
1163 visited_errors.length = visited_errors.length - 1; | 1170 visited_errors.length = visited_errors.length - 1; |
1164 } | 1171 } |
1165 } | 1172 } |
1166 | 1173 |
1167 function errorToString() { | 1174 function ErrorToString() { |
1168 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 1175 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
1169 throw MakeTypeError("called_on_null_or_undefined", | 1176 throw MakeTypeError("called_on_null_or_undefined", |
1170 ["Error.prototype.toString"]); | 1177 ["Error.prototype.toString"]); |
1171 } | 1178 } |
1172 // This helper function is needed because access to properties on | |
1173 // the builtins object do not work inside of a catch clause. | |
1174 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } | |
1175 | 1179 |
1176 try { | 1180 try { |
1177 return errorToStringDetectCycle(this); | 1181 return ErrorToStringDetectCycle(this); |
1178 } catch(e) { | 1182 } catch(e) { |
1179 // If this error message was encountered already return the empty | 1183 // If this error message was encountered already return the empty |
1180 // string for it instead of recursively formatting it. | 1184 // string for it instead of recursively formatting it. |
1181 if (isCyclicErrorMarker(e)) { | 1185 if (e === cyclic_error_marker) { |
1182 return ''; | 1186 return ''; |
1183 } | 1187 } |
1184 throw e; | 1188 throw e; |
1185 } | 1189 } |
1186 } | 1190 } |
1187 | 1191 |
1188 | 1192 |
1189 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]); | 1193 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); |
1190 | 1194 |
1191 // Boilerplate for exceptions for stack overflows. Used from | 1195 // Boilerplate for exceptions for stack overflows. Used from |
1192 // Isolate::StackOverflow(). | 1196 // Isolate::StackOverflow(). |
1193 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1197 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |