sandbox

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateTypes

func GenerateTypes(outputPath string) error

GenerateTypes combines all TypeScript definitions from contributors and writes them to the specified path

func Register

func Register(c Contributor)

Register adds a new sandbox contributor

Types

type Contributor

type Contributor interface {
	Name() string
	PolyfillSource() string  // JS code prepended to every execution
	TypesDefinition() string // TS types combined into types.d.ts
}

Contributor defines a package that extends the JS sandbox environment

type Result

type Result struct {
	Output string
	Logs   []string
}

Result contains the output of the sandbox execution and the console logs

type Sandbox

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

Sandbox represents a single execution context

func New

func New() (*Sandbox, error)

New creates a new V8 sandbox

func (*Sandbox) Close

func (s *Sandbox) Close()

Close releases V8 resources

func (*Sandbox) Execute

func (s *Sandbox) Execute(code string, fnName string, args ...any) (*Result, error)

Execute runs the JavaScript code and calls the specified function with JSON-serialized args

func (*Sandbox) RegisterGlobal

func (s *Sandbox) RegisterGlobal(name string, cb v8.FunctionCallback) error

RegisterGlobal injects a dynamic Go function into this specific Sandbox execution context

Jump to

Keyboard shortcuts

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