⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 267554 in webkit


Ignore:
Timestamp:
Sep 24, 2020, 7:51:45 PM (6 years ago)
Author:
Ross Kirsling
Message:

%TypedArray%.prototype.sort must throw if comparator is defined and uncallable
https://bugs.webkit.org/show_bug.cgi?id=216952

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/typedarray-sort.js:

Fix test.

  • test262/expectations.yaml:

Mark two test cases as passing.

Source/JavaScriptCore:

  • builtins/TypedArrayPrototype.js:

(sort):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r267549 r267554  
     12020-09-24  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        %TypedArray%.prototype.sort must throw if comparator is defined and uncallable
     4        https://bugs.webkit.org/show_bug.cgi?id=216952
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * stress/typedarray-sort.js:
     9        Fix test.
     10
     11        * test262/expectations.yaml:
     12        Mark two test cases as passing.
     13
    1142020-09-24  Ross Kirsling  <ross.kirsling@sony.com>
    215
  • trunk/JSTests/stress/typedarray-sort.js

    r264304 r267554  
    5050
    5151debug("4.0 Wrong Type for Callback Test");
    52 shouldBeTrue("testPrototypeFunction('sort', '(8)', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
    53 shouldBeTrue("testPrototypeFunction('sort', '(\"wrong\")', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
    54 shouldBeTrue("testPrototypeFunction('sort', '(new Object())', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
    55 shouldBeTrue("testPrototypeFunction('sort', '(null)', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
     52shouldThrow("testPrototypeFunction('sort', '(8)', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
     53shouldThrow("testPrototypeFunction('sort', '(\"wrong\")', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
     54shouldThrow("testPrototypeFunction('sort', '(new Object())', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
     55shouldThrow("testPrototypeFunction('sort', '(null)', [12, 15, 10, 13, 44], [10, 12, 13, 15, 44])");
    5656debug("");
    5757finishJSTest();
  • trunk/JSTests/test262/expectations.yaml

    r267549 r267554  
    12521252  default: 'TypeError: Underlying ArrayBuffer has been detached from the view (Testing with Float64Array.)'
    12531253  strict mode: 'TypeError: Underlying ArrayBuffer has been detached from the view (Testing with Float64Array.)'
    1254 test/built-ins/TypedArray/prototype/sort/comparefn-nonfunction-call-throws.js:
    1255   default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    1256   strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all (Testing with Float64Array.)'
    12571254test/built-ins/TypedArray/prototype/toLocaleString/calls-tostring-from-each-value.js:
    12581255  default: 'Test262Error: should not call valueOf if toString is present (Testing with Float64Array.)'
  • trunk/Source/JavaScriptCore/ChangeLog

    r267549 r267554  
     12020-09-24  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        %TypedArray%.prototype.sort must throw if comparator is defined and uncallable
     4        https://bugs.webkit.org/show_bug.cgi?id=216952
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * builtins/TypedArrayPrototype.js:
     9        (sort):
     10
    1112020-09-24  Ross Kirsling  <ross.kirsling@sony.com>
    212
  • trunk/Source/JavaScriptCore/builtins/TypedArrayPrototype.js

    r267549 r267554  
    218218    }
    219219
    220     var length = @typedArrayLength(this);
    221 
     220    if (comparator !== @undefined && !@isCallable(comparator))
     221        @throwTypeError("TypedArray.prototype.sort requires the comparator argument to be a function or undefined");
     222
     223    var length = @typedArrayLength(this);
    222224    if (length < 2)
    223225        return;
    224226
    225     if (@isCallable(comparator))
     227    if (comparator !== @undefined)
    226228        mergeSort(this, length, comparator);
    227229    else
    228230        @typedArraySort(this);
    229    
     231
    230232    return this;
    231233}
Note: See TracChangeset for help on using the changeset viewer.