Commit graph

1049 commits

Author SHA1 Message Date
Timothy Flynn
3dce6766a3 LibWeb: Extract some CORS and MIME Fetch helpers to their own files
An upcoming commit will migrate the contents of Headers.h/cpp to LibHTTP
for use outside of LibWeb. These CORS and MIME helpers depend on other
LibWeb facilities, however, so they cannot be moved.
2025-11-27 14:57:29 +01:00
Timothy Flynn
0fd80a8f99 LibTextCodec+LibWeb: Move isomorphic coders to LibTextCodec
This will be used outside of LibWeb.
2025-11-27 14:57:29 +01:00
Sam Atkins
a25cb679fb LibWeb/HTML: Update spec text related to template's content
Corresponds to:
aa52274b5a
2025-11-27 10:26:13 +00:00
Psychpsyo
693dd7b6f6 LibWeb: Avoid unnecessary sorting work when getting animations
This way, the list is not re-sorted on every recursive call.
2025-11-26 22:19:23 +01:00
Timothy Flynn
f675cfe90f LibWeb: Store HTTP methods and headers as ByteString
The spec declares these as a byte sequence, which we then implemented as
a ByteBuffer. This has become pretty awkward to deal with, as evidenced
by the plethora of `MUST(ByteBuffer::copy(...))` and `.bytes()` calls
everywhere inside Fetch. We would then treat the bytes as a string
anyways by wrapping them in StringView everywhere.

We now store these as a ByteString. This is more comfortable to deal
with, and we no longer need to continually copy underlying storage (as
ByteString is ref-counted).

This work is largely preparatory for an upcoming HTTP header refactor.
2025-11-26 09:15:06 -05:00
Prajjwal
50a79c6af8 LibWeb: Change SessionHistoryTraversalQueue to use Promises
If multiple cross-document navigations are queued on
SessionHistoryTraversalQueue, running the next entry before the current
document load is finished may result in a deadlock. If the new document
has a navigable element of its own, it will append steps to SHTQ and
hang in nested spin_until.
This change uses promises to ensure that the current document loads
before the next entry is executed.

Fixes timeouts in the imported tests.

Co-authored-by: Sam Atkins <sam@ladybird.org>
2025-11-26 12:27:12 +01:00
Sam Atkins
aac387bcc6 LibWeb/DOM: Copy "allow declarative shadow roots" to template document
This flag defaults to false for new Documents, such as the one created
here for use by template elements' contents. Without setting it to
true, nothing inside a template can have a declarative shadow dom.

As noted, this appears to be a spec issue. I am not convinced that this
is the correct fix, but it is simple and does solve the issue without
any apparent regressions.
2025-11-26 09:52:47 +01:00
Sam Atkins
91e73ecde1 LibWeb/DOM: Stop early-out of assigning slottables when root is a slot
This would happen for example when removing a slot element from the DOM,
in which case it would keep its old list of assigned slottables even
though it now has none. Fixes a couple of WPT tests.
2025-11-26 09:52:47 +01:00
Sam Atkins
4f4e94dc9c LibWeb/DOM: Update spec steps for Node::remove()
No behaviour changes.
2025-11-26 09:52:47 +01:00
Aliaksandr Kalenik
d1f34efa64 LibWeb: Avoid whole DOM traversal in document_tree_child_navigables()
Instead, iterate through all registered navigables and pick the ones
that belong to document's tree, preserving tree order.
2025-11-25 09:16:17 +01:00
Aliaksandr Kalenik
4c22c372a4 LibWeb: Avoid full DOM tree traversal in Window::named_objects()
Instead, take advantage of `ElementByIdMap` and
`m_potentially_named_elements` to gather elements with specified name
more efficiently.
2025-11-25 09:16:17 +01:00
Aliaksandr Kalenik
e80d1bcee7 LibWeb: Avoid full DOM tree traversal in supported_property_names()
Instead, take advantage of `ElementByIdMap` and
`m_potentially_named_elements` to gather named elements more
efficiently.
2025-11-25 09:16:17 +01:00
Jelle Raaijmakers
4cca341315 LibWeb: Remove broken spec link from MutationObserver
The link no longer works, and they are described as weak in the very
next comment as well.
2025-11-24 12:45:22 +00:00
Jelle Raaijmakers
e281e3a274 LibWeb: Move mutation observers from IntrusiveList to GC::RootVector
We need to prevent these mutation observers from being garbage
collected, and since they are only part of SimilarOriginWindowAgent and
themselves as part of the intrusive list, nobody is visiting them.

Make the list of pending mutation observers a GC::RootVector so we keep
them alive until they have been processed in the microtask.

Restores 1400+ WPT subtest passes in `dom/nodes/Element-classlist.html`.
2025-11-24 12:45:22 +00:00
Jelle Raaijmakers
405e270583 LibWeb: Skip namespaced attributes in Element::attribute_changed()
Fixes the `dom/nodes/getElementsByClassName-11.xml` WPT test, which can
be imported but unfortunately not run since it's not an .html file.

Co-authored-by: YTBuzzles <bentory15@proton.me>
2025-11-24 09:13:26 +01:00
Sam Atkins
e691f0e10f LibWeb/DOM: Stop adding duplicates to the agent's signal_slots
We use a Vector for this, but its spec definition is an ordered set.
That means we need to ensure we don't add duplicates. This fixes issues
where we would send slotchange events multiple times to the same
HTMLSlotElement.
2025-11-21 16:19:57 +01:00
Sam Atkins
6e17503423 LibWeb: Add and remove MutationObservers at specified times
In the current spec, MutationObservers are explicitly added to the
pending mutation observers list, and they are removed when that list is
cleared in the "notify mutation observers" microtask.

This solves some issues with slotchange events.

As noted, we delay actually emptying the list of pending mutation
observers until after we're finished with the "clone", because we can't
actually copy or move the intrusive list. As far as I am aware, this
should not affect behaviour because only one microtask can run at once.
2025-11-21 16:19:57 +01:00
Hendiadyoin1
bcd01da91d AK: Use Deducing this for OptionalBase
This is taken from and akin to
https://github.com/SerenityOS/serenity/pull/25894
2025-11-20 16:27:07 +01:00
Sam Atkins
29666e1d83 LibWeb/DOM: Invalidate children with relative font-weight/font-size
`font-weight` and `font-size` both can have keywords that are relative
to their inherited value, and so need recomputing when that changes.

Fixes all but one subtest in font-weight-computed.html, because that
remaining one uses container-query units. No font-size tests seem to be
affected: font-size-computed.html doesn't update the parent element's
`font-size` so this invalidation bug didn't apply.
2025-11-20 12:22:03 +01:00
Jelle Raaijmakers
41eb7251e4 LibWeb: Convert Ladybird notes in spec steps to // NB: ...
We have a couple of ways to designate spec notes and (our) developer
notes in comments, but we never really settled on a single approach. As
a result, we have a bit of a mixed bag of note comments on our hands.

To the extent that I could find them, I changed developer notes to
`// NB: ...` and changed spec notes to `// NOTE: ...`. The rationale for
this is that in most web specs, notes are prefixed by `NOTE: ...` so
this makes it easier to copy paste verbatim. The choice for `NB: ...` is
pretty arbitrary, but it makes it stand out from the regular spec notes
and it was already in wide use in our codebase.
2025-11-18 09:07:37 -05:00
Aliaksandr Kalenik
195a67ed80 LibWeb: Delete dead code from Node::append_child() 2025-11-17 23:59:27 +01:00
Andreas Kling
a94335dc5d LibWeb: Block rendering while waiting for CSS @import downloads
The implementation here is a ad-hoc, but there's no clear spec for
exactly how to handle "critical subresources" blocking rendering.

For now, this is overly conservative but fixes ugly FOUC on some
websites like https://hey.com/
2025-11-16 09:14:18 +01:00
Tim Ledbetter
36c6079dbc LibWeb+LibGfx: Implement SVGFEMorphologyElement
This filter primitive is used to erode or dilate an image.
2025-11-15 16:08:53 +01:00
Andreas Kling
66263f142b LibWeb: Add StyleScope to keep style caches per Document/ShadowRoot
Before this change, we've been maintaining various StyleComputer caches
at the document level.

This made sense for old-school documents without shadow trees, since
all the style information was document-wide anyway. However, documents
with many shadow trees ended up suffering since any time you mutated
a style sheet inside a shadow tree, *all* style caches for the entire
document would get invalidated.

This was particularly expensive on Reddit, which has tons of shadow
trees with their own style elements. Every time we'd create one of their
custom elements, we'd invalidate the document-level "rule cache" and
have to rebuild it, taking about ~60ms each time (ouch).

This commit introduces a new object called StyleScope.

Every Document and ShadowRoot has its own StyleScope. Rule caches etc
are moved from StyleComputer to StyleScope.

Rule cache invalidation now happens at StyleScope level. As an example,
rule cache rebuilds now take ~1ms on Reddit instead of ~60ms.

This is largely a mechanical change, moving things around, but there's
one key detail to be aware of: due to the :host selector, which works
across the shadow DOM boundary and reaches from inside a shadow tree out
into the light tree, there are various places where we have to check
both the shadow tree's StyleScope *and* the document-level StyleScope
in order to get all rules that may apply.
2025-11-14 22:05:33 +01:00
Psychpsyo
100f37995f Everywhere: Clean up AD-HOC and FIXME comments without colons 2025-11-13 15:56:04 +01:00
Lorenz A
3bc061d028 LibWeb: Allow all elements with tabindex attribute to be focusable 2025-11-12 13:57:05 +01:00
Tim Ledbetter
154e9db033 LibWeb: Cache the value of Element::lang()
This reduces the time spent in
`SelectorEngine::matches_lang_pseudo_class()` from 1.9% to 0.41% on
https://cloudflare.com
2025-11-12 12:36:16 +01:00
Callum Law
55afa9d37e LibWeb: Avoid unnecessary work when element display property changes
`play_or_cancel_animations_after_display_property_change` is called
whenever an element is inserted or removed, or it's display property
changes, but it is only required to run if we actually have animations
to play or cancel.

Reduces time spent in the aforementioned function from ~2% to ~0.03%
when loading https://en.wikipedia.org/wiki/2023_in_American_television
2025-11-11 08:35:39 +00:00
Tim Ledbetter
61af399b50 LibWeb: Remove unnecessary lowercase name property from Attr 2025-11-10 22:55:38 +01:00
Psychpsyo
b7a71ca950 LibWeb: Correctly sort animations returned by getAnimations() 2025-11-10 18:29:07 +01:00
Andreas Kling
0dacc94edd LibJS: Have JS::Lexer take a JS::SourceCode as input
This moves the responsibility of setting up a SourceCode object to the
users of JS::Lexer.

This means Lexer and Parser are free to use string views into the
SourceCode internally while working.

It also means Lexer no longer has to think about anything other than
UTF-16 (or ASCII) inputs. So the unit test for parsing various invalid
UTF-8 sequences is deleted here.
2025-11-09 12:14:03 +01:00
Jelle Raaijmakers
70e98e72a8 LibWeb: Add SVGFEFunc{A,B,G,R}Element 2025-11-09 01:22:48 +01:00
Jelle Raaijmakers
03a8de566b LibWeb: Add SVGFEComponentTransferElement 2025-11-09 01:22:48 +01:00
Andreas Kling
b28480f62d LibWeb: Propagate layout tree update in display: contents to parent
When an element has `display: contents` and it gets marked for a layout
tree rebuild, we actually have to mark its parent for rebuild as well.

The structure of the parent (and siblings) may change depending on how
the `display: contents` element changes (e.g position, display, etc.)
2025-11-08 11:20:32 +01:00
Jelle Raaijmakers
b6f5c91a35 LibWeb: Shave 168 bytes off of ARIAMixin
Instead of keeping the vectors inside ARIAMixin, point to the heap using
OwnPtrs.
2025-11-07 16:59:26 +01:00
Jelle Raaijmakers
9d26626200 LibWeb: Shave 24 bytes off of each DOM::Element 2025-11-07 16:59:26 +01:00
Luke Wilde
167de08c81 LibWeb: Remove exception throwing from Fetch
These were only here to manage OOMs, but there's not really any way to
recover from small OOMs in Fetch especially with its async nature.
2025-11-07 04:08:30 +01:00
Luke Wilde
82bd3d3891 LibWeb: Avoid invoking Trusted Types where avoidable
Prevents observably calling Trusted Types, which can run arbitrary JS,
cause crashes due to use of MUST and allow arbitrary JS to modify
internal elements.
2025-11-06 11:43:06 -05:00
Luke Wilde
fb9406ddcd LibWeb: Make Trusted Types injection sink names more readable
No functional change.
2025-11-06 11:43:06 -05:00
Callum Law
a95cde3660 LibWeb: Separate CSSAnimation::animationName from Animation::id 2025-11-02 23:54:00 +01:00
Callum Law
56e2ac8a9d LibWeb: Always do parent document layout updates before updating style
We were doing this manually within `Document::update_layout()` and
`CSSStyleProperties::get_direct_property()` but we should do it for all
callers of `Document::update_style()`
2025-11-02 23:54:00 +01:00
Tim Ledbetter
9da723b5c6 LibWeb: Ensure layout is up to date before resolving canvas colors 2025-10-27 16:56:01 -07:00
Tete17
33285467a8 LibWeb: Amend ShadowRoot to make it compatible with TrustedTypes 2025-10-27 16:14:20 +00:00
Tete17
db41ea8117 LibWeb: Amend Element interface to make it compatible with TrustedTypes 2025-10-27 16:14:20 +00:00
Tete17
1368744d33 LibWeb: Amend Document interface to make it compatible with TrustedTypes 2025-10-27 16:14:20 +00:00
Tete17
2fa84f1683 LibWeb: Properly propagate errors for Node set_text_content
This function was supposed to throw errors even before the TrustedTypes
spec thanks to the CharacterData replaceData call but had a MUST.

This changes this to ensure this function can throw an error
2025-10-27 16:14:20 +00:00
Tete17
887537b061 LibWeb: Implement TrustedTypes spec for set_value on Attribute 2025-10-27 16:14:20 +00:00
Tete17
e2adce84e7 LibWeb: Implement TrustedTypes spec for the concept of set_attribute_ns 2025-10-27 16:14:20 +00:00
Tete17
4b00a61479 LibWeb: Implement TrustedTypes spec for the concept of set_attribute 2025-10-27 16:14:20 +00:00
Tete17
df543cf31a LibWeb: Implement TrustedTypes spec for set_attribute on Element
This part of the spec is still under a PR in GitHub, but it should be
safe to implement like it is.
2025-10-27 16:14:20 +00:00