100 Commits
Author SHA1 Message Date
Andreas Kling 15c4a2431c LibWeb: Allow intrinsic size keywords for min-height and max-height
Serenity note: Test expectations were rebaseline'd.

(cherry picked from commit c5a54f1166e6f05277c8fae2e4b6a33346de2671)
2026-09-20 20:01:55 -04:00
Andreas Kling 2381771cc3 LibWeb: Disallow none for min-width and min-height
Serenity note: Test expectations were rebaseline'd.

(cherry picked from commit 5a9d538acc4fbea47a38def5769167a923f9f947)
2026-09-20 20:01:55 -04:00
Andreas Kling 2ddd89aa64 Tests: Import WPT tests from /css/css-sizing/parsing
Serenity note: Test expectations were rebaseline'd.

(cherry picked from commit ce6a7ba05095ef936cc8b00359b4b6a886db0c82)
2026-09-20 20:01:55 -04:00
Andreas Kling 7170e376d8 Tests: Don't print full error messages in imported WPT tests
...when running in test mode. This cuts down on the time it takes to run
the imported WPT tests, and you can still get the full error by opening
tests in the browser.

(cherry picked from commit 0ebdac0b35179376858638f0e8f47faa586dd0bc)
2026-09-17 10:39:03 -04:00
Andreas Kling 8b55754eab headless-browser: Allow overriding the test timeout with a CLI parameter
Also bump the test timeout when running ctest to 120 seconds,
to accommodate the slow GCC CI.

(cherry picked from commit be03002780d3b7d2e3e0e38c2139361aa5fb718a)
2026-09-17 10:39:03 -04:00
Andreas Kling 313c89a9ea LibWeb: Implement HTMLElement.innerText closer to spec
And here's the wild part: instead of cloning WPT tests, import the
relevant WPT tests that this fixes into our own test suite.

This works by adding a small Ladybird-specific callback in
resources/testharnessreport.js (which is what that file is meant for!)

Note that these run as text tests, and so they must signal the runner
when they are done. Tests using the "usual" WPT harness should just
work, but tests that do something more freestyle will need manual
signaling if they are to be imported.

I've also increased the test timeout here from 30 to 60 seconds,
to accommodate the larger WPT-style tests.

(cherry picked from commit ec0838b84eb662b715b79141ea983339569644d3)
2026-09-17 10:39:03 -04:00
Andreas Kling 1d3f09aaec UI/AppKit: Override deferred_invoke() to signal CFRunLoopSource
The base class deferred_invoke() adds work to the thread event queue
and calls wake(), but that's not sufficient for CFRunLoop. We also
need to signal the deferred_source via CFRunLoopSourceSignal() so the
run loop knows to call its perform callback which processes the queue.

Without this signal, deferred invocations posted from other threads
(such as IPC I/O threads) would not be processed, causing deadlocks
when waiting for sync IPC responses.

(cherry-picked from commit 367296fce6cb0cc524c48730f74a24cc8adb3c40)
2026-06-29 10:07:38 -04:00
Andreas Kling b262ca13c9 UI/AppKit: Fix wake() to use the correct run loop
wake() was using CFRunLoopGetCurrent() which returns the calling
thread's run loop. When called from an I/O thread to wake the main
thread's event loop, this would wake the wrong run loop.

Fixed by using the stored m_impl->run_loop which is captured at
construction time and refers to the event loop's owning thread.

(cherry-picked from commit da77c803c17015fa87254f85ae2da8a48b9ab071)
2026-06-29 10:07:38 -04:00
Andreas Kling 8f88beb00c LibCore: Don't require heap-allocated event to hold deferred invocation
Instead of creating a DeferredInvocationEvent every time we
deferred_invoke, we now let the QueuedEvent store the invokee Function
object directly.

(cherry-picked from commit 2a1c5dc108697a5f3722432c0c1ec51a8e94a3e6)
2026-06-29 10:07:38 -04:00
Andreas Kling 3de118dc9d LibCore: Allow posting stateless events without heap-allocated Event
This patch adds an API for posting a Core::Event::Type to the thread
event queue without requiring a full Core::Event object.

We use this API to avoid heap allocations for every timer and notifier
activation event.

(cherry-picked from commit 69515f8c8548fe35f1bb08fcc5a1d9e851b6e675)
2026-06-29 10:07:38 -04:00
Andreas Kling 64eff8f658 LibCore: Fix memory leak in anon_create() on BSD/macOS
The mmap() call here served no purpose - anon_create() is only meant to
create and return a file descriptor. The actual mapping is done later
by AnonymousBufferImpl::create().

This leaked an mmap of `size` bytes for every AnonymousBuffer created,
which includes backing stores, shareable bitmaps, and more.

(cherry picked from commit 07630f3b0c4e08771a75edcc68ab3fdbc8948b2f)
2026-01-22 19:55:50 -05:00
Andreas Kling 239dde10f4 LibWeb: Propagate text-decoration-* properties to anonymous wrappers
Fixes an issue where old prices were not displayed with strike-through
text on the PlayStation store. :^)

(cherry picked from commit 8a6c8a1c272f67cd4ba34ef55b9ac8b6a50f9102)
2025-10-29 12:55:26 -07:00
Andreas Kling 45226c1115 LibIPC: Remove unused AK::Formatter for IPC::Connection
(cherry picked from commit cf0912c700486272060f376146f53b62cd877e99)
2025-10-29 12:55:26 -07:00
Andreas Kling 02fd716e36 LibIPC: Move stuff from Connection.h to .cpp and reduce #include count
(cherry picked from commit 4fe21e6d87259718f2d2a727a479e780963d76f4;
amended to add missing includes to various serenity components)
2025-10-29 12:55:26 -07:00
Andreas Kling 8fb4aac9d7 LibIPC: Move more of Connection::try_parse_messages() to ConnectionBase
By moving this up to ConnectionBase, we have less custom code for each
templated subclass, and it gets a little easier to edit the code since
you don't have to rebuild as much when making changes.

(cherry picked from commit 6d9c4d852d100194a9e53dcbc063ccb9d3f650a5)
2025-10-29 12:55:26 -07:00
Andreas Kling 9e6666237b LibGfx: Don't try to paint glyphs that aren't in a font
Fixes https://github.com/LadybirdBrowser/ladybird/issues/88

(cherry picked from commit fbc42e7d4282053414c7cf85a3ef7a74e07f4d46;
amended to handle bitmap fonts)
2025-10-24 19:10:49 -04:00
Andreas Kling 4810f037a8 Ladybird/AppKit: Use sRGB color space when blitting web content
Before this change, we were passing CGColorSpaceCreateDeviceRGB() to
CGImageCreate(), causing the system to assume that the image data is
in a device-specific RGB space without any color profile adjustments.

If your monitor is more vibrant than the assumed profile (for example,
a wide-gamut display), colors may appear over-saturated as there's no
correction applied for how the display actually renders those colors.

We now pass CGColorSpaceCreateWithName(kCGColorSpaceSRGB) instead,
which makes colors look the same in Ladybird as in other browsers. :^)

(cherry picked from commit 7cf7a4d7aace1694a3e3a2a9405ffdf5a034efb4)
2025-05-23 20:50:43 -04:00
Andreas Kling 6987a6e646 LibJS: Allocate RegExp.{lastMatch,leftContext,rightContext} lazily
These properties are always substrings of the RegExp input string,
and so we can store them as views and lazily construct strings if
they're actually accessed (which most of the time they aren't).

This avoids a bunch of unnecessary memory copying, saving roughly
2.1 seconds per iteration of Speedometer.

(cherry picked from commit dbf52a1b5fa9d7e81816ffc6c5a587c832148bd8)
2025-02-08 20:52:01 -05:00
Andreas Kling 073b3b992d AK: Make String::number() infallible
This API will always succeed in creating a String representing the
provided number in base-10.

(cherry picked from commit dd419b5a8df3b9a32478c4a8f0ea9f70334214cd;
amended to update the rest of the system. No conflicts though!)
2024-11-29 16:03:30 -05:00
Andreas Kling a8e73f3d9f LibWeb: Remove unnecessary use of TRY_OR_THROW_OOM in XMLHttpRequest
(cherry picked from commit 279d229f71b52e1fd91100a74aa314c90db968da)
2024-11-28 22:42:14 -05:00
Andreas Kling 3b60d2af5b LibWeb: Make XMLHttpRequests functions related to MimeType infallible
(cherry picked from commit fa1c5a3e85e5d479b3ce4975b06b271a67df0be5)
2024-11-28 22:42:14 -05:00
Andreas Kling e85f364f52 LibWeb: Make MimeSniff::Resource::sniff() infallible
Everyone was already using this API as if it were infallible anyway.

(cherry picked from commit 600cb5ccbaba019954f17c7d317ba6fe54a24117;
amended to fix another conflict in StyleComputer.cpp due to serenity
still not having the third commit of LadybirdBrowser/ladybird#1278)
2024-11-28 22:42:14 -05:00
Andreas Kling cf0516b616 LibWeb: Make MimeSniff::MimeType::parse() infallible
It already returns an empty Optional for failures, so there's no need to
wrap it in an ErrorOr as well.

(cherry picked from commit 5c20bc2afc23b04ccd8037d414592e4ee841a053;
amended to fix conflict in StyleComputer.cpp due to serenity not having
the third commit of LadybirdBrowser/ladybird#1278)
2024-11-28 22:42:14 -05:00
Andreas Kling d8c9ff6c09 LibWeb: Make more MimeSniff::MimeType APIs infallible
(cherry picked from commit 88e7688940ceae92263b410dfb1722311ae27aee)
2024-11-28 22:42:14 -05:00
Andreas Kling d4abeba027 LibWeb: Make MimeSniff::MimeType::create() infallible
(cherry picked from commit 9a8db40a239e3641bba138d6ec6c564c0cc0e2c5)
2024-11-28 22:42:14 -05:00
Andreas Kling 3fe7d96fa7 LibWeb: Support Document.onvisibilitychange
We don't have a way to trigger this from a test, but the fix is so
simple that we might as well get it in. :^)

(cherry picked from commit 274411db9756a9dffe44e21b4da09c7808e9f465)
2024-11-28 21:31:42 -05:00
Andreas Kling a5e6fd3b5f LibWeb: Support Document.onreadystatechange
This is just a standard IDL event attribute handler.

Fixes at least one WPT test:
https://wpt.live/html/dom/documents/resource-metadata-management/document-readyState.html

(cherry picked from commit 26be8f865ab6bba8e1b2f9f071c0949bcfaca512)
2024-11-28 21:31:42 -05:00
Andreas Kling 04474ef84a LibWeb: Bail from various navigable operations when no active window
If we end up in a situation where the navigable no longer has an active
window, we can't perform navigation or many other navigable operations.

These are all ad-hoc, since the navigables spec is basically all written
as if there's always an active window. Unfortunately, the active window
comes from the active document's browsing context, which is a nullable
concept even in the spec, so we do need to deal with null here.

This removes all the locally reproducible crashes when running WPT over
the legacy Japanese encoding directory on my computer.

Yes, this is a bit of a monkey patch, but it should be harmless since
we're (as I understand it) dealing with navigables that are still
hanging around with related tasks queued on them. Once all these tasks
have been completed, the navigables will go away anyway.

(cherry picked from commit aae191aa33c88edba97f872707a5d0f9705cb0aa)
2024-11-28 21:31:42 -05:00
Andreas Kling 48d994839c LibWeb: Don't swallow args when forwarding cross-origin WindowProxy call
Fixes at least one WPT test that was previously timing out:
- html/semantics/document-metadata/the-base-element/base_target_does_not_affect_iframe_src_navigation.html

(cherry picked from commit 0b403d30d765ab8e5db3b7443ebeca7f85c3acf2)
2024-11-25 08:50:54 -05:00
Andreas Kling f1997d0f87 LibWeb: Allow intrinsic width layout to see definite heights
We were already allowing intrinsic height layout to see definite widths,
and I can't think of a reason *not* to allow it the other way around.

More importantly, this fixes an issue where things with an aspect ratio
didn't have a height to resolve against before.

Makes the logo show up on https://basecamp.com/ :^)

(cherry picked from commit 077bc68a4cbf2d8c97abc818515a22471da42c99)
2024-11-24 00:18:58 -05:00
Andreas Kling 303ec1c8a3 LibWeb: Don't let input element placeholders influence line-height
Before this change, we transferred the input element's line-height to
both the editable text *and* the placeholder. This caused some strange
doubling of the effective line-height when the editable text was empty,
pushing down the placeholder.

(cherry picked from commit 13ba491924c4fc3831d5a8986673d832a721f545;
amended some slighly different horizontal sizes in the expectations
file. Maybe due to serenity not using harfbuzz for shaping, or due
to not have another earlier change yet. If it's the latter, this will
fix itself when that's brought in.)
2024-11-23 23:48:34 -05:00
Andreas Kling 9b4db4a0e0 LibWeb: Make DOMException take error message as a String
There was no need to use FlyString for error messages, and it just
caused a bunch of churn since these strings typically only existed
during the lifetime of the error.

(cherry picked from commit 175f3febb8037a440d4ead7347d3266ee3d345e1;
minorly amended to fix conflict in WebSocket.cpp due to serenity
not having the adapter class removal in LadybirdBrowser/ladybird#1671)
2024-11-22 11:13:42 -05:00
Andreas Kling 8c1596ca62 Meta: Ignore LibWeb text tests for newline-at-eof check
(cherry picked from commit 85bf1d6033c6de3de4761e18e0b0992a8814d705)
2024-11-21 22:16:48 -05:00
Andreas Kling 57b3a20bd0 Tests: Import LICENSE.md from WPT
(cherry picked from commit d78c81a9fdcd065c1a4905bd5f0176c3cb640d9e)
2024-11-21 22:16:48 -05:00
Andreas Kling a65b5cb135 LibWeb: Mark image elements for layout before firing their load event
This removes a long-standing source of flakiness seen for example in
WPT's /referrer-policy/ tests.

(cherry picked from commit 063cd68bf472061ec35cf9b8970aa6e614632c9b)
2024-11-20 22:51:34 -05:00
Andreas Kling e1ba881587 AK+LibWeb: Add {Fly,}String::to_ascii_{upper,lower}_case()
These don't have to worry about the input not being valid UTF-8 and
so can be infallible (and can even return self if no changes needed.)

We use this instead of Infra::to_ascii_{upper,lower}_case in LibWeb.

(cherry picked from commit 073bcfd3866852a4c4bcca2bd131bd65ae53541f)
2024-11-18 20:22:45 -05:00
Andreas Kling abf9980ea1 LibWeb: Make SVGImageElement part of CanvasImageSource union
This is very janky at the moment but it also more correct. :^)

(cherry picked from commit cd0e4a49b8a758aca847ceaf57eec0a62cd7b687;
amended to add a missing include of LibGfx/ImmutableBitmap.h to
SVGImageElement.h that ladybird seems to get transitively somehow)
2024-11-17 16:48:43 -05:00
Andreas Kling afbb213552 LibWeb: Fail CSS color parse for "rgba(123, 123, 123, "
This matches the behavior of other browsers and fixes a WPT test.

(cherry picked from commit 902586a21de3ef8335e447053d82057c4c927d72;
amended expected output because serenity does not yet have
LadybirdBrowser/ladybird#1603)
2024-11-17 16:48:43 -05:00
Andreas Kling 0b5719685d LibWeb+LibGfx: Serialize HTML canvas fill/strokeStyle colors correctly
Before this change we were serializing them in a bogus 8-digit hex color
format that isn't actually recognized by HTML.

This code will need more work when we start supporting color spaces
other than sRGB.

(cherry picked from commit 4590c081c2eb257232463ed660498a02f9bbe7b8;
amended expected output because serenity does not yet have
LadybirdBrowser/ladybird#1603)
2024-11-17 16:48:43 -05:00
Andreas Kling bfbf4474ca LibWeb: Make Selection APIs throw on DocumentType node inputs
This matches the behavior of all major engines, and is covered by
hundreds of subtests in WPT.

Spec PR: https://github.com/w3c/selection-api/pull/342

(cherry picked from commit 13bd52249d3fe674b8c11049eb66a305e058ee6f)
2024-11-17 14:44:11 -05:00
Andreas Kling 2c5f7ad8e4 LibWeb: Use a HashTable when querying SessionHistoryTraversalQueue
Instead of asking "do you have an entry not in this Vector", let's ask
"do you have an entry not in this HashTable".

(cherry picked from commit 861d46be3e69aeb1ca4a9e75029b4ce653bbcf47)
2024-11-17 13:47:42 -05:00
Andreas Kling 23fd706ea9 LibWeb: Fire navigation event as required in History.pushState()
(cherry picked from commit a1519e67fb7a47755d12ff1e8ce2a7de28087933)
2024-11-17 13:47:42 -05:00
Andreas Kling 3e5f37f983 LibWeb: Allow changing the query of file:// URL via history.pushState()
The spec didn't match how other browsers behave, and we dutifully did
what the spec said. A spec bug has been filed, so let's fix this locally
for now with a FIXME.

(cherry picked from commit e3408c4a7f2fe2ce2435d34e816e9b5b7e58f4af)
2024-11-17 13:47:42 -05:00
Andreas Kling 3c2e4999f4 LibWeb: Let determine_the_origin() take an optional URL after all
I originally believed that this could never receive a null URL and the
spec was inaccurate, but it seems like it can indeed.

I don't have a distilled test, but this makes logging in with GitHub
work on https://v0.dev/

(cherry picked from commit 1a4b0ded1f802fdcc3ef9b919b5749b086471fc2;
amended to also cherry-pick LadybirdBrowser/ladybird#2358)
2024-11-15 10:19:53 -05:00
Andreas Kling 20057b3140 LibWeb: Scale up "inspected node" hint text to match screen DPI
This fixes an issue where the text would look very small on macOS.

(cherry picked from commit 72f425391114556973f356885dc9d4a6aeff8787;
amended to cast device_pixels_per_css_pixel() to float to pacify
-Wdouble-promotion)
2024-11-14 17:46:06 -05:00
Andreas Kling bff196be31 LibWeb: Avoid unnecessary style recomputation during traversal
While traversing the DOM tree, looking for nodes that need a style
update, we were recomputing style for every node visited along the way,
even nodes that didn't themselves need a style update (but one of their
descendants did).

This avoids a bunch of completely unnecessary style recomputation on
basically every website.

(cherry picked from commit 5431db8c1c9d366d0a27959cfbf0f146bf4be20d)
2024-11-13 10:17:34 -05:00
Andreas Kling 337b113e68 LibWeb: Use the correct document URL in DOMParser.parseFromString()
We were hard-coding "about:blank" as the document URL for parsed HTML
documents, which was definitely not correct.

This fixes a bunch of WPT tests under /domparsing/ :^)

(cherry picked from commit 55f58eea99c0429dcc39cd0430fafa60eecf5542)
2024-11-13 10:17:34 -05:00
Andreas Kling b0d8d9ef4a LibWasm: Make BytecodeInterpreter overrides final
This gives us free devirtualization of some hot calls inside the
bytecode interpreter. Most notably the did_trap() checks.

Modest performance improvement on the https://figma.com/ landing page.

(cherry picked from commit 2f3128333dcd5a781f35272800631d6cf03803ad)
2024-11-12 22:26:21 -05:00
Andreas Kling 7b2568bc9a LibJS: Stop having AsyncFunctionDriverWrapper leak itself
Async functions whose promise is never resolved were leaking, since they
had a strong root JS::Handle on themselves.

This doesn't appear to actually be necessary, since the wrapper will be
kept alive as long as it's reachable (and if it's not reachable, nobody
is going to resolve/reject the promise either).

This fixes the vast majority of leaks on Speedometer, bringing memory
usage at the end of a full run from ~12 GiB to ~3 GiB.

(cherry picked from commit b6a5b7e18626ce0dee11a25bb0d51d2e84d3c057)
2024-11-12 19:57:55 -05:00
Andreas Kling 8486d6e8aa LibJS: Use ConservativeVector when instantiating static class fields
This fixes an issue where a badly-timed garbage collection could swallow
a static field initializer.

Caught by running test262 in GC-on-every-allocation mode.

(cherry picked from commit 10724a7cb346e57b0b97e4bd54c13c5c604dbf9c)
2024-11-12 19:57:55 -05:00
Andreas Kling 1c7e69a5b5 LibJS: Make ConservativeVector<T> visit all possible values
We were miscalculating the length of the buffer in pointer-sized chunks,
which is what the conservative root scan cares about.

This could cause some values to be prematurely garbage-collected.

(cherry picked from commit 2fb3b6c542db3a86cbd1aa7e34d470e34c485372)
2024-11-12 19:57:55 -05:00
Andreas Kling b57e502d21 AK: Add ASCII fast path in StringBuilder::append(Utf16View)
And let's at least try to pre-allocate an appropriate amount of
buffer space in the builder instead of appending and growing one
code point at a time.

(cherry picked from commit b6e28ff80779520ccb49e6c15ae1866bbc8713a7)
2024-11-12 07:14:25 -05:00
Andreas Kling 1600dcaf19 LibWeb: Ignore boxes wholly in the negative scrollable overflow region
This fixes an issue where https://hey.com/ was horizontally scrollable
even though it shouldn't be.

(cherry picked from commit 94721385ceb17e20428b94a946d39828bdd5b74e)
2024-11-11 19:54:09 -05:00
Andreas Kling 3479bf0470 LibWeb: Make Document::m_intersection_observers a weak mapping
These registrations are not meant to keep the observers alive.
This fixes a handful of world leaks on Speedometer.

(cherry picked from commit b397a0d5350fad04f43e3e5d9bdb9c801a4e712a)
2024-11-11 17:22:05 -05:00
Andreas Kling 5cd1016714 LibJS: Add RawNonnullGCPtr<T>
This is really just a type alias for NonnullGCPtr<T>, but it provides
a way to have non-owning non-visited NonnullGCPtr<T> without getting
yelled at by the Clang plugin for catching GC errors.

(cherry picked from commit 6a6618f5eab6e6a2c7c3fc03f8063cc6b497a0ec)
2024-11-11 17:22:05 -05:00
Andreas Kling 3d36c75eee LibJS: Use correct cell address for HeapFunction captures in GC dumps
We were previously dumping the address of the cell pointer instead of
the address of the cell itself. This was causing mysterious orphans
in GC dumps, and it took me way too long to figure this out.

(cherry picked from commit e240084437ea0bfe03d83dc3533d4ee6214b7206)
2024-11-11 17:22:05 -05:00
Andreas Kling e9f9716ef6 LibJS: Parse dates like "Tuesday, October 29, 2024, 18:00 UTC"
This format is used on https://jetbrains.com/

(cherry picked from commit 3180df3337cc319cdc30b33b70a19b3aafa5642b)
2024-11-11 10:11:22 -05:00
Andreas Kling 37c9b1ce7b LibJS: Store RegExp flags as a bitmask
This avoids having to do O(n) contains() in the various flag accessors.

Yields a ~20% speed-up on the following microbenchmark:

    const re = /foo/dgimsvy;
    for (let i = 0; i < 1_000_000; ++i)
        re.flags;

(cherry picked from commit 257ebea3645ab709be4a984100cc6478b289d0e6)
2024-11-11 10:11:22 -05:00
Andreas Kling fcc40ca35f LibWeb: Stub out SVGGraphicsElement.getScreenCTM()
This allows us to run Speedometer 3.0 to completion. :^)

(cherry picked from commit 72320be1240039822693aa1659c4adbb24cde87f)
2024-11-11 09:17:08 -05:00
Andreas Kling 880b6b1375 LibWeb: Stop traversal early when marking nodes for child style update
These flags always propagate to the root, so once we encounter an
ancestor with the flag set, we can stop traversal since everything above
it will already be set as well.

(cherry picked from commit f106aa9e8a8f3a98b498e0f9324123963fad6ca2)
2024-11-10 21:48:40 -05:00
Andreas Kling 72227066c6 LibWeb: Avoid a weird reparse of style attributes for pseudo elements
For pseudo elements that represent a browser-generated shadow tree
element, such as ::placeholder, we were reparsing their style attribute
in StyleComputer for some reason.

Instead of doing this, just access the already-parsed version via
Element::inline_style().

(cherry picked from commit d21c5631aa5d3bebcf828e893f0d7da031481894)
2024-11-10 21:48:40 -05:00
Andreas Kling c2d89a02c7 LibWeb: Check for active document in descendant_navigables()
This is not in the spec, but I did see a null pointer dereference here
while browsing the web, and it seems completely harmless for this
function to skip over navigables without an active document.

(cherry picked from commit 56e1c0e7eec813c311c41696063a3a31b4b14f0d)
2024-11-10 20:06:23 -05:00
Andreas Kling 0897967771 LibWeb: Recompute targetStep during "apply the history step"
This is an ad-hoc change to account for the fact that we may run
arbitrary code while waiting for the tasks in this function to complete.

I don't have a way to reproduce it, but I've seen trouble caused by
navigables disappearing, which causes the history step numbers to be
disturbed.

(cherry picked from commit ac48222ed7b497b13343ec79a234ba432ffd29e2)
2024-11-10 20:06:23 -05:00
Andreas Kling e715c973cc LibWebView: Update User-Agent spoofing strings with new versions
Also use an OrderedHashMap so they show up in the same order in UI.

(cherry picked from commit a2a9a11466aba1ab357922e8bd0338222e3f4179)
2024-11-10 20:06:23 -05:00
Andreas Kling 3590a94fc4 LibJS: Don't leak class field initializers
We were storing these in Handle (strong GC roots) hanging off of
ECMAScriptFunctionObject which effectively turned into world leaks.

(cherry picked from commit 5aa1d7837fe37dd203763178df3325ff8b24abbd)
2024-11-10 19:39:05 -05:00
Andreas Kling 1b6c784b77 LibCore: Don't reserve 2 KiB of stack memory when processing event queue
The inline capacity on ThreadEventQueue::Private::queued_events caused
us to reserve (and importantly, not initialize!) 2 KiB of stack memory
when entering ThreadEventQueue::process().

This was causing any leftover pointers to GC-allocated objects within
that memory range to keep those objects alive, even when all other
references were gone.

(cherry picked from commit 8c809fa5ee52903921191db91dce432b8a62dd01)
2024-11-10 19:39:05 -05:00
Andreas Kling f670b2ca32 AK: Use getrlimit() to find the correct main thread stack size on macOS
This is what JavaScriptCore does as well.

(cherry picked from commit 11458f0d91654feed9b4e225c4e6ac8528057355)
2024-11-10 19:39:05 -05:00
Andreas Kling c00dda5a3a WebContent: Try to run manual GC with less stuff on the stack
This makes it more likely to succeed in collecting stuff that's actually
dead, by reducing the memory range scanned for possible pointers.

(cherry picked from commit 1510c1876c023de977bf5b028672e61336761176)
2024-11-10 19:39:05 -05:00
Andreas Kling ad4abc1818 UI/AppKit: Make "Dump GC Graph" menu action actually work again
This was originally implemented as a debug request, but later changed.
The Qt UI already did the right thing, so just copy the logic over.

(cherry picked from commit 08ae305dc5a621233b2d329581969899efbb1195)
2024-11-10 19:39:05 -05:00
Andreas Kling bca2b88b45 LibWeb: Always blockify the root element
This is what the spec tells us to do:

    The root element’s display type is always blockified,
    and its principal box always establishes an independent
    formatting context.

    Additionally, a display of contents computes to block
    on the root element.

Spec link: https://drafts.csswg.org/css-display/#root

Fixes #1562

(cherry picked from commit f1be662f683155705f851bcf440fe30d0e606a87)
2024-11-10 10:46:01 -05:00
Andreas Kling 16473663ea LibJS: Don't infinite loop on unknown console.log formatting specifiers
(cherry picked from commit ef9208047dc8770f6263b483d7a442df703bc42b)
2024-11-10 10:46:01 -05:00
Andreas Kling 1bf3aeaab4 LibWeb: Sync with spec in "destroy a document and its descendants"
The only real change here is that we make the document unsalvageable.
Everything else is fixing up spec comments.

(cherry picked from commit faf097bb4168208a7c0250280ff07e638be8058a)
2024-11-10 10:46:01 -05:00
Andreas Kling 4172811f75 LibWeb: Abort ongoing fetch before starting a new link element fetch
If we decide to fetch another linked resource, we don't care about the
earlier fetch and can safely abort it.

This fixes an issue on GitHub where we'd load the same style sheet
multiple times and invalidate style for the entire document every time
it finished fetching.

By aborting the ongoing fetch, no excess invalidation happens.

(cherry picked from commit 57e26ed6b9b2c0cf1e4f5ac3e85ca0c7f3647caa)
2024-11-10 10:46:01 -05:00
Andreas Kling 88b2d705e2 LibWeb: Invalidate less style on textContent change and node removal
...unless there are :has() selectors present. Then we have to invalidate
everything for now.

(cherry picked from commit b8ce34068f5bf8ab8cf049d56b864bff52ef3dff)
2024-11-10 10:46:01 -05:00
Andreas Kling a49ba1914a LibWeb: Distinguish parent/child on style invalidation for DOM insertion
(cherry picked from commit 7d644ecd50c57454dfb73b92e59d7112d54a1b1d)
2024-11-10 10:46:01 -05:00
Andreas Kling 66c8631bf8 LibWeb: Don't try to invalidate style for character data nodes
Character data nodes like text and HTML comments don't have style,
so let's just exit invalidation immediately for those.

(cherry picked from commit f351f75a34619ad969f660312a2e5486f742f685)
2024-11-10 10:46:01 -05:00
Andreas Kling 319dd59fc4 LibWeb: Cache whether there are any :has() selectors present
As useful as they may be to web developers, :has() selectors complicate
the style invalidation process quite a lot.

Let's have StyleComputer keep track of whether they are present at all
in the current set of active style sheets. This will allow us to
implement fast-path optimizations when there are no :has() selectors.

(cherry picked from commit 8beb7c77002a3359ad2fe73969fc6bb2dbc75413)
2024-11-10 10:46:01 -05:00
Andreas Kling f23323d3d7 LibWeb: Include siblings+descendants when invalidating style
When an element is invalidated, it's possible for any subsequent sibling
or any of their descendants to also need invalidation. (Due to the CSS
sibling combinators, `+` and `~`)

For DOM node insertion/removal, we must also invalidate preceding
siblings, since they could be affected by :first-child, :last-child or
:nth-child() selectors.

This increases the amount of invalidation we do, but it's more correct.

In the future, we will implement optimizations that drastically reduce
the number of elements invalidated.

(cherry picked from commit df048e10f5a84d7fd90b1115c6bb90f45acd75ec)
2024-11-10 10:46:01 -05:00
Andreas Kling b0b5a056b3 LibWeb: Allow setting shorthand CSS properties via CSSStyleDeclaration
We now expand shorthands into their respective longhand values when
assigning to a shorthand named property on a CSSStyleDeclaration.

We also make sure that shorthands can be round-tripped by correctly
routing named property access through the getPropertyValue() AO,
and expanding it to handle shorthands as well.

A lot of WPT tests for CSS parsing rely on these mechanisms and should
now start working. :^)

Note that multi-level recursive shorthands like `border` don't work
100% correctly yet. We're going to need a bunch more logic to properly
serialize e.g `border-width` or `border` itself.

(cherry picked from commit e40ad73ae79023f64e250f854d0730c21e0f54fc)
2024-11-10 10:46:01 -05:00
Andreas Kling adad01a830 LibWeb: Always flush character insertions before exiting HTML parser
This fixes an issue where document.write() with only text input would
leave all the character data as unflushed text in the parser.

This fixes many of the WPT tests for document.write().

(cherry picked from commit a0ed12e839f14b3ac80caca0e18a09ca256fd99d)
2024-11-10 10:46:01 -05:00
Andreas Kling cfa323ed6e LibWeb: Let style elements remember which StyleSheetList they live in
Instead of trying to locate the relevant StyleSheetList on style element
removal from the DOM, we now simply keep a pointer to the list instead.

This fixes an issue where using attachShadow() on an element that had
a declarative shadow DOM would cause any style elements present to use
the wrong StyleSheetList when removing themselves from the tree.

(cherry picked from commit 8543b8ad6a4d96bd0c247052572b8c2abf3929a7)
2024-11-10 10:46:01 -05:00
Andreas Kling 38ed84421b LibWeb: Add StyleElementUtils::visit_edges()
Let's do this instead of making embedders visit every field of this
helper class.

(cherry picked from commit 2064be708f7318f72553fb210f918fe167e08257)
2024-11-10 10:46:01 -05:00
Andreas Kling 4779c6ac60 LibWeb: Keep custom properties from all cascade layers
Before this change, we were cascading custom properties for each layer,
and then replacing any previously cascaded properties for the element
with only the set from this latest layer.

The patch fixes the issue by making each pass of the custom property
cascade add to the same set, and then finally assigning that set of
properties to the element.

(cherry picked from commit 95bd0602ba079e0bd7608e39bcbc3b0403ed89d1)
2024-11-10 10:46:01 -05:00
Andreas Kling 81f60e2077 LibWeb: Use LayoutState::UsedValues::containing_block_used_values() more
Use this cached pointer to the containing block's used values when
obviously possible. This avoids a hash lookup each time, and these
hash lookups do show up in profiles.

(cherry picked from commit bdb67d2bcb4ab6fa49292c3365facdeab1fd0e20)
2024-11-09 16:08:01 -05:00
Andreas Kling 33bfcc467b LibJS: Don't copy current program counter into new execution contexts
This didn't make any sense, and was already handled by pushing a new
execution context anyway.

By simply removing these bogus lines of code, we fix a bug where
throwing inside a function whose bytecode was shorter than the calling
function would crash trying to generate an Error stack trace (because
the bytecode offset we were trying to symbolicate was actually from
the longer caller function, and not valid in the callee function.)

This makes --log-all-js-exceptions less crash prone and more helpful.

(cherry picked from commit b3f77e47690cfd07058d824ea6f0b652489778bf)
2024-11-09 16:08:01 -05:00
Andreas Kling c4a11363dc LibJS: Fix mix-up when re-exporting an imported symbol with a new name
This makes https://cling.com/ load, and more of the animated elements
on https://shopify.com/ start appearing.

(cherry picked from commit 0f9444fa06031e7d8e3c1ad36e701090e0b17ec1)
2024-11-09 07:29:52 -05:00
Andreas Kling 0e13e00d6a LibJS: Use the system native page size as the HeapBlock::block_size
Before this change, we were hard-coding 4 KiB. This meant that systems
with a 16 KiB native page size were wasting 12 KiB per HeapBlock on
nothing, leading to worse locality and more mmap/madvise churn.

We now query the system page size on startup and use that as the
HeapBlock size.

The only downside here is that some of the pointer math for finding the
base of a HeapBlock now has to use a runtime computed value instead of a
compile time constant. But that's a small price to pay for what we get.

(cherry picked from commit a6bf253602702c052453d5ccb45a40d8fbb368ba)
2024-11-09 07:29:52 -05:00
Andreas Kling 438b1bddbc LibWeb: Implement vertical-align: middle correctly for atomic inlines
This makes inline icons pop into the right place on https://ahrefs.com/

(cherry picked from commit c22acc2551998e1e86970f89a452041dda8c3847)
2024-11-09 07:29:52 -05:00
Andreas Kling ad90326a6c LibWeb: Make CSS :hover selector match shadow-inclusive ancestors
Before this change, :hover wouldn't match anything outside the shadow
boundary when hovering elements inside a shadow tree. This was most
noticeable when hovering the text inside an input element and hover
styles disappearing from the hosting input element itself.

(cherry picked from commit 84ab8bf7973147d054a99445943b9da930ceb0a2)
2024-11-09 07:29:52 -05:00
Andreas Kling 31237da230 LibWeb: Don't paint text fragments with CSS visibility:hidden
We *could* even skip creating a paintable for hidden nodes, but that
means that dynamic updates to the CSS visibility property would require
mutating the paint tree, so let's keep it simple for now.

(cherry picked from commit 349b17cc7aaba8c6cce3aaef26d14a0127f43ff1)
2024-11-08 22:32:11 -05:00
Andreas Kling c2a049e031 LibWeb: Derive SVG root's natural size from width/height attributes
We were incorrectly looking at the CSS computed values for width and
height to determine the natural size of <svg> root elements.
This meant that elements where the attribute and computed value were
different values would end up with incorrect natural size.

(cherry picked from commit 8eacfc8f10256f29fed0405a6bf1cb95e73b9bef)
2024-11-08 22:32:11 -05:00
Andreas Kling f687fdf000 LibWeb: Handle document/navigable disconnection during favicon decode
If the document is disconnected from the navigable by the time a favicon
decode completes successfully, we don't want to show the favicon for
whatever document is now loaded in the navigable.

Fix this by deferring getting the navigable until after the decode has
completed.

(cherry picked from commit 5606ce412e1d946dcd59a85ed50e429efdde863f)
2024-11-08 22:32:11 -05:00
Andreas Kling 09a3dcb9c9 LibWeb: Implement very basic in-memory HTTP caching
This patch adds a simple in-memory HTTP cache to each WebContent
process.

It's currently off by default (turn it on with --enable-http-cache)
since the validation logic is lacking and incomplete.

(cherry picked from commit a3c8e60710451c1325f6718b253e8d1ee2029a30)
2024-11-05 11:22:07 -05:00
Andreas Kling 197076ed7b LibWeb: Make HTTP response directive parsing more robust
(cherry picked from commit 47169db4529d1310d8802b3b60bb97cf926374a7)
2024-11-05 11:22:07 -05:00
Andreas Kling 1c8375f5df LibWeb: Don't extrapolate transition properties for unknown properties
If we don't recognize a given transition-property value as a known CSS
property (one that we know about, not necessarily an invalid one),
we should not extrapolate the other transition-foo values for it.

Fixes #1480

(cherry picked from commit 9765a733d0bc297815fc1a7fce562e3d8f69cd84)
2024-11-05 10:48:01 -05:00
Andreas Kling fbe99575e0 LibWeb: Resolve flex item % main size to 0 during min-content sizing
When the flex container is sized under a min-content constraint in the
main axis, any flex items with a percentage main size should collapse
to zero width, not take up their own intrinsic min-content size.

This is not in the spec, but matches how other browsers behave.

Fixes an issue where the cartoons on https://basecamp.com/ were way
too large. :^)

(cherry picked from commit 59ed823724331d6457e81f8674aef392ca4dc174)
2024-11-04 21:46:05 -05:00
Andreas Kling 213f86d781 LibWeb: Adjust flex item intrinsic contributions through aspect ratio
When determining the intrinsic cross size contribution of a flex item
with a preferred aspect ratio, we have to account for any min/max
constraints in the main axis.

(cherry picked from commit bde2d3dc7b359cd4f56ad9975c44d22e43ef82fe)
2024-11-04 21:46:05 -05:00
Andreas Kling da526bac92 LibWeb: Don't invalidate layout tree on all DOM node removals
DOM nodes that didn't have a layout node before being removed from the
DOM are not going to change the shape of the layout tree after being
removed.

Observing this, we can avoid a full layout tree rebuild on some DOM node
removals.

This avoids a bunch of tree building work when loading https://x.com/

(cherry picked from commit 6f34758947852abae773798ba3ffa8e903fdc3d0)
2024-11-04 13:17:01 -05:00
Andreas Kling 5c4c048195 LibWeb: Rename invalidate_layout() => invalidate_layout_tree()
I believe this is slightly less confusing, since what the function does
is trigger a full layout tree *rebuild*, not just a relayout.

(cherry picked from commit aa8f17aea4d1aa1950a66969fc8b5c431fbc1b7c)
2024-11-04 13:17:01 -05:00
Andreas Kling 1030034130 LibWeb: Put CSS transitions debug spam behind CSS_TRANSITIONS_DEBUG
(cherry picked from commit 42a1a0bd73fecd22452e224859d27221588c3f5f;
amended to fix conflicts in Debug.h.in and all_the_debug_macros.cmake)
2024-11-04 13:15:58 -05:00