`break` or `return` inside `for ... in` leaves the enumeration on the stack
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
Start in crates/rascal/src/internal/as2_codegen/statement.rs, especially gen_for_loop and StatementKind::Return, then inspect how loop cleanup and return values are emitted. Reproduce the nested for ... in cases from the issue and check related code generation tests. Done means both break and return leave enumeration values cleaned up, so the outer loop prints x and y once each.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
for ... in keeps the enumerated names on the stack, terminated by null, and only consumes all of them when the loop runs to the end. Leaving the loop early with break or return jumps out without removing the rest. Any enclosing for ... in then picks up those leftover values: depending on what's left, it iterates over stale names, or it stops early on the inner loop's null. In the reproducers below, the outer loop gets b from every inner loop, so it never ends.
break:
var o = {a: 1, b: 2};
for (var k in {x: 1, y: 2}) {
trace(k);
for (var j in o) {
break;
}
}
return:
function first(o) {
for (var k in o) {
return k;
}
}
for (var k in {x: 1, y: 2}) {
trace(k);
first({a: 1, b: 2});
}
Expected for both: x and y, once each.
Actual, in Flash Player (Rascal 0.3.6, SWF 8), for both: x, then b repeated without end.
So the stack isn't reset when a function returns, which is why return is affected too.
gen_for_loop sets the break label to end_label, which is after the loop's cleanup.
https://github.com/Dinnerbone/Rascal/blob/3f1a80c85dcc657cf4a67b72754b9c7869a6d9c5/crates/rascal/src/internal/as2_codegen/statement.rs#L292-L302
StatementKind::Return emits Return directly. Before leaving a for ... in early, the remaining values need popping up to and including the null. Perhaps by emitting a small loop for that, similar to the loop header: Push null, Equals2, Not, If back to the start.
For a return from nested for ... in loops, each enclosing enumeration needs this, and the return value needs to be kept, for example in a register.
Real code hitting this: https://github.com/ruffle-rs/ruffle/blob/c7c2cc871c07d94f246d496e0b41479ba429085a/tests/tests/swfs/avm1/global_instance_decls/test.as#L46-L60
- Lenguaje dominante
- Rust
- Estrellas
- 22
- Forks
- 2
- Métricas de merge de PR
- Sin PR fusionados en 30 d
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 Dinnerbone/Rascal
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Dinnerbone/Rascal#92 · 1 comentario ·
-
`swf` upgrade to 0.4.0Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Dinnerbone/Rascal#91 · 2 reacciones ·
-
__bytecode__ support?Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
Dinnerbone/Rascal#88 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
Dinnerbone/Rascal#87 · 1 comentario ·
-
Cannot have comments in `@PCode`Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 58/100
Dinnerbone/Rascal#76 ·
Todos los issues de Dinnerbone/Rascal
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
rubys/roundhouse#1917 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
[cosmic-applet-battery] Division by zero displays NaN% when UPower reports max_brightness = 0Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
pop-os/cosmic-applets#1619 ·
Los mantenedores suelen responder en 3 días
-
binding:python bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día