Skip to content

Commit 49252e7

Browse files
committed
fix: simplify js.Global().Set usage and clean up code
1 parent 2df749d commit 49252e7

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

wasm/analyzer.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,15 @@ import (
1010

1111
func main() {
1212
c := make(chan struct{}, 0)
13-
defer close(c)
14-
15-
// Register function and ensure cleanup
16-
analyzeFunc := js.FuncOf(analyzeGoCode)
17-
defer analyzeFunc.Release()
18-
19-
js.Global().Set("analyzeGoCode", analyzeFunc)
13+
js.Global().Set("analyzeGoCode", js.FuncOf(analyzeGoCode))
2014
<-c
2115
}
2216

2317
func analyzeGoCode(this js.Value, args []js.Value) (result interface{}) {
2418
// Recover from panics
2519
defer func() {
2620
if r := recover(); r != nil {
27-
result = wrap("Internal error: " + fmt.Sprint(r), nil)
21+
result = wrap("Internal error: "+fmt.Sprint(r), nil)
2822
}
2923
}()
3024

@@ -76,4 +70,4 @@ func wrap(err string, data interface{}) js.Value {
7670
result["data"] = data
7771
}
7872
return js.ValueOf(result)
79-
}
73+
}

0 commit comments

Comments
 (0)