diff --git a/resources/testharness.js b/resources/testharness.js index 9995d7aea651472..5edf75bcb6a004c 100644 --- a/resources/testharness.js +++ b/resources/testharness.js @@ -2884,10 +2884,10 @@ * be cancelled. */ Test.prototype.cleanup = function() { - var error_count = 0; + var errors = []; var bad_value_count = 0; - function on_error() { - error_count += 1; + function on_error(e) { + errors.push(e); // Abort tests immediately so that tests declared within subsequent // cleanup functions are not run. tests.abort(); @@ -2904,7 +2904,7 @@ try { result = cleanup_callback(); } catch (e) { - on_error(); + on_error(e); return; } @@ -2919,7 +2919,7 @@ }); if (!this._is_promise_test) { - cleanup_done(this_obj, error_count, bad_value_count); + cleanup_done(this_obj, errors, bad_value_count); } else { all_async(results, function(result, done) { @@ -2932,7 +2932,7 @@ } }, function() { - cleanup_done(this_obj, error_count, bad_value_count); + cleanup_done(this_obj, errors, bad_value_count); }); } }; @@ -2954,17 +2954,21 @@ return false; } - function cleanup_done(test, error_count, bad_value_count) { - if (error_count || bad_value_count) { + function cleanup_done(test, errors, bad_value_count) { + if (errors.length || bad_value_count) { var total = test._user_defined_cleanup_count; tests.status.status = tests.status.ERROR; + tests.status.stack = null; tests.status.message = "Test named '" + test.name + "' specified " + total + " 'cleanup' function" + (total > 1 ? "s" : ""); - if (error_count) { - tests.status.message += ", and " + error_count + " failed"; + if (errors.length) { + tests.status.message += ", and " + errors.length + " failed"; + tests.status.stack = ((typeof errors[0] === "object" && + errors[0].hasOwnProperty("stack")) ? + errors[0].stack : null); } if (bad_value_count) { @@ -2975,8 +2979,6 @@ } tests.status.message += "."; - - tests.status.stack = null; } test.phase = test.phases.COMPLETE;