jsvm

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jsvm runs the scripts the tool ships, the mini-program and HarmonyOS runtimes', on moejs for their tests: a script's values, Go functions JS calls and JS functions Go calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertFunction

func AssertFunction(v Value) (func(this Value, args ...Value) (Value, error), bool)

AssertFunction returns v as a function Go calls.

Types

type FunctionCall

type FunctionCall struct{ Arguments []Value }

FunctionCall is a call of a Go function from JS.

func (FunctionCall) Argument

func (c FunctionCall) Argument(i int) Value

Argument returns argument i, undefined when missing.

type Runtime

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

Runtime is a realm whose builtins scripts may patch.

func New

func New() *Runtime

New returns a runtime.

func (*Runtime) ExportTo

func (vm *Runtime) ExportTo(v Value, target *func(string) string) error

ExportTo sets *target, a func(string) string, to call the JS function v.

func (*Runtime) Get

func (vm *Runtime) Get(name string) Value

Get returns the global name.

func (*Runtime) Global

func (vm *Runtime) Global() Value

Global is the global object.

func (*Runtime) NewObject

func (vm *Runtime) NewObject() Value

NewObject returns a new plain object.

func (*Runtime) RunString

func (vm *Runtime) RunString(src string) (Value, error)

RunString runs src as a script, returning its completion value.

func (*Runtime) Set

func (vm *Runtime) Set(name string, v any)

Set sets the global name to v, converted as ToValue does.

func (*Runtime) ToValue

func (vm *Runtime) ToValue(v any) Value

ToValue makes a JS value of a Go one: a Value as itself, a function as a JS function, a map's values converted in turn, and other values as moejs's FromGo converts them.

type Value

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

Value is a JavaScript value of a Runtime.

func Undefined

func Undefined() Value

Undefined is undefined.

func (Value) Export

func (v Value) Export() any

Export is v as moejs's ToGo gives it.

func (Value) Get

func (v Value) Get(name string) Value

Get returns the property name of an object, undefined for others.

func (Value) IsUndefined

func (v Value) IsUndefined() bool

IsUndefined reports whether v is undefined.

func (Value) Set

func (v Value) Set(name string, x any)

Set sets the property name of an object.

func (Value) String

func (v Value) String() string

String is v as String(v) gives it.

func (Value) ToBoolean

func (v Value) ToBoolean() bool

ToBoolean is v's truth.

func (Value) ToObject

func (v Value) ToObject(*Runtime) Value

ToObject returns v, which tests read as an object.

Jump to

Keyboard shortcuts

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