serenity
serenity copied to clipboard
LibJS: `let` variables are not captured correctly
When a let
variable is captured by a function, it's value at the time it was captured should be used. Currently, Ladybird behaves as if a var
variable was being captured.
Example:
<!DOCTYPE html>
<script>
let result = "";
let functionList = [];
for (let i = 0; i < 9; i++) {
functionList.push(function() {
return i;
});
}
for (let i = 0; i < functionList.length; i++) {
result += functionList[i]();
}
// Output in Ladybird is: 999999999.
// Output should be: 012345678.
console.log(result);
</script>
I initially spotted this while working on #23544, looking at this WPT subtest.