8000 GitHub - ag-go/ekuma: A JavaScript engine in pure Go · GitHub
[go: up one dir, main page]

Skip to content
ag-goPublic
forked from hajimehoshi/ekuma

About

A JavaScript engine in pure Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

1,152 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ekuma

Ekuma is a JavaScript engine written in pure Go. Its bytecode interpreter runs without a JIT. It implements nearly all of ES2026. The Go API is unstable. See Status.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/hajimehoshi/ekuma"
)

func main() {
	var vm ekuma.VM
	script, err := vm.ParseScript("hello.js", `"Hello, " + ["wor", "ld"].join("")`)
	if err != nil {
		log.Fatalf("parse: %v", err)
	}
	result, err := script.Evaluate(context.Background())
	if err != nil {
		log.Fatalf("evaluate: %v", err)
	}
	fmt.Println(result.String()) // Hello, world
}

The zero value of ekuma.VM is ready to use. A VM must not be copied after first use.

Differences from other engines for Go

Engine Latest release Implementation Execution strategy Pure Go Host platforms ECMAScript Modules Intl Temporal
Ekuma v0.2.0 (2026-11-28) Written in Go Bytecode interpreter ✅ Go targets ES2026 ✅ ✅ ✅
goja None Written in Go Bytecode interpreter ✅ Go targets ES5.1, and much of ES2015 and later ❌ ❌ ❌
Sobek None Written in Go Bytecode interpreter ✅ Go targets ES5.1, and much of ES2015 and later ⚠️ Experimental ❌ ❌
moejs v0.1.1 (2026-11-15) Written in Go Bytecode interpreter ✅ Go targets Much of modern ECMAScript ✅ ⚠️ Partial ❌
otto v0.5.1 (2024-11-05) Written in Go AST interpreter ✅ Go targets ES5 ❌ ❌ ❌
modernc.org/jit/js v0.5.0 (2026-11-22) QuickJS, translated from C to Go Bytecode interpreter with a JIT ✅ linux/amd64 ES2023 ✅ ⚠️ DateTimeFormat and NumberFormat in en-US ❌
modernc.org/quickjs v0.27.0 (2026-10-24) QuickJS, translated from C to Go Bytecode interpreter ✅ macOS, FreeBSD, Windows (amd64, arm64)
Linux (386, amd64, arm, arm64, loong64, ppc64le, riscv64, s390x)
ES2023 ✅ ⚠️ DateTimeFormat and NumberFormat in en-US ❌
BeastJS v0.33.3 (2026-11-27) QuickJS, compiled to Go assembly Bytecode interpreter ✅ Linux, macOS, Windows (amd64, arm64) ES2023 ✅ ✅ Opt-in ✅ Opt-in
QJS v0.0.6 (2025-10-28) QuickJS-ng, compiled to WebAssembly and run by wazero Bytecode interpreter, with wazero AOT where available ✅ wazero targets ES2023 ✅ ❌ ❌
v8go v0.44.0 (2026-11-12) Bindings to V8 JIT compiler, or bytecode interpreter with --jitless ❌ Android, Linux, macOS (amd64, arm64)
Windows (amd64)
ES2025 ❌ ✅ ❌

“Go targets” indicates that the core engine has no explicit OS or architecture allowlist. Ekuma's CI covers Linux, macOS, Windows, 386 on Linux and Windows, and browser WebAssembly (js/wasm).

Ekuma uses a register-based interpreter, hidden classes, inline property caches, and dense array storage. JavaScript calls reuse interpreter stack space, including proper tail calls. On 64-bit platforms, a value occupies two words and can hold a number, a signed 64-bit BigInt, or a short string inline. Strings use WTF-8, preserving UTF-16 semantics and allowing well-formed strings to cross the Go boundary without transcoding.

Performance

Each value is the geometric mean of the benchmark times relative to Ekuma in one round of the suite. Lower is faster.

                     V8 benchmark    QuickJS
                     suite v7        microbench     Version
Ekuma                 1.00           1.00           v0.2.0-alpha.0.20261127145346-5a36a064fec5
goja                  8.30           6.78           v0.0.0-20261118204651-8dfece3d1e1d
Sobek                 8.38           6.82           v0.0.0-20261119094010-6eceb967bb5b
moejs                 1.07           1.41           v0.1.1
otto                 43.4    (9/10)   n/a           v0.5.1
modernc.org/quickjs   5.69           4.46           v0.27.0
BeastJS               1.00           0.800          v0.33.3
QJS                   7.70   (6/10)  6.94  (69/74)  v0.0.6
QuickJS (C)           1.76           1.20           v0.0.0-20260604125329-3d5e064e9dd6
v8go --jitless        0.970          0.810          v0.44.0
v8go                  0.0489         0.152          v0.44.0

Measured on 2026-11-28: Apple M3 Pro, macOS 27.2, go1.27.4.

(k/n) means that the engine and Ekuma both completed k of n benchmarks. The mean covers those paired results. See the benchmark method, individual results, and Ekuma CPU profile.

Host API

The API follows syscall/js for working with values and functions. JavaScript exceptions return to Go as errors. Script evaluation, function calls, and property operations take a context.Context for cancellation. The package documentation describes cancellation, host panics, and pending jobs.

Scripts

A parsed Script can be evaluated repeatedly. A second evaluation in the same realm throws a SyntaxError if the script declares a top-level let, const, or class. To share one parse across VMs, use ParseUnboundScript and bind the result in each VM with VM.BindScript.

Modules

Use VM.ParseModule or VM.ParseJSONModule to parse a module. For host-provided values, use VM.NewSyntheticModule with a map from export names to values or VM.NewDefaultExportSyntheticModule with a single default export. The host supplies a synchronous loader through VM.SetModuleLoader, including for import(). Module.Evaluate loads, links, and evaluates the module and returns a promise. To share one JavaScript module parse across VMs, use ParseUnboundModule and bind the result in each VM with VM.BindModule.

Realms

VM.NewRealm creates a global object with its own built-ins. Realms in a VM share values, jobs, and settings. Use separate VMs for independent JavaScript environments.

Promises and jobs

VM.NewPromise returns a promise and a resolver for completing it from Go. Pending promise jobs run before the outermost Go call that executes JavaScript returns. VM.SetUnhandledRejection receives rejections still unhandled after those jobs run. Promise continuations, including await, preserve the host value set by VM.WithContinuationData when they were registered.

Time and randomness

Date, Temporal, and Intl.DateTimeFormat use the local time zone by default. Override it with VM.SetTimeZone, the clock with VM.SetClock, and the source of Math.random with VM.SetRandomSource.

Intl

Import the optional intl package to enable Intl, locale-aware string and formatting methods, and additional Temporal calendars in ev 8000 ery VM.

import _ "github.com/hajimehoshi/ekuma/intl"

With Go 1.27.4 and default build flags, the import increases the hello-world binary from 9.1 to 18.0 MiB on macOS arm64 and from 12.0 to 21.2 MiB on js/wasm. VM.SetLocale overrides the host default locale. See the intl package documentation for host locale selection and License for distribution notices.

Agents

VMs on different goroutines share the memory of a SharedArrayBuffer as agents do: Value.SharedDataBlock returns the memory, which VM.ValueOf turns into a new SharedArrayBuffer of another VM.

Atomics.wait throws unless VM.SetCanBlock lets the VM block. When another VM notifies a waiter of Atomics.waitAsync, its promise is settled by the jobs that the waiting VM runs at the end of its current or next outermost call from Go. VM.AwaitJobs runs pending jobs. If none are ready, it waits for an asynchronous waiter to be notified or time out. With no pending jobs or waiters, it returns immediately.

Execution limits

Use a context with a deadline to cancel script execution and the promise jobs it runs. Property operations such as Value.Get and Value.Set can run JavaScript through getters, setters, or proxies. Give these operations a deadline too when working with values from unreliable scripts. Calls made inside a host callback also inherit the outer call's context.

Each VM runs in the host process. For untrusted scripts, run Ekuma in a separate process with operating-system resource limits. See Missing for the current gaps in per-VM resource controls.

Status

53,791 of the 53,795 tests of test262 pass (99.99%). The other 4 fail for known reasons, which test262-failures.txt lists.

Ekuma checks its pure Go implementation of Intl (ECMA-402) against ICU’s own tests for collation, segmentation, and locale-aware formatting. The suite also checks Unicode normalization and Temporal calendars. In 122 of 131 subtests, Ekuma matched the pinned ICU 78.3 and 79.1 fixtures on every case it ran. The other nine recorded 302 expected differences, including 281 where only the spacing in a formatted date range differed. The run had no unexpected failures. See the ICU coverage inventory.

Implemented

  • Nearly all of the syntax and standard library up to ES2026 and Annex B, with RegExp on its own backtracking engine
  • Temporal, explicit resource management, import defer, and the newer Error, Iterator, Promise and ArrayBuffer additions
  • ShadowRealm, which is a proposal and not yet standard
  • Decorators, auto-accessors (accessor) and decorator metadata (Symbol.metadata), which are proposals and not yet standard

Notes on behavior

  • Date truncates historical UTC offsets to whole minutes. Temporal.ZonedDateTime uses the full offset for a named time zone.
  • Ekuma's generated Unicode tables follow the Go release in go.mod (Unicode 17.0.0 for Go 1.27). The parser uses the build toolchain's Unicode tables for JavaScript identifiers and may reject letters added in later Unicode versions.
  • Native builds load named time zones from system zoneinfo and Go's time.LoadLocation sources. With GOOS=js, the host's Intl.DateTimeFormat must also recognize the zone. Local Date operations use the JavaScript host's Date by default.
  • Without Intl, Temporal supports only the iso8601 calendar, the toLocale*String methods of Date use a fixed English format and those of numbers ignore the locale, localeCompare compares normalized code units, and case conversion ignores the locale.
  • Intl.Collator follows the CLDR root collation, in which Han characters sort by code point, and the tailorings of CLDR; ICU sorts Han by radical and stroke in the root
  • Intl.Segmenter uses dictionary word boundaries for Chinese, Japanese, Thai, Khmer and Burmese text in every locale. Greek locales also tailor sentence breaks at question marks
  • Intl.DisplayNames uses a regular CLDR variant's canonical subtag when the display locale has no translation. If another subtag has no display name, the result is the canonical language code, or undefined with fallback: "none"
  • Intl.DurationFormat separates the fields of the digital style as CLDR's duration patterns do, such as 1.02.03 in Serbian, where ICU uses the time separator
  • Intl.DateTimeFormat uses the names that CLDR's root locale gives a metazone through another one, such as Greenwich Mean Time for London in winter, where ICU uses the offset
  • Best-fit locale matching keeps the lookup match of a request whose script is too far from every available locale, such as ha for ha-Arab, where ICU selects the default locale
  • A BigInt has at most 2^30 bits, as in V8: an operation or a conversion whose result would be larger throws a RangeError, and a larger literal is a SyntaxError. ValueOf panics for a larger *big.Int, and a Func that returns one throws a RangeError
  • Source phase imports and %AbstractModuleSource% exist, but importing the source of any module throws a SyntaxError, since no host API gives a module a module source
  • Function.prototype[Symbol.metadata] is null, as the spec text of the decorator metadata proposal defines it, so a class without decorators inherits null unless its superclass has metadata
  • The caller and arguments properties of sloppy functions, a legacy extension that the specification leaves to implementations, are accessors of each function. Browsers instead change the accessors of Function.prototype, which the specification defines to throw. As in SpiderMonkey, caller is null for a call from strict code, a generator, an async function or a built-in function. A proper tail call from strict code leaves no frame of the strict function, so the function that it calls sees the caller of the strict function instead
  • A WeakMap or WeakSet entry is stored with its key, since Go's garbage collector has no ephemerons. A value that refers back to its WeakMap therefore keeps the map alive for as long as the key is alive
  • When a Map or Set is compacted, an unfinished iterator keeps the positions of deleted entries until its next step so it can resume in insertion order

Missing

Host API for these, some of which the engine has and only the tests use:

  • Providing a module source object for import source and import.source()
  • Property descriptors, and listing the keys of an object
  • Limits on stack depth or memory, and statistics of the memory that a VM uses

Running the tests

go test ./...

Use go test -short ./... to run the local regression tests and skip external suites. Add -tags=ekumavalidate to check bytecode generation and execution.

Conformance tests

go test . runs the external suites when their checkouts are available. Set the environment variables below or place the checkouts at the listed paths under the user cache directory. The CI setup checks out Test262 in full, lists the V8 paths, and selects ICU files from the upstream path inventory.

Suite Environment variable Default cache path CI revision Expectations
ICU 78.3 (Unicode 17, CLDR 48.2 collation) EKUMA_ICU ekuma/icu Revision Expected failures
ICU 79.1 (CLDR 49 locale and formatting data) EKUMA_ICU_CLDR ekuma/icu-cldr Revision Expected failures
Test262 EKUMA_TEST262 ekuma/test262 Revision Expected failures
V8 Intl, mjsunit, Mozilla, and WebKit EKUMA_V8 ekuma/v8 Revision Test expectations

See the ICU fixture inventory for coverage and focused test commands.

When a fixture and a published specification or data release disagree, record what the fixture expects, which revision Ekuma follows, and what change would warrant revisiting the decision. Put the note beside the expected failure, or beside the local regression test when the fixture passes.

For V8's Mozilla suite, fetch the data revision pinned by V8 from the Ekuma repository root:

bash internal/jstest/checkout-mozilla.sh "$EKUMA_V8"

With both V8 and Test262 checked out, TestV8Test262 also runs V8's local Test262 cases.

Use -test262.dir or -v8.dir to select a checkout-relative directory, or the corresponding filter flag to match part of a test path.

go test -count=1 -v -run '^TestTest262$' . -test262.dir test/intl402/Collator
go test -count=1 -v -run '^TestV8$' . -v8.dir test/intl/collator

License

Ekuma's code is licensed under 0BSD. The data tables Ekuma generates from Unicode, CLDR, and ICU releases are licensed under the Unicode License v3. The historical Chinese and Korean calendar tables are licensed under the MIT License.

Every build includes Unicode character and emoji data, so all distributions must include the Unicode copyright and permission notice.

About

A JavaScript engine in pure Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0