Documentation
¶
Overview ¶
Package js runs the flow format's JavaScript: ${...} expressions, runScript files and evalScript, with these semantics:
- each evaluation runs as (function(){ return eval(src) })() in strict mode;
- before each evaluation, globals other than the permanent ones are deleted and the current env variables are injected as string globals;
- undeclared names read as undefined (so ${X || 'default'} works);
- output, tb (also as `maestro`, for Maestro flows), json, http, faker, relativePoint and console persist;
- setTimeout, setInterval, clearTimeout and clearInterval exist: an evaluation runs its timers after its own code, before it returns (see timers.go).
Index ¶
- func Display(v goja.Value) string
- func RandomCity() string
- func RandomColor() string
- func RandomCountry() string
- func RandomEmail() string
- func RandomNumber(length int) string
- func RandomPersonName() string
- func RandomText(length int) string
- func Truthy(s string) bool
- type Engine
- type Error
- type Scope
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Display ¶
Display renders a value the way the reference JavaScript engine's toString does: strings raw, objects in display form ({a: 1}, [1, 2]), not JSON.
func RandomCity ¶
func RandomCity() string
func RandomColor ¶
func RandomColor() string
func RandomCountry ¶
func RandomCountry() string
func RandomEmail ¶
func RandomEmail() string
func RandomNumber ¶
RandomNumber is a number with `length` digits (no leading zero).
func RandomPersonName ¶
func RandomPersonName() string
func RandomText ¶
RandomText is `length` random lowercase letters.
Types ¶
type Engine ¶
type Engine struct {
// Log receives console.log lines from scripts whose Scope has no Log of its own.
Log func(string)
// ScriptDir is where http multipartForm filePath resolves; set by runScript.
ScriptDir string
// contains filtered or unexported fields
}
Engine is one flow run's JavaScript context. It is safe for concurrent use: multi-device flows share one engine (and so one `output`) across devices.
func (*Engine) Interpolate ¶
Interpolate replaces every ${...} in s with its evaluated value, using the format's rule: the expression runs to the last "}" before the next "$" (it cannot contain "$"), and \${...} is kept literally (without the backslash).
type Error ¶
type Error struct {
Msg string
// Syntax: the source does not compile, so it fails the same way every time it runs
// (a retry does not run it again, as it does after an error thrown while it runs).
Syntax bool
}
Error is a JavaScript error. It is fatal even for optional commands.
type Scope ¶
type Scope struct {
Env map[string]string
Platform string
CopiedText *string
// Log receives this evaluation's console.log lines (nil: the engine's Log).
Log func(string)
}
Scope is what one evaluation sees: the device's env variables, its platform and its clipboard. Multi-device flows share one Engine (one `output`) with a Scope per device.