js

Imports

Imports #

"internal/synctest"
"sync"
"runtime"
"unsafe"

Constants & Variables

TypeBoolean const #

const TypeBoolean

TypeFunction const #

const TypeFunction

TypeNull const #

const TypeNull

TypeNumber const #

const TypeNumber

TypeObject const #

const TypeObject

TypeString const #

const TypeString

TypeSymbol const #

const TypeSymbol

TypeUndefined const #

const TypeUndefined Type = iota

arrayConstructor var #

var arrayConstructor = *ast.CallExpr

funcs var #

var funcs = *ast.CallExpr

funcsMu var #

var funcsMu sync.Mutex

jsGo var #

var jsGo = *ast.CallExpr

nanHead const #

nanHead are the upper 32 bits of a ref which are set if the value is not encoded as an IEEE 754 number (see above).

const nanHead = 0x7FF80000

nextFuncID var #

var nextFuncID uint32 = 1

objectConstructor var #

var objectConstructor = *ast.CallExpr

typeFlagFunction const #

const typeFlagFunction

typeFlagNone const #

the type flags need to be in sync with wasm_exec.js

const typeFlagNone = iota

typeFlagObject const #

const typeFlagObject

typeFlagString const #

const typeFlagString

typeFlagSymbol const #

const typeFlagSymbol

valueFalse var #

var valueFalse = *ast.CallExpr

valueGlobal var #

var valueGlobal = *ast.CallExpr

valueNaN var #

var valueNaN = *ast.CallExpr

valueNull var #

var valueNull = *ast.CallExpr

valueTrue var #

var valueTrue = *ast.CallExpr

valueUndefined var #

var valueUndefined = Value{...}

valueZero var #

var valueZero = *ast.CallExpr

Type Aliases

Type type #

Type represents the JavaScript type of a Value.

type Type int

ref type #

ref is used to identify a JavaScript value, since the value itself can not be passed to WebAssembly. The JavaScript value "undefined" is represented by the value 0. A JavaScript number (64-bit float, except 0 and NaN) is represented by its IEEE 754 binary representation. All other values are represented as an IEEE 754 binary representation of NaN with bits 0-31 used as an ID and bits 32-34 used to differentiate between string, symbol, function and object.

type ref uint64

Structs

Error struct #

Error wraps a JavaScript error.

type Error struct {
Value
}

Func struct #

Func is a wrapped Go function to be called by JavaScript.

type Func struct {
Value
bubble *synctest.Bubble
id uint32
}

Value struct #

Value represents a JavaScript value. The zero value is the JavaScript value "undefined". Values can be checked for equality with the Equal method.

type Value struct {
_ [0]func()
ref ref
gcPtr *ref
}

ValueError struct #

A ValueError occurs when a Value method is invoked on a Value that does not support it. Such cases are documented in the description of each method.

type ValueError struct {
Method string
Type Type
}

Functions

Bool method #

Bool returns the value v as a bool. It panics if v is not a JavaScript boolean.

func (v Value) Bool() bool

Call method #

Call does a JavaScript call to the method m of value v with the given arguments. It panics if v has no method m. The arguments get mapped to JavaScript values according to the ValueOf function.

func (v Value) Call(m string, args ...any) Value

CopyBytesToGo function #

CopyBytesToGo copies bytes from src to dst. It panics if src is not a Uint8Array or Uint8ClampedArray. It returns the number of bytes copied, which will be the minimum of the lengths of src and dst.

func CopyBytesToGo(dst []byte, src Value) int

CopyBytesToJS function #

CopyBytesToJS copies bytes from src to dst. It panics if dst is not a Uint8Array or Uint8ClampedArray. It returns the number of bytes copied, which will be the minimum of the lengths of src and dst.

func CopyBytesToJS(dst Value, src []byte) int

Delete method #

Delete deletes the JavaScript property p of value v. It panics if v is not a JavaScript object.

func (v Value) Delete(p string)

Equal method #

Equal reports whether v and w are equal according to JavaScript's === operator.

func (v Value) Equal(w Value) bool

Error method #

Error implements the error interface.

func (e Error) Error() string

Error method #

func (e *ValueError) Error() string

Float method #

Float returns the value v as a float64. It panics if v is not a JavaScript number.

func (v Value) Float() float64

FuncOf function #

FuncOf returns a function to be used by JavaScript. The Go function fn is called with the value of JavaScript's "this" keyword and the arguments of the invocation. The return value of the invocation is the result of the Go function mapped back to JavaScript according to ValueOf. Invoking the wrapped Go function from JavaScript will pause the event loop and spawn a new goroutine. Other wrapped functions which are triggered during a call from Go to JavaScript get executed on the same goroutine. As a consequence, if one wrapped function blocks, JavaScript's event loop is blocked until that function returns. Hence, calling any async JavaScript API, which requires the event loop, like fetch (http.Client), will cause an immediate deadlock. Therefore a blocking function should explicitly start a new goroutine. Func.Release must be called to free up resources when the function will not be invoked any more.

func FuncOf(fn func(this Value, args []Value) any) Func

Get method #

Get returns the JavaScript property p of value v. It panics if v is not a JavaScript object.

func (v Value) Get(p string) Value

Global function #

Global returns the JavaScript global object, usually "window" or "global".

func Global() Value

Index method #

Index returns JavaScript index i of value v. It panics if v is not a JavaScript object.

func (v Value) Index(i int) Value

InstanceOf method #

InstanceOf reports whether v is an instance of type t according to JavaScript's instanceof operator.

func (v Value) InstanceOf(t Value) bool

Int method #

Int returns the value v truncated to an int. It panics if v is not a JavaScript number.

func (v Value) Int() int

Invoke method #

Invoke does a JavaScript call of the value v with the given arguments. It panics if v is not a JavaScript function. The arguments get mapped to JavaScript values according to the ValueOf function.

func (v Value) Invoke(args ...any) Value

IsNaN method #

IsNaN reports whether v is the JavaScript value "NaN".

func (v Value) IsNaN() bool

IsNull method #

IsNull reports whether v is the JavaScript value "null".

func (v Value) IsNull() bool

IsUndefined method #

IsUndefined reports whether v is the JavaScript value "undefined".

func (v Value) IsUndefined() bool

Length method #

Length returns the JavaScript property "length" of v. It panics if v is not a JavaScript object.

func (v Value) Length() int

New method #

New uses JavaScript's "new" operator with value v as constructor and the given arguments. It panics if v is not a JavaScript function. The arguments get mapped to JavaScript values according to the ValueOf function.

func (v Value) New(args ...any) Value

Null function #

Null returns the JavaScript value "null".

func Null() Value

Release method #

Release frees up resources allocated for the function. 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()

Set method #

Set sets the JavaScript property p of value v to ValueOf(x). It panics if v is not a JavaScript object.

func (v Value) Set(p string, x any)

SetIndex method #

SetIndex sets the JavaScript index i of value v to ValueOf(x). It panics if v is not a JavaScript object.

func (v Value) SetIndex(i int, x any)

String method #

func (t Type) String() string

String method #

String returns the value v as a string. String is a special case because of Go's String method convention. Unlike the other getters, it does not panic if v's Type is not TypeString. Instead, it returns a string of the form "" or "" where T is v's type and V is a string representation of v's value.

func (v Value) String() string

Truthy method #

Truthy returns the JavaScript "truthiness" of the value v. In JavaScript, false, 0, "", null, undefined, and NaN are "falsy", and everything else is "truthy". See https://developer.mozilla.org/en-US/docs/Glossary/Truthy.

func (v Value) Truthy() bool

Type method #

Type returns the JavaScript type of the value v. It is similar to JavaScript's typeof operator, except that it returns TypeNull instead of TypeObject for null.

func (v Value) Type() Type

Undefined function #

Undefined returns the JavaScript value "undefined".

func Undefined() Value

ValueOf function #

ValueOf returns x as a JavaScript value: | Go | JavaScript | | ---------------------- | ---------------------- | | js.Value | [its value] | | js.Func | function | | nil | null | | bool | boolean | | integers and floats | number | | string | string | | []interface{} | new array | | map[string]interface{} | new object | Panics if x is not one of the expected types.

func ValueOf(x any) Value

copyBytesToGo function #

copyBytesToGo copies bytes from src to dst. Using go:noescape is safe because the dst byte slice is only used as a dst copy buffer and no references to it are maintained. go:wasmimport gojs syscall/js.copyBytesToGo go:noescape

func copyBytesToGo(dst []byte, src ref) (int, bool)

copyBytesToJS function #

copyBytesToJS copies bytes from src to dst. Using go:noescape is safe because the src byte slice is only used as a src copy buffer and no references to it are maintained. go:wasmimport gojs syscall/js.copyBytesToJS go:noescape

func copyBytesToJS(dst ref, src []byte) (int, bool)

finalizeRef function #

go:wasmimport gojs syscall/js.finalizeRef

func finalizeRef(r ref)

float method #

func (v Value) float(method string) float64

floatValue function #

func floatValue(f float64) Value

handleEvent function #

handleEvent retrieves the pending event (window._pendingEvent) and calls the js.Func on it. It returns true if an event was handled.

func handleEvent() bool

init function #

func init()

isNumber method #

func (v Value) isNumber() bool

isObject method #

func (t Type) isObject() bool

jsString function #

func jsString(v Value) string

makeArgSlices function #

makeArgSlices makes two slices to hold JavaScript arg data. It can be paired with storeArgs to make-and-store JavaScript arg slices. However, the two functions are separated to ensure makeArgSlices is inlined which will prevent the slices from being heap allocated for small (<=16) numbers of args.

func makeArgSlices(size int) (argVals []Value, argRefs []ref)

makeValue function #

func makeValue(r ref) Value

predefValue function #

func predefValue(id uint32, typeFlag byte) Value

setEventHandler function #

setEventHandler is defined in the runtime package.

func setEventHandler(fn func() bool)

storeArgs function #

storeArgs maps input args onto respective Value and ref slices. It can be paired with makeArgSlices to make-and-store JavaScript arg slices.

func storeArgs(args []any, argValsDst []Value, argRefsDst []ref)

stringVal function #

stringVal copies string x to Javascript and returns a ref. Using go:noescape is safe because no references are maintained to the Go string x after the syscall returns. go:wasmimport gojs syscall/js.stringVal go:noescape

func stringVal(x string) ref

valueCall function #

valueCall does a JavaScript call to the method name m of ref v with the given arguments. Using go:noescape is safe because no references are maintained to the Go string m after the syscall returns. Additionally, the args slice is only used temporarily to collect the JavaScript objects for the JavaScript method invocation. go:wasmimport gojs syscall/js.valueCall go:nosplit go:noescape

func valueCall(v ref, m string, args []ref) (ref, bool)

valueDelete function #

valueDelete deletes the JavaScript property p of ref v. Using go:noescape is safe because no references are maintained to the Go string p after the syscall returns. go:wasmimport gojs syscall/js.valueDelete go:noescape

func valueDelete(v ref, p string)

valueGet function #

valueGet returns a ref to JavaScript property p of ref v. Using go:noescape is safe because no references are maintained to the Go string p after the syscall returns. go:wasmimport gojs syscall/js.valueGet go:noescape

func valueGet(v ref, p string) ref

valueIndex function #

go:wasmimport gojs syscall/js.valueIndex

func valueIndex(v ref, i int) ref

valueInstanceOf function #

go:wasmimport gojs syscall/js.valueInstanceOf

func valueInstanceOf(v ref, t ref) bool

valueInvoke function #

valueInvoke does a JavaScript call to value v with the given arguments. Using go:noescape is safe because the args slice is only used temporarily to collect the JavaScript objects for the JavaScript method invocation. go:wasmimport gojs syscall/js.valueInvoke go:noescape

func valueInvoke(v ref, args []ref) (ref, bool)

valueLength function #

go:wasmimport gojs syscall/js.valueLength

func valueLength(v ref) int

valueLoadString function #

valueLoadString loads string data located at ref v into byte slice b. Using go:noescape is safe because the byte slice is only used as a destination for storing the string data and references to it are not maintained. go:wasmimport gojs syscall/js.valueLoadString go:noescape

func valueLoadString(v ref, b []byte)

valueNew function #

valueNew uses JavaScript's "new" operator with value v as a constructor and the given arguments. Using go:noescape is safe because the args slice is only used temporarily to collect the JavaScript objects for the constructor execution. go:wasmimport gojs syscall/js.valueNew go:noescape

func valueNew(v ref, args []ref) (ref, bool)

valuePrepareString function #

go:wasmimport gojs syscall/js.valuePrepareString

func valuePrepareString(v ref) (ref, int)

valueSet function #

valueSet sets property p of ref v to ref x. Using go:noescape is safe because no references are maintained to the Go string p after the syscall returns. go:wasmimport gojs syscall/js.valueSet go:noescape

func valueSet(v ref, p string, x ref)

valueSetIndex function #

go:wasmimport gojs syscall/js.valueSetIndex

func valueSetIndex(v ref, i int, x ref)

Generated with Arrow