Documentation
¶
Overview ¶
Package ecmascript provides an ECMAScript-compatible action interpreter.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // InterruptedMessage is the string value of Interrupted. InterruptedMessage = "RuntimeError: timeout" // Interrupted is returned by Exec if the execution is // interrupted. Interrupted = errors.New(InterruptedMessage) // IgnoreExit will prevent the Goja function "exit" from // terminating the process. Being able to halt the process // from Goja is useful for some tests and utilities. Maybe. IgnoreExit = false )
Functions ¶
Types ¶
type Interpreter ¶
type Interpreter struct { // Testing is used to expose or hide some runtime // capabilities. Test bool // Extended adds some additional properties. Extended bool }
Interpreter implements core.Intepreter using Goja, which is a Go implementation of ECMAScript 5.1+.
See https://github.com/dop251/goja.
func (*Interpreter) Compile ¶
func (i *Interpreter) Compile(ctx context.Context, src interface{}) (interface{}, error)
Compile calls goja.Compile. This step is optional.
See BenchmarkPrecompile and BenchmarkNoPrecompile for a comparison of what compilation can do for you.
func (*Interpreter) Exec ¶
func (i *Interpreter) Exec(ctx context.Context, bs match.Bindings, props core.StepProps, src interface{}, compiled interface{}) (*core.Execution, error)
Exec implements the Interpreter method of the same name.
The following properties are available from the runtime at _.
These two things are most important:
bindings: the map of the current bindings. props: core.StepProps out(obj): Add the given object as a message to emit.
Extended properties (enabled by interpreter's Extended property):
randstr(): generate a random string. cronNext(s): Return a string representing (RFC3999Nano) the next time for the given crontab expression. esc(s): URL query-escape the given string. match(pat, obj): Execute the pattern matcher.
Testing properties (enabled by the interpreter's Test property):
sleep(ms): sleep for the given number of milliseconds. For testing. exit(msg): Terminate the process after printing the given message. For testing.
Click to show internal directories.
Click to hide internal directories.