Documentation ¶
Overview ¶
Package jsutil contains various utility functions for working with JavaScript and WebAssembly
Index ¶
- func AwaitPromise(promise js.Value) (result js.Value, err error)
- func AwaitPromiseContext(ctx context.Context, promise js.Value) (result js.Value, err error)
- func CopyBytesToGo(jsBytes js.Value) (bytes []byte, err error)
- func CopyBytesToJS(bytes []byte) (jsBytes js.Value, err error)
- func ErrorToJS(err error) js.Value
- func InefficientlyConvertFromJS(jsValue js.Value, value interface{}) (err error)
- func InefficientlyConvertToJS(value interface{}) (result js.Value, err error)
- func IsNullOrUndefined(value js.Value) bool
- func RecoverError(e interface{}) error
- func WrapInPromise(f func() (interface{}, error)) js.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AwaitPromise ¶
AwaitPromise accepts a js.Value representing a Promise. If the promise resolves, it returns (result, nil). If the promise rejects, it returns (js.Undefined, error). AwaitPromise has a synchronous-like API but does not block the JavaScript event loop.
func AwaitPromiseContext ¶
AwaitPromiseContext is like AwaitPromise but accepts a context. If the context is canceled or times out before the promise resolves, it will return (js.Undefined, ctx.Error).
func InefficientlyConvertFromJS ¶
InefficientlyConvertFromJS converts the given JS value to a Go value and sets it. This function is not very efficient and its use should be phased out over time as much as possible.
func InefficientlyConvertToJS ¶
InefficientlyConvertToJS converts the given Go value to a JS value by encoding to JSON and then decoding it. This function is not very efficient and its use should be phased out over time as much as possible.
func IsNullOrUndefined ¶
IsNullOrUndefined returns true if the given JavaScript value is either null or undefined.
func RecoverError ¶
func RecoverError(e interface{}) error
RecoverError allows a function to recover from a thrown Javascript error if called inside of a deferred function with a recover statement.
func WrapInPromise ¶
WrapInPromise converts a potentially blocking Go function to a non-blocking JavaScript Promise. If the function returns an error, the promise will reject with that error. Otherwise, the promise will resolve with the first return value.
Types ¶
This section is empty.