codec

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HtmlElements = map[string]string{}/* 141 elements not displayed */

Functions

func CallbackErrorf added in v0.8.0

func CallbackErrorf[T any](s js.Scope[T], format string, a ...any) error

func DecodeAny added in v0.11.0

func DecodeAny[T any](_ js.Scope[T], v js.Value[T]) (any, error)

DecodeAny returns the native JavaScript value and is used where a Go implementation merely has a slot for client code to store a value. When the client code is JavaScript, the value will be the JavaScript object. One example is the Detail property of a CustomEvent.

func DecodeAs added in v0.8.0

func DecodeAs[T, U any](s js.Scope[U], v js.Value[U]) (res T, err error)

func DecodeBoolean

func DecodeBoolean[T any](_ js.Scope[T], val js.Value[T]) (bool, error)

func DecodeByteString added in v0.10.3

func DecodeByteString[T any](s js.Scope[T], v js.Value[T]) (types.ByteString, error)

func DecodeDuration added in v0.11.0

func DecodeDuration[T any](_ js.Scope[T], v js.Value[T]) (time.Duration, error)

func DecodeEvent added in v0.11.0

func DecodeEvent[T any](
	_ js.Scope[T],
	options js.Object[T],
	ev *event.Event,
) error

func DecodeFunction

func DecodeFunction[T any](s js.Scope[T], v js.Value[T]) (js.Function[T], error)

func DecodeHTMLElement

func DecodeHTMLElement[T any](s js.Scope[T], v js.Value[T]) (html.HTMLElement, error)

func DecodeInt

func DecodeInt[T any](_ js.Scope[T], v js.Value[T]) (int, error)

func DecodeJsObject added in v0.11.0

func DecodeJsObject[T any](s js.Scope[T], v js.Value[T]) (res js.Object[T], err error)

func DecodeNativeValue added in v0.11.0

func DecodeNativeValue[T, U any](s js.Scope[T], v js.Value[T]) (res U, err error)

func DecodeNode

func DecodeNode[T any](s js.Scope[T], v js.Value[T]) (dom.Node, error)

func DecodeOptions added in v0.8.0

func DecodeOptions[T, U any](
	scope js.Scope[T], val js.Value[T], specs Options[T, U],
) (opts []U, err error)

func DecodeRequestBody added in v0.9.3

func DecodeRequestBody[T any](s js.Scope[T], val js.Value[T]) (io.Reader, error)

DecodeRequestBody constructs an io.Reader used for HTTP request bodies for both XMLHttpRequest.send and fetch's RequestInit.body, which supports almost identical values.

Note: Not all valid body types aren't yet supported

func DecodeString

func DecodeString[T any](s js.Scope[T], v js.Value[T]) (string, error)

func EncodeAny added in v0.11.0

func EncodeAny[T any](scope js.Scope[T], v any) (js.Value[T], error)

EncodeAny assumes that value v is a direct JavaScript. See also DecodeAny

func EncodeBoolean

func EncodeBoolean[T any](s js.CallbackScope[T], b bool) (js.Value[T], error)

func EncodeByteString added in v0.10.3

func EncodeByteString[T any](scope js.Scope[T], s types.ByteString) (js.Value[T], error)

func EncodeCallbackErrorf added in v0.8.0

func EncodeCallbackErrorf[T any](
	ctx js.CallbackContext[T],
	format string,
	a ...any,
) (js.Value[T], error)

EncodeCallbackErrorf create callback return values with a specific error message, and logs the error to the logger associated with the script context.

While _uncaught_ JavaScript errors would be logged by default, if the error is caught by JavaScript, the error message will not be logged.

This is particularly valuable for not-implemented methods, as JavaScript code will fail when perfectly valid assumptions about the function are violated.

func EncodeConstructedValue added in v0.11.0

func EncodeConstructedValue[T any](s js.CallbackScope[T], val any) (js.Value[T], error)

EncodeConstructedValue is a simple helper for JS constructor callbacks to store the constructed Go value in the JavaScript object, and possibly cache it with the script context.

func EncodeEntity

func EncodeEntity[T any, U entity.Components](s js.Scope[T], e U) (js.Value[T], error)

EncodeEntity gets the JavaScript object that wraps a specific Go object. If a wrapper already has been created, that wrapper is returned; otherwise a new object is created with the correct prototype configured.

func EncodeEntityScopedWithPrototype added in v0.10.3

func EncodeEntityScopedWithPrototype[T any](
	scope js.Scope[T],
	e entity.Components,
	protoName string,
) (js.Value[T], error)

func EncodeInt

func EncodeInt[T any](s js.Scope[T], i int) (js.Value[T], error)

func EncodeNillableString

func EncodeNillableString[T any](
	scope js.CallbackScope[T],
	s string,
	hasValue bool,
) (js.Value[T], error)

func EncodeNull

func EncodeNull[T any](s js.CallbackScope[T]) (js.Value[T], error)

func EncodeNullableString

func EncodeNullableString[T any](scope js.CallbackScope[T], s *string) (js.Value[T], error)

func EncodeOptionalString added in v0.11.0

func EncodeOptionalString[T any](
	scope js.CallbackScope[T],
	s string,
) (js.Value[T], error)

func EncodePromise added in v0.8.0

func EncodePromise[T, U any](
	scope js.Scope[T],
	prom promise.Promise[U],
	encoder Encoder[T, U],
) (js.Value[T], error)

EncodePromise converts a promise.Promise value to a JavaScript Promise value, using encoder to convert the native fulfilled value to a JavaScript value.

The returned Promise will not settile immediately after a value is received from prom, but will be deferred to run on the "main loop" that the embedder controls.

func EncodeString

func EncodeString[T any](scope js.Scope[T], s string) (js.Value[T], error)

func GetWindow added in v0.11.0

func GetWindow[T any](scope js.Scope[T]) (html.Window, error)

func LookupJSPrototype

func LookupJSPrototype(entity any) string

func NewOptionsDecoder added in v0.8.0

func NewOptionsDecoder[T, U any](
	opts Options[T, U],
) func(js.CallbackContext[T], js.Value[T]) ([]U, error)

func RetrieveEventInit added in v0.11.0

func RetrieveEventInit[T, U any](cbCtx js.CallbackContext[U]) (res T, err error)

func SetJsValue added in v0.11.0

func SetJsValue[T any](c entity.Components, v js.Value[T])

func UnsupportedOptionErrorf added in v0.8.0

func UnsupportedOptionErrorf[T any](
	s js.Scope[T],
	value js.Value[T],
	webAPI string,
	key string,
) error

UnsupportedOptionErrorf is used to detect when script code uses options or arguments that are not yet supported by Gost-DOM.

The primary usage is to identify when a failing test case is failing because of missing functionality in Gost-DOM, rather than an error in the system under test.

The value argument represents a JavaScript function argument keyed option value. If it is not null or undefined, an error is logged and returned. The name of the api is specified in the webAPI, and the unsupported method or option is specified in key.

func ZeroValue

func ZeroValue[T any]() (res T)

Types

type Encoder added in v0.8.0

type Encoder[T, U any] = func(js.Scope[T], U) (js.Value[T], error)

type EventInit

type EventInit struct {
	Bubbles    bool
	Cancelable bool
	Init       any
}

func DecodeEventInit

func DecodeEventInit[T any](
	_ js.Scope[T],
	val js.Value[T],
) (EventInit, error)

type OptionDecoder added in v0.8.0

type OptionDecoder[T, U any] = func(js.Scope[T], js.Value[T]) (U, error)

func OptDecoder added in v0.8.0

func OptDecoder[T, U, V any](
	decode func(scope js.Scope[T], val js.Value[T]) (U, error),
	f func(U) V,
) OptionDecoder[T, V]

type Options added in v0.8.0

type Options[T, U any] map[string]OptionDecoder[T, U]

Jump to

Keyboard shortcuts

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