Array iterator's next() reads [[ArrayLikeNextIndex]] after reading length
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 58/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c, javascript
Direzione di ricerca
Start with js_array_iterator_next in quickjs.c, especially the js_get_length32 call and the later read of it->idx. Compare the order with the %ArrayIteratorPrototype%.next steps cited in the issue, then run the reproduction with qjs sample.js; done when it prints 0 0 and the iterator behavior matches the specified order.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Reproduction
// sample.js
var iterator;
var nested = false;
var nestedKey;
var arrayLike = {
get length() {
if (!nested) {
nested = true;
// nested next() while the outer next() is reading length
nestedKey = iterator.next().value;
}
return 2;
}
};
iterator = Array.prototype.keys.call(arrayLike);
var outerKey = iterator.next().value;
print(nestedKey + " " + outerKey);
Expected
V8 (16.0.102):
$ v8 sample.js
0 0
Actual (QuickJS-ng)
$ qjs sample.js
0 1
Spec
%ArrayIteratorPrototype%.next reads the iterator's index before it reads the length:
6. Let index be iteratorObj.[[ArrayLikeNextIndex]].
...
9.a. Let length be ? LengthOfArrayLike(array).
...
11. Set iteratorObj.[[ArrayLikeNextIndex]] to index + 1.
The outer iterator.next() stores [[ArrayLikeNextIndex]] (0) in index (step 6) and then reads length (step 9.a, through LengthOfArrayLike). The length getter calls iterator.next() once more. This nested call also stores 0 in its own index, returns 0, and sets [[ArrayLikeNextIndex]] to 1. When it returns, the outer call continues with the index it stored earlier, so it also returns 0.
QuickJS-ng reads [[ArrayLikeNextIndex]] after reading length, so the outer call sees the 1 written by the nested call and returns 1.
In js_array_iterator_next, QuickJS-ng gets the length with js_get_length32 first and reads it->idx after that:
if (js_get_length32(ctx, &len, it->obj)) {
...
}
...
idx = it->idx;
...
it->idx = idx + 1;
JavaScriptCore, SpiderMonkey and GraalJS agree with V8. XS has the same behavior (Moddable-OpenSource/moddable#1837).
Versions
- QuickJS-ng: 0.18.0
- V8: 16.0.102
- Lingua principale
- C
- Stelle
- 3.9k
- Fork
- 389
- Merge medio
- 2g 2h
- PR unite (30g)
- 19
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di quickjs-ng/quickjs
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
quickjs-ng/quickjs#1959 ·
I maintainer di solito rispondono entro 1 giorno
-
JS_SetPropertyInternal2 loses the value when a lazy property on the prototype runs out of memoryForse già presa @TheNetherWatcher l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
quickjs-ng/quickjs#1852 ·
I maintainer di solito rispondono entro 1 giorno
-
Object.prototype.propertyIsEnumerable converts `this` before the property keyForse già presa @SomSamantray l’ha presa 48 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
quickjs-ng/quickjs#1772 ·
I maintainer di solito rispondono entro 1 giorno
-
Slow compilation of large lexical scopesForse già presa @0x5457 l’ha presa 3 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
quickjs-ng/quickjs#1953 ·
I maintainer di solito rispondono entro 1 giorno
-
JS_ToCStringLen2 contract is documented wrongForse già presa @bnoordhuis l’ha presa 3 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
quickjs-ng/quickjs#1950 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di quickjs-ng/quickjs
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
libsndfile/libsndfile#1238 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
DaveGamble/cJSON#1143 ·
-
Claude:Bug GPT:Bug triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
open5gs/open5gs#5161 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni