package wazerotest
import "github.com/tetratelabs/wazero/experimental/wazerotest"
Index ¶
- Constants
- type Function
- func NewFunction(fn any) *Function
- func (f *Function) Call(ctx context.Context, params ...uint64) ([]uint64, error)
- func (f *Function) CallWithStack(ctx context.Context, stack []uint64) error
- func (f *Function) Definition() api.FunctionDefinition
- type Global
- func GlobalF32(value float32, export ...string) *Global
- func GlobalF64(value float64, export ...string) *Global
- func GlobalI32(value int32, export ...string) *Global
- func GlobalI64(value int64, export ...string) *Global
- func (g *Global) Get() uint64
- func (g *Global) String() string
- func (g *Global) Type() api.ValueType
- type Memory
- func NewFixedMemory(size int) *Memory
- func NewMemory(size int) *Memory
- func (m *Memory) Definition() api.MemoryDefinition
- func (m *Memory) Grow(deltaPages uint32) (previousPages uint32, ok bool)
- func (m *Memory) Pages() uint32
- func (m *Memory) Read(offset, length uint32) ([]byte, bool)
- func (m *Memory) ReadByte(offset uint32) (byte, bool)
- func (m *Memory) ReadFloat32Le(offset uint32) (float32, bool)
- func (m *Memory) ReadFloat64Le(offset uint32) (float64, bool)
- func (m *Memory) ReadUint16Le(offset uint32) (uint16, bool)
- func (m *Memory) ReadUint32Le(offset uint32) (uint32, bool)
- func (m *Memory) ReadUint64Le(offset uint32) (uint64, bool)
- func (m *Memory) Size() uint32
- func (m *Memory) Write(offset uint32, value []byte) bool
- func (m *Memory) WriteByte(offset uint32, value byte) bool
- func (m *Memory) WriteFloat32Le(offset uint32, value float32) bool
- func (m *Memory) WriteFloat64Le(offset uint32, value float64) bool
- func (m *Memory) WriteString(offset uint32, value string) bool
- func (m *Memory) WriteUint16Le(offset uint32, value uint16) bool
- func (m *Memory) WriteUint32Le(offset uint32, value uint32) bool
- func (m *Memory) WriteUint64Le(offset uint32, value uint64) bool
- type Module
- func NewModule(memory *Memory, functions ...*Function) *Module
- func (m *Module) Close(ctx context.Context) error
- func (m *Module) CloseWithExitCode(ctx context.Context, exitCode uint32) error
- func (m *Module) ExitStatus() (exitCode uint32, exited bool)
- func (m *Module) ExportedFunction(name string) api.Function
- func (m *Module) ExportedFunctionDefinitions() map[string]api.FunctionDefinition
- func (m *Module) ExportedGlobal(name string) api.Global
- func (m *Module) ExportedMemory(name string) api.Memory
- func (m *Module) ExportedMemoryDefinitions() map[string]api.MemoryDefinition
- func (m *Module) Function(i int) api.Function
- func (m *Module) Global(i int) api.Global
- func (m *Module) IsClosed() bool
- func (m *Module) Memory() api.Memory
- func (m *Module) Name() string
- func (m *Module) NumFunction() int
- func (m *Module) NumGlobal() int
- func (m *Module) String() string
Constants ¶
const PageSize = 65536
The PageSize constant defines the size of WebAssembly memory pages in bytes.
See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#page-size
Types ¶
type Function ¶
type Function struct { internalapi.WazeroOnlyType // GoModuleFunction may be set to a non-nil value to allow calling of the // function via Call or CallWithStack. // // It is the user's responsibility to ensure that the signature of this // implementation matches the ParamTypes and ResultTypes fields. GoModuleFunction api.GoModuleFunction // Type lists representing the function signature. Those fields should be // set for the function to be properly constructed. The Function's Call // and CallWithStack methods will error if those fields are nil. ParamTypes []api.ValueType ResultTypes []api.ValueType // Sets of names associated with the function. It is valid to leave those // names empty, they are only used for debugging purposes. FunctionName string DebugName string ParamNames []string ResultNames []string ExportNames []string // contains filtered or unexported fields }
Function is an implementation of the api.Function interface, it represents a function in a WebAssembly module.
Until accessed through a Module's method, the function definition's ModuleName method returns an empty string and its Index method returns 0.
func NewFunction ¶
NewFunction constructs a Function object from a Go function.
The function fn must accept at least two arguments of type context.Context and api.Module. Any other arguments and return values must be of type uint32, uint64, int32, int64, float32, or float64. The call panics if fn is not a Go functionn or has an unsupported signature.
func (*Function) Call ¶
func (*Function) CallWithStack ¶
func (*Function) Definition ¶
func (f *Function) Definition() api.FunctionDefinition
type Global ¶
type Global struct { internalapi.WazeroOnlyType // Type of the global value, used to interpret bits of the Value field. ValueType api.ValueType // Value of the global packed in a 64 bits field. Value uint64 // List of names that the globla is exported as. ExportNames []string }
Global is an implementation of the api.Global interface, it represents a global in a WebAssembly module.
func GlobalF32 ¶
func GlobalF64 ¶
func GlobalI32 ¶
func GlobalI64 ¶
func (*Global) Get ¶
func (*Global) String ¶
func (*Global) Type ¶
type Memory ¶
type Memory struct { internalapi.WazeroOnlyType // Byte slices holding the memory pages. // // It is the user's repsonsibility to ensure that the length of this byte // slice is a multiple of the page size. Bytes []byte // Min and max number of memory pages which may be held in this memory. // // Leaving Max to zero means no upper bound. Min uint32 Max uint32 // contains filtered or unexported fields }
Memory is an implementation of the api.Memory interface, representing the memory of a WebAssembly module.
func NewFixedMemory ¶
NewFixedMemory constructs a Memory object of the given size. The returned memory is configured with a max limit to prevent growing beyond its initial size.
func NewMemory ¶
NewMemory constructs a Memory object with a buffer of the given size, aligned to the closest multiple of the page size.
func (*Memory) Definition ¶
func (m *Memory) Definition() api.MemoryDefinition
func (*Memory) Grow ¶
func (*Memory) Pages ¶
func (*Memory) Read ¶
func (*Memory) ReadByte ¶
func (*Memory) ReadFloat32Le ¶
func (*Memory) ReadFloat64Le ¶
func (*Memory) ReadUint16Le ¶
func (*Memory) ReadUint32Le ¶
func (*Memory) ReadUint64Le ¶
func (*Memory) Size ¶
func (*Memory) Write ¶
func (*Memory) WriteByte ¶
func (*Memory) WriteFloat32Le ¶
func (*Memory) WriteFloat64Le ¶
func (*Memory) WriteString ¶
func (*Memory) WriteUint16Le ¶
func (*Memory) WriteUint32Le ¶
func (*Memory) WriteUint64Le ¶
type Module ¶
type Module struct { internalapi.WazeroOnlyType // The module name that will be returned by calling the Name method. ModuleName string // The list of functions of the module. Functions with a non-empty export // names will be exported by the module. Functions []*Function // The list of globals of the module. Global Globals []*Global // The program memory. If non-nil, the memory is automatically exported as // "memory". ExportMemory *Memory // contains filtered or unexported fields }
Module is an implementation of the api.Module interface, it represents a WebAssembly module.
func NewModule ¶
NewModule constructs a Module object with the given memory and function list.
func (*Module) Close ¶
Close implements the same method as documented on api.Closer.
func (*Module) CloseWithExitCode ¶
CloseWithExitCode implements the same method as documented on api.Closer.
func (*Module) ExitStatus ¶
func (*Module) ExportedFunction ¶
ExportedFunction implements the same method as documented on api.Module.
func (*Module) ExportedFunctionDefinitions ¶
func (m *Module) ExportedFunctionDefinitions() map[string]api.FunctionDefinition
ExportedFunctionDefinitions implements the same method as documented on api.Module.
func (*Module) ExportedGlobal ¶
ExportedGlobal implements the same method as documented on api.Module.
func (*Module) ExportedMemory ¶
ExportedMemory implements the same method as documented on api.Module.
func (*Module) ExportedMemoryDefinitions ¶
func (m *Module) ExportedMemoryDefinitions() map[string]api.MemoryDefinition
ExportedMemoryDefinitions implements the same method as documented on api.Module.
func (*Module) Function ¶
func (*Module) Global ¶
Global implements the same method as documented on experimental.InternalModule.
func (*Module) IsClosed ¶
IsClosed implements the same method as documented on api.Module.
func (*Module) Memory ¶
Memory implements the same method as documented on api.Module.
func (*Module) Name ¶
Name implements the same method as documented on api.Module.
func (*Module) NumFunction ¶
func (*Module) NumGlobal ¶
NumGlobal implements the same method as documented on experimental.InternalModule.
func (*Module) String ¶
String implements fmt.Stringer.
Source Files ¶
- Version
- v1.9.0 (latest)
- Published
- Feb 18, 2025
- Platform
- linux/amd64
- Imports
- 12 packages
- Last checked
- 4 days ago –
Tools for package owners.