Skip to content

Renderer pipeline: pages run their scripts (7.17, 7.15 renderer half; includes #294 and #295) - #298

Closed
atiernan wants to merge 21 commits into
claude/phase7-integrationfrom
claude/renderer-pipeline
Closed

atiernan wants to merge 21 commits into
claude/phase7-integrationfrom
claude/renderer-pipeline

Conversation

@atiernan

Copy link
Copy Markdown
Member

Renderer pipeline: the page runs its scripts (7.17, and 7.15's renderer half)

This branch contains #294 (claude/html-scripts) and #295 (claude/webidl-bindings), merged into claude/phase7-integration, so it is one big PR. Review the three parts by commit.

What it does

  • One engine host. Phase 7.15 (script half): scripts run as the parser reaches them; document.write; proven incremental driver #294's PageState and WebIDL bindings (7.12): generated glue, conversions, overloads, wrappers, DOMException; DOM, Window, Location, History, Navigator and console exposed to script #295's page::Page were each a clazel-js Host; scripting state now lives in page::Page (script field) and the parser's tree moves to Page::arena when it is done. Both sides made natives re-entrant: one API, Arc<NativeFn> with Send + Sync closures; Scope::shared_function and SharedNativeFn stay as aliases. Every test from both sides is kept and passes.
  • scripting::Page::for_document (clazel-web scripting/bound.rs): takes the renderer's parsed tree, reaches its script elements in tree order through 7.15's processing model, and installs the bindings plus what HTML adds: setTimeout/setInterval/clear*, queueMicrotask, requestAnimationFrame, performance.now, localStorage, document.write/cookie/readyState/currentScript. The event loop (event_loop.rs) drives timers and microtasks; DOMContentLoaded/load/readystatechange reach addEventListener listeners. Cookies, storage, Navigate, UpdateUrl and console go through PageHooks.
  • Renderer (clazel-renderer): scripts run before the first paint; FetchScript for external ones (ScriptResponse/Body/End/Failed back); an event loop between kernel messages; after a script changes the document: re-collect style sources, title, layout, paint. location.href sends Navigate, pushState/replaceState send UpdateUrl; a clicked javascript: link (or location set to one) runs in the page and is never a Navigate. The socket is shared with the natives (page/link.rs): document.cookie/localStorage wait for the kernel's answer mid-script, other messages are kept and read next.
  • Line scripts retired: script.rs and its parser are deleted; a kind 1 commit is JavaScript run in an empty document with the same messages. Host tests, adversarial run, exit demo and the WPT cookies/ run send the same messages from JS (the cookies run can now write any cookie text, so no case is skipped).

Not done / deviations (see crates/clazel-renderer/README.md)

  • Scripts run after the whole document is parsed (the incremental driver cannot hand its tree to a script to change); scripts see the whole tree; document.write from a parser-inserted script is reported, not run.
  • Scripts inserted by scripts do not run (7.13's insertion steps); no fetch()/XHR; no on* attributes; no click events on elements (only link clicks).
  • WPT webstorage/ and cookies/ as real testharness.js pages through the kernel are not done; the existing cookies run is converted to JS instead.
  • Real-time timer wakeups rely on a 20 ms read timeout set on the renderer's socket before the sandbox (unix only, untested on Linux seccomp / Windows). No script time limit yet (7.19).
  • run_graphics, run, run_with_width now take owned Read + Send + 'static / Write + Send + 'static; the page tests' call sites changed accordingly. The bad-script host test now expects exit 0 with an uncaught ReferenceError on stderr (exit 64 existed only for the line format).

Verification

Local: cargo test -p clazel-web -p clazel-renderer -p clazel, clippy, cargo xtask check pass. cargo xtask verify --changed result is in the PR discussion. CI proof jobs need approval.

🤖 Generated with Claude Code

atiernan and others added 21 commits November 23, 2026 10:46
dispatch_seq folds the spec's one-token step over a sequence of tokens;
incremental_new_ensures and incremental_pump_ensures state what the
incremental driver (exec::incremental, next commit) is to meet: the
initial parser, and a pump that leaves the parser where the spec's step
takes it over some tokens, returning for actions, at the insertion point,
or once stopped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…shared natives

WebIDL attributes are accessor properties on prototypes (WebIDL §3.7.6),
so item 7.12 needs them in the engine:

- clazel-js-vm: an accessor property is an ACCESSOR attribute bit and a
  Cell::Accessor pair in its slot. OrdinaryGet (§10.1.8.1 steps 4 to 8)
  and OrdinarySetWithOwnDescriptor (§10.1.9.2 steps 4 to 7) call the
  getter and setter with the receiver, for property reads and writes,
  global identifiers and primitive bases; ValidateAndApplyPropertyDescriptor
  (§10.1.6.3) gets its accessor steps (2.c, 5.c, 5.d, 6.a, 6.b); object
  literal getters and setters (DefineMethod forms 1 and 2) run; the
  instanceof operator (§13.10.2, OrdinaryHasInstance §7.3.21) runs.
- clazel-js-builtins: ToPropertyDescriptor (§6.2.6.5) reads get and set.
- clazel-js: define_property takes accessors; get_own_property;
  delete_property, new_array, new_array_from and is_array over the VM's
  arrays; shared_function, a re-entrant native for Sync closures (open
  question 14's proposal, beside function, which keeps its Busy rule).

The Test262 runners gain two classifications for tests that instanceof
now reaches and that stop at the missing eval (fail stays 0). The API
test that listed arrays and delete_property as NotImplemented now asserts
that they work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Scope::function and define_method take Fn + Send + Sync, and the table
holds each closure in an Arc that a call clones, so JavaScript that calls a
native function while it is running runs it again, nested, instead of
getting Error::Busy. HTML's document.write needs this: it runs the parser,
which runs a script, which calls document.write (item 7.15). The test that
pinned Busy now checks a three-deep re-entrant call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The spec and the contracts first (CLAUDE.md rule 3); the exec functions
and their theorems follow in the next commit.

- set_data: DOM §4.10 "replace data" with offset 0 and count the node's
  length, which is what CharacterData's data setter (and textContent and
  nodeValue on character data) do. Requires a Text, Comment or
  ProcessingInstruction node.
- set_wrapper: the wrapper slot Phase 4 reserved becomes the bindings'
  object id; nothing else changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… step's contract

exec::incremental::Incremental is Phase 4's "a driver, not a restructured
spec": the proven tokenizer and step over an input stream that grows at
the insertion point (document.write), pausing after every step that asks
for an action (ScriptReady), at the insertion point, and at the end of an
input that is not closed (a document.open parser). Verus proves that every
call meets its callee's contract, that the invariant holds after every
method, that every pump ends, and incremental_pump_ensures: the parser after
a pump is the parser before given some tokens by the spec's step. It is not
proven equal to parse; the html5lib document cases run through it and give
parse_real's tree, and cases naming no scripting flag are now checked with
scripting on as well (all 1,931 give the same tree).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HTML's "clean up after running script" performs a microtask checkpoint when
the last script on the stack returns; a host that runs a page's scripts
from one scope (item 7.15) reaches the job queue there. Runtime::run_jobs
now calls it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The exec functions meet the contracts of the previous commit, and Verus
proves them (477 verified, 0 errors locally):

- theorem_set_data_wf and theorem_set_data_host_acyclic: replacing all of
  a character data node's data keeps wf and host_acyclic, the node keeps
  its kind (and a processing instruction its target), its data is the new
  data, and every other node is unchanged.
- theorem_set_wrapper_wf and theorem_set_wrapper_host_acyclic, through
  lemma_set_wrapper_wf (no clause of wf_with reads a wrapper): the slot
  holds the given id and nothing else changes.

Two mutations, each killed with a certificate: set-data-keeps-old and
set-wrapper-ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ppers, DOMException

Item 7.12 over clazel-js's public API:

- xtask/src/bindings/glue.rs: cargo xtask bindings now also writes
  src/generated/bindings.rs from the vendored IDL: for each exposed
  interface a trait the platform implements (IDL values as Rust types;
  every method defaults to a NotSupportedError naming the member), a
  native function per member (this check, argument count, conversions,
  overload resolution, the call, the result), and the installation of
  interface objects, prototypes, constants, attributes and operations
  (WebIDL §3.7). Dictionaries, enumerations and unions become Rust types
  with their conversions (§3.2.18, §3.2.19, §3.2.24). Members it cannot
  bind are listed with the reason in the file's header. check keeps
  failing when the file is stale.
- convert.rs: §3.2 for every type used (ConvertToInt with EnforceRange
  and Clamp, float and double, DOMString with LegacyNullToEmptyString,
  ByteString, USVString, object, interface, callback interface and
  function, sequence from an Array).
- overload.rs: the effective overload set and the overload resolution
  algorithm (§2.5.8, §3.6).
- platform.rs: one wrapper per platform object, made on first access with
  its unforgeable members and kept by the platform; brand checks;
  [SameObject].
- install.rs: [Replaceable], [PutForwards]; exception.rs: DOMException.
- tests/bindings.rs: idlharness-style checks over a small platform.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scripting::Page parses a document with the scripting flag on through
clazel-treebuilder's incremental driver and runs its scripts through
clazel-js's public API, its state in the engine's Host:

- "prepare the script element" (HTML 4.12.1.1) on ScriptReady: the type
  string, classic and module scripts, inline and external ones (fetched by
  the embedder: take_requests and fetched), async, defer, the pending
  parsing-blocking script, nomodule, event/for; mark as ready; execute the
  script element with document.currentScript; create and run a classic
  script, reporting exceptions, with a microtask checkpoint when the last
  script returns;
- the text mode's end tag script steps (script nesting level, parser pause
  flag, insertion point), the tokenizer blocked on a parsing-blocking
  script, abort a parser, and the end (deferred scripts, DOMContentLoaded,
  the load event's wait for async scripts);
- document.write, writeln, open and close, as edits of the input stream at
  the insertion point;
- module scripts' HTML half (module map, fetch a single module script,
  HostLoadImportedModule, fetch the descendants of and link, run a module
  script), which ends in the engine's NotImplemented today;
- evaluate a javascript: URL, and performance.now() coarsened to 100 us;
- the minimum globals before 7.12's bindings: document (write, writeln,
  open, close, currentScript), performance.now, a wrapper per node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion-timing pages

tests/scripting.rs checks each algorithm step: inline, external, async and
defer ordering, the parsing-blocking script, document.write (nested, split
tags, from external scripts), open and close, currentScript, javascript:
URLs, module scripts reaching the engine, performance.now's coarsening,
and a meta charset's reparse. It runs the six html5lib scripted_*.dat
tree-construction cases (2 pass, 4 listed: they need 7.12's DOM methods)
and 21 vendored WPT execution-timing pages with a stand-in for
testharness.js and testlib.js, which the engine cannot run yet (17 pass,
4 listed: eval, Location, DOM methods, timers).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A click on a link whose URL is a javascript: URL sends no Navigate: the URL
is the page's to evaluate in its own renderer (item 7.15), and the kernel
never sees it. This renderer does not host scripting::Page yet, so the
click does nothing for now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Page is the clazel-js host and clazel-webidl's platform (items 7.12, 7.13,
and 7.15's Window, Location, History, Navigator and console):

- Node, Document, DocumentType, DocumentFragment, CharacterData, Text,
  Comment, Element, NodeList, HTMLCollection, DOMTokenList and the exposed
  HTML element interfaces, over clazel-dom's proven operations (pre-insert,
  replace, replace all, remove, clone, attribute changes, set_data), with
  their preconditions checked first. A node's wrapper is kept in
  clazel-dom's wrapper slot, the others' in a side table.
- EventTarget, Event, CustomEvent, AbortController and AbortSignal over the
  events module's dispatch; listeners are JS values kept by handles, and a
  listener can read the event and change listeners while it runs; its
  exception is reported to the host's log. events::TargetId gains Object
  for targets that are not nodes.
- Window, Location (navigation through PageHooks::navigate), History
  (pushState and replaceState with "can have its URL rewritten", through
  PageHooks::update_url), Navigator with a fixed user agent string naming
  only Clazel, and console, written by hand (console.idl is not vendored),
  which logs to the host and never to the page.
- tests/bindings.rs runs script against parsed documents, with checks
  transcribed from WPT's dom/ and html/ tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Miri

The run took 201 s under Miri with every 7th page; two pages keep it near
130 s, well under the 300 s limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Miri found it: 4294967297 converted to long gave 0 under Miri and 1
natively, because step 10 used f64 %. Step 10 is now computed exactly on
the double's significand and exponent, and [Clamp]'s round-half-to-even
reads the parity of an integer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both sides made native closures re-entrant. One API: every closure is an
Arc<NativeFn> that is Send + Sync (#294's design); Scope::shared_function
(#295's name) stays as an alias of Scope::function, and SharedNativeFn is
an alias of NativeFn. Cargo.toml dependencies are the union.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne host (7.15, 7.12)

HTML's script processing and the WebIDL platform objects were each a
clazel-js Host. A runtime has one, so scripting's state is now a field of
page::Page (the parser's tree moves to Page::arena when the parser is done)
and Page forwards the module-loading and rejection hooks to it. Both sides'
tests pass unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…vent loop (7.15, 7.17)

Page::for_document takes the renderer's parsed tree, reaches its script
elements in tree order through HTML's script processing, and installs the
bindings with the members HTML adds (timers, queueMicrotask,
requestAnimationFrame, performance.now, localStorage, document.write and
cookie, readyState, currentScript). The event loop drives timers and
microtasks, lifecycle events reach addEventListener listeners, and cookies,
storage and navigation go through PageHooks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The graphical renderer hands the parsed tree to clazel-web's page and keeps
it running: scripts before the first paint, FetchScript for external ones,
timers and microtasks between messages, a restyle, layout and paint after a
script changed the document, a clicked javascript: link run in the page,
Navigate and UpdateUrl from location and history, and cookies and storage as
the kernel's messages waiting for their answers. The socket is shared with
the natives (page::link) and read with a timeout where the host allows one.

Phase 2's line scripts are retired: a kind 1 commit is JavaScript, run in an
empty document, with the same messages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…un are JavaScript

Phase 2's kind 1 format is deleted with its parser. The host tests, the
adversarial run, the exit demo and the WPT cookies/ run send the same
messages from JavaScript; the cookie run writes any cookie text as a string
literal, so no case is skipped for not fitting a line. The bad-script test
now expects an uncaught ReferenceError on stderr and exit status 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@atiernan

Copy link
Copy Markdown
Member Author

Contained in #300 (events and input, 7.14), which was cut from this branch; it carries #294, #295 and this PR's renderer pipeline. Branch kept.

This branch is waiting to be deployed

1 waiting deployment
full-verification — f0abc29f Waiting Nov 23, 2026 by atiernan via Approve the proofs #791
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant