scripting

package
v0.0.0-...-b2877e8 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

The scripting package implements ECMAScript execution through the v8 engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIncompatibleType   = errors.New("Incompatible type")
	ErrWrongNoOfArguments = errors.New("Not enough arguments passed")
)

Functions

func CreateAttr

func CreateAttr(host *ScriptHost) *v8.FunctionTemplate

func CreateCustomEvent

func CreateCustomEvent(host *ScriptHost) *v8.FunctionTemplate

func CreateDocumentFragmentPrototype

func CreateDocumentFragmentPrototype(host *ScriptHost) *v8.FunctionTemplate

CreateDocumentFragmentPrototype currently only exists to allow code to check for inheritence, i.e., `node instanceof DocumentFragment`

func CreateDocumentPrototype

func CreateDocumentPrototype(host *ScriptHost) *v8.FunctionTemplate

func CreateElement

func CreateElement(host *ScriptHost) *v8.FunctionTemplate

func CreateEvent

func CreateEvent(host *ScriptHost) *v8.FunctionTemplate

func CreateEventTarget

func CreateEventTarget(host *ScriptHost) *v8.FunctionTemplate

func CreateFormData

func CreateFormData(host *ScriptHost) *v8.FunctionTemplate

func CreateHtmlElement

func CreateHtmlElement(host *ScriptHost) *v8.FunctionTemplate

func CreateLocationPrototype

func CreateLocationPrototype(host *ScriptHost) *v8.FunctionTemplate

func CreateNamedNodeMap

func CreateNamedNodeMap(host *ScriptHost) *v8.FunctionTemplate

func CreateNode

func CreateNode(host *ScriptHost) *v8.FunctionTemplate

func CreateNodeList

func CreateNodeList(host *ScriptHost) *v8.FunctionTemplate

func CreateShadowRootPrototype

func CreateShadowRootPrototype(host *ScriptHost) *v8.FunctionTemplate

CreateShadowRootPrototype currently only exists to allow code to check for inheritence, i.e., `node instanceof DocumentFragment`. This is performed by HTMX; but it doesn't itself _create_ a shadow root.

func CreateURLPrototype

func CreateURLPrototype(host *ScriptHost) *v8.FunctionTemplate

func CreateWindowTemplate

func CreateWindowTemplate(host *ScriptHost) *v8.FunctionTemplate

func CreateXmlHttpRequestPrototype

func CreateXmlHttpRequestPrototype(host *ScriptHost) *v8.FunctionTemplate

func GetBodyFromDocument

func GetBodyFromDocument(ctx *ScriptContext, val *v8.Value) (*browser.XHRRequestBody, error)

func GetBodyFromXMLHttpRequestBodyInit

func GetBodyFromXMLHttpRequestBodyInit(
	ctx *ScriptContext,
	val *v8.Value,
) (*browser.XHRRequestBody, error)

func NewV8EventListener

func NewV8EventListener(ctx *ScriptContext, val *v8.Value) browser.EventHandler

func TryParseArg

func TryParseArg[T any](
	args argumentHelper,
	index int,
	parser func(*ScriptContext, *v8.Value) (T, error),
) (result T, err error)

func TryParseArgs

func TryParseArgs[T interface{}](
	ctx *ScriptContext,
	args []*v8.Value,
	index int,
	parsers ...func(*ScriptContext, *v8.Value) (T, error),
) (result T, err error)

Types

type ConstructorBuilder

type ConstructorBuilder[T any] struct {
	// contains filtered or unexported fields
}

func NewConstructorBuilder

func NewConstructorBuilder[T any](
	host *ScriptHost,
	cb v8.FunctionCallbackWithError,
) ConstructorBuilder[T]

func NewIllegalConstructorBuilder

func NewIllegalConstructorBuilder[T any](host *ScriptHost) ConstructorBuilder[T]

func (ConstructorBuilder[T]) GetInstance

func (b ConstructorBuilder[T]) GetInstance(info *v8.FunctionCallbackInfo) (T, error)

func (ConstructorBuilder[T]) NewInstanceBuilder

func (c ConstructorBuilder[T]) NewInstanceBuilder() PrototypeBuilder[T]

func (ConstructorBuilder[T]) NewPrototypeBuilder

func (c ConstructorBuilder[T]) NewPrototypeBuilder() PrototypeBuilder[T]

func (*ConstructorBuilder[T]) SetDefaultInstanceLookup

func (c *ConstructorBuilder[T]) SetDefaultInstanceLookup()

type Converters

type Converters struct{}

func (Converters) DecodeUSVString

func (w Converters) DecodeUSVString(ctx *ScriptContext, val *v8.Value) (string, error)

func (Converters) GetArgByteString

func (w Converters) GetArgByteString(args []*v8.Value, idx int) (result string, err error)

func (Converters) GetArgDOMString

func (w Converters) GetArgDOMString(args []*v8.Value, idx int) (result string, err error)

func (Converters) GetArgUSVString

func (w Converters) GetArgUSVString(args []*v8.Value, idx int) (result string, err error)

func (Converters) ToByteString

func (w Converters) ToByteString(ctx *ScriptContext, str string) (*v8.Value, error)

func (Converters) ToNullableByteString

func (w Converters) ToNullableByteString(ctx *ScriptContext, str *string) (*v8.Value, error)

func (Converters) ToUSVString

func (w Converters) ToUSVString(ctx *ScriptContext, str string) (*v8.Value, error)

func (Converters) ToUnsignedShort

func (w Converters) ToUnsignedShort(ctx *ScriptContext, val int) (*v8.Value, error)

type Disposable

type Disposable interface {
	Dispose()
}

type DisposeFunc

type DisposeFunc func()

func (DisposeFunc) Dispose

func (fn DisposeFunc) Dispose()

type ESURL

type ESURL struct {
	Converters
	// contains filtered or unexported fields
}

func NewESURL

func NewESURL(host *ScriptHost) ESURL

func (ESURL) CreateInstance

func (u ESURL) CreateInstance(ctx *ScriptContext, this *v8.Object, url string) (*v8.Value, error)

func (ESURL) CreateInstanceBase

func (u ESURL) CreateInstanceBase(
	ctx *ScriptContext,
	this *v8.Object,
	url string,
	base string,
) (*v8.Value, error)

func (ESURL) GetHash

func (u ESURL) GetHash(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) GetHost

func (u ESURL) GetHost(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) GetHostname

func (u ESURL) GetHostname(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) GetHref

func (u ESURL) GetHref(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) GetInstance

func (u ESURL) GetInstance(info *v8.FunctionCallbackInfo) (browser.URL, error)

func (ESURL) GetPassword

func (u ESURL) GetPassword(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) GetPathname

func (u ESURL) GetPathname(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) GetPort

func (u ESURL) GetPort(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) GetProtocol

func (u ESURL) GetProtocol(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) GetSearch

func (u ESURL) GetSearch(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) GetUsername

func (u ESURL) GetUsername(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) NewInstance

func (u ESURL) NewInstance(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) Origin

func (u ESURL) Origin(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) SearchParams

func (u ESURL) SearchParams(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) SetHash

func (u ESURL) SetHash(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) SetHost

func (u ESURL) SetHost(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) SetHostname

func (u ESURL) SetHostname(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) SetHref

func (u ESURL) SetHref(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) SetPassword

func (u ESURL) SetPassword(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) SetPathname

func (u ESURL) SetPathname(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) SetPort

func (u ESURL) SetPort(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) SetProtocol

func (u ESURL) SetProtocol(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) SetSearch

func (u ESURL) SetSearch(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) SetUsername

func (u ESURL) SetUsername(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESURL) ToJSON

func (u ESURL) ToJSON(info *v8.FunctionCallbackInfo) (*v8.Value, error)

type ESWrapper

type ESWrapper[T Entity] struct {
	Converters
	// contains filtered or unexported fields
}

ESWrapper serves as a helper for building v8 wrapping code around go objects. Generated code assumes that a wrapper type is used with specific helper methods implemented.

func NewESWrapper

func NewESWrapper[T Entity](host *ScriptHost) ESWrapper[T]

func (ESWrapper[T]) GetInstance

func (w ESWrapper[T]) GetInstance(info *v8.FunctionCallbackInfo) (result T, err error)

type ESXmlHttpRequest

type ESXmlHttpRequest struct{ ESWrapper[XmlHttpRequest] }

func NewESXmlHttpRequest

func NewESXmlHttpRequest(host *ScriptHost) ESXmlHttpRequest

func (ESXmlHttpRequest) Abort

func (xhr ESXmlHttpRequest) Abort(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) CreateInstance

func (w ESXmlHttpRequest) CreateInstance(ctx *ScriptContext, this *v8.Object) (*v8.Value, error)

func (ESXmlHttpRequest) GetAllResponseHeaders

func (xhr ESXmlHttpRequest) GetAllResponseHeaders(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) GetResponseHeader

func (xhr ESXmlHttpRequest) GetResponseHeader(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) GetResponseType

func (xhr ESXmlHttpRequest) GetResponseType(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) GetTimeout

func (xhr ESXmlHttpRequest) GetTimeout(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) GetWithCredentials

func (xhr ESXmlHttpRequest) GetWithCredentials(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) NewInstance

func (xhr ESXmlHttpRequest) NewInstance(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) Open

func (xhr ESXmlHttpRequest) Open(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) OverrideMimeType

func (xhr ESXmlHttpRequest) OverrideMimeType(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) ReadyState

func (xhr ESXmlHttpRequest) ReadyState(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) Response

func (xhr ESXmlHttpRequest) Response(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) ResponseText

func (xhr ESXmlHttpRequest) ResponseText(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) ResponseURL

func (xhr ESXmlHttpRequest) ResponseURL(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) ResponseXML

func (xhr ESXmlHttpRequest) ResponseXML(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) Send

func (xhr ESXmlHttpRequest) Send(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) SetRequestHeader

func (xhr ESXmlHttpRequest) SetRequestHeader(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) SetResponseType

func (xhr ESXmlHttpRequest) SetResponseType(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) SetTimeout

func (xhr ESXmlHttpRequest) SetTimeout(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) SetWithCredentials

func (xhr ESXmlHttpRequest) SetWithCredentials(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) Status

func (xhr ESXmlHttpRequest) Status(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) StatusText

func (xhr ESXmlHttpRequest) StatusText(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (ESXmlHttpRequest) Upload

func (xhr ESXmlHttpRequest) Upload(info *v8.FunctionCallbackInfo) (*v8.Value, error)

type EntityLookup

type EntityLookup[T any] func(value T, ctx *ScriptContext) (*v8.Value, error)

type EventLoop

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

func NewEventLoop

func NewEventLoop(global *v8.Object, cb func(error)) *EventLoop

func (*EventLoop) Start

func (l *EventLoop) Start() Disposable

type FunctionInfo

type FunctionInfo[T any] struct {
	// contains filtered or unexported fields
}

type Iterator

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

func NewIterator

func NewIterator[T any](host *ScriptHost, entityLookup EntityLookup[T]) Iterator[T]

func (Iterator[T]) NewIterator

func (i Iterator[T]) NewIterator(info *v8.FunctionCallbackInfo) (*v8.Value, error)

func (Iterator[T]) NewIteratorInstance

func (i Iterator[T]) NewIteratorInstance(context *ScriptContext, items []T) (*v8.Value, error)

func (Iterator[T]) Next

func (i Iterator[T]) Next(info *v8.FunctionCallbackInfo) (*v8.Value, error)

type IteratorInstance

type IteratorInstance[T any] struct {
	browser.Entity
	// contains filtered or unexported fields
}

type PrototypeBuilder

type PrototypeBuilder[T any] struct {
	// contains filtered or unexported fields
}

func (PrototypeBuilder[T]) CreateFunction

func (h PrototypeBuilder[T]) CreateFunction(
	name string,
	fn func(T, argumentHelper) (*v8.Value, error),
)

func (PrototypeBuilder[T]) CreateFunctionStringToString

func (h PrototypeBuilder[T]) CreateFunctionStringToString(name string, fn func(T, string) string)

func (PrototypeBuilder[T]) CreateReadWriteProp

func (h PrototypeBuilder[T]) CreateReadWriteProp(
	name string,
	get func(T) string,
	set func(T, string),
)

func (PrototypeBuilder[T]) CreateReadonlyProp

func (h PrototypeBuilder[T]) CreateReadonlyProp(name string, fn func(T) string)

func (PrototypeBuilder[T]) CreateReadonlyProp2

func (h PrototypeBuilder[T]) CreateReadonlyProp2(
	name string,
	fn func(T, *ScriptContext) (*v8.Value, error),
)

func (PrototypeBuilder[T]) GetInstance

func (b PrototypeBuilder[T]) GetInstance(info *v8.FunctionCallbackInfo) (T, error)

type ScriptContext

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

func (*ScriptContext) CacheNode

func (c *ScriptContext) CacheNode(obj *v8.Object, node Entity) (*v8.Value, error)

func (*ScriptContext) Dispose

func (ctx *ScriptContext) Dispose()

func (*ScriptContext) Eval

func (ctx *ScriptContext) Eval(script string) (interface{}, error)

func (*ScriptContext) GetCachedNode

func (c *ScriptContext) GetCachedNode(this *v8.Object) (Entity, bool)

func (*ScriptContext) GetInstanceForNode

func (c *ScriptContext) GetInstanceForNode(
	node Entity,
) (*v8.Value, error)

func (*ScriptContext) GetInstanceForNodeByName

func (c *ScriptContext) GetInstanceForNodeByName(
	constructor string,
	node Entity,
) (*v8.Value, error)

func (*ScriptContext) Run

func (ctx *ScriptContext) Run(script string) error

func (*ScriptContext) RunScript

func (ctx *ScriptContext) RunScript(script string) (*v8.Value, error)

func (*ScriptContext) Window

func (ctx *ScriptContext) Window() Window

type ScriptHost

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

func NewScriptHost

func NewScriptHost() *ScriptHost

func (*ScriptHost) ConsoleAPIMessage

func (host *ScriptHost) ConsoleAPIMessage(message v8.ConsoleAPIMessage)

func (*ScriptHost) Dispose

func (host *ScriptHost) Dispose()

func (*ScriptHost) GetContext

func (h *ScriptHost) GetContext(v8ctx *v8.Context) (*ScriptContext, bool)

func (*ScriptHost) MustGetContext

func (h *ScriptHost) MustGetContext(v8ctx *v8.Context) *ScriptContext

func (*ScriptHost) NewContext

func (host *ScriptHost) NewContext(window Window) *ScriptContext

type Wrapper

type Wrapper ScriptHost

func (*Wrapper) NewScriptEngine

func (w *Wrapper) NewScriptEngine(window Window) browser.ScriptEngine

Jump to

Keyboard shortcuts

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