Skip to content

bug: built-in function .name own-property undefined (Promise.race.name, Math.min.name, Array.isArray.name) — follow-up to #2060 #2144

Closed

Description

@proggeramlug

Summary

A built-in function's name own-property is undefined. Promise.race.name, Math.min.name, etc. all return undefined where the spec requires the function's name. #2060 fixed .name for user-defined function declarations and expressions; it didn't populate .name for built-ins.

Repro

console.log(Promise.race.name);             // expect: "race"
console.log(Math.min.name);                 // expect: "min"
console.log(Array.isArray.name);            // expect: "isArray"
console.log(Object.getOwnPropertyDescriptor(Promise.race, "name"));
// expect: { value:"race", writable:false, enumerable:false, configurable:true }
function foo(){}; console.log(foo.name);    // control — #2060: "foo" ✓
Node v25 Perry
Promise.race.name / Math.min.name / Array.isArray.name "race" / "min" / "isArray" undefined
getOwnPropertyDescriptor(Promise.race, "name") data desc with value:"race" undefined
user function foo(){}; foo.name (control) "foo" "foo" ✓

Why it matters

built-ins/Function was 16% on the re-harvest, with 38× Cannot read … (reading 'name') — the dominant signature. Most of those trace to a separate gap (built-in proto methods being undefined, then .name of undefined throwing — tracked in the sibling issue filed alongside). Once that lands, the residual .name === undefined cases (tests that explicitly inspect a real built-in's name) all hit this gap. Also degrades assert.throws reporting, which prints expectedErrorConstructor.name for messages — any built-in Error constructor reports as undefined instead of TypeError / RangeError / etc.

Likely cause

Whatever populated name on user-defined function objects in #2060 needs to also run when the engine creates built-in function values (the per-intrinsic setup code for Promise.*, Math.*, Array.isArray, error constructors, etc.).

Surfaced by the #799 Test262 radar re-harvest. Follow-up to #2060. Part of #793.

Activity

  1. proggeramlug commented on May 28, 2026

    @proggeramlug
    ContributorAuthor

    Fixed by #2185 (merged as f3812fbc6 on 2026-05-28). The PR title referenced this issue but didn't include a closing keyword, so GitHub left it open.

    HIR-level constant fold added in lower/expr_member.rs + lower/expr_call/native_module.rs:

    • <BuiltinCtor>.name → Expr::String("<Ctor>")
    • <BuiltinNs>.<staticFn>.name → Expr::String("<fn>") (gated on a spec-defined function table — numeric constants like Math.PI.name stay unfolded, matching Node)
    • Object.getOwnPropertyDescriptor(<BuiltinFn>, "name") → spec-compliant data descriptor object literal

    Both fold sites gate on the lowered receiver matching GlobalGet(0) / PropertyGet { GlobalGet(0), … }, so a locally-shadowed const Math = … lowers to a LocalGet and correctly bypasses the fold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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