Changeset 207235 in webkit


Ignore:
Timestamp:
Oct 12, 2016 12:40:51 PM (8 years ago)
Author:
keith_miller@apple.com
Message:

Handle non-function, non-undefined comparator in Array.prototype.sort
https://bugs.webkit.org/show_bug.cgi?id=163085

Reviewed by Yusuke Suzuki.

JSTests:

  • ChakraCore/test/Array/array_sort.baseline-jsc:
  • stress/array-sort-bad-comparator.js: Added.

(test):

Source/JavaScriptCore:

  • builtins/ArrayPrototype.js:

(sort.comparatorSort):
(sort.stringSort):
(sort):

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChakraCore/test/Array/array_sort.baseline-jsc

    r205387 r207235  
    8810
    991,1.2,4,4.8,12
     10TypeError: Array.prototype.sort requires the comparsion function be a function or undefined
    10111,2,3
  • trunk/JSTests/ChangeLog

    r207226 r207235  
     12016-10-12  Keith Miller  <keith_miller@apple.com>
     2
     3        Handle non-function, non-undefined comparator in Array.prototype.sort
     4        https://bugs.webkit.org/show_bug.cgi?id=163085
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * ChakraCore/test/Array/array_sort.baseline-jsc:
     9        * stress/array-sort-bad-comparator.js: Added.
     10        (test):
     11
    1122016-10-12  Mark Lam  <mark.lam@apple.com>
    213
  • trunk/Source/JavaScriptCore/ChangeLog

    r207230 r207235  
     12016-10-12  Keith Miller  <keith_miller@apple.com>
     2
     3        Handle non-function, non-undefined comparator in Array.prototype.sort
     4        https://bugs.webkit.org/show_bug.cgi?id=163085
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * builtins/ArrayPrototype.js:
     9        (sort.comparatorSort):
     10        (sort.stringSort):
     11        (sort):
     12
    1132016-10-12  Filip Pizlo  <fpizlo@apple.com>
    214
  • trunk/Source/JavaScriptCore/builtins/ArrayPrototype.js

    r206853 r207235  
    607607    }
    608608
    609     function comparatorSort(array, comparator)
    610     {
    611         var length = array.length >>> 0;
    612 
    613         // For compatibility with Firefox and Chrome, do nothing observable
    614         // to the target array if it has 0 or 1 sortable properties.
    615         if (length < 2)
    616             return;
    617 
     609    function comparatorSort(array, length, comparator)
     610    {
    618611        var valueCount = compact(array, length);
    619612        mergeSort(array, valueCount, comparator);
    620613    }
    621614
    622     function stringSort(array)
    623     {
    624         var length = array.length >>> 0;
    625 
    626         // For compatibility with Firefox and Chrome, do nothing observable
    627         // to the target array if it has 0 or 1 sortable properties.
    628         if (length < 2)
    629             return;
    630 
     615    function stringSort(array, length)
     616    {
    631617        var valueCount = compact(array, length);
    632618
     
    641627        @throwTypeError("Array.prototype.sort requires that |this| not be null or undefined");
    642628
    643     if (typeof this == "string")
    644         @throwTypeError("Attempted to assign to readonly property.");
    645 
    646     var array = @Object(this);
     629    var array = @Object(this);
     630
     631    var length = array.length >>> 0;
     632
     633    // For compatibility with Firefox and Chrome, do nothing observable
     634    // to the target array if it has 0 or 1 sortable properties.
     635    if (length < 2)
     636        return array;
    647637
    648638    if (typeof comparator == "function")
    649         comparatorSort(array, comparator);
     639        comparatorSort(array, length, comparator);
     640    else if (comparator === @undefined)
     641        stringSort(array, length);
    650642    else
    651         stringSort(array);
     643        @throwTypeError("Array.prototype.sort requires the comparsion function be a function or undefined");
    652644
    653645    return array;
Note: See TracChangeset for help on using the changeset viewer.