[webkit-changes] [WebKit/WebKit] 798d17: [JSC] TypedArray sorting methods should have a spe...

Commit Queue noreply at github.com
Thu Mar 14 17:59:35 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 798d1789439ab19b30559051cd834481ec7220ac
      https://github.com/WebKit/WebKit/commit/798d1789439ab19b30559051cd834481ec7220ac
  Author: Alexey Shvayka <ashvayka at apple.com>
  Date:   2024-03-14 (Thu, 14 Mar 2024)

  Changed paths:
    A JSTests/stress/sorting-boolean-result-comparator-typedarray.js
    M Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h

  Log Message:
  -----------
  [JSC] TypedArray sorting methods should have a special-case for comparator returning `false`
https://bugs.webkit.org/show_bug.cgi?id=268075
<rdar://problem/122093956>

Reviewed by Yusuke Suzuki and Justin Michaud.

This change aligns TypedArray sorting methods with Array.prototype.sort() to treat `false`,
returned from comparator function, like smallest negative number rather than zero, which is a long-time
web reality quirk [1] to allow lexicographical comparison: `["c", "b", "a"].sort((a, b) => a > b)`.

The spec [2] still lacks normative steps on how to handle comparator return value in the common case.

This patch aligns JSC with V8 and SpiderMonkey.
However, it appears that V8 have recently removed the special-case for `false` in Array sorting methods.

[1]: https://bugs.webkit.org/show_bug.cgi?id=47825
[2]: https://tc39.es/ecma262/#sec-sortindexedproperties (step 4)

* JSTests/stress/sorting-boolean-result-comparator-typedarray.js: Added.
* Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h:
(JSC::coerceComparatorResultToBoolean):
(JSC::genericTypedArrayViewProtoFuncSortImpl):

Canonical link: https://commits.webkit.org/276130@main



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list