mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-07 16:28:38 +09:00
Issue #2551 - Initial attempt at toSorted implementation
This commit is contained in:
parent
bc0dbe9abb
commit
18c04a471d
3 changed files with 27 additions and 1 deletions
|
|
@ -253,6 +253,29 @@ function ArraySort(comparefn) {
|
|||
return MergeSort(O, len, comparefn);
|
||||
}
|
||||
|
||||
// ES2023 22.1.3.30 Array.prototype.toSorted ( comparefn )
|
||||
function ArrayToSorted(comparefn) {
|
||||
if (comparefn !== undefined) {
|
||||
if (!IsCallable(comparefn)) {
|
||||
ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, comparefn));
|
||||
}
|
||||
}
|
||||
|
||||
var O = ToObject(this);
|
||||
var len = ToLength(O.length);
|
||||
|
||||
var A = ArraySpeciesCreate(O, len);
|
||||
for (var k = 0; k < len; k++) {
|
||||
if (k in O)
|
||||
_DefineDataProperty(A, k, O[k]);
|
||||
else
|
||||
delete A[k];
|
||||
}
|
||||
|
||||
callFunction(std_Array_sort, A, comparefn);
|
||||
return A;
|
||||
}
|
||||
|
||||
/* ES5 15.4.4.18. */
|
||||
function ArrayForEach(callbackfn/*, thisArg*/) {
|
||||
/* Step 1. */
|
||||
|
|
|
|||
|
|
@ -3227,6 +3227,7 @@ static const JSFunctionSpec array_methods[] = {
|
|||
/* ES2023 proposals */
|
||||
JS_SELF_HOSTED_FN("findLast", "ArrayFindLast", 1,0),
|
||||
JS_SELF_HOSTED_FN("findLastIndex", "ArrayFindLastIndex", 1,0),
|
||||
JS_SELF_HOSTED_FN("toSorted", "ArrayToSorted", 1,0),
|
||||
|
||||
JS_FS_END
|
||||
};
|
||||
|
|
@ -3401,7 +3402,8 @@ array_proto_finish(JSContext* cx, JS::HandleObject ctor, JS::HandleObject proto)
|
|||
!DefineProperty(cx, unscopables, cx->names().flatMap, value) ||
|
||||
!DefineProperty(cx, unscopables, cx->names().includes, value) ||
|
||||
!DefineProperty(cx, unscopables, cx->names().keys, value) ||
|
||||
!DefineProperty(cx, unscopables, cx->names().values, value))
|
||||
!DefineProperty(cx, unscopables, cx->names().values, value) ||
|
||||
!DefineProperty(cx, unscopables, cx->names().toSorted, value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -429,6 +429,7 @@
|
|||
macro(toJSON, toJSON, "toJSON") \
|
||||
macro(toLocaleString, toLocaleString, "toLocaleString") \
|
||||
macro(toSource, toSource, "toSource") \
|
||||
macro(toSorted, toSorted, "toSorted") \
|
||||
macro(toString, toString, "toString") \
|
||||
macro(toUTCString, toUTCString, "toUTCString") \
|
||||
macro(true, true_, "true") \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue