Imports #
"internal/synctest"
"sync"
"runtime"
"unsafe"
"internal/synctest"
"sync"
"runtime"
"unsafe"
const TypeBooleanconst TypeFunctionconst TypeNullconst TypeNumberconst TypeObjectconst TypeStringconst TypeSymbolconst TypeUndefined Type = iotavar arrayConstructor = *ast.CallExprvar funcs = *ast.CallExprvar funcsMu sync.Mutexvar jsGo = *ast.CallExprnanHead 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 = 0x7FF80000var nextFuncID uint32 = 1var objectConstructor = *ast.CallExprconst typeFlagFunctionthe type flags need to be in sync with wasm_exec.js
const typeFlagNone = iotaconst typeFlagObjectconst typeFlagStringconst typeFlagSymbolvar valueFalse = *ast.CallExprvar valueGlobal = *ast.CallExprvar valueNaN = *ast.CallExprvar valueNull = *ast.CallExprvar valueTrue = *ast.CallExprvar valueUndefined = Value{...}var valueZero = *ast.CallExprType represents the JavaScript type of a Value.
type Type intref 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 uint64Error wraps a JavaScript error.
type Error struct {
Value
}Func is a wrapped Go function to be called by JavaScript.
type Func struct {
Value
bubble *synctest.Bubble
id uint32
}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
}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
}Bool returns the value v as a bool. It panics if v is not a JavaScript boolean.
func (v Value) Bool() boolCall 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) ValueCopyBytesToGo 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) intCopyBytesToJS 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) intDelete deletes the JavaScript property p of value v. It panics if v is not a JavaScript object.
func (v Value) Delete(p string)Equal reports whether v and w are equal according to JavaScript's === operator.
func (v Value) Equal(w Value) boolError implements the error interface.
func (e Error) Error() stringfunc (e *ValueError) Error() stringFloat returns the value v as a float64. It panics if v is not a JavaScript number.
func (v Value) Float() float64FuncOf 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) FuncGet returns the JavaScript property p of value v. It panics if v is not a JavaScript object.
func (v Value) Get(p string) ValueGlobal returns the JavaScript global object, usually "window" or "global".
func Global() ValueIndex returns JavaScript index i of value v. It panics if v is not a JavaScript object.
func (v Value) Index(i int) ValueInstanceOf reports whether v is an instance of type t according to JavaScript's instanceof operator.
func (v Value) InstanceOf(t Value) boolInt returns the value v truncated to an int. It panics if v is not a JavaScript number.
func (v Value) Int() intInvoke 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) ValueIsNaN reports whether v is the JavaScript value "NaN".
func (v Value) IsNaN() boolIsNull reports whether v is the JavaScript value "null".
func (v Value) IsNull() boolIsUndefined reports whether v is the JavaScript value "undefined".
func (v Value) IsUndefined() boolLength returns the JavaScript property "length" of v. It panics if v is not a JavaScript object.
func (v Value) Length() intNew 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) ValueNull returns the JavaScript value "null".
func Null() ValueRelease 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 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 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)func (t Type) String() stringString 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 "
func (v Value) String() stringTruthy 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() boolType 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() TypeUndefined returns the JavaScript value "undefined".
func Undefined() ValueValueOf 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) ValuecopyBytesToGo 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 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)go:wasmimport gojs syscall/js.finalizeRef
func finalizeRef(r ref)func (v Value) float(method string) float64func floatValue(f float64) ValuehandleEvent retrieves the pending event (window._pendingEvent) and calls the js.Func on it. It returns true if an event was handled.
func handleEvent() boolfunc init()func (v Value) isNumber() boolfunc (t Type) isObject() boolfunc jsString(v Value) stringmakeArgSlices 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)func makeValue(r ref) Valuefunc predefValue(id uint32, typeFlag byte) ValuesetEventHandler is defined in the runtime package.
func setEventHandler(fn func() bool)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 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) refvalueCall 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 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 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) refgo:wasmimport gojs syscall/js.valueIndex
func valueIndex(v ref, i int) refgo:wasmimport gojs syscall/js.valueInstanceOf
func valueInstanceOf(v ref, t ref) boolvalueInvoke 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)go:wasmimport gojs syscall/js.valueLength
func valueLength(v ref) intvalueLoadString 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 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)go:wasmimport gojs syscall/js.valuePrepareString
func valuePrepareString(v ref) (ref, int)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)go:wasmimport gojs syscall/js.valueSetIndex
func valueSetIndex(v ref, i int, x ref)Generated with Arrow