Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Include original function names in the source map #1085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nevkontakte opened this issue Nov 11, 2021 · 0 comments · May be fixed by #1338
Open

Include original function names in the source map #1085

nevkontakte opened this issue Nov 11, 2021 · 0 comments · May be fixed by #1338

Comments

@nevkontakte
Copy link
Member

While GopherJS tends to name JS functions similar to the Go ones, the names in the stack trace don't match exactly, which tends to break code that expects particular formatting of the stack trace function names.

relevantCaller() in net/http package is the most recent example I came across:

// relevantCaller searches the call stack for the first function outside of net/http.
// The purpose of this function is to provide more helpful error messages.
func relevantCaller() runtime.Frame {
	pc := make([]uintptr, 16)
	n := runtime.Callers(1, pc)
	frames := runtime.CallersFrames(pc[:n])
	var frame runtime.Frame
	for {
		frame, more := frames.Next()
		if !strings.HasPrefix(frame.Function, "net/http.") {
			return frame
		}
		if !more {
			break
		}
	}
	return frame
}

There's also an obvious benefit to the debugging experience of being able to more easily identify functions in the call stack.

nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Jul 10, 2022
 - Avoid use of unsafe in TestNestedMethods and TestEmbeddedMethods.
 - Skip TestNotInHeapDeref and TestMethodCallValueCodePtr, which concern
   low-level GC and heap details, inapplicable to GopherJS.
 - Skip TestIssue50208 until generics are supported.
 - Add a hack into methodNameSkip() to make method names match what the
   tests expect. gopherjs#1085 would
   be a better long-term solution.
 - Stub out verifyNotInHeapPtr(), which is also not applicable to
   GopherJS.
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Jul 10, 2022
 - Avoid use of unsafe in TestNestedMethods and TestEmbeddedMethods.
 - Skip TestNotInHeapDeref and TestMethodCallValueCodePtr, which concern
   low-level GC and heap details, inapplicable to GopherJS.
 - Skip TestIssue50208 until generics are supported.
 - Add a hack into methodNameSkip() to make method names match what the
   tests expect. gopherjs#1085 would
   be a better long-term solution.
 - Stub out verifyNotInHeapPtr(), which is also not applicable to
   GopherJS.
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Aug 3, 2024
JS function names are subtly different from what vanilla Go may expect,
unless gopherjs#1085 is implemented.
It turns out that a combination of
d5771cc and 22c65b8
subtly changes how node outputs stack trace in a way that breaks my
workarounds in the reflect package.

Instead of further fumbling, I am going to disable the offending tests
temporarily, and I have a proper fix for gopherjs#1085 in the works, which will
allow us to re-enable them along with a few other tests.
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Aug 3, 2024
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.
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Aug 5, 2024
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.
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue May 9, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant