Title: [216169] trunk
Revision
216169
Author
[email protected]
Date
2017-05-03 19:16:12 -0700 (Wed, 03 May 2017)

Log Message

Array.prototype.sort should also allow a null comparator
https://bugs.webkit.org/show_bug.cgi?id=171621
JSTests:

Reviewed by Michael Saboff.

Add test to make it less likely we revert to the incompatable behavior.
Also, fix now incorrect tests.

* ChakraCore/test/Array/array_sort.baseline-jsc:
* stress/array-sort-bad-comparator.js:
(test):
* stress/sort-null-comparator.js: Added.
(assertEq):

Source/_javascript_Core:

<rdar://problem/30757933>

Reviewed by Michael Saboff.

It looks like sort not accepting a null comparator
causes some pages to stop working. Those pages work in
Chrome/Firefox so we should try to match them.

* builtins/ArrayPrototype.js:
(sort):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChakraCore/test/Array/array_sort.baseline-jsc (216168 => 216169)


--- trunk/JSTests/ChakraCore/test/Array/array_sort.baseline-jsc	2017-05-04 02:02:58 UTC (rev 216168)
+++ trunk/JSTests/ChakraCore/test/Array/array_sort.baseline-jsc	2017-05-04 02:16:12 UTC (rev 216169)
@@ -7,5 +7,4 @@
 1,2,3
 10
 1,1.2,4,4.8,12
-TypeError: Array.prototype.sort requires the comparsion function be a function or undefined
 1,2,3

Modified: trunk/JSTests/ChangeLog (216168 => 216169)


--- trunk/JSTests/ChangeLog	2017-05-04 02:02:58 UTC (rev 216168)
+++ trunk/JSTests/ChangeLog	2017-05-04 02:16:12 UTC (rev 216169)
@@ -1,3 +1,19 @@
+2017-05-03  Keith Miller  <[email protected]>
+
+        Array.prototype.sort should also allow a null comparator
+        https://bugs.webkit.org/show_bug.cgi?id=171621
+
+        Reviewed by Michael Saboff.
+
+        Add test to make it less likely we revert to the incompatable behavior.
+        Also, fix now incorrect tests.
+
+        * ChakraCore/test/Array/array_sort.baseline-jsc:
+        * stress/array-sort-bad-comparator.js:
+        (test):
+        * stress/sort-null-comparator.js: Added.
+        (assertEq):
+
 2017-05-03  Caitlin Potter  <[email protected]>
 
         [JSC] remove unneeded asyncFunctionTests.yaml

Modified: trunk/JSTests/stress/array-sort-bad-comparator.js (216168 => 216169)


--- trunk/JSTests/stress/array-sort-bad-comparator.js	2017-05-04 02:02:58 UTC (rev 216168)
+++ trunk/JSTests/stress/array-sort-bad-comparator.js	2017-05-04 02:16:12 UTC (rev 216169)
@@ -2,13 +2,9 @@
 
 function test() {
     try {
-        [1,2].sort(null);
-        return false;
-        } catch (enull) {}
-    try {
         [1,2].sort(true);
         return false;
-        } catch (etrue) {}
+    } catch (etrue) {}
     try {
         [1,2].sort({});
         return false;

Added: trunk/JSTests/stress/sort-null-comparator.js (0 => 216169)


--- trunk/JSTests/stress/sort-null-comparator.js	                        (rev 0)
+++ trunk/JSTests/stress/sort-null-comparator.js	2017-05-04 02:16:12 UTC (rev 216169)
@@ -0,0 +1,10 @@
+// While this is not required by the spec. It looks like some websites rely on the comparator being null.
+
+function assertEq(a, b) {
+    if (a !== b)
+        throw new Error();
+}
+
+let array = [2,1].sort(null);
+assertEq(array[0], 1);
+assertEq(array[1], 2);

Modified: trunk/Source/_javascript_Core/ChangeLog (216168 => 216169)


--- trunk/Source/_javascript_Core/ChangeLog	2017-05-04 02:02:58 UTC (rev 216168)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-05-04 02:16:12 UTC (rev 216169)
@@ -1,3 +1,18 @@
+2017-05-03  Keith Miller  <[email protected]>
+
+        Array.prototype.sort should also allow a null comparator
+        https://bugs.webkit.org/show_bug.cgi?id=171621
+        <rdar://problem/30757933>
+
+        Reviewed by Michael Saboff.
+
+        It looks like sort not accepting a null comparator
+        causes some pages to stop working. Those pages work in
+        Chrome/Firefox so we should try to match them.
+
+        * builtins/ArrayPrototype.js:
+        (sort):
+
 2017-05-03  Mark Lam  <[email protected]>
 
         Use the CLoop for CPU(ARM64E).

Modified: trunk/Source/_javascript_Core/builtins/ArrayPrototype.js (216168 => 216169)


--- trunk/Source/_javascript_Core/builtins/ArrayPrototype.js	2017-05-04 02:02:58 UTC (rev 216168)
+++ trunk/Source/_javascript_Core/builtins/ArrayPrototype.js	2017-05-04 02:16:12 UTC (rev 216169)
@@ -646,7 +646,7 @@
 
     if (typeof comparator == "function")
         comparatorSort(array, length, comparator);
-    else if (comparator === @undefined)
+    else if (comparator === null || comparator === @undefined)
         stringSort(array, length);
     else
         @throwTypeError("Array.prototype.sort requires the comparsion function be a function or undefined");
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to