Documentation ¶
Overview ¶
Package js the JavaScript implementation
Index ¶
- Constants
- Variables
- func EnableConsole(vm *goja.Runtime)
- func EnableRequire(vm *goja.Runtime, path ...string)
- func Format(call goja.FunctionCall, vm *goja.Runtime) goja.Value
- func InitGlobalModule(vm *goja.Runtime)
- func Run(ctx context.Context, p Program) (goja.Value, error)
- func RunString(ctx context.Context, script string) (goja.Value, error)
- func SetOptions(opt Options)
- func Throw(vm *goja.Runtime, err error)
- func ToBytes(data any) ([]byte, error)
- func ToStrings(data any) (s any, err error)
- func Unwrap(value goja.Value) (any, error)
- func VMContext(vm *goja.Runtime) context.Context
- type Cat
- func (c *Cat) Cancel()
- func (c *Cat) ClearVar()
- func (c *Cat) GetElement(key string, rule string, content any) (ret string, err error)
- func (c *Cat) GetElements(key string, rule string, content any) (ret []string, err error)
- func (c *Cat) GetString(key string, rule string, content any) (ret string, err error)
- func (c *Cat) GetStrings(key string, rule string, content any) (ret []string, err error)
- func (c *Cat) GetVar(call goja.FunctionCall, vm *goja.Runtime) goja.Value
- func (c *Cat) Log(call goja.FunctionCall, vm *goja.Runtime) goja.Value
- func (c *Cat) SetVar(key string, value goja.Value) error
- type FieldNameMapper
- type Options
- type Program
- type Scheduler
- type VM
Constants ¶
const ( // DefaultMaxTimeToWaitGetVM default retries time DefaultMaxTimeToWaitGetVM = 500 * time.Millisecond // DefaultMaxRetriesGetVM default retries times DefaultMaxRetriesGetVM = 3 )
const VMContextKey = "__ctx__"
VMContextKey the VM current context
Variables ¶
var ( // ErrInvalidModule module is invalid ErrInvalidModule = errors.New("invalid module") // ErrIllegalModuleName module name is illegal ErrIllegalModuleName = errors.New("illegal module name") // ErrModuleFileDoesNotExist module not exist ErrModuleFileDoesNotExist = errors.New("module file does not exist") )
var ( // ErrSchedulerClosed the scheduler is closed error ErrSchedulerClosed = errors.New("scheduler is closed") )
Functions ¶
func EnableRequire ¶
EnableRequire set runtime require module
func InitGlobalModule ¶
InitGlobalModule init all global modules
func SetOptions ¶ added in v0.3.0
func SetOptions(opt Options)
SetOptions set the default js Options.
Types ¶
type Cat ¶
Cat an analyzer context
func (*Cat) Cancel ¶
func (c *Cat) Cancel()
Cancel this context releases resources associated with it, so code should call cancel as soon as the operations running in this Context complete.
func (*Cat) GetElement ¶
GetElement gets the string of the content with the given arguments
func (*Cat) GetElements ¶
GetElements gets the string of the content with the given arguments
func (*Cat) GetStrings ¶
GetStrings gets the string of the content with the given arguments
func (*Cat) GetVar ¶
GetVar returns the value associated with this context for key, or nil if no value is associated with key.
type FieldNameMapper ¶
type FieldNameMapper struct{}
FieldNameMapper provides custom mapping between Go and JavaScript property names.
func (FieldNameMapper) FieldName ¶
func (FieldNameMapper) FieldName(_ reflect.Type, f reflect.StructField) string
FieldName returns a JavaScript name for the given struct field in the given type. If this method returns "" the field becomes hidden.
func (FieldNameMapper) MethodName ¶
MethodName returns a JavaScript name for the given method in the given type. If this method returns "" the method becomes hidden.
type Options ¶
type Options struct { InitialVMs int `yaml:"initial-vms"` MaxVMs int `yaml:"max-vms"` MaxRetriesGetVM int `yaml:"max-retries-get-vm"` MaxTimeToWaitGetVM time.Duration `yaml:"max-time-to-wait-get-vm"` UseStrict bool `yaml:"use-strict"` ModulePath []string `yaml:"module-path"` }
Options Scheduler options
type Scheduler ¶
type Scheduler interface { // Get the VM Get() (VM, error) // Release the VM Release(VM) // Close the scheduler Close() error }
Scheduler the VM scheduler
type VM ¶
type VM interface { // Run the js program Run(context.Context, Program) (goja.Value, error) // RunString the js string RunString(context.Context, string) (goja.Value, error) // Runtime the js runtime Runtime() *goja.Runtime }
VM the js runtime. An instance of VM can only be used by a single goroutine at a time.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package modulestest the module test vm
|
Package modulestest the module test vm |