js

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultHTTPTimeout = 5 * time.Minute

DefaultHTTPTimeout matches the product runtime's read, write, and call limit.

Variables

View Source
var (
	ErrRandomSourceRequired = errors.New("javascript random source is required")
	ErrEnvScopeUnderflow    = errors.New("javascript environment scope stack is empty")
	ErrRuntimeClosed        = errors.New("javascript runtime is closed")
)

Functions

func HasInterpolationExpression

func HasInterpolationExpression(input string) bool

HasInterpolationExpression reports whether Interpolate will recognize at least one complete expression token under its single-pass dollar grammar.

Types

type Config

type Config struct {
	Random   RandomSource
	Platform string
	// CopiedText is nil until something copies. `flowbaton.copiedText` is then
	// undefined, preserving the distinction between "nothing has been copied"
	// and "an empty string was copied".
	CopiedText *string
	LogSink    func(message string)
	HTTPClient *http.Client
}

Config contains host services copied into each runtime created by a Factory.

type EvalRequest

type EvalRequest struct {
	Script        string
	SourceName    string
	ScriptDir     string
	Env           map[string]any
	RunInSubScope bool
}

EvalRequest describes one IIFE-scoped evaluation and its environment overlay.

type EvaluationError

type EvaluationError struct {
	SourceName string
	Message    string
}

EvaluationError reports script failures without exposing goja error types.

func (*EvaluationError) Error

func (e *EvaluationError) Error() string

type Factory

type Factory interface {
	NewRuntime() (Runtime, error)
}

Factory creates one isolated shared-context runtime per root flow.

func NewFactory

func NewFactory(config Config) (Factory, error)

NewFactory validates host services and returns a reusable runtime factory.

type MissingEnvValueError

type MissingEnvValueError struct {
	Name string
}

MissingEnvValueError identifies an environment key whose value was null.

func (*MissingEnvValueError) Error

func (e *MissingEnvValueError) Error() string

type OpaqueValue

type OpaqueValue struct {
	Kind string
}

OpaqueValue represents a JavaScript value that cannot cross the Go-native runtime contract without exposing an engine-specific type.

type RandomSource

type RandomSource interface {
	Intn(n int) int
	Read(p []byte) (int, error)
}

RandomSource supplies deterministic data to the JavaScript faker binding.

type Result

type Result struct {
	Value any
	Text  string
}

Result contains a Go-native exported value and its JavaScript string form.

type Runtime

type Runtime interface {
	Evaluate(ctx context.Context, request EvalRequest) (Result, error)
	Interpolate(ctx context.Context, input string, env map[string]any) (string, error)
	PushEnv() error
	PopEnv() error
	PutEnv(name string, value any) error
	SetCopiedText(value string) error
	SetPlatform(value string) error
	SetLogSink(sink func(message string))
	PushLogSink(sink func(message string)) (restore func())
	Close() error
}

Runtime serializes access to one reusable strict JavaScript context.

Jump to

Keyboard shortcuts

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