Documentation
¶
Overview ¶
Package js implements the engine's ScriptRuntime port with goja, a pure-Go ECMAScript interpreter.
Pure Go is a hard requirement, not a preference: the headless `-tags server` build is CGO-free (the repo is on modernc.org/sqlite for the same reason), so a cgo engine like QuickJS would take that build away.
Values cross the boundary as JSON, through the VM's own JSON.parse and JSON.stringify rather than goja's Go-value wrappers. That is what makes the round trip faithful: a Go map handed to goja with ToValue is a proxy for which Array.isArray reports false and key order is a map's, whereas JSON.parse produces genuine JavaScript objects and arrays. null, [], {} and key order all survive, which is the property that ruled Lua out.
Index ¶
Constants ¶
const Name = "javascript"
Name is the language this runtime registers under.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime is the goja implementation of runtime.ScriptRuntime.
func New ¶
func New(pool *runtime.ScriptPool) *Runtime
New returns the JavaScript script runtime, bounded by pool. A nil pool gets a private one at the default size — convenient for a test, wrong for the app, where every runtime shares one budget.