Truly independent web browser
LibJS: Check the TDZ of a local that a for-in or for-of loop assigns
Shannon Booth2cef81607e57
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen.rs b/Libraries/LibJS/Rust/src/bytecode/codegen.rsindex 7e2f4326719..6ddee13a5bf 100644--- a/Libraries/LibJS/Rust/src/bytecode/codegen.rs+++ b/Libraries/LibJS/Rust/src/bytecode/codegen.rs@@ -5593,6 +5593,7 @@ fn emit_store_to_evaluated_reference(generator: &mut Generator, reference: &Evalfn emit_store_to_reference(generator: &mut Generator, target: &Expression, value: &ScopedOperand) {match &target.inner {ExpressionKind::Identifier(ident) => {+ emit_tdz_check_if_needed(generator, *ident);emit_set_variable(generator, *ident, value);}ExpressionKind::Member(data) => {diff --git a/Tests/LibJS/Runtime/loops/for-of-basic.js b/Tests/LibJS/Runtime/loops/for-of-basic.jsindex 33734f812ef..0d17ba958fa 100644--- a/Tests/LibJS/Runtime/loops/for-of-basic.js+++ b/Tests/LibJS/Runtime/loops/for-of-basic.js@@ -141,6 +141,25 @@ describe("special left hand sides", () => {expect("'use strict'; for (f() of []);").not.toEval();});+ test("variable in its temporal dead zone", () => {+ function assignLet() {+ for (value of [1]);+ let value;+ }+ function assignConst() {+ for (value of [1]);+ const value = 0;+ }+ function assignInForIn() {+ for (value in { key: 1 });+ let value;+ }++ expect(assignLet).toThrow(ReferenceError);+ expect(assignConst).toThrow(ReferenceError);+ expect(assignInForIn).toThrow(ReferenceError);+ });+test("Cannot change constant declaration in body", () => {const vals = [];for (const v of [1, 2]) {