Help us shape the future of Go! Take the 2026 Go Developer Survey

browser

package
v0.57.28 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package browser runs kernel guests on the browser's WebAssembly API.

A guest must be transformed with Binaryen's Asyncify pass (wasm-opt --asyncify). A WebAssembly import must return before the guest continues, but a host call compiled to TypeScript may need to await. The engine unwinds the guest's call stack into a buffer, awaits the call, and rewinds the guest to the same import. A copy of that buffer is a snapshot: rewinding from it again returns from the import a second time, as fork, setjmp and longjmp need.

GoScript replaces this package with its TypeScript implementation in the repository's gs directory. These declarations give the kernel the package's API to compile against; compiled by Go, the engine reports errUnsupported.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Function

type Function struct{}

Function is an exported guest function. Its calls suspend across asynchronous host calls.

func (*Function) Call

func (f *Function) Call(ctx context.Context, args ...uint64) ([]uint64, error)

Call invokes the function.

type Instance

type Instance struct{}

Instance is a WebAssembly.Instance.

func (*Instance) Close

func (i *Instance) Close(ctx context.Context) error

Close stops the instance.

func (*Instance) ExportedFunction

func (i *Instance) ExportedFunction(name string) engine.Function

ExportedFunction returns an exported function, or nil.

func (*Instance) ExportedGlobal

func (i *Instance) ExportedGlobal(name string) engine.Global

ExportedGlobal returns an exported global, or nil.

func (*Instance) Memory

func (i *Instance) Memory() engine.Memory

Memory returns the instance's linear memory.

type Module

type Module struct{}

Module is a compiled WebAssembly.Module.

func (*Module) Close

func (m *Module) Close(ctx context.Context) error

Close releases the compiled module.

func (*Module) Instantiate

func (m *Module) Instantiate(ctx context.Context, name string) (engine.Instance, error)

Instantiate creates an instance of the module named name.

type Runtime

type Runtime struct{}

Runtime compiles guests with WebAssembly.compile.

func New

func New() *Runtime

New creates a Runtime.

func (*Runtime) Close

func (r *Runtime) Close(ctx context.Context) error

Close releases the runtime.

func (*Runtime) Compile

func (r *Runtime) Compile(ctx context.Context, wasm []byte) (engine.Module, error)

Compile compiles a WebAssembly binary into a reusable module.

func (*Runtime) Define

func (r *Runtime) Define(ctx context.Context, module string, fns map[string]engine.HostFunction) error

Define provides fns to guests as the imports of module.

func (*Runtime) Snapshotter

func (r *Runtime) Snapshotter(ctx context.Context) engine.Snapshotter

Snapshotter returns the snapshotter of the host call running under ctx, or nil when its guest is not transformed with Asyncify.

Jump to

Keyboard shortcuts

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