Array iterator's next() reads [[ArrayLikeNextIndex]] after reading length
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 58/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- c, javascript
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- C
- Estrellas
- 3.9k
- Forks
- 389
- Merge medio
- 2 d 2 h
- PR fusionados (30 d)
- 19
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de quickjs-ng/quickjs
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
quickjs-ng/quickjs#1959 ·
Los mantenedores suelen responder en 1 día
-
JS_SetPropertyInternal2 loses the value when a lazy property on the prototype runs out of memoryPosiblemente ocupada @TheNetherWatcher la tomó hace 6 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
quickjs-ng/quickjs#1852 ·
Los mantenedores suelen responder en 1 día
-
Object.prototype.propertyIsEnumerable converts `this` before the property keyPosiblemente ocupada @SomSamantray la tomó hace 48 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
quickjs-ng/quickjs#1772 ·
Los mantenedores suelen responder en 1 día
-
Slow compilation of large lexical scopesPosiblemente ocupada @0x5457 la tomó hace 3 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
quickjs-ng/quickjs#1953 ·
Los mantenedores suelen responder en 1 día
-
JS_ToCStringLen2 contract is documented wrongPosiblemente ocupada @bnoordhuis la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
quickjs-ng/quickjs#1950 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de quickjs-ng/quickjs
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 2 días
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
libsndfile/libsndfile#1238 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
DaveGamble/cJSON#1143 ·
-
Claude:Bug GPT:Bug triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
open5gs/open5gs#5161 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Cyberpunk not listed in readmeAbierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 2 días