mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-28 15:28:55 +00:00
This required 2 changes: 1. In the parser, create a new variable scope, so the variable is declared in it instead of the scope in which the 'for' is found. 2. On execute, push the variable into the newly created block. Existing code created an empty block (no variables, no arguments) which allows Interpreter::enter_scope() to skip the creation of a new environment, therefore when the variable initializer is executed, it sets the variable to the outer scope. By attaching the variable to the new block, the block gets a new environment. This is only needed for 'let' / 'const' declarations, since 'var' declarations are expected to leak. Fixes: #2103
22 lines
387 B
JavaScript
22 lines
387 B
JavaScript
load("test-common.js");
|
|
|
|
try {
|
|
for (var v = 5; false; );
|
|
assert(v == 5);
|
|
|
|
const options = {error: ReferenceError};
|
|
|
|
assertThrowsError(() => {
|
|
for (let l = 5; false; );
|
|
l;
|
|
}, options);
|
|
|
|
assertThrowsError(() => {
|
|
for (const c = 5; false; );
|
|
c;
|
|
}, options)
|
|
|
|
console.log("PASS");
|
|
} catch (e) {
|
|
console.log("FAIL: " + e);
|
|
}
|