Documentation
¶
Overview ¶
Package js defines the JavaScript API TSX shares between Goja and the browser.
Index ¶
- func Caller(r *Runtime) (file string, line int, ok bool)
- func ChargeArray(r *Runtime, value Value) bool
- func IsNull(v Value) bool
- func IsUndefined(v Value) bool
- func SetAllocationHooks(r *Runtime, check func(int64), charge func(*byte, int64))
- func StringData(s Value) (*byte, int)
- func TrackCallers(*Runtime)
- type ArrayBuffer
- type AsyncContextTracker
- type Callable
- type Constructor
- type ConstructorCall
- type EngineProperties
- type Exception
- type FieldNameMapper
- type Flag
- type FunctionCall
- type InterruptedError
- type Object
- func (o *Object) ClassName() string
- func (o *Object) DefineAccessorProperty(name string, getter, setter Value, configurable, enumerable Flag) error
- func (o *Object) DefineDataProperty(name string, value Value, writable, configurable, enumerable Flag) error
- func (o *Object) DefineDataPropertySymbol(s *Symbol, value Value, writable, configurable, enumerable Flag) error
- func (o *Object) Export() any
- func (o *Object) ExportType() reflect.Type
- func (o *Object) Get(name string) Value
- func (o *Object) GetSymbol(s *Symbol) Value
- func (o *Object) Keys() []string
- func (o *Object) MarshalJSON() ([]byte, error)
- func (o *Object) Prototype() *Object
- func (o *Object) Set(name string, value any) error
- func (o *Object) SetPrototype(proto *Object) error
- func (o *Object) SetSymbol(s *Symbol, value any) error
- func (o *Object) StrictEquals(v Value) bool
- func (o *Object) String() string
- func (o *Object) ToBoolean() bool
- func (o *Object) ToFloat() float64
- func (o *Object) ToInteger() int64
- func (o *Object) ToNumber() Value
- func (o *Object) ToString() Value
- type Program
- type Promise
- type PromiseState
- type Runtime
- func (r *Runtime) ClearInterrupt()
- func (*Runtime) Close()
- func (r *Runtime) DrainPromiseJobs() error
- func (r *Runtime) ExportTo(v Value, target any) error
- func (r *Runtime) Get(name string) Value
- func (r *Runtime) GlobalObject() *Object
- func (r *Runtime) Interrupt(value any)
- func (r *Runtime) New(constructor Value, args ...Value) (*Object, error)
- func (r *Runtime) NewArray(items ...any) *Object
- func (r *Runtime) NewArrayBuffer(data []byte) ArrayBuffer
- func (r *Runtime) NewGoError(err error) *Object
- func (r *Runtime) NewObject() *Object
- func (r *Runtime) NewPromise() (*Promise, func(any) error, func(any) error)
- func (r *Runtime) NewTypeError(format string, args ...any) *Object
- func (r *Runtime) RunProgram(p *Program) (Value, error)
- func (r *Runtime) RunScript(name, source string) (Value, error)
- func (r *Runtime) RunString(source string) (Value, error)
- func (r *Runtime) Set(name string, value any) error
- func (r *Runtime) SetAsyncContextTracker(tracker AsyncContextTracker)
- func (r *Runtime) SetFieldNameMapper(mapper FieldNameMapper)
- func (r *Runtime) SetMaxCallStackSize(size int)
- func (r *Runtime) SetPromiseJobFilter(filter func(any) bool)
- func (r *Runtime) SetTimeSource(now func() time.Time)
- func (r *Runtime) ToObject(v Value) *Object
- func (r *Runtime) ToValue(value any) Value
- type StackOverflowError
- type String
- type Symbol
- func (s *Symbol) Export() any
- func (s *Symbol) ExportType() reflect.Type
- func (s *Symbol) StrictEquals(v Value) bool
- func (s *Symbol) String() string
- func (s *Symbol) ToBoolean() bool
- func (s *Symbol) ToFloat() float64
- func (s *Symbol) ToInteger() int64
- func (s *Symbol) ToNumber() Value
- func (s *Symbol) ToString() Value
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Caller ¶
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 ¶
ChargeArray accounts for storage a host wrapper checked before allocating.
func IsUndefined ¶
func SetAllocationHooks ¶
SetAllocationHooks installs the native sandbox's storage meter. Translate exceptions from callbacks just as native JavaScript functions do.
func StringData ¶
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 ¶
AsyncContextTracker captures and restores context around promise reactions.
type Constructor ¶
Constructor is a JS constructor as Go calls it with new.
func AssertConstructor ¶
func AssertConstructor(v Value) (Constructor, bool)
type ConstructorCall ¶
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.
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 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 FunctionCall ¶
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 ¶
Object has Goja's object identity and only the portable object methods.
func (*Object) DefineAccessorProperty ¶
func (*Object) DefineDataProperty ¶
func (*Object) DefineDataPropertySymbol ¶
func (*Object) ExportType ¶
func (*Object) MarshalJSON ¶
func (*Object) SetPrototype ¶
func (*Object) StrictEquals ¶
type Promise ¶
Promise and ArrayBuffer keep their native backing objects.
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 (*Runtime) ClearInterrupt ¶
func (r *Runtime) ClearInterrupt()
func (*Runtime) DrainPromiseJobs ¶
func (*Runtime) GlobalObject ¶
func (*Runtime) NewArrayBuffer ¶
func (r *Runtime) NewArrayBuffer(data []byte) ArrayBuffer
func (*Runtime) NewGoError ¶
func (*Runtime) NewPromise ¶
func (*Runtime) SetAsyncContextTracker ¶
func (r *Runtime) SetAsyncContextTracker(tracker AsyncContextTracker)
func (*Runtime) SetFieldNameMapper ¶
func (r *Runtime) SetFieldNameMapper(mapper FieldNameMapper)
func (*Runtime) SetMaxCallStackSize ¶
func (*Runtime) SetPromiseJobFilter ¶
func (*Runtime) SetTimeSource ¶
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 Symbol ¶
Symbol is a JavaScript symbol.
func (*Symbol) ExportType ¶
func (*Symbol) StrictEquals ¶
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.