Skip to main content

Crate zdc_runtime

Crate zdc_runtime 

Source
Expand description

The ZDeceptron JavaScript runtime, embedded and executable from Rust.

The runtime library that generated code links against is written in JavaScript, because it manipulates the DOM and there is no other way to do that (spec §14E.2). But verifying it must not require a JavaScript toolchain: needing Node to build ZDeceptron would be the first crack in the claim that a developer installs one binary and nothing else.

So the sources are embedded here and evaluated with a pure-Rust engine. cargo test covers the runtime; nothing else has to be installed.

§Two halves, and why the seam is a feature

Holding the runtime sources and running them are different jobs, and the evaluate feature is where they part. Everything above the seam is text and plain data — the .js and .css a bundle ships, and the signatures a capability is written against. Everything below it is boa_engine, a JavaScript interpreter written in Rust.

The seam is cut here rather than left implicit because boa_engine reaches getrandom, and getrandom will not build for wasm32-unknown-unknown without an entropy backend chosen by --cfg. zdc-codegen depends on this crate for seven const &strs, so without the seam the entire front end inherited that refusal and no part of this compiler could run in a browser (#171). See the feature’s comment in Cargo.toml for the dependency chain in full.

Structs§

Capability
One capability the compiler answers for the code it is running.
RuntimeError
An evaluation failure, with the engine’s own message.
Sandbox
A JavaScript sandbox the compiler owns, for running the code it just emitted — spec §17.4.8.

Enums§

Mode
Which build a runtime module is being emitted for — spec §16.3.1’s “ships nothing it does not use”, applied to the checks themselves.
Provided
What a capability may answer with.

Constants§

BASE_CSS
The base styling of the built-in elements, as classes.
CLOCK_JS
The clock: every "250ms", every frame and after "2s".
DEV_CLOSE
The line that closes one.
DEV_OPEN
The line that opens a block only a development build carries.
DOM_JS
DOM rendering. Requires a document, so it is embedded for shipping rather than for evaluation here.
DOM_SHIM_JS
The minimal DOM the runtime and everything downstream of it run against when there is no browser.
ELEMENTS_JS
The built-in view elements.
FOREIGN_JS
The lifecycle of a foreign … gives view: create, update, destroy.
KEYS_JS
Document key listeners: on key "Escape".
LIST_JS
Keyed list reconciliation: each, eachInto and the interim key function.
MARKUP_JS
The Prose render path — the one function in the runtime that parses HTML. Its own module so a program with no Prose does not ship it.
MEDIA_JS
media "…" — a CSS media query, as a signal that changes with it.
MODULES
Every embedded runtime module, by the path a bundle writes it to.
REMEMBERED_JS
The remembered placement’s store: localStorage, as a signal.
REQUEST_JS
The outbound request a request declaration is (#19).
RPC_JS
The client half of the derived boundary: $remote and $call.
SIGNAL_JS
The reactivity core: signals, derived values, effects, batching.
STORE_JS
Live sync for durable placement, and the transport seam it needs.
WIRE_JS
The wire format: how a ZD value survives JSON.

Functions§

eval_with_signals
Evaluate script with the reactivity core already in scope.
for_mode
One runtime module’s source, as the given build ships it.