Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upArray#sort is underspecified #241
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ljharb
Dec 10, 2015
Member
(The TypeError in the spec is step 4a in http://www.ecma-international.org/ecma-262/6.0/#sec-sortcompare)
|
(The TypeError in the spec is step 4a in http://www.ecma-international.org/ecma-262/6.0/#sec-sortcompare) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bterlson
Dec 10, 2015
Member
I don't think there's a conflict here. For non-function, non-undefined comparefn's, the sort order is implementation defined but the result of the sort function is normatively defined in sec-sortcompare. Safari and Chrome are wrong per spec I believe.
|
I don't think there's a conflict here. For non-function, non-undefined comparefn's, the sort order is implementation defined but the result of the sort function is normatively defined in sec-sortcompare. Safari and Chrome are wrong per spec I believe. |
bterlson
closed this
Dec 10, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ljharb
Dec 10, 2015
Member
Thanks for clarifying! I'll add a patch to es5-shim and a test to the compat-table.
|
Thanks for clarifying! I'll add a patch to es5-shim and a test to the compat-table. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
If this isn't covered in test262 it should be :-P /cc @goyakin |
ljharb commentedDec 10, 2015
Reading http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.sort, I see that the spec says two conflicting things about the
compareFn.Namely,
[1, 2].sort(foo), for a non-undefined, non-function foo, both is implementation-defined, and throws a TypeError (the same language is in ES5).In Safari and Chrome (and IE < 9), a non-function non-undefined argument is ignored, and the default sort is used.
In Firefox, IE >= 9, and Edge, a non-function non-undefined argument throws a
TypeError, as I'd expect.This seems like something we should specify, and that Safari and Chrome should shift to the non-implementation-defined behavior of throwing for a non-function non-undefined argument. Thoughts?