Bug 187134 - Inconsistent output compared with other JS engines when using sort()
Summary: Inconsistent output compared with other JS engines when using sort()
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-27 21:26 PDT by sunlili
Modified: 2018-06-28 07:30 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sunlili 2018-06-27 21:26:50 PDT
Hello,
The following code behaves strangely (inconsistent with other engines).

a=[3.3,2.2,1];
a.sort(function () { return -1;});

In Safari, output is
[1, 2.2, 3.3]
However, output should be:
[3.3, 2.2, 1]

BT group
2018.6.28
Comment 1 Yusuke Suzuki 2018-06-28 07:30:03 PDT
I think this is OK. This relies on how comparator is called (since it does not produce consistent results, comp(a, b) => -1 comp(b, a) => -1), and it is implementation dependent according to the spec.