File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
src/com/google/javascript/jscomp/js/es6 Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -1786,6 +1786,19 @@ Array.prototype.flat = function(depth) {};
1786
1786
*/
1787
1787
Array . prototype . toReversed = function ( ) { } ;
1788
1788
1789
+ /**
1790
+ * NOTE: this is an ES2023 extern.
1791
+ * @override
1792
+ * @param {function(T, T): number= } compareFn A function that defines the sort
1793
+ * order.
1794
+ * @return {!Array<T> }
1795
+ * @this {!IArrayLike<T>}
1796
+ * @template VALUE
1797
+ * @nosideeffects
1798
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted
1799
+ */
1800
+ Array . prototype . toSorted = function ( compareFn ) { } ;
1801
+
1789
1802
/**
1790
1803
* NOTE: this is an ES2023 extern.
1791
1804
* @override
@@ -1932,6 +1945,18 @@ ReadonlyArray.prototype.flat = function(depth) {};
1932
1945
*/
1933
1946
ReadonlyArray . prototype . toReversed = function ( ) { } ;
1934
1947
1948
+ /**
1949
+ * NOTE: this is an ES2023 extern.
1950
+ * @param {function(T, T): number= } compareFn A function that defines the sort
1951
+ * order.
1952
+ * @return {!Array<T> }
1953
+ * @this {!IArrayLike<T>}
1954
+ * @template T
1955
+ * @nosideeffects
1956
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted
1957
+ */
1958
+ ReadonlyArray . prototype . toSorted = function ( compareFn ) { } ;
1959
+
1935
1960
/**
1936
1961
* NOTE: this is an ES2023 extern.
1937
1962
* @param {number } start
Original file line number Diff line number Diff line change 33
33
'require es6/array/keys' ;
34
34
'require es6/array/of' ;
35
35
'require es6/array/toreversed' ;
36
+ 'require es6/array/tosorted' ;
36
37
'require es6/array/tospliced' ;
37
38
'require es6/array/values' ;
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2025 The Closure Compiler Authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ 'require es6/array/from' ;
18
+ 'require util/polyfill' ;
19
+
20
+ $jscomp . polyfill ( 'Array.prototype.toSorted' , function ( orig ) {
21
+ if ( orig ) return orig ;
22
+
23
+ /**
24
+ * Returns a new array with all elements sorted.
25
+ *
26
+ * Note: This polyfill purposefully is NOT spec compliant in order to minimize
27
+ * code size. See skipped unit tests for specific gaps.
28
+ *
29
+ * @see https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.tosorted
30
+ *
31
+ * @param {function(T, T): number= } compareFn A function that defines the sort
32
+ * order.
33
+ * @return {!Array<T> }
34
+ * @this {!IArrayLike<T>}
35
+ * @template T
36
+ */
37
+ var polyfill = function ( compareFn ) {
38
+ return Array . from ( this ) . sort ( compareFn ) ;
39
+ } ;
40
+
41
+ return polyfill ;
42
+ } , 'es_next' , 'es3' ) ;
You can’t perform that action at this time.
0 commit comments