Skip to content

util.getCallSites() drops functionName when a source map has no name entry #65104

Description

@privatenumber

Version

v24.15.0

Also reproduced on v23.6.0.

Platform

macOS 15.6 (Darwin 24.6.0), x86_64

Subsystem

util, source_map

What steps will reproduce the bug?

Create these two files in the same directory.

repro.js:

const{getCallSites}=require("node:util");function foo(){console.log(getCallSites(1,{sourceMap:!0})[0].functionName)}foo();
//# sourceMappingURL=repro.js.map

repro.js.map:

{
  "version": 3,
  "sources": ["original.js"],
  "sourcesContent": ["const { getCallSites } = require('node:util'); function foo() { console.log(getCallSites(1, { sourceMap: true })[0].functionName); } foo();"],
  "mappings": "AAAA,KAAM,CAAE,YAAa,EAAI,QAAQ,WAAW,EAAG,SAAS,KAAM,CAAE,QAAQ,IAAI,aAAa,EAAG,CAAE,UAAW,EAAK,CAAC,EAAE,CAAC,EAAE,YAAY,CAAG,CAAE,IAAI",
  "names": []
}

How often does it reproduce? Is there a required condition?

It reproduces every time on v23.6.0 and v24.15.0.

The source map must map the call-site location without providing a corresponding name entry. Source Map v3 permits an empty names array.

What is the expected behavior? Why is that the expected behavior?

The command should print:

foo

The generated V8 call site contains foo as its function name. Remapping its source location should preserve that name when the source map does not provide a replacement.

This is also consistent with Node.js's source-mapped stack trace formatter, which retains the generated function name when no mapped name exists.

What do you see instead?

The command prints an empty line because:

getCallSites(1, { sourceMap: true })[0].functionName === ''

Additional information

Running the same file without source-map remapping prints the expected name:

$ node repro.js
foo

reconstructCallSite() in lib/util.js currently assigns:

functionName: entry.name ?? ''

Consequently, an absent optional source-map name replaces the generated V8 function name with an empty string. It should instead fall back to the generated call site's functionName.

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