Documentation ¶
Index ¶
- Variables
- func Expose(property string, x interface{})
- func FromJSValue(x js.Value, out interface{}) error
- func NewError(goErr error) js.Value
- func Ready()
- func ToJSValue(x interface{}) js.Value
- type Decoder
- type InvalidArrayError
- type InvalidFromJSValueError
- type InvalidTypeError
- type Object
- func (o Object) Delete(p string)
- func (o Object) Equal(v js.Value) bool
- func (o Object) Expect(expectedType js.Type, path ...string) (js.Value, error)
- func (o Object) Get(path ...string) (js.Value, error)
- func (o Object) Index(i int) js.Value
- func (o Object) InstanceOf(t js.Value) bool
- func (o Object) JSValue() js.Value
- func (o Object) Length() int
- func (o Object) Set(p string, x interface{})
- func (o Object) SetIndex(i int, x interface{})
- func (o Object) String() string
- type Promise
- type TypeMismatchError
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidArgumentType = errors.New("invalid argument passed into Go function")
ErrInvalidArgumentType is returned when a generated Go function wrapper receives invalid argument types from JS.
var ErrMultipleReturnValue = errors.New("a JS function can only return one value")
ErrMultipleReturnValue is an error where a JS function is attempted to be unmarshalled into a Go function with multiple return values.
Functions ¶
func Expose ¶
func Expose(property string, x interface{})
Expose exposes a copy of the provided value in JS.
func FromJSValue ¶
FromJSValue converts a given js.Value to the Go equivalent. The new value of 'out' is undefined if FromJSValue returns an error.
When a JS function is unmarshalled into a Go function with only one return value, the returned JS value is casted into the type of the return value. If the conversion fails, the function call panics.
When a JS function is unmarshalled into a Go function with two return values, the second one being error, the conversion error is returned instead.
func Ready ¶
func Ready()
Ready notifies the JS bridge that the WASM is ready. It should be called when every value and function is exposed.
func ToJSValue ¶
ToJSValue converts a given Go value into its equivalent JS form.
One special case is that complex numbers (complex64 and complex128) are converted into objects with a real and imag property holding a number each.
A function is converted into a JS function where the function returns an error if the provided arguments do not conform to the Go equivalent but otherwise calls the Go function.
The "this" argument of a function is always passed to the Go function if its first parameter is of type js.Value. Otherwise, it is simply ignored.
If the last return value of a function is an error, it will be thrown in JS if it's non-nil. If the function returns multiple non-error values, it is converted to an array when returning to JS.
It panics when a channel or a map with keys other than string and integers are passed in.
Types ¶
type Decoder ¶
Decoder is an interface which manually decodes js.Value on its own. It overrides in FromJSValue.
type InvalidArrayError ¶
InvalidArrayError is an error where the JS's array length do not match Go's array length.
type InvalidFromJSValueError ¶
InvalidFromJSValueError is an error where an invalid argument is passed to FromJSValue. The argument to Unmarshal must be a non-nil pointer.
func (InvalidFromJSValueError) Error ¶
func (e InvalidFromJSValueError) Error() string
Error implements error.
type InvalidTypeError ¶
InvalidTypeError is an error where the JS value cannot be unmarshalled into the provided Go type.
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object is a statically typed Object instance of js.Value. It should be instantiated with NewObject where it is checked for type instead of directly. Calling methods on a zero Object is undefined behaviour.
func Global ¶
func Global() Object
Global returns the global object as a Object. If the global object is not an object, it panics.
func NewObject ¶
NewObject instantiates a new Object with the provided js.Value. If the js.Value is not an Object, it returns a TypeMismatchError.
func (Object) Equal ¶
Equal checks if the object is equal to another value. It is equivalent to JS's === operator.
func (Object) Expect ¶
Expect is a helper function that calls Get and checks the type of the final result. It returns a TypeMismatchError if a non-object is encountered while descending the path or the final type does not match with the provided expected type.
func (Object) Get ¶
Get recursively gets the Object's properties, returning a TypeMismatchError if it encounters a non-object while descending through the object.
func (Object) InstanceOf ¶
InstanceOf implements the instanceof operator in JavaScript. If t is not a constructor, this function returns false.
type Promise ¶
type Promise struct {
Object
}
Promise is an instance of a JS promise. The zero value of this struct is not a valid Promise.
func NewPromise ¶
NewPromise returns a promise that is fulfilled or rejected when the provided handler returns. The handler is spawned in its own goroutine.
func PromiseAll ¶
PromiseAll creates a promise that is fulfilled when all the provided promises have been fulfilled. The promise is rejected when any of the promises provided rejects. It is implemented by calling Promise.all on JS.
func PromiseAllSettled ¶
PromiseAllSettled creates a promise that is fulfilled when all the provided promises have been fulfilled or rejected. It is implemented by calling Promise.allSettled on JS.
func PromiseAny ¶
PromiseAny creates a promise that is fulfilled when any of the provided promises have been fulfilled. The promise is rejected when all of the provided promises gets rejected. It is implemented by calling Promise.any on JS.
func PromiseRace ¶
PromiseRace creates a promise that is fulfilled or rejected when one of the provided promises fulfill or reject. It is implemented by calling Promise.race on JS.
type TypeMismatchError ¶
TypeMismatchError is returned when a function is called with a js.Value that has the incorrect type.
func (TypeMismatchError) Error ¶
func (e TypeMismatchError) Error() string