Expand description
quickjs — an embeddable JavaScript engine written in pure Rust.
The crate is being built as a drop-in replacement for
bellard/quickjs; the language level
tracked is the upstream release whose version string is
COMPAT_VERSION.
§Current state (v0.4.0 — milestones M0–M6)
Source is parsed, compiled to bytecode and executed: Context::eval runs a
script and returns its completion value, and Context::output holds whatever
print wrote.
let rt = quickjs::Runtime::new();
let mut ctx = quickjs::Context::new(&rt);
ctx.eval("print(1 + 1)").expect("runs");
assert_eq!(ctx.output(), "2\n");The standard library covers Object, Function, Array, String, Number,
Math, JSON, Reflect, Date, RegExp, Symbol, Map/Set, BigInt,
TypedArray, DataView and the error classes; the ES6+ runtime is in place
(class, destructuring, generators, Proxy, Promise/async, for await); and
ES modules run through Context::eval_module.
§Not there yet
Every gap below is a loud failure rather than a wrong answer:
- private class fields (
#x) are rejected by the compiler with aSyntaxError; - the
std/oshost modules and the event loop are absent, sosetTimeoutis undefined and a script cannot touch the filesystem; Iteratorhelpers andRegExp.escapeare missing, andRegExplookbehind does not parse;- the host API is still small: a script can be evaluated, but Rust cannot yet register a native function on the global object or call a JavaScript function back.
See docs/requirements.md in the repository for the milestone plan and
docs/test262-status.md for the measured language coverage.
Re-exports§
pub use interp::Interp;pub use interp::Signal;pub use object::Callable;pub use object::JsObject;pub use object::ObjectKind;pub use object::Property;pub use value::Cell;pub use value::JsString;pub use value::Value;pub use js_compile;pub use js_parse;pub use quickjs_regexp as regexp;
Modules§
- bigint
- Arbitrary-precision integers, the engine’s
BigInt. - builtins
- The standard library: the globals a script reaches without an import.
- interp
- The bytecode interpreter.
- module
- The module system: records, linking, namespaces, and evaluation.
- object
- The object model: property tables, arrays, functions, and the prototype chain.
- value
- JavaScript values, and the conversions between them.
Structs§
- Collect
Stats - Statistics returned by
Heap::collect. - Context
- An execution context: a global object plus the builtins installed on it.
- Gc
- A strong, reference-counted handle to a heap value.
- Heap
- Owns the live-object registry for one JavaScript runtime.
- Runtime
- A JavaScript runtime: one heap, one memory limit, one set of host hooks.
- Tracer
- Visitor used by
Traceimplementations. - WeakGc
- A non-owning handle to a heap value.
Enums§
- Error
- Error raised by the engine.
Constants§
- COMPAT_
VERSION - Version string of the upstream QuickJS release this port tracks.
Traits§
Functions§
- is_
module_ source - Whether
sourceshould be evaluated as a module, decided the wayqjsdecides.
Type Aliases§
- Result
- Convenience alias used throughout the crate.