Skip to content

Commit

Permalink
Normative: (Typed)?Array.prototype.sort: comparefn must be fn or un…
Browse files Browse the repository at this point in the history
…defined (#785)

* Normative: `Array.prototype.sort`: comparefn must be fn or undefined
This requires implementations throw a `TypeError` when the compare
function is neither undefined nor a function, which is currently vaguely
implied but not explicitly required.

This reflects web reality in that every engine except v8 already throws
in this case.

* Normative: `TypedArray.prototype.sort`: comparefn must be fn or undefined
This requires implementations throw a `TypeError` when the compare
function is neither undefined nor a function, which is currently vaguely
implied but not explicitly required.
  • Loading branch information
ljharb authored and bterlson committed Jun 12, 2017
1 parent 925cdc4 commit 564b30b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -31386,6 +31386,7 @@ <h1>Array.prototype.sort ( _comparefn_ )</h1>
<p>The elements of this array are sorted. The sort is not necessarily stable (that is, elements that compare equal do not necessarily 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_ &lt; _y_, zero if _x_ = _y_, or a positive value if _x_ &gt; _y_.</p>
<p>Upon entry, the following steps are performed to initialize evaluation of the `sort` function:</p>
<emu-alg>
1. 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 ? ToLength(? Get(_obj_, `"length"`)).
</emu-alg>
Expand Down Expand Up @@ -32670,6 +32671,7 @@ <h1>%TypedArray%.prototype.sort ( _comparefn_ )</h1>
<p>This function is not generic. The *this* value must be an object with a [[TypedArrayName]] internal slot.</p>
<p>Upon entry, the following steps are performed to initialize evaluation of the `sort` function. These steps are used instead of the entry steps in <emu-xref href="#sec-array.prototype.sort"></emu-xref>:</p>
<emu-alg>
1. If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception.
1. Let _obj_ be the *this* value.
1. Let _buffer_ be ? ValidateTypedArray(_obj_).
1. Let _len_ be _obj_.[[ArrayLength]].
Expand Down

0 comments on commit 564b30b

Please sign in to comment.