A minimal JavaScript tree-walking interpreter written in MoonBit.
- Conformance on test262: each file is run in strict and non-strict modes and reported per mode. Do not sum the modes. Generate current numbers from CI artifacts with
make test262-report; see docs/TEST262.md. - JavaScript target: the engine builds with MoonBit's JS target and runs on Node.js.
- Benchmark dashboard: https://dowdiness.github.io/js_engine/benchmarks/
moon run cmd/main -- 'console.log(1 + 2)'
# 3moon run cmd/main -- '
function fib(n) {
if (n <= 1) { return n; }
return fib(n - 1) + fib(n - 2);
}
console.log(fib(10));
'
# 55More sample programs live in example/.
///|
test "README run facade" {
let (output, result) = @js_engine.run("console.log(1 + 2)")
json_inspect(output, content=["3"])
guard result == "undefined" else {
fail("result: expected undefined, got " + result)
}
}The public entry points are defined in js_engine.mbt:
run— evaluate a script; drains microtasks and timers before returningrun_compiled— evaluate the supported script subset through the opt-in closure-conversion prototyperun_module/run_modules— evaluate one or more ES modules and collect exportsrun_with_event_loop,run_microtask_checkpoint,run_timer_checkpoint,has_pending_microtasks,has_pending_timers— for hosts that want to drive the event loop themselves
Core ES5 plus selected ES6+ features: let / const / var, arrow functions, closures, classes, for / while / for-in / for-of, try / catch / finally, template literals, destructuring, spread / rest, ES Modules, Promises + microtasks, setTimeout / setInterval, ES6 Proxy (13 traps) + Reflect API (13 methods), TypedArrays (9 types), ArrayBuffer, DataView, RegExp, JSON, Map / Set / WeakMap / WeakSet, generators, Symbols.
For current conformance per category, see docs/supported-features.md.
token/ Token types and source locations
errors/ JavaScript error variants and formatting helpers
lexer/ Tokenizer
ast/ AST node definitions
parser/ Recursive descent parser with Pratt precedence
static_semantics/ Early-error and declaration-fact analysis
compiler/ Opt-in closure-conversion prototype
interpreter/ Wiring layer for runtime + standard library
interpreter/runtime/ Tree-walking evaluator, value model, host state
interpreter/stdlib/ JavaScript built-ins
cmd/main/ CLI entry point
cmd/test262_runner/ Native test262 runner
cmd/report_test262/ CI artifact report generator
benchmarks/ Benchmark workloads and runner
moon check # Type check
moon test # Run unit tests
moon fmt # Format code
moon info # Update .mbti interface files
moon build # BuildRun the test262 conformance suite with make test262. See docs/TEST262.md for prerequisites, filtering, and options.
- docs/README.md — start here for deeper material
- docs/development.md — maintainer workflow and generated files
- docs/ROADMAP.md — current status and active roadmap
- docs/supported-features.md — per-category conformance, Annex B, and missing features
- docs/GLOSSARY.md — terminology used in the code and docs
- AGENTS.md — MoonBit coding conventions (also used by AI agents)
Apache-2.0