question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Array.prototype.sort` spec compliance

See original GitHub issue

The 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:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rhuanjlcommented, Oct 6, 2022

@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)

0reactions
rhuanjlcommented, Oct 5, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found