modules

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = &Registry{}

DefaultRegistry is the default, gobal registry at which all modules can register.

View Source
var (
	ErrModuleRegistered = errors.New("module already registered")
)

Functions

func Register

func Register(mod Module) error

Register registers a new module at the default registr.y

Types

type Instance

type Instance struct {
	Name   string
	Module *goja.Object
}

type Module

type Module interface {
	// Name returns the name of the module. The name is used
	// to load the module in the javascript environment using
	// require()
	Name() string

	// NewModuleInstance should return a new module instance
	// that is made available to JS code using the require().
	// If nil is returned, the module instance is ignored and will
	// not be made available to the JS runtime.
	// If an error is returned, the runtime will refuse to be created.
	// The VU is already prepared and the underlying eventloop has been
	// started.
	NewModuleInstance(VU) (*goja.Object, error)
}

type Registry

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

func (*Registry) EnableModules

func (reg *Registry) EnableModules(vu VU) ([]Instance, error)

EnableModules enables all modules registered at the registry at the specified VU.

func (*Registry) Register

func (reg *Registry) Register(mod Module) error

Register registers a new module at the registry.

type VU

type VU interface {
	// Runtime returns a reference to the actual goja runtime.
	Runtime() *goja.Runtime

	// Registry returns the require registry for the goja runtime.
	Registry() *require.Registry

	// Config returns the configuration object.
	Config() config.Config

	// RunScript schedules a javascript script to be executed on the event loop.
	// It blocks until the script has been executed.
	RunScript(string) (goja.Value, error)

	// Run schedules a callback function to be executed on the event loop.
	// It blocks until the function has been executed.
	Run(func(*goja.Runtime) (goja.Value, error)) (goja.Value, error)

	// PackagePath returns the path of the parent directory that contains
	// the loaded and executed automation package.
	PackagePath() string

	// EventLoop returns the underlying event loop
	EventLoop() *eventloop.EventLoop
}

Directories

Path Synopsis
Package encoding provides a k6 JS module that implements the TextEncoder and TextDecoder interfaces.
Package encoding provides a k6 JS module that implements the TextEncoder and TextDecoder interfaces.

Jump to

Keyboard shortcuts

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