mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:41:41 +00:00
Fix how we use Comparable.compare, so we have a function with the appropriate type in JSArray.sort
This is the same fix that was done here: https://github.com/dart-lang/sdk/blob/master/sdk/lib/collection/list.dart#L349 Change-Id: I6013dc96c67b487b0e96118028ef920a84f371b5 Reviewed-on: https://dart-review.googlesource.com/52701 Reviewed-by: Stephen Adams <sra@google.com> Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
parent
30b53ceaab
commit
004ee9cd12
|
@ -523,7 +523,13 @@ class JSArray<E> extends Interceptor implements List<E>, JSIndexable {
|
|||
|
||||
void sort([int compare(E a, E b)]) {
|
||||
checkMutable('sort');
|
||||
Sort.sort(this, compare == null ? Comparable.compare : compare);
|
||||
Sort.sort(this, compare ?? _compareAny);
|
||||
}
|
||||
|
||||
static int _compareAny(a, b) {
|
||||
// In strong mode Comparable.compare requires an implicit cast to ensure
|
||||
// `a` and `b` are Comparable.
|
||||
return Comparable.compare(a, b);
|
||||
}
|
||||
|
||||
void shuffle([Random random]) {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
/// Tests that the default comparable function in JSArray.sort has a valid
|
||||
/// strong-mode type.
|
||||
void main() {
|
||||
new List<dynamic>.from(['1', '2']).sort();
|
||||
}
|
Loading…
Reference in a new issue