Truly independent web browser
LibJS: Let an assignment to a class’s binding read the binding
sideshowbarker308b4f5e09e3
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rsindex 2136fe3b703..1036d2861f3 100644--- a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs@@ -104,6 +104,8 @@ pub struct Val {pub is_const: bool,/// A `var` binding, which is known to be initialized.pub is_var: bool,+ /// The binding of a declaration, which this write gives its first value. An assignment to a binding doesn't.+ pub initializes: bool,}impl Val {@@ -1057,6 +1059,7 @@ impl Generator<'_> {is_global: false,is_const: false,is_var: false,+ initializes: false,});}@@ -1395,7 +1398,7 @@ impl Generator<'_> {.stream.values.iter()- .any(|value| value.kind == ValKind::LocalTarget && value.a == local);+ .any(|value| value.kind == ValKind::LocalTarget && value.initializes && value.a == local);if is_being_initialized {let empty = self.context.constants.add_empty();self.put(op::Mov { dst: local, src: empty });@@ -1618,6 +1621,7 @@ impl Generator<'_> {is_global: false,is_const: false,is_var: false,+ initializes: false,});}@@ -1730,6 +1734,7 @@ impl Generator<'_> {is_global: false,is_const: false,is_var: false,+ initializes: false,});}@@ -1744,6 +1749,7 @@ impl Generator<'_> {is_global: false,is_const: false,is_var: false,+ initializes: false,});}@@ -2339,6 +2345,7 @@ impl Generator<'_> {is_global: false,is_const: false,is_var: false,+ initializes: false,});}@@ -2529,6 +2536,7 @@ impl Generator<'_> {is_global: false,is_const,is_var: false,+ initializes: false,});return;}@@ -2564,6 +2572,7 @@ impl Generator<'_> {is_global: ident.is_global,is_const,is_var: ident.declaration_kind == Some(DeclarationKind::Var),+ initializes: false,});}@@ -3590,6 +3599,7 @@ impl Generator<'_> {is_global: ident.is_global,is_const: false,is_var: false,+ initializes: true,});}diff --git a/Tests/LibJS/Runtime/regress/assignment-to-class-binding-reads-it.js b/Tests/LibJS/Runtime/regress/assignment-to-class-binding-reads-it.jsnew file mode 100644index 00000000000..d556ebae52e--- /dev/null+++ b/Tests/LibJS/Runtime/regress/assignment-to-class-binding-reads-it.js@@ -0,0 +1,55 @@+describe("an assignment to a class declaration's binding can read the binding", () => {+ test("in a function", () => {+ function f() {+ class C {}+ C = C;+ return typeof C;+ }+ expect(f()).toBe("function");+ });++ test("in a block", () => {+ function f() {+ {+ class C {}+ C = [C][0];+ return typeof C;+ }+ }+ expect(f()).toBe("function");+ });++ test("as a call argument", () => {+ function f() {+ class C {}+ C = ((c, d) => d)([], C);+ return C.name;+ }+ expect(f()).toBe("C");+ });++ test("in a compound assignment", () => {+ function f() {+ class C {}+ C += "";+ return typeof C;+ }+ expect(f()).toBe("string");+ });++ test("in a logical assignment", () => {+ function f() {+ class C {}+ C ??= 1;+ return typeof C;+ }+ expect(f()).toBe("function");+ });+});++test("a class declaration's binding is still in its dead zone before the declaration", () => {+ expect(() => {+ C = C;+ class C {}+ }).toThrowWithMessage(ReferenceError, "is not initialized");+});