Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
# Embedded headers hold the exact bytes of their text sources. Freshness tests
# re-read those sources, so Windows checkouts must preserve LF for every asset.
js/core/WebFront.js text eol=lf
js/core/dom-interpreter.mjs text eol=lf
js/core/bootstrap/* text eol=lf
js/core/favicon.ico binary
include/webfront/system/WebFrontJsData.hpp text eol=lf
Expand Down
17 changes: 17 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

## Unreleased

- DOM batch protocol (#380): bounded command 5, canonical uint32 LEB128 and UTF-8 codec,
interned names and correlated rejection callbacks. The optional embedded `webfront-dom.mjs`
validates the evolving tree before applying mutations, protects page-owned islands, and
rejects executable content and normalized unsafe URLs. Catch2 and the shared Jasmine
suite cover encoding boundaries, hostile batches and real WebSocket dispatch. ADR-003
specifies the wire contract; ADR-016 adds the module within the existing 150 KiB budget.
Follow-up: validate against per-node and per-child-set deltas, cap retained UTF-8 name bytes at
1 MiB per interpreter, and document the trusted-content model, event values and recovery after
residual exceptions. Real WebSocket tests cover events and listener cleanup; a C++ regression
covers sending through a lost UI link. The manual DOM benchmark is described in embedded assets.
Reserve batch id zero for uncorrelated rejections and require explicit nonzero C++ ids. Index
subscriptions by node and revoke islands by subtree traversal. Both codecs limit each batch to
131,072 operations; C++ reserves the counted operation total and rejects unused operands.
Event integration checks count identities/values independently of arrival order.
Reject `PROPERTY value` on `output` before applying a batch, preserving tracked children;
update output text with `SET_TEXT`. Use checked event-count indexing for MSVC analysis.

- The single-command test driver can set `--command-timeout` after browser/bootstrap startup,
within its unchanged overall `--timeout` deadline (#376). The watchdog regression deliberately
delays bootstrap beyond its command limit and requires the command's start marker before accepting
Expand Down
84 changes: 79 additions & 5 deletions docs/EMBEDDED_ASSETS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Embedded assets

The C++ library embeds only what every application needs: the browser bridge (`WebFront.js`), the
The C++ library embeds the browser bridge (`WebFront.js`), the optional DOM interpreter (`webfront-dom.mjs`), the
fallback page and module, and the bootstrap page and loader of the developer environment, with the
pinned release data (`Developer*Data.hpp`). Each is generated from a readable source under `js/core/`
(including the default favicon, `js/core/favicon.ico`) into a header under `include/webfront/system/`. Libraries such as React, Babel and Jasmine are not
Expand All @@ -23,8 +23,8 @@ outside the normative list of [ADR-016](adr/ADR-016-bootstrap-comme-socle.md), o
150 KiB. The budget counts decoded bytes (gzip streams are measured by their trailer), so it does not depend on the
encoding; the test also prints the encoded bytes and the size of the headers. Adding a resource means amending the ADR
and the list in the script together. `MinimalCoreAssetsRejectsUnlisted` proves the guard fails on an unlisted
header, a hidden payload and an oversized resource. `du -sh include/webfront/system` was about 2.5 MB when the epic began
and is 188 KB now.
header, a hidden payload and an oversized resource. `du -sh include/webfront/system` was about 2.5 MB when the epic began;
the guard reports current sizes.

## Maintenance

Expand All @@ -39,8 +39,8 @@ ctest --test-dir build -R 'Asset.*Fresh|EmbeddedAssetGenerator|BundleInputs|embe

`js/core/EmbedAsset.cmake` renders a header (identity encoded, five 64-bit words per line, big-endian, the last word padded
with zeros, `dataSize` excluding the padding) and compares its exact bytes with a checked-in one (`-DCHECK`, so that a header
with CRLF line ends is stale). It assembles bounded lines and joins them once, avoiding a growing-string CMake loop: the six
core assets, about 35 KB, take a fraction of a second. Generation and checking share one renderer, without intermediate files.
with CRLF line ends is stale). It assembles bounded lines and joins them once, avoiding a growing-string CMake loop: the seven
core assets take a fraction of a second. Generation and checking share one renderer, without intermediate files.
`EmbeddedAssetGenerator` (`test/cmake/CheckEmbedAsset.cmake`) covers the exact format, empty and binary inputs, word
boundaries, padding, a path with spaces, a checkout reached through a symbolic link and a nonzero status for stale or missing
files; a per-asset `*AssetFresh` test attributes each stale header, and a Catch2 scenario decodes every header with the C++
Expand All @@ -65,3 +65,77 @@ and failure responses.

fflate (MIT) and esbuild are locked packages of the developer environment (`webfront-packages.lock.json`), not vendored
sources; fflate is not embedded in C++ applications. Package notices travel with the packages that `wf install` downloads.

## Optional DOM interpreter

A page that receives DOM batches loads the version-matched module explicitly:

```js
const { installDomInterpreter } = await import('/webfront-dom.mjs');
const dom = installDomInterpreter(webFront);
const release = dom.island('panel', document.getElementById('panel')); // empty element
// Call release() before the page takes back the subtree.
```

Register C++ callbacks `wfDom.rejected(batchId, reason)` and, when listening to events,
`wfDom.event(nodeId, nameIndex, value)`. The low-level `msg::DomBatch` codec and
`ui.sendDomBatch(batch)` implement [ADR-003](adr/ADR-003-protocole-binaire-et-bornes.md);
the document/node API remains separate work (#381). The default filesystem protects both
`WebFront.js` and `webfront-dom.mjs` from document-root overrides.

The interpreter accepts trusted application commands, as [ADR-008](adr/ADR-008-contenu-de-confiance-et-origines.md)
specifies. `style` may load CSS resources or position overlays, and `id`/`name` can introduce named
DOM properties. The allowlist does not isolate untrusted producers. The name dictionary is retained
until the document is discarded, including definitions acquired from rejected batches; it has a
1 MiB UTF-8 budget in addition to the entry and per-name limits. Low-level C++ callers manage its
mirror; the document helper is separate work (#381). After semantic rejection, retry the corrected
operations using the names already acquired, without repeating their NAME definitions. Redefining
an acquired index is rejected.

`data:` URLs are rejected even for `<img src>`; serve an image from an embedded application provider
or a development document root and use its relative HTTP URL instead.

C++ batches require an explicit nonzero identifier (`msg::DomBatch(id)`); zero is reserved for
uncorrelated malformed-message rejections. Both codecs enforce a limit of 131,072 operations per
batch as well as the 1 MiB byte limit. The owning C++ decoder reserves the counted operation total;
its object memory still scales with that count. Invalid formats, UTF-8 and unused nonzero operands
throw `std::invalid_argument`; byte/operation budget violations throw `std::length_error`.

A residual DOM exception invalidates all node handles and island registrations. Existing release
functions then do nothing. C++ receives `wfDom.rejected` and must arrange page recovery: explicitly
empty the former island elements (`replaceChildren()`) or replace them before lending empty elements
again. Names remain interned. Reload the document to reset names as well. See ADR-003 for the exact
`wfDom.event` value contract.

`PROPERTY value` is rejected on `<output>`, including empty elements, because its native setter
replaces child nodes. Create a text child and use `SET_TEXT` to update the displayed value.

## Manual small-batch measurement

`test/web/dom-benchmark.html` measures repeated single-operation SET_TEXT batches against detached
flat DOM trees with 101, 10,001 and 60,001 live nodes. SET_TEXT repeatedly assigns `x` to the same
existing text node. Each size warms up with 20 batches, then takes
three samples of 100 batches; the displayed result is the median time per batch. It includes decoding,
validation and DOM text mutation, and excludes transport, layout and rendering. It is not a CTest case
and asserts no timing threshold. To run from the repository root with optional Python tooling:

```sh
measure_dir="$(mktemp -d)"
cp test/web/dom-benchmark.html "$measure_dir/index.html"
cp js/core/dom-interpreter.mjs "$measure_dir/webfront-dom.mjs"
python3 -m http.server 8000 --bind 127.0.0.1 --directory "$measure_dir"
# Open http://127.0.0.1:8000/ in a browser and click Measure.
```

Local Chrome 156/macOS observation on 2026-10-27, baseline `fe7e23b` versus the transactional delta
implementation (milliseconds per batch, median of three samples):

| Live nodes | Whole-table copy | Transactional delta |
| --- | ---: | ---: |
| 101 | 0.095 | 0.007 |
| 10,001 | 8.628 | 0.007 |
| 60,001 | 10.627 | 0.043 |

These short local measurements are sensitive to JIT, garbage collection, timer resolution and host
load; they are not a cross-engine guarantee. The deterministic Jasmine regression separately counts
Map/Set iterator visits to ensure a small text/append batch does not scan unrelated nodes or siblings.
4 changes: 3 additions & 1 deletion docs/PROJECT_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ are retained for investigation; diagnostics alone do not establish a correction.
require macOS 14+ and a WindowServer session. Automated CEF coverage is Linux/Xvfb;
Windows/macOS CEF deployment is not qualified. WebView2 needs its installed Evergreen runtime;
fixed-version runtime packaging, application installers and accessibility remain application work.
- General DOM abstractions and a direct engine transport are proposals, not public APIs.
- The low-level DOM batch command and optional embedded interpreter are implemented; see
[the wire contract](adr/ADR-003-protocole-binaire-et-bornes.md#commande-dom-dombatch-code-5-version-1).
The document/node API (#381) and a direct engine transport remain future work.
[ADR-018](adr/ADR-018-acces-au-dom.md) describes DOM islands;
[ADR-017](adr/ADR-017-acces-direct-aux-frontends.md) retains transport experiments and acceptance criteria.
Loading
Loading