wazerotest

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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

Variables

This section is empty.

Functions

This section is empty.

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

func NewFunction(fn any) *Function

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 (f *Function) Call(ctx context.Context, params ...uint64) ([]uint64, error)

func (*Function) CallWithStack

func (f *Function) CallWithStack(ctx context.Context, stack []uint64) error

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 GlobalF32(value float32, export ...string) *Global

func GlobalF64

func GlobalF64(value float64, export ...string) *Global

func GlobalI32

func GlobalI32(value int32, export ...string) *Global

func GlobalI64

func GlobalI64(value int64, export ...string) *Global

func (*Global) Get

func (g *Global) Get() uint64

func (*Global) String

func (g *Global) String() string

func (*Global) Type

func (g *Global) Type() api.ValueType

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

func NewFixedMemory(size int) *Memory

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

func NewMemory(size int) *Memory

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 (m *Memory) Grow(deltaPages uint32) (previousPages uint32, ok bool)

func (*Memory) Pages added in v1.7.1

func (m *Memory) Pages() uint32

func (*Memory) Read

func (m *Memory) Read(offset, length uint32) ([]byte, bool)

func (*Memory) ReadByte

func (m *Memory) ReadByte(offset uint32) (byte, bool)

func (*Memory) ReadFloat32Le

func (m *Memory) ReadFloat32Le(offset uint32) (float32, bool)

func (*Memory) ReadFloat64Le

func (m *Memory) ReadFloat64Le(offset uint32) (float64, bool)

func (*Memory) ReadUint16Le

func (m *Memory) ReadUint16Le(offset uint32) (uint16, bool)

func (*Memory) ReadUint32Le

func (m *Memory) ReadUint32Le(offset uint32) (uint32, bool)

func (*Memory) ReadUint64Le

func (m *Memory) ReadUint64Le(offset uint32) (uint64, bool)

func (*Memory) Size

func (m *Memory) Size() uint32

func (*Memory) Write

func (m *Memory) Write(offset uint32, value []byte) bool

func (*Memory) WriteByte

func (m *Memory) WriteByte(offset uint32, value byte) bool

func (*Memory) WriteFloat32Le

func (m *Memory) WriteFloat32Le(offset uint32, value float32) bool

func (*Memory) WriteFloat64Le

func (m *Memory) WriteFloat64Le(offset uint32, value float64) bool

func (*Memory) WriteString

func (m *Memory) WriteString(offset uint32, value string) bool

func (*Memory) WriteUint16Le

func (m *Memory) WriteUint16Le(offset uint32, value uint16) bool

func (*Memory) WriteUint32Le

func (m *Memory) WriteUint32Le(offset uint32, value uint32) bool

func (*Memory) WriteUint64Le

func (m *Memory) WriteUint64Le(offset uint32, value uint64) bool

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

func NewModule(memory *Memory, functions ...*Function) *Module

NewModule constructs a Module object with the given memory and function list.

func (*Module) Close

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

Close implements the same method as documented on api.Closer.

func (*Module) CloseWithExitCode

func (m *Module) CloseWithExitCode(ctx context.Context, exitCode uint32) error

CloseWithExitCode implements the same method as documented on api.Closer.

func (*Module) ExitStatus

func (m *Module) ExitStatus() (exitCode uint32, exited bool)

func (*Module) ExportedFunction

func (m *Module) ExportedFunction(name string) api.Function

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

func (m *Module) ExportedGlobal(name string) api.Global

ExportedGlobal implements the same method as documented on api.Module.

func (*Module) ExportedMemory

func (m *Module) ExportedMemory(name string) api.Memory

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 (m *Module) Function(i int) api.Function

func (*Module) Global

func (m *Module) Global(i int) api.Global

Global implements the same method as documented on experimental.InternalModule.

func (*Module) IsClosed added in v1.3.0

func (m *Module) IsClosed() bool

IsClosed implements the same method as documented on api.Module.

func (*Module) Memory

func (m *Module) Memory() api.Memory

Memory implements the same method as documented on api.Module.

func (*Module) Name

func (m *Module) Name() string

Name implements the same method as documented on api.Module.

func (*Module) NumFunction

func (m *Module) NumFunction() int

func (*Module) NumGlobal

func (m *Module) NumGlobal() int

NumGlobal implements the same method as documented on experimental.InternalModule.

func (*Module) String

func (m *Module) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

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