Skip to content

Fix TypedArray.prototype.at() to handle resized ArrayBuffer correctly - #1718

Open
sr5434 wants to merge 1 commit into
quickjs-ng:masterfrom
sr5434:resizable_buffers_bug
Open

Fix TypedArray.prototype.at() to handle resized ArrayBuffer correctly#1718
sr5434 wants to merge 1 commit into
quickjs-ng:masterfrom
sr5434:resizable_buffers_bug

Conversation

@sr5434

@sr5434 sr5434 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

There is a bug where, when you expand a resizable array buffer backing a typed array, the at method reads from the newly allocated data rather than returning undefined. Below is a minimal reproducer I made:

const buffer = new ArrayBuffer(4 * Int8Array.BYTES_PER_ELEMENT, {maxByteLength: 8 * Int8Array.BYTES_PER_ELEMENT,});
const array = new Int8Array(buffer);
const index = {
    valueOf() {
        buffer.resize(6 * Int8Array.BYTES_PER_ELEMENT);
        return 4;
    },
};
array.at(index); // Node.JS gives undefined, but 0 is returned by QuickJS at master

I checked past PRs/issues, but all I could find was one about shrinking TypedArrays, while this one is about expanding them. I also added a test based on the minimal reproducer above.

@sr5434 sr5434 changed the title Fix TypedArray.prototype..at() to handle resized ArrayBuffer correctly Fix TypedArray.prototype.at() to handle resized ArrayBuffer correctly Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants