pub struct ScriptedDom { /* private fields */ }Expand description
A mutable DOM arena. Nodes live in a prunable [NodeStore] keyed by a
monotonic id; a pruned id is “gone” (ids are never reused). Memory is bounded
to live nodes by collect (G3), not to every node
ever created.
Implementations§
Source§impl ScriptedDom
impl ScriptedDom
Sourcepub fn form_values(&self, root: NodeId) -> Vec<(String, String)>
pub fn form_values(&self, root: NodeId) -> Vec<(String, String)>
Form-control values under root (inclusive), keyed by the control’s name,
falling back to id. Covers <input>/<select> (the value attribute) and
<textarea> (text content). Controls with neither a name nor an id are
skipped — nothing identifies them in a freshly loaded page.
Source§impl ScriptedDom
impl ScriptedDom
Sourcepub fn outer_html(&self, node: NodeId) -> String
pub fn outer_html(&self, node: NodeId) -> String
Serialize node and its subtree to HTML (outerHTML).
Routes through html5ever’s serializer, so void elements, attribute/text escaping, and raw-text elements are handled by the engine, not here.
Sourcepub fn inner_html(&self, node: NodeId) -> String
pub fn inner_html(&self, node: NodeId) -> String
Serialize only node’s children (innerHTML).
Source§impl ScriptedDom
impl ScriptedDom
Sourcepub fn capture_node_id(&self, id: NodeId) -> u64
pub fn capture_node_id(&self, id: NodeId) -> u64
Normalize id for capture/replay: strip any debug doc-tag fence and return
the bare arena index the recorder writes.
Sourcepub fn remint_node_id(&self, raw: u64) -> NodeId
pub fn remint_node_id(&self, raw: u64) -> NodeId
Re-mint a captured bare arena index against this document, restoring this document’s tag on a fenced build.
Sourcepub fn remove_child(&mut self, child: NodeId)
pub fn remove_child(&mut self, child: NodeId)
DOM removeChild: orphan child from its parent but keep it (and its
subtree) alive and re-insertable, recording a DomMutation::Removed.
Unlike LayoutDomMut::remove, which
also drops the subtree — script may hold a reference to a removed node and
re-insert it, so the scripted DOM orphans rather than frees.
Sourcepub fn create_document(&mut self) -> NodeId
pub fn create_document(&mut self) -> NodeId
Create a detached Document node (a second document, for
DOMImplementation.createDocument / createHTMLDocument). Lives in the same
store as the primary document, so NodeIds stay globally unique. It is
pin-kept, not a permanent root (G3): while script holds a reflector to
it (or anything in it) the host pins it and collect spares the whole
component; once script drops it, it collects like any other orphan.
Sourcepub fn create_comment(&mut self, data: &str) -> NodeId
pub fn create_comment(&mut self, data: &str) -> NodeId
Create a detached Comment node carrying data.
Sourcepub fn create_fragment(&mut self) -> NodeId
pub fn create_fragment(&mut self) -> NodeId
Create a detached DocumentFragment node (a parentless container).
Sourcepub fn from_serialized_document(html: &str) -> Self
pub fn from_serialized_document(html: &str) -> Self
Rebuild a fresh document from serialized document children (the same
shape inner_html(document()) emits for capture).
Sourcepub fn import_serialized_subtree(
&mut self,
html: &str,
) -> Result<NodeId, String>
pub fn import_serialized_subtree( &mut self, html: &str, ) -> Result<NodeId, String>
Import exactly one serialized subtree as a detached node.
Sourcepub fn collect(
&mut self,
extra_roots: impl IntoIterator<Item = NodeId>,
) -> usize
pub fn collect( &mut self, extra_roots: impl IntoIterator<Item = NodeId>, ) -> usize
Mark-sweep collection (G3 dangle contract). Prune every node not reachable
— by undirected walk over parent + child edges — from a document root
or one of extra_roots. extra_roots are the host’s live-reflector pins
(ReflectorPins); passing
them keeps a pinned orphan’s whole connected component alive (JS can walk
parentNode up and children down and re-insert any of it). The DOM stays
pin-agnostic — it takes extra roots, not reflector knowledge. Returns the
number of nodes pruned.
Idempotent and cheap to call often: the host drives it at the
drain_mutations boundary, on an idle tick, and right after an unpin.
Sourcepub fn live_node_count(&self) -> usize
pub fn live_node_count(&self) -> usize
The number of live nodes currently in the store. Bounded by collect
(G3), not by total nodes ever created — a diagnostic for the host and the
regression signal for the bounded-memory churn test.
Sourcepub fn stats(&self) -> DomArenaStats
pub fn stats(&self) -> DomArenaStats
Cheap live counts plus a rough byte estimate for the DOM arena.
Trait Implementations§
Source§impl Default for ScriptedDom
impl Default for ScriptedDom
Source§impl LayoutDom for ScriptedDom
impl LayoutDom for ScriptedDom
Source§fn is_live(&self, id: NodeId) -> bool
fn is_live(&self, id: NodeId) -> bool
The dangle-contract liveness check (see LayoutDom::is_live). Live iff
the id belongs to this document and still has an entry in the store
(attached or orphaned-but-kept); a dropped or collected node has no entry.
Never panics, unlike the read accessors.
Source§fn prev_sibling(&self, id: NodeId) -> Option<NodeId>
fn prev_sibling(&self, id: NodeId) -> Option<NodeId>
prev_sibling_element in selectors::Element); deriving it from
dom_children(parent) would be O(siblings) per call.Source§fn next_sibling(&self, id: NodeId) -> Option<NodeId>
fn next_sibling(&self, id: NodeId) -> Option<NodeId>
Self::prev_sibling.Source§fn dom_children(&self, id: NodeId) -> impl Iterator<Item = NodeId> + '_
fn dom_children(&self, id: NodeId) -> impl Iterator<Item = NodeId> + '_
Source§fn kind(&self, id: NodeId) -> NodeKind
fn kind(&self, id: NodeId) -> NodeKind
id is. Plain enum; details via the typed
accessors below.Source§fn opaque_id(&self, id: NodeId) -> u64
fn opaque_id(&self, id: NodeId) -> u64
u64. Used by foreign trait adapters
(Stylo’s OpaqueNode, selectors::OpaqueElement) that need a
pointer-shaped value for identity comparisons in the cascade. Read moreSource§fn element_name(&self, id: NodeId) -> Option<&QualName>
fn element_name(&self, id: NodeId) -> Option<&QualName>
id is an element, else None. Hot on
selector/style match paths.Source§fn attribute(
&self,
id: NodeId,
ns: &Namespace,
local: &LocalName,
) -> Option<&str>
fn attribute( &self, id: NodeId, ns: &Namespace, local: &LocalName, ) -> Option<&str>
Source§fn attributes(&self, id: NodeId) -> impl Iterator<Item = AttributeView<'_>> + '_
fn attributes(&self, id: NodeId) -> impl Iterator<Item = AttributeView<'_>> + '_
AttributeViews borrowed from the backing
store.Source§fn quirks_mode(&self) -> QuirksMode
fn quirks_mode(&self) -> QuirksMode
<!DOCTYPE>). Drives quirk-gated cascade behaviour (Stylo’s
QuirksMode-conditional UA rules, e.g. the table font-size quirk).
Defaults to standards mode; a backend that parses a real document
overrides it.Source§fn flat_children(&self, id: Self::NodeId) -> impl Iterator<Item = Self::NodeId>
fn flat_children(&self, id: Self::NodeId) -> impl Iterator<Item = Self::NodeId>
Source§fn walk<V>(
&self,
visitor: &mut V,
) -> ControlFlow<<V as NodeVisitor<Self>>::Stop>where
V: NodeVisitor<Self> + ?Sized,
fn walk<V>(
&self,
visitor: &mut V,
) -> ControlFlow<<V as NodeVisitor<Self>>::Stop>where
V: NodeVisitor<Self> + ?Sized,
document(), descending via
dom_children. Backends override when they want backend-driven
traversal (parallel layout pass, prefetching, flat-tree descent).Source§fn has_class(&self, id: Self::NodeId, class: &str) -> bool
fn has_class(&self, id: Self::NodeId, class: &str) -> bool
id carries CSS class class (whitespace-split class attr).Source§fn first_with_class(
&self,
id: Self::NodeId,
class: &str,
) -> Option<Self::NodeId>
fn first_with_class( &self, id: Self::NodeId, class: &str, ) -> Option<Self::NodeId>
class in pre-order under id (inclusive).Source§impl LayoutDomMut for ScriptedDom
impl LayoutDomMut for ScriptedDom
Source§fn create_element(&mut self, name: QualName) -> NodeId
fn create_element(&mut self, name: QualName) -> NodeId
Source§fn create_text(&mut self, data: &str) -> NodeId
fn create_text(&mut self, data: &str) -> NodeId
Source§fn append_child(&mut self, parent: NodeId, child: NodeId)
fn append_child(&mut self, parent: NodeId, child: NodeId)
child as the last child of parent, detaching it from any
previous parent first.Source§fn insert_before(
&mut self,
parent: NodeId,
child: NodeId,
reference: Option<NodeId>,
)
fn insert_before( &mut self, parent: NodeId, child: NodeId, reference: Option<NodeId>, )
child immediately before reference among parent’s children,
detaching child from any previous parent first. Appends if reference
is None, or if reference is not a child of parent (defensive: the
DOM insertBefore throws in that case, but the layout-side contract
stays total). The ordered-insertion primitive a reactive differ needs;
append_child is the reference == None tail case.Source§fn move_before(
&mut self,
parent: NodeId,
child: NodeId,
reference: Option<NodeId>,
)
fn move_before( &mut self, parent: NodeId, child: NodeId, reference: Option<NodeId>, )
child under parent before reference
(append when None), preserving subtree state — the Node.moveBefore()
contract (WHATWG DOM; docs/2026-07-05_movebefore_dom_standard_plan.md).
Records one DomMutation::Moved instead of the Removed + Inserted
pair insert_before produces for an in-tree node,
so consumers may keep the subtree’s retained state. A move resolving to
the current position records nothing; a disconnected child degrades to
a plain insert (the DOM-level moveBefore throws there; this layout-side
contract stays total, like insert_before’s bad-reference fallback).Source§fn set_attribute(&mut self, node: NodeId, name: QualName, value: &str)
fn set_attribute(&mut self, node: NodeId, name: QualName, value: &str)
Source§fn remove_attribute(&mut self, node: NodeId, name: QualName)
fn remove_attribute(&mut self, node: NodeId, name: QualName)
name from node (no-op if absent). Records
an DomMutation::AttributeChanged carrying the removed value as
old_value (the live DOM then reads as absent), so serval-layout builds
the Stylo snapshot the same way it does for a value change.Source§fn set_text(&mut self, node: NodeId, data: &str)
fn set_text(&mut self, node: NodeId, data: &str)
Source§fn set_inner_html(&mut self, node: NodeId, html: &str)
fn set_inner_html(&mut self, node: NodeId, html: &str)
node’s children with the subtree parsed from an HTML fragment
(the innerHTML setter). Records a single DomMutation::SubtreeReplaced.Source§fn drain_mutations(&mut self, out: &mut Vec<DomMutation<NodeId>>)
fn drain_mutations(&mut self, out: &mut Vec<DomMutation<NodeId>>)
out.
The provider records WHAT changed; serval-layout decides what to invalidate.Auto Trait Implementations§
impl Freeze for ScriptedDom
impl RefUnwindSafe for ScriptedDom
impl Send for ScriptedDom
impl Sync for ScriptedDom
impl Unpin for ScriptedDom
impl UnsafeUnpin for ScriptedDom
impl UnwindSafe for ScriptedDom
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more