From cee2947da0e47f3397b1e37bc1d3561dd5f21819 Mon Sep 17 00:00:00 2001 From: olehougaard Date: Tue, 14 Oct 2008 10:50:44 +0000 Subject: [PATCH] Testing that sorting behaves reasonably with a bad comparison function. Review URL: http://codereview.chromium.org/7137 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@494 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- test/mjsunit/array-sort.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/mjsunit/array-sort.js b/test/mjsunit/array-sort.js index a68b819..dfa4590 100644 --- a/test/mjsunit/array-sort.js +++ b/test/mjsunit/array-sort.js @@ -134,9 +134,21 @@ TestArraySortingWithHoles(); // Test array sorting with undefined elemeents in the array. function TestArraySortingWithUndefined() { - var a = [3, void 0, 2]; + var a = [ 3, void 0, 2 ]; a.sort(); - assertArrayEquals([ 2, 3, void 0], a); + assertArrayEquals([ 2, 3, void 0 ], a); } TestArraySortingWithUndefined(); + +// Test that sorting using an unsound comparison function still gives a +// sane result, i.e. it terminates without error and retains the elements +// in the array. +function TestArraySortingWithUnsoundComparisonFunction() { + var a = [ 3, void 0, 2 ]; + a.sort(function(x, y) { return 1; }); + a.sort(); + assertArrayEquals([ 2, 3, void 0 ], a); +} + +TestArraySortingWithUnsoundComparisonFunction(); -- 2.7.4