Skip to content

Property access on a primitive number: .constructor returns undefined instead of Number #2138

@proggeramlug

Description

@proggeramlug

Summary

Property access on a primitive number with .constructor returns undefined instead of the Number builtin. Found while filing the regression test for #2128 (number-receiver property-get safety guard) — fixing the segfault revealed this latent gap: the new guard correctly returns undefined for unknown keys, but .constructor (and other inherited Number.prototype methods like .toFixed, .toString) on a primitive should auto-box to Number.prototype and resolve.

Repro

function asAny(v: number): any { return v; }
const n = asAny(1);
console.log(n.constructor === Number); // Perry: false   Node: true
console.log(typeof n.toFixed);           // Perry: undefined  Node: function (likely)

Notes

  • Pre-drizzle-orm update/delete/leftJoin SIGSEGV on sqlite (next #489 blocker after #2050) #2128 fix this path SIGSEGV'd; post-fix it correctly returns undefined, which is strictly better but still doesn't match Node.
  • Most code uses typeof x === "number" rather than x.constructor === Number, so this is low-impact, but date-fns / lodash-style runtime type discrimination via .constructor benefits from it.
  • A targeted fix would intercept b"constructor" (and well-known Number.prototype methods) for primitive-number receivers in js_object_get_field_by_name, returning the corresponding global or prototype-method value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingparityNode.js compatibility / parity gaps

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions