Skip to content

Conversation

@grantnelson-wf
Copy link
Collaborator

@grantnelson-wf grantnelson-wf commented Oct 15, 2025

This is a branch off of #1338 so that I could fix the merge conflicts I caused. I also discovered that the issue with Windows is that when I migrated the CircleCI over to GHA, I had copied over the environment variable assignment to disable source maps for Windows. I removed that.

The following is the summary from that PR originally written by @nevkontakte


Previously GopherJS only emitted mapping between original and generated source locations. With this change it also includes original function names, which fixes #1085.

Before:

$ go install github.com/gopherjs/gopherjs && gopherjs run -m main.go
    at Object.CL (/runtime/gopherjs__runtime.go:450:3)
    at AO (/runtime/debug/stack.go:24:4)
    at Object.AN (/runtime/debug/stack.go:16:3)
    at D (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:14:3)
    at E (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:18:3)
    at $init (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:17:7)
    at $goroutine (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.3435578257:7:1727)
    at $runScheduled (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.3435578257:7:2359)
    at $schedule (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.3435578257:7:2574)
    at $go (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.3435578257:7:2210)
...

After:

$ go install github.com/gopherjs/gopherjs && gopherjs run -m main.go
    at runtime.Stack (/runtime/gopherjs__runtime.go:450:3)
    at runtime/debug.Stack (/runtime/debug/stack.go:24:4)
    at runtime/debug.PrintStack (/runtime/debug/stack.go:16:3)
    at main.x (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:14:3)
    at main.main (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:18:3)
    at $init (/home/aleks/gopherjs/repro/048-sourcemaps/js/repro/048-sourcemaps/main.go:17:7)
    at $goroutine (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.2187228924:7:1727)
    at $runScheduled (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.2187228924:7:2359)
    at $schedule (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.2187228924:7:2574)
    at $go (/home/aleks/gopherjs/repro/048-sourcemaps/main.go.2187228924:7:2210)
...

While working on this, I moved sourcemap hinting logic into its own package and added some tests. The implementation could still use some improvements, but it should be a significant improvement in the majority of cases.

nevkontakte and others added 4 commits May 9, 2025 21:43
The main change in this commit is an ability to use identifier name
mapping, which we use to show original function names in the source map.

This addresses the long-standing gopherjs#1085,
where GopherJS call stacks were somewhat difficult to interpret due to
function name mangling, especially in minified form. Now we emit an
additional source map hit with the original function name, which Node is
able to pick up.

While at it, I moved source map hinting logic into its own package with
tests and added some documentation on how it works. Now it should be
easy to extend this mechanism for even richer source maps if we want to.
The tests that were previously failing should work again with the new
function name source maps. There are only two caveats at this point:

 - For some reasons a function that's currently executing deferrals
   doesn't map to its original name.
 - Synthetic names for literal functions differ in format slightly from
   vanilla Go, which still breaks the test in net/http. The difference
   is minor enough it's not forth fixing though.
@grantnelson-wf grantnelson-wf marked this pull request as ready for review October 16, 2025 19:46
Copy link
Member

@nevkontakte nevkontakte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@grantnelson-wf grantnelson-wf merged commit 1e789f1 into gopherjs:master Oct 20, 2025
10 checks passed
@grantnelson-wf grantnelson-wf deleted the gng8 branch October 20, 2025 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include original function names in the source map

2 participants