aboutsummaryrefslogtreecommitdiff
path: root/src/syscall
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2024-11-21 17:32:22 -0800
committerGopher Robot <gobot@golang.org>2024-11-22 16:21:27 +0000
commita8eddaf758c15404acbfe61af0739b6d099f2067 (patch)
treeed4f927f4fd004287314429dd49ceb980a8cbff1 /src/syscall
parent00709919d09904b17cfe3bfeb35521cbd3fb04f8 (diff)
downloadgo-a8eddaf758c15404acbfe61af0739b6d099f2067.tar.xz
runtime, internal/synctest, syscall/js: keep bubble membership in syscalls
Propagate synctest bubble membership through syscall/js.Func functions. Avoids panics from cross-bubble channel operations in js syscalls. Fixes #70512 Change-Id: Idbd9f95da8bc4f055a635dfac041359f848dad1a Reviewed-on: https://go-review.googlesource.com/c/go/+/631055 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/syscall')
-rw-r--r--src/syscall/js/func.go27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/syscall/js/func.go b/src/syscall/js/func.go
index 53a4d79a95..23530170ff 100644
--- a/src/syscall/js/func.go
+++ b/src/syscall/js/func.go
@@ -6,7 +6,10 @@
package js
-import "sync"
+import (
+ "internal/synctest"
+ "sync"
+)
var (
funcsMu sync.Mutex
@@ -16,8 +19,9 @@ var (
// Func is a wrapped Go function to be called by JavaScript.
type Func struct {
- Value // the JavaScript function that invokes the Go function
- id uint32
+ Value // the JavaScript function that invokes the Go function
+ bubble *synctest.Bubble
+ id uint32
}
// FuncOf returns a function to be used by JavaScript.
@@ -42,11 +46,23 @@ func FuncOf(fn func(this Value, args []Value) any) Func {
funcsMu.Lock()
id := nextFuncID
nextFuncID++
+ bubble := synctest.Acquire()
+ if bubble != nil {
+ origFn := fn
+ fn = func(this Value, args []Value) any {
+ var r any
+ bubble.Run(func() {
+ r = origFn(this, args)
+ })
+ return r
+ }
+ }
funcs[id] = fn
funcsMu.Unlock()
return Func{
- id: id,
- Value: jsGo.Call("_makeFuncWrapper", id),
+ id: id,
+ bubble: bubble,
+ Value: jsGo.Call("_makeFuncWrapper", id),
}
}
@@ -54,6 +70,7 @@ func FuncOf(fn func(this Value, args []Value) any) Func {
// The function must not be invoked after calling Release.
// It is allowed to call Release while the function is still running.
func (c Func) Release() {
+ c.bubble.Release()
funcsMu.Lock()
delete(funcs, c.id)
funcsMu.Unlock()