Expand description
An in-process mock DOM — the shared oracle that gives the DOM builtins
identical semantics on the tree-walker and the register VM (they both run
call_builtin), so the sacred WASM==VM==tree-walker invariant holds even
though the DOM is browser-only.
A DOM-driving LOGOS program builds a node tree and mutates it; on the native
tiers those operations land here (a thread-local handle table + an ordered
op-log), and on the wasm tier the SAME operations land in the emitted module’s
dom_* host imports — a MockDom linker in tests, the real browser DOM in
production. Because DOM ops emit no Show, the existing output differential
passes trivially; the DOM EFFECTS are compared via op_log/render, keyed
by node creation ordinal (raw handles legitimately differ per tier), which
the wasm MockDom reproduces because it creates nodes in the same order.
Modeled on logicaffeine_base::money’s AMBIENT_RATES thread-local.
Structs§
- Dispatch
Path - Where an event dispatched at one element goes: the listeners it reaches, in order, and whether one
of them cancels its default action —
dispatch_path. - DomRecorder
- The mock DOM: a handle table of nodes + the ordered op-log. Handle 0 is always
body, the render root. - DomState
- Everything a document holds: its tree, its once-per-mount declared head, and the shell it is
served in. What
takesaves andrestoreputs back. - Dropped
File - A file a drop carries: its name, the type its author declared for it when they declared one,
and its content. Its size is always its content’s length, as a browser’s
File.sizeis; its type (DroppedFile::mime_type) is the declared one, and otherwise what a browser names the file from its name (browser_mime_type). - Fetch
Request - One recorded fetch request — the tw≡VM parity surface for the request side (what was asked for, with what method/body/headers, and its control state).
- HeadTag
- One element of a document’s
<head>: its tag, its attributes, and the text it holds — a<title>’s, a<style>’s or<script>’s raw content, nothing for a void element. - Link
- A link a click lands on: the nearest
<a href>that is the clicked element or holds it, as a browser’s activation behaviour finds it. - Validity
- Why a form control is invalid, flag for flag as a browser’s
ValidityStatereports it. The constraints modelled arerequired,type="email"/url"/number",minlength/maxlength,patternand a number’smin/max/step;min/max/stepon the date and time types are not modelled.
Enums§
- DomOp
- One recorded DOM mutation. Nodes are referenced by their creation ordinal
(the handle, assigned sequentially from 0 =
body), so op-logs compare equal across tiers regardless of how each tier numbers its handles internally. - RouteOp
- One recorded navigation — the router’s history op-log entry: a pushState (
replace: false, a new history entry) or replaceState (replace: true, swap the current one) within the page, or a document load. Compares equal across tiers; the wasmMockDomrecords the same shape. - Toggle
Control - A control whose CHECKED state a click moves. See
DomRecorder::toggle_control.
Constants§
- CSRF_
META_ NAME - The
<meta name=…>a document carries its CSRF token in — written by the server that composes a page under a## Session, and read by every tier’s host when the page makes a request. - FETCH_
ALLOWED_ REQUEST_ HEADERS - The request headers
fetchSendallows (lowercase). A header outside this list fails the request immediately with"network: header not allowed: <name>"— the browser would silently strip or reject forbidden headers per-engine; the contract makes the denial explicit and identical on every tier. - FETCH_
REQUEST_ BODY_ CAP - The largest request body
fetchSendwill put on the wire — exceeding it fails the request immediately with the"toolarge"transport error (never a silent truncation). Shared by every tier (native recorder, MockDom, browser host) so behavior cannot drift. - FETCH_
RESPONSE_ BODY_ CAP - The largest response body a fetch will deliver — a larger body is dropped and the
request fails with
"toolarge"(the callback still runs and can read the error). - LISTEN_
CAPTURE - LISTEN_
ONCE - LISTEN_
PASSIVE - LISTEN_
PREVENT - Event-modifier bits a listener registration carries (
listenFlags,DomOp::Listen) —.prevent/.stop/.once/.capture/.passive, one bit each, in that order. Every host dispatches by them as a browser does (dispatch_path), except.once, which the lowering keeps itself: a host never retires a listener on its own. - LISTEN_
STOP - NON_
BUBBLING_ EVENTS - The events a browser dispatches WITHOUT a bubbling phase — the ones a listener on an ancestor hears only by capturing. Every other event bubbles.
- STREAM_
ID_ BASE - The first id of the range a patch stream’s emitter names (
vdom.lg’svdWire); every id below it is a creation ordinal this recorder minted itself, so the two never collide. - STUB_
CONTENT_ TYPE - Every request the run registered, in id order — the tw≡VM parity surface for
the REQUEST side (method, url, body, headers, timeout, abort state).
The content type an answer a test arranged (
stub_fetch) is served with, on every tier.
Functions§
- add_
class - Add a class to an element’s class list, leaving the others alone.
- add_
event_ listener - adopt
Adopt(parent, node, tag)— seeDomOp::Adopt.- adopt_
text AdoptText(parent, node, text)— seeDomOp::AdoptText.- answers_
by_ itself - Whether the browser’s own default action of
verbon the elementselectornames changes it — typing enters text into a control that takes typed text, choosing selects an option the<select>offers — so the verb is answered whether or not the page listens: the value it entered is on the page, and the control’s validity with it. A click, a press, a submit and a hover answer only through a listener (a checkbox’s click is answered by its toggle, where the click is decided). - append_
child - arrive
- The page arrives, served in
document— the shell HTML a browser loads it in: from now on this world’s document starts from that shell’s head, this load and every reload after it, so a page the host drives in process arrives in exactly the document a browser holds. The shell’s body is not read: the page paints its body itself. - assign_
location - Another document loads at
url— a link followed, or arequest_loadcarried out. The page that asked is gone; the location and the back stack move tourl; the load is the first thing the new document’s navigation log records (RouteOp::Load); and the document is empty, since whaturlserves is another page’s content, outside the page under test. The test’s own answers for requests survive, as they do across a reload. - atomically
- Runs
changeagainst the document and keeps what it did only if it succeeds: on anErrthe document is exactly as it was before, op log included. - attribute
- One of
node’s attribute values. - begin_
dispatch - Simulate an event dispatch on the NATIVE tiers: look up the
(node, event)handler, set the current event (its target + value), and hand the closure back to the caller to invoke (the interpreter owns closure invocation). Returns the closure, orNoneif no handler is registered. - begin_
dispatch_ keyed begin_dispatch, naming the key for a keyboard event soeventKeycan report it.- begin_
fetch_ resolve - Deliver request
reqwithstatus/headers/body: record its per-request response, point the current-delivery cursor at it, and hand back its completion closure for the caller to invoke.Noneif the request is unknown or already FINAL (aborted/failed/delivered — the anti-double-delivery rule). - body
- browser_
mime_ type - The type a browser gives a file named
name: by the extension after its last., from the browser’s own table;""for a name with no extension, or with one the table does not name. - changes_
state - Whether a request changes state on the server, and so must prove it came from the page the
server handed out:
POST,PUT,PATCH,DELETE. - clear_
children - clipboard
- What is on the clipboard (
""when the page has never written to it). - control_
value - A control’s value as a browser reports it — see
Validity. - create_
element - create_
element_ as - A new element under the id a patch stream names for it — see
STREAM_ID_BASE. - create_
text_ node - create_
text_ node_ as - A new text node under the id a patch stream names for it — see
STREAM_ID_BASE. - deliver_
pop - Deliver a popstate (back/forward) at
path: move the current path and hand back every registered handler closure, in registration order, for the caller to invoke (the interpreter owns closure invocation) — none when nothing is registered. Deterministic — never a real browser event. - dispatch_
path - The walk
eventdispatched attargettakes, as a browser dispatches it: the capture-phase listeners of the target’s ancestors from the root down, the target itself, then — when the event bubbles (event_bubbles) — the other ancestors’ listeners from the target back up. A listener registered.stopends the walk after it. The target is always on the walk: whether anything there answers is the page’s own dispatcher’s to say. - document_
head - The document’s head as it stands — the shell it arrived in with the page’s own
Head:merged over it — element by element in the reference renderer’s serialization.Nonewhen the head holds no element. - downloads
- Every download the page has offered, in order.
- dropped_
file - The file the drop being delivered carries (
set_dropped_file) — no file (no name, no type, no content) when no drop has carried one. - element_
blur element.blur(): the focused element loses focus to nothing andbluris raised on it (take_raised_events); an element that does not have focus is left alone.- element_
focus element.focus(): a focusable element that does not have focus takes it, the element that had it losing it first — and theblurandfocusthat raises wait intake_raised_eventsfor the host to deliver once the turn that asked has committed, as a browser delivers them. Anything else is left alone: an element that cannot take focus, or already has it.- end_
dispatch - end_
fetch_ resolve - end_
hydration - Ends the hydration a stream opened, as the stream ends; answers its mismatches (
0when the stream hydrated nothing). - enter_
value - The value a visitor’s
Type/Chooseleaves in the controlselectornames before the verb raises its events — the browser’s own default action of typing (the text replaces what the field held) and of choosing (the option whose value, or else whose text, isvaluebecomes the select’s value). Recorder state rather than an op: it is the visitor’s act on the document, not something the page asked for. Other verbs, a control the verb cannot act on (answers_by_itself), and a choice no option offers, leave it alone. - event_
bubbles - Whether
eventbubbles in a browser — seeNON_BUBBLING_EVENTS. - event_
key eventKey() -> Text— the key of the keyboard event being dispatched,""otherwise.- event_
target - event_
value - fail_
fetch - Deliver a structured transport failure for
req(same finality rule). - fetch_
abort fetchAbort(reqId)— the request becomes FINAL with the"abort"error; a late response can never deliver.- fetch_
requests - fetch_
send fetchSend(method, url, body, headers, onDone) -> Int— register a request, returning its correlation id. Contract violations (oversized body, disallowed header) fail the request immediately with a structured error.- fetch_
set_ timeout fetchSetTimeout(reqId, millis)— arm (> 0) or clear (0) the timeout.- fetch_
start - The
fetchText(url, onDone)sugar — a GET through the correlated engine. - focus_
by - The default focus action of
verbon the elementselectornames, carried out, as the events it raises in the order a browser raises them:bluron the element that lost focus, thenfocuson the one that gained it — each(element, event), before the verb’s own events. Nothing when the selector names no element (the verb reports that itself) or focus stays put. - focus_
for - The default focus action of
verbonnode, carried out:focus_target, thenmove_focus. What a driving verb does before it raises its own events. - focus_
target - Where the default action of
verbonnodesends keyboard focus (crate::semantics::drive::Verb::focus_target):Some(element),Some(-1)for off every element,Nonewhen focus does not move. - focusable
- Whether
nodecan take keyboard focus, as a browser decides it: a control that is notdisabled(button,select,textarea, aninputother thantype="hidden"), a link or image-mapareawith anhref, aniframe, asummary,audio/videoshowingcontrols, and any element carrying atabindexor an editablecontenteditable. - focused
- The focused element, or a negative handle when nothing is focused.
- follow_
response - A form the browser submitted itself (a
POSTno listener cancelled) is answered with a new document: the browser is aturl, the address it posted to, and the document is the response. The document is the one a browser builds for the response’s type: atext/htmlresponse is the page it holds — its<head>and<body>, or the markup as the body when it is a fragment; a JSON response is shown in the browser’s JSON viewer, the raw text in a preformatted block; any other response is shown as plain text. The test’s answers for requests survive, as they survive a reload. - form_
constraints - The controls that stop
formfrom being submitted, in document order: none when the form saysnovalidateor itssubmittersaysformnovalidate, else every control the form owns whosevalidityis not valid. - form_
fields - The
(name, value)of every named field insidenode— a form’s payload, in document order. - form_of
- The
<form>nodebelongs to, if any: itself when it is one, else its form owner. - free_
node - get_
checked - get_
text - get_
value - go_back
Go back.— step one entry back and hand over the route handlers to fire, exactly as a real popstate would.Nonewhen there is nowhere to go: the first page a visitor lands on has no previous entry, and a browser’s Back button does nothing there rather than inventing one.- has_
attribute - Whether
nodecarries attributenameat all — the PRESENCE question an HTML boolean attribute is asked with ("#b" is disabled). Comparing its value against a string would call an enabled control disabled, sincedisabled=""is the enabled-looking spelling of disabled. - head_
html - The head HTML the last mounted page declared, if it declared one.
Nonemeans the page has noHead:— which is not the same as an EMPTY head, and the difference is whether the default shell’s title stands. What a server composes the page’s document from. - hydrate
Hydrate(root): the markuprootholds is the page’s first paint, and the stream’s claims adopt its nodes — seeDomOp::Hydrate. The root’sdata-logos-prerenderedmark goes with it.- init_
route - Seed the initial location (a refresh / deep-link: the app boots already AT this path with this query string). Called by tests before a run.
- insert_
before - is_
shown - Whether a visitor would SEE the first element matching
selector— seeDom::shown. - link_of
- The link a click on
nodelands on (Link), if any. - listen
listenFlags(el, event, flags): registereventonnodewith the behavioural modifiersflagsnames (LISTEN_PREVENTand its siblings), replacing the flags an earlier registration gave it.dispatch_pathwalks by them.- move_
focus - Move keyboard focus to
target(-1: off every element), as a browser’s focusing steps do:(blurred, focused)— the element that lost focus and the one that gained it,-1for none — for the caller to raiseblurand thenfocuson;Nonewhen focus is already there. - navigate
navigate(path)— history.pushState: record the navigation, move the path.- node_
address - A selector naming
nodeby the identity a browser’s reconciler keeps it by through a repaint:#idwhen the element carries an id that names it,bodyfor the page’s body, else its PLACE — its child index under each ancestor frombodydown, and its tag — whichquery_selectorresolves to whatever element of that tag stands there now. The place form is not one any page can spell: it begins with a character no selector contains, and is resolved before the selector grammar is consulted. Empty for a node that is not an attached element. - note_
event_ listener - Record that a listener was attached, without handing the recorder a closure to fire.
- notifications
- Every notification the page has raised, in order.
- notify
Notify "…".— a notification the page raised,(message, tone).- offer_
download Download <content> as "<name>".— a file the page offered,(name, content).- on_
route onRoute(handler)— register a popstate handler closure: a back/forward fires it, and every other handler registered before it, as a browser’spopstatereaches every listener.- op_log
- The ordered op-log recorded so far — the parity assertion surface.
- parse_
head - Head markup — a page’s rendered
Head:, or the head of the shell it is served in — as its elements, in order. What a browser’s parse keeps of it: element names and attribute names fold to lower case, the first of two same-named attributes wins, character references decode (never inside<style>/<script>), text between elements is formatting and is dropped, and an<html …>is a statement about the document element, never an element of the head. - pattern_
matches - Whether
valuematches a control’spattern=— an ECMAScript regular expression matched against the WHOLE value (^(?:pattern)$), with thevflag a browser compiles it with:\d,\wand\sare ASCII digits, word characters and JavaScript’s whitespace, and a class may nest classes and combine them with--and&&. A pattern that is not a valid expression constrains nothing, as in a browser. Thevflag’s strings —\q{…}and the string properties (\p{RGI_Emoji}) — are refused by name: the engine here cannot express them. - prevent_
default - Record that a listener on
nodeforeventcancels the browser’s default action. - publish
Publish M on "t".— the frame the page handed to the transport,(topic, message).- published
- Every frame the page has published, in order.
- query_
selector - query_
selector_ all - Every node matching
selector, in document order. - reload
Reload the page.as a browser reloads it: a fresh document loaded from the SAME server at the SAME address, arriving in the same shell (DomRecorder::next_document).- remove_
attribute - remove_
class - Remove a class from an element’s class list, leaving the others alone.
- remove_
node - render
- render_
children - A deterministic render of the current tree rooted at
body. The HTML of a node’s CHILDREN — what a view value renders as. The fragment that holds a rendered view is scaffolding, never markup, so it never appears in the output. - render_
served renderas a browser must be sent it to build the same page: a control’s state is spelled the way HTML’s parser reads it back — a<select>’s value as itsselectedoption, a<textarea>’s as its content — and content a parser would lose a leading newline of carries one more. Whatlargo buildputs in a pre-rendered page’s body.- replace_
route replaceRoute(path)— history.replaceState: record the navigation (replace), move the path.- request_
load assignLocation(url)—location.assign: ask the browser to load the document aturlonce the running script is done. Everything the page draws until then is drawn into the page that asked, which the browser keeps on screen until the new document replaces it; a second ask before then replaces the first.- request_
reload location.reload(): ask the browser to load the page again once the running script is done.- reset
- Start a fresh DOM (call before each tier’s run so op-logs are comparable) — a fresh load of the page: its head is the shell’s again, whatever the last load merged into it.
- response_
body responseBody(reqId) -> Text— the delivered body;""while pending or failed.- response_
error responseError(reqId) -> Text—""when none (pending or delivered OK); otherwise"timeout"|"abort"|"toolarge"|"network: <detail>".- response_
header responseHeader(reqId, name) -> Text— a delivered response header, case-insensitively;""when absent.- response_
status responseStatus(reqId) -> Int— the delivered HTTP status;0while pending or on any transport failure (responseErrorthen names the failure).- response_
text - The
responseText()sugar — the body of the request CURRENTLY being delivered (set bybegin_fetch_resolve/fail_fetch, cleared byend_fetch_resolve). - restore
- Put back a document a matching
takereturned. - retire_
stream - A program starts: what an earlier program’s stream drew keeps its place in the document under ids this recorder mints, and the new program’s stream binds its own from the first.
- route_
ops - The recorded navigation op-log — the tw≡VM parity surface for the router.
- route_
path routePath() -> Text— the current location pathname ("/"at boot).- route_
query routeQuery(name) -> Text— a query param by name (""when absent).- rtc_
add_ ice - rtc_
create_ answer - rtc_
create_ offer - rtc_
data_ channel - rtc_
peer_ connection - rtc_
send - rtc_
set_ local - rtc_
set_ remote - scroll_
to Scroll to "#card".— the element a browser would have brought into view.- scrolled_
to - The element most recently scrolled to, or
-1. - select_
text Select the text in "#draft".— the element whose text a browser would have selected.- selected
- The element whose text was most recently selected, or
-1. - set_
attribute - set_
attribute_ value - Set an attribute from a VALUE rather than from a string — the ONE place the boolean-attribute
rule lives, so no two tiers can render
disableddifferently. - set_
checked - set_
dropped_ file - The file the drop being delivered carries: what
eventFileName/eventFileSize/eventFileType/eventFileBytesanswer on a tier with no real transfer to read. The host that delivers a drop sets it first (page_host::Drive::DropFile), exactly as a browser’s drop event carries its file into the listener it reaches. - set_
focus - set_
head_ html - Record the head HTML a page rendered, and merge it into the document’s head the way a browser
host does (
runtime.js’smergeIntoHead): each element with an identity replaces every element of that identity already there, and joins the head at its end; one without is simply added. Called once, at mount. - set_
html - set_
stream - set_
text - set_
title Set the title to …—document.title = …: the head’s first<title>holds the new text, or, when the head has none, a new<title>holding it joins the head.- set_
value - stub_
fetch - Arrange the answer to a request the page is expected to send. A later stub for the same (method, url) REPLACES an earlier one, so a test can set the scene and then change it.
- stubbed_
answer - The answer arranged for
req, if a test arranged one. - submits_
its_ form - Whether activating
nodesubmits its form: a<button>of typesubmit(a button’s type when it names none), or an<input>of typesubmitorimage. - tag_of
- An element’s tag, lowercased — what the browser’s DEFAULT ACTION for a click turns on. A click
on an
<a href>follows the link and a submit on a<form>posts it, whether or not the page is listening; a runtime that only fires listeners answers neither. - take
- Take the current document, leaving a fresh one in its place —
reset, but the document it replaces comes back to the caller instead of being dropped. A nested run (a candidate page tier compared against the reference) takes the caller’s document before it paints its own, andrestores it when it is done, so the caller’s own document survives the comparison. - take_
load_ request - Where the page asked the browser to go since the last look (
request_load) — taken, so the host carries each request out once, byassign_location. - take_
popped - Whether the browser stepped back through the history since the last look — the
popstatethe host then delivers to every route handler, as a browser raises it afterhistory.back(). Taken, so each step is delivered once. - take_
raised_ events - The events the page’s own element commands raised (
element_focus,element_blur) that the host has not delivered yet,(element, event)in the order they were raised — taken, so each is delivered once. Each element is found as the page stands NOW (it was recorded by itsnode_address, which survives the turn’s repaint), and an event whose element has left the page is dropped: nothing is listening there any more. - take_
reload_ request - Whether the page asked to be loaded again since the last look (
request_reload) — taken, so the host carries each request out once. - text_
content - The element’s text content: its own text plus every descendant’s, in document order.
- title
the title—document.title: the text of the head’s first<title>, its ASCII whitespace stripped from both ends and collapsed to single spaces;""when there is none.- to_
own_ server - Whether
urlgoes to the page’s own server: a URL with no scheme and no host of its own. Decided on the URL as the page wrote it, identically in every host. - toggle_
control - unlisten
- validity
- Why
nodeis invalid (Validity) — every flag clear for an element with no constraints or barred from them. Refused only for apattern=this tier cannot check (pattern_matches). - write_
clipboard Focus SEL.— the element the page’s keyboard input goes to.Copy "…" to the clipboard.— the text a browser would have put on the clipboard.