Commit graph

717 commits

Author SHA1 Message Date
Ali Mohammad Pur
eea81738cd AK+Everywhere: Recognise that surrogates in utf16 aren't all that common
For the slight cost of counting code points when converting between
encodings and a teeny bit of memory, this commit adds a fast path for
all-happy utf-16 substrings and code point operations.

This seems to be a significant chunk of time spent in many regex
benchmarks.
2025-04-23 07:56:02 -06:00
Andreas Kling
1242b9152e LibWeb: Turn Element.scroll(0, 0) into a no-op when possible
For unscrolled elements (already at 0, 0) that aren't eligible to be the
Document.scrollingElement, we can short-circuit here and avoid doing a
synchronous relayout of the page.

This avoids a bunch of synchronous layouts on Speedometer3's NewsSite
subtests.
2025-04-22 12:09:42 +02:00
Andreas Kling
545ed08519 LibWeb: Add debug logging of reasons for layout tree update
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
2025-04-21 00:31:08 +02:00
Andreas Kling
fa9c463ffd LibWeb: Allow anonymous layout boxes to keep their intrinsic size cache
Instead of indiscriminately clearing the cache for all anonymous boxes,
we now only clear it for those that were generated by a non-anonymous
box in need of layout update.

This increases the cache hit rate and allows us to avoid more work.
2025-04-21 00:31:08 +02:00
Andreas Kling
3c15fec303 LibWeb: Move "needs layout update" flag from DOM to layout tree
This is in preparation for allowing anonymous boxes to retain their
intrinsic size cache across layouts.
2025-04-21 00:31:08 +02:00
Andreas Kling
a122685896 LibWeb: Don't look for animations to activate in disconnected subtrees
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Knocks down a 3.3% profile item to 1.6% on Speedometer 3.
2025-04-20 18:43:11 +02:00
Andreas Kling
a6dfc74e93 LibWeb: Only set prototype once for object with IDL interface
Before this change, we were going through the chain of base classes for
each IDL interface object and having them set the prototype to their
prototype.

Instead of doing that, reorder things so that we set the right prototype
immediately in Foo::initialize(), and then don't bother in all the base
class overrides.

This knocks off a ~1% profile item on Speedometer 3.
2025-04-20 18:43:11 +02:00
Andreas Kling
7884e58b5c LibWeb: Make Element::html_uppercased_qualified_name() lazy
Many elements never end up needing this string, so instead of eagerly
generating it in the Element constructor, let's defer it until someone
actually requests it.

Knocks off a ~1% profile item on Speedometer3's jQuery test.
2025-04-20 18:43:11 +02:00
Andreas Kling
94cc4adefd LibWeb: Create Element::attributes (NamedNodeMap) lazily
Many elements have zero attributes, and they don't need a NamedNodeMap
until someone asks for it.
2025-04-20 18:43:11 +02:00
Andreas Kling
0c0650e60a LibWeb: Implement more of the "script-blocking style sheet" mechanism
The basic idea is that style sheets can block script execution under
some circumstances. With this commit, we now handle the simplest cases
where a parser-inserted link element gets to download its style sheet
before script execution continues.

This improves performance on Speedometer 3 where JavaScript APIs that
depend on layout results (like Element.scrollIntoView()) would get
called too early (before the relevant CSS was downloaded), and so we'd
perform premature layout work. This work then had to be redone after
downloading the CSS anyway, wasting time.

Note that our Text/input/link-re-enable-crash.html test had to be
tweaked after these changes, since it relied on the old, incorrect,
behavior where scripts would run before downloading CSS.
2025-04-20 14:54:21 +02:00
Andreas Kling
28d564197c LibWeb: Compute containing block boxes once at start of layout
We now cache the containing block (box) once at the start of layout,
which allows Layout::Node::containing_block() to return instantly
instead of doing tree traversal.

Removes a 0.7% profile item on Speedometer 3.
2025-04-19 01:14:02 +02:00
Andreas Kling
bbef0e8375 LibWeb: Avoid dynamic_cast in DOM::Document::is_decoded_svg() 2025-04-18 14:45:56 +02:00
Andreas Kling
d8188c9f14 LibJS+LibWeb: Add JS::Object::fast_is<T> helpers for some LibWeb types
These are slightly unfortunate as we're crossing the library boundary,
but there's precedent with Object::is_dom_node(), and these are just
knocking down a few more items that were showing up in profiles.
2025-04-18 14:45:56 +02:00
Andreas Kling
aecb144df0 LibWeb: Add more fast_is<T> helpers for DOM::Node subclasses 2025-04-18 14:45:56 +02:00
Andreas Kling
e7b6b84648 LibWeb: Avoid dynamic_cast in EventTarget initialization
Let's use a virtual to tell if something uses the
WindowOrWorkerGlobalScope mixin instead.
2025-04-18 14:45:56 +02:00
Glenn Skrzypczak
c0cbd439a2 LibWeb/HTML: Dispatch command events
Command events are now dispatched when buttons are activated. The
special commands for popovers and dialogs are also implemented.
2025-04-18 12:09:57 +01:00
Sam Atkins
141f6cb392 LibWeb/HTML: Use relevant global object's document in History
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Corresponds to dba6e7b6c2
and 4c0401186c

The spec algorithms now use "the relevant global object's associated
document", so remove the concept of the History object itself having an
associated document. The spec has also combined the implementations for
forward/back/go so I've matched that too.
2025-04-18 10:49:56 +02:00
Sam Atkins
343df5d00f LibWeb: Update focus-related spec text
Corresponds to 03ab71775b

I've also split the `Document::has_focus()` method for clarity. Actually
implementing the "has focus steps" turns out to be quite involved so
I've left it for now.
2025-04-18 10:49:56 +02:00
Sam Atkins
609d568776 LibWeb: Remove "locked for focus" concept
Corresponds to 5ba23f9f6d
2025-04-18 10:49:56 +02:00
Shannon Booth
3e17b1c9ae LibWeb: Make Node::parent_element return GC::Ptr
This is useful for people like myself who run with debug mode to
more reliably get stacktraces without spinning up a debugger.
2025-04-18 10:49:02 +02:00
Shannon Booth
a14481ee05 LibWeb/HTML: Handle no parent element for Element::list_owner
Fixes a crash when running Speedometer 3.0 as reduced in the included
test case.
2025-04-18 10:48:47 +02:00
Andreas Kling
8d51c41a42 LibWeb: Remove no-longer-used StyleInvalidationReasons :^) 2025-04-17 19:45:55 +02:00
Andreas Kling
55ab8ff539 LibWeb: Use optimized invalidation for :active pseudo class 2025-04-17 19:45:55 +02:00
Andreas Kling
6da48c60ca LibWeb: Use optimized invalidation for target-related pseudo classes 2025-04-17 19:45:55 +02:00
Andreas Kling
414e0cc930 LibWeb: Use optimized invalidation for focus-related pseudo classes 2025-04-17 19:45:55 +02:00
Andreas Kling
e1777f6e79 LibWeb: Make :hover invalidation logic reusable for all pseudo classes
We achieve this by keeping track of all checked pseudo class selectors
in the SelectorEngine code. We also give StyleComputer per-pseudo-class
rule caches.
2025-04-17 19:45:55 +02:00
Timothy Flynn
6dd2a4c945 LibWeb: Do not create a RootVector to invoke IDL callbacks
These callbacks are evaluated synchronously via JS::Call. We do not need
to construct an expensive RootVector container just to immediately
invoke the callbacks.

Stylistically, this also helps indicate where the actual arguments start
at the call sites, by wrapping the arguments in braces.
2025-04-16 07:32:02 -04:00
Sam Atkins
2a96a81e68 LibWeb: Move style sheet parsing into create_a_css_style_sheet()
The spec is unclear about when exactly we should parse the style sheet.
Previously we'd do so before calling this algorithm, which was
error-prone, as seen by the bug fixed by the previous commit. The spec
for step 1 of "create a CSS style sheet" says:

1. Create a new CSS style sheet object and set its properties as
   specified.

The definitions linked are UA-defined enough that it seems reasonable to
put the parsing here. That simplifies the user code a little and makes
it harder to mess up. It does raise the question of what to do if
parsing fails. I've matched our previous behaviour by just logging and
returning in that case.

While I'm modifying this method, I've also converted the bool params to
enums so they're a little clearer to read.
2025-04-15 09:40:38 +01:00
Aliaksandr Kalenik
3e1d718b7f LibWeb: Ignore boxes without layout node in intersection observer steps
Check if box has associated layout node is not mentioned in the spec,
but it is required to match behavior of other browsers that do not
invoke intersection observer steps for boxes without layout node.
2025-04-14 17:01:53 +02:00
Sam Atkins
6ff2324f26 LibWeb/DOM: Actually stub out pointer-capture API
For real this time.

This makes panning the KendoReact map widget actually work:
https://www.telerik.com/kendo-react-ui/components/map
2025-04-14 12:55:44 +02:00
Simon Farre
55483b0096 LibWeb: Set user activation when this is Document
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
EventTarget::dispatch_event, per comments, does ad-hoc solution for UA,
and I don't know why it checks if `this` is window or `element`, but
web platform tests would fail, because `this` would actually be a
`Document` type.
2025-04-13 10:36:31 -06:00
Simon Farre
87f6a11e47 LibWeb: Add user activation for pointerdown/up
Fixed FIXME's for pointerdown and pointerup events.
2025-04-13 10:36:31 -06:00
Andreas Kling
e068ff5a5d LibWeb: Always store ComputedProperties, even if no invalidations
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Before this change, we'd skip storing the new ComputedProperties in
Element::recompute_style() if there was no invalidation needed.

This caused us to lose the information about which properties are
inherited and/or important (which is also carried by ComputedProperties,
but doesn't affect invalidation).

Consequently, we'd then fail to recompute inherited styles, since that
mechanism depends on this data.

The fix is simply to always store the new ComputedProperties.
2025-04-13 00:43:49 +02:00
Andreas Kling
2aa6d7636c LibWeb: Invalidate sheet owners after mutating cssText of its rules
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This fixes one source of flakiness on WPT (of many) where we wouldn't
recompute style after programmatically altering the contents of a style
sheet, but instead had to wait for something else to cause invalidation.
2025-04-12 14:15:57 +01:00
Aliaksandr Kalenik
6507d23e29 LibWeb: Save ScrollState snapshot in DisplayList to avoid race condition
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
With this change we save a copy of of scroll state at the time of
recording a display list, instead of actual ScrollState pointer that
could be modifed by the main thread while display list is beings
rasterized on the rendering thread, which leads to a frame painted with
inconsistent scroll state.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/4288
2025-04-12 02:55:18 +02:00
Sam Atkins
11b6bd8138 LibWeb/DOM: Stub out Element pointerevents methods 2025-04-11 21:27:13 +01:00
Timothy Flynn
4010c4643a LibWeb: Support removing callbacks from AbortSignal
This will be needed by Streams. To support this, we now store callbacks
in a hash table, keyed by an ID. Callers may use that ID to remove the
callback at a later point.
2025-04-11 12:10:46 -04:00
Sam Atkins
9dbeecb73d LibWeb: Correct some spec typos
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Corresponds to 285a58bf30
2025-04-10 04:01:37 +02:00
Andreas Kling
6bd2cf3195 LibWeb: Make Document::m_shadow_roots an IntrusiveList
This makes unregistering a ShadowRoot O(1) instead of O(n) and erases
a 2.2% item entirely from the Speedometer 2.1 profile.
2025-04-10 04:01:00 +02:00
Andreas Kling
938b1e91fe LibJS: Inline the fast path of Value::to_i32() and simplify to_u32()
The fast path of to_i32() can be neatly inlined everywhere, and we still
have to_i32_slow_case() for non-trivial conversions.

For to_u32(), it really can just be implemented as a static cast to i32!
2025-04-09 22:06:49 +02:00
Sam Atkins
a8ab4d64c4 LibWeb/DOM: Use document's URL as location for inline stylesheets
This is ad-hoc, and the spec doesn't seem to tell us what to actually do
here. Without this, following the spec steps for loading relative
`@import` URLs from a `<style>` tag always fails, because that uses the
parent style sheet's location as the base URL.
2025-04-09 18:45:57 +01:00
Sam Atkins
da1ff1ba40 LibWeb/CSS: Store CSSStyleSheet location as a URL
We already have a URL when we construct these, and we want a URL later,
so avoid serializing and re-parsing it.
2025-04-09 18:45:57 +01:00
Gingeh
4b9f5c6fb8 LibWeb: Generate ::backdrop pseudo-elements 2025-04-09 12:10:42 +01:00
Timothy Flynn
f070264800 Everywhere: Remove sv suffix from format string literals
This prevents the compile-time checks that would catch errors in the
format invocation (which would usually lead to a runtime crash).
2025-04-08 20:00:18 -04:00
Timothy Flynn
0a256b0a9a AK+Everywhere: Change StringView case conversions to return String
There's a bit of a UTF-8 assumption with this change. But nearly every
caller of these methods were immediately creating a String from the
resulting ByteString anyways.
2025-04-07 17:44:38 +02:00
Viktor Szépe
b4b8d85251 LibWeb+LibJS+Tests: Fix typos - act I 2025-04-07 11:22:13 +01:00
Aliaksandr Kalenik
d5edd62e57 LibWeb: Limit usage of getElementById() cache to connected roots
Fixes bug when we always return null from getElementById() on
unconnected roots because id to element cache is only maintained for
connected roots.

Fixes broken Perf-Dashboard suite in Speedometer 3.
2025-04-06 04:14:29 +02:00
Andreas Kling
de424d6879 LibJS: Make Completion.[[Value]] non-optional
Instead, just use js_undefined() whenever the [[Value]] field is unused.
This avoids a whole bunch of presence checks.
2025-04-05 11:20:26 +02:00
Andrew Kaster
8fd81c3338 LibGC+LibWeb+LibJS: Remove workaround for Swift boolean bitfield issue
We're using a main snapshot everywhere, so we can yeet the workaround.
2025-04-04 13:06:53 -06:00
Andrew Kaster
e4c88915ab LibGC+LibJS+LibWeb: Add workaround for Swift boolean bitfield issue
This patch adds a workaround for a Swift issue where boolean bitfields
with getters and setters in SWIFT_UNSAFE_REFERENCE types are improperly
imported, causing an ICE.
2025-04-03 16:47:48 -06:00