Chromium Code Reviews| Index: src/messages.js |
| diff --git a/src/messages.js b/src/messages.js |
| index 4a81e95b64169aca3c8886d6ff6e025fa3eada73..c1873c51fbcbe912657a3a8242132c407a50c07f 100644 |
| --- a/src/messages.js |
| +++ b/src/messages.js |
| @@ -83,7 +83,7 @@ function IsNativeErrorObject(obj) { |
| // objects between script tags in a browser setting. |
| function ToStringCheckErrorObject(obj) { |
| if (IsNativeErrorObject(obj)) { |
| - return %_CallFunction(obj, errorToString); |
| + return %_CallFunction(obj, ErrorToString); |
| } else { |
| return ToString(obj); |
| } |
| @@ -1146,28 +1146,32 @@ $Error.captureStackTrace = captureStackTrace; |
| %SetProperty($Error.prototype, 'message', '', DONT_ENUM); |
| -// Global list of error objects visited during errorToString. This is |
| +// Global list of error objects visited during ErrorToString. This is |
| // used to detect cycles in error toString formatting. |
| const visited_errors = new InternalArray(); |
| const cyclic_error_marker = new $Object(); |
| -function errorToStringDetectCycle(error) { |
| +function ErrorToStringDetectCycle(error) { |
| if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker; |
| try { |
| var type = error.type; |
|
Lasse Reichstein
2011/10/26 07:40:24
The spec doesn't say anything about reading .type.
Michael Starzinger
2011/10/26 09:30:20
I agree, the spec says nothing about any "type" or
|
| + var name = error.name |
|
Lasse Reichstein
2011/10/26 07:40:24
According to the spec, we should do ToString on na
Michael Starzinger
2011/10/26 09:30:20
Done.
|
| + var message = error.message; |
| var hasMessage = %_CallFunction(error, "message", ObjectHasOwnProperty); |
| if (type && !hasMessage) { |
| - var formatted = FormatMessage(%NewMessageObject(type, error.arguments)); |
| - return error.name + ": " + formatted; |
| + message = FormatMessage(%NewMessageObject(type, error.arguments)); |
| } |
| - var message = hasMessage ? (": " + error.message) : ""; |
| - return error.name + message; |
| + name = IS_UNDEFINED(name) ? "Error" : TO_STRING_INLINE(name); |
| + message = IS_UNDEFINED(message) ? "" : TO_STRING_INLINE(message); |
| + if (name === "") return message; |
| + if (message === "") return name; |
| + return name + ": " + message; |
| } finally { |
| visited_errors.length = visited_errors.length - 1; |
| } |
| } |
| -function errorToString() { |
| +function ErrorToString() { |
| if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| throw MakeTypeError("called_on_null_or_undefined", |
| ["Error.prototype.toString"]); |
| @@ -1177,7 +1181,7 @@ function errorToString() { |
| function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } |
| try { |
| - return errorToStringDetectCycle(this); |
| + return ErrorToStringDetectCycle(this); |
| } catch(e) { |
| // If this error message was encountered already return the empty |
| // string for it instead of recursively formatting it. |
| @@ -1189,7 +1193,7 @@ function errorToString() { |
| } |
| -InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]); |
| +InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); |
| // Boilerplate for exceptions for stack overflows. Used from |
| // Isolate::StackOverflow(). |