require

package
v0.3.71 Latest Latest
Warning

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

Go to latest
Published: May 17, 2025 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const NAME = "require"

Variables

View Source
var (
	InvalidModuleError     = errors.New("Invalid module")
	IllegalModuleNameError = errors.New("Illegal module name")
)

Functions

func GetModuleInfo

func GetModuleInfo(name, contextId string) (*commons.ModuleInfo, bool)

func RegisterNativeModule

func RegisterNativeModule(name string, info *commons.ModuleInfo)

func Require

func Require(runtime *js.Runtime, name string) js.Value

Types

type Registry

type Registry struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Registry contains a cache of compiled modules which can be used by multiple Runtimes

func NewRegistryWithLoader

func NewRegistryWithLoader(srcLoader SourceLoader) *Registry

func (*Registry) Enable

func (instance *Registry) Enable(ctx *commons.RuntimeContext) *RequireModule

Enable adds the require() function to the specified runtime.

func (*Registry) GetCompiled

func (instance *Registry) GetCompiled(path string) (prg *js.Program, err error)

type RequireModule

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

func NewRequireModule

func NewRequireModule(ctx *commons.RuntimeContext, registry *Registry) *RequireModule

func (*RequireModule) GoRequire

func (instance *RequireModule) GoRequire(p string) (ret js.Value, err error)

Require can be used to import modules from Go source (similar to JS require() function).

func (*RequireModule) JsRequire

func (instance *RequireModule) JsRequire(call js.FunctionCall) js.Value

type SourceLoader

type SourceLoader func(path string) ([]byte, error)

Jump to

Keyboard shortcuts

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