[P2] Compiler: Array prototype calls read arguments.length twice

Aperta
#3,533 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@nickna ci sta già lavorando.

Dal 7/11/2026.

  • #3510 di @nickna — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
csharp, typescript
Ambito
compilers

Direzione di ricerca

Start by reading the descriptor-aware compiled arguments work in pull request #3510 and compare its standalone assembly at 66d78c4ff with clean main at cabb41636. Trace the inline calls to Array.prototype.map, filter, flat, and toReversed, then run the supplied reproducer and the related compiler tests. Done means each method reads the live arguments length once while preserving its result length validation and element-read order.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The descriptor-aware compiled arguments work in #3510 introduced a second read of arguments.length in inline calls to Array.prototype.map, filter, flat, and toReversed. The precheck reads the length, then the arguments materializer reads it again. A getter can observe both reads and return different lengths.

function read(method) {
    function f(a, b) {
        const args = arguments;
        let count = 0;
        Object.defineProperty(args, "length", {
            get() { count++; return count === 1 ? 2 : 1; }
        });
        let result;
        if (method === "map") result = Array.prototype.map.call(args, value => value);
        if (method === "filter") result = Array.prototype.filter.call(args, value => true);
        if (method === "flat") result = Array.prototype.flat.call(args);
        if (method === "toReversed") result = Array.prototype.toReversed.call(args);
        console.log(method, count, result.join(","));
    }
    f(2, 1);
}
for (const method of ["map", "filter", "flat", "toReversed"]) read(method);

Node v22.23.2 reads the length once for each method. The outputs contain both entries (2,1 for map/filter/flat and 1,2 for toReversed). The verified standalone assembly on #3510 at 66d78c4ff reads it twice and uses the second length. Clean main at cabb41636 reads it once but falls back to backing storage, which separately loses descriptor-backed values.

Expected: use one live length read and preserve method-specific result length validation and element-read order. The distinct Array.prototype.with index validation and allocation failure is tracked in #3531.

Lingua principale
C#
Stelle
156
Fork
4
Merge medio
15h 49m
PR unite (30g)
42

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nickna/SharpTS

Tutte le issue di nickna/SharpTS

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.