Skip to content

(1) class objects: foundation — class expressions allocate a heap class object with per-evaluation own static fields #1786

Description

@proggeramlug

Part of #1785. Design: #1772.

(1) Foundation — class objects + per-evaluation own static fields

Scope

Lower a class expression (HIR Expr::ClassExprFresh) to allocate a real heap class object: js_object_alloc(template_class_id, n) (so class_id = the compile-time template), set the per-evaluation named static fields as own properties (js_object_set_field_by_name) and symbol static fields (js_object_set_symbol_property), and yield the object POINTER as the class value. Top-level class declarations are unchanged (stay INT32(class_id)).

Acceptance criteria

  • function make(a){ return class { static x = a } }make(1) !== make(2) and make(1).x === 1, make(2).x === 2.
  • A no-this static method on such a class still dispatches and returns correctly (via class_id = template).
  • Top-level class declarations + existing class test suite unchanged (no regression).
  • cargo test (runtime/hir/codegen/transform) green; cargo fmt clean.

Status

WIP-complete on branch fix-1772-class-expr-identity (commits reworking Expr::ClassExprFresh lowering + the codegen in expr/static_field_meta.rs). Verified: distinct identity + distinct own static fields. Needs final cleanup (drop the dead integer-hack runtime helpers js_class_clone_for_expr + the CLASS_DYNAMIC_PROPS / symbol parent-walks added during the abandoned approach) and a node-validatable gap test before this lands as its own PR.

Blocks

(2), (3), (4), (5).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions