From bb9c9fe92c22789b22abde06150054488a656f69 Mon Sep 17 00:00:00 2001 From: "ager@chromium.org" Date: Fri, 21 Jan 2011 14:11:35 +0000 Subject: [PATCH] Change recursive error printing to just replace recursively encountered error objects with the empty string. This actually does match the Safari behaviour. Review URL: http://codereview.chromium.org/6259010 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6430 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/messages.js | 11 ++++------- test/mjsunit/cyclic-error-to-string.js | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/messages.js b/src/messages.js index d654255..4a89647 100644 --- a/src/messages.js +++ b/src/messages.js @@ -1033,19 +1033,16 @@ function errorToStringDetectCycle() { } function errorToString() { - // These helper functions are needed because access to properties on + // This helper function is needed because access to properties on // the builtins object do not work inside of a catch clause. function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } - function isVisitedErrorsEmpty() { return visited_errors.length === 0; } try { return %_CallFunction(this, errorToStringDetectCycle); } catch(e) { - // Propagate cyclic_error_marker exception until all error - // formatting is finished and then return the empty string. Safari - // and Firefox also returns the empty string when converting a - // cyclic error to a string. - if (isCyclicErrorMarker(e) && isVisitedErrorsEmpty()) return ''; + // If this error message was encountered already return the empty + // string for it instead of recursively formatting it. + if (isCyclicErrorMarker(e)) return ''; else throw e; } } diff --git a/test/mjsunit/cyclic-error-to-string.js b/test/mjsunit/cyclic-error-to-string.js index 7c43fc5..2502b53 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 + ''); -- 2.7.4