Documentation
¶
Overview ¶
Package js defines the JavaScript API TSX shares between moejs and the browser.
Index ¶
- func AddCleanup[S any](o *Object, cleanup func(S), arg S)
- func Caller(r *Runtime) (file string, line int, ok bool)
- func IsNull(v Value) bool
- func IsUndefined(v Value) bool
- func IsolatedFrameAvailable() bool
- func SetMemoryLimit(r *Runtime, limit int64, onLimit func() error)
- 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 IsolatedChannel
- 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 (r *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) SetPromiseJobFilter(func(any) bool)
- func (r *Runtime) SetTimeSource(now func() time.Time)
- func (r *Runtime) ToObject(v Value) *Object
- func (r *Runtime) ToValue(i any) Value
- type StackOverflowError
- 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
- type WeakObject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCleanup ¶
AddCleanup runs cleanup with arg once o is collected.
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 IsUndefined ¶
func IsolatedFrameAvailable ¶
func IsolatedFrameAvailable() bool
IsolatedFrameAvailable reports whether this host can create an opaque-origin sandboxed DOM iframe with MessageChannel.
func SetMemoryLimit ¶
SetMemoryLimit stops the realm's calls once its JavaScript keeps and allocates more than limit bytes beyond what the realm keeps now: they fail with an *InterruptedError of what onLimit returns. A limit of zero or less removes it.
func TrackCallers ¶
func TrackCallers(*Runtime)
TrackCallers does nothing: the engine captures the current call stack.
Types ¶
type ArrayBuffer ¶
type ArrayBuffer struct {
// contains filtered or unexported fields
}
ArrayBuffer is a JS ArrayBuffer, or the bytes Go gives one.
func (ArrayBuffer) Bytes ¶
func (a ArrayBuffer) Bytes() []byte
Bytes are the buffer's bytes, not a copy.
type AsyncContextTracker ¶
AsyncContextTracker captures and restores context around promise reactions.
type Callable ¶
Callable is a JS function as Go calls it.
func AssertFunction ¶
AssertFunction returns v as a function Go calls.
type Constructor ¶
Constructor is a JS constructor as Go calls it with new.
func AssertConstructor ¶
func AssertConstructor(v Value) (Constructor, bool)
AssertConstructor returns v as a constructor Go calls with new.
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.
TracksReactions bool // A promise reaction runs under the context of the call that registered it.
}
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 struct {
// contains filtered or unexported fields
}
Exception is what JS threw, with its stack read through the scripts' source maps.
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 struct {
// contains filtered or unexported fields
}
InterruptedError stops a call the host interrupted.
func (*InterruptedError) CallError ¶
func (*InterruptedError) CallError() error
CallError is nil: moejs drops the jobs an interrupt cut, the calls' among them.
func (*InterruptedError) Error ¶
func (e *InterruptedError) Error() string
func (*InterruptedError) String ¶
func (e *InterruptedError) String() string
func (*InterruptedError) Unwrap ¶
func (e *InterruptedError) Unwrap() error
func (*InterruptedError) Value ¶
func (e *InterruptedError) Value() any
Value is what the host interrupted the call with.
type IsolatedChannel ¶
type IsolatedChannel struct{}
IsolatedChannel is a private MessagePort channel to an opaque-origin sandboxed iframe on the web.
func OpenIsolatedFrame ¶
func OpenIsolatedFrame(srcdoc, initToken string, onMessage func(map[string]any)) *IsolatedChannel
OpenIsolatedFrame is only available on the web (GOOS=js).
func (*IsolatedChannel) Close ¶
func (*IsolatedChannel) Close()
func (*IsolatedChannel) Post ¶
func (*IsolatedChannel) Post(map[string]any)
func (*IsolatedChannel) Ready ¶
func (*IsolatedChannel) Ready() <-chan struct{}
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object is a JS object or function of a realm.
func (*Object) ClassName ¶
ClassName is the object's class: an array's, a function's and an error's by their kind, others by their constructor's.
func (*Object) DefineAccessorProperty ¶
func (*Object) DefineDataProperty ¶
func (*Object) DefineDataPropertySymbol ¶
func (*Object) Export ¶
Export gives the object as Go reads it: a Go value as it is, an array as []any, a function as func(FunctionCall) Value, a promise as *Promise, a date as time.Time, and other objects as map[string]any.
func (*Object) ExportType ¶
func (*Object) Get ¶
Get returns the property name, nil when neither the object nor its prototypes have it.
func (*Object) MarshalJSON ¶
MarshalJSON writes the object as JSON.stringify does.
func (*Object) SetPrototype ¶
func (*Object) StrictEquals ¶
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is a script compiled for RunProgram.
func MustCompile ¶
MustCompile compiles src, as strict mode code when strict is set.
type Promise ¶
type Promise struct {
// contains filtered or unexported fields
}
Promise is a JS promise.
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 moejs.
func (*Runtime) ClearInterrupt ¶
func (r *Runtime) ClearInterrupt()
func (*Runtime) Close ¶
func (r *Runtime) Close()
Close lets go of what the realm keeps of finished calls.
func (*Runtime) DrainPromiseJobs ¶
DrainPromiseJobs has nothing to run: the outermost call runs the jobs.
func (*Runtime) GlobalObject ¶
func (*Runtime) NewArrayBuffer ¶
func (r *Runtime) NewArrayBuffer(data []byte) ArrayBuffer
func (*Runtime) NewGoError ¶
NewGoError makes an Error of err, which an exception carrying it unwraps to.
func (*Runtime) NewPromise ¶
func (*Runtime) SetAsyncContextTracker ¶
func (r *Runtime) SetAsyncContextTracker(tracker AsyncContextTracker)
func (*Runtime) SetFieldNameMapper ¶
func (r *Runtime) SetFieldNameMapper(mapper FieldNameMapper)
func (*Runtime) SetPromiseJobFilter ¶
SetPromiseJobFilter does nothing: moejs drops the queued jobs when it interrupts a call.
func (*Runtime) SetTimeSource ¶
func (*Runtime) ToObject ¶
ToObject boxes v using the realm's prototypes and returns objects unchanged.
func (*Runtime) ToValue ¶
ToValue makes a JS value of a Go one: primitives as themselves, functions as JS functions converting their arguments and results, slices and maps as arrays and objects of their items, and other values as objects whose prototype holds their fields and methods, exported back as the value.
type StackOverflowError ¶
type StackOverflowError struct {
// contains filtered or unexported fields
}
StackOverflowError is kept for the shared API: moejs throws a RangeError past its call depth, which JS can catch.
func (*StackOverflowError) Error ¶
func (e *StackOverflowError) Error() string
func (*StackOverflowError) String ¶
func (e *StackOverflowError) String() string
func (*StackOverflowError) Unwrap ¶
func (*StackOverflowError) Unwrap() error
type Symbol ¶
type Symbol struct {
// contains filtered or unexported fields
}
Symbol is a JavaScript symbol, which any realm may use.
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.
type WeakObject ¶
type WeakObject struct {
// contains filtered or unexported fields
}
WeakObject holds an object without keeping it alive.
func (WeakObject) Value ¶
func (w WeakObject) Value() *Object
Value is the object, nil once it is collected.