New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.sort() sorted order invariant does not distinguish undefined and missing values #1271

Open
lukq opened this Issue Jul 22, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@lukq

lukq commented Jul 22, 2018

The Array.sort() method specification gives steps that should be taken

The following steps are taken:
Perform an implementation-dependent sequence of calls to the [[Get]] and [[Set]] internal methods of obj, to the DeletePropertyOrThrow and HasOwnProperty abstract operation with obj as the first argument, and to SortCompare (described below), such that:
...

The calls performed are implementation-dependent. Therefore, the next paragraph states what is the correctly sorted order.

There must be some mathematical permutation π of the nonnegative integers less than len, such that

  • for every nonnegative integer j less than len, if property old[j] existed, then new[π(j)] is exactly the same value as old[j]. But if property old[j] did not exist, then new[π(j)] does not exist.
  • Then for all nonnegative integers j and k, each less than len, if SortCompare(old[j], old[k]) < 0 (see SortCompare below), then new[π(j)] < new[π(k)].

Here, the second point does not distinguish values that are undefined and values that are missing from the array.

But the text phrasing in the part about the steps to be taken, and Note 1 in Runtime Semantics: SortCompare suggest that undefined values should be sorted before missing values. I suggest the sorted array invariant be rewritten to reflect this implicit requirement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment