Skip to content

WebIDL bindings (7.12): generated glue, conversions, overloads, wrappers, DOMException; DOM, Window, Location, History, Navigator and console exposed to script - #295

Closed
atiernan wants to merge 6 commits into
claude/phase7-integrationfrom
claude/webidl-bindings
Closed

atiernan wants to merge 6 commits into
claude/phase7-integrationfrom
claude/webidl-bindings

Conversation

@atiernan

@atiernan atiernan commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Phase 7 item 7.12 (WebIDL bindings), on top of the phase 7 integration branch (#286), as one pull request. It also exposes the DOM, Window, Location, History, Navigator and console to script through the bindings.

What landed (commit by commit)

  1. clazel-js-vm, clazel-js: accessor properties, instanceof, re-entrant natives. WebIDL attributes are accessor properties, and the VM had none.
    • The VM: an ACCESSOR attribute bit with a Cell::Accessor pair in the slot. OrdinaryGet and OrdinarySetWithOwnDescriptor now call getters and setters, for property access, global identifiers and primitive bases. ValidateAndApplyPropertyDescriptor gained its accessor steps.
    • Also in the VM: object-literal get/set (DefineMethod forms 1 and 2), and the instanceof operator (§13.10.2, OrdinaryHasInstance).
    • clazel-js-builtins: ToPropertyDescriptor now reads get and set.
    • clazel-js:
      • define_property now takes accessors, and get_own_property is new.
      • delete_property, new_array, new_array_from and is_array now work over the VM's arrays.
      • shared_function is new: a re-entrant native for Sync closures. This is open question 14's proposal, added beside function, which keeps its Busy rule and its test.
  2. clazel-dom: contracts of set_data and set_wrapper. Committed on their own first (rule 3).
  3. clazel-dom: exec functions and theorems for those two operations.
    • Theorems: theorem_set_data_wf, theorem_set_wrapper_wf, theorem_set_data_host_acyclic and theorem_set_wrapper_host_acyclic.
    • Two new mutations, each killed with a certificate: set-data-keeps-old and set-wrapper-ignored.
    • Locally Verus reported 477 verified, 0 errors.
  4. clazel-webidl: the bindings.
    • cargo xtask bindings now also writes src/generated/bindings.rs from the vendored IDL. For each exposed interface it writes:
      • a trait with IDL values as Rust types; every method's default throws a NotSupportedError naming the member;
      • a native function per member;
      • the code that installs the interface object, prototype, constants, attributes and operations.
    • Dictionaries, enumerations and unions become Rust types with their conversions.
    • The file is checked in, and check fails when it is stale.
    • The file's header lists every member left out, with the reason.
    • Hand-written runtime:
      • §3.2 conversions;
      • overload resolution (§2.5.8, §3.6);
      • wrappers: one per platform object, made on first access with its unforgeable members;
      • brand checks;
      • the extended attributes [SameObject], [Replaceable], [PutForwards], [LegacyUnforgeable], [LegacyLenientSetter], [Reflect] (for DOMString and boolean) and [Global];
      • DOMException, written by hand because webidl.idl is not vendored.
    • Tests in the style of idlharness, over a mock platform.
  5. clazel-web: Page. It is the clazel-js host and the bindings' platform.
    • DOM interfaces: Node, Document, DocumentType, DocumentFragment, CharacterData, Text, Comment, Element, NodeList, HTMLCollection, DOMTokenList, and the exposed HTML element interfaces. They run on clazel-dom's proven operations, with each operation's preconditions checked first.
    • Wrappers: a node's wrapper lives in clazel-dom's wrapper slot. Every other wrapper lives in a side table.
    • Events: EventTarget, Event, CustomEvent, AbortController and AbortSignal, over the events module's dispatch.
      • Nested dispatch works.
      • A listener's exception goes to the host's log, and dispatch continues.
    • Window, Location, History, Navigator:
      • Navigator has a fixed user-agent string that names only Clazel: Mozilla/5.0 (compatible) Clazel/0.0.
    • console: writes to the host's log, never to the page.
    • Hooks: location.href = …, assign, replace, the component setters and reload call PageHooks::navigate. pushState and replaceState call PageHooks::update_url. No renderer-side hook exists yet: clazel-renderer does not run clazel-web (that is item 7.17), and 7.16's UpdateUrl message is not built. These PageHooks methods are the hooks the renderer will implement; the page also records every call.
    • tests/bindings.rs runs scripts against parsed documents, with checks transcribed from WPT dom/ and html/ tests.

Not done

  • Indexed and named properties, so [LegacyUnenumerableNamedProperties] too. clazel-js never calls HostObject's exotic hooks.
    • list[0] does not work.
    • item() and namedItem() do work.
  • Anything that needs Symbols: iterable, maplike and setlike, and @@toStringTag. A sequence<T> is read from an Array only, by index.
  • Not exposed:
    • event handler IDL attributes (onclick, and the rest);
    • [SecureContext] members;
    • members whose types cannot be converted: Promise, record, buffer types, interfaces that are not exposed.
  • Setters: innerHTML, outerHTML and setHTML*. Fragment parsing into the arena is not done. Their getters work.
  • Methods: importNode, adoptNode, normalize, compareDocumentPosition, isEqualNode, the namespace lookups, most *NS methods, and insertAdjacent*.
  • Event loop: timers, queueMicrotask and requestAnimationFrame. That is the event loop, item 7.15.
  • Left to the agent doing 7.15: script elements, document.write and open, and modules. The tree builder's driver is untouched.
  • Not supported: AbortSignal.timeout and AbortSignal.any.

Deviations

  • The global object is an ordinary object standing in for the Window. clazel-js cannot yet make a host-object global.
    • Its prototype is Window.prototype.
    • There is no WindowProperties object.
  • Overload resolution converts arguments after choosing the overload. The values are the same. The only difference is the order between a conversion's exception and the "no overload matches" TypeError.
  • Wrappers are held by strong handles. There is no collector yet.
  • [PutForwards] sets with a strict Set.
  • history.state holds the value itself. There is no StructuredSerializeForStorage yet.
  • characterSet is always UTF-8. The arena does not keep the document's encoding.
  • Interface mapping:
    • An HTML element whose specific interface is not exposed gets HTMLElement.
    • A ProcessingInstruction gets CharacterData.
  • No user-facing dialogs: alert, confirm and prompt act as "cannot show simple dialogs" and only write to the log.
  • createElement's name check is an approximation of "valid element local name".
  • console formatting is not implemented: arguments are ToString'd and joined. %s-style directives are not interpreted.
  • Test changes:
    • clazel-js/tests/api.rs's what_the_vm_lacks_says_so listed arrays and delete_property as NotImplemented. Those three assertions now assert that the operations work.
    • Both Test262 runners gain two expected-failure classifications. These are tests that instanceof now reaches, which then stop at the missing eval. fail stays 0.
  • Section numbers carry † because WebIDL, DOM and HTML are not vendored at a pinned commit.

Verification

cargo xtask verify --changed origin/claude/phase7-integration did not finish, and there is no final line to report. It was not even CHANGED CRATES PASSED. Because xtask/ changed, the run checks every crate.

What the run did:

  • Static checks, rustfmt, clippy and tests: PASS, for the whole workspace. That includes both Test262 runners at fail=0.
  • Miri: passed for every crate in alphabetical order from clazel-a64 through clazel-psl. That covers clazel-dom and every clazel-js* crate.
  • Killed: the run was then killed by a signal (exit 144) while Miri ran clazel-renderer's tests. No test had failed at that point.
  • Never reached: Verus, Kani, the mutation runs and conformance for any crate.

Separately:

  • cargo xtask verify --part miri clazel-webidl,clazel-web: FAILED on conversions. ConvertToInt used float %, which under Miri gave 0 for 4294967297 → long. The last commit fixes that.
  • cargo xtask verify --part miri clazel-webidl then gave MIRI PART PASSED.
  • clazel-web's tests under Miri passed in that run, unchanged since.
  • Miri times:
    • Each test here takes 135–216 s under Miri.
    • Installing every interface alone costs about 135 s.
    • The slowest test is events_dispatch_through_the_tree, at 216 s.
    • All are under the 300 s limit, but not well under it, and none is ignored under Miri.
  • Verus: cargo verus verify on clazel-dom, run by hand from a clean build, gave 477 verified, 0 errors.
  • Not run locally: clazel-dom's mutations, including the two new ones.

CI's full verification has not run. Its proof jobs need a reviewer's approval of the full-verification environment, and this work is not done until that run is green.

🤖 Generated with Claude Code

atiernan and others added 5 commits November 23, 2026 10:47
…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>
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>
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>
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 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>
atiernan added a commit that referenced this pull request Nov 23, 2026
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>
@atiernan

Copy link
Copy Markdown
Member Author

Contained in #298 (renderer pipeline, 7.17), which merges this branch together with the other half so they verify as one. Branch kept.

@atiernan atiernan closed this Nov 23, 2026

This branch is waiting to be deployed

1 waiting deployment
full-verification — 3b0f35d0 Waiting Nov 23, 2026 by atiernan via Approve the proofs #788
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