Skip to content

[P2] Compiler: Array.prototype.some reads a visited indexed array getter twice #3524

Open

Description

@nickna

On clean main at cabb416, compiling Array.prototype.some.call against a real array reads each visited indexed getter twice.

const values = [1, 2];
const trace = [];
Object.defineProperty(values, "0", { get() { trace.push("get0"); return 1; } });
const result = Array.prototype.some.call(values, (value, index) => {
    trace.push("callback" + index);
    return value === 1;
});
console.log(result, trace.join(","));

Node v22.23.2 prints true get0,callback0. The compiled program passes full --verify and prints true get0,get0,callback0. Run as an unchecked classic .js program using --no-tsconfig --noLib.

The compiled loop reads the value while testing for a hole and again while preparing the callback arguments. This was independently reproduced while validating the #3510 review fix.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions