goos

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: 7 Imported by: 0

Documentation

Overview

Package goos isolates code from runtime.GOOS=js in a way that avoids cyclic dependencies when re-used from other packages.

Index

Constants

View Source
const (
	IdValueNaN uint32 = iota
	IdValueZero
	IdValueNull
	IdValueTrue
	IdValueFalse
	IdValueGlobal
	IdJsGo

	IdObjectConstructor
	IdArrayConstructor
	IdJsProcess
	IdJsfs
	IdJsfsConstants
	IdUint8ArrayConstructor
	IdJsCrypto
	IdJsDateConstructor
	IdJsDate
	NextID
)
View Source
const (
	RefValueUndefined = Ref(0)
	RefValueNaN       = (NanHead|Ref(TypeFlagNone))<<32 | Ref(IdValueNaN)
	RefValueZero      = (NanHead|Ref(TypeFlagNone))<<32 | Ref(IdValueZero)
	RefValueNull      = (NanHead|Ref(TypeFlagNone))<<32 | Ref(IdValueNull)
	RefValueTrue      = (NanHead|Ref(TypeFlagNone))<<32 | Ref(IdValueTrue)
	RefValueFalse     = (NanHead|Ref(TypeFlagNone))<<32 | Ref(IdValueFalse)
	RefValueGlobal    = (NanHead|Ref(TypeFlagObject))<<32 | Ref(IdValueGlobal)
	RefJsGo           = (NanHead|Ref(TypeFlagObject))<<32 | Ref(IdJsGo)

	RefObjectConstructor     = (NanHead|Ref(TypeFlagFunction))<<32 | Ref(IdObjectConstructor)
	RefArrayConstructor      = (NanHead|Ref(TypeFlagFunction))<<32 | Ref(IdArrayConstructor)
	RefJsProcess             = (NanHead|Ref(TypeFlagObject))<<32 | Ref(IdJsProcess)
	RefJsfs                  = (NanHead|Ref(TypeFlagObject))<<32 | Ref(IdJsfs)
	RefJsfsConstants         = (NanHead|Ref(TypeFlagObject))<<32 | Ref(IdJsfsConstants)
	RefUint8ArrayConstructor = (NanHead|Ref(TypeFlagFunction))<<32 | Ref(IdUint8ArrayConstructor)
	RefJsCrypto              = (NanHead|Ref(TypeFlagFunction))<<32 | Ref(IdJsCrypto)
	RefJsDateConstructor     = (NanHead|Ref(TypeFlagFunction))<<32 | Ref(IdJsDateConstructor)
	RefJsDate                = (NanHead|Ref(TypeFlagObject))<<32 | Ref(IdJsDate)
)
View Source
const NanHead = 0x7FF80000

NanHead are the upper 32 bits of a Ref which are set if the value is not encoded as an IEEE 754 number (see above).

Variables

View Source
var Undefined = struct{ name string }{/* contains filtered or unexported fields */}

Functions

func NewFunc

func NewFunc(name string, goFunc Func) *wasm.HostFunc

func NewStack

func NewStack(name string, mem api.Memory, sp uint32) *stack

func ValueToInt32

func ValueToInt32(arg interface{}) int32

func ValueToUint32

func ValueToUint32(arg interface{}) uint32

Types

type ByteArray

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

ByteArray is a result of uint8ArrayConstructor which temporarily stores binary data outside linear memory.

Note: This is a wrapper because a slice is not hashable.

func WrapByteArray

func WrapByteArray(buf []byte) *ByteArray

func (*ByteArray) Get

func (a *ByteArray) Get(propertyKey string) interface{}

Get implements GetFunction

func (*ByteArray) Unwrap

func (a *ByteArray) Unwrap() []byte

Unwrap returns the underlying byte slice

type Func

type Func func(context.Context, api.Module, Stack)

type GetFunction

type GetFunction interface {
	Get(propertyKey string) interface{}
}

GetFunction allows getting a JavaScript property by name.

type GetLastEventArgs

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

GetLastEventArgs returns the arguments to the last event created by custom.NameSyscallValueCall.

type Ref

type Ref uint64

Ref is used to identify a JavaScript value, since the value itself cannot 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.

func ValueRef

func ValueRef(id uint32, typeFlag TypeFlag) Ref

func (Ref) ParseFloat

func (ref Ref) ParseFloat() (v float64, ok bool)

type Stack

type Stack interface {
	goarch.Stack

	ParamRef(i int) Ref

	ParamRefs(mem api.Memory, i int) []Ref

	ParamVal(ctx context.Context, i int, loader ValLoader) interface{}

	// ParamVals is used by functions whose final parameter is an arg array.
	ParamVals(ctx context.Context, mem api.Memory, i int, loader ValLoader) []interface{}

	SetResultRef(i int, v Ref)
}

type TypeFlag

type TypeFlag byte
const (
	TypeFlagNone TypeFlag = iota
	TypeFlagObject
	TypeFlagString
	TypeFlagSymbol //nolint
	TypeFlagFunction
)

the type flags need to be in sync with gojs.js

type ValLoader

type ValLoader func(context.Context, Ref) interface{}

Jump to

Keyboard shortcuts

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