Skip to content

new.target evaluates to NaN inside class constructor instead of the constructor reference #449

@proggeramlug

Description

@proggeramlug

Summary

Inside a class constructor, new.target returns the f64 NaN bit pattern instead of the constructor function reference. Surfaced by test-files/test_gap_class_advanced.ts. Reproduces on main (v0.5.503) and HEAD~5 (v0.5.498) — pre-existing.

Minimal repro

class MyConstructable {
  constructor() {
    console.log("new.target:", new.target?.name ?? "undefined");
  }
}
new MyConstructable();
Runtime Output
node --experimental-strip-types new.target: MyConstructable
perry new.target: NaN

Why this matters

new.target is the standard mechanism for:

  • Detecting whether a function was called via new vs. as a regular call
  • Distinguishing the most-derived constructor in a super() chain (essential for any class-factory or framework that does class.name-based registration)

NaN here is a leaked NaN-boxing tag value — new.target is being lowered to the literal IEEE-754 NaN bit pattern instead of the constructor's class metadata pointer. The fix probably lives near the meta-property lowering site that v0.5.502 touched for import.meta.

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