Reviewers: Lasse Reichstein,
Message:
The updated test expectations in cyclic-error-to-string.js are in line with
the
current Firefox stable. Unfortunately Safari still shows the old non-ES5
behavior. However I think it is OK for us to move to ES5 in that regard.
Description:
Fix Error.prototype.toString to be ES5 conform.
[email protected]
TEST=test262/15.11.4.4-8-1,mjsunit/cyclic-error-to-string
Please review this at http://codereview.chromium.org/8341021/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/messages.js
M src/mirror-debugger.js
M test/mjsunit/cyclic-error-to-string.js
M test/test262/test262.status
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;
+ var name = error.name
+ 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().
Index: src/mirror-debugger.js
diff --git a/src/mirror-debugger.js b/src/mirror-debugger.js
index
e3f3c48bb55fd26aaba54c08e787fa5355e21938..999252d57f5f4f604497ff3992ec8259a95392f3
100644
--- a/src/mirror-debugger.js
+++ b/src/mirror-debugger.js
@@ -1087,7 +1087,7 @@ ErrorMirror.prototype.toText = function() {
// Use the same text representation as in messages.js.
var text;
try {
- str = %_CallFunction(this.value_, builtins.errorToString);
+ str = %_CallFunction(this.value_, builtins.ErrorToString);
} catch (e) {
str = '#<Error>';
}
Index: test/mjsunit/cyclic-error-to-string.js
diff --git a/test/mjsunit/cyclic-error-to-string.js
b/test/mjsunit/cyclic-error-to-string.js
index
2502b5340fd87ca4601160027f4435c6f443b452..7c43fc580e8378f00cfe22ba80f3948c726f8b21
100644
--- a/test/mjsunit/cyclic-error-to-string.js
+++ b/test/mjsunit/cyclic-error-to-string.js
@@ -36,11 +36,11 @@ e.name = e;
e.message = e;
e.stack = e;
e.arguments = e;
-assertEquals(': ', e + '');
+assertEquals('', e + '');
e = new Error();
e.name = [ e ];
e.message = [ e ];
e.stack = [ e ];
e.arguments = [ e ];
-assertEquals(': ', e + '');
+assertEquals('', e + '');
Index: test/test262/test262.status
diff --git a/test/test262/test262.status b/test/test262/test262.status
index
2ba0f1530bc109ee561ea193ef7525514f2cc516..c3d91bc2e064cc6a10f0872b5caf86f2dfc1a2ae
100644
--- a/test/test262/test262.status
+++ b/test/test262/test262.status
@@ -502,9 +502,6 @@ S15.4.4.3_A2_T1: FAIL_OK
# Bug? Date.prototype.toISOString - value of year is Infinity
# Date.prototype.toISOString throw the RangeError
15.9.5.43-0-15: FAIL
-# Bug? Error.prototype.toString return the value of 'msg' when 'name' is
empty
-# string and 'msg' isn't undefined
-15.11.4.4-8-1: FAIL
############################ SKIPPED TESTS #############################
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev