Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: a011564b98ab104896256b0aaffd3ecb254d744a
      
https://github.com/WebKit/WebKit/commit/a011564b98ab104896256b0aaffd3ecb254d744a
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-08-05 (Wed, 05 Aug 2026)

  Changed paths:
    A JSTests/stress/array-sort-default-comparator-stability.js
    M Source/JavaScriptCore/runtime/ArrayPrototype.cpp

  Log Message:
  -----------
  [JSC] `Array#sort` without a comparator is not stable
https://bugs.webkit.org/show_bug.cgi?id=320982

Reviewed by Yusuke Suzuki.

The no-comparator string sort falls back to std::ranges::sort for buckets 
smaller
than 32 entries and past the depth cap, and std::ranges::sort is not stable. The
default sort compares ToString results, which is a consistent comparator, so the
spec requires the result to be stable [1]:

    let objects = [];
    for (let i = 0; i < 30; ++i)
        objects.push({ id: i, toString() { return "k" + (i % 3); } });
    objects.sort(); // equal keys must keep their original order

Use std::ranges::stable_sort instead.

[1]: https://tc39.es/ecma262/#sec-sortindexedproperties

Test: JSTests/stress/array-sort-default-comparator-stability.js

* JSTests/stress/array-sort-default-comparator-stability.js: Added.
(shouldBe):
(makeEntries):
(verifyStable):
* Source/JavaScriptCore/runtime/ArrayPrototype.cpp:
(JSC::sortBucketSort):

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



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

Reply via email to