diff --git a/spec.html b/spec.html index 72924233c9..9be698cac8 100644 --- a/spec.html +++ b/spec.html @@ -32488,78 +32488,54 @@

Array.prototype.some ( _callbackfn_ [ , _thisArg_ ] )

Array.prototype.sort ( _comparefn_ )

The elements of this array are sorted. The sort must be stable (that is, elements that compare equal must remain in their original order). If _comparefn_ is not *undefined*, it should be a function that accepts two arguments _x_ and _y_ and returns a negative value if _x_ < _y_, zero if _x_ = _y_, or a positive value if _x_ > _y_.

-

Upon entry, the following steps are performed to initialize evaluation of the `sort` function:

+

The following steps are taken:

- 1. If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception. + 1. [id="step-array-sort-comparefn"] If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception. 1. Let _obj_ be ? ToObject(*this* value). - 1. Let _len_ be ? LengthOfArrayLike(_obj_). - -

Within this specification of the `sort` method, an object, _obj_, is said to be sparse if the following algorithm returns *true*:

- - 1. For each integer _i_ in the range 0 ≤ _i_ < _len_, do - 1. Let _prop_ be ! ToString(𝔽(_i_)). - 1. Let _elem_ be _obj_.[[GetOwnProperty]](_prop_). - 1. If _elem_ is *undefined*, return *true*. - 1. Return *false*. + 1. [id="step-array-sort-len"] Let _len_ be ? LengthOfArrayLike(_obj_). + 1. Let _items_ be a new empty List. + 1. Let _k_ be 0. + 1. Repeat, while _k_ < _len_, + 1. Let _Pk_ be ! ToString(𝔽(_k_)). + 1. Let _kPresent_ be ? HasProperty(_obj_, _Pk_). + 1. If _kPresent_ is *true*, then + 1. Let _kValue_ be ? Get(_obj_, _Pk_). + 1. Append _kValue_ to _items_. + 1. Set _k_ to _k_ + 1. + 1. Let _itemCount_ be the number of elements in _items_. + 1. [id="step-array-sort"] Sort _items_ using an implementation-defined sequence of calls to SortCompare. If any such call returns an abrupt completion, stop before performing any further calls to SortCompare or steps in this algorithm and return that completion. + 1. Let _j_ be 0. + 1. Repeat, while _j_ < _itemCount_, + 1. Perform ? Set(_obj_, ! ToString(𝔽(_j_)), _items_[_j_], *true*). + 1. Set _j_ to _j_ + 1. + 1. Repeat, while _j_ < _len_, + 1. Perform ? DeletePropertyOrThrow(_obj_, ! ToString(𝔽(_j_))). + 1. Set _j_ to _j_ + 1. + 1. Return _obj_.

The sort order is the ordering, after completion of this function, of the integer-indexed property values of _obj_ whose integer indexes are less than _len_. The result of the `sort` function is then determined as follows:

-

If _comparefn_ is not *undefined* and is not a consistent comparison function for the elements of this array (see below), the sort order is implementation-defined. The sort order is also implementation-defined if _comparefn_ is *undefined* and SortCompare does not act as a consistent comparison function.

-

Let _proto_ be _obj_.[[GetPrototypeOf]](). If _proto_ is not *null* and there exists an integer _j_ such that all of the conditions below are satisfied then the sort order is implementation-defined:

- -

The sort order is also implementation-defined if _obj_ is sparse and any of the following conditions are true:

- -

The sort order is also implementation-defined if any of the following conditions are true:

+

The sort order is implementation-defined if any of the following conditions is true:

-

The following steps are taken:

- - 1. Perform an implementation-defined sequence of calls to the Get, Set, DeletePropertyOrThrow, and HasOwnProperty abstract operation with _obj_ as the first argument, and to SortCompare (described below), such that: - * The property key argument for each call to Get, Set, HasOwnProperty, or DeletePropertyOrThrow is the string representation of a non-negative integer less than _len_. - * The `Throw` argument for every call to Set is *true*. - * The arguments for calls to SortCompare are values returned by a previous call to the Get abstract operation, unless the properties accessed by those previous calls did not exist according to HasOwnProperty. If both prospective arguments to SortCompare correspond to non-existent properties, use *+0*𝔽 instead of calling SortCompare. If only the first prospective argument is non-existent, use *1*𝔽. If only the second prospective argument is non-existent, use *-1*𝔽. - * If _obj_ is not sparse then DeletePropertyOrThrow must not be called. - * If an abrupt completion is returned from any of these operations, it is immediately returned as the value of this function. - 1. Return _obj_. - -

Unless the sort order is specified above to be implementation-defined, the returned object must have the following two characteristics:

+

Unless the sort order is specified above to be implementation-defined, _items_ must satisfy all of the following conditions after executing step of the algorithm above:

-

Here the notation old[_j_] is used to refer to the hypothetical result of calling Get(_obj_, _j_) before this function is executed, and the notation new[_j_] to refer to the hypothetical result of calling Get(_obj_, _j_) after this function has been executed.

+

Here the notation old[_j_] is used to refer to _items_[_j_] before step is executed, and the notation new[_j_] to refer to _items_[_j_] after step has been executed.

A function _comparefn_ is a consistent comparison function for a set of values _S_ if all of the requirements below are met for all values _a_, _b_, and _c_ (possibly the same value) in the set _S_: The notation _a_ <CF _b_ means _comparefn_(_a_, _b_) < 0; _a_ =CF _b_ means _comparefn_(_a_, _b_) = 0 (of either sign); and _a_ >CF _b_ means _comparefn_(_a_, _b_) > 0.