Help us shape the future of Go! Take the 2026 Go Developer Survey

js

package
v0.64.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
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.

func (*Runtime) Check

func (*Runtime) Check(src string) error

Check compiles src without running it, so the editor's syntax check and the engine share one compiler.

func (*Runtime) Name

func (*Runtime) Name() string

Name implements runtime.ScriptRuntime.

func (*Runtime) New

func (r *Runtime) New(src string, outputs int) (runtime.ScriptInstance, error)

New compiles src into an instance holding its own VM and state object.

Jump to

Keyboard shortcuts

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