go_wasm_exec

package
v0.0.0-...-3940e3f Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2021 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(def exec.ModuleDefinition)

func MainErr

func MainErr(def exec.ModuleDefinition) error

func Run

func Run(name string, def exec.ModuleDefinition, options *Options) error

Types

type ExitError

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

func (*ExitError) Code

func (e *ExitError) Code() int

func (*ExitError) Error

func (e *ExitError) Error() string

type Function

type Function interface {
	Object

	Invoke(args []Value) (Value, error)
	New(args []Value) (Value, error)
}
var ArrayClass Function = functionObject(newArray)
var ErrorClass Function = functionObject(newError)
var FunctionClass Function = functionObject(newFunction)
var ObjectClass Function = objectClass(0)
var StringClass Function = functionObject(newString)
var Uint8ArrayClass Function = functionObject(newUint8Array)

type Object

type Object interface {
	Class() Function
	Get(property string) Value
	Set(property string, value Value)
	Delete(property string)
	Index(i int) Value
	SetIndex(i int, value Value)
	Call(method string, args []Value) (Value, error)
	Length() int
}

func NewGlobal

func NewGlobal(fs Value) Object

func NewObject

func NewObject(class Function, properties map[string]Value) Object

type Options

type Options struct {
	Env  map[string]string
	Args []string

	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	FS     wasi.FS

	Global Object

	Debug    bool
	Trace    io.Writer
	Resolver exec.ModuleResolver
}

type Type

type Type int

Type represents the JavaScript type of a Value.

const (
	TypeUndefined Type = iota
	TypeNull
	TypeBoolean
	TypeNumber
	TypeString
	TypeSymbol
	TypeObject
	TypeFunction
)

func (Type) String

func (t Type) String() string

type Value

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

func NewFS

func NewFS(stdin, stdout, stderr wasi.File, fs wasi.FS) Value

func Null

func Null() Value

Null returns the JavaScript value "null".

func Undefined

func Undefined() Value

Undefined returns the JavaScript value "undefined".

func ValueOf

func ValueOf(x interface{}) Value

ValueOf returns x as a JavaScript value:

| Go                     | JavaScript             |
| ---------------------- | ---------------------- |
| js.Value               | [its value]            |
| js.Func                | function               |
| nil                    | null                   |
| bool                   | boolean                |
| integers and floats    | number                 |
| string                 | string                 |
| []interface{}          | new array              |
| map[string]interface{} | new object             |

Panics if x is not one of the expected types.

func (Value) Array

func (v Value) Array() ([]Value, bool)

func (Value) Bool

func (v Value) Bool() bool

Bool returns the value v as a bool. It panics if v is not a JavaScript boolean.

func (Value) Call

func (v Value) Call(method string, args []Value) (Value, error)

func (Value) Delete

func (v Value) Delete(property string)

func (Value) Equal

func (v Value) Equal(w Value) bool

Equal reports whether v and w are equal according to JavaScript's === operator.

func (Value) Float

func (v Value) Float() float64

Float returns the value v as a float64. It panics if v is not a JavaScript number.

func (Value) Function

func (v Value) Function() (Function, bool)

func (Value) Get

func (v Value) Get(property string) Value

func (Value) Index

func (v Value) Index(i int) Value

func (Value) Int

func (v Value) Int() int

Int returns the value v truncated to an int. It panics if v is not a JavaScript number.

func (Value) Invoke

func (v Value) Invoke(args []Value) (Value, error)

func (Value) IsInstance

func (v Value) IsInstance(class Value) bool

func (Value) IsNaN

func (v Value) IsNaN() bool

IsNaN reports whether v is the JavaScript value "NaN".

func (Value) IsNull

func (v Value) IsNull() bool

IsNull reports whether v is the JavaScript value "null".

func (Value) IsUndefined

func (v Value) IsUndefined() bool

IsUndefined reports whether v is the JavaScript value "undefined".

func (Value) Length

func (v Value) Length() int

func (Value) New

func (v Value) New(args []Value) (Value, error)

func (Value) Object

func (v Value) Object() (Object, bool)

func (Value) Set

func (v Value) Set(property string, value Value)

func (Value) SetIndex

func (v Value) SetIndex(i int, value Value)

func (Value) String

func (v Value) String() string

String returns the value v as a string. String is a special case because of Go's String method convention. Unlike the other getters, it does not panic if v's Type is not TypeString. Instead, it returns a string of the form "<T>" or "<T: V>" where T is v's type and V is a string representation of v's value.

func (Value) Truthy

func (v Value) Truthy() bool

Truthy returns the JavaScript "truthiness" of the value v. In JavaScript, false, 0, "", null, undefined, and NaN are "falsy", and everything else is "truthy". See https://developer.mozilla.org/en-US/docs/Glossary/Truthy.

func (Value) Type

func (v Value) Type() Type

Type returns the JavaScript type of the value v. It is similar to JavaScript's typeof operator, except that it returns TypeNull instead of TypeObject for null.

func (Value) Uint8Array

func (v Value) Uint8Array() ([]byte, bool)

Jump to

Keyboard shortcuts

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