mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2025-03-10 17:29:10 +00:00
27 lines
508 B
Go
27 lines
508 B
Go
package safejs
|
|
|
|
import (
|
|
"github.com/hack-pad/safejs"
|
|
)
|
|
|
|
type Func safejs.Func
|
|
|
|
func FuncOf(fn func(this Value, args []Value) any) (Func, error) {
|
|
r, err := safejs.FuncOf(func(this safejs.Value, args []safejs.Value) any {
|
|
args2 := make([]Value, len(args))
|
|
for i, v := range args {
|
|
args2[i] = Value(v)
|
|
}
|
|
return fn(Value(this), []Value(args2))
|
|
})
|
|
return Func(r), err
|
|
}
|
|
|
|
func (f Func) Release() {
|
|
safejs.Func(f).Release()
|
|
}
|
|
|
|
func (f Func) Value() Value {
|
|
return Value(safejs.Func(f).Value())
|
|
}
|