Skip to content

Conversation

gibson042
Copy link
Member

Ref #4509

New ArrayBuffer.prototype properties

  • ArrayBuffer.prototype.transferToImmutable
    • verifyPrimordialCallableProperty(ArrayBuffer.prototype, "transferToImmutable", "transferToImmutable", 0);
    • brand-checking (throws TypeError unless receiver is an ArrayBuffer and not a SharedArrayBuffer), before coercing newLength
    • defaults newLength to [[ArrayBufferByteLength]]
    • if newLength is not undefined, casts it to an index (integral number from 0 to 2**53 - 1 inclusive) or throws a RangeError for out-of-range values, after brand-checking
    • throws TypeError if receiver is detached or immutable, after processing newLength (note the unusual receiver-after-argument order)
    • detaches the receiver
    • returns an immutable ArrayBuffer with the correct length
    • if newLength ≤ [[ArrayBufferByteLength]], returns an ArrayBuffer with contents matching the appropriate prefix of the receiver up to exclusive index newLength
    • if newLength > [[ArrayBufferByteLength]], returns an ArrayBuffer with contents matching those of the receiver, followed by the appropriate count of zeros

@gibson042 gibson042 requested a review from a team as a code owner July 18, 2025 22:28
@gibson042 gibson042 force-pushed the 2025-07-immutable-arraybuffer-transfertoimmutable branch from 397f433 to 1178b37 Compare July 31, 2025 16:32
@gibson042 gibson042 force-pushed the 2025-07-immutable-arraybuffer-transfertoimmutable branch 2 times, most recently from 54d4221 to 973e13e Compare August 1, 2025 01:24
Comment on lines +42 to +47
function repr(value) {
if (typeof value === "string") return JSON.stringify(value);
if (typeof value === "bigint") return String(value) + "n";
if (!value && 1/value === -Infinity) return "-0";
return String(value);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this belongs here

return String(value);
}

var goodLengths = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm willing to accept this test, but I think it would be nicer if we could have a generic helper function that runs through a set of interesting ToIndex arguments; this isn't the only API that could be tested in this way.

];

for (var i = 0; i < sourceMakers.length; i++) {
var name = sourceMakers[i].name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't take into account that sourceMakers[i] might be undefined.


for (var i = 0; i < sourceMakers.length; i++) {
var name = sourceMakers[i].name;
var newLength = byteLength + i + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calculating the argument based on the index in the array seems a recipe for confusion

];

for (var i = 0; i < sourceMakers.length; i++) {
var name = sourceMakers[i].name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment on lines +56 to +60
for (
var newLength = undefined;
(newLength || 0) < byteLength;
newLength = newLength === undefined ? 0 : newLength + 1
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very convoluted, probably too much so

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants