Skip to content

Commit

Permalink
Normative: Array.prototype.sort: comparefn must be fn or undefined
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ljharb committed Jan 25, 2017
1 parent c57ef95 commit 3f9dd80
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -30778,6 +30778,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

0 comments on commit 3f9dd80

Please sign in to comment.