`Array.prototype.sort` spec compliance
See original GitHub issueThe following poc outputs different results in CC and V8.
const array = [40, 30, 10];
array.sort((x, y) => { array[0] = -1; console.log(array); return x - y; });
console.log(array);
CC
-1,30,10
-1,-1,10
-1,-1,10
V8
[ -1, 30, 10 ]
[ -1, 30, 10 ]
[ 10, 30, 40 ]
That’s strange, as there’s a test case that enforces this behavior in CC: https://github.com/chakra-core/ChakraCore/blob/7bcdec7e4266f786e930f23a45976511733272c3/test/Array/array_sort.js#L209-L226
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Array.prototype.sort() - JavaScript - MDN Web Docs
Array.prototype.sort(). The sort() method sorts the elements of an array in place and returns the reference to the same array, now sorted.
Read more >Normative: A more precise Array.prototype.sort by ... - GitHub
The Array.prototype.sort procedure that this PR proposes, can be summarized as follows: Collect all existing, non- undefined values in the range of [0, ......
Read more >Using Array.prototype.sort.call to sort a HTMLCollection
Convert the NodeList to an array first: var elements = [].slice.call(table.tBodies[0].childNodes);. and then call sort normally: elements.sort(down);.
Read more >array.prototype.tosorted - npm
An ESnext spec-compliant Array.prototype.toSorted shim/polyfill/replacement that works as far down as ES3. This package implements the es-shim ...
Read more >Community Code Snippets - Three Methods to Sort an...
So here are three methods for sorting an object array! ... METHOD 1: Create a Script Include to contain a prototype sort function...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ShortDevelopment I’ve put up the PR, the substance of the change is just the array_prototype.js file, the larger diffs in the headers are generated by running the regenBytecode.py script. (They are a serialised form of the JS in array_prototype.js)
JavascriptArray::EntrySort is the old no longer used sort implementation, it is a fall back that is used if you disable the self-hosted javascript which can be done in Test/Debug builds with the runtime ch flag
-JsBuiltin-
.It is out of line with the specification on more points than the javascript implementation we’re using.