Script: Lazily transform the DOMString into Rust String instead of immediately. (#39509)

This implements LazyDOMString (from now on DOMString) as outlined in
https://github.com/servo/servo/issues/39479.
Constructing from a *mut JSString we keep the in a
RootedTraceableBox<Heap<*mut JSString>> and transform
the string into a rust string if necessary via the `make_rust_string`
method.
Methods used in script are implemented on this string. Currently we
transform the string at all times.
But in the future more efficient implementations are possible.

We implement the safety critical sections in a separate module
DOMStringInner which allows simple constructors, `make_rust_string` and
the `bytes` method.
This method returns the new type `EncodedBytes` which contains the
reference to the underlying string in either format.

Testing: WPT tests still seem to work, so this should test this
functionality.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This commit is contained in:
Narfinger
2025-10-09 20:18:03 +02:00
committed by GitHub
parent ef9f16027b
commit 423800eec4
101 changed files with 1098 additions and 633 deletions

View File

@@ -255,7 +255,7 @@ pub(crate) fn handle_get_stylesheet_style(
.filter_map(move |i| {
let rule = list.Item(i, can_gc)?;
let style = rule.downcast::<CSSStyleRule>()?;
if *selector != style.SelectorText() {
if selector != style.SelectorText() {
return None;
};
Some(style.Style(can_gc))