js

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 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 js defines the JavaScript API TSX shares between Goja and the browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Caller

func Caller(r *Runtime) (file string, line int, ok bool)

Caller is the line of JS code r runs now, through the source maps the code carries, as file and line; ok is false while r runs none.

func ChargeArray

func ChargeArray(r *Runtime, value Value) bool

ChargeArray accounts for storage a host wrapper checked before allocating.

func IsNull

func IsNull(v Value) bool

func IsUndefined

func IsUndefined(v Value) bool

func SetAllocationHooks

func SetAllocationHooks(r *Runtime, check func(int64), charge func(*byte, int64))

SetAllocationHooks installs the native sandbox's storage meter. Translate exceptions from callbacks just as native JavaScript functions do.

func StringData

func StringData(s Value) (*byte, int)

StringData is the memory goja keeps s, a string it made, in: where it starts and its size in bytes. goja keeps an ASCII string as a Go string, a byte a unit, and others as UTF-16 with a leading BOM, or, as JSON.stringify returns them, as a Go string it reads as UTF-16 once it needs to, keeping both, which starts where its record of the two does; a concatenation it has not read yet, which keeps its parts, and a value that is no string have none (nil).

func TrackCallers

func TrackCallers(*Runtime)

TrackCallers does nothing because goja provides the current call stack.

Types

type ArrayBuffer

type ArrayBuffer goja.ArrayBuffer

func (ArrayBuffer) Bytes

func (a ArrayBuffer) Bytes() []byte

type AsyncContextTracker

type AsyncContextTracker interface {
	Grab() any
	Resumed(any)
	Exited()
}

AsyncContextTracker captures and restores context around promise reactions.

type Callable

type Callable func(this Value, args ...Value) (Value, error)

Callable is a JS function as Go calls it.

func AssertFunction

func AssertFunction(v Value) (Callable, bool)

type Constructor

type Constructor func(newTarget *Object, args ...Value) (*Object, error)

Constructor is a JS constructor as Go calls it with new.

func AssertConstructor

func AssertConstructor(v Value) (Constructor, bool)

type ConstructorCall

type ConstructorCall struct {
	This      *Object
	Arguments []Value
	NewTarget *Object
}

ConstructorCall is a call of a Go constructor with new.

func (ConstructorCall) Argument

func (f ConstructorCall) Argument(i int) Value

Argument returns argument i, undefined when missing.

type EngineProperties

type EngineProperties struct {
	CanInterrupt         bool // The host can stop a running JS slice.
	ReactionsAfterCommit bool // Promise reactions run on a later page turn.
	HasNativeIntl        bool // Keep the engine's own internationalization APIs.
	SharesPageAuthority  bool // The realm can reach the containing page's APIs.
	CanLimitRegexps      bool // NSGo can bound the regular expression match time.
}

EngineProperties describes differences the TSX runtime relies on.

func Properties

func Properties() EngineProperties

Properties returns the properties of the engine selected for this build.

type Exception

type Exception goja.Exception

Exception is the value Goja threw, with its original stack and Go cause.

func (*Exception) Error

func (e *Exception) Error() string

func (*Exception) String

func (e *Exception) String() string

func (*Exception) Unwrap

func (e *Exception) Unwrap() error

func (*Exception) Value

func (e *Exception) Value() Value

type FieldNameMapper

type FieldNameMapper interface {
	FieldName(reflect.Type, reflect.StructField) string
	MethodName(reflect.Type, reflect.Method) string
}

FieldNameMapper names fields and methods when a Go value enters JS.

func UncapFieldNameMapper

func UncapFieldNameMapper() FieldNameMapper

UncapFieldNameMapper lowercases the first letter of Go fields and methods.

type Flag

type Flag int

Flag is a property attribute's setting.

const (
	FLAG_NOT_SET Flag = iota
	FLAG_FALSE
	FLAG_TRUE
)

type FunctionCall

type FunctionCall struct {
	This      Value
	Arguments []Value
}

FunctionCall is a call of a Go function from JS.

func (FunctionCall) Argument

func (f FunctionCall) Argument(i int) Value

Argument returns argument i, undefined when missing.

type InterruptedError

type InterruptedError goja.InterruptedError

InterruptedError and StackOverflowError stop a Goja call without exposing Goja's exception or stack-frame types.

func (*InterruptedError) CallError

func (e *InterruptedError) CallError() error

func (*InterruptedError) Error

func (e *InterruptedError) Error() string

func (*InterruptedError) String

func (e *InterruptedError) String() string

func (*InterruptedError) Unwrap

func (e *InterruptedError) Unwrap() error

type Object

type Object goja.Object

Object has Goja's object identity and only the portable object methods.

func (*Object) ClassName

func (o *Object) ClassName() string

func (*Object) DefineAccessorProperty

func (o *Object) DefineAccessorProperty(name string, getter, setter Value, configurable, enumerable Flag) error

func (*Object) DefineDataProperty

func (o *Object) DefineDataProperty(name string, value Value, writable, configurable, enumerable Flag) error

func (*Object) DefineDataPropertySymbol

func (o *Object) DefineDataPropertySymbol(s *Symbol, value Value, writable, configurable, enumerable Flag) error

func (*Object) Export

func (o *Object) Export() any

func (*Object) ExportType

func (o *Object) ExportType() reflect.Type

func (*Object) Get

func (o *Object) Get(name string) Value

func (*Object) GetSymbol

func (o *Object) GetSymbol(s *Symbol) Value

func (*Object) Keys

func (o *Object) Keys() []string

func (*Object) MarshalJSON

func (o *Object) MarshalJSON() ([]byte, error)

func (*Object) Prototype

func (o *Object) Prototype() *Object

func (*Object) Set

func (o *Object) Set(name string, value any) error

func (*Object) SetPrototype

func (o *Object) SetPrototype(proto *Object) error

func (*Object) SetSymbol

func (o *Object) SetSymbol(s *Symbol, value any) error

func (*Object) StrictEquals

func (o *Object) StrictEquals(v Value) bool

func (*Object) String

func (o *Object) String() string

func (*Object) ToBoolean

func (o *Object) ToBoolean() bool

func (*Object) ToFloat

func (o *Object) ToFloat() float64

func (*Object) ToInteger

func (o *Object) ToInteger() int64

func (*Object) ToNumber

func (o *Object) ToNumber() Value

func (*Object) ToString

func (o *Object) ToString() Value

type Program

type Program goja.Program

Program is a script compiled for RunProgram.

func MustCompile

func MustCompile(name, source string, strict bool) *Program

type Promise

type Promise goja.Promise

Promise and ArrayBuffer keep their native backing objects.

func (*Promise) Result

func (p *Promise) Result() Value

func (*Promise) State

func (p *Promise) State() PromiseState

type PromiseState

type PromiseState int

PromiseState is a promise's state.

const (
	PromiseStatePending PromiseState = iota
	PromiseStateFulfilled
	PromiseStateRejected
)

type Runtime

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

Runtime is a JavaScript realm backed by Goja.

func New

func New() *Runtime

func (*Runtime) ClearInterrupt

func (r *Runtime) ClearInterrupt()

func (*Runtime) Close

func (*Runtime) Close()

Close has no native resources to release on Goja.

func (*Runtime) DrainPromiseJobs

func (r *Runtime) DrainPromiseJobs() error

func (*Runtime) ExportTo

func (r *Runtime) ExportTo(v Value, target any) error

func (*Runtime) Get

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

func (*Runtime) GlobalObject

func (r *Runtime) GlobalObject() *Object

func (*Runtime) Interrupt

func (r *Runtime) Interrupt(value any)

func (*Runtime) New

func (r *Runtime) New(constructor Value, args ...Value) (*Object, error)

func (*Runtime) NewArray

func (r *Runtime) NewArray(items ...any) *Object

func (*Runtime) NewArrayBuffer

func (r *Runtime) NewArrayBuffer(data []byte) ArrayBuffer

func (*Runtime) NewGoError

func (r *Runtime) NewGoError(err error) *Object

func (*Runtime) NewObject

func (r *Runtime) NewObject() *Object

func (*Runtime) NewPromise

func (r *Runtime) NewPromise() (*Promise, func(any) error, func(any) error)

func (*Runtime) NewTypeError

func (r *Runtime) NewTypeError(format string, args ...any) *Object

func (*Runtime) RunProgram

func (r *Runtime) RunProgram(p *Program) (Value, error)

func (*Runtime) RunScript

func (r *Runtime) RunScript(name, source string) (Value, error)

func (*Runtime) RunString

func (r *Runtime) RunString(source string) (Value, error)

func (*Runtime) Set

func (r *Runtime) Set(name string, value any) error

func (*Runtime) SetAsyncContextTracker

func (r *Runtime) SetAsyncContextTracker(tracker AsyncContextTracker)

func (*Runtime) SetFieldNameMapper

func (r *Runtime) SetFieldNameMapper(mapper FieldNameMapper)

func (*Runtime) SetMaxCallStackSize

func (r *Runtime) SetMaxCallStackSize(size int)

func (*Runtime) SetPromiseJobFilter

func (r *Runtime) SetPromiseJobFilter(filter func(any) bool)

func (*Runtime) SetTimeSource

func (r *Runtime) SetTimeSource(now func() time.Time)

func (*Runtime) ToObject

func (r *Runtime) ToObject(v Value) *Object

ToObject boxes v using the realm's prototypes and returns objects unchanged.

func (*Runtime) ToValue

func (r *Runtime) ToValue(value any) Value

type StackOverflowError

type StackOverflowError goja.StackOverflowError

func (*StackOverflowError) Error

func (e *StackOverflowError) Error() string

func (*StackOverflowError) String

func (e *StackOverflowError) String() string

func (*StackOverflowError) Unwrap

func (e *StackOverflowError) Unwrap() error

type String

type String interface {
	Value
	Length() int
	CharAt(int) uint16
	Reader() io.RuneReader
}

String exposes the UTF-16 units counted by the Goja memory limiter.

type Symbol

type Symbol goja.Symbol

Symbol is a JavaScript symbol.

func NewSymbol

func NewSymbol(s string) *Symbol

func (*Symbol) Export

func (s *Symbol) Export() any

func (*Symbol) ExportType

func (s *Symbol) ExportType() reflect.Type

func (*Symbol) StrictEquals

func (s *Symbol) StrictEquals(v Value) bool

func (*Symbol) String

func (s *Symbol) String() string

func (*Symbol) ToBoolean

func (s *Symbol) ToBoolean() bool

func (*Symbol) ToFloat

func (s *Symbol) ToFloat() float64

func (*Symbol) ToInteger

func (s *Symbol) ToInteger() int64

func (*Symbol) ToNumber

func (s *Symbol) ToNumber() Value

func (*Symbol) ToString

func (s *Symbol) ToString() Value

type Value

type Value interface {
	Export() any
	ExportType() reflect.Type
	ToInteger() int64
	ToFloat() float64
	ToNumber() Value
	ToString() Value
	ToBoolean() bool
	String() string
	StrictEquals(Value) bool
}

Value is a JavaScript primitive or object. A nil Value denotes a missing property, distinct from the JavaScript values null and undefined.

func Null

func Null() Value

func Undefined

func Undefined() Value

Jump to

Keyboard shortcuts

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