wrappers

package
v0.0.0-...-4160af8 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NAME      = "gost-dom"
	BASE_PKG  = "github.com/gost-dom/browser"
	ISSUE_URL = "https://github.com/gost-dom/browser/issues"
)

Names that relate to the project name, which would only change if the project is moved/renamed.

Variables

This section is empty.

Functions

func AssignArgs

func AssignArgs(data ESConstructorData, op ESOperation) g.Generator

func CreateInitFunction

func CreateInitFunction(data ESConstructorData) g.Generator

func CreateV8Constructor

func CreateV8Constructor(data ESConstructorData) g.Generator

func CreateV8ConstructorBody

func CreateV8ConstructorBody(data ESConstructorData) g.Generator

func CreateV8ConstructorWrapperBody

func CreateV8ConstructorWrapperBody(data ESConstructorData) g.Generator

func CreateV8Generator

func CreateV8Generator(data ESConstructorData) g.Generator

func CreateV8IllegalConstructorBody

func CreateV8IllegalConstructorBody(data ESConstructorData) g.Generator

func CreateV8WrapperMethodInstanceInvocations

func CreateV8WrapperMethodInstanceInvocations(
	prototype ESConstructorData,
	op ESOperation,
	baseFunctionName string,
	args []V8ReadArg,
	instanceErr g.Generator,
	createCallInstance func(string, []g.Generator, ESOperation) g.Generator,
	extraError bool,
) g.Generator

func CreateV8WrapperTypeGenerator

func CreateV8WrapperTypeGenerator(data ESConstructorData) g.Generator

func GetInstanceAndError

func GetInstanceAndError(id g.Generator, errId g.Generator, data ESConstructorData) g.Generator

func IsNodeType

func IsNodeType(typeName string) bool

func ReturnOnAnyError

func ReturnOnAnyError(errNames []g.Generator) g.Generator

func V8RequireContext

func V8RequireContext(wrapper WrapperInstance) g.Generator

Types

type ConstructorBuilder

type ConstructorBuilder struct {
	Proto        v8PrototypeTemplate
	InstanceTmpl v8InstanceTemplate
	Wrapper      WrapperInstance
	// contains filtered or unexported fields
}

The ConstructorBuilder is the function that creates the ES constructor itself, i.e. starts with a new function template, installs prototypes on the template, etc.

func NewConstructorBuilder

func NewConstructorBuilder() ConstructorBuilder

func (ConstructorBuilder) InstallAttributeHandler

func (builder ConstructorBuilder) InstallAttributeHandler(
	op ESAttribute,
) g.Generator

func (ConstructorBuilder) InstallAttributeHandlers

func (builder ConstructorBuilder) InstallAttributeHandlers(
	data ESConstructorData,
) g.Generator

func (ConstructorBuilder) InstallFunctionHandlers

func (builder ConstructorBuilder) InstallFunctionHandlers(
	data ESConstructorData,
) JenGenerator

func (ConstructorBuilder) NewFunctionTemplate

func (iso ConstructorBuilder) NewFunctionTemplate(cb g.Generator) g.Generator

func (ConstructorBuilder) NewFunctionTemplateOfWrappedMethod

func (builder ConstructorBuilder) NewFunctionTemplateOfWrappedMethod(name string) g.Generator

type ESAttribute

type ESAttribute struct {
	Name   string
	Getter *ESOperation
	Setter *ESOperation
}

func CreateAttributes

func CreateAttributes(
	dataData WrapperTypeSpec,
	idlName idl.TypeSpec,
) (res []ESAttribute)

type ESClassWrapper

type ESClassWrapper struct {
	DomSpec                   *WrapperGeneratorFileSpec
	TypeName                  string
	InnerTypeName             string
	WrapperTypeName           string
	Receiver                  string
	RunCustomCode             bool
	WrapperStruct             bool
	SkipPrototypeRegistration bool
	IncludeIncludes           bool
	Customization             map[string]*ESMethodWrapper
}

ESClassWrapper contains information about how to generate ES wrapper code around a class in the web specification.

All classes will be generated using a set of defaults. Data in this structure will allow deviating from the defaults.

func (*ESClassWrapper) CreateWrapper

func (s *ESClassWrapper) CreateWrapper()

func (*ESClassWrapper) GetMethodCustomization

func (w *ESClassWrapper) GetMethodCustomization(name string) (result ESMethodWrapper)

func (*ESClassWrapper) MarkMembersAsIgnored

func (w *ESClassWrapper) MarkMembersAsIgnored(names ...string)

func (*ESClassWrapper) MarkMembersAsNotImplemented

func (w *ESClassWrapper) MarkMembersAsNotImplemented(names ...string)

func (*ESClassWrapper) Method

func (w *ESClassWrapper) Method(name string) (result *ESMethodWrapper)

type ESConstructorData

type ESConstructorData struct {
	Spec                *ESClassWrapper
	InnerTypeName       string
	WrapperTypeName     string
	WrapperTypeBaseName string
	Receiver            string
	Inheritance         string
	Operations          []ESOperation
	Attributes          []ESAttribute
	Constructor         *ESOperation
	RunCustomCode       bool
}

func (ESConstructorData) AttributesToInstall

func (d ESConstructorData) AttributesToInstall() iter.Seq[ESAttribute]

func (ESConstructorData) GetInternalPackage

func (d ESConstructorData) GetInternalPackage() string

func (ESConstructorData) Name

func (d ESConstructorData) Name() string

func (ESConstructorData) WrapperFunctionsToGenerate

func (d ESConstructorData) WrapperFunctionsToGenerate() iter.Seq[ESOperation]

func (ESConstructorData) WrapperFunctionsToInstall

func (d ESConstructorData) WrapperFunctionsToInstall() iter.Seq[ESOperation]

type ESMethodArgument

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

func (*ESMethodArgument) HasDefault

func (a *ESMethodArgument) HasDefault() *ESMethodArgument

func (*ESMethodArgument) HasDefaultValue

func (a *ESMethodArgument) HasDefaultValue(value string)

func (*ESMethodArgument) Ignore

func (a *ESMethodArgument) Ignore()

func (*ESMethodArgument) Required

func (a *ESMethodArgument) Required() *ESMethodArgument

func (*ESMethodArgument) SetDecoder

func (a *ESMethodArgument) SetDecoder(d string) *ESMethodArgument

func (*ESMethodArgument) SetEncoder

func (a *ESMethodArgument) SetEncoder(e string) *ESMethodArgument

type ESMethodWrapper

type ESMethodWrapper struct {
	// When set, the ES wrapper will generate an error with the message, "Not implemented"
	NotImplemented bool
	// When set, nothing will be generated for the member
	Ignored bool
	// HasNoError tells that the wrapped Go method doesn't generate an error.
	HasNoError bool
	// CustomImplementation tells that the wrapper code will be generated by hand.
	// Code generator will still install a function on the prototype template
	// referencing the custom function
	CustomImplementation bool
	Arguments            map[string]*ESMethodArgument
	// Name of the method that will convert the result to JS
	Encoder string
}

ESMethodWrapper contains information about how to generate ES wrapper code around a single class method.

func (*ESMethodWrapper) Argument

func (w *ESMethodWrapper) Argument(name string) (result *ESMethodArgument)

func (*ESMethodWrapper) Ignore

func (w *ESMethodWrapper) Ignore() *ESMethodWrapper

func (*ESMethodWrapper) SetCustomImplementation

func (w *ESMethodWrapper) SetCustomImplementation() *ESMethodWrapper

func (*ESMethodWrapper) SetEncoder

func (w *ESMethodWrapper) SetEncoder(e string) *ESMethodWrapper

func (*ESMethodWrapper) SetNoError

func (w *ESMethodWrapper) SetNoError() *ESMethodWrapper

SetNoError is a simple wrapper around [HasNoError] to support a chaning DSL syntax.

func (*ESMethodWrapper) SetNotImplemented

func (w *ESMethodWrapper) SetNotImplemented() *ESMethodWrapper

SetNotImplemented is a simple wrapper around [NotImplemented] to support a chaning DSL syntax.

type ESOperation

type ESOperation struct {
	Name                 string
	NotImplemented       bool
	RetType              idl.RetType
	HasError             bool
	CustomImplementation bool
	MethodCustomization  ESMethodWrapper
	Arguments            []ESOperationArgument
}

func CreateConstructor

func CreateConstructor(
	dataData WrapperTypeSpec,
	idlName idl.TypeSpec) *ESOperation

func CreateInstanceMethods

func CreateInstanceMethods(
	dataData WrapperTypeSpec,
	idlName idl.TypeSpec) (result []ESOperation)

func (ESOperation) Encoder

func (o ESOperation) Encoder() string

func (ESOperation) GetHasError

func (op ESOperation) GetHasError() bool

func (ESOperation) HasResult

func (op ESOperation) HasResult() bool

func (ESOperation) WrapperMethodName

func (o ESOperation) WrapperMethodName() string

type ESOperationArgument

type ESOperationArgument struct {
	Name         string
	Type         string
	Optional     bool
	Variadic     bool
	IdlType      idl.IdlTypes
	ArgumentSpec ESMethodArgument
	Ignore       bool
}

func (ESOperationArgument) DefaultValueInGo

func (a ESOperationArgument) DefaultValueInGo() (name string, ok bool)

func (ESOperationArgument) OptionalInGo

func (a ESOperationArgument) OptionalInGo() bool

type GojaNamingStrategy

type GojaNamingStrategy struct {
	ESConstructorData
}

func (GojaNamingStrategy) PrototypeWrapperBaseName

func (s GojaNamingStrategy) PrototypeWrapperBaseName() string

func (GojaNamingStrategy) PrototypeWrapperConstructorName

func (s GojaNamingStrategy) PrototypeWrapperConstructorName() string

func (GojaNamingStrategy) PrototypeWrapperTypeName

func (s GojaNamingStrategy) PrototypeWrapperTypeName() string

func (GojaNamingStrategy) ReceiverName

func (s GojaNamingStrategy) ReceiverName() string

type GojaTargetGenerators

type GojaTargetGenerators struct{}

func (GojaTargetGenerators) CreateInitFunction

func (gen GojaTargetGenerators) CreateInitFunction(data ESConstructorData) g.Generator

func (GojaTargetGenerators) CreateJSConstructorGenerator

func (gen GojaTargetGenerators) CreateJSConstructorGenerator(data ESConstructorData) g.Generator

func (GojaTargetGenerators) CreatePrototypeInitializer

func (gen GojaTargetGenerators) CreatePrototypeInitializer(data ESConstructorData) g.Generator

CreatePrototypeInitializer creates the "initializePrototype" method, which sets all the properties on the prototypes on this class.

func (GojaTargetGenerators) CreateWrapperMethod

func (gen GojaTargetGenerators) CreateWrapperMethod(
	data ESConstructorData,
	op ESOperation,
) g.Generator

func (GojaTargetGenerators) CreateWrapperMethodBody

func (gen GojaTargetGenerators) CreateWrapperMethodBody(
	data ESConstructorData,
	op ESOperation,
	callArgument g.Generator,
) g.Generator

func (GojaTargetGenerators) CreateWrapperMethods

func (gen GojaTargetGenerators) CreateWrapperMethods(data ESConstructorData) g.Generator

func (GojaTargetGenerators) CreateWrapperStruct

func (gen GojaTargetGenerators) CreateWrapperStruct(data ESConstructorData) g.Generator

type JenGenerator

type JenGenerator = g.Generator

func CreateV8ConstructorWrapper

func CreateV8ConstructorWrapper(data ESConstructorData) JenGenerator

func CreateV8FunctionTemplateCallbackBody

func CreateV8FunctionTemplateCallbackBody(
	data ESConstructorData,
	op ESOperation,
) JenGenerator

func CreateV8WrapperMethod

func CreateV8WrapperMethod(
	data ESConstructorData,
	op ESOperation,
) JenGenerator

func CreateV8WrapperMethods

func CreateV8WrapperMethods(data ESConstructorData) JenGenerator

type NewV8FunctionTemplate

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

func (NewV8FunctionTemplate) Generate

func (t NewV8FunctionTemplate) Generate() *jen.Statement

type ReturnOnError

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

func (ReturnOnError) Generate

func (ret ReturnOnError) Generate() *jen.Statement

type ScriptWrapperModulesGenerator

type ScriptWrapperModulesGenerator struct {
	Specs            WrapperGeneratorsSpec
	PackagePath      string
	TargetGenerators TargetGenerators
}

func NewGojaWrapperModuleGenerator

func NewGojaWrapperModuleGenerator() ScriptWrapperModulesGenerator

func NewScriptWrapperModulesGenerator

func NewScriptWrapperModulesGenerator() ScriptWrapperModulesGenerator

func (ScriptWrapperModulesGenerator) GenerateScriptWrappers

func (gen ScriptWrapperModulesGenerator) GenerateScriptWrappers() error

type TargetGenerators

type TargetGenerators interface {
	CreateJSConstructorGenerator(data ESConstructorData) g.Generator
}

type TypeCustomization

type TypeCustomization []string

type V8InstanceInvocation

type V8InstanceInvocation struct {
	Name     string
	Args     []g.Generator
	Op       ESOperation
	Instance *g.Value
	Receiver WrapperInstance
}

func (V8InstanceInvocation) GetGenerator

func (V8InstanceInvocation) PerformCall

func (c V8InstanceInvocation) PerformCall() (genRes V8InstanceInvocationResult)

type V8InstanceInvocationResult

type V8InstanceInvocationResult struct {
	Generator      g.Generator
	HasValue       bool
	HasError       bool
	RequireContext bool
}

type V8ReadArg

type V8ReadArg struct {
	Argument ESOperationArgument
	ArgName  g.Generator
	ErrName  g.Generator
	Index    int
}

type V8ReadArguments

type V8ReadArguments struct {
	Args      []V8ReadArg
	Generator g.Generator
}

func ReadArguments

func ReadArguments(data ESConstructorData, op ESOperation) (res V8ReadArguments)

func (V8ReadArguments) Generate

func (r V8ReadArguments) Generate() *jen.Statement

type V8TargetGenerators

type V8TargetGenerators struct{}

func (V8TargetGenerators) CreateJSConstructorGenerator

func (_ V8TargetGenerators) CreateJSConstructorGenerator(data ESConstructorData) g.Generator

type WrapperGeneratorFileSpec

type WrapperGeneratorFileSpec struct {
	Name          string
	MultipleFiles bool
	Types         map[string]WrapperTypeSpec
}

func (WrapperGeneratorFileSpec) GetTypesSorted

func (spec WrapperGeneratorFileSpec) GetTypesSorted() []WrapperTypeSpec

func (*WrapperGeneratorFileSpec) SetMultipleFiles

func (spec *WrapperGeneratorFileSpec) SetMultipleFiles(value bool)

func (*WrapperGeneratorFileSpec) Type

func (WrapperGeneratorFileSpec) UseMultipleFiles

func (spec WrapperGeneratorFileSpec) UseMultipleFiles() bool

type WrapperGeneratorsSpec

type WrapperGeneratorsSpec map[string](*WrapperGeneratorFileSpec)

WrapperGeneratorsSpec is a list of specifications for generating ES wrapper code. Each key in the map correspond to a specific IDL file

func CreateSpecs

func CreateSpecs() WrapperGeneratorsSpec

func NewWrapperGeneratorsSpec

func NewWrapperGeneratorsSpec() WrapperGeneratorsSpec

func (WrapperGeneratorsSpec) Module

type WrapperInstance

type WrapperInstance struct{ g.Value }

func (WrapperInstance) GetScriptHost

func (i WrapperInstance) GetScriptHost() g.Value

func (WrapperInstance) MustGetContext

func (i WrapperInstance) MustGetContext(info g.Generator) g.Generator

type WrapperTypeSpec

type WrapperTypeSpec = *ESClassWrapper

Jump to

Keyboard shortcuts

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