Repository navigation
Conversation
Member
Author
|
(Why do we even have this argument? What other way are you sorting the contents of a TypedArray?) |
|
The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/4043 and as multiple pages at https://tc39.es/ecma262/pr/4043/multipage . |
gibson042
approved these changes
Oct 30, 2026
nicolo-ribaudo
approved these changes
Oct 30, 2026
| <emu-clause id="sec-%typedarray%.prototype.sort" oldids="sec-typedarraysortcompare" type="built-in function"> | ||
| <h1>%TypedArray%.prototype.sort ( _comparator_ )</h1> | ||
| <p>This is a distinct method that, except as described below, implements the same requirements as those of `Array.prototype.sort` as defined in <emu-xref href="#sec-array.prototype.sort"></emu-xref>. The implementation of this method may be optimized with the knowledge that the *this* value is an object that has a fixed length and whose integer-indexed properties are not sparse.</p> | ||
| <p>This is a distinct method that, except as described below, implements the same requirements as those of `Array.prototype.sort` as defined in <emu-xref href="#sec-array.prototype.sort"></emu-xref>. The implementation of this method may be optimized with the knowledge that the *this* value is an object whose integer-indexed properties are not sparse. If _comparator_ is *undefined*, no user code is executed during this algorithm, and the TypedArray's length cannot decrease.</p> |
Member
There was a problem hiding this comment.
Suggested change
| <p>This is a distinct method that, except as described below, implements the same requirements as those of `Array.prototype.sort` as defined in <emu-xref href="#sec-array.prototype.sort"></emu-xref>. The implementation of this method may be optimized with the knowledge that the *this* value is an object whose integer-indexed properties are not sparse. If _comparator_ is *undefined*, no user code is executed during this algorithm, and the TypedArray's length cannot decrease.</p> | |
| <p>This is a distinct method that, except as described below, implements the same requirements as those of `Array.prototype.sort` as defined in <emu-xref href="#sec-array.prototype.sort"></emu-xref>. The implementation of this method may be optimized with the knowledge that the *this* value is an object whose integer-indexed properties are not sparse. If _comparator_ is *undefined*, no user code is executed by this algorithm, and the TypedArray's length cannot decrease.</p> |
Since user code from other threads could still mutate the array values if it's baked by a SharedArrayBuffer, right? (which is why you added that the length cannot decrease).
(Why do we even have this argument? What other way are you sorting the contents of a TypedArray?)
Clearly for people that prefer lexicographic order!
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This note became incorrect with the introduction of resizable ArrayBuffers, though arguably it was already incorrect given ArrayBuffer detaching. As reported in #4013 by @JinDX.
I think the "no user code" note is useful; the
UCannotation doesn't suffice because it will tell you that SortIndexedProperties can call user code - which it can, but only by calling the user-provided comparator. That really can change the length of the TA during execution although the algorithm mostly doesn't care (it does all the reads before calling the comparator, and the trailing writes just don't happen if the TA ends up too small for them).I'm open to dropping the "and the TypedArray's length cannot decrease" part since it's a little confusing in light of the up-front read.