From 7590978a839a201f79a08e0eef5f5fd5220150ec Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc Date: Tue, 27 Oct 2026 15:42:44 +0100 Subject: [PATCH] Add per-browser DOM document API [#381] --- AGENTS.md | 2 +- README.md | 2 +- docs/CHANGELOG.md | 18 + docs/DOM.md | 191 ++++++ docs/EMBEDDED_ASSETS.md | 4 +- docs/PROJECT_STATUS.md | 3 +- .../ADR-003-protocole-binaire-et-bornes.md | 44 +- docs/adr/ADR-018-acces-au-dom.md | 11 +- docs/adr/README.md | 4 +- include/webfront/WebFront.hpp | 136 +++- include/webfront/dom/Document.hpp | 361 ++++++++++ .../webfront/system/DomInterpreterData.hpp | 633 ++++++++++-------- .../webfront/system/FallbackIndexHtmlData.hpp | 66 +- .../webfront/system/FallbackModuleData.hpp | 28 +- include/webfront/weblink/DomBatch.hpp | 2 + js/core/dom-interpreter.mjs | 65 +- js/core/fallback/index.html | 4 +- js/core/fallback/webfront-fallback.mjs | 12 +- test/unit/CMakeLists.txt | 2 +- test/unit/DomDocumentTests.cpp | 361 ++++++++++ test/unit/WebFrontTests.cpp | 53 +- test/web/JasmineTest.cpp | 114 +++- test/web/suite/pages/dom-document.html | 10 + test/web/suite/specs/dom-document-specs.mjs | 115 ++++ test/web/suite/specs/dom-specs.mjs | 149 +++++ test/web/suite/specs/fallback-specs.mjs | 81 +++ test/web/suite/specs/webfront-specs.mjs | 2 + 27 files changed, 2121 insertions(+), 352 deletions(-) create mode 100644 docs/DOM.md create mode 100644 include/webfront/dom/Document.hpp create mode 100644 test/unit/DomDocumentTests.cpp create mode 100644 test/web/suite/pages/dom-document.html create mode 100644 test/web/suite/specs/dom-document-specs.mjs create mode 100644 test/web/suite/specs/fallback-specs.mjs diff --git a/AGENTS.md b/AGENTS.md index f0c5ca59..4ab30371 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -10,7 +10,7 @@ WebFront is a C++23 header-only library for serving a browser UI from a C++ appl WebFront also ships a standalone developer environment (`NativeApp::bootstrap("developer")`): a terminal whose `wf` commands (`init`, `create`, `install`, `restore`, `run`, `exec`, `check`, `test`, `build`, `dev`, `preview`, `embed`, `list`, `help`) manage a project manifest and lock, compile TS/TSX, type-check, run Jasmine specs and generate the application's embedded provider, with no JavaScript runtime or package manager on the developer's machine. It is not a sandbox. See `docs/DEVELOPER_ENVIRONMENT.md`. -The README introduces WebFront through the Game of Life walkthrough, demonstrating the developer bootstrap, reactive TypeScript UI and embedded distribution. The minimal `HelloWorld` example remains available under `examples/hello-world/`. Native modules and the bridge are covered by the Jasmine browser integration test. General DOM abstractions remain future work. Application coroutines use `webfront::Task` and `app.spawn(task)`/`ui.spawn(task)`; retain a `TaskHandle` to request individual cancellation. WebFront owns and drains these tasks. Spawn is callable from any thread while the application lives; a call rejected during shutdown returns a stopped handle. Destructors wait for outstanding operations; explicit shutdown reports a stalled join. Typed C++ sender calls support local cancellation; futures and JavaScript Promises do not expose cancellation. +The README introduces WebFront through the Game of Life walkthrough, demonstrating the developer bootstrap, reactive TypeScript UI and embedded distribution. The minimal `HelloWorld` example remains available under `examples/hello-world/`. Native modules and the bridge are covered by the Jasmine browser integration test. The optional `ui.document()` API provides per-connection DOM islands, batched writes, events and grouped sender reads; see `docs/DOM.md`. Application coroutines use `webfront::Task` and `app.spawn(task)`/`ui.spawn(task)`; retain a `TaskHandle` to request individual cancellation. WebFront owns and drains these tasks. Spawn is callable from any thread while the application lives; a call rejected during shutdown returns a stopped handle. Destructors wait for outstanding operations; explicit shutdown reports a stalled join. Typed C++ sender calls support local cancellation; futures and JavaScript Promises do not expose cancellation. ## Repository map diff --git a/README.md b/README.md index 1aaa1652..91b87454 100644 --- a/README.md +++ b/README.md @@ -279,7 +279,7 @@ CI runs one combined C++ / native-browser job per desktop platform on each code - JavaScript calls to C++ always return Promises. C++ `ui.jsFunction(name)(...)` is fire-and-forget; `ui.jsFunction(name)(...)` returns `std::future`. Missing functions, exceptions, malformed replies and disconnects fail the typed call. - The binary bridge supports scalars, strings, tuples, numeric typed arrays and packed bitsets. Arbitrary objects do not cross it. Strings have a 16-bit encoded length limit. - Development project access is explicit and intended for trusted local code. Downloaded tools run with the application's bridge authority, and script permissions frame only the `context` API: neither is a sandbox. Only packages that run in a browser are supported; installation scripts and native add-ons are not executed. Builds transform TypeScript without type checking; `wf check` type-checks with the compiler the project locks. -- Packaging, accessibility and native-engine deployment still need application-specific work. General DOM abstractions remain future work. See [project status](docs/PROJECT_STATUS.md) for known limitations. +- Packaging, accessibility and native-engine deployment still need application-specific work. The optional [`ui.document()` API](docs/DOM.md) provides DOM islands, automatically batched writes, event callbacks and grouped sender reads. See [project status](docs/PROJECT_STATUS.md) for known limitations. ## License diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e358fc66..3c07e6af 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,6 +7,24 @@ contribution terms and carry the license into newly built developer and Life starter archives. Third-party components retain their own licenses. +- Per-browser DOM documents (#381): `ui.document()` shares node identities, name interning, + writes grouped on a 1 ms server cadence, event callbacks with declared browser flags, and + explicit grouped read senders with local cancellation. The fallback page lends `root`; + custom pages opt in through `dom.connect()`. Revocation, disconnection and shutdown + invalidate handles. Reject element-only operations on text nodes/islands locally; enforce + the connection thread before document lookup and refuse document creation during closure. + DOM connection attempts retry unacknowledged revocations after partial success, retaining + the acknowledged handshake; server readiness is idempotent for a lost acknowledgement. + Revocation notification failures are logged, and missing network timers report an explicit error. + Empty event callbacks fail locally; validity predicates are + nonthrowing and return false off the document thread. Document the single-thread context + requirement and the coordinated handoff needed before page-initiated island unmounts. + Missing form values are empty. Event values over 65,535 UTF-8 bytes are not delivered to C++ + or truncated; their rejected delivery is logged in the browser console. + The fallback distinguishes bridge failures from DOM initialization failures. Batch-id exhaustion + notifies `onError`, and insert-before-self follows native no-op semantics. The server-thread + and rejection/reload contracts are in `docs/DOM.md`. + - 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 diff --git a/docs/DOM.md b/docs/DOM.md new file mode 100644 index 00000000..03180079 --- /dev/null +++ b/docs/DOM.md @@ -0,0 +1,191 @@ +# DOM from C++ + +`ui.document()` returns a `webfront::dom::Document` wrapper for the shared document +of one WebSocket connection. Copying the wrapper shares its name dictionary, pending +batch and node identities. A reload creates a new connection and document. A `Node` +is an identifier, not a local DOM object; copying or destroying it does not remove +anything in the browser. + +The embedded fallback page installs the interpreter and lends an empty island named +`root`. An application can therefore build an interface without UI files: + +```cpp +app.onUIStarted([](auto ui) { + auto doc = ui.document(); + auto root = doc.island(); // default: "root" + auto button = doc.element("button"); + auto label = doc.text("Click me"); + button.append(label); + button.listen("click", [label](std::string) { label.setText("Clicked"); }); + root.append(button); +}); +``` + +A custom page lends only empty, disjoint elements that its UI library does not +reconcile. It opts into the document callbacks explicitly: + +```js +import { installDomInterpreter } from '/webfront-dom.mjs'; +const dom = installDomInterpreter(webFront); +const release = dom.island('panel', document.getElementById('panel')); +await dom.connect(); +// Coordinate with C++ as described below before taking back the element or unmounting: +release(); +``` + +`connect()` completes only after the DOM handshake and all queued revocations are +acknowledged. A failed attempt can be retried: after a partially successful attempt, +the acknowledged handshake and revocations are not resent; only unacknowledged +revocations remain pending. Releases made between attempts are queued too. +The server treats `wfDom.ready` idempotently on a live connection, so retrying a +readiness acknowledgement does not reset names or handles. This does not reconnect +a closed bridge. Await successful `connect()` before rebuilding C++ handles for the +page's new islands. + +C++ uses `doc.island("panel")`. It cannot select arbitrary page elements, move or +remove island roots, or construct nodes from HTML. The page must call `release()` +before reclaiming a subtree; raw page mutations are not observed. Release invalidates +the root and descendants when its notification reaches C++. Remounting uses fresh +identifiers. `setText` accepts only a text node, preserving child identities. +`remove()` invalidates the entire removed subtree immediately in C++. +Attributes, properties and subscriptions require a C++-owned element: using them +on text nodes or island roots throws `std::invalid_argument` before changing the +pending batch or interning a name. Page-specific allowlist checks remain asynchronous. +`insertBefore(child, child)` is a no-op, matching the native DOM. + +## Execution and batching + +Create and use documents and nodes on the application's server context: in a C++ +bridge callback, `onUIStarted`, or a task started by `app.spawn`/`ui.spawn`. Other +threads must submit a task; off-thread access throws `std::logic_error`. Shutdown +runs after the external run callers have returned, as in [ADR-006](adr/ADR-006-taches-structurees-et-arret.md). +The connection records its server thread when accepted. `ui.document()` checks +that thread before accessing the document table, including on the first call. +Creating a document in a close-notification callback throws `ConnectionError`; a +closing connection cannot acquire a new document. + +The DOM API requires one execution thread for the application's context for the +entire connection. External callers of `run()`/`runOne()` must use that same thread; +do not run the context from several threads or alternate its execution between +threads while using DOM documents. `Node::valid()` and `Document::valid()` are +`noexcept` predicates for usability on the calling thread: both return false off +that thread, or for an invalidated handle. They do not make other DOM operations +safe to call from another thread. + +Writes accumulate in one bounded batch. Once the interpreter calls `connect()`, the +first pending write schedules an owned task that waits **1 ms** on the server context, +then flushes the pending batch. This is a scheduling cadence, not a rendering deadline. +`doc.flush()` sends sooner; reads flush preceding writes before creating their sender. +Writes made before browser readiness remain queued. Shutdown discards pending writes +and drains the scheduled tasks; it does not promise a final browser update. + +There is no implicit splitting: exceeding 1 MiB or 131,072 operations throws +`std::length_error`, leaving that failed operation unapplied to the pending batch. +Names are interned once per connection (65,536 entries, 1,024 UTF-8 bytes per name, +1 MiB total); there are at most 65,536 live nodes. Interned names are never reclaimed, +including names of removed or revoked islands. Repeatedly generating unique island +names permanently consumes this connection's dictionary budget. Reuse stable names; +a new connection/reload resets the dictionary. Identifiers are never reused in +a document. Flush earlier to bound a large construction. The browser validates the +whole batch before application, using the allowlist in [ADR-003](adr/ADR-003-protocole-binaire-et-bornes.md). +An invalid operation can still fail at the browser: C++ construction is not an +acknowledgement of successful DOM application. + +## Events and reads + +`node.listen(name, callback, {.preventDefault = true, .stopPropagation = true})` +declares browser-side flags at subscription time. An empty callback throws +`std::invalid_argument` without changing names, subscriptions or queued writes. +The callback receives a string: +input/change value (checkboxes: `"true"`/`"false"`), keyboard key, otherwise empty. +The callback runs on the server context and may queue writes or remove itself. +`unlisten(name)` and subtree removal release stored callbacks. Event values and +limits follow ADR-003. For bubbling input/change events the value belongs to the +subscribed node (`currentTarget`), not the originating child; it is empty if that +node has no `value` property. Flags cannot be decided after the asynchronous callback. + +Event values above **65,535 UTF-8 bytes** cannot cross the bridge and are **not +delivered to C++**. They are not truncated. The interpreter logs the rejected +Promise to the browser console (`WebFront DOM event delivery failed`), including +encoding, transport and callback errors. There is no C++ event-error notification; +the document stays usable and an explicit grouped read can retrieve a larger value +within its separate 1 MiB result budget. + +Reads are explicit and grouped in one request. For example, in an owned coroutine: + +```cpp +std::vector requests; +requests.push_back({label, webfront::dom::Read::text}); +requests.push_back({input, webfront::dom::Read::value}); +auto sender = ui.document().read(std::move(requests)); +auto values = co_await std::move(sender); +``` + +The result is a `std::vector` in request order. Available reads are +`text` (`textContent`), `value`, `checked`, `width` and `height` (bounding rectangle, +CSS pixels as decimal strings). Missing value/checked properties return an empty +string. Layout reads require an element. There are 1..4,096 requests per group and +at most 1 MiB of encoded results. These are snapshots at browser execution time, +not continuously synchronized values. There are no implicit reads. + +Calling `read()` flushes queued writes immediately, even if its returned sender is +never started or awaited. Only the grouped read request is lazy: the sender owns +its encoded request and dispatches that request at start. Cancellation completes +stopped locally and discards a late reply; browser execution continues. A revoked +node or closed document cannot return a successful late result. Disconnection and +browser read errors complete exceptionally. A successful result is decoded and +validated on the WebSocket receive thread, which is the sole server-context thread +under the DOM execution contract. Error/stopped completions may run on the thread +reporting disconnection or requesting stop, as for `jsFunctionSender`; they do not +execute the read's value-validation lambda. Owned application tasks resume on the +server context. See [ASYNC_EXECUTION.md](ASYNC_EXECUTION.md). + +## Lifetime and failure + +Disconnection, reload and application shutdown invalidate the old document and all +its nodes. Retained wrappers and nodes remain safe to inspect (`valid()` is false) +and mutations throw, including after the application is destroyed. This does not +extend the lifetime of the application's UI or application object. + +`doc.onError([](std::uint32_t batchId, std::string reason) { ... })` receives browser +rejections, asynchronous send errors and exhausted batch identifiers. A rejection closes the C++ document because +its optimistic identities may differ from the browser. Reload to recover. Revoking +an island while any writes are pending also closes the entire document, including +unrelated islands. This can happen during an ordinary component unmount within +the 1 ms batching interval. Coordinate every page-initiated unmount as described +below when the document must remain usable. A callback may throw; its +bridge Promise rejects and browser-side event/revocation notifications handle that +rejection. The underlying tasks remain owned and drained by the application. + +### Coordinating page unmounts + +The application must implement a handoff between the page and C++ before removing +an island. Pause all writers for the document (including tasks and event callbacks, +even those updating other islands), flush, and await an explicit browser round trip +such as a grouped read before allowing the page to call `release()` and remove the +element. Pending writes only cover the pre-flush batch; a batch already sent but not +yet applied can still be rejected by the browser after release, closing the document +through `wfDom.rejected`. The browser round trip is needed for that in-flight case too. Keep writers paused until C++ has observed the revocation; use an +application-level acknowledgement before resuming writes or creating new handles. +`release()` itself returns no acknowledgement. A failed notification after connection +is logged to the browser console (`WebFront DOM island revocation failed`); it is not +automatically retried, so the application must coordinate recovery/reload before +assuming C++ has invalidated the island. `flush()` only queues a message, +and waiting 1 ms is not a synchronization barrier. An uncoordinated unmount may +therefore require reloading the entire document, not just recreating that island. + +The document API reserves `wfDom.ready`, `wfDom.revoked`, `wfDom.event`, +`wfDom.rejected` and the browser function `wfDom.read`. After `dom.connect()`, do not mix low-level +`sendDomBatch` commands with `Document` on the same connection: the document owns +its name and node tables. Low-level interpreter users that do not call `connect()` +retain their own callbacks, including after obtaining a dormant C++ document wrapper. +Custom network providers need `ResumeAfter` to use this +optional document API; an unsupported `wfDom.ready` rejects explicitly with +`DOM API requires Net::ResumeAfter`. The interpreter accepts trusted application commands, not +untrusted content; see [EMBEDDED_ASSETS.md](EMBEDDED_ASSETS.md). + +The fallback first awaits `webFront.ready`, then imports and connects the DOM +module inside its error handler. The import is relative to the fallback module, +matching its relative script resources when served below a URL prefix. A missing module or unsupported DOM API is shown +as `Connected to WebFront; DOM unavailable: ...` (`data-state="dom-error"`), distinct +from an initial bridge connection failure. diff --git a/docs/EMBEDDED_ASSETS.md b/docs/EMBEDDED_ASSETS.md index c8d346c8..cd1f5fa3 100644 --- a/docs/EMBEDDED_ASSETS.md +++ b/docs/EMBEDDED_ASSETS.md @@ -80,7 +80,7 @@ const release = dom.island('panel', document.getElementById('panel')); // empty 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 +the higher-level document/node API is described in [DOM.md](DOM.md). 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) @@ -88,7 +88,7 @@ specifies. `style` may load CSS resources or position overlays, and `id`/`name` 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 +mirror; the `Document` helper manages its own mirror (see [DOM.md](DOM.md)). After semantic rejection, retry the corrected operations using the names already acquired, without repeating their NAME definitions. Redefining an acquired index is rejected. diff --git a/docs/PROJECT_STATUS.md b/docs/PROJECT_STATUS.md index 3c2051bc..0ea06a46 100644 --- a/docs/PROJECT_STATUS.md +++ b/docs/PROJECT_STATUS.md @@ -79,6 +79,7 @@ are retained for investigation; diagnostics alone do not establish a correction. fixed-version runtime packaging, application installers and accessibility remain application work. - 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. + The per-connection document/node API, events and grouped sender reads are available; see + [DOM from C++](DOM.md). A direct engine transport remains 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. diff --git a/docs/adr/ADR-003-protocole-binaire-et-bornes.md b/docs/adr/ADR-003-protocole-binaire-et-bornes.md index 9f1ca956..6bb82e34 100644 --- a/docs/adr/ADR-003-protocole-binaire-et-bornes.md +++ b/docs/adr/ADR-003-protocole-binaire-et-bornes.md @@ -18,11 +18,13 @@ | 1.11 | 2026-10-27 | Acceptée | Ambroise Leclerc | Validation par delta, budget cumulé des noms, récupération et contrat des événements précisés (#380). | — | | 1.12 | 2026-10-27 | Acceptée | Ambroise Leclerc | Identifiant de lot non nul, plafond d’opérations, codec canonique et nettoyage limité aux sous-arbres concernés (#380). | — | | 1.13 | 2026-10-27 | Acceptée | Ambroise Leclerc | Rejet de PROPERTY value sur output pour préserver les identifiants de ses enfants (#380). | — | +| 1.14 | 2026-10-27 | Proposée | Ambroise Leclerc | Notifications de document et lectures groupées par les appels existants (#381). | [PR #394](https://github.com/ambroise-leclerc/WebFront/pull/394) | ## État et chronologie -**Acceptée.** Décision initiale : **2022-02-06** (version 1.0). -Dernière révision : **2026-10-27** (version 1.13). +**Acceptée jusqu’à la version 1.13.** L’extension 1.14 est **proposée** dans la PR #394, en attente d’intégration. +Décision initiale : **2022-02-06** (version 1.0). +Dernière révision : **2026-10-27** (version 1.14). Le présent texte expose la décision en vigueur ; le tableau retrace ses états antérieurs. ## Contexte @@ -66,7 +68,7 @@ refusé dès l’en-tête, fragments compris. Les trames de contrôle ont leur p ## Commande DOM (`domBatch`, code 5, version 1) Cette section remplace le transport `wfDom.apply` des prototypes de l'[ADR-018](ADR-018-acces-au-dom.md) ; -les propositions d'API de document et de nœuds de cette ADR restent distinctes. +l’API de document et de nœuds de #381 utilise désormais ce transport, comme décrit ci-dessous. Un message WebSocket C++ → navigateur contient exactement un lot : `05 01`, un identifiant de lot `uint32` **little-endian fixe non nul**, puis zéro ou plusieurs opérations jusqu'à la fin du message. @@ -180,13 +182,16 @@ l'absence de module installé ou une exception DOM résiduelle pendant l'applica callback ordinaire `wfDom.rejected(uint32 batchId, string reason)` ; l'application doit l'enregistrer. Le motif est limité à 4 096 unités UTF-16 avant encodage. Si l'en-tête est tronqué, l'identifiant vaut zéro. Les événements utilisent `wfDom.event(uint32 nodeId, uint32 nameIndex, string value)` et leurs -Promises sont traitées. `nameIndex` désigne le nom interné à LISTEN. La valeur est celle du nœud +Promises sont traitées. Une valeur d’événement dépassant 65 535 octets UTF-8 +n’est pas livrée à C++ et n’est pas tronquée ; le rejet d’encodage, de transport ou +de callback est journalisé dans la console du navigateur. Il n’existe pas de +notification C++ distincte pour cet échec. `nameIndex` désigne le nom interné à LISTEN. La valeur est celle du nœud abonné (`event.currentTarget`), pas d'un descendant à l'origine d'un événement bouillonnant : | Événement | `value` | | --- | --- | | `input`, `change` sur une case à cocher | `String(currentTarget.checked)`, soit `"true"` ou `"false"` | -| Autres `input`, `change` | `String(currentTarget.value)` | +| Autres `input`, `change` | `String(currentTarget.value ?? "")` (vide si la propriété est absente) | | `keydown`, `keyup` | `event.key` | | Tout autre événement | La chaîne vide `""` | @@ -200,7 +205,27 @@ remplace les éléments d'îlot, ou vide explicitement leurs enfants (`element.r les prête de nouveau avec `island()`. Prêter un ancien élément encore non vide reste interdit. Les identifiants de nœuds sont à reconstruire, mais la table de noms et son budget restent acquis. La page peut aussi choisir de recharger tout le document pour remettre les deux tables à zéro. -L'API publique document/nœuds et les lectures groupées relèvent de #381. +L’API publique document/nœuds utilise ce flux et les appels ordinaires existants (#381). +`dom.connect()` installe `wfDom.read` dans le navigateur puis attend `webFront.ready` +avant d’appeler `wfDom.ready()` côté C++. Cet appel est idempotent sur une connexion +vivante : réessayer un acquittement perdu ne remet ni noms ni nœuds à zéro. Le mode connecté n’est acquis qu’après +l’acquittement ; un échec de cette négociation permet de réessayer. Les révocations +survenues pendant l’attente sont envoyées après acquittement. La connexion n’est +complète qu’après acquittement de toutes les révocations ; une reprise conserve la +négociation et les révocations déjà acquittées, sans répéter `wfDom.ready`. Les +révocations non acquittées et celles survenues entre tentatives restent en attente. `release()` envoie `wfDom.revoked(string islandName)` +quand ce mode est actif. Le document C++ reçoit les rejets et les événements de sa connexion ; +les utilisateurs bas niveau sans `connect()` gardent leurs propres callbacks. + +Une lecture groupée appelle `wfDom.read(Uint32Array pairs)` : chaque paire contient +l’identifiant de nœud puis la propriété (0 textContent, 1 value, 2 checked, 3 largeur, +4 hauteur du rectangle en pixels CSS). Le groupe contient 1 à 4 096 paires, toutes +validées avant lecture. Le résultat est un Uint8Array d’au plus 1 MiB : pour chaque +requête, longueur UTF-8 uint32 little-endian puis les octets de sa valeur convertie +en chaîne (propriété absente : chaîne vide). Les frontières et le nombre exact de +résultats sont contrôlés en C++. Les erreurs rejettent l’appel ordinaire. Aucun nouveau +code de type du bridge n’est ajouté. L’arrêt sender reste local et ignore une réponse tardive. +Voir [DOM.md](../DOM.md) pour les règles d’identité et d’exécution. ## Options écartées et motifs @@ -214,6 +239,9 @@ L'API publique document/nœuds et les lectures groupées relèvent de #381. - **Bénéfice :** contrat compact et tableaux numériques utilisables sans conversion en texte. - **Coût accepté :** maintenance de deux codecs et limites visibles aux utilisateurs. +- **Coût proposé en 1.14 :** état optimiste par connexion, tâche d’envoi cadencée et mémoire + des nœuds côté C++. Un rejet ou une révocation avec des écritures en attente impose + un rechargement ; l’arrêt sender ne peut pas interrompre une lecture déjà envoyée au navigateur. - **Risque :** dépassements, mauvais types ou allocation excessive ; contrôler les bornes avant lecture/allocation et exercer les décodeurs avec sanitizers et fuzzing. @@ -225,7 +253,9 @@ L'API publique document/nœuds et les lectures groupées relèvent de #381. le codec JavaScript et `IndexFS.hpp` inchangés. Les tests doivent alors démontrer la compatibilité avec le codec JavaScript existant dans un navigateur réel. - Que toute évolution du protocole s’accompagne de tests d’encodage et de décodage ainsi que - d’une régression en navigateur réel, erreurs et frontières de taille comprises. + d’une régression en navigateur réel, erreurs et frontières de taille comprises. Pour 1.14, + `DomDocumentTests.cpp` et les suites Jasmine `dom-document-specs.mjs`/`dom-specs.mjs` + couvrent identités, durées de vie, arrêt local, callbacks bas niveau avant connexion, lectures et bornes. - Ne pas contourner une limite de chaîne par un cast de longueur ; découper les données ou employer un tableau numérique lorsque le contrat fonctionnel le permet. - Garder `BuffersPolicyType` et ses valeurs de repli compatibles avec les politiques existantes. diff --git a/docs/adr/ADR-018-acces-au-dom.md b/docs/adr/ADR-018-acces-au-dom.md index 9f439389..710d109d 100644 --- a/docs/adr/ADR-018-acces-au-dom.md +++ b/docs/adr/ADR-018-acces-au-dom.md @@ -6,6 +6,7 @@ | --- | --- | --- | --- | --- | --- | | 1.0 | 2026-10-26 | Proposée | Ambroise Leclerc | Décision initiale (#378) : état de l'art TypeScript, Rust et Python vérifié, huit solutions comparées, prototypes mesurés sous WebKitGTK (flux de mutations, proxy, lectures attendues, îlots React, formulaire généré par réflexion C++26, lots hostiles), découverte d'un délai de 40 ms du transport (Nagle). | À renseigner après intégration. | | 1.1 | 2026-10-27 | Proposée, partiellement remplacée | Ambroise Leclerc | Le transport du prototype est remplacé par ADR-003 1.10 et suivantes ; l’API document/nœuds reste proposée (#381). | — | +| 1.2 | 2026-10-27 | Proposée, partiellement livrée | Ambroise Leclerc | API document/nœuds, cycle de 1 ms, événements et lectures groupées (#381). | — | ## État et chronologie @@ -13,7 +14,15 @@ Le transport DOM est désormais livré par l'[ADR-003, version 1.10 et suivantes](ADR-003-protocole-binaire-et-bornes.md), avec la commande `domBatch` et `/webfront-dom.mjs` (#380). L'appel `wfDom.apply` par `jsFunction` décrit ci-dessous est uniquement le protocole historique des prototypes ; il ne décrit pas le transport livré. -L'API document/nœuds, les adaptateurs et la réflexion restent proposés (#381 à #384). +L’API document/nœuds est livrée par #381 ([DOM.md](../DOM.md)) ; les adaptateurs et la réflexion +restent proposés (#382 à #384). Le point d’envoi retenu est un cycle serveur de 1 ms +après la première écriture en attente, au sein d’une tâche possédée et drainée. +`flush()` et les lectures explicites peuvent envoyer plus tôt. `SET_TEXT` reste limité +aux nœuds texte. Une révocation invalide le sous-arbre ; avec des écritures en attente, +le document ferme plutôt que d’envoyer un lot contenant des identifiants révoqués. +Une déconnexion ou l’arrêt invalide l’ensemble du document. Toutes les opérations +s’exécutent sur le contexte serveur ; les lectures sont des senders groupés annulables +localement, sans nouvelle catégorie de valeur sur le bridge. Les mesures historiques viennent de prototypes jetables, retirés du dépôt après mesure et consultables dans le commit `ef2bb25` de la PR #385 (`test/web/dom/`, cible manuelle `webkitgtk_dom_prototype`). Elle passera à « Acceptée » quand les critères de la section dédiée seront démontrés. diff --git a/docs/adr/README.md b/docs/adr/README.md index 2fd8b885..843f9a1a 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -42,7 +42,7 @@ verification evidence remain in [PROJECT_STATUS](../PROJECT_STATUS.md). | --- | --- | --- | --- | --- | | [ADR-001](ADR-001-coeur-cpp23-header-only.md) | A header-only C++23 core embedded in the application | Accepted | 2020-04-19 | 1.5 — 2026-10-13 | | [ADR-002](ADR-002-systemes-de-fichiers-composables.md) | An abstract, composable filesystem as the foundation for portability | Accepted | 2023-03-16 | 2.4 — 2026-10-14 | -| [ADR-003](ADR-003-protocole-binaire-et-bornes.md) | A shared, typed and bounded binary protocol | Accepted | 2022-02-06 | 1.13 — 2026-10-27 | +| [ADR-003](ADR-003-protocole-binaire-et-bornes.md) | A shared, typed and bounded binary protocol | Accepted through 1.13; 1.14 proposed | 2022-02-06 | 1.14 — 2026-10-27 | | [ADR-004](ADR-004-appels-asynchrones-et-erreurs.md) | Asynchronous calls with deliberately asymmetric contracts | Accepted | 2022-02-06 | 2.4 — 2026-10-18 | | [ADR-005](ADR-005-evolution-reseau-asio-stdnet.md) | From standalone ASIO to stdnet: anticipating standard networking without blocking progress | Accepted through 3.1; 3.2 proposed | 2022-01-21 | 3.2 — 2026-10-26 | | [ADR-006](ADR-006-taches-structurees-et-arret.md) | Owning, cancelling and joining every task | Accepted | 2026-10-13 | 2.1 — 2026-10-25 | @@ -57,7 +57,7 @@ verification evidence remain in [PROJECT_STATUS](../PROJECT_STATUS.md). | [ADR-015](ADR-015-ressources-generees-par-application.md) | Generating application-owned embedded resources | Accepted | 2026-10-20 | 1.0 — 2026-10-24 | | [ADR-016](ADR-016-bootstrap-comme-socle.md) | The bootstrap environment as WebFront's foundation | Accepted | 2026-10-22 | 1.6 — 2026-10-26 | | [ADR-017](ADR-017-acces-direct-aux-frontends.md) | Direct access to embedded frontends, with HTML kept normative | Proposed | 2026-10-24 | 1.1 — 2026-10-25 | -| [ADR-018](ADR-018-acces-au-dom.md) | DOM access from C++ through a bounded mutation stream, without contesting the DOM of UI libraries | Proposed, partially superseded | 2026-10-26 | 1.1 — 2026-10-27 | +| [ADR-018](ADR-018-acces-au-dom.md) | DOM access from C++ through a bounded mutation stream, without contesting the DOM of UI libraries | Proposed, partially superseded | 2026-10-26 | 1.2 — 2026-10-27 | Numbering follows the reading topics; milestones and individual file histories provide the chronology, which does not follow the numerical order. diff --git a/include/webfront/WebFront.hpp b/include/webfront/WebFront.hpp index 1d8f5438..079bf360 100644 --- a/include/webfront/WebFront.hpp +++ b/include/webfront/WebFront.hpp @@ -4,6 +4,7 @@ /// @brief WebFront UI main objet #pragma once +#include "dom/Document.hpp" #include "frontend/Frontend.hpp" #include "http/HTTPServer.hpp" #include "JsFunction.hpp" @@ -74,6 +75,19 @@ class BasicUI { link->sendCommand(batch); } + /// One shared DOM document for this connection; call only on the server thread. + [[nodiscard]] auto document() const { + return dom::Document{*this}; + } + +private: + template + friend class dom::Document; + [[nodiscard]] auto domState() const { + return webFront.domState(webLinkId); + } + +public: /// The frames queued for this browser and not yet written to the network; 0 once its connection is gone. [[nodiscard]] std::size_t pendingWrites() const { const auto link = webFront.findLink(webLinkId); @@ -343,7 +357,7 @@ class BasicWF { }, httpServer.taskScope(), false); { std::scoped_lock lock{linksMutex}; - webLinks.emplace(id, link); + webLinks.emplace(id, Connection{link, std::this_thread::get_id(), false}); } link->start(); // registered first: every event it dispatches finds it }); @@ -426,9 +440,43 @@ class BasicWF { [[nodiscard]] std::shared_ptr> findLink(WebLinkId id) const { std::scoped_lock lock{linksMutex}; const auto found = webLinks.find(id); - return found == webLinks.end() ? nullptr : found->second; + return found == webLinks.end() ? nullptr : found->second.link; + } + +private: + template + friend class BasicUI; + /// Internal DOM document storage, confined to the server thread. + std::shared_ptr domState(WebLinkId id) { + std::shared_ptr> link; + { + std::scoped_lock lock{linksMutex}; + const auto found = webLinks.find(id); + if (found == webLinks.end() || found->second.closed) + throw ConnectionError("Connection with client lost"); + if (found->second.thread != std::this_thread::get_id()) + throw std::logic_error("DOM document requires the server thread"); + link = found->second.link; + } + // The connection's immutable server-thread identity was checked before touching this map. + if (auto found = domDocuments.find(id); found != domDocuments.end()) + return found->second; + auto state = std::make_shared(); + state->send = [weak = std::weak_ptr(link)](const msg::DomBatch& batch) { + const auto connection = weak.lock(); + if (!connection) + throw ConnectionError("Connection with client lost"); + connection->sendCommand(batch); + }; + state->schedule = [this, id, weak = std::weak_ptr(state)] { + if (auto shared = weak.lock()) + static_cast(spawn(flushDomAfter(UI{*this, id}, std::move(shared)))); + }; + domDocuments.emplace(id, state); + return state; } +public: /// The browsers connected now: a closed connection is released shortly after its closure. [[nodiscard]] std::size_t connectedBrowsers() const { std::scoped_lock lock{linksMutex}; @@ -564,7 +612,7 @@ class BasicWF { { std::scoped_lock lock{linksMutex}; if (auto found = webLinks.find(id); found != webLinks.end()) { - released = std::move(found->second); + released = std::move(found->second.link); webLinks.erase(found); } } @@ -572,7 +620,10 @@ class BasicWF { } void releaseLinks() { - std::map>> released; + for (auto& [id, document] : domDocuments) + document->close(); + domDocuments.clear(); + std::map released; std::scoped_lock lock{linksMutex}; released.swap(webLinks); } @@ -596,15 +647,74 @@ class BasicWF { std::filesystem::path httpDocRoot; ContentPolicy contentPolicy; mutable std::mutex linksMutex; // guards webLinks, read from any thread - std::map>> webLinks; + struct Connection { + std::shared_ptr> link; + std::thread::id thread; + bool closed; + }; + std::map webLinks; WebLinkId idsCounter{0}; std::function uiStartedHandler; std::shared_ptr> uiSubscribers = std::make_shared>(); std::shared_ptr> uiClosedSubscribers = std::make_shared>(); std::map, WebLink&, msg::CallId, UI)>, std::less<>> cppFunctions; + std::map> domDocuments; std::thread serverThread; // Background thread running the HTTP server private: + static Task flushDomAfter(UI ui, std::shared_ptr state) { + co_await ui.resumeAfter(std::chrono::milliseconds(1)); + state->scheduled = false; + if (!state->alive) + co_return; + try { + state->flush(); + } catch (const std::exception& error) { + state->reject(state->batchId, error.what()); + } + } + + bool domCall(const WebLinkEvent& event, WebLink& link) { + if (event.text == "wfDom.ready") { + auto handler = detail::makeCppFunctionHandler([this, id = event.webLinkId] { + auto state = domState(id); + state->check(); + if (state->ready) + return; // Retrying a lost readiness acknowledgement must not reset the document. + state->ready = true; + state->wake(); + }); + detail::makeCppFunctionResponder(std::move(handler))(event.data, link, event.callId); + return true; + } + const auto found = domDocuments.find(event.webLinkId); + if (found == domDocuments.end() || !found->second->ready) + return false; // Low-level batch users retain their own callbacks until explicit connection. + auto state = found->second; + if (event.text == "wfDom.event") { + auto handler = detail::makeCppFunctionHandler( + [state](std::uint32_t node, std::uint32_t name, std::string value) { + if (state->alive) + state->event(node, name, std::move(value)); + }); + detail::makeCppFunctionResponder(std::move(handler))(event.data, link, event.callId); + } else if (event.text == "wfDom.revoked") { + auto handler = detail::makeCppFunctionHandler([state](std::string name) { + if (state->alive) + state->revoke(name); + }); + detail::makeCppFunctionResponder(std::move(handler))(event.data, link, event.callId); + } else if (event.text == "wfDom.rejected") { + auto handler = detail::makeCppFunctionHandler([state](std::uint32_t id, std::string reason) { + if (state->alive) + state->reject(id, std::move(reason)); + }); + detail::makeCppFunctionResponder(std::move(handler))(event.data, link, event.callId); + } else + return false; + return true; + } + void onEvent(WebLinkEvent event) { switch (event.code) { case WebLinkEvent::Code::linked: @@ -616,6 +726,15 @@ class BasicWF { // Shutdown cancels the connections' writes, which then fail and report a closure: not a disconnection. if (httpServer.taskScope().stopRequested()) break; + { + std::scoped_lock lock{linksMutex}; + if (auto found = webLinks.find(event.webLinkId); found != webLinks.end()) + found->second.closed = true; + } + if (auto found = domDocuments.find(event.webLinkId); found != domDocuments.end()) { + found->second->close(); + domDocuments.erase(found); + } uiClosedSubscribers->notify(UI{*this, event.webLinkId}); // The link is running this handler: it is released afterwards, by a task on the server context. // During shutdown the task is refused and the link goes with the application. @@ -626,6 +745,13 @@ class BasicWF { const auto link = findLink(event.webLinkId); if (!link) break; + if constexpr (requires(typename Net::Acceptor& acceptor) { Net::ResumeAfter(acceptor, std::chrono::milliseconds(1)); }) { + if (domCall(event, *link)) + break; + } else if (event.text == "wfDom.ready") { + link->sendError(event.callId, "DOM API requires Net::ResumeAfter"); + break; + } if (auto function = cppFunctions.find(event.text); function != cppFunctions.end()) function->second(event.data, *link, event.callId, UI{*this, event.webLinkId}); else diff --git a/include/webfront/dom/Document.hpp b/include/webfront/dom/Document.hpp new file mode 100644 index 00000000..8cfb79d6 --- /dev/null +++ b/include/webfront/dom/Document.hpp @@ -0,0 +1,361 @@ +/// @brief Per-connection DOM handles, batched mutations and explicit asynchronous reads. +#pragma once +#include "../Task.hpp" +#include "../weblink/DomBatch.hpp" + +#include +#include +#include +#include +#include +#include +#include + +namespace webfront::dom { +class Node; +template +class Document; +struct EventOptions { + bool preventDefault{}; + bool stopPropagation{}; +}; +enum class Read : std::uint32_t { text, value, checked, width, height }; + +namespace detail { +struct Entry { + bool text{}, island{}; + std::uint32_t parent{}; + std::set children; +}; + +/// Internal state is shared by all document wrappers for one connection. Mutations are server-thread confined. +struct State : std::enable_shared_from_this { + std::atomic alive{true}; + std::thread::id thread{std::this_thread::get_id()}; + bool ready{}, scheduled{}; + std::uint32_t nextNode{1}, batchId{1}; + msg::DomBatch pending{1}; + std::size_t operations{}, nameBytes{}; + std::map> names; + std::map nodes; + std::map> islands; + std::map, std::function> listeners; + std::function send; + std::function schedule; + std::function onError; + + bool validOnCurrentThread() const noexcept { + return alive.load() && thread == std::this_thread::get_id(); + } + void check() const { + if (!alive) + throw std::runtime_error("DOM document is closed"); + if (thread != std::this_thread::get_id()) + throw std::logic_error("DOM document requires the server thread"); + } + Entry& get(std::uint32_t id) { + check(); + const auto found = nodes.find(id); + if (found == nodes.end()) + throw std::runtime_error("DOM node is invalid"); + return found->second; + } + void wake() { + if (ready && operations && !scheduled && schedule) { + scheduled = true; + schedule(); + } + } + void add(msg::DomOperation op) { + check(); + pending.add(op); + ++operations; + wake(); + } + std::uint32_t intern(std::string_view name) { + check(); + if (auto found = names.find(name); found != names.end()) + return found->second; + if (names.size() >= 65536 || name.size() > 1024 || name.size() > 1024 * 1024 - nameBytes) + throw std::length_error("DOM name dictionary budget exceeded"); + const auto index = static_cast(names.size()); + add({msg::DomOp::name, index, 0, 0, std::string(name)}); + names.emplace(name, index); + nameBytes += name.size(); + return index; + } + std::uint32_t fresh(msg::DomOperation op, Entry entry) { + check(); + if (nodes.size() >= 65536 || nextNode == 0) + throw std::length_error("DOM node budget exhausted"); + op.a = nextNode; + add(std::move(op)); + nodes.emplace(nextNode, std::move(entry)); + return nextNode++; + } + void forget(std::uint32_t id) { + std::vector stack{id}; + while (!stack.empty()) { + const auto current = stack.back(); + stack.pop_back(); + const auto found = nodes.find(current); + if (found == nodes.end()) + continue; + for (auto child : found->second.children) + stack.push_back(child); + auto listener = listeners.lower_bound({current, 0}); + while (listener != listeners.end() && listener->first.first == current) + listener = listeners.erase(listener); + nodes.erase(found); + } + } + void revoke(const std::string& name) { + check(); + if (const auto found = islands.find(name); found != islands.end()) { + // Already queued operations may refer to the revoked subtree: fail closed rather than send a partial batch. + if (operations) { + reject(batchId, "DOM island revoked with pending writes"); + return; + } + forget(found->second); + islands.erase(found); + } + } + void close() { + alive = false; + nodes.clear(); + listeners.clear(); + islands.clear(); + send = {}; + schedule = {}; + onError = {}; + } + void reject(std::uint32_t id, std::string reason) { + auto handler = onError; + close(); + if (handler) + handler(id, std::move(reason)); + } + void flush() { + check(); + if (!ready || !operations) + return; + try { + send(pending); + } catch (...) { + reject(batchId, "DOM transport failed"); + throw; + } + operations = 0; + if (batchId == std::numeric_limits::max()) { + reject(batchId, "DOM batch identifiers exhausted"); + throw std::length_error("DOM batch identifiers exhausted"); + } + pending = msg::DomBatch(++batchId); + } + void event(std::uint32_t node, std::uint32_t name, std::string value) { + check(); + if (auto found = listeners.find({node, name}); found != listeners.end()) { + auto callback = found->second; // callback may remove itself or its node + callback(std::move(value)); + } + } +}; +} // namespace detail + +/** @brief An identifier tied to a document; copying it does not copy a DOM subtree. */ +class Node { + std::weak_ptr owner; + std::uint32_t identifier{}; + template + friend class Document; + Node(std::shared_ptr state, std::uint32_t id) : owner(std::move(state)), identifier(id) { } + std::shared_ptr state() const { + auto shared = owner.lock(); + if (!shared) + throw std::runtime_error("DOM document is gone"); + shared->get(identifier); + return shared; + } + std::shared_ptr elementState() const { + auto shared = state(); + const auto& entry = shared->get(identifier); + if (entry.text || entry.island) + throw std::invalid_argument("Operation requires a C++-owned DOM element"); + return shared; + } + void same(const Node& other) const { + if (owner.lock() != other.owner.lock()) + throw std::invalid_argument("DOM nodes belong to different documents"); + other.state(); + } + void insert(Node child, std::uint32_t reference) const { + auto s = state(); + same(child); + if (s->get(identifier).text || s->get(child.identifier).island) + throw std::invalid_argument("Invalid DOM parent or island move"); + for (auto ancestor = identifier; ancestor; ancestor = s->get(ancestor).parent) + if (ancestor == child.identifier) + throw std::invalid_argument("DOM cycle"); + s->add({reference ? msg::DomOp::insertBefore : msg::DomOp::append, identifier, child.identifier, reference}); + auto& entry = s->get(child.identifier); + if (entry.parent) + s->get(entry.parent).children.erase(child.identifier); + entry.parent = identifier; + s->get(identifier).children.insert(child.identifier); + } + +public: + Node() = default; + std::uint32_t id() const { + state(); + return identifier; + } + /// Whether this handle is live and usable on the calling thread; never touches the node table off-thread. + bool valid() const noexcept { + auto s = owner.lock(); + return s && s->validOnCurrentThread() && s->nodes.contains(identifier); + } + void setText(std::string value) const { + auto s = state(); + if (!s->get(identifier).text) + throw std::invalid_argument("setText requires a text node"); + s->add({msg::DomOp::setText, identifier, 0, 0, std::move(value)}); + } + void attribute(std::string_view name, std::string value) const { + auto s = elementState(); + s->add({msg::DomOp::attribute, identifier, s->intern(name), 0, std::move(value)}); + } + void unsetAttribute(std::string_view name) const { + auto s = elementState(); + s->add({msg::DomOp::unsetAttribute, identifier, s->intern(name)}); + } + void property(std::string_view name, std::string value) const { + auto s = elementState(); + s->add({msg::DomOp::property, identifier, s->intern(name), 0, std::move(value)}); + } + void append(Node child) const { + insert(child, 0); + } + void insertBefore(Node child, Node reference) const { + auto s = state(); + same(reference); + if (s->get(reference.identifier).parent != identifier) + throw std::invalid_argument("DOM reference is not a child"); + same(child); + if (child.identifier == reference.identifier) + return; // Like native insertBefore(x, x): preserve the subtree without emitting a mutation. + insert(child, reference.identifier); + } + void remove() const { + auto s = state(); + const auto parent = s->get(identifier).parent; + if (s->get(identifier).island) + throw std::invalid_argument("Cannot remove a page-owned island"); + s->add({msg::DomOp::remove, identifier}); + if (parent) + s->get(parent).children.erase(identifier); + s->forget(identifier); + } + void listen(std::string_view event, std::function callback, EventOptions options = {}) const { + auto s = elementState(); + if (!callback) + throw std::invalid_argument("DOM event callback must not be empty"); + const auto name = s->intern(event); + s->add({msg::DomOp::listen, identifier, name, std::uint32_t(options.preventDefault) | (std::uint32_t(options.stopPropagation) << 1)}); + s->listeners[{identifier, name}] = std::move(callback); + } + void unlisten(std::string_view event) const { + auto s = elementState(); + const auto name = s->intern(event); + s->add({msg::DomOp::unlisten, identifier, name}); + s->listeners.erase({identifier, name}); + } + bool belongsTo(const std::shared_ptr& s) const { + return owner.lock() == s; + } +}; +struct ReadRequest { + Node node; + Read property; +}; + +/** @brief One document per connected browser. All methods run on the server thread. */ +template +class Document { + UI ui; + std::shared_ptr state; + +public: + explicit Document(UI browser) : ui(browser), state(browser.domState()) { } + /// Whether this document is live and usable on the calling thread. + bool valid() const noexcept { + return state && state->validOnCurrentThread(); + } + Node island(std::string name = "root") const { + state->check(); + if (auto found = state->islands.find(name); found != state->islands.end()) + return {state, found->second}; + const auto index = state->intern(name); + const auto id = state->fresh({msg::DomOp::mount, 0, index}, {.text = false, .island = true, .parent = 0, .children = {}}); + state->islands.emplace(std::move(name), id); + return {state, id}; + } + Node element(std::string_view tag) const { + const auto name = state->intern(tag); + return {state, state->fresh({msg::DomOp::element, 0, name}, {})}; + } + Node text(std::string value) const { + return {state, state->fresh({msg::DomOp::text, 0, 0, 0, std::move(value)}, {.text = true, .island = false, .parent = 0, .children = {}})}; + } + void flush() const { + state->flush(); + } + void onError(std::function callback) const { + state->check(); + state->onError = std::move(callback); + } + /// Flushes writes immediately, even if the returned sender is discarded. Only the grouped read RPC is lazy and locally cancellable. + auto read(std::vector requests) const { + state->check(); + if (requests.empty() || requests.size() > 4096) + throw std::length_error("DOM reads require 1..4096 requests"); + std::vector encoded; + for (const auto& request : requests) { + if (!request.node.belongsTo(state)) + throw std::invalid_argument("DOM read belongs to another document"); + if (request.property > Read::height) + throw std::invalid_argument("Unknown DOM read"); + encoded.push_back(request.node.id()); + encoded.push_back(static_cast(request.property)); + } + if (!state->ready) + throw std::runtime_error("DOM interpreter has not connected"); + flush(); + return networking::ex::then(ui.template jsFunctionSender>("wfDom.read")(encoded), + [s = state, requests = std::move(requests)](std::vector bytes) { + s->check(); + if (bytes.size() > msg::DomBatch::maxBytes) + throw std::length_error("DOM read result exceeds 1 MiB"); + std::vector result; + std::size_t offset{}; + for (const auto& request : requests) { + request.node.id(); // Revoked handles cannot produce a successful late result. + if (bytes.size() - offset < 4) + throw std::runtime_error("Truncated DOM read result"); + std::uint32_t size{}; + for (unsigned shift = 0; shift < 32; shift += 8) + size |= std::uint32_t(bytes[offset++]) << shift; + if (size > bytes.size() - offset) + throw std::runtime_error("Truncated DOM read value"); + result.emplace_back(reinterpret_cast(bytes.data() + offset), size); + msg::DomBatch::validateUtf8(result.back()); + offset += size; + } + if (offset != bytes.size()) + throw std::runtime_error("Trailing DOM read data"); + return result; + }); + } +}; +} // namespace webfront::dom diff --git a/include/webfront/system/DomInterpreterData.hpp b/include/webfront/system/DomInterpreterData.hpp index 3fb58407..70926087 100644 --- a/include/webfront/system/DomInterpreterData.hpp +++ b/include/webfront/system/DomInterpreterData.hpp @@ -9,8 +9,8 @@ namespace webfront::fs::generated { struct DomInterpreterData { static constexpr std::string_view encoding{}; - static constexpr std::size_t dataSize{16652}; - static constexpr std::array data{ + static constexpr std::size_t dataSize{19839}; + static constexpr std::array data{ 0x2f2f204144522d30, 0x30333a206f707469, 0x6f6e616c20444f4d, 0x20636f6d6d616e64, 0x20696e7465727072, 0x657465722e204f6e, 0x6c79207468697320, 0x6d6f64756c652074, 0x6f75636865732074, 0x686520444f4d3b20, 0x57656246726f6e74, 0x2e6a7320726f7574, 0x657320636f6d6d61, 0x6e6420352e0a636f, 0x6e7374206d617842, @@ -152,282 +152,361 @@ struct DomInterpreterData { 0x6e73742076616c75, 0x65203d206e616d65, 0x203d3d3d2027696e, 0x70757427207c7c20, 0x6e616d65203d3d3d, 0x20276368616e6765, 0x270a202020202020, 0x2020202020202020, 0x20203f20286e6f64, 0x652e74797065203d, 0x3d3d202763686563, 0x6b626f7827203f20, 0x537472696e67286e, 0x6f64652e63686563, 0x6b656429203a2053, - 0x7472696e67286e6f, 0x64652e76616c7565, 0x29290a2020202020, 0x2020202020202020, 0x2020203a206e616d, - 0x65203d3d3d20276b, 0x6579646f776e2720, 0x7c7c206e616d6520, 0x3d3d3d20276b6579, 0x757027203f206576, - 0x656e742e6b657920, 0x3a2027273b0a2020, 0x2020202020202020, 0x2020627269646765, 0x2e63707046756e63, - 0x74696f6e28277766, 0x446f6d2e6576656e, 0x7427292869642c20, 0x696e6465782c2076, 0x616c7565292e6361, - 0x746368282829203d, 0x3e207b7d293b0a20, 0x202020202020207d, 0x3b0a202020202020, 0x20206e6f64652e61, - 0x64644576656e744c, 0x697374656e657228, 0x6e616d652c206c69, 0x7374656e6572293b, 0x0a20202020202020, - 0x206c65742067726f, 0x7570203d206c6973, 0x74656e6572732e67, 0x6574286964293b0a, 0x2020202020202020, - 0x696620282167726f, 0x757029207b206772, 0x6f7570203d206e65, 0x77204d617028293b, 0x206c697374656e65, - 0x72732e7365742869, 0x642c2067726f7570, 0x293b207d0a202020, 0x202020202067726f, 0x75702e7365742869, - 0x6e6465782c207b6e, 0x6f64652c206e616d, 0x652c206c69737465, 0x6e65727d293b0a20, 0x2020207d0a0a2020, - 0x202066756e637469, 0x6f6e206465636f64, 0x6528627974657329, 0x207b0a2020202020, 0x2020206966202821, - 0x2862797465732069, 0x6e7374616e63656f, 0x662055696e743841, 0x7272617929207c7c, 0x2062797465732e6c, - 0x656e677468203c20, 0x36207c7c20627974, 0x65732e6c656e6774, 0x68203e206d617842, 0x79746573207c7c20, - 0x62797465735b305d, 0x20213d3d2035207c, 0x7c2062797465735b, 0x315d20213d3d2031, 0x207c7c0a20202020, - 0x2020202020202020, 0x2862797465735b32, 0x5d207c2062797465, 0x735b335d207c2062, 0x797465735b345d20, - 0x7c2062797465735b, 0x355d29203d3d3d20, 0x30290a2020202020, 0x2020202020202074, 0x68726f77206e6577, - 0x2052616e67654572, 0x726f722827696e76, 0x616c696420444f4d, 0x2062617463682068, 0x6561646572206f72, - 0x2073697a6527293b, 0x0a20202020202020, 0x20636f6e73742069, 0x6e707574203d2072, 0x6561646572286279, - 0x746573292c206f70, 0x65726174696f6e73, 0x203d205b5d3b0a20, 0x202020202020202f, 0x2f2052657461696e, - 0x2065616368206675, 0x6c6c79206465636f, 0x646564204e414d45, 0x206576656e206966, 0x2061206c61746572, - 0x206f706572617469, 0x6f6e206f72207661, 0x6c69646174696f6e, 0x2072656a65637473, 0x2074686520626174, - 0x63682e0a20202020, 0x202020207768696c, 0x65202821696e7075, 0x742e646f6e652920, 0x7b0a202020202020, - 0x2020202020206966, 0x20286f7065726174, 0x696f6e732e6c656e, 0x677468203d3d3d20, 0x6d61784f70657261, - 0x74696f6e73292074, 0x68726f77206e6577, 0x2052616e67654572, 0x726f722827444f4d, 0x206261746368206f, - 0x7065726174696f6e, 0x206c696d69742065, 0x7863656564656427, 0x293b0a2020202020, 0x2020202020202063, - 0x6f6e7374206f7020, 0x3d20696e7075742e, 0x6279746528293b0a, 0x2020202020202020, 0x2020202069662028, - 0x6f70203c2031207c, 0x7c206f70203e2031, 0x3329207468726f77, 0x206e657720457272, 0x6f722860756e6b6e, - 0x6f776e20444f4d20, 0x6f7065726174696f, 0x6e20247b6f707d60, 0x293b0a2020202020, 0x2020202020202063, - 0x6f6e73742061203d, 0x20696e7075742e75, 0x696e7428293b0a20, 0x2020202020202020, 0x202020636f6e7374, - 0x2062203d205b322c, 0x20342c20352c2036, 0x2c20382c20392c20, 0x31312c2031322c20, 0x31335d2e696e636c, - 0x75646573286f7029, 0x203f20696e707574, 0x2e75696e74282920, 0x3a20303b0a202020, 0x2020202020202020, - 0x20636f6e73742063, 0x203d206f70203d3d, 0x3d2039203f20696e, 0x7075742e75696e74, 0x2829203a206f7020, - 0x3d3d3d203131203f, 0x20696e7075742e62, 0x7974652829203a20, 0x303b0a2020202020, 0x2020202020202063, - 0x6f6e73742076616c, 0x7565203d205b312c, 0x20332c20342c2036, 0x2c20375d2e696e63, 0x6c75646573286f70, - 0x29203f20696e7075, 0x742e737472696e67, 0x2829203a2027273b, 0x0a20202020202020, 0x2020202020696620, - 0x286f70203d3d3d20, 0x3129207b0a202020, 0x2020202020202020, 0x2020202020636f6e, 0x73742073697a6520, - 0x3d20656e636f6465, 0x722e656e636f6465, 0x2876616c7565292e, 0x6c656e6774683b0a, 0x2020202020202020, - 0x2020202020202020, 0x696620286120213d, 0x3d206e616d65732e, 0x6c656e677468207c, 0x7c2061203e3d206d, - 0x6178456e74726965, 0x73207c7c2073697a, 0x65203e2031303234, 0x207c7c2073697a65, 0x203e206d61784e61, - 0x6d65427974657320, 0x2d206e616d654279, 0x746573290a202020, 0x2020202020202020, 0x2020202020202020, - 0x207468726f77206e, 0x6577204572726f72, 0x2827696e76616c69, 0x6420444f4d206e61, 0x6d6520646566696e, - 0x6974696f6e206f72, 0x2064696374696f6e, 0x6172792062756467, 0x657427293b0a2020, 0x2020202020202020, - 0x2020202020206e61, 0x6d65732e70757368, 0x2876616c7565293b, 0x0a20202020202020, 0x2020202020202020, - 0x206e616d65427974, 0x6573202b3d207369, 0x7a653b0a20202020, 0x2020202020202020, 0x7d0a202020202020, - 0x2020202020206f70, 0x65726174696f6e73, 0x2e70757368287b6f, 0x702c20612c20622c, 0x20632c2076616c75, - 0x652c206e616d654c, 0x696d69743a206e61, 0x6d65732e6c656e67, 0x74687d293b0a2020, 0x2020202020207d0a, - 0x2020202020202020, 0x72657475726e206f, 0x7065726174696f6e, 0x733b0a202020207d, 0x0a0a202020206675, - 0x6e6374696f6e2061, 0x70706c7928627974, 0x657329207b0a2020, 0x202020202020636f, 0x6e7374206f706572, - 0x6174696f6e73203d, 0x206465636f646528, 0x6279746573293b0a, 0x2020202020202020, 0x2f2f204f6e6c7920, - 0x6564697465642072, 0x65636f7264732061, 0x6e64206368696c64, 0x2d7365742064656c, 0x7461732061726520, - 0x636f706965642e20, 0x556e746f75636865, 0x6420656e74726965, 0x7320737461792069, 0x6e20746865206c69, - 0x7665207461626c65, 0x2e0a202020202020, 0x2020636f6e737420, 0x6368616e67657320, 0x3d206e6577204d61, - 0x7028292c206e6577, 0x4d6f756e7473203d, 0x206e6577204d6170, 0x28293b0a20202020, 0x202020206c657420, - 0x6c69766553697a65, 0x203d206e6f646573, 0x2e73697a653b0a20, 0x2020202020202063, 0x6f6e7374206c6f6f, - 0x6b7570203d206964, 0x203d3e206368616e, 0x6765732e68617328, 0x696429203f206368, 0x616e6765732e6765, - 0x7428696429203a20, 0x6e6f6465732e6765, 0x74286964293b0a20, 0x2020202020202063, 0x6f6e737420737465, - 0x7073203d205b5d3b, 0x0a20202020202020, 0x20636f6e73742067, 0x6574203d20696420, 0x3d3e207b0a202020, - 0x2020202020202020, 0x20636f6e73742065, 0x6e747279203d206c, 0x6f6f6b7570286964, 0x293b0a2020202020, - 0x2020202020202069, 0x66202821656e7472, 0x7929207468726f77, 0x206e657720457272, 0x6f722860756e6b6e, - 0x6f776e20444f4d20, 0x6e6f646520247b69, 0x647d60293b0a2020, 0x2020202020202020, 0x202072657475726e, - 0x20656e7472793b0a, 0x2020202020202020, 0x7d3b0a2020202020, 0x202020636f6e7374, 0x2065646974203d20, - 0x6964203d3e207b0a, 0x2020202020202020, 0x20202020636f6e73, 0x7420656e74727920, 0x3d20676574286964, - 0x293b0a2020202020, 0x2020202020202069, 0x662028216368616e, 0x6765732e68617328, 0x6964292920636861, - 0x6e6765732e736574, 0x2869642c207b2e2e, 0x2e656e7472792c20, 0x6368696c6472656e, 0x3a206e6577204368, - 0x696c6444656c7461, 0x28656e7472792e63, 0x68696c6472656e29, 0x7d293b0a20202020, 0x2020202020202020, - 0x72657475726e2063, 0x68616e6765732e67, 0x6574286964293b0a, 0x2020202020202020, 0x7d3b0a2020202020, - 0x202020636f6e7374, 0x207772697461626c, 0x65203d206964203d, 0x3e207b0a20202020, 0x2020202020202020, - 0x636f6e737420656e, 0x747279203d206765, 0x74286964293b0a20, 0x2020202020202020, 0x2020206966202865, - 0x6e7472792e69736c, 0x616e642920746872, 0x6f77206e65772045, 0x72726f7228277468, 0x652070616765206f, - 0x776e732074686520, 0x69736c616e642065, 0x6c656d656e742729, 0x3b0a202020202020, 0x2020202020207265, - 0x7475726e20656e74, 0x72793b0a20202020, 0x202020207d3b0a20, 0x2020202020202063, 0x6f6e737420656c65, - 0x6d656e74203d2069, 0x64203d3e207b0a20, 0x2020202020202020, 0x202020636f6e7374, 0x20656e747279203d, - 0x207772697461626c, 0x65286964293b0a20, 0x2020202020202020, 0x2020206966202865, 0x6e7472792e746578, - 0x7429207468726f77, 0x206e657720457272, 0x6f72282765787065, 0x6374656420444f4d, 0x20656c656d656e74, + 0x7472696e67286e6f, 0x64652e76616c7565, 0x203f3f2027272929, 0x0a20202020202020, 0x2020202020202020, + 0x203a206e616d6520, 0x3d3d3d20276b6579, 0x646f776e27207c7c, 0x206e616d65203d3d, 0x3d20276b65797570, + 0x27203f206576656e, 0x742e6b6579203a20, 0x27273b0a20202020, 0x2020202020202020, 0x6272696467652e63, + 0x707046756e637469, 0x6f6e28277766446f, 0x6d2e6576656e7427, 0x292869642c20696e, 0x6465782c2076616c, + 0x7565292e63617463, 0x68286572726f7220, 0x3d3e207b0a202020, 0x2020202020202020, 0x2020202020636f6e, + 0x736f6c652e657272, 0x6f72282757656246, 0x726f6e7420444f4d, 0x206576656e742064, 0x656c697665727920, + 0x6661696c6564272c, 0x206572726f72293b, 0x0a20202020202020, 0x20202020207d293b, 0x0a20202020202020, + 0x207d3b0a20202020, 0x202020206e6f6465, 0x2e6164644576656e, 0x744c697374656e65, 0x72286e616d652c20, + 0x6c697374656e6572, 0x293b0a2020202020, 0x2020206c65742067, 0x726f7570203d206c, 0x697374656e657273, + 0x2e67657428696429, 0x3b0a202020202020, 0x2020696620282167, 0x726f757029207b20, 0x67726f7570203d20, + 0x6e6577204d617028, 0x293b206c69737465, 0x6e6572732e736574, 0x2869642c2067726f, 0x7570293b207d0a20, + 0x2020202020202067, 0x726f75702e736574, 0x28696e6465782c20, 0x7b6e6f64652c206e, 0x616d652c206c6973, + 0x74656e65727d293b, 0x0a202020207d0a0a, 0x2020202066756e63, 0x74696f6e20646563, 0x6f64652862797465, + 0x7329207b0a202020, 0x2020202020696620, 0x2821286279746573, 0x20696e7374616e63, 0x656f662055696e74, + 0x3841727261792920, 0x7c7c206279746573, 0x2e6c656e67746820, 0x3c2036207c7c2062, 0x797465732e6c656e, + 0x677468203e206d61, 0x784279746573207c, 0x7c2062797465735b, 0x305d20213d3d2035, 0x207c7c2062797465, + 0x735b315d20213d3d, 0x2031207c7c0a2020, 0x2020202020202020, 0x2020286279746573, 0x5b325d207c206279, + 0x7465735b335d207c, 0x2062797465735b34, 0x5d207c2062797465, 0x735b355d29203d3d, 0x3d2030290a202020, + 0x2020202020202020, 0x207468726f77206e, 0x65772052616e6765, 0x4572726f72282769, 0x6e76616c69642044, + 0x4f4d206261746368, 0x2068656164657220, 0x6f722073697a6527, 0x293b0a2020202020, 0x202020636f6e7374, + 0x20696e707574203d, 0x2072656164657228, 0x6279746573292c20, 0x6f7065726174696f, 0x6e73203d205b5d3b, + 0x0a20202020202020, 0x202f2f2052657461, 0x696e206561636820, 0x66756c6c79206465, 0x636f646564204e41, + 0x4d45206576656e20, 0x69662061206c6174, 0x6572206f70657261, 0x74696f6e206f7220, 0x76616c6964617469, + 0x6f6e2072656a6563, 0x7473207468652062, 0x617463682e0a2020, 0x2020202020207768, 0x696c65202821696e, + 0x7075742e646f6e65, 0x29207b0a20202020, 0x2020202020202020, 0x696620286f706572, 0x6174696f6e732e6c, + 0x656e677468203d3d, 0x3d206d61784f7065, 0x726174696f6e7329, 0x207468726f77206e, 0x65772052616e6765, + 0x4572726f72282744, 0x4f4d206261746368, 0x206f706572617469, 0x6f6e206c696d6974, 0x2065786365656465, + 0x6427293b0a202020, 0x2020202020202020, 0x20636f6e7374206f, 0x70203d20696e7075, 0x742e627974652829, + 0x3b0a202020202020, 0x2020202020206966, 0x20286f70203c2031, 0x207c7c206f70203e, 0x2031332920746872, + 0x6f77206e65772045, 0x72726f722860756e, 0x6b6e6f776e20444f, 0x4d206f7065726174, 0x696f6e20247b6f70, + 0x7d60293b0a202020, 0x2020202020202020, 0x20636f6e73742061, 0x203d20696e707574, 0x2e75696e7428293b, + 0x0a20202020202020, 0x2020202020636f6e, 0x73742062203d205b, 0x322c20342c20352c, 0x20362c20382c2039, + 0x2c2031312c203132, 0x2c2031335d2e696e, 0x636c75646573286f, 0x7029203f20696e70, 0x75742e75696e7428, + 0x29203a20303b0a20, 0x2020202020202020, 0x202020636f6e7374, 0x2063203d206f7020, 0x3d3d3d2039203f20, + 0x696e7075742e7569, 0x6e742829203a206f, 0x70203d3d3d203131, 0x203f20696e707574, 0x2e62797465282920, + 0x3a20303b0a202020, 0x2020202020202020, 0x20636f6e73742076, 0x616c7565203d205b, 0x312c20332c20342c, + 0x20362c20375d2e69, 0x6e636c7564657328, 0x6f7029203f20696e, 0x7075742e73747269, 0x6e672829203a2027, + 0x273b0a2020202020, 0x2020202020202069, 0x6620286f70203d3d, 0x3d203129207b0a20, 0x2020202020202020, + 0x2020202020202063, 0x6f6e73742073697a, 0x65203d20656e636f, 0x6465722e656e636f, 0x64652876616c7565, + 0x292e6c656e677468, 0x3b0a202020202020, 0x2020202020202020, 0x2020696620286120, 0x213d3d206e616d65, + 0x732e6c656e677468, 0x207c7c2061203e3d, 0x206d6178456e7472, 0x696573207c7c2073, 0x697a65203e203130, + 0x3234207c7c207369, 0x7a65203e206d6178, 0x4e616d6542797465, 0x73202d206e616d65, 0x4279746573290a20, + 0x2020202020202020, 0x2020202020202020, 0x2020207468726f77, 0x206e657720457272, 0x6f722827696e7661, + 0x6c696420444f4d20, 0x6e616d6520646566, 0x696e6974696f6e20, 0x6f72206469637469, 0x6f6e617279206275, + 0x6467657427293b0a, 0x2020202020202020, 0x2020202020202020, 0x6e616d65732e7075, 0x73682876616c7565, + 0x293b0a2020202020, 0x2020202020202020, 0x2020206e616d6542, 0x79746573202b3d20, 0x73697a653b0a2020, + 0x2020202020202020, 0x20207d0a20202020, 0x2020202020202020, 0x6f7065726174696f, 0x6e732e7075736828, + 0x7b6f702c20612c20, 0x622c20632c207661, 0x6c75652c206e616d, 0x654c696d69743a20, 0x6e616d65732e6c65, + 0x6e6774687d293b0a, 0x2020202020202020, 0x7d0a202020202020, 0x202072657475726e, 0x206f706572617469, + 0x6f6e733b0a202020, 0x207d0a0a20202020, 0x66756e6374696f6e, 0x206170706c792862, 0x7974657329207b0a, + 0x2020202020202020, 0x636f6e7374206f70, 0x65726174696f6e73, 0x203d206465636f64, 0x6528627974657329, + 0x3b0a202020202020, 0x20202f2f204f6e6c, 0x7920656469746564, 0x207265636f726473, 0x20616e6420636869, + 0x6c642d7365742064, 0x656c746173206172, 0x6520636f70696564, 0x2e20556e746f7563, 0x68656420656e7472, + 0x6965732073746179, 0x20696e2074686520, 0x6c69766520746162, 0x6c652e0a20202020, 0x20202020636f6e73, + 0x74206368616e6765, 0x73203d206e657720, 0x4d617028292c206e, 0x65774d6f756e7473, 0x203d206e6577204d, + 0x617028293b0a2020, 0x2020202020206c65, 0x74206c6976655369, 0x7a65203d206e6f64, 0x65732e73697a653b, + 0x0a20202020202020, 0x20636f6e7374206c, 0x6f6f6b7570203d20, 0x6964203d3e206368, 0x616e6765732e6861, + 0x7328696429203f20, 0x6368616e6765732e, 0x6765742869642920, 0x3a206e6f6465732e, 0x676574286964293b, + 0x0a20202020202020, 0x20636f6e73742073, 0x74657073203d205b, 0x5d3b0a2020202020, 0x202020636f6e7374, + 0x20676574203d2069, 0x64203d3e207b0a20, 0x2020202020202020, 0x202020636f6e7374, 0x20656e747279203d, + 0x206c6f6f6b757028, 0x6964293b0a202020, 0x2020202020202020, 0x206966202821656e, 0x7472792920746872, + 0x6f77206e65772045, 0x72726f722860756e, 0x6b6e6f776e20444f, 0x4d206e6f64652024, 0x7b69647d60293b0a, + 0x2020202020202020, 0x2020202072657475, 0x726e20656e747279, 0x3b0a202020202020, 0x20207d3b0a202020, + 0x2020202020636f6e, 0x7374206564697420, 0x3d206964203d3e20, 0x7b0a202020202020, 0x202020202020636f, + 0x6e737420656e7472, 0x79203d2067657428, 0x6964293b0a202020, 0x2020202020202020, 0x2069662028216368, + 0x616e6765732e6861, 0x7328696429292063, 0x68616e6765732e73, 0x65742869642c207b, 0x2e2e2e656e747279, + 0x2c206368696c6472, 0x656e3a206e657720, 0x4368696c6444656c, 0x746128656e747279, 0x2e6368696c647265, + 0x6e297d293b0a2020, 0x2020202020202020, 0x202072657475726e, 0x206368616e676573, 0x2e67657428696429, + 0x3b0a202020202020, 0x20207d3b0a202020, 0x2020202020636f6e, 0x7374207772697461, 0x626c65203d206964, + 0x203d3e207b0a2020, 0x2020202020202020, 0x2020636f6e737420, 0x656e747279203d20, 0x676574286964293b, + 0x0a20202020202020, 0x2020202020696620, 0x28656e7472792e69, 0x736c616e64292074, 0x68726f77206e6577, + 0x204572726f722827, 0x7468652070616765, 0x206f776e73207468, 0x652069736c616e64, 0x20656c656d656e74, 0x27293b0a20202020, 0x2020202020202020, 0x72657475726e2065, 0x6e7472793b0a2020, 0x2020202020207d3b, - 0x0a20202020202020, 0x20636f6e73742066, 0x72657368203d2028, 0x69642c20656e7472, 0x7929203d3e207b0a, - 0x2020202020202020, 0x2020202069662028, 0x216964207c7c206c, 0x6f6f6b7570286964, 0x29207c7c206c6976, - 0x6553697a65203e3d, 0x206d6178456e7472, 0x6965732920746872, 0x6f77206e65772045, 0x72726f722827696e, - 0x76616c6964206f72, 0x206475706c696361, 0x746520444f4d206e, 0x6f646527293b0a20, 0x2020202020202020, - 0x2020206368616e67, 0x65732e7365742869, 0x642c207b2e2e2e65, 0x6e7472792c207061, 0x72656e743a206e75, - 0x6c6c2c206368696c, 0x6472656e3a206e65, 0x772053657428297d, 0x293b0a2020202020, 0x202020202020202b, - 0x2b6c69766553697a, 0x653b0a2020202020, 0x2020207d3b0a2020, 0x202020202020636f, 0x6e737420666f7267, - 0x6574203d20696420, 0x3d3e207b0a202020, 0x2020202020202020, 0x202f2f2049746572, 0x6174697665207472, - 0x6176657273616c3a, 0x20686f7374696c65, 0x2064656570207472, 0x656573206d757374, 0x206e6f74206f7665, - 0x72666c6f77207468, 0x65204a6176615363, 0x7269707420737461, 0x636b2e0a20202020, 0x2020202020202020, - 0x636f6e7374207065, 0x6e64696e67203d20, 0x5b69645d3b0a2020, 0x2020202020202020, 0x20207768696c6520, - 0x2870656e64696e67, 0x2e6c656e67746829, 0x207b0a2020202020, 0x2020202020202020, 0x202020636f6e7374, - 0x2063757272656e74, 0x203d2070656e6469, 0x6e672e706f702829, 0x2c20656e74727920, 0x3d20676574286375, - 0x7272656e74293b0a, 0x2020202020202020, 0x2020202020202020, 0x666f722028636f6e, 0x7374206368696c64, - 0x206f6620656e7472, 0x792e6368696c6472, 0x656e292070656e64, 0x696e672e70757368, 0x286368696c64293b, - 0x0a20202020202020, 0x2020202020202020, 0x206368616e676573, 0x2e73657428637572, 0x72656e742c206e75, - 0x6c6c293b0a202020, 0x2020202020202020, 0x20202020202d2d6c, 0x69766553697a653b, 0x0a20202020202020, - 0x20202020207d0a20, 0x202020202020207d, 0x3b0a202020202020, 0x2020666f72202863, 0x6f6e7374207b6f70, - 0x2c20612c20622c20, 0x632c2076616c7565, 0x2c206e616d654c69, 0x6d69747d206f6620, 0x6f7065726174696f, - 0x6e7329207b0a2020, 0x2020202020202020, 0x2020636f6e737420, 0x6e616d654174203d, 0x20696e646578203d, - 0x3e207b0a20202020, 0x2020202020202020, 0x2020202069662028, 0x696e646578203e3d, 0x206e616d654c696d, - 0x697429207468726f, 0x77206e6577204572, 0x726f722860756e6b, 0x6e6f776e20444f4d, 0x206e616d6520247b, - 0x696e6465787d6029, 0x3b0a202020202020, 0x2020202020202020, 0x202072657475726e, 0x206e616d65735b69, - 0x6e6465785d3b0a20, 0x2020202020202020, 0x2020207d3b0a2020, 0x2020202020202020, 0x2020737769746368, - 0x20286f7029207b0a, 0x2020202020202020, 0x2020202063617365, 0x20313a2062726561, 0x6b3b0a2020202020, - 0x2020202020202063, 0x61736520323a207b, 0x0a20202020202020, 0x2020202020202020, 0x20636f6e73742074, - 0x6167203d206e616d, 0x6541742862293b0a, 0x2020202020202020, 0x2020202020202020, 0x6966202821746167, - 0x732e686173287461, 0x6729207c7c20666f, 0x7262696464656e54, 0x6167732e68617328, 0x7461672929207468, - 0x726f77206e657720, 0x4572726f72286066, 0x6f7262696464656e, 0x20444f4d20746167, 0x20247b7461677d60, - 0x293b0a2020202020, 0x2020202020202020, 0x2020206672657368, 0x28612c207b746167, 0x2c20746578743a20, - 0x66616c73657d293b, 0x0a20202020202020, 0x2020202020202020, 0x2073746570732e70, 0x757368282829203d, - 0x3e207b206e6f6465, 0x732e73657428612c, 0x207b6e6f64653a20, 0x646f63756d656e74, 0x2e63726561746545, - 0x6c656d656e742874, 0x6167297d293b207d, 0x293b0a2020202020, 0x2020202020202020, 0x202020627265616b, - 0x3b0a202020202020, 0x2020202020207d0a, 0x2020202020202020, 0x2020202063617365, 0x20333a0a20202020, - 0x2020202020202020, 0x2020202066726573, 0x6828612c207b7465, 0x78743a2074727565, 0x7d293b0a20202020, - 0x2020202020202020, 0x2020202073746570, 0x732e707573682828, 0x29203d3e207b206e, 0x6f6465732e736574, - 0x28612c207b6e6f64, 0x653a20646f63756d, 0x656e742e63726561, 0x7465546578744e6f, 0x64652876616c7565, - 0x297d293b207d293b, 0x0a20202020202020, 0x2020202020202020, 0x20627265616b3b0a, 0x2020202020202020, - 0x2020202063617365, 0x20343a2063617365, 0x20353a207b0a2020, 0x2020202020202020, 0x202020202020656c, - 0x656d656e74286129, 0x3b0a202020202020, 0x2020202020202020, 0x2020636f6e737420, 0x6e616d65203d206e, - 0x616d654174286229, 0x3b0a202020202020, 0x2020202020202020, 0x2020696620282161, 0x6c6c6f7765644174, - 0x7472696275746528, 0x6e616d6529292074, 0x68726f77206e6577, 0x204572726f722860, 0x666f726269646465, - 0x6e20444f4d206174, 0x7472696275746520, 0x247b6e616d657d60, 0x293b0a2020202020, 0x2020202020202020, - 0x202020696620286f, 0x70203d3d3d203420, 0x26262075726c4174, 0x7472696275746573, 0x2e686173286e616d, - 0x6529202626202173, 0x61666555726c2876, 0x616c756529292074, 0x68726f77206e6577, 0x204572726f722827, - 0x756e736166652044, 0x4f4d2055524c2729, 0x3b0a202020202020, 0x2020202020202020, 0x202073746570732e, - 0x7075736828282920, 0x3d3e206f70203d3d, 0x3d2034203f206e6f, 0x6465732e67657428, 0x61292e6e6f64652e, - 0x7365744174747269, 0x62757465286e616d, 0x652c2076616c7565, 0x29203a206e6f6465, 0x732e676574286129, - 0x2e6e6f64652e7265, 0x6d6f766541747472, 0x6962757465286e61, 0x6d6529293b0a2020, 0x2020202020202020, - 0x2020202020206272, 0x65616b3b0a202020, 0x2020202020202020, 0x207d0a2020202020, 0x2020202020202063, - 0x61736520363a207b, 0x0a20202020202020, 0x2020202020202020, 0x20636f6e73742065, 0x6e747279203d2065, - 0x6c656d656e742861, 0x293b0a2020202020, 0x2020202020202020, 0x202020636f6e7374, 0x206e616d65203d20, - 0x6e616d6541742862, 0x293b0a2020202020, 0x2020202020202020, 0x2020206966202821, 0x70726f7065727479, - 0x4e616d65732e6861, 0x73286e616d652929, 0x207468726f77206e, 0x6577204572726f72, 0x2860666f72626964, - 0x64656e20444f4d20, 0x70726f7065727479, 0x20247b6e616d657d, 0x60293b0a20202020, 0x2020202020202020, - 0x202020202f2f2054, 0x6865206e61746976, 0x65206f7574707574, 0x2e76616c75652073, 0x6574746572207265, - 0x706c616365732063, 0x68696c6472656e20, 0x626568696e642074, 0x686520747261636b, 0x6564207472656527, - 0x73206261636b2e0a, 0x2020202020202020, 0x2020202020202020, 0x696620286e616d65, 0x203d3d3d20277661, - 0x6c75652720262620, 0x656e7472792e7461, 0x67203d3d3d20276f, 0x757470757427290a, 0x2020202020202020, - 0x2020202020202020, 0x202020207468726f, 0x77206e6577204572, 0x726f72282750524f, 0x5045525459207661, - 0x6c7565206f6e206f, 0x7574707574207265, 0x7175697265732065, 0x78706c6963697420, 0x746578742d6e6f64, - 0x6520757064617465, 0x7327293b0a202020, 0x2020202020202020, 0x2020202020696620, 0x285b27636865636b, - 0x6564272c20276469, 0x7361626c6564272c, 0x2027696e64657465, 0x726d696e61746527, 0x5d2e696e636c7564, - 0x6573286e616d6529, 0x20262620215b2774, 0x727565272c202766, 0x616c7365275d2e69, 0x6e636c7564657328, - 0x76616c756529290a, 0x2020202020202020, 0x2020202020202020, 0x202020207468726f, 0x77206e6577204572, - 0x726f722827696e76, 0x616c696420444f4d, 0x20626f6f6c65616e, 0x27293b0a20202020, 0x2020202020202020, - 0x2020202069662028, 0x6e616d65203d3d3d, 0x202773656c656374, 0x6564496e64657827, 0x2026262028212f5e, - 0x2d3f5c642b242f2e, 0x746573742876616c, 0x756529207c7c2021, 0x4e756d6265722e69, 0x73496e7465676572, - 0x284e756d62657228, 0x76616c7565292920, 0x7c7c204e756d6265, 0x722876616c756529, 0x203c202d31207c7c, - 0x204e756d62657228, 0x76616c756529203e, 0x2032313437343833, 0x36343729290a2020, 0x2020202020202020, - 0x2020202020202020, 0x20207468726f7720, 0x6e6577204572726f, 0x722827696e76616c, 0x696420444f4d2073, - 0x656c656374656449, 0x6e64657827293b0a, 0x2020202020202020, 0x2020202020202020, 0x636f6e737420636f, - 0x6e76657274656420, 0x3d206e616d65203d, 0x3d3d202776616c75, 0x6527203f2076616c, 0x7565203a206e616d, - 0x65203d3d3d202773, 0x656c656374656449, 0x6e64657827203f20, 0x4e756d6265722876, 0x616c756529203a20, - 0x76616c7565203d3d, 0x3d20277472756527, 0x3b0a202020202020, 0x2020202020202020, 0x202073746570732e, - 0x7075736828282920, 0x3d3e207b206e6f64, 0x65732e6765742861, 0x292e6e6f64655b6e, 0x616d655d203d2063, - 0x6f6e766572746564, 0x3b207d293b0a2020, 0x2020202020202020, 0x2020202020206272, 0x65616b3b0a202020, - 0x2020202020202020, 0x207d0a2020202020, 0x2020202020202063, 0x61736520373a0a20, 0x2020202020202020, - 0x2020202020202069, 0x6620282177726974, 0x61626c652861292e, 0x7465787429207468, 0x726f77206e657720, - 0x4572726f72282753, 0x45545f5445585420, 0x7265717569726573, 0x2061207465787420, 0x6e6f646527293b0a, - 0x2020202020202020, 0x2020202020202020, 0x73746570732e7075, 0x7368282829203d3e, 0x207b206e6f646573, - 0x2e6765742861292e, 0x6e6f64652e646174, 0x61203d2076616c75, 0x653b207d293b0a20, 0x2020202020202020, - 0x2020202020202062, 0x7265616b3b0a2020, 0x2020202020202020, 0x2020636173652038, 0x3a20636173652039, - 0x3a207b0a20202020, 0x2020202020202020, 0x20202020636f6e73, 0x7420706172656e74, 0x203d206765742861, - 0x292c206368696c64, 0x203d207772697461, 0x626c652862293b0a, 0x2020202020202020, 0x2020202020202020, - 0x6966202870617265, 0x6e742e7465787429, 0x207468726f77206e, 0x6577204572726f72, 0x2827612074657874, - 0x206e6f6465206361, 0x6e6e6f74206f776e, 0x206368696c647265, 0x6e27293b0a202020, 0x2020202020202020, - 0x2020202020696620, 0x286f70203d3d3d20, 0x3920262620676574, 0x2863292e70617265, 0x6e7420213d3d2061, - 0x29207468726f7720, 0x6e6577204572726f, 0x722827696e736572, 0x744265666f726520, 0x7265666572656e63, - 0x65206973206e6f74, 0x2061206368696c64, 0x27293b0a20202020, 0x2020202020202020, 0x20202020666f7220, - 0x286c657420616e63, 0x6573746f72203d20, 0x613b20616e636573, 0x746f7220213d3d20, 0x6e756c6c3b20616e, - 0x636573746f72203d, 0x2067657428616e63, 0x6573746f72292e70, 0x6172656e74290a20, 0x2020202020202020, - 0x2020202020202020, 0x2020206966202861, 0x6e636573746f7220, 0x3d3d3d2062292074, 0x68726f77206e6577, - 0x204572726f722827, 0x444f4d206379636c, 0x6527293b0a202020, 0x2020202020202020, 0x2020202020696620, - 0x286368696c642e70, 0x6172656e7420213d, 0x3d206e756c6c2920, 0x6564697428636869, 0x6c642e706172656e, - 0x74292e6368696c64, 0x72656e2e64656c65, 0x74652862293b0a20, 0x2020202020202020, 0x2020202020202065, - 0x6469742862292e70, 0x6172656e74203d20, 0x613b0a2020202020, 0x2020202020202020, 0x2020206564697428, - 0x61292e6368696c64, 0x72656e2e61646428, 0x62293b0a20202020, 0x2020202020202020, 0x2020202073746570, - 0x732e707573682828, 0x29203d3e206f7020, 0x3d3d3d2038203f20, 0x6e6f6465732e6765, 0x742861292e6e6f64, - 0x652e617070656e64, 0x4368696c64286e6f, 0x6465732e67657428, 0x62292e6e6f646529, 0x203a0a2020202020, - 0x2020202020202020, 0x202020202020206e, 0x6f6465732e676574, 0x2861292e6e6f6465, 0x2e696e7365727442, - 0x65666f7265286e6f, 0x6465732e67657428, 0x62292e6e6f64652c, 0x206e6f6465732e67, 0x65742863292e6e6f, - 0x646529293b0a2020, 0x2020202020202020, 0x2020202020206272, 0x65616b3b0a202020, 0x2020202020202020, - 0x207d0a2020202020, 0x2020202020202063, 0x6173652031303a20, 0x7b0a202020202020, 0x2020202020202020, - 0x2020636f6e737420, 0x656e747279203d20, 0x7772697461626c65, 0x2861293b0a202020, 0x2020202020202020, - 0x2020202020696620, 0x28656e7472792e70, 0x6172656e7420213d, 0x3d206e756c6c2920, 0x6564697428656e74, - 0x72792e706172656e, 0x74292e6368696c64, 0x72656e2e64656c65, 0x74652861293b0a20, 0x2020202020202020, - 0x2020202020202063, 0x6f6e73742072656d, 0x6f766564203d205b, 0x5d3b0a2020202020, 0x2020202020202020, - 0x202020636f6e7374, 0x2070656e64696e67, 0x203d205b615d3b0a, 0x2020202020202020, 0x2020202020202020, - 0x7768696c65202870, 0x656e64696e672e6c, 0x656e67746829207b, 0x0a20202020202020, 0x2020202020202020, - 0x2020202020636f6e, 0x7374206964203d20, 0x70656e64696e672e, 0x706f7028293b0a20, 0x2020202020202020, - 0x2020202020202020, 0x20202072656d6f76, 0x65642e7075736828, 0x6964293b0a202020, 0x2020202020202020, - 0x2020202020202020, 0x20666f722028636f, 0x6e7374206368696c, 0x64206f6620676574, 0x286964292e636869, - 0x6c6472656e292070, 0x656e64696e672e70, 0x757368286368696c, 0x64293b0a20202020, 0x2020202020202020, - 0x202020207d0a2020, 0x2020202020202020, 0x202020202020666f, 0x726765742861293b, 0x0a20202020202020, - 0x2020202020202020, 0x2073746570732e70, 0x757368282829203d, 0x3e207b0a20202020, 0x2020202020202020, - 0x2020202020202020, 0x6e6f6465732e6765, 0x742861292e6e6f64, 0x652e72656d6f7665, 0x28293b0a20202020, - 0x2020202020202020, 0x2020202020202020, 0x666f722028636f6e, 0x7374206964206f66, 0x2072656d6f766564, - 0x29206e6f6465732e, 0x64656c6574652869, 0x64293b0a20202020, 0x2020202020202020, 0x2020202020202020, - 0x636c65616e4c6973, 0x74656e6572732872, 0x656d6f766564293b, 0x0a20202020202020, 0x2020202020202020, - 0x207d293b0a202020, 0x2020202020202020, 0x2020202020627265, 0x616b3b0a20202020, 0x2020202020202020, - 0x7d0a202020202020, 0x2020202020206361, 0x73652031313a2063, 0x6173652031323a20, 0x7b0a202020202020, - 0x2020202020202020, 0x2020656c656d656e, 0x742861293b0a2020, 0x2020202020202020, 0x202020202020636f, - 0x6e7374206e616d65, 0x203d206e616d6541, 0x742862293b0a2020, 0x2020202020202020, 0x2020202020206966, - 0x2028216576656e74, 0x732e686173286e61, 0x6d6529207c7c2063, 0x203e203329207468, 0x726f77206e657720, - 0x4572726f72282769, 0x6e76616c69642044, 0x4f4d206576656e74, 0x206f7220666c6167, 0x7327293b0a202020, - 0x2020202020202020, 0x2020202020737465, 0x70732e7075736828, 0x2829203d3e206f70, 0x203d3d3d20313120, - 0x3f206c697374656e, 0x28612c20622c206e, 0x616d652c20632920, 0x3a20756e6c697374, 0x656e28612c206229, - 0x293b0a2020202020, 0x2020202020202020, 0x202020627265616b, 0x3b0a202020202020, 0x2020202020207d0a, - 0x2020202020202020, 0x2020202063617365, 0x2031333a207b0a20, 0x2020202020202020, 0x2020202020202063, - 0x6f6e7374206e616d, 0x65203d206e616d65, 0x41742862292c206e, 0x6f6465203d206973, 0x6c616e64732e6765, - 0x74286e616d65293f, 0x2e656c656d656e74, 0x3b0a202020202020, 0x2020202020202020, 0x202069662028216e, - 0x6f64652920746872, 0x6f77206e65772045, 0x72726f722860756e, 0x6b6e6f776e20444f, 0x4d2069736c616e64, - 0x20247b6e616d657d, 0x60293b0a20202020, 0x2020202020202020, 0x2020202069662028, 0x6d6f756e7465642e, - 0x686173286e6f6465, 0x29207c7c206e6577, 0x4d6f756e74732e68, 0x6173286e6f646529, 0x29207468726f7720, - 0x6e6577204572726f, 0x72282769736c616e, 0x6420616c72656164, 0x79206d6f756e7465, 0x6427293b0a202020, - 0x2020202020202020, 0x20202020206e6577, 0x4d6f756e74732e73, 0x6574286e6f64652c, 0x2061293b0a202020, - 0x2020202020202020, 0x2020202020667265, 0x736828612c207b6e, 0x6f64652c20746578, 0x743a2066616c7365, - 0x2c2069736c616e64, 0x3a20747275657d29, 0x3b0a202020202020, 0x2020202020202020, 0x202073746570732e, - 0x7075736828282920, 0x3d3e206e6f646573, 0x2e73657428612c20, 0x7b6e6f64657d2929, 0x3b0a202020202020, - 0x2020202020202020, 0x2020627265616b3b, 0x0a20202020202020, 0x20202020207d0a20, 0x2020202020202020, - 0x2020207d0a202020, 0x20202020207d0a20, 0x202020202020202f, 0x2f20526573696475, 0x616c20444f4d2065, - 0x7863657074696f6e, 0x732028666f722065, 0x78616d706c652061, 0x2070616765277320, 0x637573746f6d2065, - 0x6c656d656e742920, 0x70726f7061676174, 0x6520746f20746865, 0x2062726964676520, 0x617320612072656a, - 0x656374696f6e2e0a, 0x2020202020202020, 0x2f2f20496e207468, 0x6174206361736520, 0x6469736361726420, - 0x68616e646c65733a, 0x2074686520616374, 0x75616c20444f4d20, 0x6d61792068617665, 0x206265656e207061, - 0x72746c7920636861, 0x6e67656420616e64, 0x206d757374206265, 0x206c656e74206167, 0x61696e2e0a202020, - 0x2020202020747279, 0x207b0a2020202020, 0x2020202020202066, 0x6f722028636f6e73, 0x742073746570206f, - 0x6620737465707329, 0x207374657028293b, 0x0a20202020202020, 0x207d206361746368, 0x20286572726f7229, - 0x207b0a2020202020, 0x2020202020202063, 0x6c65616e4c697374, 0x656e657273286c69, 0x7374656e6572732e, - 0x6b6579732829293b, 0x0a20202020202020, 0x20202020206e6f64, 0x65732e636c656172, 0x28293b0a20202020, - 0x2020202020202020, 0x69736c616e64732e, 0x636c65617228293b, 0x0a20202020202020, 0x20202020206d6f75, - 0x6e746564203d206e, 0x6577205765616b4d, 0x617028293b0a2020, 0x2020202020202020, 0x20207468726f7720, - 0x6572726f723b0a20, 0x202020202020207d, 0x0a20202020202020, 0x20666f722028636f, 0x6e7374205b69642c, - 0x20656e7472795d20, 0x6f66206368616e67, 0x657329207b0a2020, 0x2020202020202020, 0x2020696620282165, - 0x6e74727929206e6f, 0x6465732e64656c65, 0x7465286964293b0a, 0x2020202020202020, 0x20202020656c7365, - 0x207b0a2020202020, 0x2020202020202020, 0x202020656e747279, 0x2e6e6f6465203d20, 0x6e6f6465732e6765, - 0x74286964292e6e6f, 0x64653b0a20202020, 0x2020202020202020, 0x2020202069662028, 0x656e7472792e6368, - 0x696c6472656e2069, 0x6e7374616e63656f, 0x66204368696c6444, 0x656c74612920656e, 0x7472792e6368696c, - 0x6472656e203d2065, 0x6e7472792e636869, 0x6c6472656e2e636f, 0x6d6d697428293b0a, 0x2020202020202020, - 0x2020202020202020, 0x6e6f6465732e7365, 0x742869642c20656e, 0x747279293b0a2020, 0x2020202020202020, - 0x20207d0a20202020, 0x202020207d0a2020, 0x202020202020666f, 0x722028636f6e7374, 0x205b6e6f64652c20, - 0x69645d206f66206e, 0x65774d6f756e7473, 0x29206d6f756e7465, 0x642e736574286e6f, 0x64652c206964293b, - 0x0a202020207d0a0a, 0x20202020636f6e73, 0x7420617069203d20, 0x7b0a202020202020, 0x20206170706c792c, - 0x0a20202020202020, 0x2069736c616e6428, 0x6e616d652c20656c, 0x656d656e7429207b, 0x0a20202020202020, - 0x2020202020696620, 0x282128656c656d65, 0x6e7420696e737461, 0x6e63656f66204854, 0x4d4c456c656d656e, - 0x7429207c7c202174, 0x6167732e68617328, 0x656c656d656e742e, 0x6c6f63616c4e616d, 0x6529207c7c20666f, - 0x7262696464656e54, 0x6167732e68617328, 0x656c656d656e742e, 0x6c6f63616c4e616d, 0x6529290a20202020, - 0x2020202020202020, 0x202020207468726f, 0x77206e6577205479, 0x70654572726f7228, 0x27616e2069736c61, - 0x6e64206d75737420, 0x626520616e20616c, 0x6c6f776564204854, 0x4d4c20656c656d65, 0x6e7427293b0a2020, - 0x2020202020202020, 0x2020636f6e737420, 0x70726576696f7573, 0x203d2069736c616e, 0x64732e676574286e, - 0x616d65293b0a2020, 0x2020202020202020, 0x2020696620287072, 0x6576696f75732026, 0x262070726576696f, - 0x75732e656c656d65, 0x6e7420213d3d2065, 0x6c656d656e742920, 0x7468726f77206e65, 0x77204572726f7228, - 0x2769736c616e6420, 0x6e616d6520616c72, 0x65616479206c656e, 0x7427293b0a202020, 0x2020202020202020, - 0x2069662028217072, 0x6576696f75732920, 0x7b0a202020202020, 0x2020202020202020, 0x202069662028656c, - 0x656d656e742e6368, 0x696c644e6f646573, 0x2e6c656e67746820, 0x7c7c204172726179, 0x2e66726f6d286973, - 0x6c616e64732e7661, 0x6c7565732829292e, 0x736f6d6528656e74, 0x7279203d3e20656e, 0x7472792e656c656d, - 0x656e74203d3d3d20, 0x656c656d656e7420, 0x7c7c20656e747279, 0x2e656c656d656e74, 0x2e636f6e7461696e, - 0x7328656c656d656e, 0x7429207c7c20656c, 0x656d656e742e636f, 0x6e7461696e732865, 0x6e7472792e656c65, - 0x6d656e742929290a, 0x2020202020202020, 0x2020202020202020, 0x202020207468726f, 0x77206e6577204572, - 0x726f72282769736c, 0x616e6473206d7573, 0x7420626520656d70, 0x747920616e642064, 0x69736a6f696e7427, - 0x293b0a2020202020, 0x202020202020207d, 0x0a20202020202020, 0x2020202020636f6e, 0x737420746f6b656e, - 0x203d207b656c656d, 0x656e747d3b0a2020, 0x2020202020202020, 0x202069736c616e64, 0x732e736574286e61, - 0x6d652c20746f6b65, 0x6e293b0a20202020, 0x2020202020202020, 0x72657475726e2028, 0x29203d3e207b0a20, - 0x2020202020202020, 0x2020202020202069, 0x66202869736c616e, 0x64732e676574286e, 0x616d652920213d3d, - 0x20746f6b656e2920, 0x72657475726e3b0a, 0x2020202020202020, 0x2020202020202020, 0x69736c616e64732e, - 0x64656c657465286e, 0x616d65293b0a2020, 0x2020202020202020, 0x202020202020636f, 0x6e737420726f6f74, - 0x4964203d206d6f75, 0x6e7465642e676574, 0x28656c656d656e74, 0x293b0a2020202020, 0x2020202020202020, - 0x2020206d6f756e74, 0x65642e64656c6574, 0x6528656c656d656e, 0x74293b0a20202020, 0x2020202020202020, - 0x2020202069662028, 0x726f6f744964203d, 0x3d3d20756e646566, 0x696e656429207265, 0x7475726e3b0a2020, - 0x2020202020202020, 0x202020202020636f, 0x6e73742070656e64, 0x696e67203d205b72, 0x6f6f7449645d3b0a, - 0x2020202020202020, 0x2020202020202020, 0x7768696c65202870, 0x656e64696e672e6c, 0x656e67746829207b, - 0x0a20202020202020, 0x2020202020202020, 0x2020202020636f6e, 0x7374206964203d20, 0x70656e64696e672e, - 0x706f7028292c2065, 0x6e747279203d206e, 0x6f6465732e676574, 0x286964293b0a2020, 0x2020202020202020, - 0x2020202020202020, 0x2020666f72202863, 0x6f6e737420636869, 0x6c64206f6620656e, 0x7472792e6368696c, - 0x6472656e29207065, 0x6e64696e672e7075, 0x7368286368696c64, 0x293b0a2020202020, 0x2020202020202020, - 0x2020202020202063, 0x6c65616e4c697374, 0x656e657273285b69, 0x645d293b0a202020, 0x2020202020202020, - 0x2020202020202020, 0x206e6f6465732e64, 0x656c657465286964, 0x293b0a2020202020, 0x2020202020202020, - 0x2020207d0a202020, 0x2020202020202020, 0x207d3b0a20202020, 0x202020207d2c0a20, 0x2020207d3b0a2020, - 0x2020627269646765, 0x2e646f6d42617463, 0x6848616e646c6572, 0x203d206170706c79, 0x3b0a202020207265, - 0x7475726e20617069, 0x3b0a7d0a00000000 + 0x0a20202020202020, 0x20636f6e73742065, 0x6c656d656e74203d, 0x206964203d3e207b, 0x0a20202020202020, + 0x2020202020636f6e, 0x737420656e747279, 0x203d207772697461, 0x626c65286964293b, 0x0a20202020202020, + 0x2020202020696620, 0x28656e7472792e74, 0x6578742920746872, 0x6f77206e65772045, 0x72726f7228276578, + 0x7065637465642044, 0x4f4d20656c656d65, 0x6e7427293b0a2020, 0x2020202020202020, 0x202072657475726e, + 0x20656e7472793b0a, 0x2020202020202020, 0x7d3b0a2020202020, 0x202020636f6e7374, 0x206672657368203d, + 0x202869642c20656e, 0x74727929203d3e20, 0x7b0a202020202020, 0x2020202020206966, 0x2028216964207c7c, + 0x206c6f6f6b757028, 0x696429207c7c206c, 0x69766553697a6520, 0x3e3d206d6178456e, 0x7472696573292074, + 0x68726f77206e6577, 0x204572726f722827, 0x696e76616c696420, 0x6f72206475706c69, 0x6361746520444f4d, + 0x206e6f646527293b, 0x0a20202020202020, 0x2020202020636861, 0x6e6765732e736574, 0x2869642c207b2e2e, + 0x2e656e7472792c20, 0x706172656e743a20, 0x6e756c6c2c206368, 0x696c6472656e3a20, 0x6e65772053657428, + 0x297d293b0a202020, 0x2020202020202020, 0x202b2b6c69766553, 0x697a653b0a202020, 0x20202020207d3b0a, + 0x2020202020202020, 0x636f6e737420666f, 0x72676574203d2069, 0x64203d3e207b0a20, 0x2020202020202020, + 0x2020202f2f204974, 0x6572617469766520, 0x7472617665727361, 0x6c3a20686f737469, 0x6c65206465657020, + 0x7472656573206d75, 0x7374206e6f74206f, 0x766572666c6f7720, 0x746865204a617661, 0x5363726970742073, + 0x7461636b2e0a2020, 0x2020202020202020, 0x2020636f6e737420, 0x70656e64696e6720, 0x3d205b69645d3b0a, + 0x2020202020202020, 0x202020207768696c, 0x65202870656e6469, 0x6e672e6c656e6774, 0x6829207b0a202020, + 0x2020202020202020, 0x2020202020636f6e, 0x7374206375727265, 0x6e74203d2070656e, 0x64696e672e706f70, + 0x28292c20656e7472, 0x79203d2067657428, 0x63757272656e7429, 0x3b0a202020202020, 0x2020202020202020, + 0x2020666f72202863, 0x6f6e737420636869, 0x6c64206f6620656e, 0x7472792e6368696c, 0x6472656e29207065, + 0x6e64696e672e7075, 0x7368286368696c64, 0x293b0a2020202020, 0x2020202020202020, 0x2020206368616e67, + 0x65732e7365742863, 0x757272656e742c20, 0x6e756c6c293b0a20, 0x2020202020202020, 0x202020202020202d, + 0x2d6c69766553697a, 0x653b0a2020202020, 0x202020202020207d, 0x0a20202020202020, 0x207d3b0a20202020, + 0x20202020666f7220, 0x28636f6e7374207b, 0x6f702c20612c2062, 0x2c20632c2076616c, 0x75652c206e616d65, + 0x4c696d69747d206f, 0x66206f7065726174, 0x696f6e7329207b0a, 0x2020202020202020, 0x20202020636f6e73, + 0x74206e616d654174, 0x203d20696e646578, 0x203d3e207b0a2020, 0x2020202020202020, 0x2020202020206966, + 0x2028696e64657820, 0x3e3d206e616d654c, 0x696d697429207468, 0x726f77206e657720, 0x4572726f72286075, + 0x6e6b6e6f776e2044, 0x4f4d206e616d6520, 0x247b696e6465787d, 0x60293b0a20202020, 0x2020202020202020, + 0x2020202072657475, 0x726e206e616d6573, 0x5b696e6465785d3b, 0x0a20202020202020, 0x20202020207d3b0a, + 0x2020202020202020, 0x2020202073776974, 0x636820286f702920, 0x7b0a202020202020, 0x2020202020206361, + 0x736520313a206272, 0x65616b3b0a202020, 0x2020202020202020, 0x206361736520323a, 0x207b0a2020202020, + 0x2020202020202020, 0x202020636f6e7374, 0x20746167203d206e, 0x616d654174286229, 0x3b0a202020202020, + 0x2020202020202020, 0x2020696620282174, 0x6167732e68617328, 0x74616729207c7c20, 0x666f726269646465, + 0x6e546167732e6861, 0x7328746167292920, 0x7468726f77206e65, 0x77204572726f7228, 0x60666f7262696464, + 0x656e20444f4d2074, 0x616720247b746167, 0x7d60293b0a202020, 0x2020202020202020, 0x2020202020667265, + 0x736828612c207b74, 0x61672c2074657874, 0x3a2066616c73657d, 0x293b0a2020202020, 0x2020202020202020, + 0x2020207374657073, 0x2e70757368282829, 0x203d3e207b206e6f, 0x6465732e73657428, 0x612c207b6e6f6465, + 0x3a20646f63756d65, 0x6e742e6372656174, 0x65456c656d656e74, 0x28746167297d293b, 0x207d293b0a202020, + 0x2020202020202020, 0x2020202020627265, 0x616b3b0a20202020, 0x2020202020202020, 0x7d0a202020202020, + 0x2020202020206361, 0x736520333a0a2020, 0x2020202020202020, 0x2020202020206672, 0x65736828612c207b, + 0x746578743a207472, 0x75657d293b0a2020, 0x2020202020202020, 0x2020202020207374, 0x6570732e70757368, + 0x282829203d3e207b, 0x206e6f6465732e73, 0x657428612c207b6e, 0x6f64653a20646f63, 0x756d656e742e6372, + 0x6561746554657874, 0x4e6f64652876616c, 0x7565297d293b207d, 0x293b0a2020202020, 0x2020202020202020, + 0x202020627265616b, 0x3b0a202020202020, 0x2020202020206361, 0x736520343a206361, 0x736520353a207b0a, + 0x2020202020202020, 0x2020202020202020, 0x656c656d656e7428, 0x61293b0a20202020, 0x2020202020202020, + 0x20202020636f6e73, 0x74206e616d65203d, 0x206e616d65417428, 0x62293b0a20202020, 0x2020202020202020, + 0x2020202069662028, 0x21616c6c6f776564, 0x4174747269627574, 0x65286e616d652929, 0x207468726f77206e, + 0x6577204572726f72, 0x2860666f72626964, 0x64656e20444f4d20, 0x6174747269627574, 0x6520247b6e616d65, + 0x7d60293b0a202020, 0x2020202020202020, 0x2020202020696620, 0x286f70203d3d3d20, 0x342026262075726c, + 0x4174747269627574, 0x65732e686173286e, 0x616d652920262620, 0x217361666555726c, 0x2876616c75652929, + 0x207468726f77206e, 0x6577204572726f72, 0x2827756e73616665, 0x20444f4d2055524c, 0x27293b0a20202020, + 0x2020202020202020, 0x2020202073746570, 0x732e707573682828, 0x29203d3e206f7020, 0x3d3d3d2034203f20, + 0x6e6f6465732e6765, 0x742861292e6e6f64, 0x652e736574417474, 0x726962757465286e, 0x616d652c2076616c, + 0x756529203a206e6f, 0x6465732e67657428, 0x61292e6e6f64652e, 0x72656d6f76654174, 0x7472696275746528, + 0x6e616d6529293b0a, 0x2020202020202020, 0x2020202020202020, 0x627265616b3b0a20, 0x2020202020202020, + 0x2020207d0a202020, 0x2020202020202020, 0x206361736520363a, 0x207b0a2020202020, 0x2020202020202020, + 0x202020636f6e7374, 0x20656e747279203d, 0x20656c656d656e74, 0x2861293b0a202020, 0x2020202020202020, + 0x2020202020636f6e, 0x7374206e616d6520, 0x3d206e616d654174, 0x2862293b0a202020, 0x2020202020202020, + 0x2020202020696620, 0x282170726f706572, 0x74794e616d65732e, 0x686173286e616d65, 0x2929207468726f77, + 0x206e657720457272, 0x6f722860666f7262, 0x696464656e20444f, 0x4d2070726f706572, 0x747920247b6e616d, + 0x657d60293b0a2020, 0x2020202020202020, 0x2020202020202f2f, 0x20546865206e6174, 0x697665206f757470, + 0x75742e76616c7565, 0x2073657474657220, 0x7265706c61636573, 0x206368696c647265, 0x6e20626568696e64, + 0x2074686520747261, 0x636b656420747265, 0x652773206261636b, 0x2e0a202020202020, 0x2020202020202020, + 0x2020696620286e61, 0x6d65203d3d3d2027, 0x76616c7565272026, 0x2620656e7472792e, 0x746167203d3d3d20, + 0x276f757470757427, 0x290a202020202020, 0x2020202020202020, 0x2020202020207468, 0x726f77206e657720, + 0x4572726f72282750, 0x524f504552545920, 0x76616c7565206f6e, 0x206f757470757420, 0x7265717569726573, + 0x206578706c696369, 0x7420746578742d6e, 0x6f64652075706461, 0x74657327293b0a20, 0x2020202020202020, + 0x2020202020202069, 0x6620285b27636865, 0x636b6564272c2027, 0x64697361626c6564, 0x272c2027696e6465, + 0x7465726d696e6174, 0x65275d2e696e636c, 0x75646573286e616d, 0x652920262620215b, 0x2774727565272c20, + 0x2766616c7365275d, 0x2e696e636c756465, 0x732876616c756529, 0x290a202020202020, 0x2020202020202020, + 0x2020202020207468, 0x726f77206e657720, 0x4572726f72282769, 0x6e76616c69642044, 0x4f4d20626f6f6c65, + 0x616e27293b0a2020, 0x2020202020202020, 0x2020202020206966, 0x20286e616d65203d, 0x3d3d202773656c65, + 0x63746564496e6465, 0x7827202626202821, 0x2f5e2d3f5c642b24, 0x2f2e746573742876, 0x616c756529207c7c, + 0x20214e756d626572, 0x2e6973496e746567, 0x6572284e756d6265, 0x722876616c756529, 0x29207c7c204e756d, + 0x6265722876616c75, 0x6529203c202d3120, 0x7c7c204e756d6265, 0x722876616c756529, 0x203e203231343734, + 0x383336343729290a, 0x2020202020202020, 0x2020202020202020, 0x202020207468726f, 0x77206e6577204572, + 0x726f722827696e76, 0x616c696420444f4d, 0x2073656c65637465, 0x64496e6465782729, 0x3b0a202020202020, + 0x2020202020202020, 0x2020636f6e737420, 0x636f6e7665727465, 0x64203d206e616d65, 0x203d3d3d20277661, + 0x6c756527203f2076, 0x616c7565203a206e, 0x616d65203d3d3d20, 0x2773656c65637465, 0x64496e6465782720, + 0x3f204e756d626572, 0x2876616c75652920, 0x3a2076616c756520, 0x3d3d3d2027747275, 0x65273b0a20202020, + 0x2020202020202020, 0x2020202073746570, 0x732e707573682828, 0x29203d3e207b206e, 0x6f6465732e676574, + 0x2861292e6e6f6465, 0x5b6e616d655d203d, 0x20636f6e76657274, 0x65643b207d293b0a, 0x2020202020202020, + 0x2020202020202020, 0x627265616b3b0a20, 0x2020202020202020, 0x2020207d0a202020, 0x2020202020202020, + 0x206361736520373a, 0x0a20202020202020, 0x2020202020202020, 0x2069662028217772, 0x697461626c652861, + 0x292e746578742920, 0x7468726f77206e65, 0x77204572726f7228, 0x275345545f544558, 0x5420726571756972, + 0x6573206120746578, 0x74206e6f64652729, 0x3b0a202020202020, 0x2020202020202020, 0x202073746570732e, + 0x7075736828282920, 0x3d3e207b206e6f64, 0x65732e6765742861, 0x292e6e6f64652e64, 0x617461203d207661, + 0x6c75653b207d293b, 0x0a20202020202020, 0x2020202020202020, 0x20627265616b3b0a, 0x2020202020202020, + 0x2020202063617365, 0x20383a2063617365, 0x20393a207b0a2020, 0x2020202020202020, 0x202020202020636f, + 0x6e73742070617265, 0x6e74203d20676574, 0x2861292c20636869, 0x6c64203d20777269, 0x7461626c65286229, + 0x3b0a202020202020, 0x2020202020202020, 0x2020696620287061, 0x72656e742e746578, 0x7429207468726f77, + 0x206e657720457272, 0x6f72282761207465, 0x7874206e6f646520, 0x63616e6e6f74206f, 0x776e206368696c64, + 0x72656e27293b0a20, 0x2020202020202020, 0x2020202020202069, 0x6620286f70203d3d, 0x3d20392026262067, + 0x65742863292e7061, 0x72656e7420213d3d, 0x206129207468726f, 0x77206e6577204572, 0x726f722827696e73, + 0x6572744265666f72, 0x6520726566657265, 0x6e6365206973206e, 0x6f74206120636869, 0x6c6427293b0a2020, + 0x2020202020202020, 0x202020202020666f, 0x7220286c65742061, 0x6e636573746f7220, 0x3d20613b20616e63, + 0x6573746f7220213d, 0x3d206e756c6c3b20, 0x616e636573746f72, 0x203d206765742861, 0x6e636573746f7229, + 0x2e706172656e7429, 0x0a20202020202020, 0x2020202020202020, 0x2020202020696620, 0x28616e636573746f, + 0x72203d3d3d206229, 0x207468726f77206e, 0x6577204572726f72, 0x2827444f4d206379, 0x636c6527293b0a20, + 0x2020202020202020, 0x2020202020202069, 0x6620286368696c64, 0x2e706172656e7420, 0x213d3d206e756c6c, + 0x2920656469742863, 0x68696c642e706172, 0x656e74292e636869, 0x6c6472656e2e6465, 0x6c6574652862293b, + 0x0a20202020202020, 0x2020202020202020, 0x2065646974286229, 0x2e706172656e7420, 0x3d20613b0a202020, + 0x2020202020202020, 0x2020202020656469, 0x742861292e636869, 0x6c6472656e2e6164, 0x642862293b0a2020, + 0x2020202020202020, 0x2020202020207374, 0x6570732e70757368, 0x282829203d3e206f, 0x70203d3d3d203820, + 0x3f206e6f6465732e, 0x6765742861292e6e, 0x6f64652e61707065, 0x6e644368696c6428, 0x6e6f6465732e6765, + 0x742862292e6e6f64, 0x6529203a0a202020, 0x2020202020202020, 0x2020202020202020, 0x206e6f6465732e67, + 0x65742861292e6e6f, 0x64652e696e736572, 0x744265666f726528, 0x6e6f6465732e6765, 0x742862292e6e6f64, + 0x652c206e6f646573, 0x2e6765742863292e, 0x6e6f646529293b0a, 0x2020202020202020, 0x2020202020202020, + 0x627265616b3b0a20, 0x2020202020202020, 0x2020207d0a202020, 0x2020202020202020, 0x2063617365203130, + 0x3a207b0a20202020, 0x2020202020202020, 0x20202020636f6e73, 0x7420656e74727920, 0x3d20777269746162, + 0x6c652861293b0a20, 0x2020202020202020, 0x2020202020202069, 0x662028656e747279, 0x2e706172656e7420, + 0x213d3d206e756c6c, 0x2920656469742865, 0x6e7472792e706172, 0x656e74292e636869, 0x6c6472656e2e6465, + 0x6c6574652861293b, 0x0a20202020202020, 0x2020202020202020, 0x20636f6e73742072, 0x656d6f766564203d, + 0x205b5d3b0a202020, 0x2020202020202020, 0x2020202020636f6e, 0x73742070656e6469, 0x6e67203d205b615d, + 0x3b0a202020202020, 0x2020202020202020, 0x20207768696c6520, 0x2870656e64696e67, 0x2e6c656e67746829, + 0x207b0a2020202020, 0x2020202020202020, 0x2020202020202063, 0x6f6e737420696420, 0x3d2070656e64696e, + 0x672e706f7028293b, 0x0a20202020202020, 0x2020202020202020, 0x202020202072656d, 0x6f7665642e707573, + 0x68286964293b0a20, 0x2020202020202020, 0x2020202020202020, 0x202020666f722028, 0x636f6e7374206368, + 0x696c64206f662067, 0x6574286964292e63, 0x68696c6472656e29, 0x2070656e64696e67, 0x2e70757368286368, + 0x696c64293b0a2020, 0x2020202020202020, 0x2020202020207d0a, 0x2020202020202020, 0x2020202020202020, + 0x666f726765742861, 0x293b0a2020202020, 0x2020202020202020, 0x2020207374657073, 0x2e70757368282829, + 0x203d3e207b0a2020, 0x2020202020202020, 0x2020202020202020, 0x20206e6f6465732e, 0x6765742861292e6e, + 0x6f64652e72656d6f, 0x766528293b0a2020, 0x2020202020202020, 0x2020202020202020, 0x2020666f72202863, + 0x6f6e737420696420, 0x6f662072656d6f76, 0x656429206e6f6465, 0x732e64656c657465, 0x286964293b0a2020, + 0x2020202020202020, 0x2020202020202020, 0x2020636c65616e4c, 0x697374656e657273, 0x2872656d6f766564, + 0x293b0a2020202020, 0x2020202020202020, 0x2020207d293b0a20, 0x2020202020202020, 0x2020202020202062, + 0x7265616b3b0a2020, 0x2020202020202020, 0x20207d0a20202020, 0x2020202020202020, 0x636173652031313a, + 0x2063617365203132, 0x3a207b0a20202020, 0x2020202020202020, 0x20202020656c656d, 0x656e742861293b0a, + 0x2020202020202020, 0x2020202020202020, 0x636f6e7374206e61, 0x6d65203d206e616d, 0x6541742862293b0a, + 0x2020202020202020, 0x2020202020202020, 0x6966202821657665, 0x6e74732e68617328, 0x6e616d6529207c7c, + 0x2063203e20332920, 0x7468726f77206e65, 0x77204572726f7228, 0x27696e76616c6964, 0x20444f4d20657665, + 0x6e74206f7220666c, 0x61677327293b0a20, 0x2020202020202020, 0x2020202020202073, 0x746570732e707573, + 0x68282829203d3e20, 0x6f70203d3d3d2031, 0x31203f206c697374, 0x656e28612c20622c, 0x206e616d652c2063, + 0x29203a20756e6c69, 0x7374656e28612c20, 0x6229293b0a202020, 0x2020202020202020, 0x2020202020627265, + 0x616b3b0a20202020, 0x2020202020202020, 0x7d0a202020202020, 0x2020202020206361, 0x73652031333a207b, + 0x0a20202020202020, 0x2020202020202020, 0x20636f6e7374206e, 0x616d65203d206e61, 0x6d6541742862292c, + 0x206e6f6465203d20, 0x69736c616e64732e, 0x676574286e616d65, 0x293f2e656c656d65, 0x6e743b0a20202020, + 0x2020202020202020, 0x2020202069662028, 0x216e6f6465292074, 0x68726f77206e6577, 0x204572726f722860, + 0x756e6b6e6f776e20, 0x444f4d2069736c61, 0x6e6420247b6e616d, 0x657d60293b0a2020, 0x2020202020202020, + 0x2020202020206966, 0x20286d6f756e7465, 0x642e686173286e6f, 0x646529207c7c206e, 0x65774d6f756e7473, + 0x2e686173286e6f64, 0x652929207468726f, 0x77206e6577204572, 0x726f72282769736c, 0x616e6420616c7265, + 0x616479206d6f756e, 0x74656427293b0a20, 0x2020202020202020, 0x202020202020206e, 0x65774d6f756e7473, + 0x2e736574286e6f64, 0x652c2061293b0a20, 0x2020202020202020, 0x2020202020202066, 0x7265736828612c20, + 0x7b6e6f64652c2074, 0x6578743a2066616c, 0x73652c2069736c61, 0x6e643a2074727565, 0x7d293b0a20202020, + 0x2020202020202020, 0x2020202073746570, 0x732e707573682828, 0x29203d3e206e6f64, 0x65732e7365742861, + 0x2c207b6e6f64657d, 0x29293b0a20202020, 0x2020202020202020, 0x2020202062726561, 0x6b3b0a2020202020, + 0x202020202020207d, 0x0a20202020202020, 0x20202020207d0a20, 0x202020202020207d, 0x0a20202020202020, + 0x202f2f2052657369, 0x6475616c20444f4d, 0x2065786365707469, 0x6f6e732028666f72, 0x206578616d706c65, + 0x2061207061676527, 0x7320637573746f6d, 0x20656c656d656e74, 0x292070726f706167, 0x61746520746f2074, + 0x6865206272696467, 0x6520617320612072, 0x656a656374696f6e, 0x2e0a202020202020, 0x20202f2f20496e20, + 0x7468617420636173, 0x6520646973636172, 0x642068616e646c65, 0x733a207468652061, 0x637475616c20444f, + 0x4d206d6179206861, 0x7665206265656e20, 0x706172746c792063, 0x68616e6765642061, 0x6e64206d75737420, + 0x6265206c656e7420, 0x616761696e2e0a20, 0x2020202020202074, 0x7279207b0a202020, 0x2020202020202020, + 0x20666f722028636f, 0x6e73742073746570, 0x206f662073746570, 0x7329207374657028, 0x293b0a2020202020, + 0x2020207d20636174, 0x636820286572726f, 0x7229207b0a202020, 0x2020202020202020, 0x20636c65616e4c69, + 0x7374656e65727328, 0x6c697374656e6572, 0x732e6b6579732829, 0x293b0a2020202020, 0x202020202020206e, + 0x6f6465732e636c65, 0x617228293b0a2020, 0x2020202020202020, 0x202069736c616e64, 0x732e636c65617228, + 0x293b0a2020202020, 0x202020202020206d, 0x6f756e746564203d, 0x206e657720576561, 0x6b4d617028293b0a, + 0x2020202020202020, 0x202020207468726f, 0x77206572726f723b, 0x0a20202020202020, 0x207d0a2020202020, + 0x202020666f722028, 0x636f6e7374205b69, 0x642c20656e747279, 0x5d206f6620636861, 0x6e67657329207b0a, + 0x2020202020202020, 0x2020202069662028, 0x21656e7472792920, 0x6e6f6465732e6465, 0x6c65746528696429, + 0x3b0a202020202020, 0x202020202020656c, 0x7365207b0a202020, 0x2020202020202020, 0x2020202020656e74, + 0x72792e6e6f646520, 0x3d206e6f6465732e, 0x676574286964292e, 0x6e6f64653b0a2020, 0x2020202020202020, + 0x2020202020206966, 0x2028656e7472792e, 0x6368696c6472656e, 0x20696e7374616e63, 0x656f66204368696c, + 0x6444656c74612920, 0x656e7472792e6368, 0x696c6472656e203d, 0x20656e7472792e63, 0x68696c6472656e2e, + 0x636f6d6d69742829, 0x3b0a202020202020, 0x2020202020202020, 0x20206e6f6465732e, 0x7365742869642c20, + 0x656e747279293b0a, 0x2020202020202020, 0x202020207d0a2020, 0x2020202020207d0a, 0x2020202020202020, + 0x666f722028636f6e, 0x7374205b6e6f6465, 0x2c2069645d206f66, 0x206e65774d6f756e, 0x747329206d6f756e, + 0x7465642e73657428, 0x6e6f64652c206964, 0x293b0a202020207d, 0x0a0a202020206c65, 0x7420636f6e6e6563, + 0x746564203d206661, 0x6c73652c20636f6e, 0x6e656374696e6720, 0x3d206e756c6c2c20, 0x68616e647368616b, + 0x6541636b6e6f776c, 0x6564676564203d20, 0x66616c73652c2063, 0x6f6e6e656374696f, 0x6e52657175657374, + 0x6564203d2066616c, 0x73653b0a20202020, 0x636f6e7374207065, 0x6e64696e67526576, 0x6f636174696f6e73, + 0x203d206e65772053, 0x657428293b0a2020, 0x202066756e637469, 0x6f6e207265616428, 0x7265717565737473, + 0x29207b0a20202020, 0x2020202069662028, 0x2128726571756573, 0x747320696e737461, 0x6e63656f66205569, + 0x6e74333241727261, 0x7929207c7c202172, 0x657175657374732e, 0x6c656e677468207c, 0x7c20726571756573, + 0x74732e6c656e6774, 0x6820252032207c7c, 0x2072657175657374, 0x732e6c656e677468, 0x203e203831393229, + 0x0a20202020202020, 0x2020202020746872, 0x6f77206e65772052, 0x616e67654572726f, 0x722827444f4d2072, + 0x6561647320726571, 0x7569726520312e2e, 0x34303936206e6f64, 0x652f70726f706572, 0x7479207061697273, + 0x27293b0a20202020, 0x202020202f2f2056, 0x616c696461746520, 0x6576657279207265, 0x7175657374206265, + 0x666f726520726561, 0x64696e672070726f, 0x7065727469657320, 0x6f7220666f726369, 0x6e67206c61796f75, + 0x742e0a2020202020, 0x202020666f722028, 0x6c65742069203d20, 0x303b2069203c2072, 0x657175657374732e, + 0x6c656e6774683b20, 0x69202b3d20322920, 0x7b0a202020202020, 0x2020202020206966, 0x2028216e6f646573, + 0x2e68617328726571, 0x75657374735b695d, 0x29207c7c20726571, 0x75657374735b6920, 0x2b20315d203e2034, + 0x207c7c0a20202020, 0x2020202020202020, 0x2020202028726571, 0x75657374735b6920, 0x2b20315d203e3d20, + 0x332026262021286e, 0x6f6465732e676574, 0x2872657175657374, 0x735b695d292e6e6f, 0x646520696e737461, + 0x6e63656f6620456c, 0x656d656e74292929, 0x0a20202020202020, 0x2020202020202020, 0x207468726f77206e, + 0x6577204572726f72, 0x2827696e76616c69, 0x6420444f4d207265, 0x6164207265717565, 0x737427293b0a2020, + 0x2020202020207d0a, 0x2020202020202020, 0x636f6e7374207061, 0x727473203d205b5d, 0x3b0a202020202020, + 0x20206c6574207369, 0x7a65203d20303b0a, 0x2020202020202020, 0x666f7220286c6574, 0x2069203d20303b20, + 0x69203c2072657175, 0x657374732e6c656e, 0x6774683b2069202b, 0x3d203229207b0a20, 0x2020202020202020, + 0x202020636f6e7374, 0x206e6f6465203d20, 0x6e6f6465732e6765, 0x7428726571756573, 0x74735b695d292e6e, + 0x6f64652c206b696e, 0x64203d2072657175, 0x657374735b69202b, 0x20315d3b0a202020, 0x2020202020202020, + 0x20636f6e73742076, 0x616c7565203d206b, 0x696e64203d3d3d20, 0x30203f206e6f6465, 0x2e74657874436f6e, + 0x74656e74203a206b, 0x696e64203d3d3d20, 0x31203f206e6f6465, 0x2e76616c7565203a, 0x206b696e64203d3d, + 0x3d2032203f206e6f, 0x64652e636865636b, 0x6564203a0a202020, 0x2020202020202020, 0x20202020206b696e, + 0x64203d3d3d203320, 0x3f206e6f64652e67, 0x6574426f756e6469, 0x6e67436c69656e74, 0x5265637428292e77, + 0x69647468203a206e, 0x6f64652e67657442, 0x6f756e64696e6743, 0x6c69656e74526563, 0x7428292e68656967, + 0x68743b0a20202020, 0x2020202020202020, 0x636f6e7374207465, 0x7874203d20537472, 0x696e672876616c75, + 0x65203f3f20272729, 0x3b0a202020202020, 0x2020202020206966, 0x2028746578742e6c, 0x656e677468202b20, + 0x34203e206d617842, 0x79746573202d2073, 0x697a652920746872, 0x6f77206e65772052, 0x616e67654572726f, + 0x722827444f4d2072, 0x6561642072657375, 0x6c74206578636565, 0x64732031204d6942, 0x27293b0a20202020, + 0x2020202020202020, 0x636f6e7374206279, 0x746573203d20656e, 0x636f6465722e656e, 0x636f646528746578, + 0x74293b0a20202020, 0x2020202020202020, 0x6966202862797465, 0x732e6c656e677468, 0x202b2034203e206d, + 0x6178427974657320, 0x2d2073697a652920, 0x7468726f77206e65, 0x772052616e676545, 0x72726f722827444f, + 0x4d20726561642072, 0x6573756c74206578, 0x6365656473203120, 0x4d694227293b0a20, 0x2020202020202020, + 0x2020207061727473, 0x2e70757368286279, 0x746573293b0a2020, 0x2020202020202020, 0x202073697a65202b, + 0x3d2034202b206279, 0x7465732e6c656e67, 0x74683b0a20202020, 0x202020207d0a2020, 0x202020202020636f, + 0x6e73742072657375, 0x6c74203d206e6577, 0x2055696e74384172, 0x7261792873697a65, 0x292c207669657720, + 0x3d206e6577204461, 0x7461566965772872, 0x6573756c742e6275, 0x66666572293b0a20, 0x202020202020206c, + 0x6574206f66667365, 0x74203d20303b0a20, 0x2020202020202066, 0x6f722028636f6e73, 0x7420627974657320, + 0x6f66207061727473, 0x29207b0a20202020, 0x2020202020202020, 0x766965772e736574, 0x55696e743332286f, + 0x66667365742c2062, 0x797465732e6c656e, 0x6774682c20747275, 0x65293b0a20202020, 0x2020202020202020, + 0x726573756c742e73, 0x6574286279746573, 0x2c206f6666736574, 0x202b2034293b0a20, 0x2020202020202020, + 0x2020206f66667365, 0x74202b3d2034202b, 0x2062797465732e6c, 0x656e6774683b0a20, 0x202020202020207d, + 0x0a20202020202020, 0x2072657475726e20, 0x726573756c743b0a, 0x202020207d0a2020, 0x2020636f6e737420, + 0x617069203d207b0a, 0x2020202020202020, 0x2f2f204f70742069, 0x6e20746f20746865, 0x20432b2b20446f63, + 0x756d656e74204150, 0x493b206c6f772d6c, 0x6576656c20626174, 0x6368207573657273, 0x206e656564206e6f, + 0x206275696c742d69, 0x6e2063616c6c6261, 0x636b207265676973, 0x74726174696f6e2e, 0x0a20202020202020, + 0x206173796e632063, 0x6f6e6e6563742829, 0x207b0a2020202020, 0x2020202020202069, 0x662028636f6e6e65, + 0x6374656429207468, 0x726f77206e657720, 0x4572726f72282744, 0x4f4d20696e746572, 0x7072657465722061, + 0x6c72656164792063, 0x6f6e6e6563746564, 0x27293b0a20202020, 0x2020202020202020, 0x69662028636f6e6e, + 0x656374696e672920, 0x72657475726e2063, 0x6f6e6e656374696e, 0x673b0a2020202020, 0x2020202020202063, + 0x6f6e6e656374696f, 0x6e52657175657374, 0x6564203d20747275, 0x653b0a2020202020, 0x2020202020202067, + 0x6c6f62616c546869, 0x732e7766446f6d20, 0x3f3f3d207b7d3b0a, 0x2020202020202020, 0x20202020676c6f62, + 0x616c546869732e77, 0x66446f6d2e726561, 0x64203d2072656164, 0x3b0a202020202020, 0x202020202020636f, + 0x6e6e656374696e67, 0x203d20286173796e, 0x63202829203d3e20, 0x7b0a202020202020, 0x2020202020202020, + 0x2020696620282168, 0x616e647368616b65, 0x41636b6e6f776c65, 0x6467656429207b0a, 0x2020202020202020, + 0x2020202020202020, 0x2020202061776169, 0x7420627269646765, 0x2e72656164793b0a, 0x2020202020202020, + 0x2020202020202020, 0x2020202061776169, 0x7420627269646765, 0x2e63707046756e63, 0x74696f6e28277766, + 0x446f6d2e72656164, 0x79272928293b0a20, 0x2020202020202020, 0x2020202020202020, 0x20202068616e6473, + 0x68616b6541636b6e, 0x6f776c6564676564, 0x203d20747275653b, 0x0a20202020202020, 0x2020202020202020, + 0x207d0a2020202020, 0x2020202020202020, 0x202020666f722028, 0x636f6e7374206e61, 0x6d65206f66207065, + 0x6e64696e67526576, 0x6f636174696f6e73, 0x29207b0a20202020, 0x2020202020202020, 0x2020202020202020, + 0x6177616974206272, 0x696467652e637070, 0x46756e6374696f6e, 0x28277766446f6d2e, 0x7265766f6b656427, + 0x29286e616d65293b, 0x0a20202020202020, 0x2020202020202020, 0x202020202070656e, 0x64696e675265766f, + 0x636174696f6e732e, 0x64656c657465286e, 0x616d65293b0a2020, 0x2020202020202020, 0x2020202020207d0a, + 0x2020202020202020, 0x2020202020202020, 0x636f6e6e65637465, 0x64203d2074727565, 0x3b0a202020202020, + 0x2020202020207d29, 0x28293b0a20202020, 0x2020202020202020, 0x747279207b206177, 0x61697420636f6e6e, + 0x656374696e673b20, 0x7d0a202020202020, 0x2020202020206669, 0x6e616c6c79207b20, 0x636f6e6e65637469, + 0x6e67203d206e756c, 0x6c3b207d0a202020, 0x20202020207d2c0a, 0x2020202020202020, 0x6170706c792c0a20, + 0x2020202020202069, 0x736c616e64286e61, 0x6d652c20656c656d, 0x656e7429207b0a20, 0x2020202020202020, + 0x2020206966202821, 0x28656c656d656e74, 0x20696e7374616e63, 0x656f662048544d4c, 0x456c656d656e7429, + 0x207c7c2021746167, 0x732e68617328656c, 0x656d656e742e6c6f, 0x63616c4e616d6529, 0x207c7c20666f7262, + 0x696464656e546167, 0x732e68617328656c, 0x656d656e742e6c6f, 0x63616c4e616d6529, 0x290a202020202020, + 0x2020202020202020, 0x20207468726f7720, 0x6e65772054797065, 0x4572726f72282761, 0x6e2069736c616e64, + 0x206d757374206265, 0x20616e20616c6c6f, 0x7765642048544d4c, 0x20656c656d656e74, 0x27293b0a20202020, + 0x2020202020202020, 0x636f6e7374207072, 0x6576696f7573203d, 0x2069736c616e6473, 0x2e676574286e616d, + 0x65293b0a20202020, 0x2020202020202020, 0x6966202870726576, 0x696f757320262620, 0x70726576696f7573, + 0x2e656c656d656e74, 0x20213d3d20656c65, 0x6d656e7429207468, 0x726f77206e657720, 0x4572726f72282769, + 0x736c616e64206e61, 0x6d6520616c726561, 0x6479206c656e7427, 0x293b0a2020202020, 0x2020202020202069, + 0x6620282170726576, 0x696f757329207b0a, 0x2020202020202020, 0x2020202020202020, 0x69662028656c656d, + 0x656e742e6368696c, 0x644e6f6465732e6c, 0x656e677468207c7c, 0x2041727261792e66, 0x726f6d2869736c61, + 0x6e64732e76616c75, 0x65732829292e736f, 0x6d6528656e747279, 0x203d3e20656e7472, 0x792e656c656d656e, + 0x74203d3d3d20656c, 0x656d656e74207c7c, 0x20656e7472792e65, 0x6c656d656e742e63, 0x6f6e7461696e7328, + 0x656c656d656e7429, 0x207c7c20656c656d, 0x656e742e636f6e74, 0x61696e7328656e74, 0x72792e656c656d65, + 0x6e742929290a2020, 0x2020202020202020, 0x2020202020202020, 0x20207468726f7720, 0x6e6577204572726f, + 0x72282769736c616e, 0x6473206d75737420, 0x626520656d707479, 0x20616e6420646973, 0x6a6f696e7427293b, + 0x0a20202020202020, 0x20202020207d0a20, 0x2020202020202020, 0x202020636f6e7374, 0x20746f6b656e203d, + 0x207b656c656d656e, 0x747d3b0a20202020, 0x2020202020202020, 0x69736c616e64732e, 0x736574286e616d65, + 0x2c20746f6b656e29, 0x3b0a202020202020, 0x2020202020207265, 0x7475726e20282920, 0x3d3e207b0a202020, + 0x2020202020202020, 0x2020202020696620, 0x2869736c616e6473, 0x2e676574286e616d, 0x652920213d3d2074, + 0x6f6b656e29207265, 0x7475726e3b0a2020, 0x2020202020202020, 0x2020202020206973, 0x6c616e64732e6465, + 0x6c657465286e616d, 0x65293b0a20202020, 0x2020202020202020, 0x20202020636f6e73, 0x7420726f6f744964, + 0x203d206d6f756e74, 0x65642e6765742865, 0x6c656d656e74293b, 0x0a20202020202020, 0x2020202020202020, + 0x206d6f756e746564, 0x2e64656c65746528, 0x656c656d656e7429, 0x3b0a202020202020, 0x2020202020202020, + 0x202069662028636f, 0x6e6e656374656429, 0x206272696467652e, 0x63707046756e6374, 0x696f6e2827776644, + 0x6f6d2e7265766f6b, 0x65642729286e616d, 0x65292e6361746368, 0x286572726f72203d, 0x3e207b0a20202020, + 0x2020202020202020, 0x2020202020202020, 0x636f6e736f6c652e, 0x6572726f72282757, 0x656246726f6e7420, + 0x444f4d2069736c61, 0x6e64207265766f63, 0x6174696f6e206661, 0x696c6564272c2065, 0x72726f72293b0a20, + 0x2020202020202020, 0x202020202020207d, 0x293b0a2020202020, 0x2020202020202020, 0x202020656c736520, + 0x69662028636f6e6e, 0x656374696f6e5265, 0x7175657374656429, 0x2070656e64696e67, 0x5265766f63617469, + 0x6f6e732e61646428, 0x6e616d65293b0a20, 0x2020202020202020, 0x2020202020202069, 0x662028726f6f7449, + 0x64203d3d3d20756e, 0x646566696e656429, 0x2072657475726e3b, 0x0a20202020202020, 0x2020202020202020, + 0x20636f6e73742070, 0x656e64696e67203d, 0x205b726f6f744964, 0x5d3b0a2020202020, 0x2020202020202020, + 0x2020207768696c65, 0x202870656e64696e, 0x672e6c656e677468, 0x29207b0a20202020, 0x2020202020202020, + 0x2020202020202020, 0x636f6e7374206964, 0x203d2070656e6469, 0x6e672e706f702829, 0x2c20656e74727920, + 0x3d206e6f6465732e, 0x676574286964293b, 0x0a20202020202020, 0x2020202020202020, 0x2020202020666f72, + 0x2028636f6e737420, 0x6368696c64206f66, 0x20656e7472792e63, 0x68696c6472656e29, 0x2070656e64696e67, + 0x2e70757368286368, 0x696c64293b0a2020, 0x2020202020202020, 0x2020202020202020, 0x2020636c65616e4c, + 0x697374656e657273, 0x285b69645d293b0a, 0x2020202020202020, 0x2020202020202020, 0x202020206e6f6465, + 0x732e64656c657465, 0x286964293b0a2020, 0x2020202020202020, 0x2020202020207d0a, 0x2020202020202020, + 0x202020207d3b0a20, 0x202020202020207d, 0x2c0a202020207d3b, 0x0a20202020627269, 0x6467652e646f6d42, + 0x6174636848616e64, 0x6c6572203d206170, 0x706c793b0a202020, 0x2072657475726e20, 0x6170693b0a7d0a00 }; }; diff --git a/include/webfront/system/FallbackIndexHtmlData.hpp b/include/webfront/system/FallbackIndexHtmlData.hpp index 2268abd5..b4e517fd 100644 --- a/include/webfront/system/FallbackIndexHtmlData.hpp +++ b/include/webfront/system/FallbackIndexHtmlData.hpp @@ -9,8 +9,8 @@ namespace webfront::fs::generated { struct FallbackIndexHtmlData { static constexpr std::string_view encoding{}; - static constexpr std::size_t dataSize{1664}; - static constexpr std::array data{ + static constexpr std::size_t dataSize{1756}; + static constexpr std::array data{ 0x3c21444f43545950, 0x452068746d6c3e0a, 0x3c68746d6c206c61, 0x6e673d22656e223e, 0x0a3c686561643e0a, 0x3c6d657461206368, 0x61727365743d2275, 0x74662d38223e0a3c, 0x6d657461206e616d, 0x653d227669657770, 0x6f72742220636f6e, 0x74656e743d227769, 0x6474683d64657669, 0x63652d7769647468, 0x2c20696e69746961, @@ -23,36 +23,38 @@ struct FallbackIndexHtmlData { 0x62673a2023306431, 0x3131373b207d0a20, 0x207d0a20202a207b, 0x20626f782d73697a, 0x696e673a20626f72, 0x6465722d626f783b, 0x207d0a2020626f64, 0x79207b0a20202020, 0x6d617267696e3a20, 0x303b0a202020206d, 0x696e2d6865696768, 0x743a203130307668, 0x3b0a202020206469, 0x73706c61793a2066, 0x6c65783b0a202020, - 0x20616c69676e2d69, 0x74656d733a206365, 0x6e7465723b0a2020, 0x20206a7573746966, 0x792d636f6e74656e, - 0x743a2063656e7465, 0x723b0a2020202070, 0x616464696e673a20, 0x312e3572656d3b0a, 0x20202020666f6e74, - 0x2d66616d696c793a, 0x2073797374656d2d, 0x75692c202d617070, 0x6c652d7379737465, 0x6d2c20225365676f, - 0x65205549222c2073, 0x616e732d73657269, 0x663b0a2020202063, 0x6f6c6f723a207661, 0x72282d2d6667293b, - 0x0a20202020626163, 0x6b67726f756e643a, 0x20766172282d2d62, 0x67293b0a20207d0a, 0x20206d61696e207b, - 0x0a202020206d6178, 0x2d77696474683a20, 0x333272656d3b0a20, 0x2020207769647468, 0x3a20313030253b0a, - 0x2020202074657874, 0x2d616c69676e3a20, 0x63656e7465723b0a, 0x20207d0a20206831, 0x207b20666f6e742d, - 0x73697a653a20312e, 0x373572656d3b206d, 0x617267696e2d626f, 0x74746f6d3a20302e, 0x3572656d3b207d0a, - 0x202070207b206c69, 0x6e652d6865696768, 0x743a20312e353b20, 0x7d0a202023737461, 0x747573207b0a2020, - 0x2020646973706c61, 0x793a20696e6c696e, 0x652d626c6f636b3b, 0x0a202020206d6172, 0x67696e2d746f703a, - 0x203172656d3b0a20, 0x2020207061646469, 0x6e673a20302e3572, 0x656d203172656d3b, 0x0a20202020626f72, - 0x6465722d72616469, 0x75733a20302e3572, 0x656d3b0a20202020, 0x666f6e742d776569, 0x6768743a20363030, - 0x3b0a20207d0a2020, 0x237374617475735b, 0x646174612d737461, 0x74653d22636f6e6e, 0x656374696e67225d, - 0x207b206261636b67, 0x726f756e643a2063, 0x6f6c6f722d6d6978, 0x28696e2073726762, 0x2c20766172282d2d, - 0x616363656e742920, 0x3135252c20747261, 0x6e73706172656e74, 0x293b207d0a202023, 0x7374617475735b64, - 0x6174612d73746174, 0x653d22636f6e6e65, 0x63746564225d207b, 0x206261636b67726f, 0x756e643a20636f6c, - 0x6f722d6d69782869, 0x6e20737267622c20, 0x766172282d2d6163, 0x63656e7429203235, 0x252c207472616e73, - 0x706172656e74293b, 0x207d0a2020237374, 0x617475735b646174, 0x612d73746174653d, 0x226572726f72225d, - 0x207b206261636b67, 0x726f756e643a2063, 0x6f6c6f722d6d6978, 0x28696e2073726762, 0x2c20766172282d2d, - 0x6572726f72292032, 0x30252c207472616e, 0x73706172656e7429, 0x3b20636f6c6f723a, 0x20766172282d2d65, - 0x72726f72293b207d, 0x0a3c2f7374796c65, 0x3e0a3c2f68656164, 0x3e0a3c626f64793e, 0x0a3c6d61696e3e0a, - 0x20203c68313e4865, 0x6c6c6f2c20576562, 0x46726f6e74213c2f, 0x68313e0a20203c70, 0x3e54686973207061, - 0x6765206973207365, 0x7276656420627920, 0x57656246726f6e74, 0x277320656d626564, 0x6465642066616c6c, - 0x6261636b2e204974, 0x20686173206e6f20, 0x6c6f63616c205549, 0x2066696c6573206f, 0x6620697473206f77, - 0x6e2e3c2f703e0a20, 0x203c702069643d22, 0x7374617475732220, 0x726f6c653d227374, 0x6174757322206172, - 0x69612d6c6976653d, 0x22706f6c69746522, 0x20646174612d7374, 0x6174653d22636f6e, 0x6e656374696e6722, - 0x3e436f6e6e656374, 0x696e672668656c6c, 0x69703b3c2f703e0a, 0x3c2f6d61696e3e0a, 0x3c73637269707420, - 0x7372633d22576562, 0x46726f6e742e6a73, 0x223e3c2f73637269, 0x70743e0a3c736372, 0x6970742074797065, - 0x3d226d6f64756c65, 0x22207372633d2277, 0x656266726f6e742d, 0x66616c6c6261636b, 0x2e6d6a73223e3c2f, - 0x7363726970743e0a, 0x3c2f626f64793e0a, 0x3c2f68746d6c3e0a + 0x20666c65782d6469, 0x72656374696f6e3a, 0x20636f6c756d6e3b, 0x0a20202020616c69, 0x676e2d6974656d73, + 0x3a2063656e746572, 0x3b0a202020206a75, 0x73746966792d636f, 0x6e74656e743a2063, 0x656e7465723b0a20, + 0x2020207061646469, 0x6e673a20312e3572, 0x656d3b0a20202020, 0x666f6e742d66616d, 0x696c793a20737973, + 0x74656d2d75692c20, 0x2d6170706c652d73, 0x797374656d2c2022, 0x5365676f65205549, 0x222c2073616e732d, + 0x73657269663b0a20, 0x202020636f6c6f72, 0x3a20766172282d2d, 0x6667293b0a202020, 0x206261636b67726f, + 0x756e643a20766172, 0x282d2d6267293b0a, 0x20207d0a20206d61, 0x696e207b0a202020, 0x206d61782d776964, + 0x74683a2033327265, 0x6d3b0a2020202077, 0x696474683a203130, 0x30253b0a20202020, 0x746578742d616c69, + 0x676e3a2063656e74, 0x65723b0a20207d0a, 0x20206831207b2066, 0x6f6e742d73697a65, 0x3a20312e37357265, + 0x6d3b206d61726769, 0x6e2d626f74746f6d, 0x3a20302e3572656d, 0x3b207d0a20207020, 0x7b206c696e652d68, + 0x65696768743a2031, 0x2e353b207d0a2020, 0x2373746174757320, 0x7b0a202020206469, 0x73706c61793a2069, + 0x6e6c696e652d626c, 0x6f636b3b0a202020, 0x206d617267696e2d, 0x746f703a20317265, 0x6d3b0a2020202070, + 0x616464696e673a20, 0x302e3572656d2031, 0x72656d3b0a202020, 0x20626f726465722d, 0x7261646975733a20, + 0x302e3572656d3b0a, 0x20202020666f6e74, 0x2d7765696768743a, 0x203630303b0a2020, 0x7d0a202023737461, + 0x7475735b64617461, 0x2d73746174653d22, 0x636f6e6e65637469, 0x6e67225d207b2062, 0x61636b67726f756e, + 0x643a20636f6c6f72, 0x2d6d697828696e20, 0x737267622c207661, 0x72282d2d61636365, 0x6e7429203135252c, + 0x207472616e737061, 0x72656e74293b207d, 0x0a20202373746174, 0x75735b646174612d, 0x73746174653d2263, + 0x6f6e6e6563746564, 0x225d207b20626163, 0x6b67726f756e643a, 0x20636f6c6f722d6d, 0x697828696e207372, + 0x67622c2076617228, 0x2d2d616363656e74, 0x29203235252c2074, 0x72616e7370617265, 0x6e74293b207d0a20, + 0x2023737461747573, 0x5b646174612d7374, 0x6174653d22657272, 0x6f72225d2c202373, 0x74617475735b6461, + 0x74612d7374617465, 0x3d22646f6d2d6572, 0x726f72225d207b20, 0x6261636b67726f75, 0x6e643a20636f6c6f, + 0x722d6d697828696e, 0x20737267622c2076, 0x6172282d2d657272, 0x6f7229203230252c, 0x207472616e737061, + 0x72656e74293b2063, 0x6f6c6f723a207661, 0x72282d2d6572726f, 0x72293b207d0a3c2f, 0x7374796c653e0a3c, + 0x2f686561643e0a3c, 0x626f64793e0a3c6d, 0x61696e3e0a20203c, 0x68313e48656c6c6f, 0x2c2057656246726f, + 0x6e74213c2f68313e, 0x0a20203c703e5468, 0x6973207061676520, 0x6973207365727665, 0x6420627920576562, + 0x46726f6e74277320, 0x656d626564646564, 0x2066616c6c626163, 0x6b2e204974206861, 0x73206e6f206c6f63, + 0x616c205549206669, 0x6c6573206f662069, 0x7473206f776e2e3c, 0x2f703e0a20203c70, 0x2069643d22737461, + 0x7475732220726f6c, 0x653d227374617475, 0x732220617269612d, 0x6c6976653d22706f, 0x6c69746522206461, + 0x74612d7374617465, 0x3d22636f6e6e6563, 0x74696e67223e436f, 0x6e6e656374696e67, 0x2668656c6c69703b, + 0x3c2f703e0a3c2f6d, 0x61696e3e0a3c6469, 0x762069643d227765, 0x6266726f6e742d72, 0x6f6f74223e3c2f64, + 0x69763e0a3c736372, 0x697074207372633d, 0x2257656246726f6e, 0x742e6a73223e3c2f, 0x7363726970743e0a, + 0x3c73637269707420, 0x747970653d226d6f, 0x64756c6522207372, 0x633d227765626672, 0x6f6e742d66616c6c, + 0x6261636b2e6d6a73, 0x223e3c2f73637269, 0x70743e0a3c2f626f, 0x64793e0a3c2f6874, 0x6d6c3e0a00000000 }; }; diff --git a/include/webfront/system/FallbackModuleData.hpp b/include/webfront/system/FallbackModuleData.hpp index 545c9b66..37979b61 100644 --- a/include/webfront/system/FallbackModuleData.hpp +++ b/include/webfront/system/FallbackModuleData.hpp @@ -9,8 +9,8 @@ namespace webfront::fs::generated { struct FallbackModuleData { static constexpr std::string_view encoding{}; - static constexpr std::size_t dataSize{564}; - static constexpr std::array data{ + static constexpr std::size_t dataSize{962}; + static constexpr std::array data{ 0x2f2f2f2040627269, 0x6566204e61746976, 0x65206d6f64756c65, 0x20666f7220576562, 0x46726f6e74277320, 0x656d626564646564, 0x2066616c6c626163, 0x6b20706167652e20, 0x50726f7665732074, 0x68652062726f7773, 0x65722d746f2d432b, 0x2b20627269646765, 0x0a2f2f2f20636f6e, 0x6e65637465642062, 0x7920617761697469, @@ -19,13 +19,23 @@ struct FallbackModuleData { 0x74686973206d6f64, 0x756c652920616e64, 0x207265666c656374, 0x696e672074686520, 0x6f7574636f6d6520, 0x696e207468652070, 0x6167652773207374, 0x6174757320656c65, 0x6d656e742e0a0a63, 0x6f6e737420737461, 0x747573203d20646f, 0x63756d656e742e67, 0x6574456c656d656e, 0x7442794964282273, 0x746174757322293b, - 0x0a0a747279207b0a, 0x2020202061776169, 0x742077656246726f, 0x6e742e7265616479, 0x3b0a202020207374, - 0x617475732e746578, 0x74436f6e74656e74, 0x203d2022436f6e6e, 0x656374656420746f, 0x2057656246726f6e, - 0x74223b0a20202020, 0x7374617475732e64, 0x6174617365742e73, 0x74617465203d2022, 0x636f6e6e65637465, - 0x64223b0a7d206361, 0x7463682028657272, 0x6f7229207b0a2020, 0x2020737461747573, 0x2e74657874436f6e, - 0x74656e74203d2060, 0x436f6e6e65637469, 0x6f6e206661696c65, 0x643a20247b657272, 0x6f722e6d65737361, - 0x67657d603b0a2020, 0x2020737461747573, 0x2e64617461736574, 0x2e7374617465203d, 0x20226572726f7222, - 0x3b0a7d0a00000000 + 0x0a0a6c6574206272, 0x69646765436f6e6e, 0x6563746564203d20, 0x66616c73653b0a74, 0x7279207b0a202020, + 0x2061776169742077, 0x656246726f6e742e, 0x72656164793b0a20, 0x2020206272696467, 0x65436f6e6e656374, + 0x6564203d20747275, 0x653b0a2020202073, 0x74617475732e7465, 0x7874436f6e74656e, 0x74203d2022436f6e, + 0x6e65637465642074, 0x6f2057656246726f, 0x6e74223b0a202020, 0x207374617475732e, 0x646174617365742e, + 0x7374617465203d20, 0x22636f6e6e656374, 0x6564223b0a202020, 0x20636f6e7374207b, 0x20696e7374616c6c, + 0x446f6d496e746572, 0x707265746572207d, 0x203d206177616974, 0x20696d706f727428, 0x272e2f7765626672, + 0x6f6e742d646f6d2e, 0x6d6a7327293b0a20, 0x202020636f6e7374, 0x20646f6d203d2069, 0x6e7374616c6c446f, + 0x6d496e7465727072, 0x6574657228776562, 0x46726f6e74293b0a, 0x20202020646f6d2e, 0x69736c616e642827, + 0x726f6f74272c2064, 0x6f63756d656e742e, 0x676574456c656d65, 0x6e74427949642827, 0x77656266726f6e74, + 0x2d726f6f74272929, 0x3b0a202020206177, 0x61697420646f6d2e, 0x636f6e6e65637428, 0x293b0a7d20636174, + 0x636820286572726f, 0x7229207b0a202020, 0x207374617475732e, 0x74657874436f6e74, 0x656e74203d206272, + 0x69646765436f6e6e, 0x65637465640a2020, 0x2020202020203f20, 0x60436f6e6e656374, 0x656420746f205765, + 0x6246726f6e743b20, 0x444f4d20756e6176, 0x61696c61626c653a, 0x20247b6572726f72, 0x2e6d657373616765, + 0x7d600a2020202020, 0x2020203a2060436f, 0x6e6e656374696f6e, 0x206661696c65643a, 0x20247b6572726f72, + 0x2e6d657373616765, 0x7d603b0a20202020, 0x7374617475732e64, 0x6174617365742e73, 0x74617465203d2062, + 0x7269646765436f6e, 0x6e6563746564203f, 0x2022646f6d2d6572, 0x726f7222203a2022, 0x6572726f72223b0a, + 0x7d0a000000000000 }; }; diff --git a/include/webfront/weblink/DomBatch.hpp b/include/webfront/weblink/DomBatch.hpp index 48fe6c47..a47659d7 100644 --- a/include/webfront/weblink/DomBatch.hpp +++ b/include/webfront/weblink/DomBatch.hpp @@ -200,6 +200,8 @@ class DomBatch { return op; } +public: + /// Validates UTF-8 shared by DOM command strings and grouped read results. static void validateUtf8(std::string_view value) { std::size_t i = 0; while (i < value.size()) { diff --git a/js/core/dom-interpreter.mjs b/js/core/dom-interpreter.mjs index 3c1fcda2..f9d11eec 100644 --- a/js/core/dom-interpreter.mjs +++ b/js/core/dom-interpreter.mjs @@ -108,9 +108,11 @@ export function installDomInterpreter(bridge = globalThis.webFront, extensions = if (flags & 1) event.preventDefault(); if (flags & 2) event.stopPropagation(); const value = name === 'input' || name === 'change' - ? (node.type === 'checkbox' ? String(node.checked) : String(node.value)) + ? (node.type === 'checkbox' ? String(node.checked) : String(node.value ?? '')) : name === 'keydown' || name === 'keyup' ? event.key : ''; - bridge.cppFunction('wfDom.event')(id, index, value).catch(() => {}); + bridge.cppFunction('wfDom.event')(id, index, value).catch(error => { + console.error('WebFront DOM event delivery failed', error); + }); }; node.addEventListener(name, listener); let group = listeners.get(id); @@ -302,7 +304,62 @@ export function installDomInterpreter(bridge = globalThis.webFront, extensions = for (const [node, id] of newMounts) mounted.set(node, id); } + let connected = false, connecting = null, handshakeAcknowledged = false, connectionRequested = false; + const pendingRevocations = new Set(); + function read(requests) { + if (!(requests instanceof Uint32Array) || !requests.length || requests.length % 2 || requests.length > 8192) + throw new RangeError('DOM reads require 1..4096 node/property pairs'); + // Validate every request before reading properties or forcing layout. + for (let i = 0; i < requests.length; i += 2) { + if (!nodes.has(requests[i]) || requests[i + 1] > 4 || + (requests[i + 1] >= 3 && !(nodes.get(requests[i]).node instanceof Element))) + throw new Error('invalid DOM read request'); + } + const parts = []; + let size = 0; + for (let i = 0; i < requests.length; i += 2) { + const node = nodes.get(requests[i]).node, kind = requests[i + 1]; + const value = kind === 0 ? node.textContent : kind === 1 ? node.value : kind === 2 ? node.checked : + kind === 3 ? node.getBoundingClientRect().width : node.getBoundingClientRect().height; + const text = String(value ?? ''); + if (text.length + 4 > maxBytes - size) throw new RangeError('DOM read result exceeds 1 MiB'); + const bytes = encoder.encode(text); + if (bytes.length + 4 > maxBytes - size) throw new RangeError('DOM read result exceeds 1 MiB'); + parts.push(bytes); + size += 4 + bytes.length; + } + const result = new Uint8Array(size), view = new DataView(result.buffer); + let offset = 0; + for (const bytes of parts) { + view.setUint32(offset, bytes.length, true); + result.set(bytes, offset + 4); + offset += 4 + bytes.length; + } + return result; + } const api = { + // Opt in to the C++ Document API; low-level batch users need no built-in callback registration. + async connect() { + if (connected) throw new Error('DOM interpreter already connected'); + if (connecting) return connecting; + connectionRequested = true; + globalThis.wfDom ??= {}; + globalThis.wfDom.read = read; + connecting = (async () => { + if (!handshakeAcknowledged) { + await bridge.ready; + await bridge.cppFunction('wfDom.ready')(); + handshakeAcknowledged = true; + } + for (const name of pendingRevocations) { + await bridge.cppFunction('wfDom.revoked')(name); + pendingRevocations.delete(name); + } + connected = true; + })(); + try { await connecting; } + finally { connecting = null; } + }, apply, island(name, element) { if (!(element instanceof HTMLElement) || !tags.has(element.localName) || forbiddenTags.has(element.localName)) @@ -320,6 +377,10 @@ export function installDomInterpreter(bridge = globalThis.webFront, extensions = islands.delete(name); const rootId = mounted.get(element); mounted.delete(element); + if (connected) bridge.cppFunction('wfDom.revoked')(name).catch(error => { + console.error('WebFront DOM island revocation failed', error); + }); + else if (connectionRequested) pendingRevocations.add(name); if (rootId === undefined) return; const pending = [rootId]; while (pending.length) { diff --git a/js/core/fallback/index.html b/js/core/fallback/index.html index b9a021cc..e7ff7639 100644 --- a/js/core/fallback/index.html +++ b/js/core/fallback/index.html @@ -20,6 +20,7 @@ margin: 0; min-height: 100vh; display: flex; + flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem; @@ -43,7 +44,7 @@ } #status[data-state="connecting"] { background: color-mix(in srgb, var(--accent) 15%, transparent); } #status[data-state="connected"] { background: color-mix(in srgb, var(--accent) 25%, transparent); } - #status[data-state="error"] { background: color-mix(in srgb, var(--error) 20%, transparent); color: var(--error); } + #status[data-state="error"], #status[data-state="dom-error"] { background: color-mix(in srgb, var(--error) 20%, transparent); color: var(--error); } @@ -52,6 +53,7 @@

Hello, WebFront!

This page is served by WebFront's embedded fallback. It has no local UI files of its own.

Connecting…

+
diff --git a/js/core/fallback/webfront-fallback.mjs b/js/core/fallback/webfront-fallback.mjs index 61e16a34..8e7ab97f 100644 --- a/js/core/fallback/webfront-fallback.mjs +++ b/js/core/fallback/webfront-fallback.mjs @@ -4,11 +4,19 @@ const status = document.getElementById("status"); +let bridgeConnected = false; try { await webFront.ready; + bridgeConnected = true; status.textContent = "Connected to WebFront"; status.dataset.state = "connected"; + const { installDomInterpreter } = await import('./webfront-dom.mjs'); + const dom = installDomInterpreter(webFront); + dom.island('root', document.getElementById('webfront-root')); + await dom.connect(); } catch (error) { - status.textContent = `Connection failed: ${error.message}`; - status.dataset.state = "error"; + status.textContent = bridgeConnected + ? `Connected to WebFront; DOM unavailable: ${error.message}` + : `Connection failed: ${error.message}`; + status.dataset.state = bridgeConnected ? "dom-error" : "error"; } diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index ff084be7..ca9382cc 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -25,7 +25,7 @@ endif() set(TESTS_LIST) list(APPEND TESTS_LIST WebKitGTKPolicyTests.cpp ContentPolicyTests.cpp HTTPServerTests.cpp HTTPEncodingTests.cpp GzipExecutorTests.cpp AcceptEncodingTests.cpp GzipTests.cpp ModuleHTTPServerTests.cpp EncodingsTests.cpp WebSocketTests.cpp LoggerTests.cpp MimeTypeTests.cpp) -list(APPEND TESTS_LIST DomBatchTests.cpp JSFunctionTests.cpp TypeErasedFunctionTests.cpp MessagesTests.cpp IndexFSTests.cpp) +list(APPEND TESTS_LIST DomDocumentTests.cpp DomBatchTests.cpp JSFunctionTests.cpp TypeErasedFunctionTests.cpp MessagesTests.cpp IndexFSTests.cpp) list(APPEND TESTS_LIST FileSystemTests.cpp NativeFSTests.cpp) list(APPEND TESTS_LIST DefaultFSTests.cpp StdnetShutdownTests.cpp SafePathTests.cpp UISubscribersTests.cpp) list(APPEND TESTS_LIST WebFrontTests.cpp WebLinkTests.cpp CEFPathsTests.cpp CEFMacrosTests.cpp) diff --git a/test/unit/DomDocumentTests.cpp b/test/unit/DomDocumentTests.cpp new file mode 100644 index 00000000..5ac9a452 --- /dev/null +++ b/test/unit/DomDocumentTests.cpp @@ -0,0 +1,361 @@ +#include +#include + +using namespace webfront; +namespace { +struct Browser { + std::shared_ptr state; + auto domState() const { + return state; + } +}; +} // namespace + +SCENARIO("DOM documents batch writes and preserve node identity", "[dom]") { + auto state = std::make_shared(); + dom::Document doc{Browser{state}}; + std::vector sent; + unsigned batches{}, wakes{}; + state->send = [&](const msg::DomBatch& batch) { + ++batches; + sent = msg::DomBatch::decode(batch.data()).second; + }; + state->schedule = [&] { + ++wakes; + }; + GIVEN("writes before the interpreter connects") { + auto root = doc.island(); + auto element = doc.element("p"); + auto text = doc.text("été 🌍"); + element.append(text); + root.append(element); + doc.flush(); + REQUIRE(batches == 0); + REQUIRE(wakes == 0); + WHEN("the interpreter connects") { + state->ready = true; + state->wake(); + text.setText("updated"); + doc.flush(); + THEN("one batch contains the names once and all writes") { + REQUIRE(wakes == 1); + REQUIRE(batches == 1); + REQUIRE(sent.size() == 8); + REQUIRE(sent[0].code == msg::DomOp::name); + REQUIRE(sent[0].value == "root"); + REQUIRE(sent.back().code == msg::DomOp::setText); + REQUIRE(sent.back().value == "updated"); + doc.flush(); + REQUIRE(batches == 1); + } + } + WHEN("the application attempts to replace element children through setText") { + REQUIRE_THROWS_AS(element.setText("replacement"), std::invalid_argument); + REQUIRE(text.valid()); + } + WHEN("a subtree is removed") { + element.remove(); + REQUIRE_FALSE(element.valid()); + REQUIRE_FALSE(text.valid()); + REQUIRE(root.valid()); + REQUIRE_THROWS(text.setText("stale")); + } + WHEN("structure would create a cycle or move an island") { + REQUIRE_THROWS_AS(element.append(root), std::invalid_argument); + REQUIRE_THROWS_AS(text.append(element), std::invalid_argument); + auto child = doc.element("div"); + element.append(child); + REQUIRE_THROWS_AS(child.append(element), std::invalid_argument); + } + } +} + +SCENARIO("DOM events and island revocation release callbacks", "[dom]") { + auto state = std::make_shared(); + state->ready = true; + state->send = [](const auto&) { }; + dom::Document doc{Browser{state}}; + auto root = doc.island("panel"); + auto other = doc.island("other"); + auto button = doc.element("button"); + root.append(button); + int calls{}; + button.listen("click", + [&](std::string value) { + REQUIRE(value.empty()); + ++calls; + button.unlisten("click"); + }, + {true, true}); + auto event = state->names.at("click"); + doc.flush(); + state->event(button.id(), event, ""); + state->event(button.id(), event, ""); + REQUIRE(calls == 1); + doc.flush(); + const auto oldRootId = root.id(); + state->revoke("panel"); + REQUIRE_FALSE(root.valid()); + REQUIRE_FALSE(button.valid()); + REQUIRE(other.valid()); + auto newRoot = doc.island("panel"); + REQUIRE(newRoot.id() != oldRootId); + REQUIRE_THROWS(root.id()); +} + +SCENARIO("DOM connections have separate lifetimes and closed handles remain safe", "[dom]") { + auto first = std::make_shared(); + auto second = std::make_shared(); + dom::Document a{Browser{first}}, b{Browser{second}}; + auto node = a.text("first"); + auto other = b.element("div"); + REQUIRE_THROWS_AS(other.append(node), std::invalid_argument); + bool rejected{}; + a.onError([&](std::uint32_t id, std::string reason) { + rejected = id == 1 && reason == "rejected"; + }); + first->reject(1, "rejected"); + REQUIRE(rejected); + REQUIRE_FALSE(a.valid()); + REQUIRE_FALSE(node.valid()); + REQUIRE(other.valid()); + REQUIRE_THROWS(a.text("late")); + second->close(); // Same invalidation used on disconnect and shutdown. + REQUIRE_FALSE(other.valid()); + REQUIRE_THROWS(other.remove()); +} + +SCENARIO("DOM rejects off-thread access and retains a bounded pending batch on errors", "[dom]") { + auto state = std::make_shared(); + dom::Document doc{Browser{state}}; + bool rejected{}; + std::thread thread([&] { + try { + doc.text("wrong thread"); + } catch (const std::logic_error&) { + rejected = true; + } + }); + thread.join(); + REQUIRE(rejected); + auto text = doc.text("kept"); + const auto size = state->pending.data().size(); + REQUIRE_THROWS_AS(text.setText(std::string(msg::DomBatch::maxBytes, 'x')), std::length_error); + REQUIRE(state->pending.data().size() == size); + REQUIRE(text.valid()); + REQUIRE_THROWS_AS(doc.element(std::string(1025, 'x')), std::length_error); +} + +namespace { +struct ReadBrowser : Browser { + std::vector result; + std::shared_ptr starts{std::make_shared(0)}; + template + auto jsFunctionSender(std::string_view) const { + static_assert(std::is_same_v>); + return [bytes = result, calls = starts](const auto&) { + return networking::ex::then(networking::ex::just(), [bytes, calls] { + ++*calls; + return bytes; + }); + }; + } +}; +} // namespace +SCENARIO("DOM grouped read results are bounded and structurally exact", "[dom]") { + auto state = std::make_shared(); + state->ready = true; + state->send = [](const auto&) { }; + ReadBrowser browser{ + {state}, + {3, 0, 0, 0, 'o', 'n', 'e', 0, 0, 0, 0} + }; + dom::Document doc{browser}; + auto first = doc.text("one"), second = doc.text(""); + auto sender = doc.read({ + { first, dom::Read::text}, + {second, dom::Read::text} + }); + const auto result = networking::ex::sync_wait(std::move(sender)); + REQUIRE(std::get<0>(*result) == std::vector{"one", ""}); + for (auto bytes : std::vector>{ + {}, + {1, 0, 0}, + {5, 0, 0, 0, 'a'}, + {0, 0, 0, 0, 1}, + {2, 0, 0, 0, 0xc0, 0x80} + }) { + browser.result = bytes; + dom::Document malformed{browser}; + REQUIRE_THROWS(networking::ex::sync_wait(malformed.read({ + {first, dom::Read::text} + }))); + } + REQUIRE_THROWS_AS(doc.read({}), std::length_error); + state->close(); + REQUIRE_THROWS(networking::ex::sync_wait(doc.read({ + {first, dom::Read::text} + }))); +} + +SCENARIO("DOM rejects element-only operations before changing a pending batch", "[dom]") { + auto state = std::make_shared(); + dom::Document doc{Browser{state}}; + auto text = doc.text("text"), island = doc.island(); + for (const auto& node : {text, island}) { + const auto size = state->pending.data().size(); + const auto names = state->names.size(); + REQUIRE_THROWS_AS(node.attribute("title", "value"), std::invalid_argument); + REQUIRE_THROWS_AS(node.unsetAttribute("title"), std::invalid_argument); + REQUIRE_THROWS_AS(node.property("value", "value"), std::invalid_argument); + REQUIRE_THROWS_AS(node.listen("click", [](std::string) { }), std::invalid_argument); + REQUIRE_THROWS_AS(node.unlisten("click"), std::invalid_argument); + REQUIRE(state->pending.data().size() == size); + REQUIRE(state->names.size() == names); + REQUIRE(state->listeners.empty()); + REQUIRE(node.valid()); + } + REQUIRE(doc.valid()); +} + +SCENARIO("DOM reports batch identifier exhaustion exactly once", "[dom]") { + auto state = std::make_shared(); + state->batchId = std::numeric_limits::max(); + state->pending = msg::DomBatch(state->batchId); + state->ready = true; + unsigned sent{}, errors{}; + state->send = [&](const msg::DomBatch& batch) { + REQUIRE(msg::DomBatch::decode(batch.data()).first == state->batchId); + ++sent; + }; + dom::Document doc{Browser{state}}; + doc.onError([&](std::uint32_t id, std::string reason) { + REQUIRE(id == std::numeric_limits::max()); + REQUIRE(reason == "DOM batch identifiers exhausted"); + ++errors; + }); + auto node = doc.text("last batch"); + REQUIRE_THROWS_AS(doc.flush(), std::length_error); + REQUIRE(sent == 1); + REQUIRE(errors == 1); + REQUIRE_FALSE(doc.valid()); + REQUIRE_FALSE(node.valid()); +} + +SCENARIO("Inserting a DOM node before itself preserves its identity and pending batch", "[dom]") { + auto state = std::make_shared(); + dom::Document doc{Browser{state}}; + auto parent = doc.element("div"), child = doc.text("child"); + parent.append(child); + const auto size = state->pending.data().size(); + parent.insertBefore(child, child); + REQUIRE(state->pending.data().size() == size); + REQUIRE(child.valid()); + REQUIRE(state->get(child.id()).parent == parent.id()); +} + +SCENARIO("DOM validity predicates are nonthrowing and agree about the calling thread", "[dom]") { + auto state = std::make_shared(); + dom::Document doc{Browser{state}}; + auto node = doc.text("valid"); + STATIC_REQUIRE(noexcept(doc.valid())); + STATIC_REQUIRE(noexcept(node.valid())); + REQUIRE(doc.valid()); + REQUIRE(node.valid()); + bool nodeValid = true, documentValid = true, threw = false; + std::thread caller([&] { + try { + nodeValid = node.valid(); + documentValid = doc.valid(); + } catch (...) { + threw = true; + } + }); + caller.join(); + REQUIRE_FALSE(threw); + REQUIRE_FALSE(nodeValid); + REQUIRE_FALSE(documentValid); + REQUIRE(doc.valid()); + REQUIRE(node.valid()); + node.remove(); + REQUIRE_FALSE(node.valid()); + REQUIRE(doc.valid()); + auto moved = std::move(doc); + REQUIRE_FALSE(doc.valid()); + REQUIRE(moved.valid()); + state->close(); + REQUIRE_FALSE(doc.valid()); + REQUIRE_FALSE(moved.valid()); + REQUIRE_FALSE(node.valid()); +} + +SCENARIO("DOM rejects empty event callbacks without changing subscriptions or pending names", "[dom]") { + auto state = std::make_shared(); + dom::Document doc{Browser{state}}; + auto button = doc.element("button"); + unsigned calls{}; + button.listen("click", [&](std::string) { + ++calls; + }); + const auto size = state->pending.data().size(); + const auto names = state->names.size(); + REQUIRE_THROWS_AS(button.listen("keydown", {}), std::invalid_argument); + REQUIRE_THROWS_AS(button.listen("click", {}), std::invalid_argument); + REQUIRE(state->pending.data().size() == size); + REQUIRE(state->names.size() == names); + REQUIRE(state->listeners.size() == 1); + state->event(button.id(), state->names.at("click"), ""); + REQUIRE(calls == 1); +} + +SCENARIO("An island unmount with pending writes closes the entire document once", "[dom]") { + auto state = std::make_shared(); + state->ready = true; + state->send = [](const auto&) { }; + dom::Document doc{Browser{state}}; + auto first = doc.island("first"), second = doc.island("second"); + auto text = doc.text("second island"); + second.append(text); + doc.flush(); + unsigned errors{}; + doc.onError([&](std::uint32_t, std::string reason) { + REQUIRE(reason == "DOM island revoked with pending writes"); + ++errors; + }); + text.setText("pending in a different island"); + state->revoke("first"); + REQUIRE(errors == 1); + REQUIRE_FALSE(doc.valid()); + REQUIRE_FALSE(first.valid()); + REQUIRE_FALSE(second.valid()); + REQUIRE_FALSE(text.valid()); +} + + +SCENARIO("Creating a grouped DOM read flushes writes even when its lazy read sender is discarded", "[dom]") { + auto state = std::make_shared(); + state->ready = true; + unsigned writes{}; + state->send = [&](const auto&) { + ++writes; + }; + ReadBrowser browser{ + {state}, + {0, 0, 0, 0} + }; + dom::Document doc{browser}; + auto text = doc.text("pending write"); + REQUIRE(writes == 0); + static_cast(doc.read({ + {text, dom::Read::text} + })); + REQUIRE(writes == 1); + REQUIRE(*browser.starts == 0); + auto sender = doc.read({ + {text, dom::Read::text} + }); + REQUIRE(writes == 1); + REQUIRE(*browser.starts == 0); + REQUIRE(networking::ex::sync_wait(std::move(sender)).has_value()); + REQUIRE(*browser.starts == 1); +} diff --git a/test/unit/WebFrontTests.cpp b/test/unit/WebFrontTests.cpp index a2995232..96854b86 100644 --- a/test/unit/WebFrontTests.cpp +++ b/test/unit/WebFrontTests.cpp @@ -1,13 +1,13 @@ +#include "InjectableNetworking.hpp" +#include "Mocks.hpp" +#include "Version.hpp" #include #include #include -#include #include +#include #include -#include "Mocks.hpp" -#include "Version.hpp" - #include #include #include @@ -16,8 +16,10 @@ #include #include #include +#include #include #include +#include #include using namespace webfront; @@ -848,3 +850,46 @@ SCENARIO("Sending a DOM batch through a lost UI link throws ConnectionError") { } } } + +namespace { +struct DomNoTimerNet : testing::InjectableNetworking { + static inline bool accepted{}; + static auto Accept(Acceptor&) { + return networking::ex::then(networking::ex::just(), []() -> Socket { + if (std::exchange(accepted, true)) + throw std::system_error(std::make_error_code(std::errc::operation_canceled)); + return Socket{}; + }); + } +}; +} // namespace + +SCENARIO("DOM readiness explains a missing network timer while the ordinary bridge remains usable", "[dom]") { + using Socket = testing::InjectableSocket; + Socket::reset(); + DomNoTimerNet::accepted = false; + BasicWF app{WebFrontConfig{.port = "0"}}; + app.cppFunction("echo", [] { + return std::string{"bridge stays available"}; + }); + const std::string upgrade = "GET / HTTP/1.1\r\nHost: localhost\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n" + "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nSec-WebSocket-Version: 13\r\n\r\n"; + Socket::receive(std::as_bytes(std::span(upgrade))); + msg::Handshake handshake; + Socket::receive(testing::clientFrame(std::span(reinterpret_cast(handshake.header().data()), handshake.header().size()))); + REQUIRE(app.connectedBrowsers() == 1); + auto call = [](std::string name, msg::CallId id) { + msg::FunctionCall<> message; + message.setCallId(id); + websocket::Frame frame{std::span(reinterpret_cast(message.header().data()), message.header().size())}; + message.encodeParameter(name, frame); + frame.freeze(); + Socket::receive(testing::clientFrame(testing::messagePayload(frame))); + }; + call("wfDom.ready", 21); + REQUIRE(Socket::wrote("DOM API requires Net::ResumeAfter")); + call("echo", 22); + REQUIRE(Socket::wrote("bridge stays available")); + REQUIRE(app.connectedBrowsers() == 1); + app.shutdown(); +} diff --git a/test/web/JasmineTest.cpp b/test/web/JasmineTest.cpp index 11d16b90..4b7ac217 100644 --- a/test/web/JasmineTest.cpp +++ b/test/web/JasmineTest.cpp @@ -38,6 +38,7 @@ constexpr string_view jsToCppToken{"js-to-cpp-token"}; struct TestState { atomic browserReady{false}; + atomic domDocumentObserved{false}; atomic domBatchSent{false}; atomic domRejectionObserved{false}; atomic domEventsObserved{false}; @@ -58,6 +59,10 @@ class TestPages { explicit TestPages(const filesystem::path& project) : root(project / "pages") { } optional open(filesystem::path file) const { + if (file.relative_path() == "embedded-fallback.html") + return fs::IndexFS::open("index.html"); + if (file.relative_path().parent_path() == "nested-fallback") + return fs::IndexFS::open(file.filename()); try { const auto path = developer::projectPath(root, file.relative_path().generic_string()); ifstream stream(path, ios::binary); @@ -102,6 +107,14 @@ class BrowserIntegrationTest { log::error("wf test did not pass (status {})", status); return status; } + if (!shutdownDocument || shutdownDocument->valid() || shutdownNode.valid()) { + log::error("DOM handles remained valid after application shutdown"); + return 1; + } + try { + shutdownDocument->text("after shutdown"); + return 1; + } catch (const std::runtime_error&) { } return result(); } @@ -113,8 +126,15 @@ class BrowserIntegrationTest { // Accessed only by callbacks on the server context. finish() runs after WfDriver joins app.shutdown(). std::map domRejections; std::array domEventCounts{}; + std::map documentTexts, documentInputs; + std::map documentReads; + std::map documentCancelled; + optional> shutdownDocument; + dom::Node shutdownNode; optional connectedUI; UISubscription uiSubscription; + UISubscription closedDomSubscription; + std::map closedDocumentRejected; future cppResult; jthread bitsetFutureThread; static constexpr chrono::seconds cppResultWaitTimeout{10}; @@ -268,8 +288,94 @@ class BrowserIntegrationTest { }); } + struct DocumentReadNotice { + bool& cancelled; + bool pending{true}; + ~DocumentReadNotice() { + if (pending) + cancelled = true; + } + }; + Task readDocument(TestWF::UI ui) { + documentCancelled[ui.id()] = false; + DocumentReadNotice notice{documentCancelled[ui.id()]}; + try { + // Keep initializer-list temporaries out of the co_await expression (GCC coroutine ICE). + std::vector requests; + requests.push_back({documentTexts.at(ui.id()), dom::Read::text}); + requests.push_back({documentInputs.at(ui.id()), dom::Read::value}); + auto sender = ui.document().read(std::move(requests)); + auto values = co_await std::move(sender); + ui.jsFunction("documentReadResult")(values.at(0) + "|" + values.at(1)); + state.domDocumentObserved = true; + notice.pending = false; + } catch (...) { + notice.pending = false; + throw; + } + } + void registerCallbacks() { + closedDomSubscription = webFront->subscribeUIClosed([this](TestWF::UI ui) { + try { + static_cast(ui.document()); + closedDocumentRejected[ui.id()] = false; + } catch (const ConnectionError&) { + closedDocumentRejected[ui.id()] = true; + } + }); + webFront->cppFunction("domClosedDocumentRejected", [this](uint32_t id) { + return closedDocumentRejected[static_cast(id)]; + }); + webFront->cppFunction("domDocumentOffThread", [](TestWF::UI ui) { + bool rejected = false; + std::exception_ptr failure; + std::thread caller([&] { + try { + static_cast(ui.document()); + } catch (const std::logic_error&) { + rejected = true; + } catch (...) { + failure = std::current_exception(); + } + }); + caller.join(); + if (failure) + std::rethrow_exception(failure); + return rejected; + }); + webFront->cppFunction("domDocumentBuild", [this](TestWF::UI ui) { + auto doc = ui.document(); + auto root = doc.island(); + auto text = doc.text("C++ été 🌍"); + auto input = doc.element("input"); + input.property("value", "initial"); + input.listen("input", + [text](std::string value) { + text.setText(std::move(value)); + }, + {true, true}); + root.append(text); + root.append(input); + documentTexts[ui.id()] = text; + documentInputs[ui.id()] = input; + return static_cast(ui.id()); + }); + webFront->cppFunction("domDocumentRead", [this](TestWF::UI ui) { + documentReads.insert_or_assign(ui.id(), ui.spawn(readDocument(ui))); + }); + webFront->cppFunction("domDocumentCancelRead", [this](TestWF::UI ui) { + documentReads.at(ui.id()).requestStop(); + }); + webFront->cppFunction("domDocumentCancelled", [this](TestWF::UI ui) { + return documentCancelled[ui.id()]; + }); + webFront->cppFunction("domDocumentNodeValid", [this](uint32_t id) { + return documentTexts.at(static_cast(id)).valid(); + }); webFront->cppFunction("sendDomBatch", [this](TestWF::UI ui, const vector& bytes) { + // A dormant document wrapper must not intercept the low-level event/rejection callbacks below. + static_cast(ui.document()); const auto [id, operations] = msg::DomBatch::decode(std::as_bytes(std::span(bytes))); msg::DomBatch batch(id); for (const auto& operation : operations) batch.add(operation); @@ -421,6 +527,8 @@ class BrowserIntegrationTest { /// The last spec: everything the specs sent over this connection has been handled. void specsFinished() { + shutdownDocument.emplace(connectedUI->document()); + shutdownNode = shutdownDocument->text("pending at shutdown"); state.cppResultObserved = cppResultMatches(); state.specsFinished = true; } @@ -444,10 +552,8 @@ class BrowserIntegrationTest { log::error("The specs did not report the end of the run"); return 1; } - if (!(state.domBatchSent && state.domRejectionObserved && state.domEventsObserved - && state.browserReady && state.subscriberNotified - && browserCallsObserved() && cppCallsObserved() - && rejectedWebSocket->rejectedRequests() >= 2)) { + if (!(state.domDocumentObserved && state.domBatchSent && state.domRejectionObserved && state.domEventsObserved && state.browserReady + && state.subscriberNotified && browserCallsObserved() && cppCallsObserved() && rejectedWebSocket->rejectedRequests() >= 2)) { log::error("The specs passed but one of the bridge-direction checks failed"); return 1; } diff --git a/test/web/suite/pages/dom-document.html b/test/web/suite/pages/dom-document.html new file mode 100644 index 00000000..55d7537b --- /dev/null +++ b/test/web/suite/pages/dom-document.html @@ -0,0 +1,10 @@ + +
+ + diff --git a/test/web/suite/specs/dom-document-specs.mjs b/test/web/suite/specs/dom-document-specs.mjs new file mode 100644 index 00000000..68184b46 --- /dev/null +++ b/test/web/suite/specs/dom-document-specs.mjs @@ -0,0 +1,115 @@ +// Separate real connections exercise the per-browser C++ Document, including a reload. +async function until(predicate) { + const deadline = performance.now() + 5000; + while (!await predicate()) { + if (performance.now() > deadline) throw new Error('DOM document condition timed out'); + await new Promise(resolve => setTimeout(resolve, 5)); + } +} +async function connectedFrame(defer = false) { + const frame = document.createElement('iframe'); + const loaded = new Promise((resolve, reject) => { frame.onload = resolve; frame.onerror = reject; }); + frame.src = defer ? '/dom-document.html?defer' : '/dom-document.html'; + document.body.appendChild(frame); + await loaded; + await until(() => !!frame.contentWindow.documentConnected); + await frame.contentWindow.documentConnected; + return frame; +} +function call(frame, name, ...args) { return frame.contentWindow.webFront.cppFunction(name)(...args); } + +describe('C++ DOM document API', () => { + it('rejects the first off-thread document access without binding the document to that thread', async () => { + const frame = await connectedFrame(true); + try { + expect(await call(frame, 'domDocumentOffThread')).toBeTrue(); + await frame.contentWindow.connectDocument(); + await call(frame, 'wfDom.ready'); // Idempotent if a prior readiness acknowledgement was lost. + const id = await call(frame, 'domDocumentBuild'); + expect(await call(frame, 'domDocumentNodeValid', id)).toBeTrue(); + } finally { frame.remove(); } + }); + it('retries readiness when C++ accepted it but the acknowledgement was lost', async () => { + const frame = await connectedFrame(true); + const page = frame.contentWindow; + const original = page.webFront.cppFunction; + let loseAcknowledgement = true; + page.webFront.cppFunction = function(name) { + const invoke = original.call(this, name); + return (...args) => invoke(...args).then(value => { + if (name === 'wfDom.ready' && loseAcknowledgement) { + loseAcknowledgement = false; + throw new Error('readiness acknowledgement lost'); + } + return value; + }); + }; + try { + await page.connectDocument().then( + () => { throw new Error('The first acknowledgement should be lost'); }, + error => { expect(error.message).toBe('readiness acknowledgement lost'); }); + await page.connectDocument(); + const id = await call(frame, 'domDocumentBuild'); + expect(await call(frame, 'domDocumentNodeValid', id)).toBeTrue(); + } finally { page.webFront.cppFunction = original; frame.remove(); } + }); + + it('batches writes automatically, handles event flags and groups explicit sender reads', async () => { + const frame = await connectedFrame(); + try { + const page = frame.contentWindow, root = page.document.getElementById('root'); + const id = await call(frame, 'domDocumentBuild'); + await until(() => root.querySelector('input')); + expect(root.firstChild.nodeType).toBe(Node.TEXT_NODE); + expect(root.firstChild.textContent).toBe('C++ été 🌍'); + let bubbled = false; + root.addEventListener('input', () => { bubbled = true; }); + const input = root.querySelector('input'); + input.value = 'changed 🌍'; + const event = new page.Event('input', {bubbles: true, cancelable: true}); + input.dispatchEvent(event); + expect(event.defaultPrevented).toBeTrue(); + expect(bubbled).toBeFalse(); + await until(() => root.firstChild.textContent === input.value); + const result = new Promise(resolve => { page.documentReadResult = resolve; }); + await call(frame, 'domDocumentRead'); + expect(await result).toBe('changed 🌍|changed 🌍'); + + // Cancellation ends the local wait. Resolve the browser Promise afterwards to exercise a late reply. + let late; + const original = page.wfDom.read; + page.wfDom.read = () => new Promise(resolve => { late = resolve; }); + await call(frame, 'domDocumentRead'); + await until(() => late); + await call(frame, 'domDocumentCancelRead'); + await until(() => call(frame, 'domDocumentCancelled')); + late(new page.Uint8Array(0)); + page.wfDom.read = original; + await call(frame, 'domDocumentCancelled'); // Round trip after the late reply. + page.releaseIsland(); + expect(await call(frame, 'domDocumentNodeValid', id)).toBeFalse(); + } finally { frame.remove(); } + }); + + it('isolates browsers and invalidates handles on disconnect and reload', async () => { + const first = await connectedFrame(), second = await connectedFrame(); + try { + const firstId = await call(first, 'domDocumentBuild'); + const secondId = await call(second, 'domDocumentBuild'); + expect(firstId).not.toBe(secondId); + first.remove(); + await until(async () => !await webFront.cppFunction('domDocumentNodeValid')(firstId)); + expect(await webFront.cppFunction('domClosedDocumentRejected')(firstId)).toBeTrue(); + expect(await call(second, 'domDocumentNodeValid', secondId)).toBeTrue(); + const loaded = new Promise(resolve => { second.onload = resolve; }); + second.contentWindow.location.reload(); + await loaded; + await until(() => !!second.contentWindow.documentConnected); + await second.contentWindow.documentConnected; + const newId = await call(second, 'domDocumentBuild'); + expect(newId).not.toBe(secondId); + expect(await call(second, 'domDocumentNodeValid', secondId)).toBeFalse(); + expect(await call(second, 'domDocumentNodeValid', newId)).toBeTrue(); + } finally { first.remove(); second.remove(); } + }); +}); diff --git a/test/web/suite/specs/dom-specs.mjs b/test/web/suite/specs/dom-specs.mjs index c73492b4..99dce0f8 100644 --- a/test/web/suite/specs/dom-specs.mjs +++ b/test/web/suite/specs/dom-specs.mjs @@ -45,6 +45,155 @@ describe('Embedded DOM command interpreter', () => { }); afterEach(() => { release(); root.remove(); }); + it('validates grouped reads, UTF-8 framing and exact result budgets', async () => { + const previous = globalThis.wfDom; + globalThis.wfDom = {}; + try { + await dom.connect(); + await expectAsync(dom.connect()).toBeRejected(); + dom.apply(packet([name(3, 'input'), [2, 2, 3], text(3, 'été 🌍'), [8, 1, 2], [8, 1, 3]])); + const read = globalThis.wfDom.read, input = root.firstChild; + input.value = 'value'; + const result = read(new Uint32Array([3, 0, 2, 1, 2, 2])); + const view = new DataView(result.buffer), values = []; + for (let offset = 0; offset < result.length;) { + const size = view.getUint32(offset, true); offset += 4; + values.push(new TextDecoder('utf-8', {fatal: true}).decode(result.subarray(offset, offset + size))); + offset += size; + } + expect(values).toEqual(['été 🌍', 'value', 'false']); + for (const invalid of [[], new Uint32Array(), new Uint32Array([2]), new Uint32Array(8194), + new Uint32Array([999, 0]), new Uint32Array([2, 5]), new Uint32Array([3, 3])]) + expect(() => read(invalid)).toThrow(); + const textNode = root.lastChild; + textNode.data = 'x'.repeat(1024 * 1024 - 4); + expect(read(new Uint32Array([3, 0])).length).toBe(1024 * 1024); + textNode.data += 'x'; + expect(() => read(new Uint32Array([3, 0]))).toThrow(); + } finally { globalThis.wfDom = previous; } + }); + + it('uses an empty value for bubbled input/change on a non-form subscriber', () => { + const received = []; + bridge.cppFunction.and.returnValue((...args) => { received.push(args); return Promise.resolve(); }); + dom.apply(packet([name(3, 'input'), name(4, 'change'), [2, 2, 1], [2, 3, 3], + [8, 2, 3], [8, 1, 2], [11, 2, 3, 0], [11, 2, 4, 0]])); + const input = root.firstChild.firstChild; + input.value = 'child value'; + input.dispatchEvent(new Event('input', {bubbles: true})); + input.dispatchEvent(new Event('change', {bubbles: true})); + expect(received).toEqual([[2, 3, ''], [2, 4, '']]); + }); + + it('reports an oversized UTF-8 event value in the browser without truncating it', async () => { + const diagnostic = spyOn(console, 'error'); + bridge.cppFunction = webFront.cppFunction.bind(webFront); + dom.apply(packet([name(3, 'textarea'), name(4, 'input'), [2, 2, 3], [8, 1, 2], [11, 2, 4, 0]])); + const textarea = root.firstChild; + textarea.value = 'é'.repeat(32768); // 65,536 UTF-8 bytes, despite only 32,768 UTF-16 units. + textarea.dispatchEvent(new Event('input')); + await Promise.resolve(); + expect(diagnostic).toHaveBeenCalledWith('WebFront DOM event delivery failed', jasmine.any(RangeError)); + expect(textarea.value).toBe('é'.repeat(32768)); + }); + + it('logs a failed post-connection island revocation instead of silently ignoring it', async () => { + const previous = globalThis.wfDom; + globalThis.wfDom = {}; + try { + await dom.connect(); + const error = new Error('revocation unavailable'); + const diagnostic = spyOn(console, 'error'); + bridge.cppFunction.and.callFake(name => () => name === 'wfDom.revoked' ? Promise.reject(error) : Promise.resolve()); + release(); + await Promise.resolve(); + expect(diagnostic).toHaveBeenCalledWith('WebFront DOM island revocation failed', error); + } finally { globalThis.wfDom = previous; } + }); + + it('can retry connect after bridge readiness or the DOM handshake rejects', async () => { + const previous = globalThis.wfDom; + globalThis.wfDom = {}; + try { + bridge.ready = Promise.reject(new Error('bridge unavailable')); + await expectAsync(dom.connect()).toBeRejectedWithError('bridge unavailable'); + bridge.ready = Promise.resolve(); + bridge.cppFunction.and.returnValue(() => Promise.reject(new Error('DOM unavailable'))); + await expectAsync(dom.connect()).toBeRejectedWithError('DOM unavailable'); + bridge.cppFunction.and.returnValue(() => Promise.resolve()); + await expectAsync(dom.connect()).toBeResolved(); + } finally { globalThis.wfDom = previous; } + }); + + it('retries only unacknowledged revocations after a partially successful connect', async () => { + const previous = globalThis.wfDom; + globalThis.wfDom = {}; + const second = dom.island('second', document.createElement('div')); + const third = dom.island('third', document.createElement('div')); + let readyCalls = 0, fail = true; + const revoked = []; + bridge.ready = Promise.resolve(); + bridge.cppFunction.and.callFake(name => island => { + if (name === 'wfDom.ready') { + ++readyCalls; + return readyCalls === 1 ? Promise.resolve() : Promise.reject(new Error('duplicate ready')); + } + revoked.push(island); + if (island === 'second' && fail) { + fail = false; + return Promise.reject(new Error('revocation not acknowledged')); + } + return Promise.resolve(); + }); + try { + const attempt = dom.connect(); + release(); second(); + await expectAsync(attempt).toBeRejectedWithError('revocation not acknowledged'); + expect(revoked).toEqual(['root', 'second']); + third(); // Also retain releases made between the failed attempt and the retry. + expect(revoked).toEqual(['root', 'second']); + await expectAsync(dom.connect()).toBeResolved(); + expect(readyCalls).toBe(1); + expect(revoked).toEqual(['root', 'second', 'second', 'third']); + await expectAsync(dom.connect()).toBeRejectedWithError('DOM interpreter already connected'); + } finally { globalThis.wfDom = previous; } + }); + + it('defers revocations until the DOM handshake is acknowledged', async () => { + const previous = globalThis.wfDom; + globalThis.wfDom = {}; + let ready, acknowledge; + bridge.ready = new Promise(resolve => { ready = resolve; }); + const calls = []; + bridge.cppFunction.and.callFake(name => (...args) => { + calls.push([name, ...args]); + return name === 'wfDom.ready' ? new Promise(resolve => { acknowledge = resolve; }) : Promise.resolve(); + }); + try { + const pending = dom.connect(); + release(); + expect(calls).toEqual([]); + ready(); + await Promise.resolve(); + expect(calls).toEqual([['wfDom.ready']]); + acknowledge(); + await pending; + expect(calls).toEqual([['wfDom.ready'], ['wfDom.revoked', 'root']]); + } finally { globalThis.wfDom = previous; } + }); + + it('matches native insertBefore(node, node) without changing sibling order or identity', () => { + dom.apply(packet([text(2, 'first'), text(3, 'second'), [8, 1, 2], [8, 1, 3]])); + const first = root.firstChild, second = root.lastChild; + root.insertBefore(first, first); + dom.apply(packet([[9, 1, 2, 2], [7, 2, ...str('updated')]])); + expect(root.firstChild).toBe(first); + expect(root.lastChild).toBe(second); + expect(first.data).toBe('updated'); + dom.apply(packet([[10, 2], [10, 3]])); + expect(root.childNodes.length).toBe(0); + }); + it('creates, inserts, moves, removes and updates text without parsing HTML', () => { dom.apply(packet([[2, 2, 1], text(3, 'été 🌍'), [8, 2, 3], [8, 1, 2], attr(2, 2, 'hello')])); const element = root.firstChild, child = element.firstChild; diff --git a/test/web/suite/specs/fallback-specs.mjs b/test/web/suite/specs/fallback-specs.mjs new file mode 100644 index 00000000..bcf7d766 --- /dev/null +++ b/test/web/suite/specs/fallback-specs.mjs @@ -0,0 +1,81 @@ +// Execute the actual fallback module in isolated documents with controlled bridge failures. +describe('Fallback readiness diagnostics', () => { + let source, sourceUrl; + beforeAll(async () => { + const response = await fetch('/webfront-fallback.mjs'); + expect(response.ok).toBeTrue(); + source = await response.text(); + sourceUrl = response.url; + }); + async function diagnostic(moduleSource, bridgeFailure, domFailure) { + const frame = document.createElement('iframe'); + // Blob modules need fully qualified URLs; preserve the actual dynamic import and error handling. + const executable = moduleSource.replace(/import\('([^']+)'\)/g, (_, path) => + `import(${JSON.stringify(new URL(path, sourceUrl).href)})`); + const url = URL.createObjectURL(new Blob([executable], {type: 'text/javascript'})); + const loaded = new Promise(resolve => { frame.onload = resolve; }); + frame.srcdoc = `

Connecting…

+