From 96cefda9b24f2c559492960ff79005704b941f46 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 25 Jan 2017 11:54:17 -0800 Subject: [PATCH 1/2] 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. --- spec.html | 1 + 1 file changed, 1 insertion(+) diff --git a/spec.html b/spec.html index 8d4e524afa..97fe37fde9 100644 --- a/spec.html +++ b/spec.html @@ -31386,6 +31386,7 @@

Array.prototype.sort ( _comparefn_ )

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_ < _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:

+ 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"`)). From f0ee1d278b175ebf39ddd0dc73035260840e9a31 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 10 Jun 2017 13:09:51 -0700 Subject: [PATCH 2/2] 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. --- spec.html | 1 + 1 file changed, 1 insertion(+) diff --git a/spec.html b/spec.html index 97fe37fde9..f72d87d247 100644 --- a/spec.html +++ b/spec.html @@ -32671,6 +32671,7 @@

%TypedArray%.prototype.sort ( _comparefn_ )

This function is not generic. The *this* value must be an object with a [[TypedArrayName]] internal slot.

Upon entry, the following steps are performed to initialize evaluation of the `sort` function. These steps are used instead of the entry steps in :

+ 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]].