gojs

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrnoAcces Permission denied.
	ErrnoAcces = &Errno{"EACCES"}
	// ErrnoAgain Resource unavailable, or operation would block.
	ErrnoAgain = &Errno{"EAGAIN"}
	// ErrnoBadf Bad file descriptor.
	ErrnoBadf = &Errno{"EBADF"}
	// ErrnoExist File exists.
	ErrnoExist = &Errno{"EEXIST"}
	// ErrnoFault Bad address.
	ErrnoFault = &Errno{"EFAULT"}
	// ErrnoIntr Interrupted function.
	ErrnoIntr = &Errno{"EINTR"}
	// ErrnoInval Invalid argument.
	ErrnoInval = &Errno{"EINVAL"}
	// ErrnoIo I/O error.
	ErrnoIo = &Errno{"EIO"}
	// ErrnoIsdir Is a directory.
	ErrnoIsdir = &Errno{"EISDIR"}
	// ErrnoLoop Too many levels of symbolic links.
	ErrnoLoop = &Errno{"ELOOP"}
	// ErrnoNametoolong Filename too long.
	ErrnoNametoolong = &Errno{"ENAMETOOLONG"}
	// ErrnoNoent No such file or directory.
	ErrnoNoent = &Errno{"ENOENT"}
	// ErrnoNosys function not supported.
	ErrnoNosys = &Errno{"ENOSYS"}
	// ErrnoNotdir Not a directory or a symbolic link to a directory.
	ErrnoNotdir = &Errno{"ENOTDIR"}
	// ErrnoNotempty Directory not empty.
	ErrnoNotempty = &Errno{"ENOTEMPTY"}
	// ErrnoNotsup Not supported, or operation not supported on socket.
	ErrnoNotsup = &Errno{"ENOTSUP"}
	// ErrnoPerm Operation not permitted.
	ErrnoPerm = &Errno{"EPERM"}
	// ErrnoRofs read-only file system.
	ErrnoRofs = &Errno{"EROFS"}
)

This order match constants from wasi_snapshot_preview1.ErrnoSuccess for easier maintenance.

View Source
var ClearTimeoutEvent = goarch.NewFunc(custom.NameRuntimeClearTimeoutEvent, clearTimeoutEvent)

ClearTimeoutEvent implements runtime.clearTimeoutEvent which supports runtime.notetsleepg used by runtime.signal_recv.

See https://github.com/golang/go/blob/go1.20/src/runtime/sys_wasm.s#L129

View Source
var CopyBytesToGo = goos.NewFunc(custom.NameSyscallCopyBytesToGo, copyBytesToGo)

CopyBytesToGo copies a JavaScript managed byte array to linear memory. For example, this is used to read an HTTP response body.

Results

  • n is the count of bytes written.
  • ok is false if the src was not a uint8Array.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L569 and https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L437-L449

View Source
var CopyBytesToJS = goos.NewFunc(custom.NameSyscallCopyBytesToJS, copyBytesToJS)

CopyBytesToJS copies linear memory to a JavaScript managed byte array. For example, this is used to read an HTTP request body.

Results

  • n is the count of bytes written.
  • ok is false if the dst was not a uint8Array.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L583 and https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L438-L448

Debug has unknown use, so stubbed.

See https://github.com/golang/go/blob/go1.20/src/cmd/link/internal/wasm/asm.go#L131-L136

View Source
var FinalizeRef = goos.NewFunc(custom.NameSyscallFinalizeRef, finalizeRef)

FinalizeRef implements js.finalizeRef, which is used as a runtime.SetFinalizer on the given reference.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L61

View Source
var GetRandomData = goarch.NewFunc(custom.NameRuntimeGetRandomData, getRandomData)

GetRandomData implements runtime.getRandomData, which initializes the seed for runtime.fastrand.

See https://github.com/golang/go/blob/go1.20/src/runtime/sys_wasm.s#L133

View Source
var NaN = math.NaN()
View Source
var Nanotime1 = goarch.NewFunc(custom.NameRuntimeNanotime1, nanotime1)

Nanotime1 implements runtime.nanotime which supports time.Since.

See https://github.com/golang/go/blob/go1.20/src/runtime/sys_wasm.s#L117

View Source
var ResetMemoryDataView = goarch.NewFunc(custom.NameRuntimeResetMemoryDataView, resetMemoryDataView)

ResetMemoryDataView signals wasm.OpcodeMemoryGrow happened, indicating any cached view of memory should be reset.

See https://github.com/golang/go/blob/go1.20/src/runtime/mem_js.go#L82

View Source
var ScheduleTimeoutEvent = goarch.NewFunc(custom.NameRuntimeScheduleTimeoutEvent, scheduleTimeoutEvent)

ScheduleTimeoutEvent implements runtime.scheduleTimeoutEvent which supports runtime.notetsleepg used by runtime.signal_recv.

Unlike other most functions prefixed by "runtime.", this both launches a goroutine and invokes code compiled into wasm "resume".

See https://github.com/golang/go/blob/go1.20/src/runtime/sys_wasm.s#L125

View Source
var StringVal = goos.NewFunc(custom.NameSyscallStringVal, stringVal)

StringVal implements js.stringVal, which is used to load the string for `js.ValueOf(x)`. For example, this is used when setting HTTP headers.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L212 and https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L305-L308

View Source
var ValueCall = goos.NewFunc(custom.NameSyscallValueCall, valueCall)

ValueCall implements js.valueCall, which is used to call a js.Value function by name, e.g. `document.Call("createElement", "div")`.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L394 and https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L343-L358

ValueDelete is stubbed as it isn't used in Go's main source tree.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L321

View Source
var ValueGet = goos.NewFunc(custom.NameSyscallValueGet, valueGet)

ValueGet implements js.valueGet, which is used to load a js.Value property by name, e.g. `v.Get("address")`. Notably, this is used by js.handleEvent to get the pending event.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L295 and https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L311-L316

View Source
var ValueIndex = goos.NewFunc(custom.NameSyscallValueIndex, valueIndex)

ValueIndex implements js.valueIndex, which is used to load a js.Value property by index, e.g. `v.Index(0)`. Notably, this is used by js.handleEvent to read event arguments

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L334 and https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L331-L334

ValueInstanceOf is stubbed as it isn't used in Go's main source tree.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L543

ValueInvoke is stubbed as it isn't used in Go's main source tree.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L413

View Source
var ValueLength = goos.NewFunc(custom.NameSyscallValueLength, valueLength)

ValueLength implements js.valueLength, which is used to load the length property of a value, e.g. `array.length`.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L372 and https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L395-L398

View Source
var ValueLoadString = goos.NewFunc(custom.NameSyscallValueLoadString, valueLoadString)

ValueLoadString implements js.valueLoadString, which is used copy a string value for `o.String()`.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L533 and https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L409-L413

View Source
var ValueNew = goos.NewFunc(custom.NameSyscallValueNew, valueNew)

ValueNew implements js.valueNew, which is used to call a js.Value, e.g. `array.New(2)`.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L432 and https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L378-L392

View Source
var ValuePrepareString = goos.NewFunc(custom.NameSyscallValuePrepareString, valuePrepareString)

ValuePrepareString implements js.valuePrepareString, which is used to load the string for `o.String()` (via js.jsString) for string, boolean and number types. Notably, http.Transport uses this in RoundTrip to coerce the URL to a string.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L531 and https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L401-L406

View Source
var ValueSet = goos.NewFunc(custom.NameSyscallValueSet, valueSet)

ValueSet implements js.valueSet, which is used to store a js.Value property by name, e.g. `v.Set("address", a)`. Notably, this is used by js.handleEvent set the event result.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L309 and https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L318-L322

ValueSetIndex is stubbed as it is only used for js.ValueOf when the input is []interface{}, which doesn't appear to occur in Go's source tree.

See https://github.com/golang/go/blob/go1.20/src/syscall/js/js.go#L348

Walltime implements runtime.walltime which supports time.Now.

See https://github.com/golang/go/blob/go1.20/src/runtime/sys_wasm.s#L121

WasmExit implements runtime.wasmExit which supports runtime.exit.

See https://github.com/golang/go/blob/go1.20/src/runtime/sys_wasm.go#L24

View Source
var WasmWrite = goarch.NewFunc(custom.NameRuntimeWasmWrite, wasmWrite)

WasmWrite implements runtime.wasmWrite which supports runtime.write and runtime.writeErr. This implements `println`.

See https://github.com/golang/go/blob/go1.20/src/runtime/os_js.go#L30

Functions

func GetLastEventArgs

func GetLastEventArgs(ctx context.Context) []interface{}

GetLastEventArgs implements goos.GetLastEventArgs

func LoadValue

func LoadValue(ctx context.Context, ref goos.Ref) interface{}

LoadValue reads up to 8 bytes at the memory offset `addr` to return the value written by storeValue.

See https://github.com/golang/go/blob/go1.20/misc/wasm/wasm_exec.js#L122-L133

func WriteArgsAndEnviron

func WriteArgsAndEnviron(mod api.Module) (argc, argv uint32, err error)

WriteArgsAndEnviron writes arguments and environment variables to memory, so they can be read by main, Go compiles as the function export "run".

Types

type Errno

type Errno struct {
	// contains filtered or unexported fields
}

Errno is a (GOARCH=wasm) error, which must match a key in mapJSError.

See https://github.com/golang/go/blob/go1.20/src/syscall/tables_js.go#L371-L494

func ToErrno

func ToErrno(err error) *Errno

ToErrno maps I/O errors as the message must be the code, ex. "EINVAL", not the message, e.g. "invalid argument".

func (*Errno) Error

func (e *Errno) Error() string

Error implements error.

type State

type State struct {
	// contains filtered or unexported fields
}

State holds state used by the "go" imports used by gojs. Note: This is module-scoped.

func NewState

func NewState(config *config.Config) *State

func (*State) Get

func (s *State) Get(propertyKey string) interface{}

Get implements the same method as documented on goos.GetFunction

type StateKey

type StateKey struct{}

StateKey is a context.Context Value key. The value must be a state pointer.

Directories

Path Synopsis
Package config exists to avoid dependency cycles when keeping most of gojs code internal.
Package config exists to avoid dependency cycles when keeping most of gojs code internal.
Package custom is similar to the WebAssembly Custom Sections.
Package custom is similar to the WebAssembly Custom Sections.
Package goarch isolates code from runtime.GOARCH=wasm in a way that avoids cyclic dependencies when re-used from other packages.
Package goarch isolates code from runtime.GOARCH=wasm in a way that avoids cyclic dependencies when re-used from other packages.
Package goos isolates code from runtime.GOOS=js in a way that avoids cyclic dependencies when re-used from other packages.
Package goos isolates code from runtime.GOOS=js in a way that avoids cyclic dependencies when re-used from other packages.
Package run exists to avoid dependency cycles when keeping most of gojs code internal.
Package run exists to avoid dependency cycles when keeping most of gojs code internal.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL