This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
normative: sync CompareTypedArrayElements with main spec #102
Merged
Conversation
This file contains 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
My understanding of the change is that even though the buffer is copied before we sort it, the previous check for So the normative change is: let detached = new WeakSet();
function detach(ab) {
if (detached.has(ab)) return;
if (ArrayBuffer.transfer) {
ArrayBuffer.transfer(ab); detached.add(ab);
} else if (ArrayBuffer.detach) {
ArrayBuffer.detach(ab); detached.add(ab);
} else if (typeof detachArrayBuffer === "function") {
detachArrayBuffer(ab); detached.add(ab);
} else if (typeof transferArrayBuffer === "function") {
transferArrayBuffer(ab); detached.add(ab);
} else if (typeof Worker === "function") {
try { eval("%ArrayBufferDetach(ab)") } catch (e) {
var w = new Worker('data:application/javascript,');
w.postMessage(ab, [ab]);
w.terminate();
}
detached.add(ab);
} else {
throw new TypeError("cannot detach array buffer");
}
}
let ta = new Uint32Array([4, 3, 2, 1]);
let compare = (a, b) => {
detach(ta.buffer);
return a - b;
};
// before:
ta.toSorted(compare); // TypeError
// after:
ta.toSorted(compare); // Uint32Array [1, 2, 3, 4] |
With @rricard 's help. Have checked Chrome Nightly and latest Safari. And both already implement this behavior, which is great. |
Additional bit of precision here: Safari Version 16.1 (17614.2.9.1.13, 17614) |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #100
Updates
sort
andtoSorted
on TypedArrays to match the new 262 behavior: tc39/ecma262#2723cc: @syg