Compare commits

...

2611 Commits

Author SHA1 Message Date
Tim Ledbetter
1c10421316 LibWeb: Support font-stretch SVG presentation attribute
Some checks failed
CI / ${{ matrix.os_name }}, ${{ matrix.arch }}, ${{ matrix.build_preset }}, ${{ matrix.toolchain }} (arm64, Sanitizer, false, macOS, ["macos-15", "self-hosted"], Clang) (push) Has been cancelled
CI / ${{ matrix.os_name }}, ${{ matrix.arch }}, ${{ matrix.build_preset }}, ${{ matrix.toolchain }} (x86_64, Fuzzers, false, Linux, ["blacksmith-16vcpu-ubuntu-2404"], Clang) (push) Has been cancelled
CI / ${{ matrix.os_name }}, ${{ matrix.arch }}, ${{ matrix.build_preset }}, ${{ matrix.toolchain }} (x86_64, Sanitizer, false, Linux, ["blacksmith-16vcpu-ubuntu-2404"], GNU) (push) Has been cancelled
CI / ${{ matrix.os_name }}, ${{ matrix.arch }}, ${{ matrix.build_preset }}, ${{ matrix.toolchain }} (x86_64, Sanitizer, true, Linux, ["blacksmith-16vcpu-ubuntu-2404"], Clang) (push) Has been cancelled
Build Dev Container Image / build (push) Has been cancelled
Run test262 and test-wasm / run_and_update_results (push) Has been cancelled
Lint Code / lint (push) Has been cancelled
Label PRs with merge conflicts / auto-labeler (push) Has been cancelled
Push notes / build (push) Has been cancelled
2025-10-11 08:12:38 +01:00
Tim Ledbetter
14be5106d7 LibWeb: Add missing SVG presentation attributes 2025-10-11 08:12:38 +01:00
Timothy Flynn
0cae8dd712 LibWeb: Do not drop favicon resolution callbacks
Commit 77f6edaf71 tried to map the promise
returned from the ImageCodecPlugin to the same promise type used for SVG
decoding. However, `map` drops the existing resolution callbacks on the
floor.

Instead, let's keep the ImageCodecPlugin promise alone, and resolve the
returned promise explicitly.
2025-10-10 15:10:20 -04:00
Timothy Flynn
e57176b484 LibWebView: Move headless clipboard management to LibWebView
We only supported headless clipboard management in test-web. So when WPT
tests the clipboard APIs, we would blindly try to access the Qt app,
which does not exist.

Note that the AppKit UI has no such restriction, as the NSPasteboard is
accessible even without a GUI.
2025-10-10 15:10:03 -04:00
Timothy Flynn
a4a15b9a1e LibWeb+UI/AppKit: Ignore unknown clipboard MIME types
This prevents the AppKit UI from sending unknown MIME types to LibWeb,
where we would previously blindly dereference the result of parsing the
MIME string. We now ignore unknown MIME types as well.
2025-10-10 15:10:03 -04:00
Timothy Flynn
281bf227ad Meta: Support importing WPT resources in fetch() invocations 2025-10-10 15:10:03 -04:00
Timothy Flynn
a229a9d7e1 Meta: Store parsed WPT resources as a set
If a resource appears in a test more than once, such as:

    <script src="/foo.png">
    <script src="/foo.png">

Then we end up replacing "/foo.png" in the test source that many times
as we iterate over the resource array, like so:

    source.replace("/foo.png", "../foo.png")

So we end up with:

    <script src="..../foo.png">
    <script src="..../foo.png">

Store the resources as a set instead.
2025-10-10 15:10:03 -04:00
Dowsley
c6b289c3dc LibWeb: Derive implicit aria-level for h1–h6 from tag name 2025-10-10 17:18:02 +01:00
Aliaksandr Kalenik
d7f830cdd1 LibWeb: Execute rasterization callback on the rendering thread
Previously, we enqueued a task on the main thread's event loop to
execute the callback. This meant that even though the rendering thread
had finished producing the next frame, there was still a delay before
the main thread notified the UI process.

This change makes the rendering thread execute the callback directly.
This should be safe, as the only pointer captured by the callback is the
traversable `PageClient`, which is expected to remain alive for as long
as the rendering thread exists. The callback then invokes either
`page_did_paint()` or `page_did_take_screenshot()`, both of which
enqueue an IPC message, which is safe to do since `SendQueue` is
protected by a mutex.
2025-10-10 17:25:55 +02:00
Aliaksandr Kalenik
9e3e581e14 LibWeb: Delete unused m_combined_css_transform from PaintableBox 2025-10-10 16:58:51 +02:00
Aliaksandr Kalenik
72aaef5a0f LibWeb: Delete non-const layout_node_with_style_and_box_metrics()
...from PaintableBox. It was used exclusively to go to corresponding DOM
node which could be done via direct DOM node pointer owned by paintable.
2025-10-10 16:58:51 +02:00
Aliaksandr Kalenik
0fbadba2e1 LibWeb: Add a test to ensure "resize" event on VV is fired on pinch-zoom 2025-10-10 15:37:45 +02:00
Aliaksandr Kalenik
835081d66e LibWeb+LibWebView+WebContent: Reset pinch-to-zoom state on Ctrl/Cmd+0 2025-10-10 15:37:45 +02:00
Aliaksandr Kalenik
eb4c616974 LibWeb: Dispatch "resize" event on VisualViewport size change 2025-10-10 15:37:45 +02:00
Aliaksandr Kalenik
9862d8b4a6 LibWeb: Implement pinch-to-zoom support
Adds pinch event handling that adjusts the VisualViewport scale and
offset. VisualViewport's (offset, scale) is then used to construct a
transformation matrix which is applied before display list execution.
2025-10-10 15:37:45 +02:00
Aliaksandr Kalenik
b477c6bfc4 LibWeb: Implement VisualViewport aware viewport scrolling
Implements spec algorithm for viewport scrolling that first checks if
it's possible to use delta to move the visual viewport before falling
back to scrolling the layout viewport. This is a part of pinch-to-zoom
support.
2025-10-10 15:37:45 +02:00
Aliaksandr Kalenik
7ba34e8bd1 LibGfx: Implement AffineTransform::to_matrix() 2025-10-10 15:37:45 +02:00
Aliaksandr Kalenik
c630de17ab LibWeb+UI+WebContent: Pipe pinch events from AppKit UI to WebContent 2025-10-10 15:37:45 +02:00
Lorenz A
e6831003c6 LibWeb: Check for Svg & MathML tags in stack of open elements scope
list & button scope need to check svg & mathml elements besides the list
from s_base_list see
https://html.spec.whatwg.org/multipage/parsing.html#has-an-element-in-the-specific-scope
2025-10-10 12:09:20 +01:00
Manuel Zahariev
125b13a0cb LibWeb/CSS: Test cases for content inside the ::marker pseudo-element 2025-10-10 12:02:16 +01:00
Manuel Zahariev
9d77221c4d LibWeb/CSS: Add support for content to the ::marker pseudo-element
A ::marker pseudo-element is created for list item nodes (nodes
with display:list-item).

Before:
    - The content of the ::marker element is created magically from
    the value of the ordinal (for <ol>) or from a template (for <ul>).
    The style `content` is ignored for ::marker pseudo-elements.

After:
    - If a "list item node" has CSS `content` specified for its ::marker
    pseudo-element, use this to layout the pseudo-element,
    https://drafts.csswg.org/css-lists-3/#content-property
    - Otherwise, layout the list item node as before.
2025-10-10 12:02:16 +01:00
R-Goc
24ace9f183 Vcpkg: Disable cpptrace for freeBSD
Cpptrace is not supported on freeBSD, so until that changes it will not
be built from vcpkg.
2025-10-10 12:46:20 +02:00
R-Goc
ba5ef052e4 AK: Fix libbacktrace fallback
Introducing cpptrace as the primary backtrace library broke the
backtrace fallback during the code move. This commit properly links AK
to libbacktrace.

It also fixes the function signatures for the fallback backtrace
handlers.
2025-10-10 12:46:20 +02:00
R-Goc
5deeb55461 Meta: Add cpptrace to flatpak manifest
This commit adds cpptrace to the flatpak manifest, fixing the build.

Co-authored-by: Jan Koudijs <theappgineer@gmail.com>
2025-10-10 12:46:20 +02:00
Jelle Raaijmakers
5153b9ef45 CI: Trigger Flatpak CI builds with 'flatpak' PR label
Similar to the 'windows' label, this triggers Flatpak builds for x86_64
and aarch64.
2025-10-10 09:28:38 +02:00
Aliaksandr Kalenik
83fb690bce LibWeb: Remove usage of layout_node() in dom_node_for_event_dispatch
No need to go through layout node when paintable has a direct pointer to
the DOM node.
2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
b786935169 LibWeb: Delete CheckBoxPaintable::layout_box()
No need for this method when we could reach into DOM node directly from
Paintable.
2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
38ca745a59 LibWeb: Delete CanvasPaintable::layout_box()
No need for this method when we could reach into DOM node directly from
Paintable.
2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
d3f40e9a72 LibWeb: Delete AudioPaintable::layout_box()
No need for this method when we could reach into DOM node directly from
Paintable.
2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
33a8fbd22c LibWeb: Delete unused SVGGraphicsPaintable::layout_box() 2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
3675560804 LibWeb: Delete unused SVGSVGPaintable::layout_box() 2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
2c2584ee99 LibWeb: Delete VideoPaintable::layout_box()
No need for this method when we could reach into DOM node directly from
Paintable.
2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
5c699e1a45 LibWeb: Delete NavigableContainerViewportPaintable::layout_box()
No need for this method when we could reach into DOM node directly from
Paintable.
2025-10-10 09:03:39 +02:00
lukasxcs
c1ff2a845c LibWeb: Implement DataTransfer.set_data() 2025-10-10 08:02:16 +01:00
Rocco Corsi
6fa32fbf69 Tests: Adjust timing in abortsignal-timeout test to avoid failure
Many clock related functions in Ladybird use the clock type called
CLOCK_MONOTONIC_COARSE to obtain timestamps. This is a less precise
clock and can be skewed by 1 or more milliseconds.

This less precise clock timing is causing the abortsignal-timeout.html
test to fail randomly as it expects the abort signal to arrive after
10ms, but in some cases it arrives at 9ms causing the test to fail. In
some very rare cases it could even arrive in 7ms or 8ms.

Test is changed to accept 9ms as a good result and if that is still
not enough the test also will display the timings so that further
investigations can be made.
2025-10-10 08:36:11 +02:00
Adam Patterson
120bba597d LibJS: Remove using-declaration.js from .prettierignore
This is the second and final commit to remove using-declaration from
.prettierignore. While there is standard formatting changes here, there
is also scoping changes for the 'using' declarations due to the
following error:

Libraries/LibJS/Tests/using-declaration.js: SyntaxError:
Using declaration cannot appear in the top level when source
type is `script` or in the bare case statement.
2025-10-09 15:49:49 -04:00
Adam Patterson
052013f8e6 LibJS: Partially format using-declaration.js with prettier
This contains prettier formatting fixes for using-declaration.js. The
file isn't fully formatted at this state. There is a minor scoping code
change that must happen in the next commit to be able to remove this
file from .prettierignore, but I wanted to separate the code change from
the formatting change to improve the review process.

This contains formatting and changing single quotes to double quotes.
2025-10-09 15:49:49 -04:00
Adam Patterson
0eac4cc6ad LibJS: Remove files from .prettierignore
.prettierignore had files listed for an issue with 'using' declarations,
this is no longer an issue for prettier (tested on 3.6.2).
2025-10-09 15:49:49 -04:00
dependabot[bot]
52009170da CI: Bump gradle/actions from 4 to 5
Bumps [gradle/actions](https://github.com/gradle/actions) from 4 to 5.
- [Release notes](https://github.com/gradle/actions/releases)
- [Commits](https://github.com/gradle/actions/compare/v4...v5)

---
updated-dependencies:
- dependency-name: gradle/actions
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-09 17:46:22 +02:00
Sam Atkins
f61c67792d LibWeb/CSS: Allow setting shorthand values with StylePropertyMap.set()
Shorthands should be broken up into their longhands, instead of setting
them directly.

There's a catch here with our "positional value list shorthands" like
`margin`: Setting margin to a single value like `CSSUnitValue(10, "px")`
is supposed to fail here, but our type-checking code thinks it's valid
because our JSON for `margin` says it accepts lengths. This is the same
kind of issue that we had for `cursor` discussed in the
"LibWeb/CSS: Support converting CSSUnitValue to a StyleValue" commit.

Will get us a few subtest passes for every shorthand that's tested.
2025-10-09 16:14:58 +02:00
Sam Atkins
0015ee310c LibWeb/CSS: Support converting CSSUnparsedValue to a StyleValue
Unfortunately this doesn't pass a lot of tests, because we strip out
whitespace when parsing property values. In particular, the WPT suite
tests with this:

```js
new CSSUnparsedValue([' ', new CSSVariableReferenceValue('--A')])
```

...which gets the whitespace stripped from the string, meaning when we
convert the value back to JS, we get the equivalent of this:

```js
new CSSUnparsedValue(['', new CSSVariableReferenceValue('--A')])
```

...and that's not the same so the test fails.
2025-10-09 16:14:58 +02:00
Sam Atkins
9ef523ebb2 LibWeb/CSS: Prevent infinite recursion in CSSUnparsedValue::to_string()
As noted in the linked spec issue, it's possible for an author to
construct a CSSUnparsedValue that contains itself, meaning
serialization would be infinitely recursive. So instead, detect that
and then return an empty string, which copies Blink's solution to this
issue.

Stops `css/css-typed-om/cycle-in-unparsed-value-crash.html` from
crashing after we implement converting a CSSUnparsedValue to an
UnresolvedStyleValue, as that relies on serialization.
2025-10-09 16:14:58 +02:00
Sam Atkins
882bdbb019 LibWeb/CSS: Stop asserting that UnresolvedSV contains an ASF
Typed-OM means that the author can set a property's value to a
CSSUnparsedValue, which may or may not have any arbitrary substitution
functions in it. This VERIFY was just there to catch parsing bugs that
created UnresolvedStyleValues unnecessarily, and removing it is
harmless.
2025-10-09 16:14:58 +02:00
Sam Atkins
97a9082251 LibWeb/CSS: Check for var() after converting strings in Typed OM set()
This avoids regressions in the next commit.

See the linked spec issue for details. Without this, we end up doing the
wrong thing in cases like this, from a WPT test:

```js
styleMap.set('transition-duration', '1s', 'var(--A)');
```

`'var(--A)'` is a string, not a CSSVariableReferenceValue or
CSSUnparsedValue. Following the spec literally, we wouldn't throw a
TypeError here, even though we really should: The purpose of the check
is for list-valued properties, to prevent authors putting a series of
tokens that would represent multiple list items, into a single list
item slot.

So, we delay the check until after we've converted strings into values.
This does mean we're checking StyleValues instead of CSSStyleValues,
and it also means we've done more work before rejecting the input as
invalid. But correctness is nice. :^)
2025-10-09 16:14:58 +02:00
Sam Atkins
3644e75de1 LibWeb/CSS: Allow setting any property to CSS-wide keywords in typed OM
A minor thing I missed before. Gets us 4 WPT passes per property that's
tested, which is quite a lot.
2025-10-09 16:14:58 +02:00
Sam Atkins
b2d55e4caa LibWeb/CSS: Support converting CSSUnitValue to a StyleValue
A lone CSSUnitValue can now be converted to a dimension StyleValue of
the relevant type, as long as the property allows that type. If the
value is out of the allowed range, it's wrapped in calc().

There are a few failing tests still, involving setting a negative
percentage and expecting to read the computed value as 0. Those also
fail in Chromium, and a similar negative-length test expects a negative
computed value (not 0), so this appears to be an incorrect test.

Also, we regress some of the `cursor` tests. This is because our "does
property X accept type Y?" code is too naive: `cursor` is defined to
accept "number [-∞,∞]" in the JSON, and that value range is used when
clamping the result of calculations or interpolation. But because that
entry is there, we think a single number is a valid value for `cursor`.
Solving this generally is a larger task than I want to take on right
now. :^)
2025-10-09 16:14:58 +02:00
Sam Atkins
bd545af210 LibWeb/CSS: Support calculated percentages in line-height
Without this, the imported test will crash once we implement
`CSSUnitValue::create_an_internal_representation()`.
2025-10-09 16:14:58 +02:00
Lorenz A
6f31d9a40d LibWeb: Ensure Noah's Ark clause is called in the Parser 2025-10-09 12:24:45 +01:00
Callum Law
102edf638d LibWeb: Support interpolation of SuperellipseStyleValue 2025-10-09 10:23:20 +01:00
Callum Law
20a2e8ab12 LibWeb: Store corner-*-shape properties in computed form 2025-10-09 10:23:20 +01:00
Callum Law
397e39f316 LibWeb: Support corner-*-shape logical properties 2025-10-09 10:23:20 +01:00
Callum Law
7305b3fa28 LibWeb: Parse corner-*-shape physical shorthands 2025-10-09 10:23:20 +01:00
Callum Law
814efa9809 LibWeb: Parse corner-*-shape physical longhands 2025-10-09 10:23:20 +01:00
Callum Law
0bf6014001 Tests: Import css corner-shape tests 2025-10-09 10:23:20 +01:00
Luke Wilde
6d83fd92b6 LibWeb/IndexedDB: Add additional debug output for async operations 2025-10-08 17:25:29 +02:00
Luke Wilde
d87c2a55b0 LibWeb/IndexedDB: Remove spin_until from checking finished transactions 2025-10-08 17:25:29 +02:00
Luke Wilde
52b53e52fb LibWeb/IndexedDB: Remove spin_until from waiting for connection closure 2025-10-08 17:25:29 +02:00
Luke Wilde
e6dc52a52b LibWeb/IndexedDB: Remove spin_until from waiting for tasks to complete 2025-10-08 17:25:29 +02:00
Luke Wilde
5c69784ef9 LibWeb/IndexedDB: Remove spin_until from request processing 2025-10-08 17:25:29 +02:00
Luke Wilde
6d43e3cc93 LibGC: Mark Ptr::as_nonnull as a const function 2025-10-08 17:25:29 +02:00
Jelle Raaijmakers
a91031e1f3 CI: Use COMMIT file in JS repl archive to determine build commit hash
The upstream workflow `head_sha` contains the wrong hash in case the
workflow was run manually against a provided commit hash. We use the
COMMIT file that cpack adds to the archive to determine the actual
commit hash that was used to build the binaries.

Note that this will only work for builds since the introduction of that
file, so we cannot process benchmarks for older commits, unfortunately.
2025-10-08 14:42:09 +02:00
Jelle Raaijmakers
5c5de0e30e Meta: Add COMMIT file to cpack archives
This new file in the root of the archives contains the git commit hash,
to be used by e.g. the js-benchmarks webhook to determine which commit
was used to build the utilities.
2025-10-08 14:42:09 +02:00
Jelle Raaijmakers
915a89a93e Meta: Remove unused CPACK_PACKAGE_FILE_NAME
This went unused since the introduction of the explicit
CPACK_ARCHIVE_JS_FILE_NAME.
2025-10-08 14:42:09 +02:00
R-Goc
62e7d1b5c8 AK: Remove FreeLibrary call in assertion handler
The call to FreeLibrary was incorrect as GetModuleHandle does not
increment the reference count of the DLL.
2025-10-08 07:07:57 +02:00
R-Goc
3c7bad32cd AK: Clean up backtraces
This commit replaces the default backtrace logic with cpptrace, for
nicer, colored backtraces. Cpptrace runs on all of our supported
platforms excpet android. As such backtrace.h is left in place.

All the backtrace functions are made noinline to have a consistent
number of frames. A maximum depth parameter is added to dump_backtrace
with a default of 100. This should be enough, and can be easily
changed, and allows for limiting the maximum depth.

Setting the LADYBIRD_BACKTRACE_SNIPPETS environment variable enables
surrouding code snippets in the backtrace. Specifically 2 lines above
and below. This number can be changed by calling snippet_context on the
formatter. For the whole list of options of what can be done with
formatting see the cpptrace repository.

On Windows we skipped frames when verification fails and when
dump_backtrace was added the logic was wrong and would have skipped
frames we care about.

This commit also implements skipping frames on Linux.
The only time where this does not skip all frames is when the call to
backtrace gets intercepted. Then we will end up skipping one frame less
than needed.

To keep delayload on Windows a patch and overlay port is used. When
upstream accepts these changes and vcpkg bumps the version the patch
could be removed to have just the cmake define.
2025-10-08 07:07:57 +02:00
Lorenz A
1e6ac54b75 LibGfx+LibWeb: Don't display Glyphs that are not on the path 2025-10-08 03:34:53 +01:00
Rocco Corsi
b6b56910e8 LibIPC: Shutdown IPC handler when transport is lost during sync event
If the Ladybird process crashes or just ends normally, the IPC transport
connection with WebContent may be shutdown after a send sync event (for
example: WebContentClient DidRequestCookie) was sent from WebContent,
but before the Ladybird process provided the matching sync event
response (for example: WebContentClient DidRequestCookieResponse). This
can lead to a runaway WebContent process if other IPC events (for
example: WebContentServer DidPaint, or SetSystemVisibilityState, or
MouseEvent, or CloseServer, etc...) are also queued when the IPC
connection is shutdown.

At the core of the issue is that the loop waiting for the matching
send sync response will prioritize waiting for the response and remain
spinning even if the IPC connection is reporting that it was shutdown,
but only if there happens to be other unrelated events received before
the IPC shutdown is detected. These unrelated events will not be
processed because the loop is stuck waiting for the response that due
to the Ladybird process having stopped, will never be sent.

Because the shutdown of the IPC connection is not handled when other
events happen to be also present, new events may be posted for transfer
by the WebContent process if the page is very active. If many new events
are posted this could lead to a slow or very quick memory leak in the
WebContent process due to the queue growing large, sometimes all the way
to total system memory exhaustion. If no events or only a few new events
are sent, then the leak may be hard to detect.

This PR fixes the faulty IPC shutdown handling by not getting stuck if
any messages are present in the receive queue. Before returning to the
caller any remaining messages will be immediately processed.
2025-10-07 17:04:32 -05:00
Andreas Kling
695f02e8e5 LibJS: Give Interpreter a direct pointer to the identifier table
This gets rid of a lot of pointer chasing from interpreter to executable
to identifier table to the actual identifier.

1.05x speed-up on Kraken/ai-astar.js
2025-10-07 23:50:51 +02:00
Andreas Kling
d0df7c8c62 LibJS: Use [[likely]] annotations for cached environment lookups
These will generally be cached the vast majority of the time except on
first encounter, and sprinkling [[likely]] gives us a nice boost.

1.10x speed-up on this micro-benchmark:

    (() => {
        var a = 3;
        for (let i = 0; i < 100_000_000; ++i) { a; }
        eval("");
    })();
2025-10-07 23:50:51 +02:00
Pavel Shliak
8e439a3c09 LibWeb: Bring test script src reflection test back
This test was removed in 56ded2b9cc05cc820ba4a870aeb0df952eff5f5c
2025-10-07 21:52:06 +02:00
Pavel Shliak
4ff7c9043b LibWeb: Make HTMLScriptElement.src getter resolve to absolute URL
The src IDL attribute was previously implemented as an inline getter
that returned the raw attribute value. This broke spec semantics and
sites like Telegram Web that rely on document.currentScript.src to
compute Webpack’s publicPath.

According to the HTML Standard:
https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes

For URL-reflecting attributes:
  1. If contentAttributeValue is null, then return the empty string.
  2. Let urlString be the result of encoding-parsing-and-serializing
     a URL given contentAttributeValue,
     relative to element’s node document.
  3. If urlString is not failure, then return urlString.

This patch moves the getter to HTMLScriptElement.cpp and implements
these steps.
2025-10-07 21:52:06 +02:00
Luke Wilde
f44e42d27c LibWeb: Don't drop mouse wheel events sent to subframes unless handled
Otherwise scrolling gets stuck when you scroll over a non-scrollable
subframe.
2025-10-07 19:43:07 +02:00
Luke Wilde
adeedabf54 LibWeb: Don't class mousewheel as handled if scroll offset isn't updated
Before this change, you could only scroll the current hovered scroll
container, even if it was at the beginning or end and thus having no
effect.

Now, if it doesn't update, it will not be classed as handled and will
move onto the next scroll container.
2025-10-07 19:43:07 +02:00
Andreas Kling
38e224cd9f LibJS: Make overflowing arithmetic on 2x Int32 values faster
Instead of converting them to doubles and doing double math, just do the
arithmetic operation in i64 space instead.

This gives us a ~1.25x speed-up on this kind of micro-benchmark:

    (() => {
        let a = -2124299999;
        for (let i = 0; i < 100_000_000; ++i) {
            a + a;
        }
    })()

Same idea for Add, Sub, and Mul.

There's a fair bit of overflowing Int32 arithmetic in some of the
JetStream benchmarks, and this seems like an obvious improvement.
2025-10-07 18:28:26 +02:00
Jelle Raaijmakers
d696f107be CI: Add js-benchmarks commit hash to webhook payload 2025-10-07 15:12:21 +02:00
Jelle Raaijmakers
5e9d2461f3 CI: Always run latest version of js-benchmarks
Currently we default to GITHUB_REF for the checkout of js-benchmarks,
and if we've built up a large backlog of benchmark jobs to run, this can
mean we're running against a severely outdated version of js-benchmarks.

This new behavior allows us to see a failed js-benchmarks job, fix the
bug, and restart the failed job. This is important since we're testing a
specific commit and build from the upstream JS/WASM workflow.
2025-10-07 14:32:11 +02:00
Tim Ledbetter
03fa367d9d LibWeb: Parse the anchor-scope property 2025-10-07 11:30:23 +01:00
Tim Ledbetter
85a15ea1d4 LibWeb: Parse the position-visibility value 2025-10-07 11:30:23 +01:00
Tim Ledbetter
47966ed589 LibWeb: Parse the position-try-order property 2025-10-07 11:30:23 +01:00
Tim Ledbetter
2bde14b148 LibWeb: Parse the position-try-fallbacks property 2025-10-07 11:30:23 +01:00
Tim Ledbetter
27cdf3a2c8 LibWeb: Parse the position-anchor property 2025-10-07 11:30:23 +01:00
Tim Ledbetter
7374a07fbc LibWeb: Parse the anchor-name property 2025-10-07 11:30:23 +01:00
Callum Law
846f1626dd LibWeb: Remove unused {Calculated,Percentage}Or::absolutized methods
Reverts c8bd58c and 0df9c22. These were used to absolutize values stored
within other `StyleValue`s but we should instead store these values as
`StyleValue`s directly instead of within `{Calculated,Percentage}Or`.
2025-10-07 10:50:01 +01:00
Callum Law
e772a992be LibWeb: Store CursorStyleValue sub-values directly
Storing these within NumberOrCalculated is unnecessary
2025-10-07 10:50:01 +01:00
Callum Law
25192d3c20 LibWeb: Store BorderRadiusStyleValue sub-values directly
Storing these within LengthPercentage is unnecessary
2025-10-07 10:50:01 +01:00
Callum Law
2ebf446cbf LibWeb: Store BackgroundSizeStyleValue sub-values directly
Storing these within LengthPercentage is unnecessary
2025-10-07 10:50:01 +01:00
Callum Law
309ff33278 LibWeb: Add convenience from_style_value for LengthPercentage{OrAuto} 2025-10-07 10:50:01 +01:00
Callum Law
4a998879d5 LibWeb: Add absolutized method for TransformStyleValue 2025-10-07 10:50:01 +01:00
Callum Law
e675b95f51 LibWeb: Add absolutized method to OpenTypeTaggedStyleValue 2025-10-07 10:50:01 +01:00
Callum Law
2c7b56511b LibWeb: Add absolutized method to CounterDefinitionsStyleValue
This avoids a crash when a counter value relies on relative units
2025-10-07 10:50:01 +01:00
Callum Law
52192a308b LibWeb: Update absolutize to take a ComputationContext struct
This struct will in the future hold information other than a length
resolution context (e.g. context for tree counting functions) and a
single struct is easier to work with than multiple parameters.
2025-10-07 10:50:01 +01:00
Callum Law
47ffffb775 LibWeb: Absolutize value at start of compute_value_of_property
This saves us having to do it in various places later on.
2025-10-07 10:50:01 +01:00
Callum Law
28c12324c2 LibWeb: Remove unused NumericCalculationNode::to_style_value 2025-10-07 10:50:01 +01:00
Callum Law
f2a302663c LibWeb: Simplify value parsing code
We know that `parse_calculated_value` returns a
`RefPtr<CalculatedStyleValue const>` so we can avoid various checks on
the StyleValue type.
2025-10-07 10:50:01 +01:00
Andreas Kling
4d99f9f5d1 LibJS: Try to avoid a [[GetOwnProperty]] when setting Object property
The [[Set]] operation on objects will normally end up doing
[[GetOwnProperty]] twice, but if the object and the receiver are one on
the same, we can avoid the double work.

AFAIK this is not observable via proxies or other mechanisms.

1.10x speed-up on MicroBench/object-set-with-rope-strings.js
2025-10-07 11:34:19 +02:00
Callum Law
2098e516d2 LibWeb: Update layout of ancestor documents when getting computed style
Pending changes to an ancestor document's layout can affect an element's
computed style e.g. an IFrame's width being changed can affect media
query evaluation and the value of the `vw` unit.
2025-10-07 10:32:59 +01:00
Callum Law
05c336ea4e LibWeb: Use document's viewport when resolving lengths in media queries
Previously we would always use the window's viewport which was incorrect
if we were within an iframe.

This is likely applicable to all uses of
`Length::ResolutionContext::for_window`.
2025-10-07 10:32:59 +01:00
Callum Law
c33be71df9 LibWeb: Use correct value for font size in MediaFeature::compare
We were using the font's point size instead of it's pixel size, we were
already computing this information earlier in the function anyway so
let's just use that.
2025-10-07 10:32:59 +01:00
Callum Law
eeb3890ad7 LibWeb: Resolve stroke-dasharray percentages as lengths
Fixes a crash on https://collabskus.github.io/
2025-10-07 10:19:26 +01:00
Jelle Raaijmakers
988c7bb758 CI: Run js-benchmarks with --continue-on-failure for manual builds
If we ever want to rerun benchmarks for an older commit, e.g. if we
added new benchmarks that we would want historical performance data on,
we need to consider that some benchmarks might fail because of a bug or
missing feature. For manual runs of the upstream build, pass
`--continue-on-failure` so we simply skip these failing benchmarks.
2025-10-06 21:33:06 +02:00
Jelle Raaijmakers
5f12c091ac CI: Add manual workflow dispatch to JS/WASM artifacts build
This allows us to manually kick off jobs for the JS/WASM artifacts
build with an explicit reference to build, which is useful if we want to
generate benchmark results for older commits.

Note that this workflow does not actually produce benchmark results -
that's the job of another workflow. The webhook storing the benchmark
results only appends new benchmarks; existing ones will be kept.

Also note that the GitHub checkout action defaults to the default
reference if `inputs.reference_to_build` is not provided, such as in the
case of a push to the master branch.
2025-10-06 16:17:32 +02:00
Ali Mohammad Pur
9ceb8052c8 LibWasm: Avoid revalidating memory/address for every element in memory.*
This also "fixes" the "address leak" detected by GCC (which is not
actually leaked to the tailcalled function).
2025-10-06 16:00:02 +02:00
Jelle Raaijmakers
941cfd8026 Revert "CI: Pin js-benchmarks to current master"
This reverts commit 8d46a11748.

The updated webhook supports the newer output format of our
js-benchmarks tool, allowing us to store multiple result types per
benchmark and subtest combination.
2025-10-06 14:15:47 +02:00
Andreas Kling
7a2fe53c65 Revert "LibJS: Use HashMap::ensure() in VM string cache helpers"
This reverts commit 5810ddf339.

Appears to have introduced flakiness on WPT.
2025-10-06 12:15:34 +02:00
ljamar
0d62803f15 LibWeb/HTML: Correct color parsing for CanvasGradient color
This resolves all WPT timeouts in
wpt/html/canvas/offscreen/fill-and-stroke-styles
2025-10-06 12:13:31 +02:00
Andreas Kling
ce16bdd07d Revert "AK: Use HashMap::ensure() for FlyString and Utf16FlyString lookups"
This reverts commit 9425ee6d2b.

Appears to have introduced flakiness on WPT.
2025-10-06 10:07:40 +02:00
Pavel Shliak
88500580e6 LibWeb: Make getBBox() throw error for non-rendered elements
Per SVG2 spec (§ Geometry Properties: getBBox), getBBox() must throw
InvalidStateError if the element is not rendered and its geometry cannot
be computed. Previously we would crash on null paintables; now we throw
with a clear error instead.
2025-10-06 00:14:04 +02:00
Andreas Kling
46c6176235 LibJS: Cache bytecode constant strings with their Utf16String as key 2025-10-05 21:44:06 +02:00
Andreas Kling
5810ddf339 LibJS: Use HashMap::ensure() in VM string cache helpers
This cuts the number of hash lookups on cache hit from 2 to 1.
2025-10-05 21:44:06 +02:00
Andreas Kling
9425ee6d2b AK: Use HashMap::ensure() for FlyString and Utf16FlyString lookups
This consolidates sometimes-two hash lookups into always-one, which is
less work in the case where a new fly-string is introduced.
2025-10-05 21:44:06 +02:00
Andreas Kling
ca772caee6 AK: Add HashTable::ensure(hash, predicate, init_callback)
...and use it to make HashMap::ensure() do a single hash lookup instead
of three.

We achieve this by factoring out everything but the bucket construction
logic from HashTable::write_value() into a lookup_for_writing() helper
so we can use it from more places.
2025-10-05 21:44:06 +02:00
Andreas Kling
b691f4c7af LibJS: Add number-to-string cache for numbers < 1000
We are often forced to convert numbers to strings inside LibJS, e.g when
iterating over the property names of an array, but it's also just a very
common operation in general.

This patch adds a 1000-entry string cache for the numbers 0-999 since
those appear to be by far the most common ones we convert.
2025-10-05 21:44:06 +02:00
Andreas Kling
0c3f113e05 LibJS: Avoid some heap allocations in JSRopeString::resolve()
- Give piece vectors some inline capacity (for the common case of a+b)
- Pre-calculate the sum of UTF-16 code unit lengths for StringBuilder
2025-10-05 21:44:06 +02:00
Tim Ledbetter
51ea4a7e2a LibWeb: Align position-area values with the specification
This change renames the following `position-area` values:

x-self-start -> self-x-start
x-self-end -> self-x-end
y-self-start -> self-y-start
y-self-end -> self-y-end
span-x-self-start -> span-self-x-start
span-x-self-end -> span-self-x-end
span-y-self-start -> span-self-y-start
span-y-self-end -> span-self-y-end
2025-10-05 15:48:21 +01:00
Andreas Kling
15eb80cb5a LibJS: Prefer UTF-16 sources when resolving rope string to UTF-16 2025-10-05 16:39:14 +02:00
Andreas Kling
cc560a6feb LibJS: Avoid string ref-count churn in PrimitiveString::*_string_view() 2025-10-05 16:39:14 +02:00
Andreas Kling
24934ba479 LibJS: Make single-character ASCII string cache strings be Utf16String
Just another little step towards all strings being Utf16String.
2025-10-05 16:39:14 +02:00
Andreas Kling
792913e9f7 LibJS: Make PrimitiveString::create() take String/Utf16String by const&
This avoids unnecessary ref-count churn in the case where a string is
already in the VM's string cache.
2025-10-05 16:39:14 +02:00
Andreas Kling
0675c6e3cc LibJS: Make Value::to_utf16_string() avoid UTF-8 roundtrip if possible
To do this, it's not enough for to_utf16_string() to just be a wrapper
around to_string(), we have to duplicate some of the logic.
2025-10-05 16:39:14 +02:00
ayeteadoe
f4c8fd4bef LibCore+LibWebView+UI/Qt: Support TimeZoneWatcher on Windows
To detect system time zone changes on Windows, the event we need to look
for is WM_TIMECHANGE. The problem is how the callback with said message
actually gets invoked is very particular. (1) We must have an active
message pump (event loop) for the message to ever be processed. (2) We
must be a GUI application as WM_TIMECHANGE messages are seemingly sent
to top level windows only. It doesn't say that in the docs for the
event, but attempts of creating a LibTest-based application with a
message pump and a message only window and never receiving the event
point to that probably being true.

This workaround is built off the fact that Qt's message pump defined
internally in QEventDispatcherWin32::processEvents does in fact receive
WM_TIMECHANGE events, even though it is not exposed as a QEvent::Type.
Given the requirements stated above it makes sense that it works here as
the message pump is executing in a QGuiApplication context. So we use a
native event filter to hook into the unexposed WM_TIMECHANGE event and
forward it along to the on_time_zone_changed() callback.

Note that if a Windows GUI framework is done in the future, we'll have
to re-add support to ensure the TimeZoneWatcher still gets invoked.
2025-10-05 15:46:15 +02:00
ayeteadoe
ba9c8b8462 LibCore: Remove unused macOS FileWatcher implementation 2025-10-05 15:46:15 +02:00
ayeteadoe
c5d17e2796 LibUnicode: Query timezone from host config when cache is stale
icu::TimeZone::createDefault() was returning the timezone that was set
when current_time_zone() was first called or the timezone set via
set_current_time_zone().

This meant that even when the system timezone changed and we instructed
all WebContent processes to invoke
ConnectionFromClient::system_time_zone_changed(), the updated timezone
system was not being used as we fetched from icu's default timezone.

icu::TimeZone::detectHostTimeZone() gets the timezone from the current
host system configuration and ensures we are always synced with the host
if we have no timezone cache.
2025-10-05 15:46:15 +02:00
Jan Koudijs
597f04e462 Meta: Update fast_float to v8.1.0 in Flatpak manifest
Version 8.1.0 of fast_float contains a change that fixes #6205.
2025-10-05 14:41:01 +02:00
Jan Koudijs
ea178a85e1 Meta: Set option to enable baseline CPU target for CI in Flatpak
PR #6010 adds the ENABLE_CI_BASELINE_CPU option,
but for the Flatpak manifest it was missed to set the value.
This commit fixes that.
2025-10-05 14:41:01 +02:00
Andreas Kling
72ea158f16 AK: Initialize StringBuilder buffer in place
Before this change, we'd construct a ByteBuffer for the internal buffer,
and then move-construct StringBuilder::m_buffer from it.

Due to ByteBuffer's inline capacity, this meant we had to memmove the
inline buffer an extra time for every StringBuilder created.
2025-10-05 11:24:46 +02:00
Andreas Kling
1ec72de0a6 AK: Remove unnecessary StringBuilder::create() factory 2025-10-05 11:24:46 +02:00
Andreas Kling
bb93107a7d AK: Avoid redundant ASCII validation in StringBuilder::append(Utf16View)
If the UTF-16 data comes from ASCII-only storage, we can skip the ASCII
validation and save ourselves the effort.
2025-10-05 11:24:46 +02:00
Andreas Kling
b50ff02da4 AK: Skip ASCII validation in {Utf16String,String}::number() 2025-10-05 11:24:46 +02:00
Andreas Kling
1c04b6da3b AK: Make Utf16String::number(Integral) fast like String::number()
Move the fast String::number() implementation to a shareable place
so both string types can make use of it.
2025-10-05 11:24:46 +02:00
Sam Atkins
feafaf09fc LibWeb/CSS: Support converting CSSImageValue to a StyleValue
No known WPT improvements. CSSImageValue is a black box which we
implement the same as CSSStyleValue, so this may not be observably
different.
2025-10-04 22:57:00 +02:00
Sam Atkins
d855b3d90f LibWeb/CSS: Support converting CSSKeywordValue to a StyleValue
Either KeywordStyleValue or CustomIdentStyleValue depending on whether
we recognize it as a CSS::Keyword.
2025-10-04 22:57:00 +02:00
Sam Atkins
84f0f37a29 LibWeb/CSS: Implement StylePropertyMap::set()
With this commit, only direct CSSStyleValues created from internal
StyleValues can be converted back to a StyleValue. More subtests will
pass as create_an_internal_representation() is implemented for the
various CSSStyleValue subclasses. :^)

Gets us... a LOT of WPT passes, because there's a ton of coverage for
each property.
2025-10-04 22:57:00 +02:00
Sam Atkins
927ce89864 LibWeb/CSS: Make CSSStyleValue::parse_a_css_style_value() public
Needed by StylePropertyMap.
2025-10-04 22:57:00 +02:00
Sam Atkins
2f3053bc64 LibWeb/CSS: Use FlyString for StylePropertyMap property arguments
The bindings are able to give us FlyString, and that's the type we use
for property names, so let's use that instead of String.
2025-10-04 22:57:00 +02:00
Sam Atkins
7778f3b279 LibWeb/CSS: Allow setting StyleValues on CSSStyleProperties directly
This is used by StylePropertyMap - we already have verified that the
value is acceptable for the property before this point.
2025-10-04 22:57:00 +02:00
Sam Atkins
2de4fe8104 LibWeb/CSS: Store StyleValue pointer instead of string on CSSStyleValue
When setting style to a CSSStyleValue we need to convert it to a
StyleValue. If we already have one, we might as well use it avoid the
work of serialization and re-parsing.

I realised I misunderstood what "constructed from a USVString" means, so
I've adjusted based on that. It does raise a question on what the source
USVString is if that string resulted in multiple CSSStyleValues being
created - see the linked issue.
2025-10-04 22:57:00 +02:00
Sam Atkins
1e1752b33b LibWeb/CSS: Mark list-valued properties
Typed-OM requires us to have a generic way of asking "does property X
accept a list or a single value?" so this exists mainly for that.
Coordinating lists are annotated too - I'm not clear on exactly what
will be needed for those, but giving them a unique value now at the
worst will make them easier to find later.
2025-10-04 22:57:00 +02:00
Sam Atkins
b3ad4be90c LibWeb/CSS: Ensure properties can be computed from "basic" StyleValues
This commit modifies the `compute_foo()` code for `font-style` and
`math-depth`. They previously assumed that their StyleValue was always
a special kind: FontStyleStyleValue or MathDepthStyleValue. This was
always true, because that's how we parse them, but it stops being true
once StylePropertyMap is involved: An author can set font-style to a
CSSKeywordValue of "italic", and this should work.

There are multiple ways that we could solve this, but the simplest and
easiest to maintain seems to be to handle those more basic StyleValues
in this computation code. Going forward, we'll have to be aware that
similar properties could have a basic StyleValue from the typed-OM
instead of the property-specific one we'd expect.
2025-10-04 22:57:00 +02:00
Julian Dominguez-Schatz
b9153f0ca1 LibWeb/IndexedDB: Allow queryOrOptions to be null in getAllKeys
This fixes a crash on initial load of the page http://demo.actualbudget.org.
Minimal repro of the issue (error in the console without this PR):

<script>
const r = indexedDB.open("t", 1);
r.onupgradeneeded = e => e.target.result.createObjectStore("s", { keyPath: "id" });
r.onsuccess = () => r.result.transaction("s", "readonly").objectStore("s").getAllKeys();
</script>
2025-10-04 20:49:53 +02:00
Ali Mohammad Pur
31da9ab4e8 LibWasm: Take memory_fill arguments in the right order
This makes ruffle.rs work again :^)
2025-10-04 11:17:08 +02:00
Ali Mohammad Pur
353febfab6 LibWasm: Remove confusing newline after a few TAILCALLs 2025-10-04 11:17:08 +02:00
Aliaksandr Kalenik
86505a7de4 LibWeb: Remove unnecessary adjustments for transforms in hit_test()
of `PaintableBox` and `PaintableWithLines`.

If we ended up with non-identity transform in `hit_test()` of PB or PWL
and have to account for transforms, means we forgot to skip stacking
context while iterating through children.

- Add missing check to skip paintable that eastablishing a stacking
  context in `PaintableBox::hit_test_children()`
- Otherwise it mostly reverts changes done by 4070f5a7e
2025-10-03 21:49:59 +02:00
Aliaksandr Kalenik
c5da92f664 LibWeb: Try to dispatch wheel event on hit-testing target first
...before falling back to containing block. Fixes a bug when we can't
scroll innermost scrollable element, because wheel event dispatching
immediately falls back to containing block.
2025-10-03 19:34:20 +02:00
Jelle Raaijmakers
b1a7782c59 Devcontainer: Add libtool to dependencies 2025-10-03 15:00:09 +01:00
Johannes Gustafsson
e9e58d83b3 LibWeb: Add WPT tests related to XPath evaluation 2025-10-03 13:16:11 +02:00
Johannes Gustafsson
d2030a5377 LibWeb: Implement Document.evaluate and related XPath methods 2025-10-03 13:16:11 +02:00
Johannes Gustafsson
0ea519c539 LibWeb: Implement XPath functionality using libxml2 2025-10-03 13:16:11 +02:00
Johannes Gustafsson
f04b866cb0 LibWeb: Implement stubs for XPathEvaluator 2025-10-03 13:16:11 +02:00
Zaggy1024
1ae7ecc3e9 LibGfx: Free the harfbuzz buffer when measuring text width
I spotted this leak when WebContent was exiting with ASan enabled on a
page with a media element. MediaPaintable calls Gfx::Font::width(),
which calls through to measure_text_width(), which then drops an
hb_buffer_t* without freeing it.
2025-10-03 09:22:22 +02:00
Timothy Flynn
400300945f LibJS: Fill all available space when TA.copyWithin shrinks the array
This is a normative change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/d228070p
2025-10-03 09:03:40 +02:00
Timothy Flynn
a7e55f3024 LibJS: Explicitly prevent out-of-bounds access in String.lastIndexOf
This is a normative change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/541b2f6

Note we already handled this case well, but let's update our impl to
match the latest spec text.
2025-10-03 09:03:40 +02:00
Timothy Flynn
a4991143e0 LibJS: Update spec links and steps for the U8Array base64/hex proposal
This proposal reached stage 4 and was merged into ECMA-262. See:
https://github.com/tc39/ecma262/commit/3dfa316
2025-10-03 09:03:40 +02:00
Timothy Flynn
a7e5fa2256 LibJS: Update spec links and steps for the Math.sumPrecise proposal
This proposal reached stage 4 and was merged into ECMA-262. See:
https://github.com/tc39/ecma262/commit/27172c8
2025-10-03 09:03:40 +02:00
Timothy Flynn
cb56ea7e24 LibJS: Update spec links and steps for the Error.isError proposal
This proposal reached stage 4 and was merged into ECMA-262. See:
https://github.com/tc39/ecma262/commit/caa0482
2025-10-03 09:03:40 +02:00
Timothy Flynn
979761ad82 LibJS: Implement WeakMap.prototype.getOrInsert[Computed]
This is part of the Upsert proposal:
https://github.com/tc39/proposal-upsert
2025-10-03 08:58:40 +02:00
Timothy Flynn
b6924309a0 LibJS: Implement Map.prototype.getOrInsert[Computed]
This is part of the Upsert proposal:
https://github.com/tc39/proposal-upsert
2025-10-03 08:58:40 +02:00
Timothy Flynn
7d4245cf8a LibJS: Remove unnecessary call to Value::to_string_without_side_effects
This is handled internally by the throw completion formatter.
2025-10-03 08:58:40 +02:00
Timothy Flynn
853e3ecf23 LibJS: Include the WeakMap key (not value) in non-weakable key errors
It is the key that cannot be held weakly, and thus the key that should
be include in the error message.
2025-10-03 08:58:40 +02:00
Feng Yu
fd3c69227f LibWeb/HTML: Implement focus restoration in HTMLDialogElement
When a dialog is closed, restore focus to the previously focused
element if focus is within the dialog or if the dialog was modal.
2025-10-03 08:55:53 +02:00
vedant-pandey
d082e7ec58 LibJS: Move Typed Array copyWithin optimization before index update
The optimization for non-shared ArrayBuffers operates on incorrect
values of from_byte_index and to_byte_index because they will have been
modified in the preceding steps. This causes the incorrect range to be
copied within the buffer.
2025-10-02 19:41:31 +02:00
Aliaksandr Kalenik
20490d146c LibWeb/WebGL: Deduplicate read_and_pixel_convert_texture_image_source()
After we commited code produced by WebGL generator this function ended
up duplicated between WebGL 1 and 2 contexts.
2025-10-02 18:41:02 +02:00
Aliaksandr Kalenik
a6288e12e9 LibWeb/WebGL: Use TexImageSource alias in method signatures 2025-10-02 18:41:02 +02:00
Timothy Flynn
bbe254f3cb test-web: Log which WebView is running each test
When trying to repro a failed CI test, it is handy to know the order in
which test-web ran its tests. We've seen in the past that the exact
order can be important to debug flakey tests.

This adds the index of the WebView running the test to verbose log
statements (which is enabled in CI).
2025-10-02 11:12:47 -04:00
Sam Atkins
ccd9bb0286 LibWeb/CSS: Remove outdated use of PropertyID::Invalid
This doesn't exist any more, but did when I submitted the
PropertyNameAndID PR. Oops!
2025-10-02 14:25:48 +01:00
Zaggy1024
592be4ecad LibCore: Allow Promise to be resolved if it has a non-Error error type 2025-10-02 14:50:04 +02:00
Sam Atkins
e24d1ee895 WebDriver: Support custom properties in WebDriver::get_element_css_value
I noticed the existing code would end up calling
`computed_properties->property(PropertyID::Custom)`
so let's actually ask for the custom property instead.
2025-10-02 13:46:04 +01:00
Sam Atkins
561fdc0228 LibWeb/CSS: Use PropertyNameAndID in Parser::convert_to_style_property() 2025-10-02 13:46:04 +01:00
Sam Atkins
d014c6818a LibWeb/CSS: Use PropertyNameAndID in CSSSV::parse_a_css_style_value() 2025-10-02 13:46:04 +01:00
Sam Atkins
2906176500 LibWeb/CSS: Update CSS::supports() to match current spec
Also introduce usage of PropertyNameAndID.
2025-10-02 13:46:04 +01:00
Sam Atkins
ce7a8418ed LibWeb: Add and use CSSStyleProperties helpers in Algorithms code 2025-10-02 13:46:04 +01:00
Sam Atkins
2f02ccc5c1 LibWeb/CSS: Take PropertyNameAndID in in style-only CSSSD methods
StylePropertyMap only ever works with style properties - never
descriptors. Switching `has_property()` and `get_property_style_value()`
to taking PropertyNameAndID skips some duplicate work.
2025-10-02 13:46:04 +01:00
Sam Atkins
47062424fb LibWeb/CSS: Pull out and expand CSSStyleProperties::get_property()
This awkwardly sat as the internal final API for getting a StyleProperty
directly for a given PropertyID, and also the external API for getting
the StyleProperty for a PropertyID. For the latter, it lacked support
for shorthands, and for both it lacked support for custom properties.

This commit:
- Moves the code from get_property() into get_direct_property()
- Makes get_property() call get_property_internal() to support
  shorthands
- Adds custom property support for get_direct_property()

This also wins us some WPT points for StylePropertyMap.
2025-10-02 13:46:04 +01:00
Sam Atkins
8f456d781c LibWeb/CSS: Take PropertyNameAndID in get_property_internal() 2025-10-02 13:46:04 +01:00
Sam Atkins
d60c8d80e5 LibWeb: Rename CSSStyleProperties::property() -> get_property()
Verbs are nice, and `property` is too useful as a variable name.
2025-10-02 13:46:04 +01:00
Sam Atkins
38664cb79f LibWeb/CSS: Use PropertyNameAndID in CSSSP::set/remove_property()
This saves the PropertyID overloads from converting the ID to a string,
and then back to an ID again.
2025-10-02 13:46:04 +01:00
Sam Atkins
a30afafcc9 LibWeb/CSS: Use FlyString for CSSStyleValue property name 2025-10-02 13:46:04 +01:00
Sam Atkins
a8312bf571 LibWeb/CSS: Use FlyString const& for property name IDL parameters 2025-10-02 13:46:04 +01:00
Sam Atkins
37fa6459fb LibWeb/Editing: Use PropertyID CSSStyleProperties overloads 2025-10-02 13:46:04 +01:00
Sam Atkins
c0ef7f09e4 LibWeb/CSS: Use PropertyNameAndID instead of old Variant 2025-10-02 13:46:04 +01:00
Sam Atkins
3af8e705c1 LibWeb/CSS: Introduce a PropertyNameAndID type
We often want to call a function with either a built-in or custom
property, and that means either passing it as a string (and converting
back and forth between strings and PropertyIDs) or using the
PropertyIDOrCustomPropertyName variant, which complicates user code.
PropertyNameAndID is intended to make that easier: Create it with a
string or PropertyID, and it can tell you either one.
2025-10-02 13:46:04 +01:00
Sam Atkins
89c89470ef LibWeb/CSS: Stop rejecting declarations with vendor-prefixed keywords
property_accepts_type() only looks at the property itself, not any
longhands it might have, so we thought that `font` didn't accept
`<custom-ident>`s, and seeing "-apple-..." makes us throw out the
declaration even though it's valid as a font name.

We'll reject these like any other unrecognized value if it's somewhere
that's not supported, so this was really just an optimization for a
rare edge case, and removing the check doesn't have any observable
effect except fixing this bug and any similar cases.

Changing property_accepts_type() to look at longhands is not
straightforward, as not all longhand values are valid in the shorthand.
2025-10-02 13:26:26 +02:00
aplefull
b3bdb202f8 LibGfx: Allow decoding of GIFs with empty LZW data
The decoder was requiring GIF files to be at least 32 bytes, but the
actual minimum for a valid GIF is only 26 bytes:
- 6 bytes for the header
- 7 bytes for the Logical Screen Descriptor
- 10 bytes for the Image Descriptor
- 2 bytes for the LZW minimum code size and block terminator
- 1 byte for the GIF trailer

This change allows us to load minimal 1x1 GIFs with empty LZW data.
They are commonly used on the web as transparent placeholders with
minimal file size.
2025-10-02 11:04:35 +02:00
Zaggy1024
30d4810d70 LibMedia: Actually read Matroska tracks' CodecDelay elements 2025-10-02 11:03:26 +02:00
Zaggy1024
ce228663f1 LibMedia: Rename Matroska TRACK_CODEC_PRIVATE to TRACK_CODEC_PRIVATE_ID 2025-10-02 11:03:26 +02:00
rmg-x
b9554038ff LibWeb+LibXML: Make Listener::set_source(ByteString) fallible
`set_source` takes a ByteString but the implementation might require a
specific encoding. Make it fallible so that we don't need to crash in
the case of invalid UTF-8 or similar.

The test includes a sequence of invalid UTF-8 bytes that crash the
browser without this change.
2025-10-02 02:25:28 +02:00
Ali Mohammad Pur
2397ae4af5 LibWasm: Use [[gnu::musttail]] on new-enough GCC versions
This is supported starting GCC 15.
The warning -Wmaybe-musttail-local-addr complained about &value possibly
escaping (it cannot, but gcc is being pessimistic about
store_to_memory), so a little rearrangement of that function was
necessary.
2025-10-01 23:47:29 +02:00
Ali Mohammad Pur
15bb9fee71 AK: Use OOB pointer for "empty" last-fast-access Vector last ptr
This is a _significant_ perf improvement as we no longer have to think
about tracking state transitions from empty <-> nonempty.
(corresponds to a ~20% perf improvement in LibWasm)
2025-10-01 23:47:29 +02:00
Ali Mohammad Pur
02b3c4f8a9 LibWasm: Utilise direct threading if/when possible
~50% performance improvement on coremark.
2025-10-01 23:47:29 +02:00
Ali Mohammad Pur
cf30d61d8b LibWasm: Use a faster way to detect live registers
Instead of doing a naive O(n^2) liveness detection loop, use a bitmap
for values allocated to registers.
This cuts down validating time from 20% to 1.4% of runtime on the same
game as last commit.
2025-10-01 23:47:29 +02:00
Ali Mohammad Pur
c0223befe1 LibWasm: Avoid frequent re/deallocations while validating expressions
Freeing and reallocating these vectors was ~6% of runtime when
validating some web-based game.
2025-10-01 23:47:29 +02:00
Ali Mohammad Pur
80e5356853 AK: Add Vector::remove_all(container)/remove_all(it, end)
Instead of repeatedly removing elements off the vector, this allows for
specifying all the removed indices at once, and does not perform any
extra reallocations or unnecessary moves.
2025-10-01 23:47:29 +02:00
Aliaksandr Kalenik
93d7efa4c3 LibIPC: Delete unused code in Connection 2025-10-01 14:59:23 -04:00
Jelle Raaijmakers
a5697b4796 LibWeb: Remove unused fields from BrowsingContext
These were introduced in 83c5ff57d8, but
we stopped using them. No functional changes.
2025-10-01 07:21:54 -04:00
Tim Ledbetter
c79063a77d LibWeb: Convert blend test to use rectangle rather than circle
Using a circle isn't relevant to the outcome of the test and introduces
anti-aliasing artifacts.
2025-09-30 22:33:12 +01:00
Tim Ledbetter
a00e7cb20b LibWeb: Implement <feComposite> SVG filter 2025-09-30 22:33:12 +01:00
Sam Atkins
bbfc3a0f5e LibWeb/CSS: Use a bitfield for Containment flags
Shrinks the struct down from 5 bytes to 1.
2025-09-30 22:05:45 +01:00
Sam Atkins
3916e33276 LibWeb/CSS: Parse the container-type property
This applies size, inline-size, and style containment in some cases.
There are other WPT tests for that, but we seem to not implement enough
of containment for this to have an effect so I've not imported those.

Gets us 35 WPT subtests.
2025-09-30 22:05:45 +01:00
Sam Atkins
b0bb775c05 LibWeb/CSS: Remove unnecessary CSS:: namespaces from ComputedValues.h
These are just visual noise.
2025-09-30 22:05:45 +01:00
Aliaksandr Kalenik
ffc05a9ca9 LibWeb/WebGL: Define Uint32List exactly like in the spec
Same fix as d54cab60 but applied for Uint32List.
2025-09-30 18:35:32 +02:00
Aliaksandr Kalenik
c75a8fab3b LibWeb/WebGL: Define Int32List exactly like in the spec
Same fix as d54cab60 but applied for Int32List.
2025-09-30 17:57:46 +02:00
Aliaksandr Kalenik
655cd339a7 LibWeb/WebGL: Move Float32List -> Span<float> conversion into helper
This allows to remove lots of duplicated code.
2025-09-30 16:47:16 +02:00
Aliaksandr Kalenik
d54cab60a8 LibWeb/WebGL: Define Float32List exactly like in the spec
Use `Float32Array or sequence<GLfloat>` instead of
`BufferSource or sequence<GLfloat>`. This meaningfully changes behavior
for `Float16Array` and `Float64Array`: they are now converted to
`sequence<GLfloat>` by iterating the typed array, rather than being
treated as a `BufferSource`. As a result, many WebGL calls now work
correctly where we previously crashed in `VERIFY_NOT_REACHED()` due to
the assumption that a `BufferSource` was always a `Float32Array`.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/5962
2025-09-30 16:47:16 +02:00
Aliaksandr Kalenik
22075c08e4 BindingsGenerator: Return the exact typed array member type for unions
Allows definition of:
`typedef (Float32Array or sequence<GLfloat>) Float32List;`

which did fail to compile before, because `GC::Root<JS::Object>` fails
to implicitly cast into
`AK::Variant<GC::Root<JS::Float32Array>, AK::Vector<float>>`.
2025-09-30 16:47:16 +02:00
Sam Atkins
a098b5fcc4 LibWeb/CSS: Remove PropertyID::Invalid 2025-09-30 15:21:09 +02:00
Sam Atkins
56c7d838f0 LibWeb/CSS: Stop using PropertyID::Invalid in border parsing 2025-09-30 15:21:09 +02:00
Sam Atkins
7d4b2d10e4 LibWeb/CSS: Remove default value for parse_css_value() PropertyID
Every user provides this, and it's not clear what passing
PropertyID::Invalid here actually means.
2025-09-30 15:21:09 +02:00
Tim Ledbetter
3299ea97c6 LibWeb: Treat word-wrap as an alias for overflow-wrap 2025-09-30 13:50:53 +01:00
Tomasz Strejczek
a010557205 LibCore: Remove DateTime
Remove DateTime and its dependencies as it's not longer used.
2025-09-30 12:39:01 +02:00
Tomasz Strejczek
6fc4c544de LibIPC: Remove DateTime encoder/decoder
Remove LibCore::DateTime encoder/decoder as it is not longer needed.
2025-09-30 12:39:01 +02:00
Tomasz Strejczek
27dfaea32f LibWeb: Replace DateTime::parse with UnixDateTime::parse
Replace LibCore::DateTime::parse with UnixDateTime::parse. Add
conversion from UTC to local time zone.
2025-09-30 12:39:01 +02:00
Tomasz Strejczek
5f12d34d13 LibDNS: Remove LibCore::DateTime dependency
Replace LibCore::DateTime Formatter with AK::UnixDateTime's Formatter.
2025-09-30 12:39:01 +02:00
Tomasz Strejczek
5cde267979 AK: Implement Formatter<UnixDateTime>
Implement StringBuilder's Formatter<UnixDateTime>. Add necessary tests.
2025-09-30 12:39:01 +02:00
Tomasz Strejczek
ea32e39d68 AK: Add UnixDateTime::parse() method
Copy parse() method from LibCore::DateTime::parse(). Augment the method
to handle parsing from GMT time. Fix incorrect handling of year in '%D'
format specifier. Remove all format specifiers related to time zones.
Copy relevant tests and add additional ones.
2025-09-30 12:39:01 +02:00
luizgfc
820fee434e LibWeb: Import WPT test about custom property resolution precedence 2025-09-30 09:54:10 +01:00
luizgfc
82bddd5209 Tests: Important custom properties precedence on resolution 2025-09-30 09:54:10 +01:00
luizgfc
13748a8c19 LibWeb: Make Custom Properties cascading consider !important
Make so that !important properties are always applied last, prioritizing
them over normal properties
2025-09-30 09:54:10 +01:00
R-Goc
71c8ee31fb Docs: Recommend the standard git workflow
The standard workflow for working with forks is to clone the fork and
add the main repository as upstream. Also recommend using git switch
instead of checkout.
2025-09-30 08:43:38 +02:00
Pascal Pomper
5b1eba7ac8 LibWeb: Position absolute block-level boxes below previous siblings
Whether an absbox is positioned below or to the right of its previous
sibling in an `InlineFormattingContext` is determined by the
display-outside value before blockification, so we store the
pre-blockification `display` value in `ComputedValues` to access it in
`InlineFormattingContext` and position the box accordingly.
2025-09-29 18:37:53 +02:00
Andreas Kling
7867fef8d7 LibWeb: Use correct width for flex item intrinsic height calculation
Before this change, we always used the flex container's full available
space as the width for intrinsic (height) sizing of flex items.

This meant that flex lines with more than one flex item had their
intrinsic height determined as if they were alone on the line.

For flex row layouts, if we've already determined the flex item's main
size, we now use that as the width to get the intrinsic height.

This leads to more correct layouts, and also avoids some redundant work
since we no longer do unnecessary sizing work with the wrong width (and
can hit cache instead).
2025-09-29 13:27:58 +02:00
Andreas Kling
6ec10a5408 LibWeb: Make more FlexFormattingContext functions take FlexItem
...instead of taking the Layout::Box. This will allow us to make more
nuanced decisions in those functions by having access to flex layout
internal state.
2025-09-29 13:27:58 +02:00
Tim Ledbetter
fda5ea8277 LibWeb: Correctly resolve position-area computed value 2025-09-29 12:48:13 +02:00
Tim Ledbetter
eb571a1a46 LibWeb: Parse the position-area property 2025-09-29 09:53:27 +02:00
Rocco Corsi
12bb266bf2 Documentation: Add libtool to openSUSE dependencies
Provide help with out-of-date openSUSE packages.

Update the libpulse-devel and qt6-multimedia-devel instructions
when dynamic linking errors are encountered.
2025-09-28 21:30:34 -04:00
Andreas Kling
f00f975cf4 LibWeb: Treat percentage max-width as none during min-content sizing
...but only for non-replaced boxes. This is what CSS-SIZING-3 tells us
to do, and we were already doing it for width, but neglecting max-width.
2025-09-28 19:25:18 +02:00
Andreas Kling
652e52d76a LibWeb: Get ResizeObserver::m_document from Window directly
We don't have to go via the window's navigable to find the document
we're being created for. It's right there on the window.
2025-09-28 19:25:18 +02:00
Andreas Kling
d36e5098f8 LibWeb: Support percentage attributes on SVG rect element
This makes the IMDb logo have a yellow background as expected.
2025-09-28 19:25:18 +02:00
Callum Law
99dd648475 LibWeb: Disallow ASF in DOMMatrix constructor
We have no context to resolve ASFs against here so we should throw.
2025-09-28 17:43:25 +02:00
Tim Ledbetter
bf1564388d LibWeb: Serialize grid-template shorthand correctly 2025-09-28 17:34:58 +02:00
Timothy Flynn
cb6ca85564 LibJS: Handle relativeTo ZDTs that fall within second DST wallclock time
This is a normative change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/1a089eb
2025-09-28 11:33:43 -04:00
Rocco Corsi
1ecb78897f Documentation: Add 'libtool' & 'perl-Time-Piece` to fedora dependencies 2025-09-28 11:26:10 -04:00
Rocco Corsi
adc78e9d54 LibJS: Correct line ending detection in debug output 2025-09-28 11:23:41 -04:00
Pavel Shliak
fb97fde15b Meta: Fix libjs-test262 CI workflow
libtool is required to build gperf
2025-09-28 11:22:55 -04:00
Tim Ledbetter
b2591309d6 LibWeb: Use preferred style for swift guard case clause
This stops `swift-format` complaining.
2025-09-27 20:38:47 +01:00
Sam Atkins
11a6b6f38f LibDevTools: Don't assume computed layout values are strings
Width and height are doubles, so get_string() will return nothing and
fail. We just want a JsonValue here without caring what type it is, so
let's just use get() instead.
2025-09-26 22:31:24 +02:00
Sam Atkins
b8fa9ac7e7 WebContent: Expose custom properties to DevTools
ComputedProperties doesn't contain custom properties, at least at the
moment. So, we have to iterate them separately.
2025-09-26 22:31:07 +02:00
Sam Atkins
1ccf37a6ac LibWeb/CSS: Expose StyleProperty outside of LibWeb 2025-09-26 22:31:07 +02:00
Sam Atkins
aa8bf6372f LibWeb/CSS: Inline EasingStyleValue::CubicBezier::operator==()
For whatever reason, this method in particular ends up failing to link
into WebContent with a subsequent change. It's small and simple, so
just inline it.
2025-09-26 22:31:07 +02:00
Sam Atkins
3d141ac6a1 LibDevTools: Compare StyleSheetIdentifiers using operator==
We were ignoring the dom_element_unique_id field, which meant if we had
more than one inline style sheet on a page, we would not distinguish
between them. This had the effect of halting the style sheet loading
process in the dev tools, with none appearing.
2025-09-26 22:30:20 +02:00
Sam Atkins
9ebdb58604 LibWeb/CSS: Add operator== to StyleSheetIdentifier
Only the rule count isn't part of identifying the style sheet.
2025-09-26 22:30:20 +02:00
Sam Atkins
f17317b7fc LibDevTools: Annotate style sheets how Firefox expects
Mark UA style sheets as "system", which makes them read-only in the
Firefox dev tools. Also give them an href with a fake resource:// URL so
that they don't appear as "<inline style sheet>", and don't set the href
for actual inline style sheets, for the opposite reason.

I've kept the title for UA style sheets, because that means we see
`Thing/Default.css` instead of just `Default.css` for all of them.
2025-09-26 22:30:20 +02:00
Aliaksandr Kalenik
086ef9e339 LibWeb: Delete unused Paintable::combined_css_transform() 2025-09-26 20:11:32 +02:00
Callum Law
c4d6deb5c7 LibWeb: Parse widows CSS property 2025-09-26 16:32:54 +01:00
Callum Law
3d85532752 LibWeb: Parse orphans CSS property 2025-09-26 16:32:54 +01:00
Jan Koudijs
937f598de5 Meta: Update simdutf to v7.4.0 in Flatpak manifest 2025-09-26 17:23:53 +02:00
Aliaksandr Kalenik
e07bb32455 LibJS+LibWeb: Add Object::fast_is<Element>() 2025-09-26 16:21:18 +02:00
Aliaksandr Kalenik
88d8380920 LibJS: Add FunctionObject::fast_is<NativeFunction>() 2025-09-26 16:21:18 +02:00
Aliaksandr Kalenik
b549d51cdc LibJS: Add Object::fast_is<Set>() and Object::fast_is<Map>()
These are often hit by object serialization code path.
2025-09-26 16:21:18 +02:00
Aliaksandr Kalenik
aec20e032b LibJS: Add FunctionObject::fast_is<BoundFunction>() 2025-09-26 16:21:18 +02:00
Tim Ledbetter
e1e7007707 Documentation: Add libtool as a dependency on Ubuntu 2025-09-26 13:45:45 +01:00
Tim Ledbetter
b64cb89b9d LibWeb: Implement compositing of font-variation-settings values 2025-09-26 11:20:54 +01:00
Tim Ledbetter
f9452b77b7 LibWeb: Implement interpolation of font-variation-settings values 2025-09-26 11:20:54 +01:00
Tim Ledbetter
83ad5ce8a2 LibWeb: Don't deduplicate font-variation-settings values at parse time
We now only deduplicate and sort the computed value of the
`font-variation-settings` property.
2025-09-26 11:20:54 +01:00
Tim Ledbetter
6cb0f0fbcd LibWeb: Ensure large animation progress values don't overflow 2025-09-26 11:20:54 +01:00
Tim Ledbetter
d18d40f7b9 LibWeb: Handle interpolation of grid track size lists
This allows the `grid-template-rows` and `grid-template-columns`
properties to be correctly interpolated.
2025-09-26 11:15:08 +01:00
Tim Ledbetter
436e9c317a LibWeb: Extract commonly used interpolation lambdas into methods 2025-09-26 11:15:08 +01:00
Tim Ledbetter
f438c1721c LibWeb: Add GridTrackSize constructor that initializes values explicitly 2025-09-26 11:15:08 +01:00
Tim Ledbetter
56d5177eda LibWeb: Add length percentage getter to CSS::Size 2025-09-26 11:15:08 +01:00
Tim Ledbetter
d9b66b22a6 LibWeb: Add type getter to CSS::Size 2025-09-26 11:15:08 +01:00
Callum Law
9ee9be720c LibWeb: Collapse & trim whitespace when serializing UnresolvedStyleValue 2025-09-26 07:30:10 +01:00
InvalidUsernameException
a405d6df67 Meta: Update sdl to version 3.2.22 2025-09-25 21:14:29 -04:00
InvalidUsernameException
e12ae7c7c2 Meta: Update openssl to version 3.5.3 2025-09-25 21:14:29 -04:00
InvalidUsernameException
237b2a76e1 Meta: Update libwebp to version 1.6.0#1 2025-09-25 21:14:29 -04:00
InvalidUsernameException
e3a81d520d Meta: Update ffmpeg to version 7.1.1#5 2025-09-25 21:14:29 -04:00
InvalidUsernameException
2dd1918b10 Meta+Tests: Update fast-float to version 8.1.0
This release comes with a fix for a bug where certain unicode emoji
characters encoded in UTF-16 were mistakenly parsed as integers. This
manifested in keys of an JS object being coerced into integers, i.e.
`{ "⤵️": 42 }` would become `{ "5": 42 }`.

Relevant upstream PR: https://github.com/fastfloat/fast_float/pull/325
2025-09-25 21:14:29 -04:00
InvalidUsernameException
c6ece554ba Meta: Update dirent to version 1.26.0 2025-09-25 21:14:29 -04:00
InvalidUsernameException
7f5d694853 Meta: Update dbus to version 1.16.2#2 2025-09-25 21:14:29 -04:00
InvalidUsernameException
5917c7f6fa Meta: Update curl to version 8.16.0 2025-09-25 21:14:29 -04:00
InvalidUsernameException
a975988f9c Meta: Update vcpkg baseline 2025-09-25 21:14:29 -04:00
Psychpsyo
4e0abaaede LibWeb: Don't assume ImageBox's image provider is the DOM node
This gets rid of the assumption that the DOM node of an ImageBox is
also its image provider. This will become necessary when generating
the image boxes for view transition pseudos, for which the DOM node
won't be the image provider. (that'll be the pseudo element itself)
2025-09-25 22:38:05 +01:00
Andreas Kling
321809320b LibWeb+LibGfx: Remove Path::close_all_subpaths()
As it turns out, SkPath already behaves the way we need for SVG and HTML
canvas elements. Less work for us, yay! This removes a 5% item from the
profile when scrolling on https://imdb.com/

Note that there's a tiny screenshot test expectation change due to
minor antialiasing differences when we no longer do our redundant
subpath modifications.
2025-09-25 21:42:52 +02:00
Andreas Kling
989f6ddb42 LibWeb: Add fast_is<T> for hotly dynamic_cast'ed things on imdb.com 2025-09-25 21:42:52 +02:00
Psychpsyo
2fcacd21f5 LibWeb: Compute bounds for paint-contained stacking contexts
This makes it so that the bounds for any paint-contained stacking
context are not derived from its children, but rather just set to
the rectangle that they will be clipped to anyways due to the paint
containment. Should make rendering faster on pages that use paint
containment.
2025-09-25 15:10:10 +02:00
Sam Atkins
d9ed784f92 Tests: Add the hidden-img hack to a couple of flaky tests
Editing a WPT import feels wrong because fixing the bug would be better,
but flaky CI helps nobody.
2025-09-25 10:35:28 +01:00
Sam Atkins
c3fd21b0ba Tests: Disable a few tests that regularly flake on CI 2025-09-25 10:35:28 +01:00
Tim Ledbetter
585e96d61d LibWeb: Escape custom-ident when serializing grid track placement values 2025-09-25 10:34:45 +01:00
Tim Ledbetter
d42235a642 LibWeb: Use move() for grid track placement values where possible 2025-09-25 10:34:45 +01:00
Aliaksandr Kalenik
90432f35d5 LibWeb: Call saveLayer() after applying matrix in PushStackingContext
This is required because bounding rect used in `saveLayer()` is computed
in stacking context's coordinate space.

Fixes regression introduced in ba2926f
2025-09-25 04:39:26 +02:00
Rocco Corsi
892e75ddfb LibCore: Fix ThreadedPromise issues found with ThreadSanitizer 2025-09-24 21:05:54 -05:00
Andreas Kling
ec73299398 LibWeb: Resolve paint-only properties in SVGPathPaintable once
Instead of resolving some viewport-relative sizes on every paint, we now
do them just once in paint-only property update.

This takes SVGPathPaintable::paint() from 15% to 8% in the profile when
scrolling on https://imdb.com/
2025-09-24 23:59:41 +02:00
Andreas Kling
eff9989aeb LibWeb: Only update paint-only properties in affected subtrees
Before this change, we always updated paint-only properties for every
single paintable after layout or style changes.

This could get very expensive in large documents, so this patch makes
it something we can do partially based on "repaint" invalidations.

This cuts down time spent in paint-only property update when scrolling
https://imdb.com/ from 19% to 5%.
2025-09-24 23:59:41 +02:00
Andreas Kling
beb70d2112 LibWeb: Add Paintable::debug_description()
I keep reimplementing this function over and over when debugging stuff,
so let's just have it around.
2025-09-24 23:59:41 +02:00
Andreas Kling
4b281fa880 LibWeb: Make Length ctor/dtor/factory inline
These functions are trivial, and we were actually bleeding a lot of time
in profiles to just function entry/exit.

By marking Length::make_px() as [[nodiscard]], we also exposed some
places that were creating a Length and not using it for anything.
2025-09-24 23:59:41 +02:00
Andreas Kling
fab96ff805 LibWeb: Don't flag ComputedValues for non-initial border radii too soon
Before this change, we were basically always setting the non-initial
border radii flag on ComputedValues, which made the work-avoiding
optimization based on this flag ineffective.
2025-09-24 23:59:41 +02:00
Andreas Kling
2e0dff420e LibWeb: Use move() in ComputedValue setters where applicable
This avoids copy-constructing various expensive temporaries.
2025-09-24 23:59:41 +02:00
Aliaksandr Kalenik
ba2926f8b3 LibWeb: Calculate and use bounds for "simple" stacking contexts
Teach the display list executor to derive a bounding rectangle for
stacking contexts whose inner commands can all report bounds, that is,
most contexts without nested stacking contexts.

This yields a large performance improvement on https://tc39.es/ecma262/
where the display list contains thousands of groups like:
```
PushStackingContext blending=Multiply
    DrawGlyphRun
PopStackingContext
```
Previously, `PushStackingContext` triggered an unbounded `saveLayer()`
even when the glyph run lies wholly outside the viewport. With this
change, we (1) cull stacking contexts that fall outside the viewport and
(2) provide bounds to `saveLayer()` when they are visible.

With this change rendering thread goes from 70% to 1% in profiles of
https://tc39.es/ecma262/. Also makes a huge performance difference on
Discord.
2025-09-24 22:11:24 +02:00
Sam Atkins
4acde45d5e LibWeb/CSS: Remove now-unused non-spec calc() resolution code
We're now fully using the simplification algorithm to produce calc
results.
2025-09-24 16:33:53 +01:00
Sam Atkins
0314606c73 LibWeb/CSS: Replace resolve_length_deprecated() with resolve_length() 2025-09-24 16:33:53 +01:00
Sam Atkins
995b7eb7b4 LibWeb/CSS: Replace resolve_percentage_deprecated() with undeprecated 2025-09-24 16:33:53 +01:00
Sam Atkins
0dba531772 LibWeb/CSS: Replace resolve_number_deprecated() with resolve_number() 2025-09-24 16:33:53 +01:00
Sam Atkins
d9a386fa81 LibWeb/CSS: Replace resolve_integer_deprecated() with resolve_integer() 2025-09-24 16:33:53 +01:00
Sam Atkins
0ff012d3f3 LibWeb/CSS: Replace resolve_time_deprecated() with resolve_time() 2025-09-24 16:33:53 +01:00
Sam Atkins
7428a8eb40 LibWeb/CSS: Replace resolve_resolution_deprecated() with undeprecated 2025-09-24 16:33:53 +01:00
Sam Atkins
7f237b3e62 LibWeb/CSS: Replace resolve_frequency_deprecated() with undeprecated 2025-09-24 16:33:53 +01:00
Sam Atkins
cd29111b36 LibWeb/CSS: Replace resolve_flex_deprecated() with resolve_flex() 2025-09-24 16:33:53 +01:00
Sam Atkins
375e32c523 LibWeb/CSS: Replace resolve_angle_deprecated() with resolve_angle()
Gets us some WPT passes. 🎉
2025-09-24 16:33:53 +01:00
Sam Atkins
525b5bf623 Tests: Update empty-editable-shows-cursor expectation file
Somehow this went out of sync between it running on CI and getting
merged.
2025-09-24 13:45:59 +01:00
zac
8c29b0a848 LibWeb/Tests: Add empty text chunk in empty editables
Otherwise the cursor won't get rendered in empty input fields.
2025-09-24 12:33:17 +01:00
zac
152711958e LibWeb: Add const where possible in InlineLevelIterator 2025-09-24 12:33:17 +01:00
zac
fca2d71b16 LibWeb: Set is_first_chunk to false as needed in InlineLevelIterator
`m_text_node_context->is_first_chunk` was always true because
`InlineLevelIterator::next_without_lookahead` never set it to false.
2025-09-24 12:33:17 +01:00
zac
191b026c9f LibWeb: Rename is_generated to is_generated_for_pseudo_element
While much longer, this better conveys the intent. Since this method
isn't used too often, I think the extra length is worth it.
2025-09-24 12:33:17 +01:00
zac
e96122a58c LibWeb: Remove redundant for_each_fragment method in PaintableBox 2025-09-24 12:33:17 +01:00
Sam Atkins
b24b00fb7d LibWeb/CSS: Reify CSSTransformValues
We have a slightly odd setup here. TransformationStyleValue reifies as a
single CSSTransformComponent. It's StyleValueList that actually reifies
as a CSSTransformValue - but only if it only contains
TransformationStyleValues.

+79 WPT subtests.
2025-09-24 12:27:05 +01:00
Sam Atkins
d5977b9f74 LibWeb/CSS: Implement CSSTransformValue
This is the final CSSStyleValue class used by the per-property test
harness, so those now actually run instead of throwing an exception on
load. 🎉

+39 WPT subtests. (Plus however many from the per-property tests finally
running.)

The two failing serialization tests are also failed by Safari in exactly
the same way, so that seems more like a spec issue. (The spec is
incomplete in quite a few places.) The failing subtest for toMatrix() is
also a spec issue: is2D is handled oddly by CSSMatrixComponent and this
subtest fails because of the `matrix` getter, which is unspecified. See
https://github.com/w3c/css-houdini-drafts/issues/1155 for details.
2025-09-24 12:27:05 +01:00
Sam Atkins
3269937e6d LibWeb/Geometry: Add a method to multiply a DOMMatrix by a DOMMatrix
This will be needed by CSSTransformValue.
2025-09-24 12:27:05 +01:00
Sam Atkins
d3d695e9d2 LibWeb/CSS: Make CSSStyleValue.to_string() return ExceptionOr
DOMMatrix.to_string() throws exceptions if any of its values are
non-finite. This ends up affecting CSSStyleValue because its subclass
CSSTransformValue (which is about to be added) serializes
CSSTransformComponents, and one of those is CSSMatrixComponent, which
calls DOMMatrix.to_string().

This is all quite unfortunate, and because at the time the spec for
DOMMatrix was written, CSS couldn't represent NaN or infinity. That's
no longer true, so I'm hoping the spec can be updated and this can be
reverted. https://github.com/w3c/fxtf-drafts/issues/611
2025-09-24 12:27:05 +01:00
Sam Atkins
a1db5e7789 LibWeb/CSS: Implement CSSMatrixComponent
Equivalent to the matrix() and matrix3d() transform functions.

+19 WPT subtests.
2025-09-24 12:27:05 +01:00
Sam Atkins
2ffbb284f2 LibWeb/CSS: Implement CSSPerspective
Equivalent to the perspective() transform function.

+34 WPT subtests, and the transformvalue-normalization test now runs to
completion instead of throwing an error - though its cases still fail
until CSSTransformValue is implemented.
2025-09-24 12:27:05 +01:00
Sam Atkins
68ceacb0c5 LibWeb/CSS: Implement CSSKeywordish type 2025-09-24 12:27:05 +01:00
Sam Atkins
da883877f5 LibWeb/CSS: Implement CSSSkewY
Equivalent to the skewY() transform function.

+27 WPT subtests.
2025-09-24 12:27:05 +01:00
Sam Atkins
b0cc1c6406 LibWeb/CSS: Implement CSSSkewX
Equivalent to the skewX() transform function.

+27 WPT subtests.
2025-09-24 12:27:05 +01:00
Sam Atkins
161e384521 LibWeb/CSS: Implement CSSSkew
Equivalent to the skew() transform function.

+39 WPT subtests.
2025-09-24 12:27:05 +01:00
Sam Atkins
456946368e LibWeb/CSS: Implement CSSScale
Equivalent to the scale() transform functions.

+33 WPT subtests.
2025-09-24 12:27:05 +01:00
Sam Atkins
d348d8d9b8 LibWeb/CSS: Implement CSSRotate
Equivalent to the rotate() transform functions.

+39 WPT subtests.
2025-09-24 12:27:05 +01:00
Sam Atkins
c7d22d8cfd LibWeb/CSS: Implement CSSTranslate
Equivalent to the translate() transform functions.

+34 WPT subtests.
2025-09-24 12:27:05 +01:00
Sam Atkins
8e86bf2dd0 LibWeb/CSS: Implement CSSTransformComponent
This is a base type for the various transform functions.

CSSMatrixComponent's to_string() can throw exceptions, so to_string() is
implemented that way. https://github.com/w3c/fxtf-drafts/issues/611

+9 WPT subtests.
2025-09-24 12:27:05 +01:00
Callum Law
43dd0f2dda LibWeb: Properly clamp interpolated opacity values
Opacity values are unique in that the range which calculated and
interpolated values should be clamped to [0,1] is different from the
range of allowed values [-∞,∞].

This fixes 28 WPT tests that were regressed in #6112
2025-09-24 12:01:52 +01:00
Callum Law
517e3f5f1d LibWeb: Serialize animation according to spec
We now:
 - Serialize longhands in the correct order
 - Support serializing multiple values
 - Include default longhands where required (to distinguish
   animation-name from that longhand).
2025-09-24 11:58:20 +01:00
Callum Law
869442c206 LibWeb: Parse animation shorthand as comma separated list
We now parse (but don't yet trigger animations for) multiple definitions
within a single animation property.
2025-09-24 11:58:20 +01:00
Callum Law
2ff1ae6155 LibWeb: Escape serialized custom idents 2025-09-24 11:58:20 +01:00
Callum Law
c5e6e4fd95 LibWeb: Use custom_ident method for getting @font-face font-family
`CustomIdentStyleValue::to_string` will be updated to return the escaped
value in a future commit but we want to use the unescaped value here.
2025-09-24 11:58:20 +01:00
Callum Law
ce4a24eec5 LibWeb: Store animation-name in ComputedProperties in computed form 2025-09-24 11:58:20 +01:00
Callum Law
030e6d7c9b LibWeb: Parse animation-* properties as comma separated lists
We are yet to actually support having more than one value but this gets
us closer and gains us some WPT tests in the process.
2025-09-24 11:58:20 +01:00
Callum Law
4fd57f90b3 LibWeb: Apply animations after computing property values
We were unnecessarily computing property values within
`collect_animation_into` which we can avoid by ensuring that all calls
to `collect_animation_into` happen after property values are computed.
2025-09-24 11:58:20 +01:00
Callum Law
4f5feaf3b6 Tests: Import a bunch of animation property parsing tests
Done in a distinct commit to show progress over following commits
2025-09-24 11:58:20 +01:00
Shivendra Kumar
4221a18974 LibWeb: Fix typo "folowing" → "following" 2025-09-24 11:54:42 +01:00
Niccolo Antonelli Dziri
a72b0c29bb LibWeb: Add a simplified Notification constructor
This allows the Notification object to be created in javascript without
any additional functionalities.

It passes two wpt tests which require a call to the notification
constructor with no arguments.

https://wpt.live/notifications/constructor-basic.https.html

https://wpt.live/notifications/constructor-invalid.https.html
2025-09-24 11:53:14 +01:00
Tim Ledbetter
0aec8912c9 LibWeb: Remove special casing for font oblique angle from CSS parser 2025-09-24 11:40:38 +01:00
Tim Ledbetter
27de4fdcea LibWeb: Clamp interpolated font-style angle
This change adds the allowed angle range to the `font-style` property
definition. This allows these angles to be clamped after interpolation.

Ideally, the generator should be updated so that we can specify the
angle is in degrees. This would allow us to make use of this
information during parsing, which we can't do currently because we
don't know what the unit is. Using this value for interpolation
purposes is fine because the angle has been converted to its canonical
unit by this point.
2025-09-24 11:40:38 +01:00
InvalidUsernameException
9d7689ecd8 LibWeb: Do not stomp over content size of SVGs
When displaying SVGs inside a navigable directly, we want to display
them in the size specified by their width and height attributes instead
of stretching them to the viewport as layout normally would.

However, when doing so, we need to actually check that the SVG we are
laying out is indeed directly inside the navigable. Otherwise we just
blindly overwrite whatever content sizes have been calculated by layout
code for e.g. SVG elements inlined somewhere in an HTML document.

Due to the way this was written originally, the bug was not very
noticable. The code overwrote the content width/height with the computed
width/height, which was often still correct in the sense that those two
had the same value. However, content size may also be the result of
{min,max}-{width,height} constraints, which can make it differ from the
computed values.

This bug was likely a regression introduced in
f5e01192cc.
2025-09-24 11:25:43 +01:00
me-it-is
b76f1fb011 AK: Fix is_within_range when converting from float
Within range now uses the max capacity of a type rather than its size.
This fixes some subtests in
https://wpt.fyi/results/wasm/core/conversions.wast.js.html?product=ladybird
2025-09-24 10:40:24 +01:00
Julian Dominguez-Schatz
193163be2f Tests: Add test for credentials flag in fetch 2025-09-24 10:12:56 +01:00
Julian Dominguez-Schatz
36bfee7f1b Tests: Add 'reflect' option to http-test-server.py
Add an option to http-test-server.py to return received headers as the
response body. This is useful for checking that outgoing headers are
correct, for example in cookie tests.
2025-09-24 10:12:56 +01:00
Julian Dominguez-Schatz
4e3387778e LibWeb: Respect IncludeCredentials for Set-Cookie during fetch
Per https://fetch.spec.whatwg.org/#http-network-fetch, Set-Cookie should
only store a cookie if IncludeCredentials::Yes is set. Fixes 1 web
platform test.
2025-09-24 10:12:56 +01:00
Pavel Shliak
a7f85e1349 Meta: Use StringView consistently in IDL types argument list 2025-09-24 08:45:26 +01:00
Tim Ledbetter
23380a563a LibWeb: Include custom-ident type in specification of grid properties
Previously, serialization of `grid-column-*` and `grid-row-*`
properties containing a custom-ident would fail.
2025-09-24 02:25:26 +02:00
Tim Ledbetter
4def0b9dc4 LibWeb: Serialize grid-area according to specification 2025-09-24 02:25:26 +02:00
Aliaksandr Kalenik
9bbc1cd618 LibWeb: Check if transform is identity instead of has_css_transform()
...in clip and scroll frames calculation algorithm.

Fix a regression from 719a50c where display-list recording disagreed
with the clipping logic about whether a stacking context is transformed.
`has_css_transform()` returns true whenever the computed transform is
not `none`, which differs from an identity-matrix check. These yield
different results for cases like `translate(0, 0)`.
2025-09-23 23:35:19 +02:00
Aliaksandr Kalenik
719a50c9bf LibWeb: Don't emit Push{Pop}StackingContext without visible effect
Before this change we would emit PushStackingContext/PopStackingContext
display list items regardless of whether the stacking context had any
transform/opacity/clip effects.

Display list size on https://x.com/ladybirdbrowser is reduced from ~2700
to ~800 items.
2025-09-23 19:05:01 +02:00
Aliaksandr Kalenik
2cf10981af LibGfx+LibWeb: Implement GlyphRun::bounding_rect()
Allows us to skip painting of glyph runs lying outside of viewport.
2025-09-23 17:55:32 +02:00
Tim Ledbetter
9c204f36ec LibWeb: Make eventInitDict GamepadEvent constructor parameter optional
This differs from the specification but matches the behavior of
existing implementations.
2025-09-23 16:04:56 +01:00
Tim Ledbetter
5df91dc761 Tests/LibWeb: Import Gamepad API idlharness tests 2025-09-23 16:04:56 +01:00
Callum Law
af32413dec LibWeb: Store line-height in ComputedProperties in computed form
We now fail a few more tests in properties-value-inherit-001.txt as we
no longer overwrite the non-animated value of `line-height` with the
animated value, this is in line with other major browsers.
2025-09-23 15:57:32 +01:00
Callum Law
3b15c303f6 LibWeb: Use computed line-height for FontMetrics
We were already doing this within `compute_property_values` where
we resolved most relative lengths but the remainder was instead
incorrectly using the font's line-spacing
2025-09-23 15:57:32 +01:00
Callum Law
a5139733cc Tests: Import line-height WPT tests
Done in a distinct commit to show progress in later commits
2025-09-23 15:57:32 +01:00
Callum Law
e8ad657589 LibWeb: Don't override value of font-style when computing keyframes
We don't actually rely on this being in computed form yet so this is a
non-functional change for now.
2025-09-23 15:57:32 +01:00
Zaggy1024
fceb73e65a LibThreading: Remove Weakable from Thread
Weakable is not thread-safe, so taking a strong reference from a
WeakPtr<Thread> may result in a use-after-free. We don't use this
functionality anywhere anyway, so remove it.
2025-09-22 17:28:21 -05:00
Zaggy1024
2aaf53bd2c Everywhere: Use a forward declaration for pointers to Threading::Thread 2025-09-22 17:28:21 -05:00
Zaggy1024
5383265b9c LibThreading: Forward-declare Thread in LibThreading/Forward.h
The class is ref-counted, so using forward declarations in a lot of
headers currently including Thread.h is an easy change.
2025-09-22 17:28:21 -05:00
Zaggy1024
55f334b473 LibThreading: Correct the authors in the copyright comment in Forward.h
I created this file a couple years ago, but had a copy/pasted copyright
comment from another file, without the authors being changed. It's now
corrected to attribute it to myself, as it should have been already.
2025-09-22 17:28:21 -05:00
Zaggy1024
84241ea761 Tests: Add a test for HashTable<NonTrivial>::clear_with_capacity() 2025-09-22 17:28:00 -05:00
Zaggy1024
744568c912 AK: Destroy non-trivial types by ref in HashTable::clear_with_capacity
Buckets being iterated by pointer instead of reference was causing a
compilation error when calling clear_with_capacity() on a HashTable
containing a non-trivially-destructible type.
2025-09-22 17:28:00 -05:00
Zaggy1024
319e381eb9 LibMedia: Mark FFmpegVideoDecoder functions with virtual override
The destructor lacked any of these specifiers, and others lacked the
virtual specifier.
2025-09-22 19:34:48 +02:00
Zaggy1024
fc1cc49d6a LibMedia: Remove an unused private function from FFmpegVideoDecoder 2025-09-22 12:04:29 -05:00
Zaggy1024
6cbe607ecf LibMedia+Tests: Call decoder input samples "coded data" for clarity
The word sample is very ambiguous in the realm of decoders, so let's
just make it abundantly clear what the decoder is receiving.
2025-09-22 12:04:29 -05:00
Zaggy1024
8d77e8b09d LibMedia: Refer to demuxer outputs as coded frames
This should be a clearer name, as "sample" is most often used to refer
to the output of a decoder.
2025-09-22 12:04:29 -05:00
Aliaksandr Kalenik
2a288f6d53 LibJS: Invalidate PrototypeChainValidity when prototype shape is a dict
Adds missing PrototypeChainValidity invalidation for add/set/delete
operations on dictionary-mode prototype shapes.
2025-09-22 18:41:23 +02:00
Sam Atkins
3272b8c0f3 LibWeb/CSS: Delete EasingFunctions.json
The generator that used this was removed back in
667e313731 but this small JSON file was
overlooked.
2025-09-22 15:35:43 +01:00
mikiubo
43978ba459 LibWeb: Enable anti-aliasing in DisplayListPlayerSkia::fill_rect
Set SkPaint anti-aliasing to true when filling rectangles
This improves rendering quality by smoothing jagged edges

update clip-path-transformed.html and ref image with anti-aliasing

Partially fixes #5909
2025-09-22 16:22:48 +02:00
Andreas Kling
e41cfb92e2 LibWeb: Add fast_is<T> optimization for Layout::InlineNode 2025-09-22 15:00:50 +02:00
Andreas Kling
84bedebb09 LibWeb: Add fast_is<T> optimization for more paintables
We were doing a lot of dynamic_cast with these types, so let's avoid it.
2025-09-22 15:00:50 +02:00
Andreas Kling
4eca3781c7 LibGfx: Add fast_is<T> optimization for Typeface and TypefaceSkia 2025-09-22 15:00:50 +02:00
Andreas Kling
bc368110ab AK: Make is<T const> use fast_is<T>
We were missing many opportunities to use the fast_is optimization due
to requiring T be non-const.
2025-09-22 15:00:50 +02:00
Ali Mohammad Pur
83f52fca80 Meta: Pin Wasm spec testsuite to a known commit
The current HEAD contains a bunch of stuff not supported by wabt (or
us), that also appear to not be fully merged yet; stick to the last
known commit for now.
2025-09-22 13:49:59 +02:00
Shannon Booth
c1d022523b LibWeb/HTML: Enforce width and height range for OffscreenCanvas
We should be throwing a TypeError on values outside of the range
for an unsigned long instead of the default modulo behaviour.
2025-09-22 12:37:30 +01:00
Shannon Booth
e3b5507113 LibWeb/HTML: Avoid crash for extreme bitmap sizes in OffscreenCanvas 2025-09-22 12:37:30 +01:00
Aliaksandr Kalenik
de3f32a5c9 LibCore: Make timer firing order stable for equal deadlines
Timers scheduled with identical `fire_time` could fire out of order
because the heap is not stable. This change assigns a monotonically
increasing `sequence_id` when a timer is scheduled and extend the heap
comparator to order by (`fire_time`, `sequence_id`). This guarantees
FIFO among timers with the same deadline.

This matches the HTML "run steps after a timeout" ordering requirement:
older invocations with <= delay complete before newer ones.
https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#run-steps-after-a-timeout
2025-09-22 12:34:32 +01:00
Aliaksandr Kalenik
1d41cf10f4 LibJS: Optimize keys deduplication in get_object_property_iterator()
This change implements a part responsible for this invariant in a more
efficient way:
"Enumerating the properties of the target object includes enumerating
properties of its prototype, and the prototype of the prototype, and so
on, recursively; but a property of a prototype is not processed if it
has the same name as a property that has already been processed by the
iterator's next method."

Previously we inserted `(key, enumerable)` pairs into an
`OrderedHashTable`. That always built and maintained a hash table, even
when no prototype-level filtering was needed.

Now we:
- Collect only enumerable keys into `Vector<PropertyKey>`.
- Track `seen_non_enumerable_properties` so a non-enumerable own
  property still shadows prototype properties with the same name.
- Lazily materialize `HashTable<PropertyKey>` only if we encounter an
  enumerable property on a prototype and must check for duplicates. In
  the common case materialization is avoided, because default Object or
  Array prototype properties are non-enumerable.
2025-09-21 15:06:32 +02:00
Aliaksandr Kalenik
451c947c3f LibJS: Fast-path own-property enumeration and reduce descriptor lookups
Before this change, PropertyNameIterator (used by for..in) and
`Object::enumerable_own_property_names()` (used by `Object.keys()`,
`Object.values()`, and `Object.entries()`) enumerated an object's own
enumerable properties exactly as the spec prescribes:
- Call `internal_own_property_keys()`, allocating a list of JS::Value
  keys.
- For each key, call internal_get_own_property() to obtain a
  descriptor and check `[[Enumerable]]`.

While that is required in the general case (e.g. for Proxy objects or
platform/exotic objects that override `[[OwnPropertyKeys]]`), it's
overkill for ordinary JS objects that store their own properties in the
shape table and indexed-properties storage.

This change introduces `for_each_own_property_with_enumerability()`,
which, for objects where
`eligible_for_own_property_enumeration_fast_path()` is `true`, lets us
read the enumerability directly from shape metadata (and from
indexed-properties storage) without a per-property descriptor lookup.
When we cannot avoid `internal_get_own_property()`, we still
benefit by skipping the temporary `Vector<Value>` of keys and avoiding
the unnecessary round-trip between PropertyKey and Value.
2025-09-21 15:06:32 +02:00
Andreas Kling
66601f7d59 LibWeb: Cache results of harfbuzz text shaping
This patch introduces a per-Gfx::Font cache for harfbuzz text shaping
results. As long as the same OpenType features are used, we now cache
the results of harfbuzz shaping, saving massive amounts of time during
text layout.

As an example, it saves multiple seconds when loading the ECMAScript
specification at <https://tc39.es/ecma262>. Before this change, harfbuzz
shaping was taking up roughly 11% of a profile of loading that page.
The cache brings it down to 1.8%.

Note that the cache currently grows unbounded. I've left a FIXME about
adding some limits.
2025-09-21 13:22:38 +02:00
Andreas Kling
3dd700e4de LibWeb: Remove UTF-8 text shaping code path
We now only support the UTF-16 path. (Of course we still handle when
Utf16String is internally optimized with ASCII storage.)
2025-09-21 13:22:38 +02:00
Andreas Kling
6042b5631a LibWeb: Make DisplayListRecorder::draw_text() take text as UTF-16
This is prep work for getting rid of UTF-8 text shaping.
2025-09-21 13:22:38 +02:00
Andreas Kling
b634918ff6 LibWeb: Remove Font::width() overloads for UTF-8
This is prep work for getting rid of UTF-8 text shaping.
2025-09-21 13:22:38 +02:00
Andreas Kling
434bf30cda LibWeb: Use Utf16String in CanvasText APIs
This is prep work for getting rid of UTF-8 text shaping.
2025-09-21 13:22:38 +02:00
Timothy Flynn
5bd867f1dc LibJS: Revert inadvertent observable Temporal change
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/6274e5d
2025-09-19 11:24:02 -04:00
Tim Ledbetter
637724f8d9 LibWeb: Add the overflow-inline property 2025-09-19 13:41:27 +01:00
Tim Ledbetter
2e00ff80e5 LibWeb: Add the overflow-block property 2025-09-19 13:41:27 +01:00
Timothy Flynn
2df4835025 LibWeb: Place HTTP cache logging behind a debug flag
It's quite verbose to have logging on by default here.
2025-09-19 13:52:07 +02:00
Zaggy1024
7434c763d5 LibMedia: Remove default cases when converting CodecID for FFmpeg
This forces us to keep at least that conversion switch statement
up-to-date.
2025-09-19 13:01:00 +02:00
Timothy Flynn
efa9311527 LibWeb+WebContent+UI: Port text pasting to UTF-16 2025-09-19 06:38:52 -04:00
Timothy Flynn
ca082d6d73 LibWebView+UI: Move clipboard handling from the WebView to the App
Clipboard handling largely has nothing to do with the individual web
views. Rather, we interact with the system clipboard at the application
level. So let's move these implementations to the Application.
2025-09-19 06:38:52 -04:00
dependabot[bot]
4f31e492e7 CI: Bump actions/setup-python from 5 to 6
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5 to 6.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-19 12:34:45 +02:00
Tim Ledbetter
e502f19fa7 LibWeb: Implement the animation-composition property 2025-09-19 10:10:05 +01:00
Callum Law
968a8e618c LibWeb: Use computed font style when parsing font-style descriptor
This means we now properly support relative units and clamping for calcs
in font-style descriptors
2025-09-19 10:06:33 +01:00
Callum Law
e17d91780d LibWeb: Clamp computed value for font-style oblique angle
Values outside [-90deg,90deg] are invalid and should be clamped
2025-09-19 10:06:33 +01:00
Callum Law
dc41d045d8 LibWeb: Store font-style in ComputedProperties in computed form 2025-09-19 10:06:33 +01:00
Callum Law
10793aef56 LibWeb: Move to_font_slope from StyleValue to FontStyleStyleValue
This method only operated on `FontStyleStyleValue`s anyway so this is a
better place to have it
2025-09-19 10:06:33 +01:00
Callum Law
425b7de44a LibWeb: Use compute_font_width for font-width descriptor
This allows us to remove `StyleValue::to_font_width`
2025-09-19 10:06:33 +01:00
Callum Law
335c8c7ffb LibWeb: Store font-width in ComputedProperties in computed form 2025-09-19 10:06:33 +01:00
Callum Law
073d10c6d1 LibWeb: Clamp dimension percentage values to the specified percentage
Previously we would clamp the percentage value to the allowed range for
canonical dimension values rather than the percentage value.

Also fixes an issue where we would clamp pure percentages (i.e.
percentages that don't have a hint) against the allowed values for the
first dimension we checked (i.e. angle)
2025-09-19 10:06:33 +01:00
Callum Law
b52525b454 LibWeb: Convert font-width percentages to keywords when serializing font 2025-09-19 10:06:33 +01:00
Callum Law
45a4e9cd0f LibWeb: Use compute_font_weight for font-weight descriptor
This allows us to remove `StyleValue::to_font_weight`
2025-09-19 10:06:33 +01:00
Callum Law
44eaa7ad98 LibWeb: Avoid overwriting non-animated font-weight when computing font
Previously if we would overwrite the non-animated font-size with the
animated font-size if it was set.

Loses us 2 WPT tests but this is in line with other browsers
2025-09-19 10:06:33 +01:00
Callum Law
39484e2027 LibWeb: Store font-weight in ComputedProperties in computed form
We now also more closely follow the spec when computing values for
font-weight and we now:
 - Support relative lengths in `calc()`s
 - Properly clamp `calc()`s
 - Support relative keywords (e.g. lighter, bolder)
 - Respect that font-weight can be a non-integer number.

This does expose a few false positives in the font-weight-computed.html
WPT test. This is because we don't recompute non-inherited font-weight
within `recompute_inherited_style` which means that relative keyword
values can fall out of sync with their parent's value. These previously
passed as we treated `bolder` and `lighter` as aliases for `bold` and
`normal` respectively.
2025-09-19 10:06:33 +01:00
Callum Law
cfbe0244d4 LibWeb: Use computed value of font-size in keyframes
Remaining test failures in font-size-interpolation-00* are either:
 - Rounding of font-size to CSSPixels when setting the expected value
 - Not clamping negative values from the point of view of
   getComputedStyle (used values are still clamped)
2025-09-19 10:06:33 +01:00
Callum Law
64d2f0d55a LibWeb: Avoid overwriting non-animated font-size when computing font
Previously if we would overwrite the non-animated font-size with the
animated font-size if it was set.

Gains us 8 WPT tests and means we now fail 9 others in line with other
browsers.
2025-09-19 10:06:33 +01:00
Callum Law
c6049e6853 LibWeb: Remove StyleComputer::root_element_font_metrics_for_element
This method is now unused so can be removed
2025-09-19 10:06:33 +01:00
Callum Law
e9faf056f1 LibWeb: Decouple font-size computation from compute_font_for_syle_values
There are other places we want to convert font-size into it's computed
form than just when we are loading the font (e.g. computing keyframes).

Gains us 36 WPT passes as we now correctly clamp negative calc values.
2025-09-19 10:06:33 +01:00
Callum Law
d6754307f9 LibWeb: Separate relative sizes from absolute_size_mapping
Having relative sizes handled in this function was misleading
2025-09-19 10:06:33 +01:00
Callum Law
1ca511b627 LibWeb: Correctly resolve percentages against relative lengths in calcs
Previously we would always assume the percentage was 100%
2025-09-19 10:06:33 +01:00
Callum Law
b80e6a4d30 LibWeb: Rename get_inherit_value to get_non_animated_inherit_value
This more acurately represents what it does.
2025-09-19 10:06:33 +01:00
Callum Law
3b6d17cd42 LibWeb: Import a bunch of CSS font related tests
Done in distinct commit to see progress over multiple following commits
2025-09-19 10:06:33 +01:00
InvalidUsernameException
fbf47e57d0 LibWeb: Paint inspector overlays as a separate pass
The overlay shown for the node hovered in the inspector is painted as
part of the normal tree traversal of all paintables. This works well in
most cases, but falls short in specific scenarios:
* If the hovered node or one of its ancestors establishes a stacking
  context and there is another element that establishes a stacking
  context close by or overlapping it, the overlay and especially the
  tooltip can become partially hidden behind the second element. Ditto
  for elements that act as if they established a stacking context.
* If the hovered node or one of its ancestors involves clipping, the
  clip is applied to the overlay and espicially the tooltip. This can
  cause them to be partially invisible.
* Similarly, if the hovered node or one of its ancestors has a defined
  mask, the mask is applied to the overlay, often making it mostly
  invisible.
* No overlays are shown for SVG nodes because they are painted
  differently from HTML documents.

Some of these problems may be fixable with the current system. But some
seem like they fundamentally cannot work fully when the overlays are
painted as part of the regular tree traversal.

Instead we pull out painting the overlay as a separate pass executed
after the tree traversal. This way we ensure that the overlays are
always painted last and therefore on top of everything else. This also
makes sure that the overlays are unaffected by clips and masks. And
since overlay painting is independent from painting the actual elements,
it just works as well.

However we need to be careful, because we still need to apply some of
the steps of the tree traversal to get the correct result. Namely we
need to apply scroll offsets and transforms. To do so, we collect all
ancestors of the hovered node and apply those as if we were in the
normal tree traversal.
2025-09-19 10:17:56 +02:00
InvalidUsernameException
870b7c79c3 LibWeb: Add a constructor for StackingContextTransform
This avoids some code duplication in an upcoming commit.
2025-09-19 10:17:56 +02:00
InvalidUsernameException
7dd3fca858 LibWeb: Reuse existing method instead of duplicating code 2025-09-19 10:17:56 +02:00
InvalidUsernameException
29cc4e5953 LibWeb: Avoid rebuilding bindings when editing Paintable.h 2025-09-19 10:17:56 +02:00
InvalidUsernameException
0e7749e6cd LibWeb: Unify similar debug overlay code paths
The debug option 'Show Line Box Borders' and the inspector overlay for
text nodes are conceptually similar. However they use two different
code paths. This commits unifies both to use the same code.
2025-09-19 10:17:56 +02:00
InvalidUsernameException
9ace789ab4 LibWeb: Draw line box borders only in foreground-phase
Previously line box borders were drawn in every phase. This caused
redundent lines to be drawn on top of each other. But it also caused
boxes to appear for text that was not visible on screen because other
elements overlayed it. That was confusing to look at since all text on
the page is highlighted at the same time using this debug functionality.
2025-09-19 10:17:56 +02:00
Andreas Kling
59a28febc9 AK: Store hash with HashTable entry to avoid expensive equality checks
When T in HashTable<T> has a potentially slow equality check, it can be
very profitable to check for a matching hash before full equality.

This patch adds may_have_slow_equality_check() to AK::Traits and
defaults it to true. For trivial types (pointers, integers, etc) we
default it to false. This means we skip the hash check when the equality
check would be a single-CPU-word compare anyway.

This synergizes really well with things like HashMap<String, V> where
collisions previously meant we may have to churn through multiple O(n)
equality checks.
2025-09-18 22:37:18 +02:00
Sam Atkins
c077ba9caf Tests: Import a few missing .idl files from WPT
This allows the css/css-typed-om/idlharness.html test to run locally.
2025-09-18 17:25:52 +01:00
Tim Ledbetter
9b15517052 LibWeb: Apply composite operator to keyframe effects 2025-09-18 16:46:06 +01:00
Callum Law
004bd3dc8f LibWeb: Clamp calc()'d shadow blur radius to positive values 2025-09-18 15:21:22 +01:00
Callum Law
19e3ddc0c6 LibWeb: Simplify parse_single_shadow_value
The `possibly_dynamic_length` function was unnecessary and can be
replaced with the standard `parse_length_value`
2025-09-18 15:21:22 +01:00
Callum Law
c3a78d2884 LibWeb: Don't include spread distance when serializing text-shadow
We shouldn't include spread distance when serializing `text-shadow` as
it is not supported unlike `box-shadow` - to achieve this we store
whether this is a text or box shadow within the ShadowStyleValue and
serialize appropriately.
2025-09-18 15:21:22 +01:00
Callum Law
1ac7b47764 LibWeb: Disallow spread distance value when parsing text-shadow
`text-shadow` does not support setting a value for spread distance
unlike `box-shadow`.
2025-09-18 15:21:22 +01:00
Callum Law
5d8a859457 Tests: Import text-shadow parsing test
Done in a distinct commit to show progress in following commits
2025-09-18 15:21:22 +01:00
Aliaksandr Kalenik
c3b0eabf18 LibJS: Capture PrototypeChainValidity before executing internal_get()
- Capture PrototypeChainValidity before invoking `internal_get()`. A
  getter may mutate the prototype chain (e.g., delete itself). Capturing
  earlier ensures such mutations invalidate the cached entry and prevent
  stale GetById hits.
- When caching, take PrototypeChainValidity from the base object
  (receiver), not from the prototype where the property was found.
  Otherwise, changes to an intermediate prototype between the base
  object and the cached prototype object go unnoticed, leading to
  incorrect cache hits.
2025-09-18 15:56:20 +02:00
Sam Atkins
1b8e81cd6f IDLGenerators: Support null as a default value for dictionary types
Specifically, NotificationOptions has this:

```webidl
dictionary NotificationOptions {
    // ...
    boolean? silent = null;
    // ...
};
```
https://notifications.spec.whatwg.org/#dictdef-notificationoptions

Without this patch, we generate this code, which isn't valid:

```c++
silent_value_11 = static_cast<bool>(null);
```

Treating `null` the same as no default value seems like the best option,
as they're equivalent in our C++ types.
2025-09-18 13:59:46 +01:00
Sam Atkins
95aceb6ec9 LibWeb: Store custom properties in an OrderedHashMap
We are expected to preserve their order within a style declaration, so
let's do that. Passes 1 tracked WPT subtest.
2025-09-18 14:59:14 +02:00
Timothy Flynn
2674bd428e LibWeb: Implement up/down arrow navigation for EditingHostManager 2025-09-18 07:39:10 -04:00
Timothy Flynn
f529a4d98e LibWeb: Add a FIXME comment about multiple DOM nodes in arrow navigation 2025-09-18 07:39:10 -04:00
Timothy Flynn
80412d1ea5 LibWeb: Add a FIXME comment about handling wrapping in arrow navigation 2025-09-18 07:39:10 -04:00
Timothy Flynn
42a5f66e41 LibWeb: Move grapheme edge detection across lines to helper functions
EditingHostManager is going to have exactly the same implementation as
FormAssociatedElement.
2025-09-18 07:39:10 -04:00
Timothy Flynn
8b2187bf92 LibWebView+UI: Generate the entire Inspect menu
Now that all the actions in the Inspect menu are generated, we can
generate the menu itself.
2025-09-18 07:27:24 -04:00
Timothy Flynn
14d49d5a3a LibWebView+UI: Generate action to enable/disable DevTools 2025-09-18 07:27:24 -04:00
Timothy Flynn
6d30b0f4d4 LibWebView+UI: Generate actions to open about: pages 2025-09-18 07:27:24 -04:00
Timothy Flynn
ce331cbcd5 LibWebView+UI: Add an Application method to open a URL in a new tab
This lets us avoid each UI needing to handle link clicks directly, and
lets actions stored in LibWebView avoid awkwardly going through the link
click callbacks to open URLs.
2025-09-18 07:27:24 -04:00
Timothy Flynn
c2365653a5 LibURL: Add a few missing internal page factories 2025-09-18 07:27:24 -04:00
Timothy Flynn
60b71805bc UI/AppKit: Add menu icons for the zoom menu
Neglected to add these in ede6314cb6.
2025-09-18 07:27:24 -04:00
Timothy Flynn
255c4c2d9b UI/Qt: Simplify setting some action shortcuts
These were copied from their previous instantiations, but we don't need
to go through QKeySequence::keyBindings for standard shortcuts.
2025-09-18 07:27:24 -04:00
Timothy Flynn
dbce62bc0d UI/Qt: Move the View Source action back to the Inspect menu
Accidental copy/paste from e6b32bbbbf6c3b80649e355c2ad7f6ad87430fc3.
2025-09-18 07:27:24 -04:00
Rocco Corsi
3d1d055e27 LibRegex: Export OpCode/OpCode_Compare for REGEX_DEBUG builds
When building with REGEX_DEBUG or ENABLE_ALL_THE_DEBUG_MACROS there are
two issues with linking of bin/TestRegex

 - Libraries/LibRegex/RegexDebug.h:76 with undefined reference
       regex::OpCode_Compare::variable_arguments_to_byte_string(
           AK::Optional<regex::MatchInput const&>) const

 - Libraries/LibRegex/RegexByteCode.h:672 with undefined reference
       regex::OpCode::name(regex::OpCodeId)

Add REGEX_API on regex::OpCode and regex::OptCode_Compare to allow
access to the classes in bin/TestRegex
2025-09-18 11:02:13 +02:00
Rocco Corsi
73658c9785 LibDNS: Export DNS::Messages::Records::SIG for DNS_DEBUG builds
When building with DNS_DEBUG or ENABLE_ALL_THE_DEBUG_MACROS there is a
linking issue with Libraries/LibDNS/Resolver.h:1003 with
undefined reference DNS::Messages::Records::SIG::to_string() const

Add DNS_API on DNS:Messages::Records::SIG definition to allow access
to the class in bin/dns, bin/TestDNSResolver, libexec/RequestServer
2025-09-18 11:02:13 +02:00
luizgfc
b8787cb021 LibWeb: Import CSSOM variable names fixed WPT test 2025-09-18 09:25:23 +01:00
luizgfc
bcbbecff9f LibWeb: Correctly handle properties on CSS declaration serialization 2025-09-18 09:25:23 +01:00
luizgfc
3b5df12b38 LibWeb: Handle custom properties on CSSStyleProperties list 2025-09-18 09:25:23 +01:00
Zaggy1024
261cd5846f LibWeb: Use Duration::to_seconds_f64 to set HTMLMediaElement duration 2025-09-17 16:45:45 -05:00
Zaggy1024
5207de9a2d AK: Add a function to Duration to convert it to double seconds 2025-09-17 16:45:45 -05:00
Jelle Raaijmakers
c31eff6a47 Everywhere: Use Optional<T>::ensure() where useful
No functional changes.
2025-09-17 12:01:18 -04:00
Jelle Raaijmakers
0fe9255991 AK: Add Optional<T>::ensure()
We often use Optional<T> in a cache pattern such as:

  if (!m_cache.has_value())
      m_cache = slow_thing();
  return m_cache.value();

The new ::ensure() makes it a bit simpler:

  return m_cache.ensure([&] { return slow_thing(); });
2025-09-17 12:01:18 -04:00
Aliaksandr Kalenik
d45f8a3081 LibJS: Add inline caching for adding new own properties to objects
We already had IC support in PutById for the following cases:
- Changing an existing own property
- Calling a setter located in the prototype chain

This was enough to speed up code where structurally identical objects
(same shape) are processed in a loop:
```js
const arr = [{ a: 1 }, { a: 2 }, { a: 3 }];
for (let obj of arr) {
    obj.a += 1;
}
```

However, creating structurally identical objects in a loop was still
slow:
```js
for (let i = 0; i < 10_000_000; i++) {
    const o = {};
    o.a = 1;
    o.b = 2;
    o.c = 3;
}
```

This change addresses that by adding a new IC type that caches both the
source and target shapes, allowing property additions to be fast-pathed
by directly jumping to the shape that already includes the new property.
2025-09-17 12:44:44 +02:00
Aliaksandr Kalenik
a54215c07d LibJS: Make internal_define_own_property() save added property offset
...in `PropertyDescriptor`. This is required for the upcoming change
that needs to know offset of newly added properties to set up inline
caching.
2025-09-17 12:44:44 +02:00
Timothy Flynn
ede6314cb6 LibWebView+UI/AppKit: Display icons in the macOS UI on Tahoe
On macOS Tahoe, it is now recommended to show menu item icons. We use
system symbols for this now. Symbols do not have constant variable names
and must be found via the SF Symbols app.

The symbols chosen here were to match Safari as close as possible.
2025-09-17 11:29:01 +01:00
Timothy Flynn
8ebc20a4f0 UI/AppKit: Make the location field bordered on Tahoe
Otherwise, it sticks out on macOS Tahoe when it is unbordered. This
matches Safari's look.
2025-09-17 11:29:01 +01:00
Timothy Flynn
e0a7217c4b UI/AppKit: Hide button borders when the button should be invisible
On macOS Tahoe, the zoom button's border is visible when the button
itself is hidden. This feels like a macOS bug, but for now let's hide
the borders as well.
2025-09-17 11:29:01 +01:00
Rocco Corsi
55d4adc614 LibWasm: Missing argument formatter (Wasm::Value) for WASI_DEBUG
Formatting code was removed in PR #960 for performance improvements.
Adding Wasi::Value back as u128 to allow WASI_DEBUG MACRO compilation
2025-09-16 22:13:23 +02:00
Jelle Raaijmakers
49817a1c6a CI+Meta: Add option to enable baseline CPU target for CI
We currently have the issue that our macOS builds are being hosted by
both Apple M1 and M4 runners. By default, these target `-mcpu=apple-m1`
and `-mcpu=apple-m3` respectively, causing their ccache artifacts to be
incompatible and effectively thrashing each other's ccache cache on each
run.

Add a new CMake option `ENABLE_CI_BASELINE_CPU` that toggles a baseline
`-mcpu/-march` compile option for each of the supported build platforms.
When disabled (the default), we now default to `-march=native` which on
Linux could theoretically lead to better performance.

The new CPU baseline is used by the `lagom-template.yml` and
`js-and-wasm-artifacts.yml` workflows, since they both produce artifacts
or caches that might be picked up by other runners. We also enable it
for Flatpak builds, so they target a fixed architecture instead of
whatever architecture the action runner that picked up the job has.
2025-09-16 10:53:15 -04:00
Callum Law
7a9b1a8033 LibWebView: Show a better error for invalid download dir in headless
Previously if the directory returned by `downloads_directory()` didn't
exist (or wasn't a directory) when taking a screnshot in headless mode
we try to ask the user for the download directory and fail with the
unhelpful error: QWidget: Must construct a QApplication before a QWidget
2025-09-16 10:39:20 -04:00
Jelle Raaijmakers
b9da7baac4 LibWeb: Extend logic for extraneous line breaks in block elements
While editing, we need to consider whether removing a <br> has any
effect on layout to determine whether its extraneous. This new condition
finds most cases for extraneous <br>s inside block elements.
2025-09-16 06:57:30 -04:00
Jelle Raaijmakers
f77f169824 LibWeb: Reformat code and comments in Editing::split_the_parents()
Mainly rewrapping the spec text to 120 characters. No functional
changes.
2025-09-16 06:57:30 -04:00
Jelle Raaijmakers
c557db8315 LibWeb: Pass existing DOM::BoundaryPoints in delete_the_selection() 2025-09-16 06:57:30 -04:00
Jelle Raaijmakers
9b614eebb3 LibWeb: Make TreeNode::child_at_index() accept a size_t
This gets rid of IDE warnings when the call site already uses a size_t.
2025-09-16 06:57:30 -04:00
Jelle Raaijmakers
b51cc00478 LibWeb: Resolve Unicode FIXME in forwardDelete 2025-09-16 06:57:30 -04:00
Tete17
82f56e30ed LibWeb: Adapt the parsing of script elements to accommodate TrustedTypes 2025-09-16 10:57:34 +02:00
Tete17
f7c05013c7 LibWeb: Add innerText attribute of HTMLScriptElement for TrustedTypes 2025-09-16 10:57:34 +02:00
Tete17
6b9c44390f LibWeb: Add textContent attribute of HTMLScriptElement for TrustedTypes 2025-09-16 10:57:34 +02:00
Tete17
f65dca1b53 LibWeb: Extend src attribute of HTMLScriptElement with TrustedTypes
The field does no longer have the Reflect and URL attributes so we
remove it from our internal unit test.
2025-09-16 10:57:34 +02:00
Tete17
664a3b536a LibWeb: Extend set_text of HTMLScriptElement to accommodate TrustedTypes 2025-09-16 10:57:34 +02:00
Timothy Flynn
b4df857a57 LibWeb+LibWebView+WebContent: Replace DNT with GPC
Global Privacy Control aims to be a replacement for Do Not Track. DNT
ended up not being a great solution, as it wasn't enforced by law. This
actually resulted in the DNT header serving as an extra fingerprinting
data point.

GPC is becoming enforced by law in USA states such as California and
Colorado. CA is further working on a bill which requires that browsers
implement such an opt-out preference signal (OOPS):

https://cppa.ca.gov/announcements/2025/20250911.html

This patch replaces DNT with GPC and hooks up the associated settings.
2025-09-16 10:38:20 +02:00
Timothy Flynn
d9ebd44924 UI/Qt: Remove unused/undefined declaration from Qt settings 2025-09-16 10:38:20 +02:00
Zaggy1024
850aea7e17 LibWeb: Remove a FIXME and simplify the painting of video frames
The extra representations of a video element are unnecessary to specify
in VideoPaintable, as the playback system itself should take care of
all the details of the representation as specified.
2025-09-16 10:26:03 +02:00
Zaggy1024
861c10f37f LibWeb: Use an IIFE to determine a VideoPaintable's representation 2025-09-16 10:26:03 +02:00
Timothy Flynn
7b3465ab55 LibWeb: Do not require multipart form data to end with CRLF
According to RFC 2046, the BNF of the form data body is:

    multipart-body := [preamble CRLF]
                      dash-boundary transport-padding CRLF
                      body-part *encapsulation
                      close-delimiter transport-padding
                      [CRLF epilogue]

Where "epilogue" is any text that "may be ignored or discarded". So we
should stop parsing the body once we encounter the terminating delimiter
("--").

Note that our parsing function is from an attempt to standardize the
grammar in the spec: https://andreubotella.github.io/multipart-form-data
This proposal hasn't been updated in ~4 years, and the fetch spec still
does not have a formal definition of the body string.
2025-09-15 18:28:48 +02:00
Callum Law
34b8947ca0 LibWeb: Support text-underline-position: under 2025-09-15 15:24:20 +01:00
Callum Law
b0e3af7d10 LibWeb: Parse text-underline-position property
This introduces the `TextUnderlinePositionStyleValue` class, it is
possible to represent `text-underline-position` as a `StyleValueList`
but would have required ugly workarounds for either serialization or in
`ComputedProperties::text_underline_position`
2025-09-15 15:24:20 +01:00
Callum Law
a6812e1005 LibWeb: Store parsed shorthands in canonical order 2025-09-15 15:24:20 +01:00
Sam Atkins
d127eb5117 LibWeb/Geometry: Correct typos in DOMMatrix "not 0 or -0" checks
Assuming 0 and -0 are distinct values, `a != 0 || a != -0` is always
true.
2025-09-15 13:34:24 +02:00
Aliaksandr Kalenik
85e029b2e7 LibJS+LibWeb: Inline fast path for Value::to_object()
Adds inline implementation for the most common case when `Value` is
already an object.

1.47x improvement on the following benchmark:
```js
const o = {};
for (let i = 0; i < 10_000_000; i++) {
    o.a = 1;
    o.b = 2;
    o.c = 3;
}
```
2025-09-15 12:16:58 +02:00
Tim Ledbetter
f5fd6338d5 LibWeb: Handle interpolation of mixed-type LengthPercentages 2025-09-15 10:41:01 +01:00
Tim Ledbetter
7409c564d7 LibWeb: Extract mixed-type interpolation to a separate method 2025-09-15 10:41:01 +01:00
Tim Ledbetter
b19fee9962 LibWeb: Interpolate ellipse() function by computed value 2025-09-15 10:34:43 +01:00
Tim Ledbetter
f146207a04 LibWeb: Interpolate circle() function by computed value 2025-09-15 10:34:43 +01:00
Tim Ledbetter
4a0fe65923 LibWeb: Interpolate polygon() function by computed value 2025-09-15 10:34:43 +01:00
Tim Ledbetter
853bedeb31 LibWeb: Interpolate rect() function by computed value 2025-09-15 10:34:43 +01:00
Tim Ledbetter
0c89e86ff7 LibWeb: Interpolate xywh() function by computed value 2025-09-15 10:34:43 +01:00
Tim Ledbetter
be94c8d456 LibWeb: Interpolate inset() function by computed value 2025-09-15 10:34:43 +01:00
Lorenz A
47796e7967 LibWeb: Serialize HTML attribute names as per spec 2025-09-15 10:08:12 +02:00
Luke Wilde
4772e1b0c9 LibWeb/Fetch: Add missing spec step for checking for tuple origin
Fixes https://github.com/LadybirdBrowser/ladybird/issues/6188
2025-09-15 09:58:33 +02:00
Sam Atkins
5904694844 LibWeb/CSS: Implement CSSImageValue and reify images as it
This is specced to be opaque, so there's not much to it.
2025-09-15 08:47:10 +01:00
Sam Atkins
eb39c0162c Tests: Import a selection of CSS Typed-OM property tests
This is an arbitrary set of tests intended to cover the different
CSSStyleValue types without too much overlap.

Right now they all fail, because testsuite.js attempts to create one of
every type of CSSStyleValue on load, and we don't have most of them.
2025-09-15 08:47:10 +01:00
Callum Law
50239b58aa LibWeb: Reset border-image to initial value when using border
Also includes associated handling for serialization of the `border`
shorthand.
2025-09-15 08:42:22 +01:00
Callum Law
588c611e7e LibWeb: Use correct initial value for border-image
Omitting the `/`s meant that `1` and `0` were parsed as part of
border-slice instead of their intended values.

No functional changes but this will be relied on in a later commit.
2025-09-15 08:42:22 +01:00
ayeteadoe
9f23b0a069 Services/WebDriver: Enable on Windows 2025-09-15 09:19:52 +02:00
ayeteadoe
69e92f69a7 LibCore: Implement SIGTERM-based kill() on Windows
There is no direct Win32 API equivalent, but calling WM_CLOSE on
the top-level windows allows for a graceful shutdown where resources
are able to clean themselves up properly
2025-09-15 09:19:52 +02:00
Pavel Shliak
bbb9159883 LibWeb: Fix Request() TypeError message typo for mode='navigate'
The Request constructor’s mode validation threw
  "Mode must not be 'navigate"
missing the closing quote. Add the trailing quote so the error reads:
  "Mode must not be 'navigate'".
2025-09-15 08:19:34 +01:00
Kemal Zebari
faf3c19026 LibWeb/MimeSniff: Match spec change by using correct font essence
Spec change was made to fix a typo; application/font-off ->
application/font-otf
2025-09-15 07:31:02 +01:00
MFMF-EGY
fff09ed330 LibWeb: Handle interpolation of BorderRadius style value type 2025-09-14 16:49:20 +01:00
Shivendra Kumar
b3e8784f92 LibCrypto: Fix typo in comment 2025-09-14 10:45:41 +01:00
Marcos Del Sol Vives
40792aa85d LibWeb/CSS: Fix compilation with CSS_TRANSITIONS_DEBUG
A new parameter was added to Web::CSS::StyleValue::to_string() in
PR #2820 but this debug message was never updated. If
CSS_TRANSITIONS_DEBUG was enabled, compilation would fail.
2025-09-13 23:33:57 +02:00
Aliaksandr Kalenik
0076ab74b2 LibJS: Don't attempt to cast property key to number in PutByIdWithThis
Property key for this instruction cannot be a number.
2025-09-13 20:02:28 +02:00
Aliaksandr Kalenik
e81833423b LibJS: Add PutByNumericId and change PutById to be string key only
Previously, PutById constructed a PropertyKey from the identifier,
which coerced numeric-like strings to numbers. This moves that decision
to bytecode generation: the bytecode generator now emits PutByNumericId
for numeric keys and PutById for string keys. This removes per-execution
parsing from the interpreter.

1.4x speedup on the following microbenchmark:
```js
const o = {};
for (let i = 0; i < 10_000_000; i++) {
    o.a = 1;
    o.b = 2;
    o.c = 3;
}
```
2025-09-13 20:02:28 +02:00
Louis Dalibard
660bcfa2cd LibGfx+LibWeb+UI: Add OpenHand cursor for CSS grab property 2025-09-13 14:27:18 +02:00
Tim Ledbetter
19577b966e LibWeb: Implement interpolation of border-image-slice style values 2025-09-13 12:05:19 +02:00
Jelle Raaijmakers
9e9db9a9dd LibWeb: Store correct text offsets in PaintableFragment
Previously, we were collapsing whitespace in Layout::TextNode and then
passed the resulting string for further processing through ChunkIterator
-> InlineLevelIterator -> InlineFormattingContext -> LineBuilder ->
LineBoxFragment -> PaintableFragment. Our painting tree is where we deal
with things like range offsets into the underlying text nodes, but since
we modified the original string, the offsets were wrong.

This changes the way we generate fragments:

  * Layout::TextNode no longer collapses whitespace as part of its
    stored "text for rendering", but moves this logic to ChunkIterator
    which splits up this text into separate views whenever whitespace
    needs to be collapsed.

  * Layout::LineBox now only extends the last fragment if its end offset
    is equal to the new fragment's start offset. Otherwise, there's a
    gap caused by collapsing whitespace and we need to generate a
    separate fragment for that in order to have a correct start offset.

Some tests need new baselines because of the fixed start offsets.

Fixes #566.
2025-09-12 15:34:09 -04:00
Jelle Raaijmakers
d1076c1e6e LibWeb: Remove text storage from TextPaintable
Instead of copying the layout node's text, retrieve the text from the
layout node directly.
2025-09-12 15:34:09 -04:00
Jelle Raaijmakers
e6474778c6 LibWeb: Some text-related cleanup
No functional changes.
2025-09-12 15:34:09 -04:00
Jelle Raaijmakers
7375d8c6f9 LibWeb: Simplify ASCII whitespace check in Layout::TextNode
No functional changes.
2025-09-12 15:34:09 -04:00
Jelle Raaijmakers
26b5fa348c LibWeb: Make Navigable::active_document() const 2025-09-12 15:34:09 -04:00
Jelle Raaijmakers
12cec1bdb3 LibWeb: Clean up Range::to_string()
No functional changes.
2025-09-12 15:34:09 -04:00
Jelle Raaijmakers
75d41859fd LibWeb: Remove PWL::layout_node_with_style_and_box_metrics()
These methods already exist in PaintableBox.
2025-09-12 15:34:09 -04:00
Callum Law
a805635e40 LibWeb: Compute dimension percentage mix as percentage where applicable
When we have a `calc` which is a mix of a dimension and a percentage, we
should use the percentage alone for the computed value if the dimension
component is 0 e.g. `calc(50% + 0px)` should use `50%` as it's computed
value.
2025-09-12 15:04:30 +01:00
Nico Weber
9272df7a86 Everywhere: Fix a few unreachable-return / unreachable-break warnings
I was playing with clang's -Wunreachable-code-aggressive a bit.
This fixes a handful uncontroversial things it flags.

No behavior change.
2025-09-12 14:33:14 +01:00
Sam Atkins
a139ad1c44 LibWeb/CSS: Implement CSSNumericValue.to()
Tries to convert the CSSNumericValue to a CSSUnitValue with the given
unit.

This gets us the remaining 11 WPT subtests for this method.
2025-09-12 13:45:41 +02:00
Sam Atkins
80abffd2e8 LibWeb/CSS: Implement "Create a sum value" 2025-09-12 13:45:41 +02:00
Sam Atkins
1c952b01ac LibWeb/CSS: Implement "Convert a CSSUnitValue" 2025-09-12 13:45:41 +02:00
Sam Atkins
050d3a58cf LibWeb/CSS: Generate canonical/compatible unit functions
These are used by `CSSNumericValue.to(unit)` which attempts to convert
to the provided unit.
2025-09-12 13:45:41 +02:00
Sam Atkins
5a42b7a40f LibWeb/CSS: Implement product_of_two_unit_maps()
Helper function for combining two UnitMaps.
2025-09-12 13:45:41 +02:00
Sam Atkins
e6e380b109 LibWeb/CSS: Implement "create a type from a unit map" 2025-09-12 13:45:41 +02:00
Sam Atkins
09a6b179d0 LibWeb/CSS: Take FlyString in NumericType::create_from_unit()
We only call this with FlyStrings, so we might as well.
2025-09-12 13:45:41 +02:00
Sam Atkins
995c19da56 LibWeb/CSS: Return unit names as FlyStrings
From the CSS token side, we already have these in FlyString form. From
the generated code side, we can easily return FlyStrings instead of
StringViews. So, let's do that, and save some work converting back and
forth.
2025-09-12 13:45:41 +02:00
Sam Atkins
59c4076066 LibWeb/CSS: Mark CSSStyleValue classes final where possible 2025-09-12 13:45:41 +02:00
Tim Ledbetter
3099459504 LibWeb: Return the same DataTransfer.types() array if unmodified 2025-09-12 12:30:33 +02:00
Tim Ledbetter
3fc7613bf1 LibWeb: Implement DataTransferItemList.clear() 2025-09-12 12:30:33 +02:00
Tim Ledbetter
0c1532626f LibWeb: Implement DataTransfer.clearData() 2025-09-12 12:30:33 +02:00
Tim Ledbetter
d9341adb1e LibWeb: Implement DataTransferItemList.remove() 2025-09-12 12:30:33 +02:00
Veeti Paananen
8ab3549585 LibWeb: Add support for HTMLHRElement size presentational hint 2025-09-12 11:23:38 +01:00
Zaggy1024
26a21f2070 LibMedia: Make MatroskaDemuxer::get_codec_id_for_string static 2025-09-12 11:23:47 +02:00
Zaggy1024
9077873803 LibMedia: Stop initializing an empty optional in MatroskaDemuxer
There was a warning for the Optional initializer having no effect, but
removing the initializer caused the call to add a track to the HashMap
to complain. A constructor looks a little nicer here anyway.
2025-09-12 11:23:47 +02:00
Zaggy1024
ae7f82591b LibMedia: Separate file duration from track duration in Demuxer
Most users will only care about the total file duration, and shouldn't
be required to determine the file duration from multiple track
durations. To facilitate that, add a total_duration() function that
returns the demuxer's duration not associated to any particular track.
2025-09-12 11:23:47 +02:00
Zaggy1024
6653b747ff LibMedia: Allow demuxers to specify a preferred track
...and return all tracks of a matching type from FFmpegDemuxer, rather
than only the single best one.
2025-09-12 11:23:47 +02:00
Zaggy1024
8d64e72655 LibMedia: Remove the duration field from Track::VideoData
Most demuxer users will only care about the whole file's duration
anyway, so this field doesn't really do us any good.
2025-09-12 11:23:47 +02:00
Aliaksandr Kalenik
db5fd614ac LibWeb: Require layout update for less properties in getComputedStyle()
Some properties like `justify-items`, `grid`, or `display` do affect
layout, but their used values can be obtained without performing a
layout calculation.

This change introduces a new helper,
`property_needs_layout_for_getcomputedstyle()`, specifically for use by
`CSSStyleProperties::property()`. It returns true only for properties
such as `width`, `height`, `margin`, `padding`, `top`, and `left`, where
an up-to-date layout is required to return the correct used value.
2025-09-12 11:06:16 +02:00
Callum Law
815e77c04d LibWeb: Respect text-underline-offset when rendering underlines 2025-09-12 07:07:15 +01:00
Callum Law
9aa2d1bd3e LibWeb: Make text-decoration lines entire width of fragment
This fixes an issue where text decorations (e.g. underlines) of text
split across multiple fragments would have unintended 1px gaps.

Gains us 2 WPT passes (imported)
2025-09-12 07:07:15 +01:00
Callum Law
858450922b LibWeb: Parse and compute text-underline-offset property 2025-09-12 07:07:15 +01:00
Zaggy1024
f9305e7e67 LibMedia: Format switch statements consistently in FFmpegVideoDecoder 2025-09-11 18:41:58 -05:00
Zaggy1024
924ba6c1f4 LibMedia: Use FFmpeg's info to tell us if YUVJ is full-range
It reports this correctly for the video linked in #4993, and likely any
other videos using the YUVJ format, so we don't need this extra check.
2025-09-11 18:41:58 -05:00
Timothy Flynn
4a5c374084 UI/Qt: Place the "reset zoom" button to the left of the hamburger menu
It feels a bit awkward having this button displace the menu.
2025-09-11 14:23:45 -04:00
Timothy Flynn
9684e6dbc5 LibWebView+UI: Generate the zoom menu 2025-09-11 14:23:45 -04:00
Timothy Flynn
7d6ea99d0d LibWebView+UI: Generate the preferred color, contrast, and motion menus 2025-09-11 14:23:45 -04:00
Timothy Flynn
9c99c48f47 LibWebView+UI: Generate the application debug menu
By migrating the debug menu to LibWebView, the AppKit and Qt UIs are now
in sync - the AppKit UI was previously missing some actions.

Further, this inadvertently fixes bugs around applying debug settings to
new web views, especially across site-isolated processes. We were
previously not applying settings appropriately; this now "just works" in
the LibWebView infra.
2025-09-11 14:23:45 -04:00
Timothy Flynn
5d8d9b337a LibWebView+UI: Generate application context menus
This migrates all duplicated context menus from the UIs to LibWebView.
The context menu actions are now largely handled directly in LibWebView,
with some UI-specific callbacks added to display e.g. confirmation
dialogs.

Actions that only ever apply to a specific web view are stored on the
ViewImplementation itself. Actions that need to be dynamically applied
to the active web view are stored on the Application.
2025-09-11 14:23:45 -04:00
Timothy Flynn
a5be0f0a18 LibWebView+UI: Add structures to hold context menu and action data
We currently duplicate a lot of code to handle application/context menus
and actions. The goal here is to hold the data for the menus and actions
in LibWebView. Each UI will then be able to generate menus from the data
on-the-fly.

The structures added here are meant to support generic and checkable
actions, action groups, submenus, etc.
2025-09-11 14:23:45 -04:00
Timothy Flynn
2632b1375b LibWebView+UI: Extract some UI-specific displays to Application helpers
This is preparation for moving application menus to LibWebView. We will
need a way to display these dialogs from outside of the UI layer.
2025-09-11 14:23:45 -04:00
Timothy Flynn
95dca6c787 UI/Qt: Clean up some manual forward declarations
Several are unused, and there's certainly no need for the `using`
declaration.
2025-09-11 14:23:45 -04:00
Timothy Flynn
171937cc72 LibWebView: Return a ByteString from WebView::url_text_to_copy
The result is currently only used as a StringView, but a future commit
will place the result in Web::Clipboard::SystemClipboardRepresentation,
which requires a ByteString (there's no UTF-8 clipboard requirement).
2025-09-11 14:23:45 -04:00
Sam Atkins
524a161a51 LibWeb: Take AbstractElement in start_a_transition() 2025-09-11 18:45:35 +02:00
Sam Atkins
e6bb0ab000 LibWeb/CSS: Take AbstractElement in compute_transitioned_properties() 2025-09-11 18:45:35 +02:00
Sam Atkins
77f1057992 LibWeb/CSS: Take AbstractElement in cascade_custom_properties() 2025-09-11 18:45:35 +02:00
Sam Atkins
b49d00996b LibWeb/CSS: Take AbstractElement in compute_text_align() 2025-09-11 18:45:35 +02:00
Sam Atkins
fa790e5095 LibWeb/CSS: Take AbstractElement in for_each_matching_rules() 2025-09-11 18:45:35 +02:00
Sam Atkins
cdc4f7c989 LibWeb/CSS: Take AbstractElement to compute alias mapping contexts 2025-09-11 18:45:35 +02:00
Sam Atkins
cdbaa73576 LibWeb/CSS: Take AbstractElement in box-type transformation functions 2025-09-11 18:45:35 +02:00
Sam Atkins
44e70d9087 LibWeb/CSS: Take AbstractElement in compute_cascaded_values() 2025-09-11 18:45:35 +02:00
Sam Atkins
82d194ba99 LibWeb/CSS: Take AbstractElement in start_needed_transitions() 2025-09-11 18:45:35 +02:00
Sam Atkins
acb211174d LibWeb/CSS: Take AbstractElement in MatchingRule collection 2025-09-11 18:45:35 +02:00
Sam Atkins
50c0b4549c LibWeb/CSS: Take AbstractElement in collect_animation_into() 2025-09-11 18:45:35 +02:00
Sam Atkins
b2ee4a9444 LibWeb/CSS: Take AbstractElement in StyleComputer::compute_properties()
As noted, the chunk of this method that deals with animations could do
with some helpers on AbstractElement, but I'm leaving that until it's
clearer how animations and pseudo-elements should interact.
2025-09-11 18:45:35 +02:00
Sam Atkins
0293176429 LibWeb/CSS: Take AbstractElement in StyleComputer::get_*_inherit_value() 2025-09-11 18:45:35 +02:00
Sam Atkins
64c3319147 LibWeb/CSS: Take AbstractElement in font computation methods 2025-09-11 18:45:35 +02:00
Sam Atkins
263c51f6ac LibWeb/CSS: Take AbstractElement in compute_pe_style_if_needed() 2025-09-11 18:45:35 +02:00
Sam Atkins
cee84d22a0 LibWeb/CSS: Take AbstractElement in cascade_declarations() 2025-09-11 18:45:35 +02:00
Sam Atkins
8706a6165d LibWeb: Take AbstractElement in compute_style_impl() 2025-09-11 18:45:35 +02:00
Sam Atkins
d0b6fadb6d LibWeb/DOM: Add CascadedProperties accessors to AbstractElement 2025-09-11 18:45:35 +02:00
Sam Atkins
27aab90e66 LibWeb: Take AbstractElement in StyleComputer::compute_style() 2025-09-11 18:45:35 +02:00
Sam Atkins
1667d6d4da LibWeb/CSS: Use AbstractElement in CSSStyleProperties::property()
Avoids duplicating the "get layout node" logic.
2025-09-11 18:45:35 +02:00
Sam Atkins
916e24de30 LibWeb/CSS: Take AbstractElement in resolve_unresolved_properties() 2025-09-11 18:45:35 +02:00
Sam Atkins
83aee2c7fc LibWeb: Take AbstractElement in resolve_unresolved_style_value() 2025-09-11 18:45:35 +02:00
Sam Atkins
40ab71e41e LibWeb/DOM: Expose AbstractElement outside of LibWeb
This ends up used by the WebContent service's ConnectionFromClient in a
later commit.
2025-09-11 18:45:35 +02:00
Sam Atkins
583d74e3a9 LibWeb/DOM: Reduce AbstractElement.h's includes
This doesn't need all of Selector.h and its various includes, it just
needs the PseudoElement enum.

StringStyleValue.h was transitively including ComponentValue.h through
this, so it now includes it directly.
2025-09-11 18:45:35 +02:00
Sam Atkins
5534ed6715 LibWeb/CSS: Use generated code to convert between dimension units 2025-09-11 17:06:44 +01:00
Sam Atkins
82f5be871a LibWeb: Generate the "Numeric Factory" OM methods on the CSS namespace
Generating boilerplate is nice! This also has the bonus that we're more
correct: I included all the units listed in the spec before,
(see https://drafts.css-houdini.org/css-typed-om-1/#numeric-factory )
but we're supposed to exactly include ones for the units we support:

> If an implementation supports additional CSS units that do not have a
  corresponding method in the above list, but that do correspond to one
  of the existing CSSNumericType values, it must additionally support
  such a method, named after the unit in its defined canonical casing,
  using the generic behavior defined above.

> If an implementation does not support a given unit, it must not
  implement its corresponding method from the list above.

Now, our factory functions will exactly match the units we support.

The changed test result is partly the order being different, and partly
that the container-query units are no longer included as we don't
actually support them.
2025-09-11 17:06:44 +01:00
Sam Atkins
66710f0065 LibIDL: Support extended attributes on namespace members
Specifically, this is so that ImplementedAs can be used on them.
2025-09-11 17:06:44 +01:00
Sam Atkins
6e3cd7dd06 LibIDL: Support partial namespaces 2025-09-11 17:06:44 +01:00
Sam Atkins
b3c099bd68 LibWeb/CSS: Use dimension_for_unit() when we don't need the exact unit
A small code reduction, and means that NumericType will catch if new
dimensions are added, and attr() will just work in that case.
2025-09-11 17:06:44 +01:00
Sam Atkins
b3e32445d3 LibWeb/CSS: Use generated FooUnit types instead of Foo::Type
I've also renamed the `m_type` and `type()` members to be `m_unit` and
`unit()` instead, to match what they actually are.
2025-09-11 17:06:44 +01:00
Sam Atkins
bda4f8cbe8 LibWeb/CSS: Use raw_value() to bounds-check all dimension types
This avoids constructing temporary objects to compare against, and
reduces the amount of code. Also, a few of these were actually wrong!
2025-09-11 17:06:44 +01:00
Sam Atkins
cbc019350b LibWeb/CSS: Generate code for CSS dimension units 2025-09-11 17:06:44 +01:00
Veeti Paananen
5e23df7d8a LibWeb: Fix case insensitivity for HTMLElement "hidden" attribute 2025-09-11 15:20:18 +02:00
Tim Ledbetter
bf8b8c260a LibWeb: Simplify interpolation of mixed percentage-dimension values 2025-09-11 06:10:23 +01:00
Callum Law
a46453f234 LibWeb: Map logical alias transition properties to physical counterparts
Transitions apply after logical properties are mapped to their physical
counterparts so we should apply this mapping to `transition` properties

Gains us 20 WPT tests.
2025-09-11 06:08:07 +01:00
Callum Law
62176391dd LibWeb: Include z-index in transition: all
Gains us 37 WPT tests.
2025-09-11 06:08:07 +01:00
Callum Law
0209e502cf LibWeb: Use expanded longhands when computing transition properties
Using longhands rather than expanded longhands meant for instance that
we wouldn't transition `border-top-width` if we had `border` as the
transition property.
2025-09-11 06:08:07 +01:00
Callum Law
af431d800b Tests: Import/create tests related to transition property handling
Done in a distinct commit to see progress over following commits
2025-09-11 06:08:07 +01:00
Callum Law
6453c2cf71 LibWeb: Use correct animation type for fill property
This was incorrectly marked as `none` when it should be
`by-computed-value`.

Gains us 103 WPT tests.
2025-09-11 05:31:27 +01:00
Psychpsyo
c04f83f5f4 LibWeb: Add view transition related user relevancy 2025-09-10 17:37:41 +01:00
Tim Ledbetter
9c062d9d4e LibWeb: Improve interpolation of mixed percentage-dimension values
If we are interpolating between a dimension and a percentage value and
the dimension component is 0, we now return a percentage value rather
than a `calc()` value.
2025-09-10 17:00:20 +01:00
Pratyush Nair
01be928a16 LibWeb: Avoid dereferencing a null pointer to document 2025-09-10 16:57:36 +01:00
Feng Yu
66d18170c6 LibWeb: Add activeElement attribute in ShadowRoot 2025-09-10 16:52:39 +01:00
Psychpsyo
0989c3cdaf LibWeb: Keep view transition pseudo styles in sync with new element
This makes it so that view-transition pseudo-element styles are
updated before returning them from window.getComputedStyle(). This
is necessary because they could be outdated, in case JS has
modified the styles of the elements they are trying to stay in sync
with since last frame.

The corresponding WPT test has not been imported, since it still
fails for unrelated reasons.
2025-09-10 16:39:43 +01:00
Timothy Flynn
98c7a011d4 test-web: Wait for crash tests with a test-wait attribute
Similar to ref tests, we don't want to incorrectly pass a test that did
not remove this attribute.
2025-09-10 16:38:24 +01:00
Timothy Flynn
467c58eaf3 Tests/LibWeb: Disable css-view-transitions/first-line-reparent-crash 2025-09-10 16:38:24 +01:00
Tim Ledbetter
bd7348949a LibWeb: Make word-spacing and letter-spacing default value compute to 0 2025-09-10 16:12:29 +01:00
Tim Ledbetter
112a45bdf2 LibWeb: Return resolved value of normal if letter-spacing value is 0 2025-09-10 16:12:29 +01:00
Tim Ledbetter
831088939a LibWeb: Return word-spacing computed value as CSSPixels 2025-09-10 16:12:29 +01:00
Tim Ledbetter
099247d502 LibWeb: Return letter-spacing computed value as CSSPixels 2025-09-10 16:12:29 +01:00
Callum Law
c677b64773 LibWeb: Update animation type of compositing properties
This updates `background-blend-mode`, `mix-blend-mode`, and `isolation`
to be animation type `discrete` rather than `none`. This reflects
https://github.com/w3c/fxtf-drafts/commit/169b0e1 but isn't reflected
on the published spec as the published spec is out of date - see
https://github.com/w3c/fxtf-drafts/issues/547

Gains us 26 WPT tests.
2025-09-10 15:02:20 +01:00
Callum Law
b6ec5bfb7e LibWeb: Resolve border-image-width percentages as lengths
All remaining failing subtests in border-image-width-interpolation.html
are related to incorrect handling of mixed dimension and percentage
interpolation and are fixed by #6142.
2025-09-10 14:58:59 +01:00
Psychpsyo
fa3c45d0b4 LibWeb: Implement optional function IDL arguments
This allows us to run some more view transitions WPT tests, one of
which has been imported.
2025-09-10 09:49:14 -04:00
Tim Ledbetter
4559d5f6f6 LibWeb: Always round text-decoration-thickness value up to 1px 2025-09-10 15:36:12 +02:00
Callum Law
405c5ffa60 LibWeb: Propagate border-box dimensions when getting max content width
This means that we now calculate the inner width correctly for `display:
inline-block` nodes when we have `box-sizing: border-box` and
`min-width`, as we would previously assume these dimensions were all `0`
2025-09-10 11:41:30 +02:00
Tim Ledbetter
551c7f966b LibWeb: Use correct root element when resolving paint properties
Previously, the first `HTMLHtmlELement` in the given document would
always be  used when determining whether to propagate background
properties to the body element. This meant the wrong root element was
used for SVG `foreignObject` elements, which could lead to a crash.
2025-09-10 11:35:02 +02:00
me-it-is
62fe795c9b LibWeb: Throw range error when initial is greater than maximum
When constructing WebAssembly.Memory if initial is greater than maximum
a range error will be thrown.

Fixes "Initial value exceeds maximum" in
https://wpt.fyi/results/wasm/jsapi/memory/constructor.any.worker.html?product=ladybird
2025-09-10 05:23:07 +02:00
Luke Wilde
6d3fd2b543 LibWeb: Implement cookie fetching for Workers
Allows formulas to update on Google Sheets, which uses a Worker to
update them and makes cookie authenticated requests, which was failing
before this commit.

This has the limitation that it has to proxy through the WebContent
process, but that's how the current infrastructure is, which is outside
the scope of this commit.
2025-09-09 15:28:38 +02:00
Luke Wilde
05438e70f1 LibWeb: Receive cookies through principal_host_defined_page
Previously we depended on an associated document on the ESO to get to
the page, but Workers do not have documents. However, we can simply get
to the page with `principal_host_defined_page`, removing the issue.
2025-09-09 15:28:38 +02:00
Psychpsyo
905e749575 LibWeb: Use correct style rule index in view transitions
This used to crash a lot of attempted view transitions, now it
doesn't anymore.
2025-09-09 12:50:09 +01:00
dependabot[bot]
5d9e51d675 CI: Bump actions/github-script from 7 to 8
Bumps [actions/github-script](https://github.com/actions/github-script) from 7 to 8.
- [Release notes](https://github.com/actions/github-script/releases)
- [Commits](https://github.com/actions/github-script/compare/v7...v8)

---
updated-dependencies:
- dependency-name: actions/github-script
  dependency-version: '8'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-09 12:32:16 +02:00
Callum Law
1c2c77b441 LibWeb: Remove unnecessary handling of StyleValueList border longhands
This is no longer needed as we parse border longhands directly to
ShorthandStyleValues
2025-09-09 11:45:47 +02:00
Callum Law
a7e5ded188 LibWeb: Add generic logic for parsing "positional-value-list-shorthands"
Continues the work started in #5386 to simplify handling of positional
value list shorthand properties.

Previously we would parse these as `StyleValueList`s and then rely on
`StyleComputer::for_each_property_expanding_shorthands` to expand them
into longhands.

This required a bit of work to handle `ShorthandStyleValue`s for the
`@page` `margin` descriptor.
2025-09-09 11:45:47 +02:00
Callum Law
b1e77b3522 LibWeb: Parse longhands of border as ShorthandStyleValues
Previously we would instead parse these as single values and rely on
ad-hoc functionality in `for_each_property_expanding_shorthands` to
expand them to longhands.

This gets us a step closer to removing that ad-hoc functionality.
2025-09-09 11:45:47 +02:00
Psychpsyo
17e5289524 LibWeb: Suppress rendering due to view transitions
This also fixes a bug in the view transitions code that was
required to get the imported test to pass. The code for setting
the initial containing block size just did not set the right thing,
since doing so would trigger an error later on.

That later error resulted from walking up the tree, without
considering that the document element has a parent that is not
itself an element. (and then doing element things to it)
2025-09-09 10:25:17 +02:00
Aliaksandr Kalenik
18cf540bfb LibWeb: Fix crashing in LengthOrAutoOrCalculated::without_auto()
...when `LengthOrAutoOrCalculated` holds calculated value. We were
incorrectly assuming that if contained value is not auto, then it must
be a length.

Fixes crashing on https://hollowknightsilksong.com/
2025-09-08 19:35:31 +01:00
Zaggy1024
cae14c763d LibMedia: Convert FFmpeg time units to AK::Duration with integer math
The existing conversion was rounding to the nearest millisecond, which
is much less precision than most videos will want. Instead, use only
integer math to directly convert the presentation time to seconds and
nanoseconds for our AK::Duration to represent accurately.
2025-09-08 13:29:04 -05:00
Aliaksandr Kalenik
98c00f4b45 Tests: Import resize-observer/observe.html WPT test 2025-09-08 18:39:54 +02:00
Aliaksandr Kalenik
ad15edf2ff LibWeb: Pass ResizeObserver instance as a second argument to callback 2025-09-08 18:39:54 +02:00
Aliaksandr Kalenik
1cc9fb6135 LibWeb: Use ResizeObserver instance as this in callback function 2025-09-08 18:39:54 +02:00
zac
5c14db868d LibWeb: Prevent hidden PaintableWithLines being hit tested
Now follows the same pattern as PaintableBox and StackingContext, where
it exits if hidden, then hit tests children, then hit tests itself if
it's `visible_for_hit_testing()`.
2025-09-08 15:36:27 +02:00
zac
4e892b8b67 LibWeb: Prevent StackingContext from hit testing when not visible
It exits if not visible, then hit tests children, then hit tests itself
if it's `visible_for_hit_testing()`.
2025-09-08 15:36:27 +02:00
Aliaksandr Kalenik
e2eb8716e5 LibWeb: Fix incorrect margin collapsing behavior [BFC]
This change removes premature reset of
`block_container_y_position_update_callback`. Also makes callback
private in `BlockMarginState`, because resetting it independently of
currently accumulated margins is incorrect.

Lots of test expectations are updated, but there is no visual
difference.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/6074
2025-09-08 14:09:06 +02:00
Aliaksandr Kalenik
01bfb5bc81 LibWeb: Capture y by value in position update callback [BFC]
Callback registered by
`register_block_container_y_position_update_callback()` is executed
after `layout_block_level_box()` returned, so capturing stack variable
`y` by reference is UB.
2025-09-08 14:09:06 +02:00
InvalidUsernameException
08162fb9af LibWebView+Base: Remove unnecessary scrollbar from error pages
I've been looking at the crash-page too much recently and the slight
scrollbar caused by the padding has been annoying me.
2025-09-08 12:02:44 +01:00
Callum Law
5ed3b2ed16 LibWeb: Support interpolation of CalculatedStyleValue
We also support interpolating from a CalculatedStyleValue to a
compatible dimension or percentage style value.

This also brings with it a couple of improvements in how we handle
interpolation between mixed dimension and percentage types in terms of:
 - Proper simplification of the resulting calc()
 - Improved handling of interpolation outside the 0-1 range
2025-09-08 11:58:44 +01:00
Andreas Kling
8833ffaf5d LibWebView: Enable HTTP cache by default
The HTTP cache is now stable enough that we can ask more people to help
us testing it. So let's turn it on by default! It can be turned off with
--disable-http-cache if needed.
2025-09-08 12:53:21 +02:00
Aliaksandr Kalenik
4a140b740c LibWeb: Early return if document doesn't have navigable in container
...navigable shared attribute processing steps.

After e095bf3a5f
https://wpt.live/html/rendering/pixel-length-attributes.html ends up in
this function with null navigable, which leads to crash while executing
steps. Adding early return in case iframe's document doesn't have a
navigable is enough to make the test pass again.

This commit doesn't import the WPT test, because it's already imported
and we have it disabled since it takes too much time on CI.
2025-09-08 12:12:23 +02:00
Callum Law
f061f565b9 LibWeb: Remove unused ComputedProperties::resolve_opacity_value 2025-09-08 11:03:32 +01:00
Callum Law
5a7eaf6f73 LibWeb: Store flood-opacity in computed form in ComputedProperties 2025-09-08 11:03:32 +01:00
Callum Law
91e88ad6e8 LibWeb: Store stroke-opacity in computed form in ComputedProperties 2025-09-08 11:03:32 +01:00
Callum Law
c045969234 LibWeb: Store stop-opacity in computed form in ComputedProperties 2025-09-08 11:03:32 +01:00
Callum Law
9434b08bed LibWeb: Store fill-opacity in computed form in ComputedProperties 2025-09-08 11:03:32 +01:00
Callum Law
1ba84de4f6 LibWeb: Store opacity in computed form in ComputedProperties 2025-09-08 11:03:32 +01:00
Callum Law
246a1c41ff LibWeb: Don't resolve calc'd opacity percentages at parse time
This behaviour should only apply to literal percentages as clarified
here: https://github.com/w3c/csswg-drafts/commit/4ee8429

We were also doing this wrong by converting the numeric type of the calc
to Length which was causing values to be defaulted to 1 instead (hence
the new passing tests for computed values as well)
2025-09-08 11:03:32 +01:00
Callum Law
d53668b376 Tests: Update opacity parsing tests 2025-09-08 11:03:32 +01:00
Psychpsyo
9ea8b5a0a3 LibWeb: Add CSS column-height property 2025-09-07 15:59:39 +01:00
InvalidUsernameException
b057bad102 LibWeb/CSS: Migrate some call sites to non-deprecated resolve_* methods
This ensures that we clamp values for properties like padding-* to valid
ranges (non-negative in this case) if they are specified with `calc()`.

The length-related changes in this commit combined with the ones from
the previous commit fix the primary layout issue on https://lwn.net
(yes, not the first place I would have expected problems either).
2025-09-07 15:55:16 +01:00
InvalidUsernameException
7afcf305b2 LibWeb/CSS: Resolve percentages against values in their canonical unit 2025-09-07 15:55:16 +01:00
InvalidUsernameException
923dce4ec1 LibWeb/CSS: Add missing include 2025-09-07 15:55:16 +01:00
Tim Ledbetter
fa6c7959ff LibWeb: Pass calculation context by const reference 2025-09-07 14:50:36 +01:00
Tim Ledbetter
96b628fe21 LibWeb: Clamp interpolated values to their accepted range 2025-09-07 14:50:36 +01:00
Psychpsyo
56739b4b16 LibWeb: Implement plumbing for view transitions
This implements large parts of the CSS view-transitions-1 spec.
2025-09-07 13:58:05 +01:00
Pavel Shliak
4f0e8236a0 LibJS: Make class accessors non-enumerable
According to ECMA-262 §15.4.5 (MethodDefinitionEvaluation),
getters and setters defined in class bodies
must create property descriptors with
[[Enumerable]]: false. Previously we incorrectly marked them enumerable.

This patch updates `ClassMethod::class_element_evaluation` so that both
getter and setter descriptors use `.enumerable = false`.
2025-09-07 08:35:10 -04:00
Tim Ledbetter
21082f5002 Meta: Only update hosts file when necessary in WPT.sh
Previously, the hosts file was updated at the same time the WPT repo
was cloned, but updating the hosts file is only necessary for commands
that start the WPT test runner.
2025-09-07 08:14:42 -04:00
euro20179
e442aa6e10 LibWeb: Ensure parser cannot change the mode is handled
This fixes at least 1 wpt bug where text/plain documents are rendered in
quirks mode. The test in question: https://wpt.live/html/browsers/browsing-the-web/read-text/load-text-plain.html
2025-09-07 11:11:43 +01:00
Tim Ledbetter
3c6472dc00 LibWeb: Do nothing when calling CanvasPath.closePath() with empty path 2025-09-06 08:47:48 -04:00
Pavel Shliak
a125bc97c4 LibWasm: Fix memory.fill ignoring memory index and unsafe bounds check
Previously, the memory.fill instruction always wrote to memory 0,
ignoring the selected memory index. This caused incorrect behavior
in multi-memory modules (e.g. filling mem0 instead of mem1).
Additionally, the bounds check used `destination_offset + count`
without overflow checking, which could wrap and bypass validation.

This patch:
- Passes `args.memory_index` into store_to_memory, so the correct
  memory is filled.
- Uses Checked<u32> for destination_offset + count, consistent
  with memory.copy and memory.init, to prevent overflow.

Minimal repro:

    (module
      (memory $m0 1)
      (memory $m1 1)

      (func (export "go") (result i32)
        ;; Fill mem1[0] with 0xAA
        i32.const 0
        i32.const 170
        i32.const 1
        memory.fill (memory 1)

        ;; Return (mem1[0] << 8) | mem0[0]
        i32.const 0
        i32.load8_u (memory 1)
        i32.const 8
        i32.shl
        i32.const 0
        i32.load8_u (memory 0)
        i32.or
      )
    )

Before fix: returns 170 (0x00AA).
After fix:  returns 43520 (0xAA00).
2025-09-06 08:51:11 +02:00
Pavel Shliak
9e11fa0ac6 LibWasm: Close byte list for active data segments in WAT output
LibWasm/Printer no longer leaves
the byte list in active data segments unclosed
2025-09-06 06:21:03 +02:00
Pavel Shliak
c53d9d7122 LibWasm: Use 0x40 flag for SIMD memory memidx like scalar ops
SIMD loads/stores checked bit 0x20 of the align immediate to detect a
following memory index, unlike scalar mem ops which use 0x40 per the
multi-memory encoding. This caused the memidx byte to be misparsed as
the next immediate (e.g. offset).

Update both SIMD sites (v128 load/store and lane variants) to check and
clear 0x40, then read LEB128<u32> memidx.

Repro:
  (module (memory $m0 1) (memory $m1 1)
    (func (export "go")
      i32.const 0
      v128.load (memory 1)
      drop))
Before: printed memidx 0 with offset 1.
After:  prints memidx 1 with offset 0.
2025-09-06 06:19:40 +02:00
Pavel Shliak
cdab6b0a2f LibWasm: Fix pushes for i16x8.replace_lane in Opcode table
The opcode entry declared i16x8_replace_lane with pushes = -1, but
replace_lane pops 2 (vector, lane value) and pushes 1 result vector.
Set pushes to 1 to match the other replace_lane opcodes.
2025-09-06 06:06:44 +02:00
Pavel Shliak
5f4ad17f89 LibWasm: Fix Negate::name() to return "neg"
Negate was incorrectly returning "== 0", a copy/paste from EqualsZero.
This patch corrects it to return "neg", matching the operator's actual
semantics and WebAssembly mnemonics (f32.neg, f64.neg).
2025-09-06 01:06:58 +02:00
Timothy Flynn
4b68fab14c WebContent: Set WebDriver scroll behavior to "instant"
https://github.com/w3c/webdriver/commit/bba8cb7
2025-09-05 10:23:07 -04:00
Zaggy1024
7811c2e71b LibMedia: Ensure that the PulseAudioContext atexit() call succeeds 2025-09-04 19:37:56 +02:00
Zaggy1024
ee3c080fb5 LibMedia: Initialize Track's primitive fields to zero 2025-09-04 13:34:19 -04:00
Zaggy1024
33e97fa5d7 LibMedia: Note that PlaybackStream callbacks cannot run simultaneously
This is a requirement of implementations of PlaybackStream, so we
should have a little comment about it. Otherwise, we may encounter data
races later.
2025-09-04 13:29:18 -04:00
Aliaksandr Kalenik
e095bf3a5f LibWeb: Rewrite "destroy a document and descendants" without spin until
Replaces spin until with GC-allocated counting object that invokes
destruction callback once all child navigable documents are destroyed.

The change doesn't have a test but not using spin until is strictly
better than using it. Also improves https://www.rottentomatoes.com/
where previously we would hang or crash after loading.
2025-09-04 15:53:46 +02:00
Aliaksandr Kalenik
308c2eab0e LibWeb: Throw parsing error if ::slotted() argument is not 1 compound
...selector. Grammar per spec: `::slotted( <compound-selector> )`, so
we should reject selector as invalid if first compound selector is
followed by something else.

This change makes layout more correct on https://www.rottentomatoes.com/
2025-09-04 13:55:20 +01:00
Sam Atkins
27caa1e175 Tests: Disable Text/input/input-file.html because of frequent flakiness 2025-09-04 13:51:16 +01:00
Sam Atkins
930ee495e7 LibWeb/CSS: Remove the "Auto" type from Length
This has always been a bit of a hack. Initially it made sense as a lot
of properties that accept a length also accept `auto`, but while
convenient, that leads to problems: It's easy to forget to check if a
length is `auto`, and places that don't accept it end up with an
invalid state lurking in the type system, which makes things unclear.
2025-09-04 13:31:24 +01:00
Sam Atkins
f74a40fdcb LibWeb/CSS: Use LengthPercentageOrAuto for rx/ry computed values
These are the last users of `Length::make_auto()`. :^)
2025-09-04 13:31:24 +01:00
Sam Atkins
dd122e2f74 LibWeb: Make LengthBox hold LengthPercentageOrAuto
Not every user of this requires an `auto` state, but most do.

This has quite a big diff but most of that is mechanical:
LengthPercentageOrAuto has `resolved_or_auto()` instead of `resolved()`,
and `to_px_or_zero()` instead of `to_px()`, to make their output
clearer.
2025-09-04 13:31:24 +01:00
Sam Atkins
70609cbf4d LibWeb/CSS: Use default constructor for initial inset value
This already sets everything to auto.
2025-09-04 13:31:24 +01:00
Sam Atkins
7244c6ddf9 LibWeb/Layout: Use LengthOrAuto in BFC::compute_width() 2025-09-04 13:31:24 +01:00
Sam Atkins
64da3b8f7d LibWeb/Layout: Use LengthOrAuto in BFC::compute_width_for_floating_box() 2025-09-04 13:31:24 +01:00
Sam Atkins
80310b5ebf LibWeb/Layout: Use LengthOrAuto in abspos non-replaced width computation 2025-09-04 13:31:24 +01:00
Sam Atkins
04622f3940 LibWeb/CSS: Use LengthPercentageOrAuto for background sizes
...instead of `auto` Lengths.

This also fixes interpolating between two `auto` `<bg-size>`s, which
fixes a lot of animation tests for both `background-size` and `mask`.
2025-09-04 13:31:24 +01:00
Sam Atkins
60fc23e916 LibWeb/CSS: Use Optional instead of auto lengths in Size
Any type of Size which has no LengthPercentage value now uses an empty
optional instead of making an auto Length as before.

We also now serialize a `fit-content` Size as `fit-content` instead of
`fit-content(auto)`, though this doesn't affect test results and I
didn't identify where it's actually used.
2025-09-04 13:31:24 +01:00
Sam Atkins
d10eaa996e LibWeb/CSS: Use empty optional for stretch in FitContentSV
...instead of using an `auto` Length.
2025-09-04 13:31:24 +01:00
Sam Atkins
f57ffc3655 LibWeb/CSS: Introduce a LengthPercentageOrAuto type 2025-09-04 13:31:24 +01:00
Sam Atkins
240536acaa LibWeb: Remove auto length from SourceSet
The spec is a bit awkward here: A few algorithms create an "empty"
SourceSet, and then assign its source-size value a few steps later, so
we have a temporary state with no length. In order to avoid complicating
the types with Optional, I've chosen to just assign it to 0px.
Previously we used `auto`, but `auto` is not a valid value here - it is
used inside the "parse a sizes attribute" algorithm, but that always
returns an actual length (or calc).
2025-09-04 13:31:24 +01:00
Sam Atkins
577564a1a2 LibWeb/CSS: Add LengthOrAutoOrCalculated
It's `LengthOrCalculated` for places that want `<length> | auto`.
2025-09-04 13:31:24 +01:00
Sam Atkins
1a3246b560 LibWeb/CSS: Stop allowing auto in ComputedProperties::length_percentage
We only had one user of this which allows `auto`, which is length_box().
So, inline the code there, remove the `auto` branch from
length_percentage(), and then remove length_percentage_or_fallback()
entirely as nobody uses it any more.
2025-09-04 13:31:24 +01:00
Sam Atkins
9b27aaa00c LibWeb/CSS: Use LengthOrAuto for clip rects 2025-09-04 13:31:24 +01:00
Sam Atkins
f663c0a72d LibWeb/CSS: Introduce a LengthOrAuto type
`clip: rect()` in particular wants this for its parameters.
2025-09-04 13:31:24 +01:00
Sam Atkins
381d3bf4e0 LibWeb: Stop pretending text-decoration-thickness is a LengthPercentage
It has two keywords: auto and from-font. from-font isn't handled
properly yet, but at least we have a FIXME for it now. :^)
2025-09-04 13:31:24 +01:00
Sam Atkins
ae40c7ed95 LibWeb/CSS: Use Size in GridSize
Reduces a bunch of duplicate logic here for holding different sizing
functions, and also removes a user of `auto` Length.
2025-09-04 13:31:24 +01:00
Sam Atkins
ad5f7c56c1 LibWeb/CSS: Prepare Size for use in GridSize
Make it constructible from a LengthPercentage, report whether it
contains a length-percentage, and add an equality operator.
2025-09-04 13:31:24 +01:00
Callum Law
d3e04c96d9 LibWeb: Simplify SourceSet::normalize_source_densities
Relative lengths should be resolved against the initial font rather than
the element's font so all the work around updating layout is unnecessary
2025-09-04 10:05:44 +01:00
Aliaksandr Kalenik
4c7da460dc LibWeb: Add ::slotted() pseudo-element support
Implements `::slotted()` to enough extent we could pass the imported WPT
test and make substantial layout correctness improvement on
https://www.rottentomatoes.com/
2025-09-04 09:51:34 +01:00
Jelle Raaijmakers
8986e1f1ec LibWeb: Merge nested editing hosts
If a node with `contenteditable=true/plaintextonly` is the child of an
editable node or an editing host, we should make it editable instead of
an editing host. This effectively merges nested editing hosts together,
which is how other browsers deal with this as well.

Gains us 5 WPT subtest passes in `editing`.
2025-09-04 00:24:55 +02:00
Jelle Raaijmakers
3931c0336b LibWeb: Clean up some editing-related code
No functional changes.
2025-09-04 00:24:55 +02:00
Kenneth Myhra
dd83634121 LibWeb/FileAPI: Remove redundant if condition
We have already verified above that options->type is not empty.
2025-09-03 21:43:36 +02:00
Kenneth Myhra
a021134457 LibWeb/FileAPI: Make sure to always run the constructor steps for Blob
Previously we did not execute the constructor steps if we constructed a
Blob from a ByteBuffer and a String. Though we only construct a Blob
from ByteBuffer and String internally we still need to run these steps.

By creating the new type 'BlobPartsOrByteBuffer' we can consolidate
those two approaches to creating a Blob into our already existing
constructor steps.
2025-09-03 21:43:36 +02:00
InvalidUsernameException
f9a54d6439 Tests/LibWeb: Do not crash test runner when screenshot sizes differ
This regressed in 0f642ecb5c.
2025-09-03 17:31:21 +02:00
InvalidUsernameException
a259ed4db6 Tests/LibWeb: Do not leak multiple GB of screenshots in the test runner
For every ref tests actual and expected screenshots are taken. These
screenshots are only needed while the individual test executes. However,
they are never freed during the run, leading to a continuous increase in
memory usage of the test runner while executing ref tests.

With the number of ref tests growing, this currently amounts to nearly 3
GB of uncompressed bitmap data being held in memory. Lets avoid that by
clearing the screenshot data at the end of each test. With this change
applied, the memory usage of test-web stays stable and below 100 MB for
the entire test run.
2025-09-03 17:31:21 +02:00
Luke Wilde
18c0739bbb LibJS: Copy base object of LHS of assignment to preserve eval order
Previously, the given test would create an object with the test
property that pointed to itself.

This is because `temp = temp.test || {}` overwrote the `temp` local
register, and `temp.test = temp` used the new object instead of the
original one it fetched.

Allows https://www.yorkshiretea.co.uk/ to load, which was failing in
Gsap library initialization.
2025-09-02 12:59:52 +01:00
ayeteadoe
454e6a6f7f LibWeb/Gamepad: Forward declare SDL components to fix Windows build
We have to prevent from including any SDL headers in LibWeb headers.
Otherwise there will be transitive Windows.h includes that will
re-declare some of our existing forward decls/defines in
LibCore/SocketAddressWindows.h
2025-09-02 11:11:12 +01:00
Tim Ledbetter
5ce518f493 LibWeb: Change iterable<T> declaration order to match specifications 2025-09-02 10:41:33 +01:00
Tim Ledbetter
fdbd25967b LibIDL: Allow iterable<T> to be defined before property getter
Previously, an error would occur if an `iterable<T>` was defined before
the required value iterator. An is now also reported if an`iterable<T>`
is defined before a pair iterator, previously this error would only be
reported if the iterable was defined after the pair iterator.
2025-09-02 10:41:33 +01:00
Luke Wilde
9adf27f009 LibWeb: Add tests for Gamepad API by utilising virtual SDL3 joysticks 2025-09-01 21:10:47 +02:00
Luke Wilde
74e0483ea5 LibWeb: Implement the Gamepad API with SDL3 2025-09-01 21:10:47 +02:00
Luke Wilde
50dcd8fc85 Meta+WebContent+LibWeb: Add, link and initialize SDL3 2025-09-01 21:10:47 +02:00
Luke Wilde
36d5e814ef IDLGenerator: Use fully qualified type names for namespace conflicts 2025-09-01 21:10:47 +02:00
Tete17
848020a9a1 LibWeb: Add more WPT test for TrustedTypes
We now implement 100% of the idlharness :)
2025-09-01 16:19:24 +01:00
Tete17
b6a16ed3c6 LibWeb: Implement get_trusted_type_compliant_string algorithm 2025-09-01 16:19:24 +01:00
Tete17
ab82c4c5fc LibWeb: Implement Content Security Check for sink types 2025-09-01 16:19:24 +01:00
Tete17
a5c631aff3 LibWeb: Implement Does Sink Require Trusted Types algo 2025-09-01 16:19:24 +01:00
Tete17
8df173e1bd LibWeb: Add require-trusted-types-for Directive
This is meant to configure the behaviour of an injection sinks when a
string is passed.
2025-09-01 16:19:24 +01:00
Tete17
2083708897 LibWeb: Enumerate all injection sinks relevant to the TrustedTypes spec
This enables us to more strictly control the available sinks we support.
2025-09-01 16:19:24 +01:00
Tete17
af933c2721 LibWeb: Implement last 2 remaining FIXME's on TrustedTypePolicyFactory
emptyHTML is used to avoid having to create a no-op policy while
emptyScript is used to detect if the browser supports the spec natively.
2025-09-01 16:19:24 +01:00
Tete17
4f9eb78b9d LibWeb: Refactor magic string in favour of TrustedTypeName 2025-09-01 16:19:24 +01:00
Tim Ledbetter
7dade36d96 LibWeb: Ensure SVG image element respects viewBox
Previously, any active viewBox was ignored by SVG image elements.
2025-09-01 13:28:35 +01:00
Callum Law
56c4e8199b LibWeb: Clamp negative font-size when loading font
`font-size` can end up with a negative value - either due to `calc`
being resolved using the old method which doesn't clamp the value, or
interpolation - in this case we should clamp negative values to zero.

Gains us 36 new WPT passes and fixes crashes in the three imported
tests.
2025-09-01 12:28:53 +01:00
Callum Law
39dc604642 LibWeb: Return unanimated font-size in ComputedProperties::font_size()
1a3da3d introduced a crash as we assumed that font-size values were
always stored in their computed forms, this isn't correct for animated
font-size values.

As a temporary workaround until we store animated font-sizes in their
computed form we will return the non-animated value - this restores the
functionality prior to 1a3da3d
2025-09-01 12:28:53 +01:00
Callum Law
6fcaceedd9 LibWeb: Clamp negative computed values for padding-* properties
Interpolation can leave `padding-*` values as negative - this should be
handled by interpolation clamping it to the allowed range of values
but we don't yet do that. As a stop gap we can clamp this before setting
it in ComputedValues.

This fixes 3 crashes and gains us 11 passes in the imported WPT tests
2025-09-01 12:28:53 +01:00
Jelle Raaijmakers
a0b7d0542c LibWeb: Misc. code cleanup of LayoutState
No functional changes.
2025-09-01 11:20:43 +01:00
Jelle Raaijmakers
64093f7d26 LibWeb: Detach paint tree from layout tree in one go
We used to only walk the paintable root tree from the layout root and
detach paintables from there. In some cases, this could leave paintables
behind, so we added another loop that iterates over all layout nodes and
detaches their paintables, if any remained.

Instead of traversing two trees like this, just traverse the layout tree
once and detach the inclusive descendant's paintables, similar to how we
deal with the DOM tree immediately after that.
2025-09-01 11:20:43 +01:00
Jelle Raaijmakers
f122e1f78a LibWeb: Let PaintableBox be const for longer in LayoutState
Makes it clearer where we're modifying it. No functional changes.
2025-09-01 11:20:43 +01:00
Ali Mohammad Pur
4462348916 Everywhere: Slap some [[clang::lifetimebound]] where appropriate
This first pass only applies to the following two cases:
- Public functions returning a view type into an object they own
- Public ctors storing a view type

This catches a grand total of one (1) issue, which is fixed in
the previous commit.
2025-09-01 11:11:38 +02:00
Ali Mohammad Pur
8b3e888920 LibMedia: Don't store view into deleted ByteString
DecoderError::formatted() made a ByteString, took a view into it,
dropped the ByteString, then propagated the (now invalid) view back to
the caller as an error.
Since the object has to keep the ByteString alive, keep it as a variant
to make sure the "happy" path with no alloc remains alloc-free.
2025-09-01 11:11:38 +02:00
Aliaksandr Kalenik
0ef61ad813 LibWeb: Skip flexible tracks expansion if there's no any of them [GFC]
We could skip calculating fr unit size if we know there's no flexible
tracks.
2025-08-31 19:13:14 +02:00
Aliaksandr Kalenik
7b1a97c109 LibWeb: Skip calculating item's min-content size if possible [GFC]
We could skip doing item's intrinsic min-content layout if we know for
sure that there's no tracks with intrinsic sizing function to distribute
the min-content size to.
2025-08-31 19:13:14 +02:00
Andreas Kling
f89afe8e27 LibJS: Allocate context up front in SuperCallWithArgumentArray
This also removes the last user of Interpreter's argument buffer
allocation API, which we've used to repeatedly shoot ourselves in the
foot. Good-bye!
2025-08-31 15:24:37 +02:00
Andreas Kling
996ea109b3 LibJS: Allocate context up front when calling with argument array
This necessitated splitting CallWithArgumentArray into three variants,
one for each call type (call, construct and direct eval).
2025-08-31 15:24:37 +02:00
Andreas Kling
e5b07858a2 LibJS: Allocate Call{Construct,DirectEval,Builtin) contexts up front
We already do this for normal Call contexts, so this is just continuing
to propagate the same pattern to other instructions.

Fixes #6026
2025-08-31 15:24:37 +02:00
Idan Horowitz
849ade88ce LibWeb: Fire change events on deletion in FormAssociated Text Elements
Previously we would only trigger change events on insertion, which
resulted in javascript code missing changes due to deletion.

This makes the calculator on the MDN simple web worker demo update on
deletion as well.
2025-08-31 01:47:52 +02:00
Aliaksandr Kalenik
87c7fb1d63 LibWeb: Use 0 as min-content size for items with overflow:hidden [GFC]
This behavior is not specified but required to match other browsers.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/5907
2025-08-30 15:57:45 +02:00
Erik Kurzinger
42339be999 LibWeb: Use intrinsic size for current_image_bitmap
Currently, ImageProvider::current_image_bitmap takes a Gfx::IntSize
argument which determines the size of the returned bitmap. The default
value of this argument is 0x0 which causes the function to return
nullptr. This behavior is evidently unintuitive enough that it has lead
to incorrect usage in multiple places. For example, the 2D canvas
drawImage method will never actually draw anything because it calls
current_image_bitmap with no arguments. And the naturalWidth and
naturalHeight of an image will always return 0 (even after the image has
loaded) for the same reason.

To correct this and hopefully avoid similar issues in the future,
ImageProvider::current_image_bitmap will be renamed to
current_image_bitmap_sized, and the default value for the size argument
will be removed. For consistency, a similar change will be made to
SVGImageElement::default_image_bitmap.

The existing current_image_bitmap function will no longer take a size
argument. Instead it will always return a bitmap of the image's
intrinsic size. This seems to be what most existing callers had already
assumed was the function's behavior.
2025-08-30 15:49:11 +02:00
Erik Kurzinger
0189553bed LibWeb/WebGL: Avoid freeing GL objects belonging to other contexts
The free_surface_resources() function in OpenGLContext.cpp is
responsible for freeing all GL and EGL objects tied to the lifetime of
the painting surface. It is called when the associated canvas is resized
or destroyed. However, if there are multiple WebGL canvases and another
canvas's context is current when the function is called, it will
unintentionally free GL objects belonging to that other context.

To fix this, we call eglMakeCurrent at the start of
free_surface_resources(). This ensures that we will be deleting the
intended objects.

Note that m_impl->surface could be EGL_NO_SURFACE if
free_surface_resources() is called before the painting surface has been
created, but that should be fine. EGL_KHR_surfaceless_context support is
ubiquitous at this point.
2025-08-30 15:49:11 +02:00
Erik Kurzinger
21ff66c6cb LibWeb/SVG: Parse comma-separated SVG viewBox
From the SVG spec

The value of the ‘viewBox’ attribute is a list of four numbers <min-x>,
<min-y>, <width> and <height>, separated by whitespace and/or a comma...

Currently try_parse_view_box will fail to parse the attribute if the
values are separated by commas.

This change replaces try_parse_view_box with a more correct
implementation. It will reside in the AttributeParser.cpp. This new
implementation correctly handles comma-separated viewBox values, and is
also more robust against invalid inputs.

Additionally, it adds a new test case to ensure viewBox values with
various syntax are parsed correctly and invalid values are rejected.
2025-08-30 15:49:11 +02:00
Tete17
c3aa8f0c8d LibWeb: Remove FIXME from attribute validity in HTMLFieldSetElement
It already implements the function.
2025-08-29 19:27:30 +01:00
Tete17
70c3f203ef LibWeb: Implement validation_message for form associated elements
It wins us a quick WPT test as well as implement a bunch of IDL methods.
2025-08-29 19:27:30 +01:00
Tete17
8ab568bc76 LibWeb: Unify will_validate for form associated elements
We had the same implementation in quiet a few places. With this change
we unify them in a single place
2025-08-29 19:27:30 +01:00
Tete17
af88a43e9a LibWeb: Unify check_validity for form associated elements 2025-08-29 19:27:30 +01:00
Tete17
44053ed3c2 LibWeb: Unify report_validity for form associated elements
This function was implemented in a few classes but is a common element
in all form associated elements and the functionality should be there.

With these minimal changes we get to implement 4 idl functions for free.
2025-08-29 19:27:30 +01:00
Tete17
46b1466998 LibWeb: Remove extra whitespace in idl file 2025-08-29 19:27:30 +01:00
Luke Wilde
b17783bb10 Everywhere: Change west consts caught by clang-format-21 to east consts 2025-08-29 18:18:55 +01:00
Callum Law
829437c11d LibWeb: Implement autocorrect attribute 2025-08-29 15:47:17 +01:00
Callum Law
a6fb7c84e9 LibWeb: Implement the autocapitalize attribute 2025-08-29 15:47:17 +01:00
Callum Law
11457e533a LibWeb: Update is_autocapitalize_inheriting method name with spec
This was changed when the autocorrect attribute was introduced:
https://github.com/whatwg/html/commit/7bab05a
2025-08-29 15:47:17 +01:00
Callum Law
e539990c7f LibWeb: Implement writingSuggestions attribute 2025-08-29 15:47:17 +01:00
Callum Law
87e0523664 LibWeb: Implement the spellcheck attribute 2025-08-29 15:47:17 +01:00
Sam Atkins
7be645a091 LibWeb/CSS: Implement CSSNumericType.equals() 2025-08-29 11:57:10 +02:00
Sam Atkins
d29084997e LibWeb/CSS: Reify math functions into CSSMathValue types 2025-08-29 11:57:10 +02:00
Sam Atkins
9264f540dd LibWeb/CSS: Correct definition of CSSNumericType
What I thought was a spec issue was actually a combination of my own
misunderstanding and a bug in our IDL generator. With that bug fixed, I
can correct this to how it is in the spec.
2025-08-29 11:57:10 +02:00
Sam Atkins
ffb236adbd IDLGenerators: Correctly treat optional enums as optional
Specifically, this makes enums in dictionaries not cause compile errors.
2025-08-29 11:57:10 +02:00
Sam Atkins
e174215845 LibGC: Add Ptr::as_nonnull()
Convert from a GC::Ptr to a GC::Ref directly, instead of having to write
`GC::Ref { *thing }`.
2025-08-29 11:57:10 +02:00
Sam Atkins
277117eed5 LibWeb/CSS: Implement CSSNumericValue.parse()
Reifying the result gets quite ad-hoc. Firstly because "parse a
component value" produces a ComponentValue, not a full StyleValue like
we need for math functions. And second, because not all math functions
can be reified as a CSSNumericValue:

Besides the fact that I haven't implemented CalculatedStyleValue
reification at all yet, there are a lot of math functions with no
corresponding CSSMathValue in the spec yet. If the calculation tree
contains any of those, the best we can do is reify as a CSSStyleValue,
and that isn't a valid return value from CSSNumericValue.parse(). So, I
made us throw a SyntaxError in those cases. This seems to match
Chrome's behaviour. Spec issue:
https://github.com/w3c/css-houdini-drafts/issues/1090
2025-08-29 11:57:10 +02:00
Sam Atkins
73d7d6b831 LibWeb: Generate a math_function_from_string() function
This will be used as a convenient way to see if a string is the name of
a math function.
2025-08-29 11:57:10 +02:00
Sam Atkins
177395155a LibWeb/CSS: Implement CSSMathClamp
As the final CSSMathFoo class, this makes the serialization test finally
run instead of crashing.
2025-08-29 11:57:10 +02:00
Sam Atkins
dd3007dcd7 LibWeb/CSS: Implement CSSMathMax
Basically the same as CSSMathMin.
2025-08-29 11:57:10 +02:00
Sam Atkins
1a35795f47 LibWeb/CSS: Implement CSSMathMin 2025-08-29 11:57:10 +02:00
Sam Atkins
8efd0639cd LibWeb/CSS: Implement CSSMathInvert
This is almost identical to CSSMathNegate.
2025-08-29 11:57:10 +02:00
Sam Atkins
f2ec04d20d LibWeb/CSS: Implement CSSMathNegate 2025-08-29 11:57:10 +02:00
Sam Atkins
e21610180f LibWeb/CSS: Implement CSSMathProduct
This is almost identical to CSSMathSum.
2025-08-29 11:57:10 +02:00
Sam Atkins
e17052a343 LibWeb/CSS: Implement CSSMathSum 2025-08-29 11:57:10 +02:00
Sam Atkins
a46c980629 LibWeb/CSS: Implement CSSNumericArray 2025-08-29 11:57:10 +02:00
Sam Atkins
6c8876cdb8 LibWeb/CSS: Implement CSSMathValue
This is a base class for the various math functions, so it's not used
directly anywhere.
2025-08-29 11:57:10 +02:00
Sam Atkins
ef8ca729cc IDLGenerators: Make 'operator' a reserved word
This is the name of an attribute of CSSMathValue.
2025-08-29 11:57:10 +02:00
Sam Atkins
4791f9e88f IDLGenerators: Make attribute names C++-safe 2025-08-29 11:57:10 +02:00
Sam Atkins
46b55f0f46 LibWeb/CSS: Implement rectify_a_numberish_value() 2025-08-29 11:57:10 +02:00
Tuur Martens
222ca9e2cd Documentation: Rectify incorrect preset name 2025-08-29 11:54:16 +02:00
Bernard Niset
de99dd42a2 Tests: Use 127.0.0.1 instead of localhost in HTTP test server
This fixes slow test execution on macOS where localhost resolution
has a 200ms delay due to IPv6 fallback behavior in libcurl.

The XMLHttpRequest-override-mimetype-blob.html test now runs in ~0.6s
instead of ~16s on macOS.

Fixes #4850
See also: https://github.com/curl/curl/issues/2281
2025-08-29 10:34:43 +01:00
Tim Ledbetter
d4f05bc4ef LibWeb: Implement <feImage> SVG filter 2025-08-29 10:15:24 +01:00
Tim Ledbetter
5eff541804 LibWeb: Construct filter chain at paint time
This allows us to use style and box metrics when applying filters.
2025-08-29 10:15:24 +01:00
Jelle Raaijmakers
054b4dace0 LibWeb: Hit test StackingContext's children before testing visibility
If a node that establishes a StackingContext has `pointer-events: none`,
hit testing should first proceed with hit testing the SC's children
before deciding to bail. We were checking for `pointer-events` too
early, causing large parts of certain websites to be noninteractive.

Fixes #6017.
2025-08-29 01:25:01 +02:00
Jelle Raaijmakers
8bbb3429b4 LibWeb: Simplify reverse child traversal in StackingContext::hit_test()
No need for manual index fiddling, use Vector::in_reverse().
2025-08-29 01:25:01 +02:00
Timothy Flynn
2fa6655dcb LibJS: Ensure NudgeToCalendarUnit is given a non-zero duration sign
Otherwise, we trip internal Temporal spec assertions.

This is an editorial change in the Temporal spec. See:
https://github.com/tc39/proposal-temporal/commit/30f8575
2025-08-29 01:14:20 +02:00
Timothy Flynn
0c038bf12e LibJS: Read user options in a Temporal AO sooner
This is a normative change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/9924aa4
2025-08-29 01:14:20 +02:00
Timothy Flynn
355589a89e LibJS: Read user options in some Temporal toString methods sooner
This is a normative change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/3eaaadf
2025-08-29 01:14:20 +02:00
Jelle Raaijmakers
d87b3030a7 LibWeb: Prevent creation of new UsedValues for nested inline nodes
In LayoutState, used_values_per_layout_node should not be modified in
order to determine inline nodes' dimensions - all the required values
should already be in there. In 2585f2da0d
we did accidentally create new values, causing the code further down to
try and get a PaintableBox from an anonymous container and crashing.

Fixes #6015.
2025-08-28 22:38:15 +02:00
Tim Ledbetter
b23fd1f440 LibWeb: Update layout when view box properties are changed 2025-08-28 15:42:56 +02:00
Tim Ledbetter
ea41aba6c7 LibWeb: Move common SVGViewport code into an SVGFitToViewBox class
Special handling for SVGClipPathElement and SVGMaskElement, which use a
a ViewBox and PreserveAspectRatio value internally, has been moved to
`SVGFormattingContext`.
2025-08-28 15:42:56 +02:00
Jelle Raaijmakers
c8d24d4966 LibWeb: Correctly position absolute inline boxes in last line
If we were calculating the static position for an absolutely positioned
inline box that resides in the last line of its containing block, we
would not have yet provided the fragments in that line with their
final positions. Additionally, we would always move the box beneath the
fragment, which was incorrect.

Fixes #5867.
2025-08-28 13:45:37 +02:00
Jelle Raaijmakers
349fdd9f47 LibWeb: Explicitly update LineBuilder's last line at end of IFC run
Currently we're relying on LineBuilder's destructor to handle updating
the last line, if required. In order to fix an issue with our absolute
positioning code, we need to be able to update the last line earlier
than that. Remove the destructor and replace it with an explicit call to
LineBuilder::update_last_line().

No functional changes.
2025-08-28 13:45:37 +02:00
Jelle Raaijmakers
90bc805cb0 LibWeb: Simplify UsedValues::static_position()
No functional changes.
2025-08-28 13:45:37 +02:00
Andreas Kling
a26007f195 LibWeb: Don't die when transferring the same MessagePort more than once
One MessagePort can be entangled with another MessagePort, either in the
same agent, or in another agent.

In the same-agent case, the MessagePort objects point to each other via
the MessagePort::m_remote_port field.

In the separate-agent case, they live in separate processes entirely and
thus can't point at each other.

In both cases, the MessagePorts have an underlying transport channel,
which means they are "entangled". However, we can't assume that being
entangled means having a non-null m_remote_port.

This patch simply adds a missing null check for m_remote_port and thus
makes https://vscode.dev/ stop crashing with a null dereference.
2025-08-28 13:42:06 +02:00
Timothy Flynn
e36cd6d82d Tests/LibWeb: Ensure SIGINT causes test-web to exit with a non-zero code
Sending a ctrl+c to a program should generally cause it to exit with a
non-zero status code.
2025-08-28 13:25:33 +02:00
Sam Atkins
f93819eda2 LibWeb/CSS: Remove unused <an+b># code for pseudo-classes
This reverts e7890429aa and partly reverts
a59c15481f.

The one pseudo-class that accepted multiple of these was :heading(), and
since that got changed to take integers instead, there's no need to keep
this extra complexity (and memory usage) around.
2025-08-28 12:40:03 +02:00
Sam Atkins
d461e96f40 LibWeb/CSS: Make :heading() pseudo-class take integers not AN+B
Corresponds to 8eb3787e34
2025-08-28 12:40:03 +02:00
Sam Atkins
9ffc15ba3f LibWeb/CSS: Serialize :heading(...) pseudo-class properly
We originally had special handling for `:host()` as that had been the
only pseudo-class that could be both an identifier or a function.
However, this meant duplicating the serialization logic, and also we
had to manually remember to add the same hack for any other
identifier-and-function cases. Which I forgot to do with `:heading()`!

So instead, for these cases, detect if they actually have arguments
specified and use that to determine which form to serialize as. We do
still have to write a check for each one of these pseudo-classes, but
the VERIFY should make it easier to remember.
2025-08-28 12:40:03 +02:00
Tim Ledbetter
277b81ca97 LibWeb/SVG: Respect paint-order when painting SVG paths 2025-08-28 10:31:09 +01:00
Tim Ledbetter
a87a9156d5 LibWeb/CSS: Parse the paint-order property 2025-08-28 10:31:09 +01:00
Callum Law
1052ee20b0 LibWeb: Move snap_a_length_as_a_border_width to StyleComputer.cpp
All users are in this file so it makes more sense to have it here
2025-08-28 09:29:46 +01:00
Callum Law
0ce6cc38b7 LibWeb: Store outline-width in computed form in ComputedProperties
We now also store `outline-width` in ComputedValues as a `CSSPixels`
since we know it's an absolute length at `apply_style` time - this saves
us some work in converting to CSSPixels during layout.

Gains us 46 new passes since we now interpolate keywords (thick, thin,
etc) correctly.

Also loses us 4 WPT tests as we longer clamp negative values produced by
interpolation from the point of view of getComputedStyle (although the
'used' value is still clamped).
2025-08-28 09:29:46 +01:00
Callum Law
6eae92511f LibWeb: Store border-*-width in computed form in ComputedProperties
Gains us 112 new passes since we now interpolate keywords (thick, thin,
etc) correctly.

Also loses us 4 WPT tests as we longer clamp negative values produced by
interpolation from the point of view of getComputedStyle (although the
'used' value is still clamped).
2025-08-28 09:29:46 +01:00
Callum Law
3b8c2a97c0 LibWeb: Don't resolve UnresolvedStyleValues in set_keyframes
If the custom property related to this UnresolvedStyleValue changed
we would not reflect the up to date value in the animation.
2025-08-28 09:29:46 +01:00
Callum Law
d4aa40a9fe LibWeb: Use computed not just absolutized value when computing keyframes
No functionality changes as we don't yet implement computing any
property values using this method.
2025-08-28 09:29:46 +01:00
Callum Law
f9e5332d16 LibWeb: Initial work to store ComputedProperties in computed form
`StyleValue`s stored within `ComputedProperties` should be in their
computed forms, this is for various reasons including:
 - Inheritance should be of computed values
 - Animations should work on computed values
 - Triggering transitions should work on computed values

Currently we store `StyleValue`s in an absolutized version of the
specified value - this is equivalent to the computed form in many cases
which is why this hasn't been causing significant issues but there are
some cases - such as `border-*-width` keywords where this is not the
case.

No functionality change as we are yet to implement any properties
2025-08-28 09:29:46 +01:00
Jelle Raaijmakers
2585f2da0d LibWeb: Apply nested inline margin box sizes to inline layout nodes
When committing the layout state, we now take nested inlines' margin,
border and padding sizes into account.

Fixes #3491.
2025-08-28 00:05:28 +02:00
Jelle Raaijmakers
22ccae7e68 LibWeb: Make node argument to UsedValues::set_node() const
No functional changes.
2025-08-28 00:05:28 +02:00
stelar7
fde5dc7491 LibWeb/IDB: Implement create_a_request_to_retrieve_multiple_items 2025-08-27 16:13:25 +02:00
stelar7
2557e85407 LibWeb/IDB: Implement IDBIndex::get_all_records 2025-08-27 16:13:25 +02:00
stelar7
bd25be9ed3 LibWeb/IDB: Update IDBIndex::get_all_keys to spec 2025-08-27 16:13:25 +02:00
stelar7
9c2d4973c3 LibWeb/IDB: Update IDBIndex::get_all to spec 2025-08-27 16:13:25 +02:00
stelar7
bac1c84241 LibWeb/IDB: Implement retrieve_multiple_items_from_an_index 2025-08-27 16:13:25 +02:00
stelar7
559b9dbd83 LibWeb/IDB: Implement IDBObjectStore::get_all_records 2025-08-27 16:13:25 +02:00
stelar7
6f756f7f6c LibWeb/IDB: Update IDBObjectStore::get_all_keys to spec 2025-08-27 16:13:25 +02:00
stelar7
ca34ecad33 LibWeb/IDB: Update IDBObjectStore::get_all to spec 2025-08-27 16:13:25 +02:00
stelar7
839ffd45f3 LibWeb/IDB: Implement retrieve_multiple_items_from_an_object_store 2025-08-27 16:13:25 +02:00
stelar7
752210aec1 LibWeb/IDB: Implement IDBRecord 2025-08-27 16:13:25 +02:00
stelar7
fe5d5639ef LibWeb/IDB: Move Records and give more descriptive names 2025-08-27 16:13:25 +02:00
stelar7
87af53a613 LibWeb/IDB: Implement is_a_potentially_valid_key_range 2025-08-27 16:13:25 +02:00
Glenn Skrzypczak
89f94845cf LibWeb/HTML: Use from_milliseconds_since_epoch directly
Use `from_milliseconds_since_epoch` directly instead of converting to
seconds first and calling `from_seconds_since_epoch`.
2025-08-27 15:10:06 +02:00
Glenn Skrzypczak
bd34b11ca2 LibWeb/HTML: Implement date conversions for month and week inputs
This implements the conversion algorithms between strings and dates for
inputs of the types month and week.
2025-08-27 15:10:06 +02:00
Callum Law
ede80ccdfb LibWeb: Allow UseInitial in keyframes when updating animated style
This removes the AnimationRefresh argument from `collect_animation_into`
which was added in a9b8840 - it's only effect was disallowing
`UseInitial`s within keyframes when we were doing animated style
updates which I believe is unintentional.

Gains us 214 WPT tests.
2025-08-27 14:50:58 +02:00
Callum Law
d69e62425e LibWeb: Resolve CSS-wide keywords in keyframe properties
Also resolves the `revert` keyword against longhand properties rather
than potential shorthands as this could cause a crash.

Gains us 20 WPT tests.
2025-08-27 14:50:58 +02:00
joanvilarrasa
6f3b38de0f LibWeb: Emit XMLHttpRequest timeout event when the request times out
When an XMLHttpRequest times out, we now emit a timeout event
2025-08-27 14:15:48 +02:00
Timothy Flynn
086877a280 AK: Use simdutf to validate UTF-16 strings as ASCII 2025-08-27 13:25:03 +02:00
Timothy Flynn
6634100914 Meta: Update sqlite3 to version 3.50.4 2025-08-27 13:25:03 +02:00
Timothy Flynn
9f26495988 Meta: Update simdutf to version 7.4.0 2025-08-27 13:25:03 +02:00
Timothy Flynn
f2dbe267ee Meta: Update openssl to version 3.5.2 2025-08-27 13:25:03 +02:00
Timothy Flynn
57bd5baff4 Meta: Update libwebp to version 1.6.0 2025-08-27 13:25:03 +02:00
Timothy Flynn
ca4ac66543 Meta: Update libpng to version 1.6.50 2025-08-27 13:25:03 +02:00
Timothy Flynn
c7e11f1f19 Meta: Update libjpeg-turbo to version 3.1.1 2025-08-27 13:25:03 +02:00
Timothy Flynn
eaeecc8628 Meta: Update ffmpeg to version 7.1.1#4 2025-08-27 13:25:03 +02:00
Timothy Flynn
4d6f11445b Meta: Update vcpkg baseline 2025-08-27 13:25:03 +02:00
Jelle Raaijmakers
f4b04beccd LibWeb: Show inline positioning in layout tree dump
Inline nodes in our layout tree have a position, so let's show it. By
centralizing the logic for this, block nodes now lose their redundant
'content-size' dump info which is already part of the box model dump.
2025-08-27 11:53:45 +01:00
Jelle Raaijmakers
5ad4edb322 LibWeb: Use as_if instead of is + static_cast in layout tree dump 2025-08-27 11:53:45 +01:00
Jelle Raaijmakers
c738e4f97f LibWeb: Remove unused line_box_color_on from layout tree dump 2025-08-27 11:53:45 +01:00
Jelle Raaijmakers
fc86cc3375 LibWeb: Use different builder name for layout tree identifier string
Stops shadowing the outer `builder`. No functional changes.
2025-08-27 11:53:45 +01:00
Jelle Raaijmakers
b92764dcc0 LibWeb: Use StringBuilder::append_repeated() for layout tree indentation
No functional changes.
2025-08-27 11:53:45 +01:00
Jelle Raaijmakers
e173b00db6 LibWeb: Always show box model info when dumping layout tree
This is useful information. Let's not hide it.
2025-08-27 11:53:45 +01:00
Jelle Raaijmakers
676f5837b3 LibWeb: Implement SVGLength's read-only property
An SVGLength can be read-only, e.g. all animVal values cannot be
modified. Implement this for all instantiations of SVGLength.

While we're here, add `fake_animated_length_fixme()` so we can easily
find all sites where we need to improve our animated length game.
2025-08-27 11:50:27 +02:00
stelar7
f9a13ecb13 LibWeb/EME: Implement navigator.requestMediaKeySystemAccess 2025-08-27 09:58:00 +02:00
stelar7
c9b3365286 LibWeb/EME: Implement is_supported_key_system 2025-08-27 09:58:00 +02:00
stelar7
7b9d5f9fdc LibWeb/EME: Implement get_supported_configuration 2025-08-27 09:58:00 +02:00
stelar7
ca66a4933e LibWeb/EME: Implement get_supported_configuration_and_consent 2025-08-27 09:58:00 +02:00
stelar7
8f2886733c LibWeb/EME: Implement get_supported_capabilities_for_audio_video_type 2025-08-27 09:58:00 +02:00
stelar7
d65f599f92 LibWeb/EME: Add EncryptedMedia allowed allowed feature flag 2025-08-27 09:58:00 +02:00
stelar7
b1c1e33bae LibWeb/EME: Implement MediaKeySystemAccess 2025-08-27 09:58:00 +02:00
stelar7
cc50b30399 LibWeb/EME: Implement a KeySystem 2025-08-27 09:58:00 +02:00
stelar7
7f2b431810 Meta/IDL: Ensure unique variable name when iterating dictionary members 2025-08-27 09:58:00 +02:00
stelar7
69c6b6df91 Meta/IDL: Correctly generate variable names when value contains a dot 2025-08-27 09:58:00 +02:00
zac
4070f5a7e0 LibWeb: Prevent hit testing from transforming position more than once
The transform of each paintable was being applied multiple times due to
the recursive nature of the hit testing methods. Previously it used
combined_css_transform to transform the position, and then it would pass
that position to children, which would then apply combined_css_transform
again, and so on.

PaintableBoxes are also not hit tested anymore when having a stacking
context. A similar check is done in PaintableWithLines, but it was
missing from PaintableBox. Without this check some elements can get
returned multiple times from a hit test.

StackingContexts with zero opacity will now also get hit tested, as it
should have been before.
2025-08-27 09:14:33 +02:00
dependabot[bot]
2569ef0f40 CI: Bump actions/setup-java from 4 to 5
Bumps [actions/setup-java](https://github.com/actions/setup-java) from 4 to 5.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](https://github.com/actions/setup-java/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-27 08:48:21 +02:00
Viktor Szépe
1c01e183b7 Everywhere: Fix even more typos 2025-08-27 08:48:01 +02:00
Aliaksandr Kalenik
77f6edaf71 LibWeb: Support decoding SVG favicons
Adds a path that checks if blob contains SVG image before reaching for
image decoder.

Fixes logged image decoding errors on https://chatgpt.com/
2025-08-27 08:41:01 +02:00
Jelle Raaijmakers
f9888b0641 Tests: Report view's test path instead of URL in test-web
When a test is active in a test-web view, show the relative path to the
test instead of the view's URL. This gives a better starting point for
debugging than whatever the last loaded URL happened to be.

If no test is active, we still show the view's URL.
2025-08-26 19:37:16 -04:00
Ali Mohammad Pur
bf3fa13773 wasm: Don't use a new AbstractMachine to instantiate modules
Bad rebase conflict resolution broke code, grug sad.
2025-08-26 19:06:59 +02:00
Jelle Raaijmakers
84c4eb7aa9 LibWeb: Always update computed properties for finished animations
If an animation got to its finished state before its target's computed
properties could be updated, we would end up with invalid styles. Do not
skip finished animations, but prevent effect invalidation on timeline
updates if the animation is already finished.

This fixes the CI flake on WPT test
`css/css-transitions/inherit-height-transition.html`.
2025-08-26 18:47:57 +02:00
Jelle Raaijmakers
13cba5ecb4 LibWeb: Make KeyframeEffect final 2025-08-26 18:47:57 +02:00
Jelle Raaijmakers
af552856c8 LibWeb: Remove unused TemporaryExecutionContext from Animation
We don't need a temporary execution context to create a promise.
2025-08-26 18:47:57 +02:00
Jelle Raaijmakers
55255586e8 LibWeb: Remove unused include from Animation.cpp 2025-08-26 18:47:57 +02:00
Luke Wilde
e2c935475f LibWeb/Fetch: Enable callbacks in the abort signal algorithm callback
If the request has a body, the abort will interact with promises, which
requires callbacks to be enabled.

Fixes crashing on Atlassian products.
2025-08-26 16:29:35 +02:00
Tim Ledbetter
4acd517d8f LibWeb: Propagate use element width and height to the referenced element 2025-08-26 16:02:57 +02:00
Luke Wilde
847589404b LibWeb: Set filename of module scripts to full URL instead of basename
Atlassian login gets the base URL for its module scripts by throwing an
error and pulling out the current script's URL from error.stack with
regex.

Since we only returned a basename for module scripts, it would fail to
match and try and use `/` as a base URL (because it does
[matched_string] + "/"), which is not a valid base URL.
2025-08-26 15:46:45 +02:00
Ali Mohammad Pur
22448b0c35 LibWasm: Move the interpreter IP out of the configuration object
This, along with moving the sources and destination out of the config
object, makes it so we don't have to double-deref to get to them on each
instruction, leading to a ~15% perf improvement on dispatch.
2025-08-26 15:20:33 +02:00
Ali Mohammad Pur
3e62cae2ad AK: Add Variant::unsafe_get()
This performs no validation and no verifications on release.
only useful when you've already verified the type by external means.
2025-08-26 15:20:33 +02:00
Ali Mohammad Pur
d8ea9e67f8 LibWasm: Access registers directly without bounds checks
The register array is guaranteed to be large enough for all registers
used in the program, so get rid of the bounds checks.
2025-08-26 15:20:33 +02:00
Ali Mohammad Pur
f7bdc596b4 LibWasm: Avoid allocations for the label stack as much as possible
Namely, find an upper bound at validation time so we can allocate the
space when entering the frame.

Also drop labels at once instead of popping them off one at a time now
that we're using a Vector.
2025-08-26 15:20:33 +02:00
Ali Mohammad Pur
191499696b wasm: Make it possible to provide exported functions using js
This can be done by passing
`--export-js <module>.<fn>[(<arg>:type, ...)][:type]=<source>`,
which uses a js function `(arg...) => source` to resolve the requested
import `module::fn`.

All literal wasm value types (i<n> and v128) are supported as both
parameter and return types.
2025-08-26 15:20:33 +02:00
Ali Mohammad Pur
6732e1cdc3 LibWasm: Don't clobber registers on (most) calls
This still passes the values on the stack, but registers are now allowed
to cross a call boundary.
This is a very significant (>50%) improvement on the small call
microbenchmarks on my machine.
2025-08-26 15:20:33 +02:00
Kenneth Myhra
4963dea504 LibWeb/XHR: Remove outdated FIXME about Streams not integrated in XHR
Streams were integrated into XHR::send() in: https://github.com/SerenityOS/serenity/pull/24132
2025-08-26 07:18:49 -04:00
Kenneth Myhra
5d94119f4c LibWeb/XHR: Add missing spec comment for step 12 in XHR::send() 2025-08-26 07:18:49 -04:00
Kenneth Myhra
e6a3307955 LibWeb/XHR: Remove outdated FIXMEs about propagating errors
The methods these FIXMEs refer to is no longer fallible.
2025-08-26 07:18:49 -04:00
Kenneth Myhra
2b832fdc31 LibWeb/XHR: MUST handle_{errors,response_end_of_body} in async context
These cannot throw in an async context and we no longer care about minor
OOM errors so let's MUST these.
2025-08-26 07:18:49 -04:00
rmg-x
ac755d0916 Tests/LibWeb: Reset zoom on web view before running tests
This prevents test failures when running locally if the user set a
default zoom level other than 1.0
2025-08-26 06:31:22 -04:00
rmg-x
9b0157523d Base+UI: Implement user interface for defaultZoomLevelFactor setting 2025-08-26 06:31:22 -04:00
rmg-x
333164ecf9 LibWebView: Add defaultZoomLevelFactor setting and necessary plumbing 2025-08-26 06:31:22 -04:00
Idan Horowitz
73266c8498 LibWeb: Add missing cookie-age-limit steps to CookieStore::set() 2025-08-26 06:28:10 -04:00
Idan Horowitz
e059c9d5a3 WebContent: Add missing step in WebDriver cookie serialization 2025-08-26 06:28:10 -04:00
Idan Horowitz
e3a5d117a6 LibWeb: Mark CookieChangeEvent's changed and deleted as CachedAttribute
This makes them actually conform to the [SameObject] extended attribute.
2025-08-26 06:28:10 -04:00
Idan Horowitz
4c49ce5fe5 LibWeb: Add support for caching IDL attribute values
This lets us properly implement for [SameObject] for generated
constructs like FrozenArray<T>.
2025-08-26 06:28:10 -04:00
Callum Law
912ffc3f84 LibWeb: Remove unnecessary ComputedProperties::maybe_null_property
We know that all (longhand) properties have a value so this is
unnecessary.
2025-08-26 12:17:55 +02:00
Callum Law
6bccc7c242 LibWeb: Don't allocate space for shorthands in ComputedProperties
Only longhands have computed values so allocating space for shorthands
is just wasted memory
2025-08-26 12:17:55 +02:00
Callum Law
9f5696e9c5 LibWeb: Avoid getting shorthand property from ComputedProperties
ComputedProperties only includes longhands so we shouldn't try to get
shorthands - this will be asserted in a later commit.
2025-08-26 12:17:55 +02:00
Callum Law
1ba64a1d7e LibWeb: Remove StyleComputer as friend of ComputedProperties
Everything we need to do with ComputedProperties in StyleComputer can be
done via the public APIs
2025-08-26 12:17:55 +02:00
Callum Law
ed947940d7 LibWeb: Simplify conversion of percentage line-height to absolute length
We can take advantage of the fact that we already do this in
`compute_line_height`.
2025-08-26 12:17:55 +02:00
Callum Law
1a3da3d825 LibWeb: Don't store separate computed value for font_size
The StyleValue stored in m_property_values is already in it's computed
form and it's trivial to pull the underlying value out so there is no
need to store this separately.

Also removes unnecessary handling of percentage values in
`absolutize_values` - this is already handled within `compute_font`.
2025-08-26 12:17:55 +02:00
Callum Law
8682a97933 LibWeb: Only include longhands when dumping resolved style
Shorthands will always be null so are not useful
2025-08-26 12:17:55 +02:00
Callum Law
487d0abd7c LibWeb: Only consider longhands when recomputing inherited style
Only longhands have computed values so checking shorthand values is
unnecessary
2025-08-26 12:17:55 +02:00
Callum Law
c635a43c18 LibWeb: Only consider longhand properties when computing invalidation
We only store computed values for longhand properties so checking
shorthand properties is unnecessary
2025-08-26 12:17:55 +02:00
Callum Law
fba4187c8f LibWeb: Add a constant for the number of longhand properties
We use this in multiple places (and will in more places in the future)
so it's worth having as a constant from a clarity point of view
2025-08-26 12:17:55 +02:00
Callum Law
58431603ca LibWeb: Remove unused Element::resolved_css_values 2025-08-26 12:17:55 +02:00
Callum Law
5431f1534a LibWeb: Remove unnecessary check on ComputedProperties array size
This is a constant length array - this check will always be false
2025-08-26 12:17:55 +02:00
Jelle Raaijmakers
65910dc343 LibWeb: Update focusing spec steps
Update a couple of focus-related spec steps and their implementations.
The most relevant change is that we no longer allow focusing on elements
that return false for `->is_focusable()`, which necessitates fixing a
broken test that tried to `.focus()` on `<div>`s that were not
focusable. That test's output now more accurately reflects the expected
outcome as seen in other browsers.
2025-08-26 10:25:59 +02:00
Jelle Raaijmakers
cc19dd3fb0 LibWeb: Simplify getting the document's root element in elementFromPoint 2025-08-26 10:25:59 +02:00
Jelle Raaijmakers
518c048eb4 LibWeb+WebContent: Rename Document::focused_element to ::focused_area
And make it a DOM::Node, not DOM::Element. This makes everything flow
much better, such as spec texts that explicitly mention "focused area"
as the fact that we don't necessarily need to traverse a tree of
elements, since a Node can be focusable as well.

Eventually this will need to be a struct with a separate "focused area"
and "DOM anchor", but this change will make it easier to achieve that.
2025-08-26 10:25:59 +02:00
Jelle Raaijmakers
90f1c8724b LibWeb: Nested editing host focus should propagate to farthest ancestor
Nested editing hosts should act as a single big editing host, as long as
there are no uneditable elements in between.
2025-08-26 10:25:59 +02:00
Jelle Raaijmakers
6c0a0b86ba LibWeb: Simplify delete and return actions in EditingHostManager
No functional changes.
2025-08-26 10:25:59 +02:00
Jelle Raaijmakers
60a501d824 LibWeb: Do not update selection on uneditable contents without Shift key
If selection navigation happens through an editing host, we should
enforce that for collapsed navigations (i.e. moving the caret) it can
only happen if the focus node of the selection is editable.
2025-08-26 10:25:59 +02:00
Jelle Raaijmakers
09645875ea LibWeb: Clean up Selection::move_offset_to_* methods
No functional changes.
2025-08-26 10:25:59 +02:00
Jelle Raaijmakers
2e910dd6e1 LibIDL: Change overload sets to be ordered
We fill these overload sets from vectors, which means that by the time
we iterated over them, any semblance of their original ordering was
lost. Their ordering is important, because we invoke
define_native_function() for them which eventually stores ordered
properties.

This should not be an issue as long as iterating over a HashMap that was
filled in exactly the same way results in the same ordering. However,
HashTable utilizes kmalloc_good_size() to determine a good allocation
size - and the implementation for kmalloc_good_size() on Linux and macOS
differs, causing a different capacity and ordering on those platforms.

This was not caught by CI, because we run that with sanitizers enabled
which overrides malloc_good_size() on macOS, resulting in the same
behavior as on Linux.

Change the overload sets to be OrderedHashMaps instead and rebaseline
the failing test.
2025-08-26 10:14:22 +02:00
Jelle Raaijmakers
3522ff16c0 Meta: Reuse "define the operations" algorithm for generated namespaces
This is one step closer to the spec. No functional changes.
2025-08-26 10:14:22 +02:00
Tim Ledbetter
cb1a1a5cb5 LibWeb: Replace is<T>() with as_if<T>() where possible 2025-08-25 18:45:00 +02:00
Andreas Kling
3d97251da3 LibWeb: Wrap out-of-flow table children in anonymous table cells
This fixes an issue where floating children of a table box would not get
laid out at all if they were surrounded by nothing but whitespace.
2025-08-25 14:55:19 +02:00
norbiros
92b560edce LibWeb/CSS: Fix basic absolute positioning inside grid containers
Now elements with position `absolute` properly resolve their position
inside parent elements with `grid`. I also imported some WPT tests
related to that topic.

Part 2 of resolving issues on https://hack4krak.pl
2025-08-25 14:09:12 +02:00
norbiros
2ed7e0422e LibWeb/CSS: Import absolute positioning tests inside grid containers 2025-08-25 14:09:12 +02:00
Jelle Raaijmakers
305dfe3f40 AK: Don't remove CV qualifiers from types in Optional<T>
CV qualifiers are already ignored by __is_base_of(), which is what
IsBaseOf<T,U> uses.
2025-08-25 11:02:42 +02:00
sayhan
02abd3e373 Meta: Fixed variable typo switfc -> swiftc 2025-08-25 11:02:04 +02:00
Andreas Kling
0d2800e411 LibWeb: Don't relocate fragments across atomic inline boundary
All fragments inside an atomic inline box should stay within that box,
otherwise we'll screw up the paint order and paint them behind things
that they're supposed to be on top of.

This fixes an issue with inline-block content not appearing on sites
like Google Docs and Reddit, among others.
2025-08-24 21:00:08 +02:00
ayeteadoe
1573ca35cc LibDNS: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-24 12:58:27 -06:00
ayeteadoe
8150fb4cbb LibMedia: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-24 12:58:27 -06:00
ayeteadoe
a99c8d05b7 Utilities/image: Enable on Windows 2025-08-24 12:58:27 -06:00
ayeteadoe
7d00c43269 Utilities/dns: Enable on Windows 2025-08-24 12:58:27 -06:00
ayeteadoe
b7bc60d614 Utilities/abench: Enable on Windows 2025-08-24 12:58:27 -06:00
ayeteadoe
f4b20129d7 Utilities/xml: Enable on Windows 2025-08-24 12:58:27 -06:00
ayeteadoe
2c91014bbf LibXML: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-24 12:58:27 -06:00
ayeteadoe
a95e0d2777 Utilities/wasm: Enable on Windows 2025-08-24 12:58:27 -06:00
ayeteadoe
070392307a LibWasm: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-24 12:58:27 -06:00
ayeteadoe
3355b7fb1f Tests/LibJS: Enable test-js on Windows 2025-08-24 12:58:27 -06:00
Andreas Kling
79b30e7c9a LibWeb: Create a new painter after resizing canvas element backing store
Otherwise, we just keep painting into the old backing store. This fixes
an issue where the main spreadsheet area in Google Sheets was not
visually updating, despite everything looking good in memory.
2025-08-24 16:36:24 +02:00
ayeteadoe
1d93c0b8a5 Tests/LibTLS: Enable TestTLSHandshake in Windows CI 2025-08-23 18:35:45 -06:00
ayeteadoe
cc38235ca1 Tests/LibDNS: Enable in Windows CI 2025-08-23 18:35:45 -06:00
ayeteadoe
4180944b4d LibTLS: Use Windows-specific method to set default certificate store
test_tls in TestDNSResolver was failing to perform the TLSv12
connection due to the following error: "14430000:error:0A000086:SSL
routines:tls_post_process_server_certificate:certificate verify
failed:ssl\statem\statem_clnt.c:2124". To perform the equivalent
on Windows, we can instead load the built in OSSL_STORE for Windows
2025-08-23 18:35:45 -06:00
ayeteadoe
ff71efebb6 LibCore: Fix WSAEMSGSIZE error in pending_bytes with proper zero-init
In SocketWindows, the return value for the ioctl call was not
initialized to zero. This was causing test_udp in TesDNSResolver
to fail as UDPSocket::read_some() was incorrectly failing with
WSAEMSGSIZE due the result of pending_bytes being some
unspecified default value for an uninitialized unsigned long
2025-08-23 18:35:45 -06:00
ayeteadoe
4fa8238a46 Meta: Install qtbase and qtmultimedia vcpkg ports on Windows 2025-08-23 16:04:36 -06:00
ayeteadoe
9ec1643d88 CMake: Add helper to ensure vcpkg DLLs are copied to the output dir
The BUILD_RPATH/INSTALL_RPATH CMake infrastructure is not supported
on Windows, but we want to ensure Ladybird executables are runnable
after the build phase so there can be an efficient dev loop.
lagom_copy_runtime_dlls() can be used by executable targets so all
their dependent dlls are copied to their output directory in their
post build step.
2025-08-23 16:04:36 -06:00
ayeteadoe
3df8e00d91 LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
ayeteadoe
94a3a7d9a1 Tests/LibMedia: Enable in Windows CI 2025-08-23 16:04:36 -06:00
ayeteadoe
0c9b16d09c Tests/LibWebView: Enable in Windows CI 2025-08-23 16:04:36 -06:00
ayeteadoe
a2d3562647 Tests/LibXML: Enable in Windows CI 2025-08-23 16:04:36 -06:00
ayeteadoe
6dbb59da77 LibJS: Export symbols causing linker errors in various consumers
After LibJS had its symbol exports optimized the targets
js, test-js, test262-runner, test-wasm, and LibWeb began to get linker
errors after the work to add Windows support for test-web and ladybird
targets. These extra JS_API annotations fix all those linker errors.
2025-08-23 16:04:36 -06:00
ayeteadoe
9c67c4a270 LibWebView: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
ayeteadoe
ed93551d59 Qt/ladybird: Enable in Windows CI 2025-08-23 16:04:36 -06:00
ayeteadoe
f58298132b LibDevTools: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
ayeteadoe
84690f432e test-web: Allow help command to succeed
These are required for test-web runtime to actually work
2025-08-23 16:04:36 -06:00
ayeteadoe
0b19c04b53 test-web: Enable building in Windows CI
The tests are not registered with CTest yet
2025-08-23 16:04:36 -06:00
ayeteadoe
0847ca4854 WebWorker: Enable in Windows CI 2025-08-23 16:04:36 -06:00
ayeteadoe
0a699132f3 WebContent: Enable in Windows CI 2025-08-23 16:04:36 -06:00
ayeteadoe
e497303e94 LibTextCodec: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
ayeteadoe
58be9e6400 RequestServer: Enable in Windows CI 2025-08-23 16:04:36 -06:00
ayeteadoe
c7f35193d0 LibDevTools: Enable in Windows CI 2025-08-23 16:04:36 -06:00
ayeteadoe
97e8a922ad ImageDecoder: Enable in Windows CI 2025-08-23 16:04:36 -06:00
ayeteadoe
ee3c033de2 LibWebView: Enable in Windows CI 2025-08-23 16:04:36 -06:00
ayeteadoe
09ff99c50e LibImageDecoderClient: Enable in Windows CI 2025-08-23 16:04:36 -06:00
Aliaksandr Kalenik
025011d8e0 LibWeb: Fix algorithm that distributes space beyond limits [GFC]
Fixes bug when we didn't use `tracks_to_grow_beyond_limits` and instead
distributed extra space to all affected tracks. Also implements missing
"when accommodating max-content" part.
2025-08-23 23:16:18 +02:00
Idan Horowitz
d2857164ea Tests: Test that unvisited Templated members are caught by ClangPlugin
Specifically AK::Optional<T> and AK::Variant<...> were of interest in
recent issues.
2025-08-23 21:21:04 +02:00
Idan Horowitz
bcb8b06a74 ClangPlugins: Make sure forward declared fields are visited as well
Instead of ignoring fields using forward-delcared types, always assume
they inherit from GC::Cell. This improves the worst case from a missed
unvisited field, to a slightly wrong error message.

Fixes #5959.
2025-08-23 21:21:04 +02:00
Idan Horowitz
1eed5bdef7 ClangPlugins: Check for unvisited JS::Value members
JS:Value members might hold a JS::Cell inside, so they must be visited
in ::visit_edges implementations as well.

Fixes #5958.
2025-08-23 21:21:04 +02:00
Idan Horowitz
66bd7fa530 LibJS: Add missing visit of Realm::m_builtins 2025-08-23 21:21:04 +02:00
Andreas Kling
3873b1d8cf LibWeb: Create XML document object for SVG-as-image
It's not enough to just use the XML parser, we also have to make sure
the DOM document we produce is an actual XML document.

Fixes #5966
2025-08-23 14:01:37 +01:00
Andreas Kling
4350bccf8e LibWeb: Use Accelerate framework on macOS to premultiply bitmap data
This leverages hardware acceleration to speed things up considerably,
shaving ~500ms of load time off of https://cloudflare.com/
2025-08-23 14:09:17 +02:00
Andreas Kling
67432e35f1 LibGfx: Match vImage premultiply/unpremultiply rounding behavior
Our Color::to_premultiplied() and Color::to_unpremultiplied() used
integer truncation.

Apple’s Accelerate framework (and many other libraries) use
round-to-nearest, which avoids bias and produces results that differ
by ±1 in many cases.

This commit switches both helpers to round-to-nearest and clamps the
results to [0,255]. For alpha==0 we now return fully transparent black
(0,0,0,0) to align with common conventions, instead of preserving RGB.
2025-08-23 14:09:17 +02:00
CountBleck
7575beafcb LibWeb: Import tests for resizable/growable ArrayBuffer Wasm memories
We pass to-fixed-length-buffer.any.html and to-resizable-buffer.any.html
but not to-resizable-buffer-shared.any.html, because LibJS doesn't have
growable SharedArrayBuffers implemented...
2025-08-23 08:26:23 +02:00
CountBleck
d0d5bffb2d LibWeb: Implement resizable ArrayBuffers for Wasm memories
This commit adds the toResizableBuffer() and toFixedLengthBuffer()
methods to WebAssembly.Memory. This includes the necessary hook to
HostResizeArrayBuffer. Some modifications to function signatures in
LibWeb/WebAssembly/Memory.h were also made (changing the return type
from WebIDL::ExceptionOr to JS::ThrowCompletionOr) to allow the use of
some code in the aforementioned hook.

Note: the hook for HostGrowSharedArrayBuffer isn't implemented, since
LibJS doesn't seem to have complete support for growable
SharedArrayBuffers; the relevant methods/getters don't even exist on
the prototype, let alone HostGrowSharedArrayBuffer!

This should help pass the WebAssembly.Memory WPT tests included in
Interop 2025, except those pertaining to growable SharedArrayBuffers.
2025-08-23 08:26:23 +02:00
CountBleck
826eb68ecd LibWeb: Add test ensuring re-exported Wasm memories equal the import
If a memory is imported by a Wasm instance and re-exported, the export's
value should be the exact same WebAssembly.Memory object as the
WebAssembly.Memory object passed for the import.
2025-08-23 08:26:23 +02:00
CountBleck
f2a170bcfb LibWeb: Implement the WebAssembly "Memory object cache" + other changes
This cache is referenced by a few parts of the JS API spec, including
the threads spec (such as in toFixedLengthBuffer), as well as the
"refresh the Memory buffer" algorithm, which was implemented as a method
of Memory before this change.

Now, this algorithm can be implemented in a spec-like fashion (though it
mostly seems to add extra complexity). This change also fixes a bug
where memories that were re-exported from an imported WebAssembly.Memory
were given a distinct WebAssembly.Memory object, since the caching that
existed in Instance.cpp was instance-local, not global to the realm.

We also make Memory::m_buffer non-lazy, since we have to implement
"initialize a memory object" correctly anyway.
2025-08-23 08:26:23 +02:00
CountBleck
a2dc6c4bbb LibJS: Keep the lengths of ArrayBuffers with unowned ByteBuffers fixed
The relevant type of ArrayBuffer DataBlock is now a struct containing
both a ByteBuffer* and a size_t size, and not just a ByteBuffer*, with
the size being that of the ByteBuffer. This type of DataBlock is only
used for WebAssembly.Memory (see commit 4fd43a8f96), meaning this
change won't affect any other code. This change is required to pass one
WPT subtest in wasm/jsapi/memory/grow.any.html, since old fixed-length
SharedArrayBuffers after a WebAssembly.Memory growth should keep their
length, while the new buffer after the growth will have the updated
length.
2025-08-23 08:26:23 +02:00
CountBleck
0bda014c96 LibWeb: Don't create a copy SharedArrayBuffer for shared Wasm memories
For whatever reason, the implementation of "create a fixed length memory
buffer" was borked for shared Wasm memories, in that a new
SharedArrayBuffer was created, with the contents of the Wasm memory
copied into it. This is incorrect, since the SharedArrayBuffer should be
a view into the Wasm memory's span, not a copy of it. This helps pass a
WPT subtest in wasm/jsapi/memory/grow.any.html.
2025-08-23 08:26:23 +02:00
Tim Ledbetter
aadd563592 LibWeb: Replace usages of dynamic_cast with as and as_if 2025-08-22 20:26:09 +02:00
Tim Ledbetter
d31aec25e8 AK: Ignore possible const reference when comparing type equality in is 2025-08-22 20:26:09 +02:00
Tim Ledbetter
4e57a2aedf LibWeb: Ensure static cast is used when possible in as_if 2025-08-22 20:26:09 +02:00
Andreas Kling
5e6b8b2785 LibWeb: Add missing visit of IDBRequest::m_source
Clang plugin bug: LadybirdBrowser/ladybird#5959
2025-08-22 19:29:29 +02:00
Andreas Kling
02f3002081 LibWeb: Add missing visit of IDBCursor::m_value
Clang plugin bug: LadybirdBrowser/ladybird#5958
2025-08-22 19:29:29 +02:00
Timothy Flynn
1f88e6819a LibWeb: Ensure hit testing is grapheme aware
Previously, clicking in the middle of a multi-code point grapheme would
place the cursor at a code unit index somewhere in the middle of the
grapheme. This was not only visually misleading, but the user could then
start typing and insert characters in the middle of the cluster. This
also made text select pretty wonky.

The main issue was that we were treating the glyph index in a glyph run
as a code unit index. We must instead map that glyph index back to a
code unit index with help from LibGfx (via harfbuzz).

The distance computation used here was also a bit off, especially for
the last glyph in a glyph run. We essentially want the cursor to end
up on whichever edge of the clicked glyph it is closest to. The result
of the distance computation limited us to the left edge of the last
glyph. Instead, we can use the same edge tracking we use for form-
associated elements to handle this for us.
2025-08-22 14:06:46 +02:00
Timothy Flynn
c3f4d32162 LibWeb: Extract FormAssociatedElement's grapheme edge code to a helper
The edge detection will be used at least in hit testing.
2025-08-22 14:06:46 +02:00
Timothy Flynn
047f521c4c LibGfx+LibWeb: Add some extra fields to glyph run data
We currently have a mixup in LibWeb between code unit offset and glyph
offset during hit testing. These extra fields will allow us to correct
this discrepency.
2025-08-22 14:06:46 +02:00
Timothy Flynn
b1fe816336 AK: Provide a length_in_code_units API for UTF-8 strings
This is just to afford API symmetry with UTF-16 strings to help in
templated methods.
2025-08-22 14:06:46 +02:00
zac
41eaf0d966 Tests: Add tests for some common image types in TestLibCoreMimeType 2025-08-22 08:03:28 -04:00
zac
b8f95a091c LibCore: Add AVIF to registered types in MimeData 2025-08-22 08:03:28 -04:00
Callum Law
5c2fe12772 LibWeb: Don't consider null -> null as a change for invalidation
This avoids excessive invalidation within `recompute_inherited_style`
where we inherit a value but not an animated value.
2025-08-22 12:17:55 +02:00
Callum Law
cecd5b3b5b LibWeb: Compute invalidation before value is moved
`set_animated_property` will move `new_animated_value` away so we need
to compute invalidation before we call it
2025-08-22 12:17:55 +02:00
Andreas Kling
3c808de270 LibWeb: Use XML parser for SVG-as-image documents
We were already using the XML parser for SVG files when opening at the
top level. This patch makes things consistent by using the same code
path when parsing SVG-as-image.

We also make some tweaks in SVG presentation attribute handling since
we can no longer rely on the HTML length attribute parsing quirk when
parsing width/height attributes.
2025-08-22 11:35:59 +02:00
Andreas Kling
b7595013c1 LibWeb+LibXML: Preserve element attribute order in XML documents
We now use OrderedHashMap instead of HashMap to ensure that attributes
on XML elements retain their original order.
2025-08-22 11:35:59 +02:00
Sam Atkins
da88db04cf LibWeb/CSS: Implement the "numeric factory" methods (CSS.px() and pals) 2025-08-22 09:48:30 +01:00
Sam Atkins
24017e4ab7 LibWeb/CSS: Reify numbers, dimensions and percentages as CSSUnitValue 2025-08-22 09:48:30 +01:00
Sam Atkins
5384338788 LibWeb/CSS: Implement CSSUnitValue 2025-08-22 09:48:30 +01:00
Sam Atkins
0fa1099ce5 LibWeb/CSS: Support creating a NumericType from Flex units 2025-08-22 09:48:30 +01:00
Sam Atkins
6cb8e92bd4 LibWeb/CSS: Stub out CSSNumericValue
Most of the methods on this rely on its subclasses existing, so for now
it's very basic.
2025-08-22 09:48:30 +01:00
Sam Atkins
5bdc2981e3 LibWeb/CSS: Rename CSSNumericType to NumericType
The CSSNumericType defined in the spec is a simple dictionary which is
only used for OM purposes. This NumericType class is used internally
and matches the more abstract definition of a "type".
2025-08-22 09:48:30 +01:00
rmg-x
43d071e3b7 LibWeb/WebIDL: Remove unused AK/Diagnostics.h import in DOMException 2025-08-22 09:47:01 +01:00
rmg-x
1678231eed LibWeb: Fix else-after-return in hash_algorithm_identifier_from_value
and constify it :^)
2025-08-22 09:47:01 +01:00
rmg-x
3ef65e45d7 LibWeb/Crypto: Avoid heap allocation for AesGcm tag lengths 2025-08-22 09:47:01 +01:00
Callum Law
6373ab68ee LibWeb: Use inherited value of math-style when computing math-depth
The spec calls for us to use the inherited value but we were using our
own value.
2025-08-22 09:48:52 +02:00
Callum Law
4efbd0dc4d LibWeb: Support relative lengths in math-depth calcs
As this is computed before font-size we use the parent's length
resolution context.
2025-08-22 09:48:52 +02:00
Callum Law
944b985929 LibWeb: Remove handling of invalid values in compute_math_depth
This was unnecessary as the parser will never produce values other than
MathDepthStyleValue
2025-08-22 09:48:52 +02:00
Callum Law
a2c9ab9c9a LibWeb: Return AbstractElement from element_to_inherit_style_from
No functional changes.
2025-08-22 09:48:52 +02:00
Sam Atkins
8af99388a6 LibGC: Make GC::Root bool operator explicit
Not having this led to a sneaky bug where, given a Variant like so:

  Variant<double, GC::Root<T>>

An incorrectly-written visit() branch for the Root would just cause it
to be cast to a double and call that branch instead.

With the cast made explicit, we get a compiler error, which is far more
useful.

Co-authored-by: Jelle Raaijmakers <jelle@ladybird.org>
2025-08-21 12:50:43 -04:00
Erik Kurzinger
ce03b8b3b1 LibGfx+LibWeb: Only compile dma-buf-related code on Linux
Shareable Vulkan image allocation on Linux relies on the dma-buf
interface, which is a Linux-specific thing. Therefore, we should only be
compiling it (and any code that uses it) on Linux. This change adds
preprocessor guards to do that. Enabling similar functionality on other
operating systems will need to leverage analogous interfaces on those
platforms, e.g. win32 handles on Windows.

All Vulkan image code will now be guarded by the USE_VULKAN_IMAGES
preprocessor definition, currently enabled on Linux if Vulkan is
available. Additionally, we shuffle around some code in
OpenGLContext.cpp to simplify the preprocessor conditionals.
2025-08-21 14:42:41 +02:00
Jelle Raaijmakers
871838dda3 Meta: Add Gregory Bertilson to maintainer list :^) 2025-08-21 14:20:45 +02:00
Callum Law
9122d0d014 LibWeb: Remove compute_defaulted_{values|property_value}
These functions are unused.
2025-08-21 13:49:21 +02:00
Callum Law
ce0fef7c45 LibWeb: Initialize properties before calling compute_{math_depth|font}
`StyleComputer::create_document_style` was the only place this wasn't
the case so we can remove the calls to
`compute_defaulted_property_value`. The call to
`compute_defaulted_values` in `create_document_style` is now redundant
so has been removed`
2025-08-21 13:49:21 +02:00
Callum Law
b267012ba7 LibWeb: Handle color: currentcolor in compute_properties
This was the last thing that `compute_defaulted_values` was doing when
called from here.

It also comes with the added benefit of us correctly inheriting animated
colors.
2025-08-21 13:49:21 +02:00
Callum Law
48832972b1 LibWeb: Handle -libweb-inherit-or-center in compute_text_align
This seems like a more natural place to handle this
2025-08-21 13:49:21 +02:00
Callum Law
ca9cb42ed4 LibWeb: Handle unset immediately in compute_properties
Previously we would hand off to `compute_defaulted_properties` to
resolve these values but there is no need as we can just resolve them
immediately.
2025-08-21 13:49:21 +02:00
Dan Vittegleo
c9fbc2db0b LibWeb: Implement CSS border radius overlapping algorithm
Fixes rendering of elements with large border-radius values by scaling
radii proportionally when they exceed element dimensions per CSS spec.

Co-authored-by: Samyat Gautam <thesamyatgautam@gmail.com>
2025-08-21 11:52:38 +02:00
Callum Law
9330bf4b72 LibWeb: Propagate animated values in recompute_inherited_style
As `recompute_inherited_style` works in-place rather than building
ComputedProperties from scratch we need to keep track of which animated
properties are inherited to know whether we should remove them when we
have no more inherited value.
2025-08-21 10:46:55 +01:00
Sam Atkins
0fc512e56d LibWeb/CSS: Reify UnresolvedStyleValue as CSSUnparsedValue 2025-08-21 10:21:54 +01:00
Sam Atkins
6428c9990d LibWeb/CSS: Implement CSSUnparsedValue and CSSVariableReferenceValue
We don't serialize these the way WPT expects, because we don't implement
the comment-insertion rules from CSS-Syntax. We don't implement that
for regular serialization either, so it's something we can worry about
later.
2025-08-21 10:21:54 +01:00
Sam Atkins
213a548b1f LibWeb/CSS: Implement CSSStyleValue.parse() and .parseAll()
The "subdivide into iterations" part is left as a FIXME for now, until
we have a way of knowing if a property is a list or not.

The parse_a_css_style_value() helper has an unwieldy return type because
of the requirement that it return either one value or a list of values,
but sticking to the spec here seems worthwhile for now.
2025-08-21 10:21:54 +01:00
Sam Atkins
3613181f54 LibWeb/CSS: Reify idents as CSSKeywordValue
For us, that's KeywordStyleValue and CustomIdentStyleValue.

CustomIdentStyleValue now has a .cpp file to reduce the number of
includes in its header file.
2025-08-21 10:21:54 +01:00
Sam Atkins
a93c6a347f LibWeb/CSS: Implement CSSKeywordValue
CSSStyleValue is adjusted to allow for subclasses. Serialization for
CSSKeywordValue is implemented differently than the spec says because
of a spec bug: https://github.com/w3c/csswg-drafts/issues/12545
2025-08-21 10:21:54 +01:00
Tim Ledbetter
030e670fcb LibWeb/SVG: Resolve stroke URI reference values 2025-08-21 00:33:53 +02:00
Tim Ledbetter
05432d7157 LibWeb/SVG: Resolve fill URI reference values 2025-08-21 00:33:53 +02:00
Jelle Raaijmakers
8d46a11748 CI: Pin js-benchmarks to current master
The output format for js-benchmarks is going to change, and while the
webhook parsing the results has not yet been updated pin the
js-benchmark checkout to a specific commit.
2025-08-21 00:30:42 +02:00
Ben Eidson
96b142e10b LibWeb/WebAudio: Add renderQuantumSize
Adds this attribute to BaseAudioContext.idl and adds associated test for
OfflineAudioContext. This gives a set value that can be used to start
implementing OfflineAudioContext::start_rendering(). Updates idlharness
test to account for now implemented renderQuantumSize.
2025-08-20 14:51:01 +02:00
quonverbat
97d7316254 Documentation: Fix grammar error 2025-08-20 14:48:29 +02:00
quonverbat
cb742ee2ba Documentation: Fix capitalization and add Markdown
Some words were not capitalized and some tools were not in code blocks
2025-08-20 14:48:29 +02:00
Tim Ledbetter
4906afb2ae LibWeb: Set the initial value of stroke-dashoffset to 0px
Previously, an initial value of 0 was being used.
2025-08-20 14:30:51 +02:00
Jelle Raaijmakers
1a52fcd6ad LibWeb: Draw selected text with its own color
Other browsers such as Chrome and Firefox retain the text's color when
the text is part of a selection, so let's mimic them.
2025-08-20 14:30:16 +02:00
Jelle Raaijmakers
9887b52663 LibWeb: Convert fragment's enclosing device rect to IntRect just once
No functional changes.
2025-08-20 14:30:16 +02:00
Jelle Raaijmakers
51ce46859e LibWeb: Make DOM::Position's node mandatory
We can only construct positions if there's a node involved, which was
already enforced by Position::create() only accepting a GC::Ref.
2025-08-20 12:25:00 +01:00
Jelle Raaijmakers
cd08b3b6f4 LibWeb: Reset cursor blink cycle, even if there's no viewport paintable
If we programmatically set a selection in an editable element during
document load, we failed to start the cursor blink cycle timer. The
cursor blink logic already takes care of us not having the paintable
yet, so start it unconditionally.
2025-08-20 12:36:01 +02:00
Jamie Mansfield
97746fb574 LibGfx: Fix colour with Photoshop JPEG files using CMYK
This is based on the original functionality Lucus wrote prior to using
libjpeg.

Co-authored-by: Lucas CHOLLET <lucas.chollet@free.fr>
2025-08-20 12:04:39 +02:00
Jelle Raaijmakers
738eb68dda LibWeb: Always focus on editing host if currently not focused
We were constraining the focusing behavior for editing hosts a bit too
much; regardless of how the selection changed, if the start container is
inside an editing host and it's currently not focused, we should focus
it. This fixes focus stealing by other elements that set a selection
inside an editing host on a click event, for example.
2025-08-20 11:36:40 +02:00
Jelle Raaijmakers
3a741b0ce6 LibWeb: Indicate focus on contenteditable elements
This mirrors what Chrome and Firefox do.
2025-08-20 11:36:27 +02:00
Andreas Kling
05d6090fcc Revert "LibWeb: Invalidate layout on opacity change to/from zero"
This partially reverts commit 3aff3327c4
by removing the code change but keeping the added test.

Now that paintables visibility caching has been reverted, this is no
longer doing anything except causing excessive relayouts on pages
like https://linear.app/
2025-08-20 09:14:58 +02:00
Andreas Kling
f4ee341a14 Revert "LibWeb: Store visibility for Paintables"
This reverts commit 7dc8062283.

This did not propagate correctly to paintables whose style was inherited
from an ancestor, causing rendering artifacts on https://linear.app/
2025-08-20 09:14:58 +02:00
Andreas Kling
657f1c37a8 LibWeb: Mark CSS filter property as affecting stacking context tree 2025-08-20 09:14:58 +02:00
Andreas Kling
0baf068bbf LibWeb: Remove redundant dynamic_cast in ~AnimationUpdateContext() 2025-08-20 09:14:58 +02:00
Andreas Kling
775d15c115 LibWeb: Avoid unnecessary style invalidation in Document::set_url()
If we set the same URL that we already had, there's no need to
invalidate style for the base URL changing.

This avoids some style recomputation while loading pages.
2025-08-20 09:14:58 +02:00
Andreas Kling
ec2b568919 LibWeb: Add missing StyleInvalidationReason for HTMLDialogElement
We were accidentally using NodeRemove instead of a unique reason.
2025-08-20 09:14:58 +02:00
Tim Ledbetter
83b1ead1e7 LibWeb: Ensure UIEventInit.view is set for mouse and pointer events 2025-08-20 09:13:32 +02:00
Rocco Corsi
a60debe7bb LibWeb: Don't always stop drawing scrollbar on mouseleave
PaintableBox::handle_mouseleave is turning off scrollbar updating, but
the user might still have the primary button down to scroll. Don't turn
it off if grabbing the thumb to scroll.

Resolves crashing on MacOSX AppKit and Qt where gutter_size is 0 when
mouse is moved outside window.
2025-08-19 20:12:01 -04:00
Tete17
658477620a LibWeb/LibURL/LibIPC: Extend createObjectURL to also accept MediaSources
This required some changes in LibURL & LibIPC since it has its own
definition of an BlobURLEntry. For now, we don't have a concrete usage
of MediaSource in LibURL so it is defined as an empty struct.

This removes one FIXME in an idl file.
2025-08-19 23:50:38 +02:00
Tete17
f60529dac5 LibWeb: Modify createObjectURL to return Utf16Strings 2025-08-19 23:50:38 +02:00
Luke Wilde
a04f2d0796 Meta: Remove curl overlay port
The http3 feature is now upstream, so we no longer need an overlay port
to use it.
2025-08-19 22:08:55 +02:00
Luke Wilde
43c1b1b434 Meta: Bump vcpkg baseline 2025-08-19 22:08:55 +02:00
Jelle Raaijmakers
0cf6bd0324 LibWeb: Maintain rect positioning when rounding to device pixel rects
When rounding a CSSPixelRect to a DevicePixelRect, we simply pulled its
width and height through round() and called it a day. Unfortunately this
could negatively affect the rect's perceived positioning.

A rect at { 0.5, 0.0 } with size { 19.5 x 20.0 } should have its right
edge at position 20, but after rounding it would end up at { 1, 0 } with
size { 20 x 20 }, causing its right edge to be at position 21 instead.

Fix this by first rounding the right and bottom edges of the input rect,
and then determining the dimensions by subtracting its rounded position.

Fixes #245.
2025-08-19 21:53:46 +02:00
Jelle Raaijmakers
64acef30ec LibWeb: Simplify filling rects with rounded corners
We can use BorderRadiiData::as_corners() to avoid converting the corners
one by one. Instead of passing all four corners one by one, use a
reference to CornerRadii.

No functional changes.
2025-08-19 21:53:46 +02:00
Jelle Raaijmakers
e421b34e14 LibWeb: Do not unnecessarily construct Colors in PaintableBox::paint()
No functional changes.
2025-08-19 21:53:46 +02:00
Jelle Raaijmakers
a83815360c LibWeb: Use unchecked appends and simplify code in GFC track handling
No functional changes.
2025-08-19 21:53:46 +02:00
Aliaksandr Kalenik
d04e3c9bce LibWeb/WebGL: Use auto when possible in OpenGLContext.cpp 2025-08-19 20:45:18 +02:00
Aliaksandr Kalenik
2df0b6024f LibGfx: Use array_size() when possible in VulkanContext.cpp 2025-08-19 20:45:18 +02:00
Aliaksandr Kalenik
3ec37978e6 LibGfx: Use reinterpret_cast instead of C style in create_vulkan_context 2025-08-19 20:45:18 +02:00
Sam Atkins
437062819b Documentation: Note libdrm-devel requirement on Fedora 2025-08-19 12:49:51 +02:00
rmg-x
3721d4608b Devcontainer: Add libdrm-dev to list of Ubuntu packages 2025-08-19 11:43:51 +01:00
rmg-x
82dd8d4dd5 Documentation: Add libdrm-dev to Ubuntu/Debian build instructions 2025-08-19 11:43:51 +01:00
Jelle Raaijmakers
bc7658d3d3 LibCore: Don't send SIGTRAP when debugger attaches
Both gdb and lldb interrupt execution after attaching to the process, so
no need to send a SIGTRAP immediately after which would require typing
`continue` in the debugger twice.
2025-08-19 06:24:57 -04:00
Timothy Flynn
1869399fd1 AK: Specialize Optional for Utf16String and Utf16FlyString
We added this for String some time ago, so let's give Utf16String the
same optimization. Note that Utf16String was already handling its data
member potentially being null as of 5af99f4dd0.
2025-08-19 06:24:09 -04:00
Jelle Raaijmakers
9e29d0c040 LibWeb: Make button layout wrappers inherit styles correctly
There are some nuances to creating these wrappers, such as manually
propagating certain text styles that are not inherited by default. We
already have the logic for this in
`NodeWithStyle::create_anonymous_wrapper()`, so reuse that method in our
implementation of the button layout.

Fixes applying certain text styles (such as `text-decoration`) to the
text of a `<button>`.
2025-08-19 11:12:23 +02:00
Jelle Raaijmakers
f530ea5f7e Tests: Rename button test to something sensible
This had nothing to do with table cells.
2025-08-19 11:12:23 +02:00
Jelle Raaijmakers
715de4693c LibGC+LibWeb: Remove unused include and class 2025-08-19 11:12:23 +02:00
Tim Ledbetter
cfc6439c12 LibWeb: Use shape-rendering to control anti aliasing for SVG paths
Anti-aliasing is disabled if `shape-rendering` is set to
`optimizeSpeed` or `crispEdges`.
2025-08-19 09:47:28 +01:00
Tim Ledbetter
1d745884be LibWeb: Parse the shape-rendering property 2025-08-19 09:47:28 +01:00
Aliaksandr Kalenik
d94b33e205 LibWeb: Handle correctly case when abspos and relpos GFC is interleaved
...by another GFC. When searching for grid item that contains an
abspos box positioned relative to GFC, it's incorrect to assume that the
closest ancestor box whose parent establishes GFC is always the one we
are looking for, because there may be non-positioned GFC in between.

Fixes regression introduced in 80c8e78.
2025-08-19 09:28:45 +02:00
Erik Kurzinger
8fd1df4f8b LibGfx: Enable WebGL on Linux
This enabled WebGL on Linux. It uses ANGLE's OpenGL backend running atop
EGL_PLATFORM_SURFACELESS_MESA. Eventually we should probably switch to
the Vulkan backend but that doesn't seem to be enabled in the vcpkg
angle package. Anyway, switching later should be trivial.

The painting surface is allocated through Vulkan and then imported into
EGL as a dma-buf. The DRM format modifier mechanism, along with Vulkan
initializing the image with VK_IMAGE_LAYOUT_GENERAL, should ensure
surface compatibility across the two APIs.

For now, we will synchronize rendering and presentation using glFinish,
although this is admittedly suboptimal. Really we should grab an
EGLSync, export that to an fd, import it into Skia and have it wait for
it before reading from the image. That can be implemented in a future
change, though.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
80693274a7 LibGfx: Fail WebGL context creation if no EGLConfig is found 2025-08-19 00:30:22 +02:00
Erik Kurzinger
72a7051877 LibGfx: Request correct EGLConfig surface type for WebGL
We currently look for an EGLConfig that supports window surfaces, but we
actually use a pbuffer surface.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
df09472d4d LibGfx: Free WebGL painting surface resources on resize
If a WebGL canvas is resized through the set_size function, we will
re-create the painting surface. However, this currently leaks all of the
associated EGL/OpenGL objects. This change introduces the
free_surface_resources function which will free all resources associated
with the painting surface. It will be called before allocating a new
surface and during context destruction. It keeps track of the OpenGL
texture for the color buffer in m_impl instead of just storing it on the
stack.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
41f1e920d8 LibGfx: Allow creating a PaintingSurface from a Vulkan image
This adds a new PaintingSurface creation function, create_from_vkimage,
which returns a PaintingSurface backed by a vulkan image. It's analogous
to the existing create_from_iosurface function. In both cases the
backing object will be imported into Skia as a render target and then an
SkSurface will be wrapped around that.

In order to ensure that the image will not be freed while still in use
by Skia, we will manually bump the refcount of the VulkanImage object
before passing it to Skia and then use the releaseCallback parameter of
WrapBackendRenderTarget to register a callback that drops this
reference.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
08343970fb LibGfx: Save VulkanContext in SkiaBackendContext
This retains access to the vulkan device, queue, etc. handles which will
be needed for image allocation and possible other things in the future.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
60a7359f0f LibGfx: Implement Vulkan image allocation
This introduces the ability to allocate Vulkan images which can be
shared across graphics APIs or across processes using the Linux dma-buf
interface.

The create_shareable_vulkan_image function takes a VulkanContext, image
width, height, and format, and an array of DRM format modifiers
representing image memory layouts accepted by the caller. The function
will intersect this list with the list of modifiers supported by the
Vulkan implementation, ensuring the resulting image uses one of those
layouts (exactly which one is up to the implementation). The function
will return a VulkanImage object, which is reference-counted and
encapsulates the VkImage itself as well as the backing memory
allocation. It also stores various image parameters such as usage,
tiling, etc.

The VulkanImage::get_dma_buf_fd function will create a file descriptor
representing the image's backing dma-buf which can then be imported by a
different API or sent over a unix domain socket.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
06c916d91c LibGfx: Allocate command buffer for VulkanContext
A later change will add the ability to allocate images. We need a
command buffer in order to initialize the layout of those images.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
1a6a114667 LibGfx: Save graphics queue family index in VulkanContext
This will be needed for image allocation, and anyway I think we're
supposed to be passing this to Skia during context creation.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
dc3cb2122d CI: Add libdrm-dev dependency
We need the drm_fourcc.h header to use the dma-bufs in LibGfx
2025-08-19 00:30:22 +02:00
Andreas Kling
29278038a2 LibWeb: Don't assume grid-related properties don't have var() in them
When serializing the "style" attribute, we were incorrectly assuming
that some of the grid-related CSS properties would never contain var()
substitution functions.

With this fixed, we can now book appointments on https://cal.com/ :^)
2025-08-18 21:18:16 +02:00
Sam Atkins
92dc2faa10 LibWeb/CSS: Use serialize_a_number() for Ratio serialization 2025-08-18 16:52:39 +01:00
Sam Atkins
6b69b00a05 LibWeb/CSS: Use serialize_a_number() for Time serialization
As noted, the spec tells us to do something different than what is
expected by WPT, so we slightly ignore it.
2025-08-18 16:52:39 +01:00
Sam Atkins
682e080d57 LibWeb/CSS: Use serialize_a_number() for Resolution serialization
As noted, the spec tells us to do something different than what is
expected by WPT, so we slightly ignore it.
2025-08-18 16:52:39 +01:00
Sam Atkins
53f226c14c LibWeb/CSS: Use serialize_a_number() for Percentage serialization 2025-08-18 16:52:39 +01:00
Sam Atkins
e30d968049 LibWeb/CSS: Use serialize_a_number() for Frequency serialization 2025-08-18 16:52:39 +01:00
Sam Atkins
1c82d74a18 LibWeb/CSS: Use serialize_a_number() for Flex serialization 2025-08-18 16:52:39 +01:00
Sam Atkins
00b1b34c80 LibWeb/CSS: Use serialize_a_number() for Angle serialization
Gets us 12 known passes!
2025-08-18 16:52:39 +01:00
Sam Atkins
dffebee901 LibWeb/CSS: Use serialize_a_number() for Length serialization
This changes the maximum number of decimal places from 5 to 6, but 5 was
previously a guess, and not specified behaviour:

> For all of the decimal changes (except color) I couldn't really find a
> spec that mandates any required precision, so I just copied what
> Firefox seems to do, which is limit the output to 5 decimal places.
> https://github.com/SerenityOS/serenity/pull/23449
2025-08-18 16:52:39 +01:00
Sam Atkins
1a7f6c8f87 LibWeb/CSS: Define and use serialize_a_number()
No behaviour change, this just moves things.
2025-08-18 16:52:39 +01:00
Abhinav
0205480051 LibWeb: Process closure of socket for WebSockets 2025-08-18 09:35:47 -06:00
Abhinav
6077c51468 LibWeb: Make WebSocket closure adhere to spec for all ReadyStates 2025-08-18 09:35:47 -06:00
Timothy Flynn
5ec70bd00a Revert "LibJS: Revert common error types to only hold a single string"
This reverts commit 695bbcb991.

Despite improving performance on my Linux machine, this managed to tank
performance on the Linux benchmark machine.
2025-08-18 13:42:22 +02:00
Tim Ledbetter
b81d3e813c LibWeb: Eagerly create stacking context if will-change set for property
If `will-change` is set to a property value where that property could
create a stacking context, then we create a stacking context regardless
of the current value of that property.
2025-08-18 12:36:37 +01:00
Tim Ledbetter
4f663ca6e7 LibWeb: Parse the will-change property
This property provides a hint to the rendering engine about properties
that are likely to change in the near future, allowing for early
optimizations to be applied.
2025-08-18 12:36:37 +01:00
Timothy Flynn
0e4fb9ae73 LibWeb: Ensure up/down arrow navigation is grapheme-aware
Previously, it was possible for an up/down arrow press to place the
cursor in the middle of a multi-code point grapheme cluster. We want to
prevent this in a way that matches the behavior of other browsers.

Both Chrome and Firefox will map the starting position to a visually
equivalent position in the target line with harfbuzz and ICU segmenters.
The need for this is explained in a code comment. The result is a much
more natural feeling of text navigation.
2025-08-18 13:17:28 +02:00
Abhinav
be5c52bfef Meta: Detect urls to import from Worker 2025-08-18 11:27:12 +01:00
Callum Law
9a8c6ff8c3 LibWeb: Inherit animated CSS property values separately
When starting transitions we compute the after-change style, for any
inherited properties this should include the non-animated value.

Previously we were only inheriting the animated value and treating it as
non-animated so were instead including the animated value.

This commit fixes that by inheriting both the animated and non-animated
values (with the former being stored in `m_animated_property_values`,
and the latter in `m_property_values`).

This gains us 12 new WPT passes.

This brings with it 252 new WPT fails from the various 'events' tests in
css/css-transitions/properties-value-inherit-001.html, however these
also fail in other browsers (Chrome, Edge and Firefox) and the behaviour
that causes these failures is specifically mentioned in the spec.
2025-08-18 11:18:34 +01:00
Callum Law
54f1407177 LibWeb: Only associate transition with element once
We already handle this within the above call to `Animation::set_effect`

Gains us 3 WPT tests.
2025-08-18 11:18:34 +01:00
Callum Law
84fb0b458f LibWeb: Properly initialize KeyframeEffect contained in CSSTransition
This commit updates the CSSTransition constructor to:
 - Leave the KeyframeEffect start time unresolved
 - Set the KeyframeEffect start delay

Gains us 14 WPT passes but exposes one false positive in
properties-value-inherit-001.html
2025-08-18 11:18:34 +01:00
Callum Law
589529e081 LibWeb: Import tests related to CSSTransition 2025-08-18 11:18:34 +01:00
Jelle Raaijmakers
087601832a LibWeb: Set fit-content width for buttons in used values, not computed
For button layouts, we were overriding the computed `width` value with
`fit-content` in `TreeBuilder::wrap_in_button_layout_if_needed()`. But
the spec asks us to set the _used value_ instead, so we now actually
calculate the fit-content width and set the box' content width to it.

Fixes #2516.
2025-08-18 11:04:34 +01:00
Jelle Raaijmakers
39f36327d4 LibWeb: Simplify obtaining used value for PaintableBox
No functional changes.
2025-08-18 11:04:34 +01:00
Jelle Raaijmakers
ff5f80a196 LibWeb: Add HTMLElement::uses_button_layout()
This suits the spec a bit better, and exposes the fact that we were
allowing `::ImageButton` to use the button layout although it is never
specified that it should do so. Tests were rebaselined for this.
2025-08-18 11:04:34 +01:00
Callum Law
027c9f53be LibWeb: Handle text-overflow: ellipsis with trailing whitespace
We should calculate whether we need to truncate text with an ellipsis
exclusive of any trailing collapsible whitespace.

This was causing issues where an inline element was automatically sized
(e.g. min-content) as we would calculate available width exclusive of
trailing collapsible whitespace and then our text chunk would be wider,
always inserting an ellipsis.

Fixes the visual element of #4048 but we still are incorrect in how we
collapse whitespace more generally
2025-08-18 11:00:26 +01:00
Callum Law
3aff3327c4 LibWeb: Invalidate layout on opacity change to/from zero
As of 7dc8062 paintables compute and cache their visibility (which
depends on opacity) at construction - this cached value can fall out of
sync with reality if if the opacity changes to/from zero within the
lifetime of that paintable.

This commit invalidates layout when an opacity changes to/from zero so
that we reconstruct paintables with the correct visibility.
2025-08-18 10:21:44 +01:00
Sam Atkins
089f70a918 LibWeb/CSS: Reify StyleValues in StylePropertyMap get()/getAll()
The limitations right now are:
- We don't know if a property is a list or not.
- We always reify as a CSSStyleValue directly.

So, we pass some tests but only ones that expect a CSSStyleValue.
2025-08-18 10:12:53 +01:00
Sam Atkins
25c4c2397e LibWeb/CSS: Add StyleValue getter to CSSStyleDeclarations
Will be used by StylePropertyMap, as that wants a StyleValue to reify,
not a string representation.
2025-08-18 10:12:53 +01:00
Sam Atkins
276540fbe9 LibWeb/CSS: Add ability to reify a StyleValue
When no better reification form is available, we produce an opaque
CSSStyleValue with a serialized value. For starters, this will be the
only way to reify, and then we'll add others later.
2025-08-18 10:12:53 +01:00
Sam Atkins
b80930ae34 LibWeb/CSS: Connect up StylePropertyMaps to their source
After looking into this more, the `[[declarations]]` slot does not seem
to need to be a literal map of property names and values. Instead, it
can just point at the source (an element or style declaration), and
then direct all read or write operations to that.

This means the `has()` and `delete()` methods actually work now.

A few remaining failures in these tests are because of:
- StylePropertyMap[ReadOnly]s not being iterable yet
- We're not populating an element's custom properties map, which get
  fixed whenever someone gets around to producing proper computed
  values of them.
2025-08-18 10:12:53 +01:00
Sam Atkins
37ea9a4ce3 LibWeb/CSS: Add has_property() to CSSStyleDeclaration
This isn't part of the CSSOM API directly, but will be used by
StylePropertyMapReadOnly.has() to avoid doing the work to serialize a
string version of the property's value, just to throw it away again.
2025-08-18 10:12:53 +01:00
Jelle Raaijmakers
fcd39b67af Tests: Set SIGTERM as the timeout signal handler for ctest
We occasionally (frequently) time out in CI. If ctest triggers this
timeout, it sends a SIGSTOP followed by a SIGKILL. Since we want to
gracefully exit the test runner, ask ctest to send a SIGTERM instead.

This should cause active test status reports to show up in CI.
2025-08-17 20:51:56 -04:00
Jelle Raaijmakers
bee0ba2bb4 Tests: Report status on SIGINT and SIGTERM in LibWeb test runner
If you interrupt the test runner (Ctrl+C, SIGINT) or if the test runner
is gracefully being terminated (SIGTERM), it now reports the current
status of all the spawned views with their URL and, if an active test is
still being run, the time since the start of the test.

Hopefully this will help gain insight into which tests are hanging.
2025-08-17 20:51:56 -04:00
Jelle Raaijmakers
63119355e3 LibIPC: Do not try to send a response back if transport was closed
The local handling of some messages might cause the transport to get
closed. If that's the case, we shouldn't try to send back a response.

This fixes many of the "Trying to post_message during IPC shutdown"
errors I was seeing when terminating Ladybird or when abnormally exiting
from LibWeb tests.
2025-08-17 20:51:56 -04:00
Jelle Raaijmakers
9e4b6c1ded LibWebView: Remove m_in_shutdown in favor of event loop's exit request 2025-08-17 20:51:56 -04:00
Timothy Flynn
695bbcb991 LibJS: Revert common error types to only hold a single string
Before porting to UTF-16, these instances held a String. The port to
UTF-16 changed them to hold the original string as a StringView, and
lazily allocated the UTF-16 message as needed. This somehow negatively
impacting the zlib.js benchmark in the Octane suite.
2025-08-18 01:43:45 +02:00
Timothy Flynn
f8d414ec37 Meta: Pass ladybird.py extra arguments to the target process
Let's behave a bit more like the run command here. This allows us to run
`ladybird.py profile js zlib.js`, for example.
2025-08-18 01:43:45 +02:00
Jelle Raaijmakers
afda3aba14 LibCore: Remove Command
This went unused.
2025-08-17 16:44:14 -04:00
Glenn Skrzypczak
c01dc5900a LibWeb/HTML: Check all radio buttons in group for required attribute
This fixes a bug in the algorithm for determining if radio buttons are
missing their value. Previously it was only checked if the button
itself is required. Now the algorithm checks if the radio button group
contains a required radio button in order to determine if the value is
required.
2025-08-17 22:27:14 +02:00
Kenneth Myhra
f7442ae907 LibWeb: Remove unnecessary as_if<SVGGradientPaintStyle>() on paint_style
This causes a compiler error on GCC 15.0.1 and should be unnecessary
since paint_style already is of type SVGGradientPaintStyle.
2025-08-17 21:18:28 +01:00
Idan Horowitz
1f1adb6d7e LibWeb+LibURL: Default empty string paths to URL's path in CookieStore 2025-08-17 22:17:36 +02:00
Idan Horowitz
2f61199b01 LibWeb: Rename __hosthttp- to __host-http- in CookieStore 2025-08-17 22:17:36 +02:00
Idan Horowitz
d126b31b92 LibWeb: Consistently trim whitespace from name and value in CookieStore 2025-08-17 22:17:36 +02:00
Andreas Kling
3ab6d43ae2 LibWeb: Add missing null check in root_intersection_rectangle() 2025-08-17 19:09:50 +02:00
Andreas Kling
efd4f63454 LibWeb: Allow blockification across display: contents boundary
Flex/grid items are always blockified (have their CSS display forced
into "block") by style computation.

We were doing this by looking at the CSS display of the parent. However,
if the parent has `display: contents`, we must look at the *grandparent*
instead.

This corrects the layout of buttons underneath Reddit article cards.
2025-08-17 19:09:50 +02:00
Aliaksandr Kalenik
80c8e787a8 LibWeb: Fix abspos layout when box is contained by grid area
Before this change, `layout_absolutely_positioned_element()` in GFC
had an assumption that all contained by grid container abspos boxes were
also direct children of the grid container. This change adds handling
for the cases when it's not true and, in order to identify grid area
abspos box belongs to, we have to find ancestor grid item.
2025-08-17 17:58:16 +02:00
Tete17
08284e0ef6 LibJS: Implement console.dirxml
This function actually gets tested in WPT.
2025-08-17 07:28:56 -04:00
Tim Ledbetter
ad06ac0d58 LibWeb: Implement the color-interpolation property for SVG gradients
This changes the operating color space for gradient `<linearGradient>`
and `<radialGradient>` elements.
2025-08-17 10:51:05 +02:00
Vaxry
040ccc3b42 LibWeb: Allow loading style sheets without a MIME type
Some websites do not specify the MIME type of style sheets, instead
using as= or just leaving it empty.

Both Chromium and Firefox do load them regardless, so let's do it too.
2025-08-17 02:34:35 +02:00
Andreas Kling
9208a54b0b LibWeb: Allow style inheritance through slots
When a subtree is projected through a slot, its root now inherits style
from the slot's parent, rather than the parent of the unprojected root.

This fixes a ton of subtle issues, and is very noticeable on Reddit.
2025-08-16 21:03:31 +02:00
Callum Law
ba62679a7a LibWeb: Make text cursor same height as text
Previously we would paint the cursor the entire height of the text
fragment - this didn't look great with large line-heights. Now we only
paint it the height of the actual text, with the top of the cursor
aligning with the font "ascent" and the bottom the "descent".
2025-08-16 15:47:44 +02:00
Callum Law
71b039a721 LibWeb: Use document's global object in is_base_allowed_for_document
Previously we were using the document's window - this was both contrary
to spec and causing crashes when the document did not have a window (for
instance the `temp_document` in `HTMLParser::parse_html_fragment`.

This means we no longer crash when navigating between pages on
https://rocketlabcorp.com
2025-08-16 14:19:05 +02:00
Timothy Flynn
017ae80668 LibWeb: Validate form submissions whose submitter is not form-associated
The spec for checking the no-validate state ends with a default return
value of "false". However, we were only hitting this case for form-
associated elements. If the submitter is the form itself, we want to
enter the form validation steps.
2025-08-15 15:28:37 +02:00
mikiubo
23aadc02ca LibWeb: Implement up/down arrow navigation in textarea 2025-08-15 06:32:11 -04:00
Sam Atkins
888cb038e8 LibWeb/CSS: Expose a couple of types on PaintWorklet and LayoutWorklet
This has no actual effect, but it's nice to remove the FIXMEs.
2025-08-15 09:21:28 +02:00
Sam Atkins
6be9f0757f LibIDL: Add LayoutWorklet and PaintWorklet parsing
We don't support these yet, but this avoids having to comment out IDL
definitions that are exposed to them.
2025-08-15 09:21:28 +02:00
Sam Atkins
24c5dc2f7f LibIDL: Deduplicate code that parses an ExposedTo name 2025-08-15 09:21:28 +02:00
Sam Atkins
80a6dc4da0 LibIDL: Make ExposedTo an enum class 2025-08-15 09:21:28 +02:00
Timothy Flynn
c369f68eff LibWeb: Delete entire graphemes when the delete/backspace key is pressed
We currently delete a single code unit. If the user presses backspace on
a multi code point emoji, they are going to expect the entire emoji to
be removed. This now matches the behavior of Chrome and Firefox.
2025-08-14 22:21:51 +02:00
Timothy Flynn
76bab90812 LibWeb: Use rendered text to find word boundaries when double-clicking
This effectively reverts da26941b50.

When the user double-clicks a word on screen, they are interacting with
the rendered text, which has e.g. whitespace collapsing applied. If we
acquire word boundaries from the raw text, the resulting selection is
not right.

We still have issues with acquiring the right selection via APIs such as
`document.getSelection`. The offsets computed here are effectively then
applied to the raw text. But this issue is present all over EventHandler
and this patch at least makes the selection visually accurate.
2025-08-14 19:36:38 +02:00
Timothy Flynn
e314ca5e9d LibJS: Introduce ParseMonthCode and CreateMonthCode Temporal AOs
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/28357ea
https://github.com/tc39/proposal-temporal/commit/32f4b02
https://github.com/tc39/proposal-temporal/commit/f860ac6
https://github.com/tc39/proposal-temporal/commit/e6f565d
2025-08-14 11:35:28 -04:00
Timothy Flynn
0f4d5d3abc LibJS: Remove no-op call to ValidateTemporalUnitValue
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/07c924b
2025-08-14 11:35:28 -04:00
Glenn Skrzypczak
d25d62e74c AK/Time+LibWeb/HTML: Fix ISO8601 week conversions
This reimplements conversions between unix date times and ISO8601
weeks. The new algorithms also do not use loops, so they should be
faster.
2025-08-14 11:05:28 -04:00
Glenn Skrzypczak
ec807d40dd LibWeb/HTML: Correctly convert number to time/local datetime string
This fixes a bug where non-zero milliseconds were previously not
included if the second component was zero.
2025-08-14 11:05:28 -04:00
Glenn Skrzypczak
354fd56046 LibWeb/HTML: Step to next value without step mismatch
Inputs now correctly step to the next valid value if they suffer a step
mismatch.
2025-08-14 11:05:28 -04:00
Glenn Skrzypczak
a127f77602 LibWeb/HTML: Implement default value of range inputs
Range inputs now always uses the default value if the value attribute
is not set and the input is not dirty.
2025-08-14 11:05:28 -04:00
Glenn Skrzypczak
aea8650d8b LibWeb/HTML: Enforce constraints on range inputs
This extends the sanitization algorithm for range inputs in order to
prevent overflow, underflow and step mismatch.
2025-08-14 11:05:28 -04:00
Glenn Skrzypczak
57376f8701 LibWeb/HTML: Ensure the year of month and week values is greater than 0
The validation algorithm for month and week inputs now also checks if
the year is greater than zero.
2025-08-14 11:05:28 -04:00
Glenn Skrzypczak
544a6b21fc LibWeb/HTML: Correctly normalize local datetime values
Now trailing zeros in the second and millisecond part of local datetime
values are removed during normalization.
2025-08-14 11:05:28 -04:00
Glenn Skrzypczak
cac2ee41b9 LibWeb/HTML: Correctly compute whether element is mutable
This adapts the implementation of `is_mutable` to align more closely
with the spec. Specifically, it is now also taken into account whether
the element is enabled.
2025-08-14 11:05:28 -04:00
Kenneth Myhra
1228063a85 LibWeb: Enforce Integrity Policy on Fetch requests 2025-08-14 13:37:38 +01:00
CountBleck
ec051bdec2 LibWeb: Import css/selectors/user-valid.html from WPT 2025-08-14 11:55:02 +02:00
CountBleck
d49fb169bc LibWeb: Correct typos for user validity of form elements on submission
The spec and comments say "set field's user validity to true", but we
now actually set it to true and not false.

This passes one subtest in WPT's css/selectors/user-valid.html.
2025-08-14 11:55:02 +02:00
norbiros
783ae44462 LibWeb: Fix color interpolation by premultiplying alpha
The current Color::interpolate_color method does not follow the specs
properly. Started improving it by handling premultiplied alpha in color
interpolation.

Only one WPT test covers this (color-transition-premultiplied), which we
currently pass due to a different approach in Color.mixed_with.
2025-08-14 11:09:05 +02:00
ayeteadoe
d91d28dc2a Meta: Replace lint-clang-format.sh with lint-clang-format.py
Currently you need to use Git Bash or alternative bash implementations
to fully run the pre-commit checks on Windows. This will now allow
for formatting changes without bash.
2025-08-14 10:57:31 +02:00
stelar7
8addd5771f LibWeb/IDB: Add debug dump to Keys 2025-08-14 09:31:56 +01:00
stelar7
9e66f49b44 LibWeb/Tests: Update IDB keyorder test file 2025-08-14 09:31:56 +01:00
stelar7
75054aeecd LibWeb/IDB: Allow null errors during abort 2025-08-14 09:31:56 +01:00
stelar7
474b748275 LibWeb/IDB: Check the request error instead of the transaction 2025-08-14 09:31:56 +01:00
stelar7
a7bcb1b0c5 LibWeb/IDB: Dont set state in IDBTransaction::abort 2025-08-14 09:31:56 +01:00
Timothy Flynn
70db474cf0 LibJS+LibWeb: Port interned bytecode strings to UTF-16
This was almost a no-op, except we intern JS exception messages. So the
bulk of this patch is porting exception messages to UTF-16.
2025-08-14 10:27:08 +02:00
Timothy Flynn
cf61171864 LibJS: Port remaining bytecode identifiers to UTF-16 2025-08-14 10:27:08 +02:00
Timothy Flynn
829fd25264 LibJS: Add a UTF-16 variant of Value::to_string_without_side_effects 2025-08-14 10:27:08 +02:00
Timothy Flynn
c87122eb32 LibJS: Add a method to stringify a BigInt to UTF-16
And remove the ByteString variant while we are here.
2025-08-14 10:27:08 +02:00
Luke Wilde
12dc771186 CI: Create wasm artifact and use it in the js-benchmarks workflow 2025-08-14 10:02:35 +02:00
Jamie Mansfield
73a05f9163 LibWeb: Implement VTTCue.position 2025-08-13 23:05:50 +02:00
Jamie Mansfield
8204143b08 LibWeb: Implement VTTCue.line 2025-08-13 23:05:50 +02:00
Jelle Raaijmakers
9080af4085 RequestServer: Don't set CURLOPT_HTTPGET _and_ CURLOPT_CUSTOMREQUEST
We always set CURLOPT_CUSTOMREQUEST, so we can skip setting
CURLOPT_HTTPGET.
2025-08-13 10:30:04 -04:00
Jelle Raaijmakers
ed57d2de98 RequestServer: Don't return unused bool when setting curl options 2025-08-13 10:30:04 -04:00
Jelle Raaijmakers
da351ac468 RequestServer: Pass nullptr instead of an unused variable 2025-08-13 10:30:04 -04:00
Jelle Raaijmakers
585e4ed875 RequestServer: Add some useful dbgln_if()s
In trying to debug request handling, I've found these to help
understanding what's going on behind the scenes.
2025-08-13 10:30:04 -04:00
Jelle Raaijmakers
41cf150a5b LibDNS+RequestServer: Don't construct Vectors to validate DNS response
Instead of filling vectors and returning them just to invoke
`.is_empty()`, forward the calls to the underlying vectors directly.
2025-08-13 10:30:04 -04:00
Timothy Flynn
62d85dd90a LibJS: Port RegExp flags and patterns to UTF-16 2025-08-13 09:56:13 -04:00
Timothy Flynn
b955c9b2a9 LibJS: Port the Identifier AST (and related) nodes to UTF-16
This eliminates quite a lot of UTF-8 / UTF-16 churn.
2025-08-13 09:56:13 -04:00
Timothy Flynn
00182a2405 LibJS: Port the JS lexer and parser to UTF-16
This ports the lexer to UTF-16 and deals with the immediate fallout up
to the AST. The AST will be dealt with in upcoming commits.

The lexer will still accept UTF-8 strings as input, and will transcode
them to UTF-16 for lexing. This doesn't actually incur a new allocation,
as we were already converting the input StringView to a ByteString for
each lexer.

One immediate logical benefit here is that we do not need to know off-
hand how many UTF-8 bytes some special code points occupy. They all
happen to be a single UTF-16 code unit. So instead of advancing the
lexer by 3 positions in some cases, we can just always advance by 1.
2025-08-13 09:56:13 -04:00
Timothy Flynn
eb74781a2d LibJS: Keep the lookahead lexer alive after parsing its next token
Currently, the lexer holds a ByteString, which is always heap-allocated.
When we create a copy of the lexer for the lookahead token, that token
will outlive the lexer copy. The token holds a couple of string views
into the lexer's source string. This is fine for now, because the source
string will be kept alive by the original lexer.

But if the lexer were to hold a String or Utf16String, short strings
will be stored on the stack due to SSO. Thus the token will hold views
into released stack data. We need to keep the lookahead lexer alive to
prevent UAF on views into its source string.
2025-08-13 09:56:13 -04:00
Timothy Flynn
8472e469f4 AK+LibJS+LibWeb: Recognize that our UTF-16 string is actually WTF-16
For the web, we allow a wobbly UTF-16 encoding (i.e. lonely surrogates
are permitted). Only in a few exceptional cases do we strictly require
valid UTF-16. As such, our `validate(AllowLonelySurrogates::Yes)` calls
will always succeed. It's a wasted effort to ever make such a check.

This patch eliminates such invocations. The validation methods will now
only check for strict UTF-16, and are only invoked when needed.
2025-08-13 09:56:13 -04:00
Timothy Flynn
36c7302178 AK: Optimize the UTF-16 StringBuilder for ASCII storage
When we build a UTF-16 string, we currently always switch to the UTF-16
storage mode inside StringBuilder. Then when it comes time to create the
string, we switch the storage to ASCII if possible (by shifting the
underlying bytes up).

Instead, let's start out with ASCII storage and then switch to UTF-16
storage once we see a non-ASCII code point. For most strings, this will
avoid allocating 2x the memory, and avoids many ASCII validation calls.
2025-08-13 09:56:13 -04:00
Timothy Flynn
99d7e08dff AK: Templatize GenericLexer for UTF-16 strings
We now define GenericLexer as a template to allow using it with UTF-16
strings. To keep existing users happy, the template is defined in the
Detail namespace. Then AK::GenericLexer is an alias for a char-based
view, and AK::Utf16GenericLexer is an alias for a char16-based view.
2025-08-13 09:56:13 -04:00
Timothy Flynn
28d9d3a2c7 AK+Libraries: Reduce API surface of GenericLexer a bit
* Remove completely unused methods.
* Deduplicate methods that were overloaded with both StringView and
  char const* parameters.

A future commit will templatize GenericLexer by char type. This patch
serves to make that a tiny bit easier.
2025-08-13 09:56:13 -04:00
Timothy Flynn
213683956c LibCrypto: Return StringView from ASN1 enum-to-string factories
We were implicitly including ByteString.h here, which will become a
compile error in an upcoming commit. Let's just return StringView.
2025-08-13 09:56:13 -04:00
Jelle Raaijmakers
7078769ba3 LibWeb: Don't indicate focus for all form associated elements
This was a misinterpretation of the spec; we should only indicate focus
if the form associated element supports keyboard input, for which
FormAssociatedTextControlElement is a much better match.
2025-08-13 09:44:38 -04:00
Nico Weber
7a01912af3 LibWeb/IDB: Fix typo in diagnostic 2025-08-13 14:21:56 +01:00
rmg-x
d489e46448 RequestServer: Clarify comment for removing Content-Type header
This comment assumed that the reader knew how curl behaved with empty
header values.
2025-08-13 06:30:56 -04:00
rmg-x
d1db27dc42 RequestServer: Remove unused include of AK/Badge.h 2025-08-13 06:30:56 -04:00
Aliaksandr Kalenik
4d223462a5 LibWeb: Fix cyclic percentage resolution in calculate_min_content_width
Brings back some code removed in 652a457, but this time with explanation
from https://www.w3.org/TR/css-sizing-3 spec.
2025-08-13 10:14:37 +01:00
Sam Atkins
911274a84d LibWeb/CSS: Implement ElementCSSInlineStyle.attributeStyleMap
Again, this isn't yet very usable, but it does appease some tests.
2025-08-13 09:47:50 +01:00
Sam Atkins
215d8b8076 LibWeb/CSS: Implement CSSStyleRule.styleMap
StylePropertyMap is just a stub, so this doesn't yet accomplish much.
2025-08-13 09:47:50 +01:00
Sam Atkins
3bb54ffd59 LibWeb/CSS: Stub out StylePropertyMap 2025-08-13 09:47:50 +01:00
Sam Atkins
c768cc7208 LibWeb/CSS: Implement Element.computedStyleMap()
Currently the map doesn't return any values, so it's not very useful,
but this does make a few tests pass just by existing. :^)
2025-08-13 09:47:50 +01:00
Sam Atkins
1620fc5bf6 LibWeb/CSS: Stub out StylePropertyMapReadOnly
Nothing yet produces this, and the useful parts of get() and get_all()
will have to wait until type reification is implemented.
2025-08-13 09:47:50 +01:00
Sam Atkins
05884f1d91 LibWeb/CSS: Implement is_a_valid_css_property()
Also mark these functions as inline instead of static, to fix a compiler
error about them being unused.
2025-08-13 09:47:50 +01:00
Sam Atkins
882288bf86 LibWeb/CSS: Stub out CSSStyleValue 2025-08-13 09:47:50 +01:00
Sam Atkins
b447dc63c4 IDLGenerators: Include JS::Array in constructor implementations
Will be required by CSSStyleValue.
2025-08-13 09:47:50 +01:00
Sam Atkins
7ec374c74c Tests: Import tests for CSS typed OM
This is everything except some failing ref-tests, and
`css/css-typed-om/the-stylepropertymap/properties/*` because importing
a test for every property feels excessive.
2025-08-13 09:47:50 +01:00
Sam Atkins
00cadf41d8 LibWeb/CSS: Update UA stylesheet to use :heading
Corresponds to part of
65dc095e44
2025-08-13 09:47:28 +01:00
Sam Atkins
503d41d02d LibWeb/CSS: Implement the :heading/:heading() pseudo-class
Corresponds to part of
65dc095e44
2025-08-13 09:47:28 +01:00
Sam Atkins
e7890429aa LibWeb/CSS: Add support for pseudo-classes taking <an+b># 2025-08-13 09:47:28 +01:00
Sam Atkins
fbae3b824a LibWeb/CSS: Move An+B matching code into ANPlusBPattern::matches()
Not everything we want to match is an "nth element".

Also moved its serialization function's implementation out of the header
while I was at it.
2025-08-13 09:47:28 +01:00
Sam Atkins
a59c15481f LibWeb/CSS: Prepare pseudo-classes for multiple An+B patterns
The upcoming `:heading()` pseudo-class takes multiple comma-separated
An+Bs. Also rename this field as the `:nth-[last-]child()`
pseudo-classes are only a subset of the users.
2025-08-13 09:47:28 +01:00
Lukas Schmidt
c2fc4b25cd LibWeb: Implement HTMLElement.draggable() 2025-08-12 17:15:06 +01:00
Sam Atkins
615034433b LibWeb/HTML: Add missing if to <details> attribute_changed() logic 2025-08-12 15:53:51 +02:00
Sam Atkins
a28b2b4ca1 WebContent: Correct StyleValue.h include
Regressed in c57975c9fd, oops!
2025-08-12 09:41:47 -04:00
Callum Law
ed6cac89b9 LibWeb: Discard inaccuracies when interpolating rotate 2025-08-12 14:35:02 +01:00
Jelle Raaijmakers
d6761ab251 CI: Remove Microphone access step for macOS
This no longer seems to be necessary.
2025-08-12 14:31:41 +02:00
Kenneth Myhra
0dc2fb3781 LibWeb: Update Fetch's compute the redirect-taint concept 2025-08-12 07:08:33 -04:00
Kenneth Myhra
e9246c15d9 LibWeb: Pass top-level navigation initiator origin to Fetch's Request 2025-08-12 07:08:33 -04:00
dependabot[bot]
60ca15c0de CI: Bump actions/checkout from 4 to 5
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-12 07:05:19 -04:00
Jelle Raaijmakers
a64cee528c CI: Update to Xcode 16.4
Our current macOS runners have Xcode 16.4 installed.
2025-08-11 18:25:34 +02:00
Callum Law
778da0175e LibWeb: Clamp and censor top-level calc results
We now clamp the values returned from calc into the allowed range (where
we know it) and censor any `NaN`s to `0` both when we resolve and when
we serialize.

Gains us 76 WPT passes.
2025-08-11 17:10:04 +01:00
Callum Law
bc2ca96f50 LibWeb: Make signature of CSS::{Percentage,Number}::to_string consistent
By making this consistent with the other numeric data type classes we
can simplify cases where we are dealing with variants containing these
types.
2025-08-11 17:10:04 +01:00
Callum Law
3fe3adadc4 LibWeb: Remove unnecessary includes in Percentage.h 2025-08-11 17:10:04 +01:00
Callum Law
f15153ea86 LibWeb: Move formatter for Percentage into Percentage.h 2025-08-11 17:10:04 +01:00
Callum Law
90948405fc LibWeb: Return an intermediate struct from CSV::resolve_value
Returning this struct will allow us to modify the underlying value of
the `CalculationResult` without requiring us to go through the process
of constructing a whole new `CalculationResult` to return.
2025-08-11 17:10:04 +01:00
Callum Law
6025805f19 LibWeb/Meta: Compute the accepted value range for CalculationContexts
This currently only applies to property-level calculation contexts, more
work to be done to generate accepted ranges for other calculation
contexts (e.g. within transformation functions, color functions, etc)
2025-08-11 17:10:04 +01:00
Callum Law
2af7016a77 LibWeb: Rename ValueType::OpenTypeTag to ValueType::OpentypeTag
This is the correct capitalization in line with what it is called in the
spec "opentype-tag".
2025-08-11 17:10:04 +01:00
Callum Law
861bcbd9ad AK: Format floats with precision in scientific notation where applicable 2025-08-11 17:10:04 +01:00
Callum Law
1474da31c7 AK: Reduce duplication between put_f32_or_f64 and put_f64_with_precision
We were handling the special cases of NaN and Infinity in basically the
same way across both functions - we can reduce code duplication by
moving this to before we branch.

This is also required as we will be moving the logic to encode in
scientific notation above the branch in a later commit and the
`convert_floating_point_to_decimal_exponential_form` method doesn't work
with non-finite values.
2025-08-11 17:10:04 +01:00
Callum Law
1a9dd70792 LibWeb: Serialize NumberStyleValue with 6 decimal places of precision 2025-08-11 17:10:04 +01:00
Callum Law
7182a537f3 LibWeb: Reduce inaccuracies when creating rotation matrices
When converting rotate transform functions `sin` and `cos` can sometimes
be inaccurate. To avoid these inaccuracies we:
 - Mod the angle to minimise inaccuracies in the first place.
 - Discard tiny (smaller than epsilon) values returned by `sin` and
   `cos` as inaccuracies.

This is in line with  other browsers (e.g. Gecko and WebKit).
2025-08-11 17:10:04 +01:00
Callum Law
719ab5735e LibWeb: Avoid addition to infinity when rounding calc'd z-index 2025-08-11 17:10:04 +01:00
Timothy Flynn
f03c432b52 AK: Use simdutf for searching strings for a single code unit
In the following synthetic benchmark, the simdutf version is 4x faster:

    BENCHMARK_CASE(find)
    {
        auto string = u"😀Foo😀Bar"sv;

        for (size_t i = 0; i < 100'000'000; ++i)
            (void)string.find_code_unit_offset('a');
    }
2025-08-11 16:55:37 +02:00
Andreas Kling
bd7599ccfc LibCore: Remove macro-generated EventReceiver::try_create(...) factories
We can just use the infallible factory everywhere instead.
2025-08-11 16:55:25 +02:00
Andreas Kling
aec1f6aa7e LibCore: Remove unused CustomEvent 2025-08-11 16:55:25 +02:00
Andreas Kling
c47e253c60 LibCore: Remove unused "visible for timer purposes" concept
This was a long-unused leftover from SerenityOS.
2025-08-11 16:55:25 +02:00
Andreas Kling
0037df88d5 LibCore: Remove unused ChildEvent 2025-08-11 16:55:25 +02:00
Andreas Kling
75091016d7 LibCore: Remove parent/child concept from EventReceiver
This ownership model is no longer used.
2025-08-11 16:55:25 +02:00
Andreas Kling
134fd8e413 LibCore: Don't have Promise inherit from EventReceiver
This was only used for parenting promises to each other, but we can do
that with a simple vector of children.
2025-08-11 16:55:25 +02:00
Andreas Kling
dfe776b722 WebDriver: Stop using the ancient Core::EventReceiver parent/child API
Before this change, clients were kept alive by making them children of
the TCPServer object. This ownership model is going away (and this was
the only remaining use of it!) so let's just put the clients in a hash
table instead.
2025-08-11 16:55:25 +02:00
Andreas Kling
045eaa1576 LibLine: Remove unnecessary use of EventReceiver parent/child API 2025-08-11 16:55:25 +02:00
Andreas Kling
b8357bc190 LibCore: Remove unused LocalServer constructor parameter 2025-08-11 16:55:25 +02:00
Andreas Kling
cfcb63239d LibCore: Remove unused ThreadedPromise constructor 2025-08-11 16:55:25 +02:00
Andreas Kling
fa8592b4a9 LibCore: Remove unused UDPServer constructor parameter 2025-08-11 16:55:25 +02:00
Andreas Kling
036aa43a41 LibCore: Remove unused TCPServer constructor parameter 2025-08-11 16:55:25 +02:00
Andreas Kling
d13884e933 LibCore: Remove unused Timer APIs for constructing with a parent 2025-08-11 16:55:25 +02:00
Andreas Kling
4d285d6dce LibCore: Remove an unused Promise constructor 2025-08-11 16:55:25 +02:00
Andreas Kling
ecf0395c27 LibCore: Stop parenting notifiers
There's no need to participate in the ancient EventReceiver parent/child
ownership scheme here. Notifiers are already owned by RefPtrs anyway.
2025-08-11 16:55:25 +02:00
Andreas Kling
34709cc796 LibCore: Remove unused "name" concept from EventReceiver 2025-08-11 16:55:25 +02:00
Tete17
cf211cf99a LibWeb: Migrate TrustedTypes to Utf16String 2025-08-11 12:21:31 +01:00
Tete17
7559084b22 LibWeb: Add wpt test for createPolicy and createXXX
This gives us at least 72 new tests :)
2025-08-11 12:21:31 +01:00
Tete17
53e0f287d1 LibWeb: Implement reporting of trusted-types-policy violations 2025-08-11 12:21:31 +01:00
Tete17
bc9e67a0dc LibWeb: Implement methods dependant on TrustedScriptURL 2025-08-11 12:21:31 +01:00
Tete17
adaad653ca LibWeb: Implement TrustedScriptURL class 2025-08-11 12:21:31 +01:00
Tete17
40691bf25d LibWeb: Implement methods dependant on TrustedScript 2025-08-11 12:21:31 +01:00
Tete17
56cab6955a LibWeb: Implement TrustedScript type
This turns out to be very similar to TrustedHTML.
2025-08-11 12:21:31 +01:00
Tete17
c84c97b339 LibWeb: Implement createHTML for TrustedTypePolicy
This is the main mechanism by which users of the api can create
safe object with a callback for any needed sanitation of the values.
2025-08-11 12:21:31 +01:00
Tete17
966e00fd69 LibWeb: Finish algorithm to block trusted type policy creation with CSP
This is the mechanism that should pages to determine what kind of
policies can be created on their domains mostly based around the HTTP
headers the server responds with.
2025-08-11 12:21:31 +01:00
Tete17
6398e771a3 LibWeb: Implement create_policy function for TrustedTypePolicyFactory
It simply consists of a wrapper around the main algorithm
2025-08-11 12:21:31 +01:00
Tete17
90bcc16a7b LibWeb: Add TrustedTypePolicy class
It is mostly a skeleton with no actual implementation.
2025-08-11 12:21:31 +01:00
Tete17
a73c082f36 LibWeb: Implement is_html method for TrustedTypePolicyFactory
This is used to check the legitimacy of a TrustedHTML object.
2025-08-11 12:21:31 +01:00
Tete17
0a147aa9a1 LibWeb: Implement TrustedHTML class
The TrustedHTML interface represents a string that a developer can
confidently insert into an injection sink that will render it as HTML.

These objects are immutable wrappers around a string, constructed via a
TrustedTypePolicy’s createHTML method.
2025-08-11 12:21:31 +01:00
Tete17
68c55b0ef1 LibWeb: Implement getPropertyType for TrustedTypePolicyFactory
This allows authors to check if a Trusted Type is required for the given
Elements property.

This adds 28 more passing WPT tests :)
2025-08-11 12:21:31 +01:00
Sam Atkins
4bcfc4bacc LibWeb/HTML: Add cross-site ancestor flag to environment
Corresponds to baec061a70
2025-08-11 11:08:04 +01:00
Sam Atkins
cfdc4bad7c LibWeb: Update more navigation code to spec
Partly corresponds to 80ebad5fbf

This is mostly to handle null source_documents, which is something that
needs more work elsewhere. The spec change above is about the deferred
fetch quota.
2025-08-11 11:08:04 +01:00
Sam Atkins
0e5fd11bdc LibWeb/HTML: Create navigation params for browser-UI navigations
Step 4 corresponds to 3b6a99b1d9

The rest is from some earlier spec change.
2025-08-11 11:08:04 +01:00
Sam Atkins
cf969abba7 LibWeb/HTML: Add missing "else" to create_navigation_params_by_fetching 2025-08-11 11:08:04 +01:00
Sam Atkins
0b998b8379 LibWeb: Update base URL change processing
Corresponds to 49f5cd381e
2025-08-11 11:08:04 +01:00
Sam Atkins
7c8c05ee82 LibWeb/Layout: Support visibility:collapse on table-row elements
When a table row (or its group) is set to collapse, the row takes up no
vertical space in the layout.

We have to account for this in multiple places, so I've cached whether a
row is collapsed in the TableGrid::Row.
2025-08-11 11:07:47 +01:00
Sam Atkins
3b97bdc7bf Tests: Import WPT tests for table rows with visibility:collapse
These mostly fail for now.
2025-08-11 11:07:47 +01:00
Sam Atkins
5f986b2c33 LibWeb/Painting: Paint ridge and groove border styles 2025-08-11 11:07:15 +01:00
Sam Atkins
5d4a4e44fe LibWeb/Painting: Paint border-style: double using two solid borders
Call paint_border() recursively, once for the outer line, and once for
the inner one. This is done in a lambda so that we can reuse it for a
couple of other line styles.

Border-radius behaviour doesn't match other browsers, and goes a bit
haywire in some cases. I've left some FIXMEs for someone who
understands the maths here better than I do. 😅

The LineStyle handling is moved to the start of the function, to avoid
unnecessary work.
2025-08-11 11:07:15 +01:00
Sam Atkins
c660df70b4 LibWeb/Painting: Note that inset and outset borders are implemented 2025-08-11 11:07:15 +01:00
Sam Atkins
7c2b8f6ee7 LibWeb/Painting: Move per-edge getter into BordersDataDevicePixels
Reduces some duplication.
2025-08-11 11:07:15 +01:00
Timothy Flynn
e2b245add1 LibJS: Handle out-of-range prefixed numbers in Token::double_value
This regressed in cd15b1a2c9.

If a prefixed number is out-of-range of a u64, stroul would previously
fall back to ULONG_MAX. This patch restores that behavior.
2025-08-10 13:35:37 +02:00
Aliaksandr Kalenik
652a457f52 LibWeb: Fix grid layout for replaced items with percentage max-width
CSS grid specification states that for grid items with a replaced
element and a percentage preferred size or maximum size, the percentage
should be resolved against 0 during content-based minimum size
calculation. This makes sense, as it prevents replaced items from
overshooting their grid track while intrinsic track sizes are
calculated, and allows later track size resolution steps to scale
replaced items to fit their grid track.
2025-08-10 11:07:02 +02:00
Timothy Flynn
57b5df21c7 LibWeb: Select the entire input when double clicking password fields
This matches the behavior of other browsers, and hides any indication
of word boundaries in the password.
2025-08-10 11:05:49 +02:00
Timothy Flynn
ded337cfec LibWebView: Gracefully handle RequestServer death
This works exactly the same as ImageDecoder death handling.
2025-08-10 11:02:50 +02:00
Timothy Flynn
b1b218596f LibWeb+WebContent: Add IPC to re-establish RequestServer connections 2025-08-10 11:02:50 +02:00
Timothy Flynn
6f4be4791a LibRequests: Add hooks to handle RequestServer death 2025-08-10 11:02:50 +02:00
Timothy Flynn
e421c233a6 LibWebView: Ignore ImageDecoder death during process shutdown 2025-08-10 11:02:50 +02:00
Timothy Flynn
58f5fe7d79 RequestServer: Add an IPC method to reconnect N request clients
Similar to the same IPC on ImageDecoder, this just avoids IPC churn.
2025-08-10 11:02:50 +02:00
ayeteadoe
78a08bac82 LibWasm: Fix Windows build 2025-08-09 16:41:37 -06:00
Tim Ledbetter
b15c4cccbf LibWeb: Ignore non-element nodes when evaluating filters
This prevents an unknown filter debug message would be printed for
comments.
2025-08-08 23:54:17 +01:00
Idan Horowitz
81e3afd1fd LibWeb+LibWebView: Implement emitting CookieChangeEvents 2025-08-08 13:09:58 -04:00
Idan Horowitz
a72a0b3c2d LibWeb+LibWebView: Move RFC6265 helpers to LibWeb
This will make them usable by LibWeb's CookieStore code as well.
2025-08-08 13:09:58 -04:00
Idan Horowitz
93692242b9 AK: Implement take_all_matching(predicate) API in HashMap 2025-08-08 13:09:58 -04:00
Idan Horowitz
5097e72174 AK: Implement take_all_matching(predicate) API in HashTable 2025-08-08 13:09:58 -04:00
Idan Horowitz
70efa8c1c5 LibWeb: Implement CookieChangeEvent 2025-08-08 13:09:58 -04:00
Idan Horowitz
185f8f7d56 LibWeb: Implement CookieStore::delete(options) 2025-08-08 13:09:58 -04:00
Idan Horowitz
d62fea0340 LibWeb: Implement CookieStore::delete(name) 2025-08-08 13:09:58 -04:00
Idan Horowitz
f724f542ed LibWeb: Implement CookieStore::set(options) 2025-08-08 13:09:58 -04:00
Idan Horowitz
1f37130703 LibWeb: Implement CookieStore::set(name, value) 2025-08-08 13:09:58 -04:00
Idan Horowitz
1328754fb0 LibWeb: Implement CookieStore::getAll(options) 2025-08-08 13:09:58 -04:00
Idan Horowitz
972e4e2cfc LibWeb: Implement CookieStore::get(options) 2025-08-08 13:09:58 -04:00
Idan Horowitz
536158878d LibWeb: Implement CookieStore::getAll(name) 2025-08-08 13:09:58 -04:00
Idan Horowitz
5545d38d7a LibWeb: Implement CookieStore::get(name) 2025-08-08 13:09:58 -04:00
Idan Horowitz
dc1b7b1925 IDLGenerators: Support generating dictionary to value converter helpers
This is useful when returning dictionaries as a Promise.
2025-08-08 13:09:58 -04:00
Idan Horowitz
d6c2893663 LibWeb: Add initial CookieStore support 2025-08-08 13:09:58 -04:00
Timothy Flynn
4a8c70b3a5 LibWeb: Parse CSS/image URLs using DOMURL::parse
DOMURL::parse handles blob URLs.
2025-08-08 17:47:51 +01:00
Timothy Flynn
9e474a4eb0 LibWeb: Add missing includes to SharedResourceRequest
Missing Cell.h and Ptr.h were causing a bunch of clangd errors. Also
remove unused includes while we're here.
2025-08-08 17:47:51 +01:00
Aliaksandr Kalenik
4b3a87eb14 LibJS: Add fast path for Array.prototype.shift
Makes `MicroBench/array-prototype-shift.js` 100x faster on my machine.

Progress on https://github.com/LadybirdBrowser/ladybird/issues/5725
2025-08-08 18:10:14 +02:00
Sam Atkins
7c29db6ab0 Meta: Exclude crash and screenshot tests from newline-at-eof requirement 2025-08-08 15:59:24 +01:00
Luke Wilde
4d34095b0a LibWeb/Wasm: Return Hash{Map,Table} caches by const reference
When loading Infiltrating the Airship in Ruffle, the copying of these
hash maps/tables were at least 10% of the runtime. This disappears when
returning them by const reference.
2025-08-08 16:30:37 +02:00
Sam Atkins
5bd3bc309e LibWeb/CSS: Rename color style value types
The typed-om classes will be separate.
2025-08-08 15:19:03 +01:00
Sam Atkins
6cad3f1921 LibWeb/CSS: Rename CSSColorValue -> ColorStyleValue
The typed-om class will be a separate thing.
2025-08-08 15:19:03 +01:00
Sam Atkins
99bce9a94d LibWeb/CSS: Replace CSSUnitValue with DimensionStyleValue
CSSUnitValue is a typed-om type which we will implement separately in
the future. However, it still seems useful to give our dimension values
a base class. (Maybe they could be templated in the future?) So instead
of deleting it entirely, rename it to DimensionStyleValue and make its
API match our style better.
2025-08-08 15:19:03 +01:00
Sam Atkins
7157d19f56 LibWeb/CSS: Separate IntegerSV and NumberSV from CSSUnitValue
This inheritance exists for typed-om classes, but StyleValues aren't
typed-om.

Somehow this makes our z-index interpolation slightly more correct. 🎉
2025-08-08 15:19:03 +01:00
Sam Atkins
51a657ca47 LibWeb/CSS: Delete CSSNumericValue
This will need to be re-added later as a proper typed-om type, but right
now it's useless.
2025-08-08 15:19:03 +01:00
Sam Atkins
4e92ab52e3 LibWeb/CSS: Rename CSSKeywordValue -> KeywordStyleValue
The typed-om CSSKeywordValue will need to be a separate class.
2025-08-08 15:19:03 +01:00
Sam Atkins
c57975c9fd LibWeb: Move and rename CSSStyleValue to StyleValues/StyleValue.{h,cpp}
This reverts 0e3487b9ab.

Back when I made that change, I thought we could make our StyleValue
classes match the typed-om definitions directly. However, they have
different requirements. Typed-om types need to be mutable and GCed,
whereas StyleValues are immutable and ideally wouldn't require a JS VM.

While I was already making such a cataclysmic change, I've moved it into
the StyleValues directory, because it *not* being there has bothered me
for a long time. 😅
2025-08-08 15:19:03 +01:00
Ali Mohammad Pur
0d8ad0a9fe Meta: Bump minimum compiler versions for deducing this 2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
cadc3f85a6 Tests: Run all Vector tests for FastLastAccess::Yes too 2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
8af095f797 LibWasm: Make Wasm::Validator::Stack hold a Vector instead of inheriting 2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
b97ad99014 LibWasm: Remove unnecessary C-style casts
Or replace them with static-cast when necessary.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
1ef536194d LibWeb/WebAssembly: Avoid scanning all externs when resolving references
This was very hot on a profile of ruffle.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
33cd5ae08c LibWasm: Fuse some very common instruction combos into specialised ops
Largely combinations of i32.const and local.get.
This shaves off at most single-digit% number of instructions from
dispatch, which translates to at most ~10% reduced dispatch time.

Across most benchmarks, this gains around ~5% perf increase.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
0e5ecef848 LibWasm: Try really hard to avoid touching the value stack
This commit adds a register allocator, with 8 available "register"
slots.
In testing with various random blobs, this moves anywhere from 30% to
74% of value accesses into predefined slots, and is about a ~20% perf
increase end-to-end.

To actually make this usable, a few structural changes were also made:
- we no longer do one instruction per interpret call
- trapping is an (unlikely) exit condition
- the label and frame stacks are replaced with linked lists with a huge
  node cache size, as we only need to touch the last element and
  push/pop is very frequent.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
998454028c LibWasm+wasm: Remove the debug interpreter
This is largely unused (only in wasm.cpp)
A future reimplementation can bring it back as a separate interpreter
class that embeds the current bytecode interpreter.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
4e2845847b LibJS: Add a fast-path to <Int32>.to_uint8()
This was showing up in a profile as hot.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
e47fceed38 AK: Optionally keep track of the last slot in Vector
last() and take_last() are extremely common ops when the vector is used
like a stack.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
2cd4b4e28d AK: Skip vcalls to Stream::read_value and read_until_filled in LEB128
...for the first byte.
This function only really needs to read a single byte at that point, so
read_until_filled() is useless and read_value<u8> is functionally
equivalent to just a read.

This showed up hot in a wasm parse benchmark.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
931b554f68 LibWasm: Give some inline capacity to the frame and label stacks
The average wasm function rarely goes over these bounds for the labels
(32 nested control structures), and 8 frames is just enough to clear
most initialization code/start section without allocating anything.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
bf4c436ef3 AK: Add some higher-level operations to DoublyLinkedList<T>
This also adds a node cache as allocation/deallocation was showing up in
my profiles; disabled by default to keep the old behaviour.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
dc67f0ad4e LibWasm: Hold on to the stack depth for expressions in the validator
This allows preallocating the value stack when pushing frames, avoiding
repeated reallocs and copies.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
3f77aa8521 LibWasm: Try to avoid vcalls on very busy stream read functions
This was a bottleneck when parsing, in general.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
834fb0be36 AK: Make some Stream::read* functions available inline
These are quite bottlenecky in wasm, the next commit will try to make
use of this by calling them directly instead of doing a vcall, and
having them inlineable helps the compiler a bit.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
bd7c188b86 LibWasm: Avoid memory copy in read_value<T>() if possible
If the address is already aligned properly, just read a T from it;
otherwise copy it to a local aligned array. This was a bottleneck on
memory-heavy benchmarks.
2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
5c6f223f48 LibWasm: Avoid repeated shrinkage of value stack 2025-08-08 12:54:06 +02:00
Ali Mohammad Pur
0f13952f30 AK: Simplify some stream reading logic
These do the same thing in a less convoluted way. NFC.
2025-08-08 12:54:06 +02:00
Callum Law
e260ba54e0 LibWeb: Propagate NaN in CSS clamp function
Gains us 10 WPT tests.
2025-08-08 11:43:49 +01:00
Callum Law
4ba54a7a1c LibWeb: Handle NaN and Infinite values in CSS round function
Gains us 10 WPT tests
2025-08-08 11:43:49 +01:00
Callum Law
376b992f0e LibWeb: Handle NaN within CSS min and max functions
Gains us 10 WPT tests
2025-08-08 11:43:49 +01:00
Callum Law
9e1ace28a6 LibWeb: Import WPT tests related to handling non-finite values in calcs 2025-08-08 11:43:49 +01:00
Kenneth Myhra
1b350596fb LibWeb: Align Fetching chapter's "To fetch" with latest spec changes 2025-08-08 11:12:53 +01:00
Kenneth Myhra
593ee1ae0a LibWeb: Implement AO populate request from client 2025-08-08 11:12:53 +01:00
Kenneth Myhra
70cafc558e LibWeb: Replace request's "window" with "traversable for user prompts"
User prompts are not tied to specific Windows or the client's Window.
They are tied to a traversable navigable (browser tab).
2025-08-08 11:12:53 +01:00
Kenneth Myhra
681e4e5d01 LibWeb: Define stream variable before using it
This is an editoral change from the fetch spec. Since we already defined
the stream before it being used this only re-numbers the spec steps.

It also corrects a minor typo ('followings' to 'following') which was
corrected in the same editoral spec change.
2025-08-08 11:12:53 +01:00
Callum Law
a1037e28d6 LibWeb: Improve support for CalculatedStyleValue in scale
- Properly serialize CalculatedStyleValue components
- Allow CSV to be the 'Z' component in interpolated value

Gains us 52 WPT tests
2025-08-08 09:45:00 +01:00
Callum Law
39fdcbc526 LibWeb: Improve support for CalculatedStyleValue in translate
- Omit calcs that are resolved to `0px` from the serialized value
- Allow CSV to be the 'Z' component in interpolated value.
- Allow calcs with mixed percentages in the first two arguments.

To achieve the third item above the concept of a "special" value parsing
context has been added - this will also be useful for instance for
different arguments of color functions having different contexts.

Gains us 23 WPT tests
2025-08-08 09:45:00 +01:00
Callum Law
18d65b014f LibWeb: Add formatter for Web::CSS::ValueType
Currently unused but I found it useful for debugging
2025-08-08 09:45:00 +01:00
Callum Law
9bfd46ce31 LibWeb: Add formatter for Web::CSS::CSSStyleValue::Type
Currently unused but I found it useful for debugging
2025-08-08 09:45:00 +01:00
Callum Law
56b6987fd0 LibWeb: Use a macro for repetitive code in CSSStyleValue.{h,cpp}
This reduces the number of places we need to touch when creating a new
type
2025-08-08 09:45:00 +01:00
Edwin Hoksberg
ef9a3a2327 LibWeb: Import serial idl harness wpt tests 2025-08-08 10:23:17 +02:00
Edwin Hoksberg
1be31c103f LibWeb: Stub WebSerial API 2025-08-08 10:23:17 +02:00
Andreas Kling
34ec33d71c LibWeb: Don't treat SVG "use clone" removals as "use source" removals
We were failing to discriminate between DOM removals happening to SVG
elements cloned as part of an SVG use element instantiation.

When a "use source" element is removed, all clones of that source must
be updated to reflect the change. But when a "use clone" element is
removed, that's fine.

This was causing the surprising disappearance of use element subtrees,
seen for example on https://cal.com/
2025-08-07 22:15:36 +02:00
Andreas Kling
42802b0785 LibWeb: SVG use element shadow roots should be closed, not open
This goes against the spec but matches all other browser engines.
2025-08-07 22:15:36 +02:00
Andreas Kling
1402c143a9 LibWeb: Add Internals.getShadowRoot(element)
This lets you access closed shadow roots from JavaScript, even though
they're not normally accessible to JavaScript. This can be used to poke
into UA shadow roots in tests.
2025-08-07 22:15:36 +02:00
Luke Wilde
59162342e6 LibWeb: Set LinkProcessingOptions' cryptographic_nonce_metadata
Fixes external CSS being blocked on https://beatsaver.com/, where they
have a `style-src` directive set to `'self' 'nonce-[value]'`

Relates to #5643, but does not make the website load.
2025-08-07 19:26:57 +02:00
Luke Wilde
1d57df6e26 LibWeb/CSP: Implement the sandbox directive 2025-08-07 19:24:39 +02:00
Luke Wilde
40bb50ac60 LibWeb: Parse and propagate the iframe sandbox attribute 2025-08-07 19:24:39 +02:00
Luke Wilde
a5e2fd2e12 LibWeb/CSP: Implement the webrtc directive 2025-08-07 19:24:39 +02:00
Luke Wilde
855e17529c LibWeb/CSP: Implement the report-to directive
This doesn't do anything by itself, the report a violation algorithm
will handle this directive itself.
2025-08-07 19:24:39 +02:00
Luke Wilde
ed0230bb93 LibWeb/CSP: Implement the report-uri directive
This doesn't do anything by itself, the report a violation algorithm
will handle this directive itself.
2025-08-07 19:24:39 +02:00
Jelle Raaijmakers
85ad99b98a LibWeb: Implement <feMerge> SVG filter 2025-08-07 16:41:12 +02:00
Jelle Raaijmakers
1377dba7af LibWeb: Implement <feOffset> SVG filter 2025-08-07 16:41:12 +02:00
Sam Atkins
89b59cb5c3 LibWeb/CSS: Implement env() as an arbitrary substitution function
Technically, env() should not be an ASF. (😱) This is why some tests
still fail - env() as specced is expected to have its syntax checked
fully at parse-time, whereas ASFs are not properly syntax-checked until
later. However, I think this approach was worth doing for a few reasons:

- env() behaves like an ASF otherwise. (It is replaced with a set of
  arbitrary component-values that are not known until computed-value
  time.)
- env() was defined before the ASF concept existed, so I strongly
  suspect it will be updated in the future to match that definition,
  with a couple of adjustments. (eg, env() is allowed in some extra
  places compared to var() and attr().)
- This was much quicker and easier to implement (under 3 hours in total)
  compared to the greater amount of work to implement a whole separate
  system just for env().
- Most of these tests are marked tentative, and the spec definition of
  env() is still somewhat in flux, so failing some is not a huge deal.

If in the future I turn out to be wrong on this, we can convert it to
its own special thing.
2025-08-07 16:38:29 +02:00
Sam Atkins
22e00451b9 LibWeb/DOM: Add ability to query Document for environment variables
Currently this returns them in ComponentValue form, as that's what's
needed by env().
2025-08-07 16:38:29 +02:00
Sam Atkins
7b30c94fcf LibWeb+CodeGenerators: Generate EnvironmentVariable enum and functions 2025-08-07 16:38:29 +02:00
Sam Atkins
b03e829a49 Tests: Import WPT tests for CSS env() 2025-08-07 16:38:29 +02:00
Sam Atkins
5808eff1f4 LibWeb/CSS: Hyphenate request-url-modifier names
Corresponds to e1bf92d49a

Also update our imported WPT tests.
2025-08-07 13:38:25 +01:00
Sam Atkins
24f4356c3f LibWeb/CSS: Specify behavior for OOB CSSStyleDeclaration::item()
Corresponds to 56ed462ccd

We already did the right thing.
2025-08-07 14:29:17 +02:00
zac
6602fa5d15 UI/Qt: Add Alt+D as a shortcut to focus the location editor 2025-08-07 07:01:22 -04:00
Timothy Flynn
f3c3213b06 Meta: Add a ladybird.py command to profile a process
Works basically the same as the debug command. This command uses
callgrind for now, which matches LibWebView/HelperProcess.cpp.
2025-08-07 06:57:26 -04:00
Timothy Flynn
11f4b9c6ae Meta: Resolve pyright warnings in ladybird.py and helpers 2025-08-07 06:57:26 -04:00
Aliaksandr Kalenik
564003b22a LibWeb: Mark width & height of grid item definite before inside layout
FFC expects parent formatting context to mark size as definite if that's
the case, because otherwise it cannot figure cross line size correctly.
Fixes incorrect alignment when FFC is nested in GFC.

Progress on https://web.telegram.org/a/ layout.
2025-08-07 09:34:16 +02:00
EvoPot
4786eaf6be Documentation: Fix capitalization of "Windows" 2025-08-06 21:17:49 -06:00
Jelle Raaijmakers
7162c73b6c LibWeb: Add SVGUnitTypes
The empty `.h` is required since our generated bindings currently always
try to include one.
2025-08-06 23:05:56 -04:00
ayeteadoe
688d0ada97 Tests/LibCore: Enable TestLibCoreStream in Windows CI 2025-08-06 20:24:38 -06:00
ayeteadoe
e01a95f6cd LibCore: Implement UDPSocket::connect() on Windows 2025-08-06 20:24:38 -06:00
ayeteadoe
ba15348d56 LibCore: Implement PosixSocketHelper::pending_bytes() on Windows 2025-08-06 20:24:38 -06:00
ayeteadoe
4d68d28e16 LibCore: Implement PosixSocketHelper::set_receive_timeout() on Windows 2025-08-06 20:24:38 -06:00
ayeteadoe
79594279da LibCore: Make TCPServer::set_blocking() unsupported on Windows
Winsock2 doesn't seem to support blocking sockets, or at least
not in the naiive way.
2025-08-06 20:24:38 -06:00
ayeteadoe
d236e1a509 LibCore: Implement LocalServer on Windows 2025-08-06 20:24:38 -06:00
ayeteadoe
6e7565766d LibCore: Implement LocalSocket::connect() on Windows 2025-08-06 20:24:38 -06:00
ayeteadoe
904f736b95 LibCore: Implement UDPServer on Windows 2025-08-06 20:24:38 -06:00
ayeteadoe
cc3cabc768 LibCore: Implement TCPServer on Windows 2025-08-06 20:24:38 -06:00
ayeteadoe
9d7971c111 Tests/LibCore: Enable several tests in Windows CI
These are the set of tests that were already building and passing
with little to no modifications required.
2025-08-06 20:24:38 -06:00
Timothy Flynn
cd15b1a2c9 LibJS: Use AK's number parsing over stroul in JS::Token
This gives us a drop-in replacement for UTF-16 strings.
2025-08-07 02:05:50 +02:00
Timothy Flynn
20995c620f LibJS: Remove MarkupGenerator
It is unused.
2025-08-07 02:05:50 +02:00
Timothy Flynn
298ec6a12a AK: Ensure StringBuilder encodes U+10000 as 2 UTF-16 code units 2025-08-07 02:05:50 +02:00
Timothy Flynn
1b611fba67 AK: Ensure Utf16FlyString is hash-compatible with Utf16View/Utf16String 2025-08-07 02:05:50 +02:00
Timothy Flynn
274f8ee462 AK: Make hashing of UTF-16 strings cheaper
No need to iterate every byte of the string, we can iterate the code
units instead.

We must also actually record that we have cached the hash :^)
2025-08-07 02:05:50 +02:00
Timothy Flynn
73154defa8 AK: Allow implicitly constructing a Utf16View from a Utf16FlyString
The same already works for String and FlyString into StringView, and for
Utf16String into Utf16View.
2025-08-07 02:05:50 +02:00
Timothy Flynn
1bc80848fb AK+LibWeb: Add a UTF-16 starts/ends with wrapper for a single code unit 2025-08-07 02:05:50 +02:00
Timothy Flynn
7082cafdbc AK: Add a UTF-16 replacement wrapper to replace a single code unit
Just for convenience for interop with existing code.
2025-08-07 02:05:50 +02:00
Timothy Flynn
9e0b1bdfca AK: Add a parameter to to_number methods to change the parsed base
This just forwards through to AK::parse_number.
2025-08-07 02:05:50 +02:00
Timothy Flynn
bbda6d13f7 AK: Add a Utf16View method to retrieve an iterator at a code unit offset 2025-08-07 02:05:50 +02:00
Luke Wilde
4aa355658f LibWeb/CSP: Implement the base-uri directive 2025-08-07 00:45:31 +02:00
Luke Wilde
febe4fdb46 LibWeb/CSP: Implement the frame-ancestors directive 2025-08-07 00:45:31 +02:00
Luke Wilde
f9247116b1 LibWeb/CSP: Implement the form-action directive 2025-08-07 00:45:31 +02:00
InvalidUsernameException
6c4483fe0e LibWeb/CSS: Serialize mask shorthand-property properly 2025-08-06 23:09:07 +01:00
InvalidUsernameException
39b64c9b5c LibWeb/CSS: Parse mask shorthand-property into longhands
This commit regresses a couple tests related to the mask shorthand
property. This is because we now parse the longhands but there are
errors related to serialization. Some of the failures are fixed again in
the next commit. However, for some animation tests this is not the case.
Those failures were simply masked by the fact that we did not parse the
property correctly.
2025-08-06 23:09:07 +01:00
InvalidUsernameException
5fca78e0f9 LibWeb/CSS: Parse mask-image property with multiple values 2025-08-06 23:09:07 +01:00
InvalidUsernameException
f953196cb4 LibWeb/CSS: Parse mask-clip property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
eea6792cf7 LibWeb/CSS: Parse mask-origin property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
866e12f688 LibWeb/CSS: Parse mask-size property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
7c5f1a93ed LibWeb/CSS: Parse mask-repeat property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
add3a095d8 LibWeb/CSS: Rename background-repeat related symbols to align with spec
These will be used for the mask-repeat property as well in an upcoming
commit, hence the more generic names. Also, this more closely matches
the names used in the spec.
2025-08-06 23:09:07 +01:00
InvalidUsernameException
667f195d1e LibWeb/CSS: Parse mask-position property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
d022eea9fc LibWeb/CSS: Parse mask-mode property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
22d7a58998 LibWeb/CSS: Parse mask-composite property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
d51f46a0f7 Tests/LibWeb: Import tests for mask property and longhands 2025-08-06 23:09:07 +01:00
Aliaksandr Kalenik
e3aa3016bf LibWeb: Correctly calculate grid item size while accommodating fr track
Implements text from grid layout specification.
Improves layout on https://cal.com/
2025-08-06 22:42:07 +02:00
Edwin Hoksberg
6d954b73f1 LibWeb: Fix IDL codegen for dictionary return type with optional members 2025-08-06 16:34:44 -04:00
Bernard Niset
02b5ab385a Meta: Generate correct format for user-variables.cmake 2025-08-06 16:32:15 -04:00
ahl-trifork
e534395243 LibIDL: Parse extended attributes before required keyword 2025-08-06 18:18:24 +01:00
Callum Law
04ac06f3c4 LibWeb: Absolutize CursorStyleValues in StyleComputer::absolutize_values 2025-08-06 17:44:12 +01:00
Callum Law
c49afd7b28 LibWeb: Absolutize LengthPercentage members of BorderRadiusStyleValues 2025-08-06 17:44:12 +01:00
Callum Law
315f811d69 LibWeb: Absolutize BackgroundSizeSVs in StyleComputer::absolutize_values 2025-08-06 17:44:12 +01:00
Callum Law
70cb8d23fb Tests: Import/create tests related to absolutization of StyleValues
Done in a separate commit to show progress
2025-08-06 17:44:12 +01:00
Callum Law
c8bd58c0ba LibWeb: Add method to absolutize CalculatedOr 2025-08-06 17:44:12 +01:00
Callum Law
0df9c225aa LibWeb: Add method to absolutize PercentageOr 2025-08-06 17:44:12 +01:00
Callum Law
ba4a57b34d LibWeb: Absolutize StyleValueList in StyleComputer::absolutize_values 2025-08-06 17:44:12 +01:00
Callum Law
a2ceed27e2 LibWeb: Absolutize CalculatedSVs in StyleComputer::absolutize_values 2025-08-06 17:44:12 +01:00
Callum Law
9db3c66a85 LibWeb: Use correct font size when absolutizing animated properties 2025-08-06 17:44:12 +01:00
Callum Law
011ab5f714 LibWeb: Use correct SerializationMode when serializing CalculatedOr 2025-08-06 17:44:12 +01:00
Callum Law
a5cbcaf698 LibWeb: Use correct SerializationMode when serializing PercentageOr 2025-08-06 17:44:12 +01:00
Andreas Kling
74722cc499 LibWeb: Use the soon-to-be hovered element for tooltip notifications
Instead of the currently hovered element.
2025-08-06 17:26:18 +01:00
Callum Law
a44e28fd56 LibWeb: Avoid premature creation of CSSPixels in calc simplification
Previously we were converting lengths to CSSPixels values when we didn't
need to, this had a couple of effects in that:
 - We rounded to CSSPixel resolution prematurely (sometimes giving
   incorrect results)
 - We converted NaN to 0 when we shouldn't have.

We now avoid prematurely converting lengths to CSSPixels values in two
places:
 - `CalculationResult::from_value`
 - `CalculatedStyleValue::resolve_length_deprecated` (the new method
   already avoided rounding).

Gains us 16 WPT tests.
2025-08-06 14:57:34 +01:00
Callum Law
3fa7bc1919 LibWeb: Simplify calc products including unresolved percentages 2025-08-06 14:53:22 +01:00
Callum Law
c3b1013018 LibWeb: Skip inverted non-canonical values when simplifying product node
This matches the logic with the non-inverted children.

Gains us 2 WPT tests.
2025-08-06 14:53:22 +01:00
Jelle Raaijmakers
cd1cf75f7b LibWeb: Unbreak SVGFilterElement compilation
This was caused by an undetected merge conflict.
2025-08-06 15:47:44 +02:00
Tim Ledbetter
1dd3608960 LibWeb/SVG: Apply SVGFeBlendElement blend mode
Previously, the blend mode was always assumed to be `normal`.
2025-08-06 15:21:03 +02:00
Tim Ledbetter
22225af994 LibGfx: Reorder CompositingAndBlendingOperator values
This change aligns blending operator values with the constants in
`SVGFEBlendElement`.
2025-08-06 15:21:03 +02:00
Jelle Raaijmakers
3d613a2ac4 LibWeb: Simplify SVGFilterElement::gfx_filter()
No functional changes.
2025-08-06 14:00:31 +01:00
Jelle Raaijmakers
400a36aac1 LibWeb: Warn about unknown SVG filters
This might give some debug noise, but it's better than remaining silent.
2025-08-06 14:00:31 +01:00
Sam Atkins
9b6c26e347 Tests: Include test URL in fuzzy mismatch reports
The test logs tend to get a bit mixed together, so this makes it
possible to identify which values correspond to which test when multiple
are failing at once.
2025-08-06 13:51:36 +02:00
Sam Atkins
75046857ce Tests: Report image differences on tests with no fuzzy config defined
This can be helpful for identifying what the fuzzy config should be for
new tests.
2025-08-06 13:51:36 +02:00
Sam Atkins
90b49b9015 Tests: Report what the fuzzy configuration parsing error was 2025-08-06 13:51:36 +02:00
Sam Atkins
9889710033 Tests: Allow whitespace around fuzzy-matching configurations
Several WPT tests have a space after the semicolon, for example
https://wpt.live/css/css-images/gradient/gradient-single-stop-001.html :

```
<meta name="fuzzy" content="maxDifference=0-1; totalPixels=0-6000">
```
2025-08-06 13:51:36 +02:00
Andreas Kling
28c1dd551b LibWeb: Don't let aspect-ratio influence size definiteness
As it turns out, we still have to let the formatting contexts do a bit
of layout work in order to correctly apply the aspect-ratio. Hence we
can't just implicitly transfer definiteness from one size to the other.

This is a revert of 1cfd8b3ac0.
2025-08-05 21:33:41 +02:00
Andreas Kling
41e8211405 LibWeb: Honor "should treat as auto" cases in aspect-ratio decisions 2025-08-05 21:33:41 +02:00
Aliaksandr Kalenik
1201447dfe WebContent: Delete unused PageClient::layout_root() 2025-08-05 17:24:34 +02:00
Aliaksandr Kalenik
7a34bc2700 LibWeb: Re-evaluate media queries only when things they depend on change
Before this change we were re-evaluating media queries on every frame
which adds up in 1-4% in profiles on Discord.
2025-08-05 17:24:34 +02:00
Timothy Flynn
3920194bca LibJS: Move regulating and balancing logic into ISODateSurpasses
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/eddb77f
2025-08-05 11:18:08 -04:00
Timothy Flynn
a95d3e2a5e LibJS: Split ISO and non-ISO Temporal calendar operations
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/47042f2
2025-08-05 11:18:08 -04:00
Timothy Flynn
6d1f90c739 AK: Remove now-unused UTF-16 length from UTF-8 string helper 2025-08-05 15:13:36 +02:00
Timothy Flynn
04d32deb52 LibWeb: Port SVGFormattingContext to UTF-16 2025-08-05 15:13:36 +02:00
Timothy Flynn
d893d3234d LibGfx: Support UTF-16 SVG text placement 2025-08-05 15:13:36 +02:00
Timothy Flynn
2dc0a3b3ce AK: Add trim methods to Utf16String that skip allocation when not needed
If the string does not begin with any of the provided code units, we do
not need to create a new string.
2025-08-05 15:13:36 +02:00
Timothy Flynn
0efa98a57a LibJS+LibWeb+WebContent: Port JS::PropertyKey to UTF-16
This has quite a lot of fall out. But the majority of it is just type or
UDL substitution, where the changes just fall through to other function
calls.

By changing property key storage to UTF-16, the main affected areas are:
* NativeFunction names must now be UTF-16
* Bytecode identifiers must now be UTF-16
* Module/binding names must now be UTF-16
2025-08-05 07:07:15 -04:00
Timothy Flynn
cd276235d7 AK: Add a couple of validation-skipping UTF-16 string factories
String and FlyString are known to be valid UTF-8, so we can skip
validation when constructing a UTF-16 string from them.
2025-08-05 07:07:15 -04:00
Timothy Flynn
782f8c381c AK: Implement the spaceship operator for UTF-16 strings 2025-08-05 07:07:15 -04:00
Timothy Flynn
5af99f4dd0 AK: Allow Utf16StringBase to hold null data
This is required by JS::PropertyKey. This will also be needed when we
implement an Optional<Utf16String> specialization.
2025-08-05 07:07:15 -04:00
Timothy Flynn
0bf565b97f AK: Allow comparing UTF-16 strings to UTF-8 strings
Before now, you could compare a Utf16View to a StringView, but it would
only be valid if the StringView were ASCII. When porting code to UTF-16,
it will be handy to have a code point-aware implementation for non-ASCII
StringViews.
2025-08-05 07:07:15 -04:00
Timothy Flynn
319e7aa03b AK: Do not replace lonely surragates with U+FFFD while iterating
Utf8View doesn't do this either. The wobbly format is expected by JS.
2025-08-05 07:07:15 -04:00
Callum Law
a70a397501 LibWeb: Support percentages in word-spacing
Fixes crash in the created test as well as https://wpt.live/css/css-text
/word-spacing/reference/word-spacing-percent-001-ref.html. The WPT test
hasn't been imported as it passing is currently a false-positive due to
the fact that we don't yet respect `word-spacing` in most cases.
2025-08-05 11:43:55 +01:00
Jelle Raaijmakers
62cf33b98e LibGfx: Remove WebP animation writer and utility
This went unused.
2025-08-05 11:30:20 +02:00
Andreas Kling
b60d465029 LibWeb: Defer updating hovered node until end of mouse event handling
Updating the hovered node may fire events, and so we can't assume the
layout and paintable nodes we've found via hit testing will be valid
after doing it.
2025-08-05 11:29:45 +02:00
Andreas Kling
7e06906157 LibWeb: Use GC::Ptr more instead of raw pointers in EventHandler
Gives us nicer stack traces in debug builds.
2025-08-05 11:29:45 +02:00
Sam Atkins
e0c851b736 Tests/LibWeb: Generate screenshot test boilerplate in add_libweb_test.py
Creating the image is left as an exercise to the user, but this saves
some copypasta when adding a new test.
2025-08-05 09:59:47 +01:00
Idan Horowitz
110136b862 LibCrypto: Convert SignedBigInteger::import_data to accept Bytes
This brings it up to par with UnsignedBigInteger.
2025-08-05 09:08:56 +02:00
Idan Horowitz
b0fdbe3756 LibCrypto: Convert UnsignedBigInteger::import_data to accept Bytes
All the callers are already using Bytes and manually converting to the
old style pointer + length when calling this API.
2025-08-05 09:08:56 +02:00
Idan Horowitz
2a3b072d0e LibCrypto: Convert SignedBigInteger::export_data to return a span
This brings it up to par with UnsignedBigInteger.
2025-08-05 09:08:56 +02:00
Idan Horowitz
660a499223 LibCrypto: Convert UnsignedBigInteger::export_data to return a span
This helps make callers only use the slice of the output buffer that
was written to.

As part of updating the callers of the API several bugs were fixed and
useless code paths were removed:
- The exported data is not host-endianess dependent (always big endian)
- The exported data does not contain leading zeros
- The output buffer is only written up to the result's size
2025-08-05 09:08:56 +02:00
Callum Law
15cee5cc15 LibWeb: Correctly round non-integer z-indexes
Previously we would just cast to an int.

Gains us 3 WPT tests.
2025-08-05 06:37:40 +01:00
Tim Ledbetter
9a5b740da1 LibWeb: Remove unnecessary debug logging from SVGSVGElement 2025-08-05 01:46:36 +02:00
Idan Horowitz
e2fe46065a LibWeb: Remove extraneous trailing '/' from service worker script scope
The spec language specifies 'Set maxScopeString to "/", followed by the
strings in XXXX’s path (including empty strings), separated from each
other by "/"': That is, adjacent components are separated by a '/', but
the last component does not get a trailing '/'.

This resulted in the generated scope string ending with '//' in some
cases, incorrectly tripping the 'Service-Worker-Allowed' security check
2025-08-05 00:37:53 +02:00
Sam Atkins
56852fb5c2 LibWeb/CSS: Set style sheet for children of ContentStyleValue
Without this, any relative url()s in the `content` property don't know
what style sheet they are in, which makes them load relative to the
document instead.
2025-08-05 00:35:03 +02:00
Idan Horowitz
aeb7b442d3 LibWeb: Add initial support for bitmap cropping to createImageBitmap 2025-08-04 23:39:11 +02:00
Idan Horowitz
e81c33da42 LibGfx: Skip manual cropping for the degenerate case 2025-08-04 23:39:11 +02:00
Idan Horowitz
3c3da1ce8c LibGfx: Allow specifying outside color in Bitmap::cropped()
This is required for LibWeb bitmap cropping.
2025-08-04 23:39:11 +02:00
Idan Horowitz
bf2dc77dfc LibGfx: Remove unused new bitmap format option from Bitmap::cropped() 2025-08-04 23:39:11 +02:00
ayeteadoe
da2969008b CI: Enable compiler cache for Windows 2025-08-04 22:05:47 +02:00
Sam Atkins
e4b2e7b131 LibWeb: Remove now-unnecessary hack from preferred_color_scheme() 2025-08-04 14:01:00 +02:00
Sam Atkins
b06d2370c1 UI/Qt: Initialize BrowserWindow fields
Initializing m_current_screen may not be necessary, but the initial
value of m_preferred_color_scheme is sent to WebContent, so failing to
give it an initializer would cause bugs.
2025-08-04 14:01:00 +02:00
Callum Law
344d6199da LibWeb: Use correct colors for SVGFEFloodElement::flood_color
Previously we would always render floods as black, we now use the
computed color.

We also now support relative lengths within any `calc`s present.
2025-08-04 11:29:05 +01:00
Callum Law
3b52b1139a LibWeb: Support relative lengths in stop-color calcs 2025-08-04 11:29:05 +01:00
Callum Law
db439d224a LibWeb: Support creating ColorResolutionContext from AbstractElement
No functionality changes.
2025-08-04 11:29:05 +01:00
Callum Law
e0e00220fe LibWeb: Handle Auto resolution within Page::preferred_color_scheme
Handling this here means we don't have to it within individual callers
2025-08-04 11:29:05 +01:00
Callum Law
a19a6deaa4 LibWeb: Take a ColorResolutionContext in color_or_fallback
Taking a ColorResolutionContext directly instead of creating one from a
layout node allows us to call this from places where we don't have a
layout node.
2025-08-04 11:29:05 +01:00
Callum Law
46153910ec LibWeb: Update to_color to take ColorResolutionContext
Using a generic context argument will allow us to resolve colors in
places where we have all the required information but not in the form of
a layout node as was expected previously.
2025-08-04 11:29:05 +01:00
Callum Law
b0508fb39a LibWeb: Move CSS::CalculationResolutionContext to its own file
This struct will be used within CSSStyleValue.h in a future commit and
having it in CalculatedStyleValue.h causes a dependency loop.
2025-08-04 11:29:05 +01:00
norbiros
7dc41b52db LibWeb/CSS: Use proper parsing_params in CSS.registerProperty 2025-08-04 11:08:46 +01:00
norbiros
190745fd58 LibWeb/CSS: Parse initial value using syntax from @property
Now we pass all WPT tests in:
`css/css-properties-values-api/at-property-cssom`.

Note: Failing tests were false positives.
Proper handling of inheriting values and detecting computational
independence will be done in another PR.
2025-08-04 11:08:46 +01:00
Sam Atkins
31536c53a2 UI/AppKit: Add "Dump CSS Errors" menu item 2025-08-04 10:50:09 +01:00
Sam Atkins
d65d46f4f0 UI/Qt: Add "Dump CSS Errors" menu item
Dumps out any CSS errors that have appeared since launch.
2025-08-04 10:50:09 +01:00
Sam Atkins
1adddb158a WebContent+LibWeb/CSS: Add debug request to dump CSS errors 2025-08-04 10:50:09 +01:00
Sam Atkins
01661503b9 LibWeb/CSS: Remove unused Debug.h include from GradientParsing.cpp 2025-08-04 10:50:09 +01:00
Sam Atkins
dc91688f18 LibWeb/CSS: Use ErrorReporter for property/descriptor parsing errors 2025-08-04 10:50:09 +01:00
Sam Atkins
cebdcd9f69 LibWeb/CSS: Use ErrorReporter for value-parsing errors
Also remove some redundant reporting for `<urange>` parsing errors.
2025-08-04 10:50:09 +01:00
Sam Atkins
3b7aa736e7 LibWeb/CSS: Use ErrorReporter for media query parsing 2025-08-04 10:50:09 +01:00
Sam Atkins
1a599ceb98 LibWeb/CSS: Reject @font-face and margin rules that have a prelude
I couldn't find any WPT coverage for this, so here's a homemade test.
2025-08-04 10:50:09 +01:00
Sam Atkins
e072ddfebd LibWeb/CSS: Use ErrorReporter for rule-parsing errors
Unfortunately we already have an InvalidRuleError type defined in the
CSS Parser, so it has to be qualified here, at least for now.
2025-08-04 10:50:09 +01:00
Sam Atkins
0bd83dd996 LibWeb/CSS: Use ErrorReporter for "rule X not allowed in Y" errors
QualifiedRule::for_each_as_declaration_list() now takes a rule_name, so
that the error message can actually be useful - we only know what a
qualified rule is by context.
2025-08-04 10:50:09 +01:00
Sam Atkins
d6cfd56ae6 LibWeb/CSS: Use ErrorReporter for selector parsing errors
Also removed the error reporting from parse_a_n_plus_b_pattern() as its
caller already reports that error.
2025-08-04 10:50:09 +01:00
Sam Atkins
2a2a1986cc LibWeb/CSS: Add dump_string() method to TokenStream
This is to support error reporting. It's not the most elegant way of
getting the source CSS, but it works.
2025-08-04 10:50:09 +01:00
Sam Atkins
012f4735a7 LibWeb/CSS: Introduce structured reporting for CSS errors
Instead of random dbgln_if(CSS_PARSER_DEBUG) messages, this lets us
report what kind of error it was. Repeated errors are combined instead
of spamming the console.

Ideally this would also record where the error occurred, but not yet.
2025-08-04 10:50:09 +01:00
Sam Atkins
b7a108d7cb LibWeb/CSS: Remove unused ParseError::InternalError 2025-08-04 10:50:09 +01:00
Sam Atkins
d55626dc32 LibWeb/CSS: Remove debug logging I left in by accident 2025-08-04 10:50:09 +01:00
Sam Atkins
d86bcc795d LibWeb/CSS: Remove duplicate error reporting for invalid descriptors
parse_descriptor_value() already logs this.
2025-08-04 10:50:09 +01:00
devgianlu
b068dd732d LibWeb/Crypto: Remove RSA-PSS key import FIXMEs after spec fix 2025-08-04 10:40:53 +02:00
devgianlu
667de49a6c LibWeb/Crypto: Remove clang-format style issues FIXMEs
These FIXMEs don't mean much. If you try to inline it, you'll see it's
broken. PR review will catch it.
2025-08-04 10:40:53 +02:00
devgianlu
d71b66239b LibWeb/Crypto: Remove support applicable specification TODOs
We have a bunch of TODO/FIXME about supporting applicable specifications
for algorithms that are not mentioned in the spec. There is no plan to
have any, there is nothing to do as of now.
2025-08-04 10:40:53 +02:00
devgianlu
6281175e86 LibWeb/Crypto: Use builtin base64 encoding/decoding padding options 2025-08-04 10:40:53 +02:00
Callum Law
8a4e9f571f LibWeb: Respect letter-spacing for last glyph of each chunk
Previously we would omit the letter spacing for the end glyph of each
chunk in a misguided attempt to conform to the spec's instruction that
we "really should not append letter spacing to the right or trailing
edge of a line", this behaviour can be removed entirely as other
browsers (Firefox, Chrome) don't implement it either.
2025-08-03 22:23:34 +02:00
Tim Ledbetter
1d9e4a6f62 LibWeb: Parse anchor() function for inset properties 2025-08-03 22:09:31 +02:00
Idan Horowitz
ba6b82464c LibWeb: Add initial support for SVGImageElement in createImageBitmap 2025-08-03 21:47:48 +02:00
Idan Horowitz
bb6855c849 LibWeb: Add a getter for the default image bitmap of SVGImageElement
The default image bitmap is the first frame for animated bitmaps, and
the only frame for non-animated bitmaps.
2025-08-03 21:47:48 +02:00
Idan Horowitz
3b8ccf4d77 LibWeb: Add initial support for HTMLImageElement in createImageBitmap 2025-08-03 21:47:48 +02:00
Idan Horowitz
cc0496284b LibWeb: Add a getter for the default image bitmap of HTMLImageElement
The default image bitmap is the first frame for animated bitmaps, and
the only frame for non-animated bitmaps.
2025-08-03 21:47:48 +02:00
Idan Horowitz
9b11e0051c LibWeb: Support ImageBitmapOptions's resize{Width,Height} fields 2025-08-03 21:47:48 +02:00
Michael Manganiello
7fed49ea5c LibWeb: Fix local storage type in Window::local_storage()
The storage type was being incorrectly set to Session instead of Local,
apparently because of copying the implementation from
`Window::session_storage()`.

Bug introduced in commit 2066ed2318
2025-08-03 19:23:09 +02:00
Tim Ledbetter
3e8ede5dc4 LibWeb: Remove HTMLImageElement::src()
This is no longer used.
2025-08-03 17:33:06 +02:00
Tim Ledbetter
4a1740f299 LibWeb: Ensure image context menu uses the correct image source
Previously, the value of the `src` tag would always be used as the
image source URL when requesting an image context menu, which may not
be correct if an image uses a `srcset` or has a parent picture tag.
2025-08-03 17:33:06 +02:00
Emmanuel Ferdman
d821af1f24 Base: Stop relying on const-ness not being enforced by LibJS 2025-08-03 05:37:34 -07:00
devgianlu
4e6da3b14a LibWeb/Crypto: Avoid double copies when create CryptoKeys 2025-08-03 04:52:35 -07:00
devgianlu
b4deae6abf LibWeb/Crypto: Add JWK alg attribute to Ed{448,25519} keys
Spec PR: https://github.com/WICG/webcrypto-secure-curves/pull/34
2025-08-03 04:52:35 -07:00
devgianlu
3a8984b255 LibWeb/Crypto: Add raw key length checks to {Ed,X}{448,25519} key import
Following the spec update we finally can add these checks.

Spec PR: https://github.com/WICG/webcrypto-secure-curves/pull/35
2025-08-03 04:52:35 -07:00
Aliaksandr Kalenik
41e3ddb7fa LibGfx+LibWeb: Remove aa_translation from StrokePath and FillPath
`aa_translation` is something we inherited from times when
AntiAliasingPainter was a thing. This change replaces it by applying
offset directly to path.
2025-08-03 10:42:33 +02:00
Aliaksandr Kalenik
a41d586117 LibWeb: Merge FillPathUsingPaintStyle and FillPathUsingColor
Use `Variant<PaintStyle, Gfx::Color>` in new `FillPath` instead of
duplicating two almost identical display list items.
2025-08-03 10:42:33 +02:00
Aliaksandr Kalenik
5c11a541d3 LibWeb: Merge StrokePathUsingPaintStyle and StrokePathUsingColor
Use `Variant<PaintStyle, Gfx::Color>` in new `StrokePath` instead of
duplicating two almost identical display list items.
2025-08-03 10:42:33 +02:00
Aliaksandr Kalenik
e41c85ec47 LibWeb: Replace DrawTriangleWave with StrokePathUsingColor
There's no need to have separate display list item for drawing triangle
wave when we could simply use StrokePathUsingColor. By switching to
StrokePathUsingColor we could also reduce painting because it supports
filtering out by bounding box.
2025-08-03 10:42:33 +02:00
Glenn Skrzypczak
3dd8b3230e LibWeb/HTML: Only include direction if dirname applies
This commit changes form data to only include the direction of auto
directionality form associated elements.
2025-08-02 18:27:35 +01:00
Glenn Skrzypczak
c5fc4a5ac2 Meta: Download resources referenced in action attributes of forms
Resources referenced in the action attribute of forms now also get
downloaded by the WPT import script.
2025-08-02 18:27:35 +01:00
Timothy Flynn
50fed1d65c LibWeb+LibWebView+WebContent+UI: Port the document title to UTF-16 2025-08-02 10:10:14 -07:00
Timothy Flynn
13ed6aba71 AK+LibIPC: Implement an encoder/decoder for UTF-16 strings 2025-08-02 10:10:14 -07:00
Tim Ledbetter
e36df5ea0a LibWeb: Serialize background-size auto correctly
When `background-size` is `auto` in both axes, the `auto` value is no
longer repeated.
2025-08-02 08:51:23 +02:00
Tim Ledbetter
c4ceec9296 LibWeb: Avoid unnecessary copies of background size values 2025-08-02 08:51:23 +02:00
Michael Manganiello
e7654c2e08 LibWeb: Fix off-by-one offset error in NodeIterator forward traversal
As `node->parent()` was being called before comparing `node` with
`stay_within`, the code was incorrectly allowing traversal to the
parent node even when it should not have.

This change ensures that the parent is only checked after
confirming that the current node is not the `stay_within` node.

All `dom/traversal/NodeIterator.html` WPT tests get fixed after this
change.
2025-08-02 07:38:27 +02:00
Tim Ledbetter
f2682bb544 LibWeb: Use correct animation type for border-spacing
This follows the `css-tables` specification rather than the older CSS2
specification.
2025-08-01 15:18:17 +02:00
Tim Ledbetter
4c91b42dd2 LibWeb: Use shortest serialization for repeated style list values 2025-08-01 15:18:17 +02:00
Chase Knowlden
6b4e00bc39 LibCrypto: Implement Ed25519 Small Order Points 2025-08-01 14:31:44 +02:00
Jelle Raaijmakers
af8b256832 LibWeb: Avoid floats for BFC/FFC/GFCs with a definite width
Applicable FCs with an indefinite width simply shrink in their available
space as long as floats are intruding, but as soon as we have a definite
width we must push the box down until it it has enough space again.

Fixes #4136.
2025-08-01 14:26:12 +02:00
Jelle Raaijmakers
d27395cf1f LibWeb: Add spec links and text for BFC/FFC/GFC float intrusion behavior
No functional changes.
2025-08-01 14:26:12 +02:00
Jelle Raaijmakers
6c14e740f1 LibWeb: Remove tentative and contradictory BFC wrapping test
This tests is trying to see if we're taking into account the full margin
box width (75px - 50px) when determining whether there is enough space
to fit the BFC box. No major browser passes this test, and other tests
such as `css/CSS2/floats/new-fc-beside-float-with-margin.html` seem to
require that we ignore those margins.
2025-08-01 14:26:12 +02:00
Jelle Raaijmakers
525f609c9b LibWeb: Reuse display list command nesting level change for verification
No functional changes.
2025-08-01 14:20:51 +02:00
Jelle Raaijmakers
f28b7064ee LibWeb: Add indentation to display list dumps
Output display list dumps with an indentation level to show balanced
commands. It makes it much easier to see what is happening between e.g.
PushStackingContext and PopStackingContext, or SaveLayer and Restore.
2025-08-01 14:20:51 +02:00
Aliaksandr Kalenik
ffa6813b61 LibWeb: Delete unused DisplayListRecorder::display_list() 2025-08-01 13:00:41 +02:00
Aliaksandr Kalenik
5eef78bcd8 LibWeb: Remove params suffix from paint_{inner}outer_box_shadow 2025-08-01 13:00:41 +02:00
Aliaksandr Kalenik
b1c5026b81 LibWeb: Rename painter to recorder in DisplayListRecorderStateSaver 2025-08-01 05:25:56 -04:00
Aliaksandr Kalenik
aea9136239 LibWeb: Remove unnecessary state saving in SVGPathPaintable::paint()
Nothing in this function needs to save painter state.
2025-08-01 05:25:56 -04:00
Aliaksandr Kalenik
0a97de85c9 LibWeb: Move item no-op check from display list player to recorder
If item doesn't produce any output then let's skip appending it to the
display list.
2025-08-01 05:25:56 -04:00
Aliaksandr Kalenik
7d90d9d0a3 LibWeb: Rename m_command_list to m_display_list in DisplayListRecorder 2025-08-01 05:25:56 -04:00
Aliaksandr Kalenik
b265618bfb LibWeb: Rename Command to DisplayListCommand
Gives name more consistent with other display list related classes.
2025-08-01 05:25:56 -04:00
Aliaksandr Kalenik
61114f6d16 LibWeb: Rename PaintContext to DisplayListRecordingContext
PaintContext dates back to a time when display lists didn't exist and it
truly represented "paint context". Renaming it to better align with its
current role.
2025-08-01 05:25:56 -04:00
Aliaksandr Kalenik
1001ff2599 LibGfx+LibWeb: Delete unused PaintStyle::paint() implementations
These are unused since we moved to Skia and it's misleading to keep
them around.
2025-08-01 04:39:50 -04:00
Jelle Raaijmakers
0ce1571e71 LibWeb: Selecting an editing host should focus it
Unspecced but common behavior in the major browsers: if the selection
moves to an editing host, the editing host itself should become focused.
2025-08-01 10:09:26 +02:00
Jelle Raaijmakers
c9d4913bb4 LibWeb: Do not modify selection if editing host is already selected
If an editing host receives focus, we would always set a new selection
range. However, we only need to do that if we're not already part of the
active range. This corresponds to behavior shown by Chrome and Firefox.
2025-08-01 10:09:26 +02:00
Jelle Raaijmakers
8537f0fa82 UI/AppKit: Focus webview if URL was changed
When we manually enter a new URL and hit enter, the web view gets
focused. But when the URL changes for other reasons, such as starting
Ladybird with a URL argument, the location field was still focused.
2025-08-01 10:09:26 +02:00
Jelle Raaijmakers
0cab272f7f LibWeb: Change Editing::editing_host_of_node() to Node::editing_host()
No functional changes.
2025-08-01 10:09:26 +02:00
Luke Wilde
3f5bc023e2 LibWeb+WebContent+UI: Remove unused same-origin policy toggle
Page::is_same_origin_policy_enabled is unused, and the original FIXME
has been implemented.
2025-07-31 18:38:03 -04:00
Kemal Zebari
4e4026c89a LibWeb/MimeSniff: Update Rar signature to match spec 2025-07-31 16:21:20 +02:00
zac
068974732f LibWeb: Improve cursor appearance
`draw_rect` renders the outline of a rectangle.
`fill_rect` seems like a better option for rendering the cursor.
2025-07-31 13:06:56 +02:00
Tim Ledbetter
ca9364983c LibWeb/CSS: Support interpolating filter and backdrop-filter values 2025-07-30 23:29:07 +02:00
Andreas Kling
3b63582068 LibWeb: More thoroughly detach layout/paint trees from each other
Before committing a new layout (and thus building a new paint tree)
we now go through both the old paint tree and the layout tree and detach
them from each other.

This is a little extra work, but it ensures that there are no lingering
references across the trees, which we were apparently accumulating in
some cases on Discord, causing GC leaks.
2025-07-30 16:58:29 -04:00
Tim Ledbetter
138eabcf0d Meta: Ensure WPT repository exists before attempting to import tests
Previously, importing tests would fail if the WPT repository wasn't
already cloned.
2025-07-30 22:47:04 +02:00
Jelle Raaijmakers
3e4a1cbd55 LibWeb: Use ConservativeVector for recorded node values in Editing API
The `RecordedNodeValue` struct contains a `GC::Ref` to a DOM node, which
might disappear as a result of a garbage collection. For example, during
the "outdent" command, we record nodes, split the parent of those nodes
potentially resulting in all kinds of DOM changes, and then try to
restore the nodes' values. This caused a crash in the
`editing/run/outdent.html` WPT subtests.

By returning a `ConservativeVector`, we make sure the `GC::Ref` gets
marked during sweeps and nodes do not suddenly disappear.
2025-07-30 16:36:17 -04:00
Jelle Raaijmakers
c4f5e7bee3 LibWeb: Implement anchor-size(..) function parsing
This parses `anchor-size(..)` functions in CSS, but does not yet result
in a useful `Size`: we need style & layout interleaving similar to
container queries for this, since the resulting value depends on layout
results.

Not supported yet: `anchor-size()` appearing inside a `calc()` node.

Adds 4280 WPT subtest passes in `css/css-anchor-position`.
2025-07-30 18:13:59 +01:00
Jelle Raaijmakers
02598040ad LibWeb: Add CSS::Parser::parse_dashed_ident() 2025-07-30 18:13:59 +01:00
Tete17
ae3bda993a LibWeb: Add initial TrustedType WPT tests 2025-07-30 15:51:35 +01:00
Tete17
5a40115b86 LibWeb: Implement getAttributeType for TrustedTypePolicyFactory
This allows authors to check if Trusted Type is required for a given
Element's content attribute. This allows to pass the correct type
when they call to Element.setAttribute.
2025-07-30 15:51:35 +01:00
Tete17
8fdd9b68dc LibWeb: First implementation of the TrustedTypePolicyFactory
Most of the functions are either not implemented of filled with dummy
values.
2025-07-30 15:51:35 +01:00
Tete17
223b1cc704 LibWeb: Add barebones SVGAnimationElement class
Many wpt test on trusted-types relay on this class being defined to even
begin the test as it declares some event handlers.

This is not really an implementation but the most basic setup needed to
run the tests.
2025-07-30 15:51:35 +01:00
Andreas Kling
c4b13589e9 LibWeb: Make StyleComputer and FontLoader GC-allocated
This allows them to keep style sheets alive while loading fonts for
them. Fixes some GC crashes seen on the WPT WOFF2 tests after
66a19b8550 stopped FetchRecord leaks from
keeping various other things alive.
2025-07-30 16:35:08 +02:00
Jelle Raaijmakers
aa563706ca LibWeb: Rework AnimationTimeline's monotonically increasing property
Our previous implementation kept track of an AnimationTimeline being
monotonically increasing, by looking at new time values coming in and
setting `m_monotonically_increasing` to `false` whenever a new value
is before the previous known time value.

As far as I can tell, the spec doesn't really ask us to do so: it just
defines 'monotonically increasing' as a property of a timeline, i.e. it
guarantees that returned time values from `::current_time()` are always
greater than or equal to the last returned value.

This fixes a common crash seen when the last render opportunity lies
before the document's origin time, and `::set_current_time()` was
invoked with a negative value. This was especially visible in the
`Text/input/wpt-import/css/cssom/CSSStyleSheet-constructable.html` test.
2025-07-30 14:37:54 +02:00
Aliaksandr Kalenik
a3af7ca1a0 LibJS: Skip PrivateEnvironment allocation if possible
If class doesn't have any private fields, we could avoid allocating
PrivateEnvironment for it.

This allows us to skip thousands of unnecessary PrivateEnvironment
allocations on Discord.
2025-07-30 13:01:53 +02:00
Aliaksandr Kalenik
d1fbb7b51e LibWeb: Invalidate less elements affected by CSS custom properties
Before this change, whenever element's attributes changed, we would add
a flag to "pending invalidation", indicating that all descendants whose
style uses CSS custom properties needed to be recomputed. This resulted
in severe overinvalidation, because we would run invalidation regardless
of whether any custom property on affected element actually changed.

This change takes another approach, and now we decide whether
descendant's style needs to be recomputed based on whether ancestor's
style recomputation results in a change of custom properties, though
this approach adds a little overhead to style computation as now we have
to compare old vs new hashmap of custom properties.

This brings substantial improvement on discord and x.com where, before
this change, advantage of using invalidation sets was lost and we had
to recompute all descendants, because almost all of them use custom
properties.
2025-07-30 11:06:05 +02:00
Aliaksandr Kalenik
cbe4ba60c3 LibWeb: Implement faster equals() for UnresolvedStyleValue
Compare `Vector<Parser::ComponentValue>` directly instead of
serializing them into strings first.

This is required for the upcoming changes where we would compare
previous and new sets of custom properties to figure out whether we need
to invalidate descendant elements. Without this change `equals()` would
show up being hot in profiles.
2025-07-30 11:06:05 +02:00
Aliaksandr Kalenik
b1efd62ce6 LibWeb: Save more details about ASF presence in UnresolvedStyleValue
In the upcoming changes we would have to know specifically whether
`var()`, `attr()` or both are included in UnresolvedStyleValue.
2025-07-30 11:06:05 +02:00
Aliaksandr Kalenik
d47a22150d AK: Define operator== for HashMap 2025-07-30 11:06:05 +02:00
Tim Ledbetter
62e52163d6 LibWeb: Interpolate text-shadow values as a shadow list
This is the same behavior as is currently used for `box-shadow`.
2025-07-30 10:51:50 +02:00
Tim Ledbetter
3ae48776fd LibWeb: Round integral values to the nearest integer when interpolating
Previously, color components were being incorrectly rounded when
interpolating.
2025-07-30 10:51:50 +02:00
Aliaksandr Kalenik
3c3f1f9fad LibWeb: Don't capture proxy as root in ProxyConstructor::revocable
`revoker_closure` is used to construct `NativeFunction` that visits
`raw_capture_range()`, so there is no need to use GC root for `proxy`.
2025-07-30 08:43:53 +02:00
Andreas Kling
66a19b8550 LibWeb: Make ESO "fetch group" weakly reference the fetch records
Otherwise we end up holding on to every fetch record indefinitely.

Found by analyzing GC heap graphs on Discord.
2025-07-29 20:00:17 -04:00
Aliaksandr Kalenik
4cbf47dcd2 LibWeb: Unregister ResizeObserver from Document when it has no targets
According to the spec, `ResizeObserver` needs to live for as long as
it's referenced from script or has observation targets. With this change
we make sure that `ResizeObserver` is unregistered from the `Document`
when it has no target.

Fixes GC leak that caused us to keep all resize observers alive until
document they belong to is destroyed.
2025-07-30 00:54:57 +02:00
Aliaksandr Kalenik
40fd2643cc LibWeb: Don't visit DocumentShadowRootList from Document
`ShadowRoot` register itself in Document` from constructor and
unregister itself from `finalize()`. The problem is that `finalize()`
won't be invoked for as long as `ShadowRoot` is visited by
`Document`, leading to GC leaks.
2025-07-30 00:54:57 +02:00
Aliaksandr Kalenik
52b4f2a40a LibWeb: Don't visit registered document observers from Document
`DocumentObserver` register itself in Document` from constructor and
unregister itself from `finalize()`. The problem is that `finalize()`
won't be invoked for as long as `DocumentObserver` is visited by
`Document`. By not visiting registered observers from `Document` we
move this responsibility to object that allocated observer, which is
always exactly what we want, e.g. once `SVGUseElement` that uses
observer is gone, observer won't be visited anymore which will lead to
`finalize()` being called.
2025-07-30 00:54:57 +02:00
Grant Knowlton
9e1e4f3b15 AK: Validate compressed tags in IPv4-mapped IPv6 address
This disallows parsing IPv4 mapped IPv6 address strings with multiple
compression prefixes.  Tests are provided for the updated
functionality.
2025-07-30 00:53:10 +02:00
Andrew Kaster
cf355d48b1 CMake: Install AppStream metainfo file with absolute path
Fixes CMake install with a separate build directory breakage introduced
by 1b1eae4409
2025-07-29 11:31:12 +02:00
Jan Koudijs
1b1eae4409 Meta: Add a freedesktop appstream/metainfo manifest 2025-07-28 19:37:48 -06:00
Andreas Kling
81d4079c12 LibWeb: Support CSS content property images (and lists, too!)
This patch expands our generated content support beyond single strings
to lists of strings and/or images.

Pseudo-elements like ::before and ::after can now use content:url(...)
to insert anonymous image boxes into the layout tree.

This is heavily used in Google Docs for UI elements.
2025-07-28 22:46:27 +02:00
Andreas Kling
77abe2a84d LibWeb: Allow ImageProvider subclasses to visit additional GC edges
More prep work for CSS content:image.
2025-07-28 22:46:27 +02:00
Andreas Kling
0e94c4e270 LibWeb: Allow ImageProvider to not have a corresponding DOM node
This is prep work for CSS content:image.
2025-07-28 22:46:27 +02:00
Andreas Kling
9603aa0745 LibWeb: Allow Layout::ImageBox to be anonymous
This is prep work for CSS content:image, which means pseudo-elements can
be used to generate images without a corresponding DOM node.
2025-07-28 22:46:27 +02:00
Timothy Flynn
67cc02ab59 LibWeb+UI: Add an explicit IPC to handle mouse leave events
The faux position we created here is adjusted by the device pixel ratio
later on, which would invoke integer overflow on screens with a DPR
greater than 1.

Instead of creating special data for a mouse move event, let's just add
an explicit leave event handler.
2025-07-28 21:26:33 +02:00
Timothy Flynn
8600925713 LibWeb: Port HTMLElement innerText/outerText to UTF-16 2025-07-28 18:30:50 +02:00
Timothy Flynn
5c561c1a53 LibWeb: Port node text content to UTF-16 2025-07-28 18:30:50 +02:00
Timothy Flynn
27a4c1eaf6 LibWeb: Remove errant comment from HTMLElement::rendered_text_fragment
This became untrue in  a1a740bb3e.
2025-07-28 18:30:50 +02:00
Timothy Flynn
63bce2b78c LibWeb: Remove the ad-hoc strip_newlines method from HTMLSelectElement
This doesn't appear to be doing anything that the Infra method it calls
isn't already doing.
2025-07-28 18:30:50 +02:00
Timothy Flynn
d9502505c2 AK: Fix bounds assertions in Utf16View::iterator_offset 2025-07-28 18:30:50 +02:00
Timothy Flynn
67723ef83c AK: Add a method to peek ahead of a UTF-16 iterator 2025-07-28 18:30:50 +02:00
Timothy Flynn
21d7d236e6 AK: Add a method to check if a UTF-16 string contains any code point 2025-07-28 18:30:50 +02:00
Callum Law
8ada4b7fdc LibRegex: Account for opcode size when calculating incoming jump edges
Not accounting for opcode size when calculating incoming jump edges
meant that we were merging nodes where we otherwise shouldn't have been,
for example /.*a|.*b/.
2025-07-28 17:06:58 +02:00
Timothy Flynn
c8888609f4 LibWeb: Port the FormAssociatedElement value to UTF-16
This porting effort makes it pretty clear we will want a UTF-16-aware
GenericLexer. But for now, we can actually make ASCII assumptions about
what we are parsing, and act accordingly.
2025-07-28 12:25:11 +02:00
Timothy Flynn
e7b08cf291 LibWeb: Add a DOM::Element::set_attribute override for UTF-16 strings
This just transcodes to UTF-8 for now, but primarily serves to to keep
compatibility with generated IDL definitions.
2025-07-28 12:25:11 +02:00
Timothy Flynn
9d993143de LibJS: Implement a UTF-16 number-to-string converter 2025-07-28 12:25:11 +02:00
Timothy Flynn
f3146d3320 LibGfx: Implement a UTF-16 Color stringifier 2025-07-28 12:25:11 +02:00
Timothy Flynn
96e75a023b AK: Implement a UTF-16 UnixDateTime stringifier 2025-07-28 12:25:11 +02:00
Timothy Flynn
ed63a60247 AK: Return an empty optional when UTF-16 code unit lookup fails
Accidentally returned the wrong type here.
2025-07-28 12:25:11 +02:00
Timothy Flynn
baddac5155 AK: Implement a method to split a UTF-16 string 2025-07-28 12:25:11 +02:00
Timothy Flynn
48a3b2c28e AK: Implement a method to count instances of a needle in a UTF-16 string 2025-07-28 12:25:11 +02:00
Jelle Raaijmakers
b6732240c7 LibWeb: Avoid float intrusions for BFCs, FFCs and GFCs
We were only avoiding float intrusions for BFCs, but FFCs and GFCs
should also accommodate for any floats present.

Work towards #4136.
2025-07-28 12:13:06 +02:00
Jelle Raaijmakers
5a6a1074f7 LibWeb: Remove unused includes from FlexFormattingContext 2025-07-28 12:13:06 +02:00
Jelle Raaijmakers
ab3e9799d5 LibWeb: Allow negative margins to influence inline offset after float
In 89ba00304c, the box' X position was
capped at 0 to prevent negative X positions to act as if there were
intruding floats on the left side. Instead, we need to check whether the
left side float intrusion we are going to calculate matters at all -
because if there's no matching float box, the intrusion is always going
to be 0 and we don't need to take the box' X position into account.

Fixes the floating publication images on https://lexfridman.com/.
2025-07-28 12:11:56 +02:00
Arran Ireland
06ffe532c2 LibWeb: Ensure cast to double for double matrix 2025-07-28 09:15:23 +02:00
Arran Ireland
9a8599f265 LibGfx+LibMedia+LibWeb: Use new Matrix subscript operator 2025-07-28 09:15:23 +02:00
Arran Ireland
423e944a92 LibGfx+LibWeb: Upgrade to multi-arg subscript operator in Matrix
See the following for more details:
https://en.cppreference.com/w/cpp/language/operators.html#Array_subscript_operator
2025-07-28 09:15:23 +02:00
Tim Ledbetter
168ea88cb2 test-web: Add an option to randomize the test order 2025-07-28 09:01:56 +02:00
Rocco Corsi
d322c3a21f LibGfx: VulkanContext coverity reports integer_overflow on index
Coverity static analysis reports that the code that scans the queue
families for one that has the graphics bit, can be -1 if none are
found, which could cause a problem when the -1 (signed) value is
used later as an index in a uint32_t (unsigned) variable.

Its not immediately clear how often this could occur, not finding
a queue family with the graphics bit, but adding some protecting
just in case.
2025-07-27 23:38:49 -04:00
Timothy Flynn
bc4112bf18 UI: Inform WebContent when the mouse leaves the WebView widget
Previously, when the mouse left the WebView, the currently hovered node
would remain hovered (including the scroll bar). This felt a bit awkward
and is not how other browsers behave.
2025-07-27 23:38:00 -04:00
Abhinav
8303a558f1 LibWeb: Fix acceptable WebSocket close code range 2025-07-27 15:36:34 +02:00
Jelle Raaijmakers
ed94381209 LibWasm: Return canonical NaN for min/max/floor/ceil/truncate operations
Instead of returning whichever argument was NaN, return the canonical
NaN instead. The spec allows the old behavior:

  "Following the recommendation that operators propagate NaN payloads
   from their operands is permitted but not required."

But Chrome, Firefox and Safari do not propagate the operand payloads.

Fixes 448 WPT subtests in `wasm/core`.

Co-authored-by: Ali Mohammad Pur <ali.mpfard@gmail.com>
2025-07-27 15:35:28 +02:00
Aliaksandr Kalenik
a6857a6ce1 LibWeb: Log more useful information in display list dump 2025-07-27 10:20:18 +02:00
Aliaksandr Kalenik
789016841e LibWeb: Pass device_pixels_per_css_pixel into DisplayList constructor
Having a setter for `device_pixels_per_css_pixel` was confusing because
display lists are immutable, so it doesn't make sense to override this
value after the display list has been created.
2025-07-27 10:20:18 +02:00
Aliaksandr Kalenik
8e3a42c54e LibWeb: Delete unused is_fixed_position from PushStackingContextParams 2025-07-27 10:20:18 +02:00
Aliaksandr Kalenik
0e8d70d8c3 LibWeb: Rename draw_text_run to draw_glyph_run in DisplayListRecorder
For consistency with corresponding display list item name.
2025-07-27 10:20:18 +02:00
Andrew Kaster
64f1a76636 CMake: Ignore invalid offset of when generating Swift interop header 2025-07-26 23:33:58 +02:00
Andrew Kaster
7d669b8b0c AK: Update Swift test for Utf16String changes 2025-07-26 23:33:58 +02:00
Abhinav
93a0ef949a LibWeb: Update x25519 raw key import tests 2025-07-26 10:43:16 -06:00
Abhinav
ea8538ea49 LibWeb: Don't import raw X25519 key of incorrect length 2025-07-26 10:43:16 -06:00
Aliaksandr Kalenik
8569124b87 LibWeb: Fix scroll state refresh in cached display list for iframes
6507d23 introduced a bug when snapshot for iframe is saved in
`PaintNestedDisplayList` and, since display lists are immutable, it's
not possible to update before the next repaint.

This change fixes the issue by moving `ScrollStateSnapshot` for
nested display lists from `PaintNestedDisplayList` to
`HashMap<NonnullRefPtr<DisplayList>, ScrollStateSnapshot>` that is
placed into pending rendering task, making it possible to update
snapshots for all display lists before the next repaint.

This change doesn't have a test because it's really hard to make a ref
test that will specifically check scenario when scroll offset of an
iframe is advanced after display list is cached. We already have
`Tests/LibWeb/Ref/input/scroll-iframe.html` but unfortunately it did
not catch this bug.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/5486
2025-07-26 11:53:21 -04:00
Luke Wilde
124bdce99c UI/Qt: Set WC's max FPS to the refresh rate of the current screen 2025-07-26 10:09:12 -04:00
Luke Wilde
b0d97c991f UI/AppKit: Set WC's max FPS to the max FPS of the current screen 2025-07-26 10:09:12 -04:00
Luke Wilde
c93c30d596 LibWebView+WebContent: Make it possible to change the painting interval
This allows us to paint at the refresh rate of the screen. The default
is 60, as before, in case it never gets set by anything.
2025-07-26 10:09:12 -04:00
Luke Wilde
31faf31f6a LibCore: Unmark timer interval being dirty after applying new interval
Previously it was never unmarked, so the timer would constantly stop
and start, which made the timer jittery especially at small intervals.
2025-07-26 10:09:12 -04:00
Timothy Flynn
3a072f66e3 LibWeb: Pass Utf16String around directly in Editing APIs
Noticed while working adjacent to these APIs that we take a Utf16String
and pass it around as a Utf16View, only to re-allocate the Utf16String
in many commands. Let's just pass the string itself around.
2025-07-26 00:40:06 +02:00
Timothy Flynn
f001dbea30 LibWeb: Add missing includes to Editing/Commands.h
clangd is complaining loudly about these.
2025-07-26 00:40:06 +02:00
Timothy Flynn
2da615ed31 LibWeb: Port document.execCommand and InputEvent to UTF-16 2025-07-26 00:40:06 +02:00
Timothy Flynn
49467d0583 LibIDL+LibWeb: Support UTF-16 USVString 2025-07-26 00:40:06 +02:00
Timothy Flynn
1375e6bf39 AK+LibJS+LibWeb: Use simdutf to create well-formed strings 2025-07-26 00:40:06 +02:00
Timothy Flynn
017a6cc687 LibWeb+WebContent: Port FormAssociatedTextControlElement APIs to UTF-16 2025-07-26 00:40:06 +02:00
Timothy Flynn
cdf270a5e6 WebContent: Invert focus condition in WebDriver's Element Send Keys
The spec states we should inspect the relevant value if the element does
*not* have focus.
2025-07-26 00:40:06 +02:00
Timothy Flynn
c566cc5024 LibWeb: Invoke correct word-jumping method in EditingHostManager 2025-07-25 12:57:03 -04:00
Timothy Flynn
97548f48de LibWeb: Port rendered text to UTF-16
This migrates TextNode::text_for_rendering() to Utf16String and deals
with the fallout. As a consequence, this effectively reverts commit
3df83dade8.

The layout test expecation file updates are because we now express text
lengths and offsets in UTF-16 code units.

The selection-over-multiple-code-units expectation file update actually
represents a correctness fix. Our result now matches Firefox.
2025-07-25 18:16:22 +02:00
Timothy Flynn
a270706411 LibWeb: Port DOM::Range stringification to UTF-16 2025-07-25 18:16:22 +02:00
Timothy Flynn
8d17786b8c LibWeb: Add missing include to LineBoxFragment.h
This missing include is making clangd behave badly on this file.
2025-07-25 18:16:22 +02:00
Timothy Flynn
0e9b694058 LibGfx: Support UTF-16 text shaping
We can achieve this with templating the string view type, and then just
piping the view into the correct `hb_buffer_add_utf*` API.
2025-07-25 18:16:22 +02:00
Timothy Flynn
a740bfd8ff AK+LibUnicode: Implement Unicode-aware UTF-16 case transformations 2025-07-25 18:16:22 +02:00
Timothy Flynn
df77ae1920 AK: Implement creating a UTF-16 string from a repeated code point 2025-07-25 18:16:22 +02:00
Timothy Flynn
a46e9b2adb AK: Compute the correct capacity in StringBuilder::try_append_repeated
This was mistakenly broken in 2803d66d87.
2025-07-25 18:16:22 +02:00
Timothy Flynn
745f288796 AK: Implement a method to acquire a UTF-16 iterator's code unit offset
This is the same as Utf8View::iterator_offset().
2025-07-25 18:16:22 +02:00
mikiubo
acf1fe7b05 LibWeb: Return base Document for non-HTML parses
The HTML specification does not explicitly require
a specific return type for parseFromString(),
but according to Web Platform TestsDOMParser-parseFromString.html,
the expected return value for
XML MIME types is a Document—not an XMLDocument.
2025-07-25 10:08:29 -06:00
Jelle Raaijmakers
acc7c2f7f3 LibWeb: Do not use namespace in interface names
Gives us 20 additional WPT subtest passes in `wasm/jsapi`.
2025-07-25 16:50:45 +02:00
Jelle Raaijmakers
73967ee90c Everywhere: Use HashMap::update() where applicable 2025-07-25 16:22:06 +02:00
Jelle Raaijmakers
0b96690f0c AK: Add HashMap::update()
This updates a HashMap by copying another HashMap's keys and values.
2025-07-25 16:22:06 +02:00
Jelle Raaijmakers
76ee1ce04c LibWeb: Support wasm module instantiation using a global address
Fixes 1 WPT subtest in `wasm/core/simd`.
2025-07-25 15:35:27 +02:00
Jelle Raaijmakers
58c3a391a3 LibWeb+LibWasm: Reject module instantiation with correct error type
The spec tells us to reject the promise with a RuntimeError instead of a
LinkError whenever the module's start function fails during module
instantiation. Fixes 1 WPT subtest in `wasm/core`.
2025-07-25 15:13:28 +02:00
Jelle Raaijmakers
35ca7f82b0 LibWeb: Add BaseAudioContext::createScriptProcessor()
This is a deprecated node, but it's still widely used on the web.
2025-07-25 11:48:04 +02:00
Luke Wilde
da5fca15ee LibWeb: Only expose performance.{timing,navigation} on Window
They are only valid in a Window context, and the spec only exposes them
in Window contexts.

Fixes workers crashing on:
- https://web.whatsapp.com/
- https://pro.kraken.com/app/trade/btc-usd
2025-07-25 11:46:58 +02:00
Luke Wilde
bd51bc6874 LibIDL: Pass partial interface extended attributes onto its members 2025-07-25 11:46:58 +02:00
Tim Ledbetter
89fb783b42 LibWeb: Throw pre insertion validity errors from the correct global 2025-07-25 09:08:14 +02:00
Ali Mohammad Pur
c7ad6cd508 LibRegex: Use code unit length in more places that apply
Finishes what 7f6b70fafb started.
Having one part use length and another code unit length lead to crashes,
the added test ensures we don't mess that up again.
2025-07-24 23:09:01 +02:00
Andrew Kaster
97c8fdd042 Documentation: Add instructions on how to build the Flatpak 2025-07-24 14:25:03 -06:00
Aliaksandr Kalenik
66e1d599f8 LibWeb: Use scroll state from snapshot while applying clip rectangles
Fixes race condition introduced in eed47acb when rendering thread
accesses ScrollFrame that could be mutated in the middle of
rasterization by the main thread, resulting in broken rendering.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/5553
2025-07-24 13:03:23 -04:00
Timothy Flynn
8b6e3cb735 LibWeb+LibUnicode+WebContent: Port DOM:CharacterData to UTF-16
This replaces the underlying storage of CharacterData with Utf16String
and deals with the fallout.
2025-07-24 19:00:20 +02:00
Timothy Flynn
cb85eac3d8 LibIDL+IDLGenerators: Begin supporting UTF-16 strings in IDL
This adds a new IDL type, Utf16DOMString. This is the same as DOMString,
except it is UTF-16. This type is temporary - we will want DOMString to
be UTF-16 by default once we've ported enough of LibWeb.

To make this support easier, some string IDL generator handling is moved
directly into `generate_to_string` from the call sites.
2025-07-24 19:00:20 +02:00
Timothy Flynn
6c73dff120 AK: Implement a UTF-16 method to check if a string is ASCII whitespace 2025-07-24 19:00:20 +02:00
Timothy Flynn
f53389bab1 AK: Add a couple of Utf16String factories
* Utf16String::from_utf8_with_replacement_character
* Utf16String::from_code_point
2025-07-24 19:00:20 +02:00
Andreas Kling
b4435bd50c LibWeb: Don't clip descendants outside stacking context root rect
Skia allows you to pass a bounding rect to its saveLayer() function as
an optimization when you know that you won't paint outside those bounds.
Unfortunately, we were passing a too-small rectangle that didn't take
into account transformed descendants, etc.

For now, simply pass null instead of a bounding rect. This way, Skia
figures it out internally. It may allocate larger temporary bitmaps than
needed this way, but at least we get more correct results. I've left
re-enabling the optimization as a FIXME in the code.

This fixes unwanted clipping in various parts of the Discord UI.
2025-07-24 11:15:01 -04:00
Jelle Raaijmakers
b1c3ce807b AK: Rename Utf16View::trim_whitespace() to ::trim_ascii_whitespace()
This reflects the naming of String::trim_ascii_whitespace() and better
indicates what exactly we're trimming.
2025-07-24 07:18:25 -04:00
Jelle Raaijmakers
e029e785d2 LibWeb: Convert Editing API internals to UTF-16
Both sides of the Editing internals now have to deal with some awkward
converting between UTF-8 and UTF-16, but the upside is that it
immediately exposed an issue with the `insertText` command: instead of
dealing with code units, it was iterating over code points causing the
selection to be updated only once instead of twice. This resulted in the
final selection potentially ending up in between a surrogate pair.

Fixes #5547 (pasting/typing surrogate pairs).
2025-07-24 07:18:25 -04:00
Jelle Raaijmakers
9a03ee1c24 AK: Fix mention of renamed member in Utf16View 2025-07-24 07:18:25 -04:00
Jelle Raaijmakers
15178d5230 AK: Add ::ends_with() to Utf16View and Utf16StringBase
I noticed that we can significantly simplify ::starts_with(), and based
the new ::ends_with() on that.
2025-07-24 07:18:25 -04:00
Jelle Raaijmakers
7f8468b0e6 AK: Compare pointers in TypedTransfer<T>::compare()
We can return `true` quickly if the two pointers are identical.
2025-07-24 07:18:25 -04:00
Jelle Raaijmakers
54dd45d3f6 AK: Add Span::ends_with()
Originally I added this to use it in Utf16View::ends_with(), but the
final implementation ended up a lot simpler. I chose to keep this anyway
since it mirrors Span::starts_with().
2025-07-24 07:18:25 -04:00
Jelle Raaijmakers
a9862d60bf LibGfx: Add Color::from_utf16_string() 2025-07-24 07:18:25 -04:00
Jelle Raaijmakers
fd066d2b58 LibWeb: Update two stray "take the action for command" invocations
This is the more idiomatic (although functionally equivalent) way of
taking the action for any command.
2025-07-24 07:18:25 -04:00
aplefull
e2f8f5a350 LibRegex: Fix capture groups in quantified alternations
This prevents empty matches from overwriting non-empty captures in
quantified alternations. Fixes patterns like (a|a?)+ where the optional
branch would incorrectly overwrite meaningful captures with empty
strings.
2025-07-24 10:40:16 +02:00
Timothy Flynn
173bb67004 LibJS+LibUnicode: Port Intl.RelativeTimeFormat to UTF-16 strings 2025-07-24 10:39:52 +02:00
Timothy Flynn
abcb2d42bc LibUnicode: Port Intl.PluralRules to UTF-16 strings 2025-07-24 10:39:52 +02:00
Timothy Flynn
6fe0e13474 LibJS+LibUnicode: Port Intl.DurationFormat to UTF-16 strings 2025-07-24 10:39:52 +02:00
Timothy Flynn
e637e148d4 LibJS+LibUnicode: Port Intl.NumberFormat to UTF-16 strings 2025-07-24 10:39:52 +02:00
Timothy Flynn
db2148b44a LibJS+LibUnicode: Port Intl.ListFormat to UTF-16 strings 2025-07-24 10:39:52 +02:00
Timothy Flynn
7d80aabbdb LibJS+LibUnicode: Port Intl.DisplayNames to UTF-16 strings 2025-07-24 10:39:52 +02:00
Timothy Flynn
ee01f857d1 LibJS+LibUnicode: Port Intl.DateTimeFormat to UTF-16 strings 2025-07-24 10:39:52 +02:00
Timothy Flynn
b2f053e783 LibJS+LibUnicode: Port Intl.Collator to UTF-16 strings 2025-07-24 10:39:52 +02:00
Andrew Kaster
09c031fa96 CI: Add nightly flatpak workflow
This will build both aarch64 and x86_64 flatpaks nightly. The test jobs
I did with the default GitHub runners took ~1h30m for aarch64 and
~2h30m for x86_64, but this will hopefully improve over time as the
cache is built up. And be better time-wise on the blacksmith runners.

Disk space is a large concern with these flatpak builds. A naive script
on my local machine showed that we needed a max of 10.3 GiB of free
space for the x86_64 build, with clang as the compiler. For some reason,
building with default gcc 14 uses more disk space than that, bumping
up against the default 14 GiB free space limit guaranteed by GitHub for
their default runners.
2025-07-23 16:27:49 -06:00
Andrew Kaster
358a24b461 CI: Give Windows CI workflow a unique name
This should ™️ make it easier to identify the workflow in the
GitHub Actions UI pane on the website.
2025-07-23 16:27:49 -06:00
Aliaksandr Kalenik
c8b574e9b4 LibWeb: Remove animations from timeline in Element::removed_from()
`AnimationTimeline` visits pointers of all registered animations, so if
element is removed from DOM tree but its animations remain registered in
timeline, then `Animation` and owner `Element` will be kept alive until
`AnimationTimeline` is destroyed.
2025-07-23 17:50:01 -04:00
Andrew Kaster
85baf71d48 Meta: Use clang to build ladybird module in flatpak 2025-07-23 15:12:00 -06:00
Jan Koudijs
0c89b2e690 Meta: Add offline build for ANGLE flatpak module
At the same time, build with gcc instead of bundled clang.

Co-Authored-By: Andrew Kaster <andrew@ladybird.org>
2025-07-23 15:12:00 -06:00
Andrew Kaster
7d458103a8 Meta: Move skia and angle flatpak build scripts to their own directories 2025-07-23 15:12:00 -06:00
Andrew Kaster
35f65b8dab Meta: Bump version of gn flatpak source module to rev 2255 2025-07-23 15:12:00 -06:00
Andrew Kaster
738c81877c Meta: Move build of gn module in flatpak build before angle 2025-07-23 15:12:00 -06:00
Andrew Kaster
08221c2534 Meta: Skip build directories when building Ladybird module in flatpak
flatpak-builder doesn't respect .gitignore when creating its local build
directory, so we need to explicitly skip potentially large ignored
directories to avoid bloating the flatpak build directory during builds.
2025-07-23 15:12:00 -06:00
Timothy Flynn
b3d52a8238 LibJS: Compute offsetBehaviour in ToTemporalZonedDateTime after parsing
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/4b83ba3
2025-07-23 22:05:15 +02:00
Timothy Flynn
e95f225362 LibJS: Correctly disallow certain calendar-based Temporal strings
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/d83241f
2025-07-23 22:05:15 +02:00
Timothy Flynn
3f75cf270a LibJS: Move ambiguous Temporal time string handling to a separate parser
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/fa3d0b9
2025-07-23 22:05:15 +02:00
Timothy Flynn
7ca3598221 LibJS: Add new spec comments to ISO 8601 early-error handlers
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/f8489fb
2025-07-23 22:05:15 +02:00
Timothy Flynn
3b3ff6f057 LibJS: Split up the GetTemporalUnitValuedOption AO
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/fcdb47e
https://github.com/tc39/proposal-temporal/commit/ef04774
https://github.com/tc39/proposal-temporal/commit/2070032
https://github.com/tc39/proposal-temporal/commit/adf50d4
https://github.com/tc39/proposal-temporal/commit/40eaeb7
https://github.com/tc39/proposal-temporal/commit/aab7bee
https://github.com/tc39/proposal-temporal/commit/a10d38d
https://github.com/tc39/proposal-temporal/commit/06ce375
2025-07-23 22:05:15 +02:00
Timothy Flynn
1aee1a050e LibJS: Use consistent naming for this value in Temporal prototypes
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/ed49b0b
2025-07-23 22:05:15 +02:00
Timothy Flynn
0c5c6a9944 LibJS: Use consistent wording around NewTarget in Temporal constructors
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/e454171
2025-07-23 22:05:15 +02:00
Luke Wilde
a2f3a5a6ce LibWeb: Send a beforeinput event for pasting
This allows us to paste text into Discord.
2025-07-23 22:04:45 +02:00
Andreas Kling
8d02f28cc2 LibWeb: Don't treat non-replaced sizes as 0 for min-content contrib
This behavior is part of the cyclic percentage contribution logic from
CSS-SIZING-3 which explicitly only applies to non-replaced boxes.

This fixes an issue on Discord where buttons in the settings UI were
cropped to a narrower width than intended.

Fixes #3572
2025-07-23 19:52:59 +02:00
aplefull
34f0ac15fd LibWeb: Resolve calculated time values in animations and transitions
This lets us play animations and transitions when time values are
stored in the form of calculated values, such as `calc(1s + 500ms)`.
2025-07-23 15:21:23 +01:00
Luke Wilde
a2770bbcb7 LibWeb/WebSocket: Include the User-Agent header on connection
This makes the WebSockets on https://pro.kraken.com/app/trade/btc-usd
happier, but the page doesn't quite work yet.
2025-07-23 13:51:44 +01:00
Sam Atkins
943cc0e32a LibWeb/CSS: Implement "legacy value aliases" in generated code
This uses a `foo>bar` notation in the `valid-identifiers` field of
Properties.json, to say "replace `foo` with `bar`".

The motivation here is to avoid calling `parse_css_value_for_property()`
inside the per-property switch in `parse_css_value()`. Eventually we'll
need to be able to call that switch from
`parse_css_value_for_properties()` so that shorthands can make use of
any bespoke parsing code to parse their longhands.
2025-07-23 12:50:42 +01:00
Tim Ledbetter
062862f315 LibWeb/CSS: Add -webkit-filter as a legacy alias 2025-07-23 09:32:39 +02:00
Glenn Skrzypczak
6e6507c8c5 LibWeb/HTML: Sanitize email input with multiple attribute
This implements the missing part of the value sanitization algorithm
for email inputs with the multiple attribute.
2025-07-22 23:02:33 +01:00
Timothy Flynn
04fe0c6aec LibJS: Create match indices based on code unit length
In Unicode mode, we were mixing code units (start_index) with code point
length (end_index).
2025-07-22 23:11:19 +02:00
Timothy Flynn
772479b334 LibJS: Fix typo in GetMatchIndexPair definition 2025-07-22 23:11:19 +02:00
ayeteadoe
77d9508618 LibWeb/CSS: Fix implicit narrowing cast in interpolate_rotate
The changes introduced in 484a09d6a2
broke the Windows LibWeb build, so this fixes that
2025-07-22 13:21:17 -06:00
Timothy Flynn
6ddbb70051 AK: Remove constexpr specifier from Utf16View::bytes()
The Span constructor used here uses reinterpret_cast under the hood, so
it and Utf16View::bytes() cannot be constexpr.
2025-07-22 13:33:51 -04:00
Jelle Raaijmakers
9bf250c8d1 LibLine: Correctly handle consumed code points in Editor
We should not compare code point offsets to byte offsets, but compare
the consumed code points to the input's length expressed in code points
instead.

Relates to #5547.
2025-07-22 18:49:14 +02:00
Jelle Raaijmakers
526615bc10 LibWeb: Stub Navigator.getGamepads() 2025-07-22 11:55:29 -04:00
Jelle Raaijmakers
cdb736bea5 LibWeb: Remove WrappingReference from IDLGenerators
We have no cases where WrappingReferences::No does not result in the
right wrapper expression, so let's remove the enum.
2025-07-22 11:55:29 -04:00
ayeteadoe
2e2484257d LibJS: Enable EXPLICIT_SYMBOL_EXPORT and annotate minimum symbol set 2025-07-22 11:51:29 -04:00
ayeteadoe
539a675802 LibJS: Revert Enable EXPLICIT_SYMBOL_EXPORT
This reverts commit c14173f651. We
should only annotate the minimum number of symbols that external
consumers actually use, so I am starting from scratch to do that
2025-07-22 11:51:29 -04:00
Timothy Flynn
42b41431eb AK+LibJS: Enforce limits in Utf16View offset computations
RegExp was the only caller relying on being able to provide an offset
larger than the string length. So let's do a pre-check in RegExp and
then enforce that the offsets we receive in Utf16View are valid.
2025-07-22 17:17:33 +02:00
Timothy Flynn
ad7ac679fd AK: Compute Utf16View::code_point_offset_of correctly
There were a couple of issues here, including the following computation
could actually overflow to NumericLimits<size_t>::max():

    code_unit_offset -= it.length_in_code_units();
2025-07-22 17:17:33 +02:00
Timothy Flynn
f595e47c1f AK: Add unit tests for Utf16View::code_unit_offset_of 2025-07-22 17:17:33 +02:00
Timothy Flynn
0bbb725bcd AK: Mark a couple of methods in Utf16View.h as constexpr 2025-07-22 17:17:33 +02:00
Jelle Raaijmakers
265e278275 AK: Allow indexing at length in Utf8View::byte_offset_of()
And do the same for Utf8View::code_point_offset_of(). Some of these
`VERIFY`s of the view's length were introduced recently, but they caused
the parsing of named capture groups in RegexParser to crash in some
situations.

Instead, allow indexing at the view's length: the byte offset of code
point `length()` is known, even though that code point does not exist in
the view. Similarly, we know the code point offset at byte offset
`byte_length()`. Beyond those offsets, we still crash.

Fixes 13 failures in test262's `language/literals/regexp/named-groups`.
2025-07-22 09:10:32 -04:00
Jelle Raaijmakers
3db7d802db LibRegex: Early return in Parser::try_skip()
No functional changes.
2025-07-22 09:10:32 -04:00
Jelle Raaijmakers
a6dfc6cdff LibWeb: Resolve NavigatorBeacon FIXME regarding the partial interface 2025-07-22 13:07:06 +01:00
Jelle Raaijmakers
529ab9d88a Meta: Allow partial interface when formatting IDL files 2025-07-22 13:07:06 +01:00
Jelle Raaijmakers
1da304f7b7 LibIDL: Support partial interfaces
Partial interfaces have the same name as the interface they extend, and
can appear in any order. In practice, we import the partial interfaces
into the main interface's IDL.
2025-07-22 13:07:06 +01:00
Luke Wilde
9c5dff5be0 RequestServer+LibWebSocket: Drain underlying socket and resulting frames
`curl_easy_recv` must be called in a loop until it returns EAGAIN,
because it may cache data, but only activate the read notifier once.

Additionally, the data received can contain multiple WebSocket frames
and only activate the notifier once, so we have to keep reading frames
until there isn't enough data.

We also have to do this immediately after connecting a WebSocket,
since the server may immediately send data when the WebSocket opens
and before we create the read notifier.

This makes Discord login faster and more reliable, and makes Discord
activities start loading.
2025-07-22 13:55:45 +02:00
Tim Ledbetter
484a09d6a2 LibWeb: Support interpolating rotate values 2025-07-22 11:09:45 +01:00
Tim Ledbetter
cf33dec6d6 LibWeb: Extract SLERP algorithm into its own method
No functional changes.
2025-07-22 11:09:45 +01:00
norbiros
ab574deb93 Tests: Import some css/css-properties-values-api WPT tests
Casual import of 4 WPT tests related to `CSS.registerProperty`
2025-07-22 10:57:54 +01:00
norbiros
90c0decd95 LibWeb/CSS: Add CSS.registerProperty JS method
This adds an *almost* complete implementation of `CSS.registerProperty`
method enabling further progress on the `@property` feature.
2025-07-22 10:57:54 +01:00
Andreas Kling
038d8ade50 LibWeb: Always parse calc() inside CSS color functions consistently
Before this change, calc() would resolve to different types depending on
the nearest containing value context. This meant that rgb(calc(), ...)
by itself worked correctly due to fallbacks, but rgb(calc(), ...) inside
e.g a linear-gradient would create a calc() value that resolves to a
length, which subsequently got rejected by the color value parser.

Fixing this makes various little gradients show up on Discord.
2025-07-22 08:47:22 +01:00
Jelle Raaijmakers
5d19aacce7 LibJS: Do not directly append RegExp pattern code points during parse
There apparently is a bit of a disconnect between the spec asking us to
construct the pattern using code points and LibRegex not being able to
swallow those. Whenever we had multi-byte code points in the pattern and
tried to match that in unicode mode, we would fail.

Change the parser to encode all non-ASCII code units. Fixes 2 test262
cases in `language/literals/regexp`.
2025-07-22 01:23:52 +02:00
Jelle Raaijmakers
7f6b70fafb LibRegex: Use code unit length in Matcher<Parser>::match()
We were calling into `view.length()`, which potentially returned the
code _point_ length for Utf16Views. Make sure we use the code unit
length instead, since we're only indexing into code units.
2025-07-22 01:23:52 +02:00
Jelle Raaijmakers
930ac9898f LibRegex: Simplify ternary condition in RegexByteCode
No functional changes.
2025-07-22 01:23:52 +02:00
Tim Ledbetter
92f85d180e LibWeb: Serialize empty ImageBitmap data as null 2025-07-21 19:19:50 -04:00
Tim Ledbetter
854d48f973 LibWeb: Use correct angle type when serializing hue-rotate filter values
At some point `hue-rotate` was changed to use `AngleOrCalculated`
rather than `Angle`, but `Angle` was still being used in a `visit`,
which otherwise defaulted to zero. This caused all `hue-rotate` angles
to serialize to zero.
2025-07-22 00:53:10 +02:00
Tim Ledbetter
d38fac7518 LibWeb/SVG: Ignore view boxes with negative width or height 2025-07-22 00:52:24 +02:00
Tim Ledbetter
a990de65e4 LibWeb: Implement SVGViewElement
This identifies a particular region of an SVG image, which can then be
linked to by an SVG fragment identifier.
2025-07-22 00:52:24 +02:00
Timothy Flynn
81fc8ab8cc LibRegex: Rename a couple of RegexStringView methods for clarity
`operator[]` -> `code_point_at`
`code_unit_at` -> `unicode_aware_code_point_at`

`unicode_aware_code_point_at` returns either a code point or a code unit
depending on the Unicode flag.
2025-07-21 23:44:18 +02:00
Timothy Flynn
2dfcc4c307 LibRegex: Compare code units (not code points) in non-Unicode char range 2025-07-21 23:44:18 +02:00
Andreas Kling
e749be2295 LibWeb: Only cascade relevant CSS properties for logical alias context
We only need the cascaded values for writing-mode and direction when
resolving the logical alias context, so we can skip all other
properties.
2025-07-21 20:37:17 +01:00
Luke Wilde
8210a7b3e3 LibWeb: Resolve FontFaceSet::load promise with all loaded FontFaces
The resulting array is required on https://www.canva.com/
2025-07-21 16:29:55 +01:00
dmaivel
52a23dc02e AK+LibWeb/CSS: Add lower-greek counter style 2025-07-21 15:18:17 +01:00
Sam Atkins
938f27bbe3 LibWeb/CSS: Update UA styling for view-transition pseudo-elements
And also indent the file consistently.

Corresponds to 3d13816af7
2025-07-21 15:29:31 +02:00
Timothy Flynn
8600c5149b LibCrypto: Allow moving SignedBigInteger / UnsignedBigInteger
We defined copy operations but not move operations, so every existing
move() resulted in a copy.
2025-07-21 15:17:53 +02:00
Timothy Flynn
cd73c70ad6 LibCrypto: Copy the cached hash in SignedBigInteger / UnsignedBigInteger
The hash computation for big integers is pretty expensive, so if we have
a cached hash when copying a big int, let's also copy the hash.
2025-07-21 15:17:53 +02:00
Luke Wilde
0faf96fa1b Meta/curl: Update to 8.15.0
This includes the patch for issue 17917, so we can remove our custom
patch :^)
2025-07-21 15:09:35 +02:00
Aliaksandr Kalenik
4319e6b80e LibWeb: Don't put unlayered rules into into empty "service" layer
Fixes bug when `build_matching_rule_set()` mistakenly included all
unlayered rules twice. This was caused by mistakenly including all
unlayered rules into `""` named "service" layer, because we couldn't
tell if FlyString = `""` means no layer or layer named `""`.
2025-07-21 12:33:35 +01:00
Jelle Raaijmakers
7ea0f13cd9 CI: Actually pass down secrets to lagom-template.yml
By default, reusable workflows do not inherit secrets. This caused our
vcpkg source asset cache to never be updated.
2025-07-21 11:58:03 +02:00
Jelle Raaijmakers
62236fa503 CI: Enable vcpkg cache update for fuzzers build
This was a cache race condition between the fuzzers and sanitizer
builds, where the vcpkg binary cache could have been updated before the
sanitizer builds started doing their vcpkg install, causing the source
assets to never be updated at all.
2025-07-21 11:58:03 +02:00
Tim Ledbetter
1263d58689 LibWeb: Ignore zero width when calculating SVG intrinsic aspect ratio
Previously, an SVG with width of zero would have am intrinsic aspect
ratio of zero. With this change, if an SVG has a width or height of
zero, the intrinsic aspect ratio is determined by the SVG's viewbox.
2025-07-21 11:29:25 +02:00
Sam Atkins
16ef883e44 IDLGenerators: Update spec steps for "internally create a new object..."
Also wrap these in {} so it's clearer which steps are from this, and
which are from the HTML algorithm.
2025-07-21 10:05:32 +01:00
Sam Atkins
3ca879776f IDLGenerators: Allow initialize() as an IDL member name
While not a C++ keyword, we already define a `Foo::initialize()` method
on every generated binding type, so we need to avoid clashing with that.
2025-07-21 10:05:32 +01:00
Sam Atkins
ef252d63c8 IDLGenerators: Add support for default values on bool dictionary members 2025-07-21 10:05:32 +01:00
Sam Atkins
11e2dbb555 LibWeb/CSS: Support text-justify: distribute legacy value alias
...for `text-justify: inter-character`.

We previously had this mapped in Enums.json, but the behaviour is
different: `a=b` in Enums.json keeps `a` around but makes it behave the
same as `b`. A legacy name alias is instead expected to replace `a`
with `b`, so we have to do that separately.
2025-07-21 10:04:42 +01:00
Sam Atkins
db75405881 LibWeb/CSS: Support overlay keyword as alias to auto in overflow
We don't yet have a system for "legacy value aliases", but until we have
a lot of them we can handle them manually.

We also have to do this in two places because
parse_css_value_for_property() doesn't call any property-specific
parsing code.
2025-07-21 10:04:42 +01:00
Andreas Kling
128b66e30d LibWeb: Avoid duplicate work when computing style
Before this change we were running the CSS cascade machinery twice per
element:

- First, to compute the "logical alias mapping context" based on
  writing-mode and pals.

- Then, to compute all properties.

This patch factors out the heaviest work from the cascade machinery
to a separate step that can be run only once. This step will:

- Collect all the matching rules for the element
- Resolve custom properties for the element

We still perform the per-element cascade twice, but now this is hogging
less than 1% of CPU time when typing on Discord (compared to 9% before.)
2025-07-20 17:22:23 -04:00
rmgx
98b45b4137 Meta: Remove ladybird.sh 2025-07-20 20:51:51 +02:00
Manuel Zahariev
3bc0504abb Documentation: Troubleshoot double free race condition on exit 2025-07-20 13:30:31 -04:00
Michael Manganiello
89036dd70c LibWeb: Fix size computation for elements with max-width and max-height
The specification [1] indicates that the tentative used width and height
should be computed first, and if they exceed the `max-width` or
`max-height`, the rules should be applied again using the computed
values of `max-width` and `max-height`.

The only required change to follow the spec is to remove the early
`return` statements, in both `compute_width_for_replaced_element`
and `compute_height_for_replaced_element`.

Fixes #5100.

[1] https://www.w3.org/TR/CSS22/visudet.html#min-max-widths
2025-07-20 17:34:19 +02:00
Luke Wilde
45127aee88 LibWeb: Check if transferred ImageBitmap is exposed in target realm
This was forgotten in ed3d0d7.
2025-07-21 00:52:07 +12:00
Gingeh
28774efa22 LibWeb: Don't crash when drawing null image from offscreen canvas 2025-07-20 08:54:53 +02:00
Gingeh
55129644d5 LibWeb: Don't crash when root element becomes a popover or fullscreen 2025-07-20 08:54:53 +02:00
Gingeh
f38e07e0c5 LibWeb: Don't crash when an unknown property begins with a single dash 2025-07-20 08:54:53 +02:00
Tim Ledbetter
48417152df LibWeb: Don't crash when creating empty bitmap from a HTMLCanvasElement 2025-07-20 16:26:57 +12:00
Tim Ledbetter
bd83f5bde6 test-web: Treat files in images directories as resources for WPT tests 2025-07-20 16:26:57 +12:00
Tim Ledbetter
4a223ad085 Meta: Don't check png sizes for images imported from WPT 2025-07-20 16:26:57 +12:00
Tim Ledbetter
7874f325a8 LibWeb: Implement InputEvent.getTargetRanges()
This returns a list of ranges that would be affected by a change to the
DOM if the input event is not cancelled.
2025-07-20 12:34:14 +12:00
Kenneth Myhra
ed3d0d76ec LibWeb: Implement transfer {,receiving} steps for ImageBitmap 2025-07-20 12:30:43 +12:00
Kenneth Myhra
c0976b18e0 LibWeb: Implement {,de}serialization steps for ImageBitmap
To make {,de}serialization of ImageBitmap work we also had to add
support for creating an ImageBitmap from a HTMLCanvasElement in
WindowOrWorkerGlobalScopeMixin::create_image_bitmap_impl().
2025-07-20 12:30:43 +12:00
Kenneth Myhra
7b4ee57037 LibWeb: Add get_bitmap_from_surface() and use it from to_blob()
This refactors out the reading part of Gfx::Bitmap from
HtmlCanvasElement::surface(). We can then reuse this from
WindowOrWorkerGlobalScopeMixin::create_image_bitmap_impl() when we
create an ImageBitmap from a HtmlCanvasElement.
2025-07-20 12:30:43 +12:00
Kenneth Myhra
09f336bf8f LibGfx: Use static_cast instead of C-style cast 2025-07-20 12:30:43 +12:00
Kenneth Myhra
2394845d58 LibWeb: Align specification step text with current specification 2025-07-20 12:30:43 +12:00
Timothy Flynn
27d139e817 LibWeb: Define Wasm native errors correctly
1. Fix typos in some macro invocations of these error types. We now use
   a single xmacro to instantiate error definitions to prevent such
   errors in the future.

2. Use the "WebAssembly." prefix as needed.

3. Allocate the error constructors and prototypes with `realm.create`
   rather than `heap.allocate`. The latter does not invoke `initialize`
   methods. This exposed the next issue:

4. Use the correct intrinsic prototype in the error constructor. We were
   using the base native error prototype. We unfortunately cannot invoke
   OrdinaryCreateFromConstructor from LibJS directly with the correct
   prototype, so an implementation was added here.

5. Use intrinsic accessors to create the constructors. I don't think
   this one was actually a fix, but it makes the setup look more like
   other built-ins.
2025-07-19 16:48:01 -04:00
Timothy Flynn
6b3f796e5b LibWeb: Propagate errors from module instantiation 2025-07-19 16:48:01 -04:00
Timothy Flynn
a458a7d35b LibWeb: Do not coerce object IDL types to JS objects
We should bail with a TypeError if the provided value is not a JS object
already.
2025-07-19 16:48:01 -04:00
Timothy Flynn
7b14da14d8 Tests/LibWeb: Import tests for incorrect Wasm instantiations 2025-07-19 16:48:01 -04:00
ayeteadoe
f468f702d5 CMake: Update default BUILD_PRESET arg to Release in WPT.sh
The presets were recently refactored and 'default' was
renamed to 'Release', but keeping it in sync with
any consumer shell scripts was missed.
2025-07-19 21:03:51 +02:00
Andreas Kling
92221f0c57 LibWeb: Apply all animations and transitions before invalidating style
This fixes an issue where only the last KeyframeEffect applied to an
element would actually have an effect on the computed properties.

It was particularly noticeable when animating a shorthand property like
border-width, since only one of the border edges would have its width
actually animate.

By deferring the invalidation until all animations have been processed,
we also reduce the amount of work that gets done on pages with many
animations/transitions per element. Discord is very fond of this for
example.
2025-07-19 11:08:46 -04:00
Andrew Kaster
50422eb563 Tests: Add XHTML tests for CDATA, PIs and Comment nodes in the DOM 2025-07-19 14:56:20 +02:00
Andrew Kaster
f9f854b493 LibWeb: Preserve comments in XML documents 2025-07-19 14:56:20 +02:00
Andrew Kaster
9d93d37644 LibWeb: Listen for CDATASections and ProcessingInstructions in XML docs
Using the new hooks in the XML Parser's listener interface, we now
append DOM nodes for CDATASections and ProcessingInstructions
to the document as they are encountered. This commit also fixes where
comment nodes are appended, ensuring they are added to the current node
instead of the document root.
2025-07-19 14:56:20 +02:00
Andrew Kaster
d9976b98b9 LibXML: Add parser hooks for CDATASection and ProcessingInstructions
This allows listeners to be notified when a CDATASection or
ProcessingInstruction is encountered during parsing. The non-listener
path still has the incorrect behavior of silently treating CDATASection
as Text nodes, but this allows listeners to handle them correctly.
2025-07-19 14:56:20 +02:00
Luke Wilde
5a1de8a187 LibWeb/CSP: Implement the child-src directive 2025-07-19 17:15:21 +12:00
Luke Wilde
c5748437db LibWeb/CSP: Implement the default-src directive 2025-07-19 17:15:21 +12:00
Luke Wilde
25425f63ba LibWeb/CSP: Implement the worker-src directive 2025-07-19 17:15:21 +12:00
Aliaksandr Kalenik
714ff4e3f9 LibWeb: Fix previous style calculation for CSS transitions on pseudo
...elements. Adds missing pseudo-element type passed into computed
properties getter.

Previously, due to this bug, we were using the element's computed
properties as the previous computed properties for its pseudo-elements.
This caused an excessive number of unintended CSS transitions to run.
The issue was particularly noticeable in Discord's emoji picker, where
each emoji has `::after` pseudo-element. We were incorrectly triggering
transitions on all their properties, resulting in significant
unnecessary work in style computation and animation event dispatching.
2025-07-18 21:19:37 +02:00
Aliaksandr Kalenik
2fc405f1b2 LibWeb: Allow to pass pseudo-element type in computed properties getter
...and setter. We had lots of places where we check if pseudo-element
type is specified and then use `pseudo_element_computed_properties()` or
`computed_properties()`. This change moves these checks from caller side
to the getter and setter.
2025-07-18 21:19:37 +02:00
Jelle Raaijmakers
86dc3ce001 AK: Add dbgln_dump() macro
This turns:

  dbgln_dump(some_expression() + 1);

Into:

  dbgln("some_expression() + 1: {}", (some_expression() + 1));
2025-07-18 14:40:00 -04:00
Timothy Flynn
9582895759 AK+LibJS+LibWeb+LibRegex: Replace AK::Utf16Data with AK::Utf16String 2025-07-18 12:45:38 -04:00
Timothy Flynn
a43cb15e81 LibJS+LibWeb: Replace JS::Utf16String with AK::Utf16String 2025-07-18 12:45:38 -04:00
Timothy Flynn
d40e3af697 AK: Implement UTF-16 string-to-number conversions 2025-07-18 12:45:38 -04:00
Timothy Flynn
6e0290ecaa AK: Define some UTF-16 helper methods
* contains
* escape_html_entities
* replace
* to_ascii_lowercase
* to_ascii_uppercase
* to_ascii_titlecase
* trim
* trim_whitespace
2025-07-18 12:45:38 -04:00
Timothy Flynn
7f069efbc4 AK: Implement a flyweight string for Utf16String
Utf16FlyString more or less works exactly the same as FlyString. It will
store the raw encoded data of the string instance. If the string is a
short ASCII string, Utf16FlyString holds the ShortString bytes; else,
Utf16FlyString holds a pointer to the Utf16StringData.
2025-07-18 12:45:38 -04:00
Timothy Flynn
2803d66d87 AK: Support UTF-16 string formatting
The underlying storage used during string formatting is StringBuilder.
To support UTF-16 strings, this patch allows callers to specify a mode
during StringBuilder construction. The default mode is UTF-8, for which
StringBuilder remains unchanged.

In UTF-16 mode, we treat the StringBuilder's internal ByteBuffer as a
series of u16 code units. Appending a single character will append 2
bytes for that character (cast to a char16_t). Appending a StringView
will transcode the string to UTF-16.

Utf16String also gains the same memory optimization that we added for
String, where we hand-off the underlying buffer to Utf16String to avoid
having to re-allocate.

In the future, we may want to further optimize for ASCII strings. For
example, we could defer committing to the u16-esque storage until we
see a non-ASCII code point.
2025-07-18 12:45:38 -04:00
Timothy Flynn
fe676585f5 AK: Add a UTF-16 string with optimized short- and ASCII-string storage
This is a strictly UTF-16 string with some optimizations for ASCII.

* If created from a short UTF-8 or UTF-16 string that is also ASCII,
  then the string is stored in an inlined byte buffer.

* If created with a long UTF-8 or UTF-16 string that is also ASCII,
  then the string is stored in an outlined char buffer.

* If created with a short or long UTF-8 or UTF-16 string that is not
  ASCII, then the string is stored in an outlined char16 buffer.

We do not store short non-ASCII text in the inlined buffer to avoid
confusion with operations such as `length_in_code_units` and
`code_unit_at`. For example, "😀" would be stored as 4 UTF-8 bytes
in short string form. But we still want `length_in_code_units` to
be 2, and `code_unit_at(0)` to be 0xD83D.
2025-07-18 12:45:38 -04:00
Timothy Flynn
8fbb80fffc AK: Do not fall back to simdutf for UTF-16 ASCII validation
This was a mistake. Consider U+201C (LEFT DOUBLE QUOTATION MARK). This
code point is encoded as the bytes 0x1c 0x20 in UTF-16LE. Both of these
bytes are ASCII if interpreted as UTF-8. But the string itself is most
certainly not ASCII.
2025-07-18 12:45:38 -04:00
Callum Law
4ee8110449 LibWeb: Handle flood-opacity in line with other opacity properties
We now do the proper thing in terms of:
 - Allowing percentages
 - Returning the computed value in getComputedStyle
 - Handling values out of the [0,1] range

Gains us 13 WPT passes in the imported tests.
2025-07-18 11:04:55 -04:00
Callum Law
6f39c30704 LibWeb: Propagate flood-color and flood-opacity to ComputedValues 2025-07-18 11:04:55 -04:00
Timothy Flynn
f6f31fe215 LibWeb: Remove ability to override MessagePort's primary interface
This hack no longer has any users.
2025-07-18 10:09:02 -04:00
Timothy Flynn
d471b52b0e LibWeb: Assume structured deserialization creates the correct type
Most locations already make this assumption, but we had a few that would
silently ignore data mismatches. Let's just always assume the type is
correct for now. If a bad actor has a hold of our transport socket, it's
probably better to crash WebContent than to continue on with incorrect
data.

In the future, maybe we will want to throw an exception instead.
2025-07-18 10:09:02 -04:00
Timothy Flynn
ed71db45e7 LibWeb: Move array buffer/view serializers above their users
Now that these serializers are internal to StructuredSerialize.cpp,
let's put them above Serializer so they don't have to be forward-
declared and explicitly instantiated.
2025-07-18 10:09:02 -04:00
Timothy Flynn
64abc6101d LibWeb+WebWorker: Use IPC mechanics for structured serialization
Our structured serialization implementation had its own bespoke encoder
and decoder to serialize JS values. It also used a u32 buffer under the
hood, which made using its structures a bit awkward. We had previously
worked around its data structures in transferable streams, which nested
transfers of MessagePort instances. We basically had to add hooks into
the MessagePort to route to the correct transfer receiving steps, and
we could not invoke the correct AOs directly as the spec dictates.

We now use IPC mechanics to encode and decode data. This works because,
although we are encoding JS values, we are only ultimately encoding
primitive and basic AK types. The resulting data structures actually
enforce that we implement transferable streams exactly as the spec is
worded (I had planned to do that in a separate commit, but the fallout
of this patch actually required that change).
2025-07-18 10:09:02 -04:00
Timothy Flynn
7fad8c333d LibWeb: Use forward-declarations of structured serialized types
This reduces the rebuilt targets when touching StructuredSerialize.h
from ~1200 to ~400. The remaining are due to generated IPC headers.
2025-07-18 10:09:02 -04:00
Timothy Flynn
20c6005341 LibWeb: Use TemporaryExecutionContext in structured deserialization
No need to manually prepare / clean up a context. We also previously
would not have done the clean up steps if structured deserialization
threw an exception.
2025-07-18 10:09:02 -04:00
Timothy Flynn
b1cfc96609 LibWeb: Don't check is_object in every serialization branch
Instead of every branch being of the form:

    if (value.is_object() && is<SomeType>(value.as_object()) {
        auto& some_type = static_cast<SomeType&>(value.as_object());
    }

Let's extract the `is_object` check to an outer branch, and use `as_if`
to check the type.

No functional change, but this makes a future change simpler to review.
2025-07-18 10:09:02 -04:00
Timothy Flynn
b204977efb LibJS: Allow creating shared ArrayBuffer objects more easily
This will allow structured deserialization in LibWeb to create shared
buffers without having to go through CreateSharedByteDataBlock. That
will let us pass in the underlying ByteBuffer, rather than having to
allocate a second buffer via CreateSharedByteDataBlock and memcpy the
data into it.
2025-07-18 10:09:02 -04:00
Timothy Flynn
3fb4e769d8 LibJS: Allow assigning an error message after Error object creation
This will be used by structured deserialization in LibWeb.
2025-07-18 10:09:02 -04:00
Timothy Flynn
fd6d868ae2 LibIPC: Add some type aliases and MessageBuffer helpers
To re-use some of these wordy types outside of LibIPC, let's add some
aliases.
2025-07-18 10:09:02 -04:00
Jelle Raaijmakers
8dd259b8d8 LibWeb: Stub CSSCounterStyleRule
Just the interface. Adds 6 new WPT subtest passes.
2025-07-18 11:51:41 +01:00
norbiros
7ad01d28a8 LibWeb/CSS: Add basic registered properties with initial values
Add global registry for registered properties and partial support
for `@property` rule. Enables registering properties with initial
values. Also adds basic retrieval via `var()`.

Note: This is not a complete `@property` implementation.
2025-07-18 11:12:39 +01:00
Trey Shaffer
e7f0126c2e LibWebView: Don't provide autocomplete suggestions for file:// URLs 2025-07-18 10:58:07 +01:00
Jelle Raaijmakers
4e51e585a2 LibWeb: Only show namespace if non-default in DOM tree dump
When dumping the DOM tree, only prefix the element's local name with its
short namespace identifier if it's not the document's default namespace.
This gets rid of the excessive "html:" and "svg:" prefixes in context of
an HTML or SVG document, respectively.
2025-07-18 10:54:50 +01:00
Jelle Raaijmakers
ae4aa2eeb0 LibWeb: Clean up dumping the DOM tree
Use namespace constants and `as_if()` where possible. No functional
changes.
2025-07-18 10:54:50 +01:00
Luke Wilde
8e999bca62 LibWeb/CSP: Implement the style-src-attr directive 2025-07-18 11:58:04 +12:00
Luke Wilde
574b736156 LibWeb/CSP: Implement the style-src-elem directive 2025-07-18 11:58:04 +12:00
Luke Wilde
8b0b3b186f LibWeb/CSP: Implement the style-src directive 2025-07-18 11:58:04 +12:00
Jelle Raaijmakers
d1abd11b78 WebContent: Do not crash on dumping unavailable localStorage
Be a bit more defensive about this so we don't crash when trying to dump
unavailable local storage, such as on about:newtab.
2025-07-17 23:40:08 +01:00
Sam Atkins
0ff61e5e7b LibWeb/CSS: Implement path() basic shape 2025-07-17 13:59:23 -04:00
Sam Atkins
8538186ca5 LibWeb/SVG: Add serialization of Paths
CSS users (like the `path()` function) need to be able to serialize
their path data in a canonical form.
2025-07-17 13:59:23 -04:00
Sam Atkins
6b53454b68 LibWeb/SVG: Move path data into Path.{h,cpp}
More things need this than just the `<path>` element, so let's avoid
having to include `SVGPathElement.h` in places that don't need it.

Minor changes at the same time:
- Wrap it in a Path class
- Specify underlying type for PathInstructionType
- Make a couple of free functions into methods
- Give PathInstruction an operator==

No functionality changes.
2025-07-17 13:59:23 -04:00
Sam Atkins
07b5b7ffb6 Tests: Import CSS clip-path: path(...) tests 2025-07-17 13:59:23 -04:00
Aliaksandr Kalenik
1bf4d3391e LibWeb: Use GC::Ptr for BrowsingContext pointer saved in Document
Likely we forgot to update `WeakPtr` to `GC::Ptr` after converting
`BrowsingContext` to GC-allocated object.
2025-07-17 15:55:30 +01:00
Jelle Raaijmakers
59a867d3e3 Tests: Enable all screenshot tests on all platforms
With the newly supported fuzzy matching in our test-web runner, we can
now define the expected maximum color channel and pixel count errors per
failing test and set a baseline they should not exceed.

The figures I added to these tests all come from my macOS M4 machine.
Most discrepancies seem to come from color calculations being slightly
off.
2025-07-17 12:59:11 +01:00
Jelle Raaijmakers
0d856a8fa7 Tests: Implement fuzzy screenshot comparisons in test-web
We now read WPT's `<meta name="fuzzy">` tags if present in tests and
apply them while comparing screenshots.
2025-07-17 12:59:11 +01:00
Jelle Raaijmakers
e4b2253b63 Tests: Replace load-reference-page debug action with internals method
WPT reference tests can add metadata to tests to instruct the test
runner how to interpret the results. Because of this, it is not enough
to have an action that starts loading the (mis)match reference: we need
the test runner to receive the metadata so it can act accordingly.

This sets our test runner up for potentially supporting multiple
(mis)match references, and fuzzy rendering matches - the latter will be
implemented in the following commit.
2025-07-17 12:59:11 +01:00
Jelle Raaijmakers
0f642ecb5c LibGfx: Replace Bitmap::visually_equals() with ::diff()
This produces more granural information on the actual pixel errors
present between two bitmaps. It now also asserts that both bitmaps are
the same size, since we should never compare two differently sized
bitmaps anyway.
2025-07-17 12:59:11 +01:00
Sam Atkins
b7b504cf2d LibWeb: Remove XML-derived attribute name validation from DOMStringMap
Corresponds to 841fcfdb2c
2025-07-17 13:54:01 +02:00
Tim Ledbetter
1e30fd5c6a Meta: Add WPT.sh bisect for finding WPT regressions automatically 2025-07-17 10:51:12 +02:00
Tim Ledbetter
117ff3778a Meta: Ensure the correct log file path is used with WPT.sh compare
Previously, using abolute paths with `WPT.sh compare` would fail, as
directories were always assumed to be relative to the working directory.
2025-07-17 10:51:12 +02:00
Jelle Raaijmakers
115e5f42af LibWeb: Improve graphical list item marker positioning
While 788d5368a7 took care of better text
marker positioning, this improves graphical marker positioning instead.

By looking at how Firefox and Chrome render markers, it's clear that
there are three parts to positioning a graphical marker:

  * The containing space that the marker resides in;
  * The marker dimensions;
  * The distance between the marker and the start of the list item.

The space that the marker can be contained in, is the area to the left
of the list item with a height of the marker's line-height. The marker
dimensions are relative to the marker's font's pixel size: most of them
are a square at 35% of the font size, but the disclosure markers are
sized at 50% instead. Finally, the marker distance is always gauged at
50% of the font size.

So for example, a list item with `list-style-type: disc` and `font-size:
20px`, has 10px between its start and the right side of the marker, and
the marker's dimensions are 7x7.

The percentages I've chosen closely resemble how Firefox lays out its
list item markers.
2025-07-17 09:35:09 +01:00
Andreas Kling
ada198bee0 LibJS: Add fast path for TypedArrayPrototype.copyWithin()
This can be a simple memmove() in the most common cases.

Shaves 500ms of load time off of https://terminal.shop/api
2025-07-17 08:50:04 +02:00
Callum Law
3d7c5115d8 LibWeb: Move Transformation::to_matrix to new CSV resolve methods
This gains us 2 WPT passes as we now correctly disallow relative lengths
in more places in the `DOMMatrix` constructor.
2025-07-17 08:31:52 +02:00
Aliaksandr Kalenik
aa31b69e7e LibWeb+WebContent: Delete unused page_did_layout() 2025-07-17 08:24:19 +02:00
Aliaksandr Kalenik
b0ef7f4427 LibWeb: Defer invalidation sets processing until update_style()
This change converts `Node::invalidate_style()` (invalidation sets
overload) from eagerly doing tree traversal that marks elements affected
by invalidation set to instead adding "pending invalidation sets" into
`StyleInvalidator`, processing of which is deferred until the next
`update_style()`. By doing that we sometimes substantially reduce amount
of work done performing tree traversal that marks elements for style
recalculation.

Improves performance on Discord, were according to my measurements we
were previously spending 20% of time in style invalidation, but now it's
down to <1%.
2025-07-17 00:43:26 +02:00
Aliaksandr Kalenik
8cbe27b2f9 LibWeb: Move perform_pending_style_invalidations() in StyleInvalidator
This change introduces StyleInvalidator as a preparation for upcoming
change that will make `perform_pending_style_invalidations()` take care
of pending invalidation sets.
2025-07-17 00:43:26 +02:00
Andreas Kling
03256a2543 LibWeb: Add "parallel queue" and allow it as fetch task destination
Note that it's not actually executing tasks in parallel, it's still
throwing them on the HTML event loop task queue, each with its own
unique task source.

This makes our fetch implementation a lot more robust when HTTP caching
is enabled, and you can now click links on https://terminal.shop/
without hitting TODO assertions in fetch.
2025-07-17 00:13:39 +02:00
Aliaksandr Kalenik
9a5ef95022 LibWeb: Delete unused m_animation_driver_timer in Document 2025-07-16 22:09:46 +02:00
Timothy Flynn
0e6ee925f0 Meta+LibJS: Update simdutf to version 7.3.3
This contains a fix for handling invalid trailing padding characters.
2025-07-16 17:03:15 +02:00
Timothy Flynn
66b21eee04 Meta: Update sqlite3 to version 3.50.2 2025-07-16 17:03:15 +02:00
Timothy Flynn
c6ebb7bf55 Meta+LibCrypto: Update openssl to version 3.5.1
This contains an API change that disallows setting the salt to a null
value. See:

4f5ffddfcb

This seems to be the opposite of the intended effect of that change,
but this patch includes a workaround nonetheless.

Co-Authored-By: devgianlu <altomanigianluca@gmail.com>
2025-07-16 17:03:15 +02:00
Timothy Flynn
2d121097c9 Meta: Update libpng to version 1.6.48 2025-07-16 17:03:15 +02:00
Timothy Flynn
d8657e53f0 Meta: Update libjpeg-turbo to version 3.1.0#2 2025-07-16 17:03:15 +02:00
Timothy Flynn
fd499ddb62 Meta: Update dirent to version 1.25 2025-07-16 17:03:15 +02:00
Timothy Flynn
776da5dd6b Meta: Update vcpkg baseline 2025-07-16 17:03:15 +02:00
Sam Atkins
27a666f3b2 LibWeb/CSS: Implement type(<syntax>) in attr()
This lets the `attr()` interpret the attribute's contents as an
arbitrary type instead of just as a string or number.
2025-07-16 14:47:45 +01:00
Sam Atkins
0a5e8c2865 LibWeb/CSS: Implement "parse with a <syntax>"
Uses the SyntaxNode tree to parse a list of ComponentValues into some
kind of StyleValue.
2025-07-16 14:47:45 +01:00
Sam Atkins
ded2207762 LibWeb/CSS: Parse the CSS <syntax> type into a tree
`<syntax>` is a limited subset of the "value definition syntax" used in
CSS specs. It's used for `@property`'s `syntax` descriptor, and for the
`type()` function in `attr()`.
2025-07-16 14:47:45 +01:00
Sam Atkins
5d1ba658c9 Tests: Import attr()-related WPT tests 2025-07-16 14:47:45 +01:00
Sam Atkins
72a7a18502 LibWeb/CSS: Use parse_value() to shrink parse_css_value_for_properties() 2025-07-16 14:47:45 +01:00
Sam Atkins
c7d4c4fbff LibWeb/CSS: Add a method to parse a value based on a ValueType 2025-07-16 14:47:45 +01:00
Sam Atkins
08bf9d39de LibWeb/CSS: Add String->ValueType conversion function
And also move this out of PropertyID.h because it's a separate thing.

I considered generating this but there's really not much to it.
2025-07-16 14:47:45 +01:00
Sam Atkins
0c66adfa1a LibWeb/CSS: Check Enums.json for what type names are enums
The hard-coded list here is fragile. We can just look at the Enums file
to see what our actual enum names are, instead.
2025-07-16 14:47:45 +01:00
Sam Atkins
7e2fa2650d LibWeb/CSS: Sort the entries in Enums.json
I semi-unintentionally add a checker for this in the next commit.
2025-07-16 14:47:45 +01:00
Sam Atkins
d18b0c07ca LibWeb/CSS: Make UnresolvedStyleValue figure out if it contains ASFs
UnresolvedStyleValue::create() has one user where we know if there are
any arbitrary substitution functions in the list of CVs, and two users
where we don't know and just hope there aren't any. I'm about to add
another user that also doesn't know, and so it seems worth just making
UnresolvedStyleValue::create() do that work instead.

We keep the parameter, now Optional<>, so that we save some redundant
work in that one place where we do already know.
2025-07-16 14:47:45 +01:00
Sam Atkins
5aba457009 LibWeb/CSS: Add tokenize() method to style values, to get a list of CVs
A couple of arbitrary substitution functions require us to get or
produce some style value, and then substitute its ComponentValues into
the original ComponentValue list. So this commit gives CSSStyleValue a
tokenize() method that does so.

Apart from a couple of unusual cases like the guaranteed-invalid value,
style values can all be converted into ComponentValues by serializing
them as a string, and then parsing that as a list of component values.
That feels unnecessarily inefficient in most cases though, so I've
implemented faster overrides for a lot of the basic style value
classes, but left that serialize-and-reparse method as the fallback.
2025-07-16 14:47:45 +01:00
Sam Atkins
9bc5c6fb35 LibWeb/DOM: Add document getter to AbstractElement 2025-07-16 14:47:45 +01:00
Callum Law
33cf3d7782 LibWeb: Serialize RGB, HWB and HSL colors with unresolved components
Gains us 44 WPT passes.
2025-07-16 13:05:33 +01:00
Callum Law
6a9c8d7767 LibWeb: Don't resolve colors with unresolved components
`CSSColorValue`s which have unresolved `calc` components should be able
to be resolved. Previously we would always resolve them but with
incorrect values.

This is useful as we will now be able to now whether we should serialize
colors in their normalized form or not.

Slight regression in that we now serialize (RGB, HSL and HWB) colors
with components that rely on compute-time information as an empty
string, but that will be fixed in the next commit.
2025-07-16 13:05:33 +01:00
Callum Law
e66332c07a LibWeb: Add new CalculatedStyleValue::resolve_* methods
These new methods are built on top of the spec's
`simplify_a_calculation_tree` algorithm where the old methods were
ad-hoc.

These methods are not used anywhere yet as callers will need to be
migrated over from the deprecated methods one-by-one to account for
differences in behaviour.

No functionality changes.
2025-07-16 13:05:33 +01:00
Callum Law
afa95c2815 LibWeb: Mark CalculatedStyleValue::resolve_* methods as deprecated
The existing resolve methods are not to spec and we are working to
replace them with new ones based on the `simplify_a_calculation_tree`
method.

These are marked as deprecated rather than replaced outright as work
will need to be done on the caller side to be made compatible with the
new methods, for instance the new methods can fail to resolve (e.g.
if we are missing required context), where the existing methods will
always resolve (albeit sometimes with an incorrect value).

No functionality changes.
2025-07-16 13:05:33 +01:00
Callum Law
a13f6cdf86 LibWeb: Use correct command in reorder_modifiable_descendants
Gains us 7 WPT passes in the imported test
2025-07-16 12:40:38 +02:00
Callum Law
1d3e539c09 LibWeb: Account for logical property groups in set_a_declaration
When setting a declaration for a property in a logical property group,
it should appear after all other declarations which belong to the same
property group but have different mapping logic (are/aren't a logical
alias).

Gains us 1 WPT pass.
2025-07-16 11:16:49 +01:00
Callum Law
47ddc2ea87 LibWeb: Respect logical property groups when serializing shorthands
We should not serialize a group of properties `longhands` as a single
shorthand if there is any property declared between the first and
last property in `longhands` which is not part of `longhands` but
belongs to the same logical property group, and has different mapping
logic to any of property in `longhands`
2025-07-16 11:16:49 +01:00
Callum Law
05e2e398bd LibWeb: Add method to get logical property group for PropertyID 2025-07-16 11:16:49 +01:00
Sam Atkins
511e282002 LibWeb/HTML: Return CSSStyleProperties from getComputedStyle()
Corresponds to 94fdd8ab1e
2025-07-16 09:50:30 +02:00
Andrew Kaster
870915b594 Devcontainer: Set dynamic triplets for vcpkg cache feature
This ensures that when we set an overlay port directory for building
the vcpkg cache, we set the default (and host) triplet to match the
triplet files we have in each directory.
2025-07-16 08:36:50 +02:00
Andrew Kaster
0b854ed8eb Devcontainer: Enable vcpkg asset cache for vcpkg cache feature
This enables our vcpkg asset cache in the devcontainer setup, protecting
CI jobs against flaky upstream tarball downloads.
2025-07-16 08:36:50 +02:00
Jelle Raaijmakers
616a2af23d Tests: Enable screenshot tests on arm64
Of the available 71 screenshot tests that we have, 42 fail on macOS
arm64. Let's make it possible to skip those and run the remaining
succeeding screenshot tests on arm64 anyway.
2025-07-16 08:36:14 +02:00
Callum Law
a1c9b86ad3 LibWeb: Account for non-shorthand sub-properties when serializing border
When parsing values in `process_a_keyframes_argument` we don't expand
properties using `StyleComputer::for_each_property_expanding_shorthands`
unlike most other places - this means that if we parse a `border` we end
up with the `border`'s sub-properties (`border-width`, `border-style`,
`border-color`) still in their unexpanded forms (`CSSKeywordValue`,
`LengthStyleValue`, `StyleValueList`, etc) rather than
`ShorthandStyleValue`s which causes a crash when serializing the
`border` value in `KeyframeEffect::get_keyframes`.

The proper fix here is to parse `border`'s sub-properties directly to
`ShorthandStyleValue`s instead of relying on
`StyleComputer::for_each_property_expanding_shorthand` to do this
conversion for us but this may be a while off.

This commit also imports the previously crashing tests.
2025-07-16 06:49:38 +01:00
Aliaksandr Kalenik
52e9dcd911 LibWeb: Assign new m_viewport_size before resizing backing store
Fixes bug when `resize_backing_stores_if_needed()` picks up previous
viewport size for allocation of new backing stores.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/5336
2025-07-15 18:39:01 -04:00
Aliaksandr Kalenik
6ddc582551 LibWeb: Delete unreachable code in Node::invalidate_style()
`if (invalidation_set.needs_invalidate_whole_subtree())` branch in the
end of the function was always false.
2025-07-15 18:31:43 -04:00
Andrew Kaster
c1ece2b4ed Meta: Clean up flatpak manifest and remove most linter warnings
We now clean up installed helper tools, includes from dependencies, and
pkgconfig/CMake files. This decreases the size of the flatpak from
~206MiB to ~150 MiB on my machine.

The manifest is also mostly clean of linter warnings from the
flatpack-builder manifest linter, with the exception of the overly broad
session bus policy.

The docs at https://docs.flathub.org/docs/for-app-authors/linter list a
method for selecting the correct session bus policies, but it is unclear
how to actually get the full set.
2025-07-15 14:16:42 -06:00
Undefine
9d26caf0d5 Documentation: Add build instructions for FreeBSD 2025-07-15 13:44:54 -06:00
Undefine
060e8518b4 Meta: Workaround CMAKE_LINKER_TYPE being broken on FreeBSD
https://gitlab.kitware.com/cmake/cmake/-/issues/27037
2025-07-15 13:44:54 -06:00
Undefine
2aa8c950ca LibCore+Meta: Workaround some symbols not being exported on FreeBSD
On FreeBSD some symbols like `environ` or `__progname` are not exported
anywhere and are filled in by the dynamic loader. `environ` is
a special case because we make use of it explicitly so we need to mark
it a weak symbol so the linker doesn't complain.
2025-07-15 13:44:54 -06:00
Undefine
3056e54cd0 Meta: Update ffmpeg
This is update contains fixes for the FreeBSD build
2025-07-15 13:44:54 -06:00
Undefine
1a42fc4fcd Meta: Patch angle vcpkg to build on FreeBSD 2025-07-15 13:44:54 -06:00
Undefine
6645e4efbb Meta: Build QT with vcpkg on FreeBSD
This is a workaround for the fact that on FreeBSD the system icu has
symbol renaming disabled which causes our build to clash with the
expectations of the system QT.
2025-07-15 13:44:54 -06:00
Undefine
f51f067f23 Meta: Don't build libproxy on FreeBSD
The build for it is broken on FreeBSD and doesn't seem to be needed
anyways.
2025-07-15 13:44:54 -06:00
Undefine
f0cdf0e9b5 Meta: Fix building skia on FreeBSD 2025-07-15 13:44:54 -06:00
Undefine
515a94c49d Meta: Update vcpkg baseline 2025-07-15 13:44:54 -06:00
Undefine
48403eab21 Meta: Add vcpkg triplets for FreeBSD 2025-07-15 13:44:54 -06:00
Sam Atkins
632ce9523b LibWeb/CSS: Add :unchecked pseudo-class
This just got added to the Selectors spec:

b78c97c19d

It's thus missing from the HTML spec and WPT, but I figured it was
simple enough to add.
2025-07-15 21:27:44 +02:00
Sam Atkins
b973c8d275 LibWeb/CSS: Remove the :target-within pseudo-class
This has been removed from the spec:

03b340c34f
2025-07-15 21:27:44 +02:00
Luke Wilde
d9cb8185cc LibWeb: Include submitter name and value when constructing FormData
This fixes the SSO buttons on OpenAI's login page giving "Unknown
error"
2025-07-15 20:49:39 +02:00
Jelle Raaijmakers
144eac44fb LibGfx: Remove Font::pixel_size_rounded_up()
The remaining callsites were removed in the previous commit.
2025-07-15 19:05:36 +01:00
Jelle Raaijmakers
788d5368a7 LibWeb: Improve list item marker positioning and alpha/roman text
This commit is a three-parter that is hard to separate without breaking
marker rendering:

  1. Any marker style that results in a string, except for a literal
     string (e.g. `list-style-type: "@"`), should get the string ". "
     appended. We forgot to do this for the alpha and roman types.

  2. Instead of using the "pixel size rounded up" from a font and adding
     an arbitrary 1 to that, we now use the exact pixel size for as long
     as possible to improve our vertical positioning of markers.

  3. Instead of always adding a "default marker width" to the marker
     content width, we now only do this if we did not have text metrics
     available (i.e. the marker style is not a text type). This greatly
     improves horizontal positioning of text markers.
2025-07-15 19:05:36 +01:00
Aliaksandr Kalenik
8142c311ec LibWeb: Reset document's cursor blink timer after selection change
For contenteditable `Selection` in collapsed state represents cursor
position, so whenever it's update, we should also reset the blink timer.

Fixes bug on Discord when cursor is blinking while it is being moved by
pressing arrow keys.
2025-07-15 17:25:02 +01:00
Tim Ledbetter
e26d848dde Meta: Exit gracefully when importing multiple WPT tests is interrupted 2025-07-15 18:10:07 +02:00
Tim Ledbetter
d6f419af53 Meta: Add --wpt-base-url option to the WPT importer
This allows files to be downloaded locally by first running:
`./Meta/WPT.sh serve` then importing with
`--wpt-base-url http://web-platform.test:8000`.
2025-07-15 18:10:07 +02:00
Aliaksandr Kalenik
9b9acf0bd5 LibWeb: Delete schedule_style_update() and schedule_layout_update()
Both functions schedule HTML event loop processing but that's
unnecessary, because we schedule a rendering task that checks if
style/layout needs an update 60/s anyway.
2025-07-15 16:57:35 +02:00
Callum Law
93f957051a LibWeb: Handle serialization of invalid border in all contexts
Previously as we handled this in `get_property_internal` there were some
contexts that we missed, for instance `CSSStyleProperties::serialized`.
2025-07-15 14:26:02 +01:00
Callum Law
927cd969b2 LibWeb: Generically serialize "positional-value-list-shorthand"s
We were previously handling this ad-hoc via logic in
`get_property_internal` but this didn't cover all contexts (for
instance `CSSStyleProperties::serialized`.

Gains us 9 more WPT tests as we now cover properties which weren't
included in the previous ad-hoc approach.
2025-07-15 14:26:02 +01:00
Callum Law
9ed85ddd63 LibWeb: Mark relevant properties as "positional-value-list-shorthands"
Some shorthand properties work differently to normal in that mapping of
provided values to longhands isn't necessarily 1-to-1 and depends on the
number of values provided, for example `margin`, `border-width`, `gap`,
etc.

These properties have distinct behaviors in how they are parsed and
serialized, having them marked allows us to implement theses behaviors
in a generic way.

No functionality changes.
2025-07-15 14:26:02 +01:00
Callum Law
48153ecf45 LibWeb: Remove duplicate logic for white-space special keywords
This is already handled in `ShorthandStyleValue::to_string`.

No functionality change.
2025-07-15 14:26:02 +01:00
Callum Law
09a5c04e5c LibWeb: Handle serialization of invalid font-variant in all contexts
Previously as we handled this in `get_property_internal` there were some
contexts that we missed, for instance `CSSStyleProperties::serialized`.
2025-07-15 14:26:02 +01:00
Luke Wilde
d08d6b08d3 LibWeb: Use enum for serialization and reimplement interface exposure
Our currently implementation of structured serialization has a design
flaw, where if the serialized/transferred type was not used in the
destination realm, it would not be seen as exposed and thus we would
not re-create the type on the other side.

This is very common, for example, transferring a MessagePort to a just
inserted iframe, or the just inserted iframe transferring a MessagePort
to it's parent. This is what Google reCAPTCHA does.

This flaw occurred due to relying on lazily populated HashMaps of
constructors, namespaces and interfaces. This commit changes it so that
per-type "is exposed" implementations are generated.

Since it no longer relies on interface name strings, this commit
changes serializable types to indicate their type with an enum,
in line with how transferrable types indicate their type.

This makes Google reCAPTCHA work on https://www.google.com/recaptcha/api2/demo
It currently doesn't work on non-Google origins due to a separate
same-origin policy bug.
2025-07-15 09:20:02 -04:00
Luke Wilde
d6b9bd306c LibWeb: Don't read from MessagePort transport if it's not entangled
If the MessagePort is not entangled, then m_transport is null, meaning
it's not valid to read from the transport.

This fixes the cross-piping streams WPT crash test crashing in the
upcoming commit.
2025-07-15 09:20:02 -04:00
Luke Wilde
cb1c388ee3 Generators/Interfaces: Refactor separate interface Vectors into a struct 2025-07-15 09:20:02 -04:00
Undefine
c60e3fb445 Meta: Fix the angle version
The version in the angle portfile, angle vcpkg and ladybird vcpkg was
not the same.
2025-07-15 14:10:30 +01:00
Shannon Booth
9054ff29f0 LibWeb/CSS: Parse the ::slotted pseudo-element 2025-07-15 13:54:17 +01:00
Shannon Booth
0151a088ad LibWeb/CSS: Fix missing ':' in debug logging for pt-name-selector 2025-07-15 13:54:17 +01:00
Shannon Booth
15657ec4c3 LibWeb: Include or declare missing definitions for PseudoElement.h
clangd was loudly complaining about this file.
2025-07-15 13:54:17 +01:00
Jelle Raaijmakers
b56d4e9bab Tests: Rebaseline Layout/input/table/th-default-text-align.html
Needed after edca2ab666.
2025-07-15 11:21:14 +02:00
Sam Atkins
b3abbeab89 LibWeb/CSS: Support inherit custom properties on :root
Make sure we have a parent element before trying to look at it!

I've also pulled out a stub function for getting a custom property's
initial value, so that there's only one place to change once we support
`@property` more.
2025-07-15 10:36:08 +02:00
Jelle Raaijmakers
edca2ab666 LibWeb: Do not create an anonymous container for table cells by default
We were always creating an anonymous container for the inline contents
of table cells, but the layout node we spawn for the table cells
themselves already is capable of dealing with inline nodes. Regular
logic should kick in for dealing with the block/inline node invariant.
2025-07-15 10:06:36 +02:00
Andreas Kling
a4fb21308d LibWeb: Don't add range data for FontCascadeList with no Unicode ranges
This fixes a bunch of WPT crashes in /html/canvas/offscreen/text/
2025-07-15 10:06:10 +02:00
Jelle Raaijmakers
9f7447f546 LibWeb: Prioritize inheriting text-align for <th>
Because we defined `th { text-align: center }` in our UA stylesheet, it
received a higher precedence than inherited (inline) styles. Firefox
deals with this by defining a custom `text-align` value that prioritizes
any inherited value before defaulting to `text-align: center`.

We now do this as well :^)
2025-07-15 10:05:48 +02:00
Tim Ledbetter
d1678e03ff LibWeb: Check parent node exists before checking its type 2025-07-15 18:37:50 +12:00
InvalidUsernameException
8002efe780 LibWeb: Don't distort replaced elements with natural size in flex layout
When layouting a replaced element with natural width and height (e.g. a
raster graphic), the replaced element would correctly end up with its
natural size in the main-axis dimension. For the cross axis dimension
however, the replaced element was stretched or squished to the flex
containers inner cross size, which is wrong. Instead, we need to respect
the replaced elements aspect ratio.

Since the touched code does not have a direct correspondence to any spec
text, I am not fully certain that the change is completely correct.
However, tests agree with it, so the new code seems more correct than
the old one at least.

This fixes 50 WPT subtests in `css/css-flexbox`, most of which are
already in-tree. I have also created a new test for a scenario that did
not seem to be covered by WPT.
2025-07-15 00:52:50 +02:00
Andreas Kling
0fece0650e LibGfx: Let FontCascadeList quickly reject out-of-range code points
By keeping track of the enclosing range around all Unicode ranges of a
FontCascadeList entry, we can quickly reject any code point that's
outside all ranges.

This knocks font_for_code_point() from 7% to 3% in the profile when
scrolling on https://screenshotone.com/
2025-07-14 19:05:25 +02:00
Tim Ledbetter
488333aa4b Tests: Convert an SVG text test to a crash test
This should have been a crash test, but the test runner previously
didn't wait long enough for the test to crash.
2025-07-14 13:05:17 -04:00
Tim Ledbetter
e1f0284fba test-web: Wait longer before completing crash tests
Previously, a lot of imported WPT crash tests wouldn't wait long
enough for a crash to occur.
2025-07-14 13:05:17 -04:00
Aliaksandr Kalenik
eed47acb1f LibWeb: Expand ClipFrame into clip rectangles during display list replay
Until now, every paint phase of every PaintableBox injected its own
clipping sequence into the display list:
```
before_paint: Save
              AddClipRect (1)
              ...clip rectangles for each containing block with clip...
              AddClipRect (N)

paint:        ...paint phase items...

after_paint:  Restore
```

Because we ran that sequence for every phase of every box, Skia had to
rebuild clip stack `paint_phases * paintable_boxes` times. Worse,
usually most paint phases contribute no visible drawing at all, yet we
still had to emit clipping items because `before_paint()` has no way to
know that in advance.

This change takes a different approach:
- Clip information is now attached as metadata `ClipFrame` to each
  DisplayList item.
- `DisplayListPlayer` groups consecutive commands that share a
  `ClipFrame`, applying the clip once at the start of the group and
  restoring it once at the end.

Going from 10 ms to 5 ms in rasterization on Discord might not sound
like much, but keep in mind that for 60fps we have 16 ms per frame and
there is a lot more work besides display list rasterization we do in
each frame.

* https://discord.com/channels/1247070541085671459/1247090064480014443
  - DisplayList items:  81844  -> 3671
  - rasterize time:     10 ms  -> 5 ms
  - record time:        5 ms   -> 3 ms

* https://github.com/LadybirdBrowser/ladybird
  - DisplayList items:  7902  -> 1176
  - rasterize time:     4 ms  -> 4 ms
  - record time:        3 ms  -> 2 ms
2025-07-14 15:48:28 +02:00
Aliaksandr Kalenik
7e333cdcf7 LibWeb: Separate device pixel conversion helpers from PaintContext
In the upcoming change, device pixel conversion of ClipFrame will
happen during display list replay, where PaintContext is not available,
so let’s move it out of PaintContext.
2025-07-14 15:48:28 +02:00
Jelle Raaijmakers
4c88c7445c LibCore: Remove EventReceiver's event filter
This went unused.
2025-07-14 11:54:57 +01:00
Andreas Kling
11fa5fdd47 LibWeb: Honor box-sizing for block-level replaced element widths
Before this change, we were always behaving as if box-sizing were
content-box for block-level replaced element widths.

This fixes the squishy logo on https://videolan.org/
2025-07-14 11:16:13 +02:00
Ryan Liptak
6da1dfa8f2 LibWeb/HTML: Improve data structure of named character reference data
Introduces a few ad-hoc modifications to the DAFSA aimed to increase
performance while keeping the data size small.

- The 'first layer' of nodes is extracted out and replaced with a lookup
  table. This turns the search for the first character from O(n) to O
  (1), and doesn't increase the data size because all first characters
  in the set of named character references have the
  values 'a'-'z'/'A'-'Z', so a lookup array of exactly 52 elements can
  be used. The lookup table stores the cumulative "number" fields that
  would be calculated by a linear scan that matches a given node, thus
  allowing the unique index to be built-up as normal with a O(1) search
  instead of a linear scan.
- The 'second layer' of nodes is also extracted out and searches of the
  second layer are done using a bit field of 52 bits (the set bits of
  the bit field depend on the first character's value), where each set
  bit corresponds to one of 'a'-'z'/'A'-'Z' (similar to the first
  layer, the second layer can only contain ASCII alphabetic
  characters). The bit field is then re-used (along with an offset) to
  get the index into the array of second layer nodes. This technique
  ultimately allows for storing the minimum number of nodes in the
  second layer, and therefore only increasing the size of the data by
  the size of the 'first to second layer link' info which is 52 * 8 =
  416 bytes.
- After the second layer, the rest of the data is stored using a
  mostly-normal DAFSA, but there are still a few differences:
   - The "number" field is cumulative, in the same way that the
     first/second layer store a cumulative "number" field. This cuts
     down slightly on the amount of work done during the search of a
     list of children, and we can get away with it because the
     cumulative "number" fields of the remaining nodes in the DAFSA
     (after the first and second layer nodes were extracted out) happens
     to require few enough bits that we can store the cumulative version
     while staying under our 32-bit budget.
   - Instead of storing a 'last sibling' flag to denote the end of a
     list of children, the length of each node's list of children is
     stored. Again, this is mostly done just because there are enough
     bits available to do so while keeping the DAFSA node within 32
     bits.
   - Note: Together, these modifications open up the possibility of
     using a binary search instead of a linear search over the
     children, but due to the consistently small lengths of the lists
     of children in the remaining DAFSA, a linear search actually seems
     to be the better option.

The new data size is 24,724 bytes, up from 24,412 bytes (+312, -104 from
the 52 first layer nodes going from 4-bytes to 2-bytes, and +416 from
the addition of the 'first to second layer link' data).

In terms of raw matching speed (outside the context of the tokenizer),
this provides about a 1.72x speedup.

In very named-character-reference-heavy tokenizer benchmarks, this
provides about a 1.05x speedup (the effect of named character reference
matching speed is diluted when benchmarking the tokenizer).

Additionally, fixes the size of the named character reference data when
targeting Windows.
2025-07-14 09:43:08 +02:00
Aliaksandr Kalenik
9bb5e70f5a LibWeb: Skip tree traversal if invalidation set doesn't have properties
This allows us to skip unnecessary tree traversal to mark style for
recalculation when invalidation set only has `InvalidateSelf`.
2025-07-14 09:32:05 +02:00
Tim Ledbetter
80ccb12a12 LibWeb: Don't crash when appending to an XML document template element
When the XML parser appends child nodes to a template element, it must
actually append the template element's contents. This special behavior
caused us to return to the wrong parent element after adding child
nodes to a template element, leading to a crash.
2025-07-14 09:15:41 +02:00
Callum Law
7cc718f1c1 LibWeb: Avoid vector creation getting {short,long}hands for CSS property
The `shorthands_for_longhand`, `longhands_for_shorthand`, and
`expanded_longhands_for_shorthand` methods can be pretty hot in
profiles where we serialize a lot of CSS properties.

By returning a const reference to a static vector instead of allocating
and returning a new vector every time we can avoid a decent amount of
work.

Overall runtime for the particularly serialization heavy
wpt.live/css/cssom/cssom-getPropertyValue-common-checks.html
decreased by ~20% comparing before and after this change.
2025-07-14 09:08:55 +02:00
Luke Wilde
a3cacbfaaa Meta/curl: Add upstream patch for issue 17917
See: https://github.com/curl/curl/issues/17917

This allows us to connect to https://developer.mozilla.org/ with
HTTP/3 enabled.

Thanks to Tim Ledbetter (https://github.com/tcl3) for finding that we
couldn't connect!
2025-07-13 20:54:45 +02:00
Aliaksandr Kalenik
f65db4507a UI+WebContent: Add menu option to dump display list 2025-07-13 19:15:05 +02:00
Aliaksandr Kalenik
8ae7417445 LibWeb: Add internals call to dump display list
It's useful to have tests that dump display list items, so we can more
easily see how changes to the display list recording process affect the
output. Even the small sample test added in this commit shows that we
currently record an unnecessary AddClipRect item for empty paint phases.

For now, the dump doesn't include every single property of an item, but
we can shape it to include more useful information as we iterate on it.
2025-07-13 19:15:05 +02:00
Aliaksandr Kalenik
6be559f639 AK: Define ConstIterator for SegmentedVector 2025-07-13 19:15:05 +02:00
Tim Ledbetter
941da11ece LibWeb: Avoid accessing opaque origin port during CSP checks 2025-07-13 14:33:33 +02:00
Tim Ledbetter
cd0cadc5e1 LibWasm: Use correct null check when getting iterator method 2025-07-13 11:28:19 +02:00
Tim Ledbetter
5478361ba0 LibWeb: Avoid division by zero with small aspect ratios 2025-07-13 05:41:48 +02:00
Tim Ledbetter
cd0074528e LibWeb: Verify type before casting PaintableBox to PaintableWithLines
Previously, calling `BlockContainer::paintable_with_lines()` would cast
a `PaintableBox` to a `PaintableWithLines` without verifying that the
cast was valid, which isn't the cast for `FieldsetPaintable`, for
example. This method now returns null if it isn't poossible to cast to
`PaintableWithLines`.
2025-07-13 03:01:59 +02:00
Aliaksandr Kalenik
4f9aca4302 LibWeb: Skip backing store allocation for traversables created for SVG
Recently, we moved the backing store manager into Navigable, which means
we now try to allocate a backing store for all navigables, including
those corresponding to SVG image documents. This change disables that
behavior for all navigables except top-level non-SVG traversables,
because otherwise it causes issues when we stop repainting: the browser
process was notified about an allocated backing stores that does not
correspond to the page, and then all subsequent repaints are ignored
until the window is resized.
2025-07-13 00:06:30 +02:00
Jelle Raaijmakers
1e0013a3bc LibWeb: Use margin box height for inline-block vertical alignment
For `vertical-align: middle` and `vertical-align: text-bottom`, we used
just the content height of the inline box to determine its alignment
position. This caused incorrect positioning when padding is applied.

This fixes the button alignment on our GitHub page.

Fixes #290.
2025-07-12 18:03:14 +02:00
Andreas Kling
8e49b69f42 LibWeb: Never split <svg> for inline continuations
This fixes an issue where we'd make an absolute mess from nested SVG
roots with display:block. Before this fix, the inner SVG root would
trigger the inline continuation logic and try to split the tree.
2025-07-12 14:11:41 +02:00
Andreas Kling
4e23882995 LibWeb: Use foreignObject's own size as available space inside it
This ensures that percentages resolve against the foreignObject's size
instead of the size of its containing block.

This makes user profile pictures clip correctly in the "Friends" view
of the Discord app.
2025-07-12 14:11:41 +02:00
Jelle Raaijmakers
c39edfab2d Tests: Fix calculation of elapsed time in tests
We were already taking the "elapsed" part of the global timer, by
subtracting the known runtime from that we always ended up with 0
milliseconds.
2025-07-12 14:05:32 +02:00
Tim Ledbetter
4dd538e708 LibWeb/SVG: Prefer href to xlink:href attribute on images 2025-07-12 13:13:47 +02:00
Tim Ledbetter
93a35895ae LibWeb/SVG: Don't crash when changing SVG image href
Previously, a segfault could occur if `m_resource_request` was replaced
before its callbacks were invoked.
2025-07-12 13:13:47 +02:00
Ali Mohammad Pur
5b45223d5f LibRegex: Account for uppercase characters in insensitive patterns 2025-07-12 11:26:23 +02:00
Tim Ledbetter
31e8189f9f LibWeb/SVG: Implement the SVGAElement.referrerPolicy attribute 2025-07-12 11:05:48 +02:00
Tim Ledbetter
d86f0a1b29 LibWeb/SVG: Implement the SVGAElement.target attribute 2025-07-12 11:05:48 +02:00
Aliaksandr Kalenik
910fd426a2 LibWeb: Allow <svg> to establish a stacking context
83b6bc4 went too far by forbidding SVGSVGElement from establishing a
stacking context. This element type does follow the behavior of CSS
boxes, unlike inner SVG elements like `<rect>`, `<circle>`, etc., which
are not supposed to be aware of concepts like stacking contexts,
overflow clipping, scroll offsets, etc.

This change allows us to delete overrides of `before_paint()` and
`after_paint()` in SVGPaintable and SVGSVGPaintable, because display
list recording code has been rearranged to take care of clipping and
scrolling before recursing into SVGSVGPaintable descendants.

`Screenshot/images/css-transform-box-ref.png` expectation is updated and
fixes a bug where a rectangle at the very bottom of the page was not
clipped correctly.
`Screenshot/images/svg-filters-lb-website-ref.png` has a more subtle
difference, but if you look closely, you’ll see it matches other
browsers more closely now.
2025-07-12 11:01:15 +02:00
Shannon Booth
79293a3cbc LibWeb/XHR: Don't construct a String from a String
Serializing a URL already returns a String.
2025-07-12 02:57:36 +01:00
Luke Wilde
f50f23b19f LibWeb/CSP: Implement the script-src-attr directive 2025-07-12 13:06:33 +12:00
Luke Wilde
f382bccc3d LibWeb/CSP: Implement the script-src-elem directive 2025-07-12 13:06:33 +12:00
Tim Ledbetter
caf45f2317 LibWeb: Implement the SVGGeometryElement.pathLength attribute 2025-07-12 11:49:10 +12:00
Aliaksandr Kalenik
410e82c9fd LibWeb: Rearrange code such that a lot less files include Command.h
With this change number of recompiled files after modification of
`Command.h` goes down from >1000 to <100.
2025-07-11 17:37:27 +02:00
Callum Law
d980321a77 LibWeb: Include own shadow root in for_each_shadow_including_descendant
Fixes a crash in wpt.live/css/cssom/CSSStyleSheet-constructable.html
2025-07-11 16:21:11 +02:00
Luke Wilde
409758f040 Meta: Enable the zstd feature for curl
This content encoding is used by Facebook.

For example:

```
> GET /rsrc.php/v5/yj/l/0,cross/VNfVTw9fSM1.css HTTP/3
Host: static.xx.fbcdn.net
Accept-Encoding: deflate, gzip, br, zstd
Alt-Used: (nil):0
User-Agent: Mozilla/5.0 (macOS; AArch64) Ladybird/1.0
Accept: text/css,*/*;q=0.1
Accept-Language: en
Sec-Fetch-Dest: style
Sec-Fetch-Mode: cors
Origin: https://www.facebook.com
Sec-Fetch-Site: cross-site
Referer: https://www.facebook.com/
```

The response (with some headers removed for brevity):
```
< HTTP/3 200
< content-encoding: zstd
< content-type: text/css; charset=utf-8
< last-modified: Mon, 01 Jan 2001 08:00:00 GMT
< expires: Fri, 10 Jul 2026 07:47:17 GMT
< cache-control: public,max-age=31536000,immutable
< content-length: 7448
< date: Fri, 11 Jul 2025 11:52:03 GMT
< access-control-allow-origin: https://www.facebook.com
* Added alt-svc: static.xx.fbcdn.net:443 over h3
< alt-svc: h3=":443"; ma=86400
< priority: u=3,i
<
```
2025-07-11 14:16:07 +02:00
Jelle Raaijmakers
0fccc75fd7 Meta: Remove bookmarks.json
This seems to be unused.
2025-07-11 14:04:23 +02:00
Jelle Raaijmakers
97fa0be16e LibWeb: Implement SVGAnimatedNumber 2025-07-11 11:25:59 +01:00
Jelle Raaijmakers
ffcf91cd30 LibWeb: Correct initialization order for SVGFE*Element
We should first set the prototype before initializing our base,
otherwise e.g. attributes will simply not work.
2025-07-11 11:25:59 +01:00
Callum Law
1a0d4487a8 LibWeb: Implement matches attribute on CSSSupportsRule and CSSMediaRule
Gains us 4 WPT tests.
2025-07-11 10:57:19 +02:00
Callum Law
fc395f9824 Tests: Always load WPT interfaces from root interfaces directory
Previously we would load from "../interfaces" which wouldn't work for
nested tests.
2025-07-11 10:57:19 +02:00
ayeteadoe
ccb87b4cb4 Tests/LibGfx: Enable file based tests on Windows
These actually were always working since we first enabling LibGfx
on Windows. I was just running them outside of the ctest context
and therefore had the wrong working directory so the test-inputs folder
could not be found
2025-07-11 10:54:37 +02:00
Tim Ledbetter
88efb362c4 LibWeb: Remove UA styles for h1 in article, aside, nav and section 2025-07-11 08:24:32 +02:00
Jelle Raaijmakers
2998049fe9 LibWeb: Implement the unreachable scrollable overflow
Whenever we end up with a scrollable overflow rect that goes beyond
either of its axes (i.e. the rect has a negative X or Y position
relative to its parent's absolute padding box position), we need to clip
that rect to prevent going into the "unreachable scrollable overflow".

This fixes the horizontal scrolling on https://ladybird.org (gets more
pronounced if you make the window very narrow).
2025-07-11 08:23:46 +02:00
Shannon Booth
05ddf5c718 LibWeb/DOM: Add StorageEvent and DragEvent to Document.createEvent
We have since implemented these interfaces.
2025-07-11 08:22:36 +02:00
Shannon Booth
1d5ca2ae80 Tests/LibWeb: Import WPT Document-createEvent WPT tests 2025-07-11 08:22:36 +02:00
Andrew Kaster
c2a37e693c Utilites: Remove extra dashes from raw strings argument to js 2025-07-10 16:28:40 -06:00
Olekoop
d6ea941208 Meta: Fix linker issue when compiling for Android 2025-07-10 15:44:53 -06:00
Olekoop
f26a898ffc Android: Workaround the system certificate issue
Due to removal of local ca-certificates we need to use system's
certificate. However, on Android it is stored in multiple files.
Ladybird doesn't support multiple certificates yet, so we just
concatenate all of them into one big file.
2025-07-10 15:44:53 -06:00
Olekoop
0738852466 Documentation: Update the version of Android Studio 2025-07-10 15:44:53 -06:00
Olekoop
e65a38bb0e Meta: Enable Vulkan and ANGLE when compiling for Android
Vulkan seems to have been disabled due to not being able to compile.
However, it compiles on my machine and it works on my phone.

As for ANGLE, someone just forgot about Android.
2025-07-10 15:44:53 -06:00
Olekoop
af2d46bd3d LibMedia+Meta: Enable FFmpeg under Android and remove the stubs
The licensing issue seems to be resolved (#2214).
The stubs are not longer necessary. Even if they were, they do not
compile properly.
2025-07-10 15:44:53 -06:00
Olekoop
a70fade461 Documentation: Remove metions about Android port not working 2025-07-10 15:44:53 -06:00
Olekoop
f6c90d00a9 Meta: Don't compile libproxy for Android
libproxy isn't availiable for Android.
2025-07-10 15:44:53 -06:00
Olekoop
4b384a3593 Meta: Add a workaround when compiling for Android
We shouldn't do any of this but it's necessary in order to link it
properly.
2025-07-10 15:44:53 -06:00
Olekoop
834eb04d33 ImageDecoder: Make it compile for Android 2025-07-10 15:44:53 -06:00
Olekoop
6f350c51fd Android: Keep up with the times
While some of the changes are due to syntax and have no effect on
the functionality, others are more important.

The major changes are
- Use Painter instead of now removed DeprecatedPainter
- Remove the need of LibArchive by using Java's native zip support
- Have a proper C++23 compiler by updating NDK to r29 beta 2
- Store user data and config in an user accessible way
- Update AGP to 8.11 and update compile target to SDK level 35
2025-07-10 15:44:53 -06:00
Jelle Raaijmakers
c99a467cdb LibWeb: Do not crash when navigating to mailto: links
We forgot to implement a couple of "otherwise," statements from the
"populating a session history entry" spec. While we're here, let's
update the spec copy where relevant.
2025-07-10 22:43:30 +02:00
Jelle Raaijmakers
d822b96786 LibWeb: Remove setting the Skia backend context in Navigable
This is unused. The backend context is also referenced in the Skia
player, which we move to the rendering thread.
2025-07-10 15:27:58 +02:00
Shannon Booth
bd6581fe22 LibRegex: Correctly use ClassSetReservedPunctuator in ClassSetCharacter
We had typo'd using ClassSetReservedDoublePunctuator which was
resulting in a parse error for the regex:

([^\\:]+?)

With the 'v' flag set.

Co-Authored-By: Ali Mohammad Pur <mpfard@serenityos.org>
2025-07-10 11:41:02 +02:00
Jelle Raaijmakers
3a232880ed Meta: Remove Polar from FUNDING.yml and FAQ.md
The issue bounty system was discontinued, so remove it from our GitHub
repo's sponsoring links and documentation.
2025-07-10 10:04:33 +02:00
Lucien Fiorini
8b1f1ae87a js: Rename the --disable-string-quotes flag to --raw-strings
Since it does more than removing the quotes by escaping the string too
It makes sense to change the name of the flag to something more close
to what it's really doing.
2025-07-09 18:30:02 -06:00
Lucien Fiorini
8caa7c89cf js: Safely acquire print target AK::Stream
Flush the buffered output stream before acquiring an unbuffered
AK::Stream and add support for newline within the print function.
2025-07-09 18:30:02 -06:00
ayeteadoe
8b778de36b Meta: Update vcpkg for patched libjxl port and remove our overlay port 2025-07-09 17:52:32 -06:00
Ben Eidson
3aff12bbab LibWeb/WebAudio: Implement AudioNode::disconnect()
Destubs AudioNode::disconnect() and its related overloads.

Ensures that inverse connections are properly removed
when disconnecting AudioNodeConnections. Adds associated
WPT but skips them for now because they rely on
OfflineRenderContext::start_rendering to be fully implemented.
2025-07-09 17:52:06 -06:00
ayeteadoe
75d26b1610 CMake: Improve preset display names and descriptions
Now all configure and build presets have consistently formatted
display names with useful content
2025-07-09 16:26:59 -06:00
Andrew Kaster
fa003fb2b0 LibTest: Move declaration of JS main target around to avoid CMake bug
For some reason, with CMake 4.0.3 and the Swift language enabled, this
target was getting random tokens in the compile commands. Moving it up
to the top of the file seems to fix this.
2025-07-09 16:26:49 -06:00
Andrew Kaster
a0b902cca1 CMake: Set visibility flags with add_cxx_compile_options() helper
This makes the flags not break Swift builds
2025-07-09 16:26:49 -06:00
Andrew Kaster
3040ca4311 LibWeb: Remove noisy debug messages from HTMLParser 2025-07-09 16:26:49 -06:00
Andrew Kaster
ce01236000 Meta: Update swift version to 2025-06-22 2025-07-09 16:26:49 -06:00
Tim Ledbetter
438bb56160 LibWeb/SVG: Don't crash when a filter has no valid effects 2025-07-10 00:18:25 +02:00
Luke Wilde
0cff47828d LibWeb/CSP: Implement the script-src directive 2025-07-09 15:52:54 -06:00
Luke Wilde
3d43462ccd LibJS: Implement the Dynamic Code Brand Checks stage 3 proposal
This is an active proposal at stage 3 of the TC39 proposal process.
See: https://tc39.es/proposal-dynamic-code-brand-checks/
See: https://github.com/tc39/proposal-dynamic-code-brand-checks

This proposal essentially adds support for the TrustedScript type from
the Trusted Types specification to eval and Function. This in turn
pipes support for the type into the CSP hook to check if the CSP allows
dynamic code compilation.

However, it currently doesn't support ShadowRealms, so the
implementation here is a close approximation, using PerformEval as the
basis.
See: https://github.com/tc39/proposal-dynamic-code-brand-checks/issues/19

This is required to support the new function signature for the CSP
hook, and will allow us to slot in Trusted Types support in the future.
2025-07-09 15:52:54 -06:00
Luke Wilde
2368641de5 LibWeb: Track if element was created from token with dupe attributes
This is required for CSP to ignore the nonce attribute to prevent
duplicate attributes hijacking the attribute.

See https://w3c.github.io/webappsec-csp/#security-nonce-hijacking
2025-07-09 15:52:54 -06:00
Andrew Kaster
b6b030aa43 CI: Update preset name for test262 job 2025-07-09 23:41:58 +02:00
Jelle Raaijmakers
37b8ab54df CI+CMake: Remove most of the *_CI CMake presets
These existed because of their `vcpkg_ci` base preset, whose goal was to
enable vcpkg-supported caching on GitHub. We now handle vcpkg caching in
the CI steps, removing the necessity for all these *_CI preset variants.

This allows us to reuse `inputs.build_preset` in the test step, and we
can do away with the Windows-specific test step since it is now almost
identical to the Linux/macOS test step.

I've left in the Windows_CI presets, because that one actually results
in a different set of compiled files compared to the
Windows_Experimental presets.
2025-07-09 15:32:57 -06:00
Jelle Raaijmakers
4a57fe4392 CI+CMake: Enable vcpkg source assets cache
I've set up a shared vcpkg source assets cache using Azurite. By
default, it runs in read-only mode allowing anyone who builds Ladybird
to use the cache to speed up downloads of source tarballs. This should
alleviate some of the more slower vcpkgs downloads I've been seeing
lately.

CI runs on master put vcpkg in readwrite mode, updating the cache for
everyone.
2025-07-09 15:32:57 -06:00
Jelle Raaijmakers
de36d9fb85 CI: Unify the Linux/macOS/Windows build steps
For macOS, we now default to ENABLE_QT=OFF and use the same build step
as for the other platforms. We keep a single separate macOS + Qt build
step to prevent bitrotting that part of the code.

The Windows step ran in a different directory and skipped the install
step; we can just use the Linux behavior here.
2025-07-09 15:32:57 -06:00
Luke Wilde
08a03534af Meta+RequestServer: Enable HTTP/3 for curl
This adds an overlay port for curl that adds the features required for
HTTP/3.

This is not quite compatible with the upstream vcpkg.json, because
enabling HTTP/2 makes it use the default SSL backend, which is
sectransp for macOS and schannel on Windows. These backends are not
compatible with ngtcp2. Additionally, we can not build curl with
multiple SSL backends when using ngtcp2.

I couldn't find a way to selectively disable/enable dependencies based
on what features are enabled, so I made HTTP/2 pick OpenSSL in our
overlay port. Upstream vcpkg will likely want to support wolfSSL and
GnuTLS backends for ngtcp2, so they'll be additional work to get this
into upstream.
2025-07-09 14:44:56 -06:00
Luke Wilde
993d8df29b Meta: Add overlay port for curl
This will be used to add HTTP/3 support.
2025-07-09 14:44:56 -06:00
Tim Ledbetter
c4cf1ccede LibWeb: Don't crash when parsing ASF with non comma-separated arguments 2025-07-09 19:47:12 +01:00
Aliaksandr Kalenik
193900d661 LibWeb: Cache compiled shaders for masks in DisplayListPlayerSkia
By avoiding recompilation every time `apply_mask_bitmap()` is called, we
save ~5 ms (20ms -> 15ms) in rendering of browser channel on Discord on
my machine.
2025-07-09 19:21:31 +02:00
Lucien Fiorini
4711c38aa1 Tests: Add screenshot test for the background SVG in the LB website 2025-07-09 18:07:12 +01:00
Lucien Fiorini
635adc8aa7 LibWeb/SVG: Implement resolution for a subset of SVG filters 2025-07-09 18:07:12 +01:00
Lucien Fiorini
5d85959f5f LibWeb/SVG: Add FEGaussianBlurElement 2025-07-09 18:07:12 +01:00
Lucien Fiorini
f8b12614df LibWeb/SVG: Add FEBlendElement 2025-07-09 18:07:12 +01:00
Lucien Fiorini
d3684a36b0 LibWeb/SVG: Add FEFloodElement 2025-07-09 18:07:12 +01:00
Lucien Fiorini
de271b16fc LibWeb/SVG: Add FilterPrimitiveStandardAttributes 2025-07-09 18:07:12 +01:00
Lucien Fiorini
6fb75b5ba9 LibWeb/SVG: Add filter primitive attributes 2025-07-09 18:07:12 +01:00
Callum Law
a8fc15c6b3 LibWeb: Don't fail on non-fill keyword parsing <border-image-slice>
Previously if we encountered a keyword other than `fill` when parsing
`<border-image-slice` we would return a nullptr.

This could cause issues when we parse `<border-image-slice>` as part of
parsing `border-image`, for example `border-image: 100% none` would fail
as we would try parse `none` as part of the `<border-image-slice>`
instead of `<border-image-source>`.

This change makes it so that we don't consume the token and leave it to
be parsed as part of the next section of the grammar.
2025-07-09 16:59:22 +01:00
Callum Law
cfafb3bf36 LibWeb: Remove unused code in for_each_property_expanding_shorthands
This case is already handled by this point as `value` is a shorthand.

No functionality changes.
2025-07-09 16:59:22 +01:00
Sam Atkins
ce79bc793c LibWeb/CSS: Protect against the billion-laughs attack
The attack unfortunately still slows us down, but this prevents us from
OOMing. Currently, we don't save the value of `var(--foo)` after
computing it once, so in this example, we end up computing `--prop1` 4
times to compute `--prop3`, but then we start again from scratch when
computing `--prop4`:

```css
  --prop1: lol;
  --prop2: var(--prop1) var(--prop1);
  --prop3: var(--prop2) var(--prop2);
  --prop4: var(--prop3) var(--prop3);
}
```

This should be solvable later if we update the computed values as we go.
2025-07-09 16:44:20 +01:00
Sam Atkins
b6032b0fcd LibWeb/CSS: Reimplement var()/attr() as arbitrary substitution functions
"Arbitrary substitution functions" are a family of functions that
includes var() and attr(). All of them resolve to an arbitrary set of
component values that are not known at parse-time, so they have to be
substituted at computed-value time.

Besides it being nice to follow the spec closely, this means we'll be
able to implement the others (such as `if()` and `inherit()`) more
easily.

The main omission here is the new "spread syntax", which can be
implemented in the future.
2025-07-09 16:44:20 +01:00
Sam Atkins
b417d13a7b LibWeb/CSS: Add method to parse <declaration-value>
This has an extra parameter to allow stopping at the first comma token,
which we need for var() and attr()'s "argument grammar".

Co-authored-by: Tim Ledbetter <tim.ledbetter@ladybird.org>
2025-07-09 16:44:20 +01:00
Sam Atkins
26acd897bf LibWeb: Produce computed values for custom properties
Custom properties are required to produce a computed value just like
regular properties. The computed value is defined in the spec as
"specified value with variables substituted, or the guaranteed-invalid
value", though in reality all arbitrary substitution functions should be
substituted, not just `var()`.

To support this, we parse the CSS-wide keywords normally in custom
properties, instead of ignoring them. We don't yet handle all of them
properly, and because that will require us to cascade them like regular
properties. This is just enough to prevent regressions when implementing
ASFs.

Our output in this new test is not quite correct, because of the awkward
way we handle whitespace in property values - so it has 3 spaces in the
middle instead of 1, until that's fixed.

It's possible this computed-value production should go in
cascade_custom_properties(), but I had issues with that. Hopefully once
we start cascading custom properties properly, it'll be clearer how
this should all work.
2025-07-09 16:44:20 +01:00
Sam Atkins
1ff1093a24 LibWeb: Define a PropertyIDOrCustomPropertyName type
We often want to identify a property, but if we have a PropertyID we
don't want to have to convert it to a string to then convert it back
again. However, custom properties don't have a useful PropertyID. So,
here's a type with a verbose name.
2025-07-09 16:44:20 +01:00
Sam Atkins
cd4ea67706 LibWeb/DOM: Add custom-property helpers to AbstractElement 2025-07-09 16:44:20 +01:00
Sam Atkins
97ad1ea7e0 LibWeb/DOM: Don't crash getting custom properties from invalid pseudos 2025-07-09 16:44:20 +01:00
Sam Atkins
9079be850b LibWeb/CSS: Include guaranteed-invalid value in ComponentValue
Treating these like any other ComponentValue means not having to convert
between different types of Vector, and that we will be able to use
TokenStream to parse the "argument grammars" of arbitrary substitution
functions.
2025-07-09 16:44:20 +01:00
Sam Atkins
b5ed910f1f LibWeb: Rename "var_or_attr" to "arbitrary_substitution_function"
This is the spec term, and will apply to many more things than var() and
attr().
2025-07-09 16:44:20 +01:00
Sam Atkins
8f01297182 LibWeb: Remove now-invalid attr() type support
Previously the type argument in attr() could be the name of a CSS type
on its own. This has changed, and now only `raw-string`
(previously `string`) or the name of a dimension unit is allowed. Other
types and more complex grammar use the `type()` function, which we
don't yet support.

I've updated the syntax comment, but not the algorithm itself, which
will be reimplemented in a later commit.
2025-07-09 16:44:20 +01:00
Sam Atkins
58fa9ddc29 Tests: Remove unused parts of css-attr-typed layout test
Having <link rel=match> in here is confusing. I've also removed the uses
of `length` and `color` as types, as this is no longer valid according
to the spec.
2025-07-09 16:44:20 +01:00
Sam Atkins
59f2c8df7a Tests: Import some custom-property tests
To make it easier to track progress and regressions in subsequent
changes.
2025-07-09 16:44:20 +01:00
Sam Atkins
a6ff088984 LibWeb/CSS: Stop converting at-rule names to lowercase
This basically reverts a6efdb1068.

The test added there still passes without the ad-hoc behaviour, so let's
remove it.
2025-07-09 15:04:57 +01:00
Sam Atkins
d5bee680b0 LibWeb/CSS: Construct all CSS Tokens in a consistent way
Add `create_foo()` static methods for the missing Token::Types, and use
them in the Tokenizer. This means we slightly deviate from the spec now:
it says "create foo token... set its bar to 32", but we now just wait
and construct the Token fully-formed. But those cases are short so it
should still be clear what we're doing.

This makes it possible to construct all kinds of Token elsewhere, such
as for testing purposes.
2025-07-09 15:04:57 +01:00
Tim Ledbetter
57dd85e4ac LibWeb/DOM: Throw errors from correct realm in Node::move_node() 2025-07-09 15:59:06 +02:00
Andreas Kling
aae0b52403 LibWeb: Resolve mask/clip in foreignObject's own coordinate space
We were neglecting to resolve these correctly, which caused them to get
the same metrics as the nearest viewport above the foreignObject.
2025-07-09 14:36:08 +02:00
Andreas Kling
f5f3cd041a LibWeb: Apply SVG viewbox transform to foreignObject elements 2025-07-09 14:36:08 +02:00
Andreas Kling
f343a418b2 LibWeb: Never split SVG foreignObject for inline continuations
This would produce a bizarre layout tree and certainly not yield
expected results.
2025-07-09 14:36:08 +02:00
Andreas Kling
b4708510fb LibWeb: Layout foreignObject as block-level element with hidden overflow
This is according to the default user-agent style from the SVG2 spec.

In order for this to work correctly, we also have to assign width and
height to foreignObject boxes during SVG layout, since they are handled
manually by SVGFormattingContext.
2025-07-09 14:36:08 +02:00
Andreas Kling
b3fd939628 LibWeb: Make sure we run selectors for mixed-case tag names
Before this change, we would never apply CSS rules where the selector
had a mixed-case tag name. This happened because our rule caches would
key them on the lowercased tag name, but we didn't lowercase the tag
name when fetching things from the cache.

This uncovered the fact that the SVG2 spec has a bunch of style applied
to non-rendered elements in a way that doesn't match other browsers.
Instead of blindly following the spec, we now match other browsers.
2025-07-09 14:36:08 +02:00
Andreas Kling
61df035612 LibWeb: Show element namespace URI in DOM tree dumps
This is helpful when debugging SVG-in-HTML content.
2025-07-09 14:36:08 +02:00
Andreas Kling
ddcb87fb40 LibWeb: Make TreeBuilder nicer to SVG foreignObject
This patch does two things:

1. Makes TreeBuilder never cross the foreignObject boundary when looking
   for an appropriate insertion parent. Before this change, we would
   sometimes make things inside the foreignObject DOM subtree have
   layout nodes outside the foreignObject.

2. Makes foreignObject boxes participate in the anonymous wrapping of
   inline-level boxes. This is particularly imporant for absolutely
   positioned elements inside foreignObject, which were previously
   getting incorrectly wrapped if there was any text (even empty)
   preceding the abspos element.
2025-07-09 14:36:08 +02:00
Andreas Kling
07838016c8 LibWeb: Make layout code aware that we create BFC for foreignObject
We were already always doing this, but through an unusual mechanism:
SVG layout creates a BFC on the stack when laying out foreignObject
subtrees.

This change makes the rest of the layout system aware of this, and
also allows it to be reflected in layout dumps.
2025-07-09 14:36:08 +02:00
Andreas Kling
0cf9a4543a LibWeb: Make SVG foreignObject establish a new stacking context
This matches the behavior of Blink and Gecko, but not WebKit.
2025-07-09 14:36:08 +02:00
Andreas Kling
dab1fd265d test-web: Dump stacking context tree in layout test output
This will allow us to test (and catch regressions in) stacking context
tree construction and updates, etc.
2025-07-09 14:36:08 +02:00
Callum Law
f46bd7f5eb LibWeb: Create enum for <line-width> keywords 2025-07-09 13:28:12 +02:00
Sam Atkins
0809eacd97 LibWeb/CSS: Update definition for cursor property
No functional changes. The main difference is renaming the cursor enum
to match the spec term `<cursor-predefined>`, which is a bit more
verbose but clearer in meaning.

Corresponds to 1a57a4025c
2025-07-09 13:21:26 +02:00
Veeti Paananen
c3e470569e LibWeb: Preserve File last modified timestamp in FormData copies
+1 WPT pass
2025-07-09 10:20:52 +01:00
Callum Law
da40419c5b LibWeb: Support border-{block,inline} shorthands
Gains us 4 WPT tests
2025-07-09 10:10:38 +01:00
Callum Law
d280cf56e6 LibWeb: Handle border-{inline,block}-* properties with a single value
Gains us 14 WPT tests
2025-07-09 10:10:38 +01:00
Callum Law
ceb1c37ba3 LibWeb: Import CSS logical border property parsing WPT tests 2025-07-09 10:10:38 +01:00
Callum Law
7d50dba3fc LibWeb: Deduplicate logic in for_each_property_expanding_shorthands 2025-07-09 10:10:38 +01:00
Callum Law
56c68aedea LibWeb: Remove special parsing of physical border longhands
Parsing of these properties is handled by the default behaviour.

No functionality changes.
2025-07-09 10:10:38 +01:00
Shannon Booth
24d522afce LibWeb/DOM: Avoid passing null to valid name prefix
Applies spec change of https://github.com/whatwg/dom/commit/1b4bd48
which we already happened to be doing to avoid crashing.
2025-07-09 10:57:14 +02:00
Shannon Booth
642a2430a9 LibWeb/DOM: Properly extract local name and prefix from strict split
Previously we were taking the local name from everything after the
first ':', instead of second element of strictly splitting qualified
name.
2025-07-09 10:57:14 +02:00
Shannon Booth
f263a1a6b2 Tests/LibWeb: Rebaseline createElement and createElementNS WPT tests
These tests were previously not aligned against the DOM standard.
2025-07-09 10:57:14 +02:00
Shannon Booth
ab2e732da9 Tests/LibWeb: Import DOM name validation WPT test 2025-07-09 10:57:14 +02:00
Veeti Paananen
c834c594ac LibWeb: Set correct content and document types in DOMParser
It appears this was removed by accident in an earlier commit, regressing
the included WPT test.
2025-07-09 20:10:11 +12:00
Aliaksandr Kalenik
bfa978c501 LibWeb: Remove unnecessary save/restore generated for stacking context 2025-07-08 23:54:35 +02:00
Aliaksandr Kalenik
8d9920af16 LibWeb: Account for natural aspect ratio in calculate_min_content_height
By the time we calculate the min-content height, the width is already
known, so we can use it to calculate the height based on the natural
aspect ratio.
2025-07-08 22:35:04 +02:00
Andrew Kaster
44d2e22b93 CMake: Add a flatpak build for org.ladybird.Ladybird
This build depends on the KDE Flatpak SDK, and builds any missing
dependencies manually as source modules.

The flatpak can be built with the following command:

```sh
flatpak-builder --user --force-clean --install-deps-from=flathub \
    --ccache --repo=Build/repo --install Build/flatpak \
    Meta/CMake/flatpak/org.ladybird.Ladybird.json
```

After building, the flatpak can be run with:

```sh
flatpak run --user --devel org.ladybird.Ladybird
```

If there are issues launching RequestServer, the .pid and .sock files
under $XDG_RUNTIME_DIR may need removed.

```sh
flatpak run --user --command=sh --devel org.ladybird.Ladybird
rm -f $XDG_RUNTIME_DIR/Ladybird.*
```
2025-07-08 11:45:32 -06:00
Andrew Kaster
204e787131 CMake: Add service, desktop, and icon files for Linux-like systems
These files are lifted from the ladybird-gtk4 repository and adapted
to work with the Qt UI port. They are installed by default on Linux, but
can be installed via a CMake option on other platforms.

Co-Authored-By: Sergey Bugaev <bugaevc@serenityos.org>
Co-Authored-By: Nicolas Ramz <nicolas.ramz@adevinta.com>
Co-Authored-By: Beckett Normington <beckett@b0ba.dev>
Co-Authored-By: Xexxa <93391300+Xexxa@users.noreply.github.com>
2025-07-08 11:45:32 -06:00
Sam Atkins
69d4811ef7 LibWeb: Generate logical property mappings
To support this, how we declare logical property aliases has changed.
Instead of `logical-alias-for` being a list of properties, it's now an
object with a `group` and `mapping`. The group is the name of a logical
property group in LogicalPropertyGroups.json. The mapping is which
side/dimension/corner this property is. Hopefully it's self-explanatory
enough.

The generated code is very much a copy of what was previously in
`StyleComputer::map_logical_alias_to_physical_property_id()`, so there
should be no behaviour change.
2025-07-08 11:45:15 -06:00
Andrew Kaster
4c48a51860 Tests: Disable TestTLSHandshake on Windows
This test can't find the default certs on Windows.
2025-07-08 10:27:05 -06:00
Callum Law
36e2d25efa LibWeb: Parse grid track placements closer to spec
This brings parsing of grid-row-* and grid-column-* properties (and
their associated shorthands) more inline with spec.

Changes:
- Only set omitted properties for combined-value shorthands (e.g.
  `grid-row: a` rather than `grid-row: a / b`) if the single value is
  `<custom-ident>`.

- `[ [ <integer [-∞,-1]> | <integer [1,∞]> ] && <custom-ident>? ]`:
  - Properly resolve `calc`s for `<integer>` that rely on compute-time
    information.

- `[ span && [ <integer [1,∞]> || <custom-ident> ] ]`
  - Allow `calc`s for `<integer>`
  - Allow `<custom-ident>`

There is still work to be done to properly use these parsed values.

Gains us 46 WPT tests.
2025-07-08 17:26:16 +01:00
Sam Atkins
a424a06d45 LibWeb/DOM: Copy document's allow declarative shadow roots when cloning
Corresponds to 77920094a4
2025-07-08 17:08:39 +01:00
Sam Atkins
5c365884dd LibWeb/HTML: Update HTMLScriptElement.idl to match current spec
Corresponds to e21d9ff0d6

As far as I can tell, none of the rest of this change requires
modifications on our end.
2025-07-08 17:08:39 +01:00
Sam Atkins
0cfa243baa LibWeb/HTML: Update "create policy container from fetch response" spec
Corresponds to 83cc45b9c5
2025-07-08 17:08:39 +01:00
Sam Atkins
0d34f70d95 LibWeb/HTML: Queue a task to resolve createImageBitmap
Corresponds to e288a0efe5
2025-07-08 17:08:39 +01:00
Sam Atkins
df2b2d2c14 LibWeb/HTML: Fix return value checking for unload cancellation
Corresponds to 4467ddf323
2025-07-08 17:08:39 +01:00
Sam Atkins
91e8a19391 LibWeb: Always set [[ErrorToRethrow]] for import validation errors
Corresponds to f6fb04a11f
2025-07-08 17:08:39 +01:00
Sam Atkins
4e854ca44a LibWeb/HTML: Provide a fallback for validation anchor
Corresponds to daa3016b40

Also import a related test.
2025-07-08 17:08:39 +01:00
Sam Atkins
da8a29376f LibWeb: Use ThrowCompletion AO to create throw completions
Corresponds to 4989b3457f
2025-07-08 17:08:39 +01:00
Sam Atkins
b05fe0127b LibWeb/HTML: Allow more characters in custom element names
Corresponds to 78d2678789

And import a related test.
2025-07-08 17:08:39 +01:00
Sam Atkins
af17f38bbf LibWeb/HTML: Implement and use "optional value"
Corresponds to f3444c23ff

Also import a test.
2025-07-08 17:08:39 +01:00
Sam Atkins
22cc36eeaa LibWeb/HTML: Replace "zero" with "0" in some places
Corresponds to 706b986010
2025-07-08 17:08:39 +01:00
Sam Atkins
e74afec9c5 LibWeb: Capitalize "No Popover state" consistently
Corresponds partly to 8035a256bf
2025-07-08 17:08:39 +01:00
Sam Atkins
31b302fc73 WebContent: Include pseudo-elements and custom properties in styles dump
Pseudo elements are only dumped if they have computed style.

Custom properties are only dumped on their originating element, because
of how we currently store them.
2025-07-08 16:49:22 +01:00
Timothy Flynn
8cec9e7557 LibJS+LibUnicode: Remove unused FormatNumericToString AO 2025-07-08 11:19:27 -04:00
Jelle Raaijmakers
b019633558 Meta: Disable clang-tidy's const correctness checks
Using `const` should not be warned about everywhere if it does not have
a clear advantages. Compilers are able to deduce constness in most cases
and on top of that, it's generally accepted that using `const`
communicates developer intent above all else.
2025-07-08 11:04:15 -04:00
Jelle Raaijmakers
e96fd53eda Revert "LibWebView: Add Arial Unicode MS to the list of Sans Serif (...)
(...) fallbacks"

This reverts commit 9e7b40747f. This
caused most bold headings to display as regular headings, since Arial
Unicode MS does not support other styles (as opposed to Arial).

We need a better font selection algorithm to properly support selecting
fonts for specific glyphs. Issue #2332 exists to keep track of
supporting less frequently used glyphs.
2025-07-08 09:17:32 -04:00
Jelle Raaijmakers
ead0a2c78a Everywhere: Rename serenity_main to ladybird_main
No functional changes.
2025-07-08 09:17:16 -04:00
Timothy Flynn
af671f58ed LibCore: Revert change to simplify tracking of notifers and poll structs
The issue with that refactor was that the same fd can be used in more
than one notifier. This reverts us back to using 2 members to track the
notifiers in play.
2025-07-08 13:53:27 +01:00
Sam Atkins
b711b01f76 LibWeb/CSS: Remove comment that free space is distributed
Corresponds to 24c1b60e9a
2025-07-08 10:24:49 +01:00
Sam Atkins
d9aeffa302 LibWeb/CSS: Adjust grammar definitions
Corresponds to:
e2903b127e
1b4ea44fc8
2025-07-08 10:24:49 +01:00
Aliaksandr Kalenik
b87e01e304 LibWeb: Skip recording display list items with color.alpha() == 0
Cuts display list size, mostly because now we avoid lots of FillRect
previusly recorded for boxes with transparent background.

Website      | DisplayList Items Before | DisplayList Items After
-------------|--------------------------|-------------------------
ladybird.org | 1431                     | 1117
null.com     | 4714                     | 4484
discord.com  | 5360                     | 4992
2025-07-08 10:24:11 +02:00
Aliaksandr Kalenik
46097c6753 LibWeb: Avoid unnecessary save/restore in paint_background()
`paint_background()` is invoked for each PaintableBox, so by avoiding
save/restore pair emitted for each call, we substantially decrease
display list size.

Website      | DisplayList Items Before | DisplayList Items After
-------------|--------------------------|-------------------------
ladybird.org | 2753                     | 1431
null.com     | 5298                     | 4714
discord.com  | 6598                     | 5360
2025-07-08 10:24:11 +02:00
Andrew Kaster
62c5f4b822 CMake: Remove unconditional Qt linkage from WebContent and WebWorker
WebContent only needs it when using QtMultimedia for audio playback, and
WebWorker never needs it.
2025-07-07 15:53:15 -06:00
Timothy Flynn
a9f7579738 LibCore: Awaken read notifiers when we receive POLLHUP events
POLLHUP is set when the remote end of the monitored fd is closed. There
may still be some buffered data to read from the socket, however. Some
systems do not set POLLIN in these cases. So we should just always try
to read from fds when we receive this event.
2025-07-07 15:53:15 -06:00
Timothy Flynn
f46b721c57 LibCore: Always reset the polled revents field back to 0
One benefit of using `poll` over `select` is that we can re-use the poll
structure list. But there's no guarantee that the underlying system will
reset the `revents` field back to 0. So let's explicitly do so.
2025-07-07 15:53:15 -06:00
Timothy Flynn
0499d216b8 LibCore: Simplify tracking of notifiers and poll structures
We don't need 2 vectors and a hash map to track these structures. We can
store the poll structures in a list and just track notifiers by the fd.
2025-07-07 15:53:15 -06:00
Andrew Kaster
6264d303af RequestServer: Simplify library creation for implementation library
Using ladybird_lib() adds all sorts of extra goodies to the target, such
as installation, soname setting, a custom target name, adding lagom- to
the name of the library, etc. All we need for this impl lib is the
generated sources support, so move to a bare add_library() call instead.

The previous call was also wrong, and always created liblagom-TYPE.so.
2025-07-07 15:49:32 -06:00
Aliaksandr Kalenik
9ac685b948 LibWeb: Remove unnecessary const_cast in ViewportPaintable 2025-07-07 22:04:25 +02:00
Aliaksandr Kalenik
5a874cc62a LibWeb: Remove ClippableAndScrollable mixin
Initially ClippableAndScrollable was introduced, because we had
PaintableBox and InlinePaintable and both wanted to share clipping and
scrolling logic. Now, when InlinePaintable is gone, we could inline
ClippableAndScrollable implementation into PaintableBox.
2025-07-07 22:04:25 +02:00
Shannon Booth
d5e41f1f72 LibWeb: Handle null namespace in prefix map serializing XML
A "namespace prefix map", see:

https://w3c.github.io/DOM-Parsing/#the-namespace-prefix-map

Is meant to also hold null namespaces:

> where namespaceURI values are the map's unique keys
> (which can include the null value representing no namespace)

Which we previously neglected. This resulted in a crash for
the updated WPT test.
2025-07-07 20:24:47 +01:00
Shannon Booth
8bd43f2cb9 AK: Add hash traits for Optional<T>
To enable storing it in a hashmap. 13 is a somewhat arbitrary
value, something like 0 is not appropriate since a lot of types
return 0 as a hash for an invalid / empty state.
2025-07-07 20:24:47 +01:00
edvwib
8ca956e6f1 LibWeb: Implement 'no-validate state' concept 2025-07-07 20:12:11 +01:00
Aliaksandr Kalenik
edfae02680 LibWeb: Make apply{clear}_clip_overflow_rect non-virtual 2025-07-07 18:55:30 +02:00
Aliaksandr Kalenik
c0526b085d LibWeb: Make apply_scroll_offset and reset_scroll_offset non-virtual 2025-07-07 18:55:30 +02:00
Aliaksandr Kalenik
773d19b406 LibWeb: Apply either enclosing or own clip rect depending on PaintPhase
Previously, we always applied the enclosing clip rectangle for all paint
phases except overlays, and the own clip rectangle for the background
and foreground phases. The problem is that applying a clip rectangle
means emitting an AddClipRect display list item for each clip rectangle
in the containing block. With this change, we choose whether to include
the own clip based on the paint phase and this way avoid emitting
AddClipRect for enclosing clip rectangles twice.
2025-07-07 18:55:30 +02:00
Luke Wilde
05ee3f1876 RequestServer: Wait until initial connection is open for multiplexing
By default, if multiple requests start to a newly seen origin, curl
will not wait for a connection to open to figure out if the server
supports multiplexing and will instead open a new connection for each
request (including a new TLS session and such)

This is particularly an issue for initial page load, where a complex
website could, for example, request tens of items at once (e.g. a bunch
of scripts).

We can be kinder to servers that support multiplexing by telling curl
to wait till an initial connection is established to determine if
multiplexing is supported.

On my machine and internet connection, this reduces the amount of
connections to github.githubassets.com on initial load of
https://github.com/LadybirdBrowser/ladybird from 12 to 2.
2025-07-07 14:11:26 +02:00
Tim Ledbetter
6ef96ba170 Revert "Tests: Replace background-near-zero-svg test with WPT import"
The unmodified test is flaky on CI.

This reverts commit 8fce09f521.
2025-07-07 06:53:21 -04:00
Shannon Booth
e6235210ff LibURL: Convert to scalar string before URL parsing
URL parsing is expected to take place on well formed unicode
strings.
2025-07-07 06:50:57 -04:00
Andrew Kaster
ad1938086d AK: Add missing find_package command for fast_float
This was missed in 62d9a84b8d
2025-07-07 06:47:06 -04:00
Andrew Kaster
5523158b95 CMake: Install files for fonts, internal, about-settings on non-macOS
The corresponding install commands were missed when these file groups
were added.
2025-07-07 06:47:06 -04:00
Andrew Kaster
5878715889 CMake: Set SKCMS_API to default visibility for non-vcpkg skia as well 2025-07-07 06:47:06 -04:00
Andrew Kaster
9df7eb2e1b LibWeb: Support linking custom-built ANGLE libraries not from vcpkg
This is a similar approach to what we're using for skia.
2025-07-07 06:47:06 -04:00
Tim Ledbetter
c427f75b02 Meta: Include the --install-fonts argument when running WPT
This ensures the Ahem test font is installed.
2025-07-07 11:57:41 +02:00
Andrew Kaster
6785a01c6e RequestServer: Remove CMake dependency on LibWebView
We really don't need to link LibWebView and all its deps into RS.

Fix up the CMake to properly depend on the generated IPC files instead.
2025-07-07 09:10:05 +02:00
Andrew Kaster
1a6b4aaa49 RequestServer: Remove serenity_resource_root argument from main
We don't need it now that we're not trying to load the cacert.pem file.
Clean up includes while we're here.
2025-07-07 09:10:05 +02:00
Andrew Kaster
ffd600a7f5 Meta+RequestServer: Remove local download of ca-certificates
We haven't required a local copy of the ca-certificates since switching
to OpenSSL as the backend for TLS. Remove the script to download the
PEM file, and update the tests to use the system's CA certificates.
2025-07-07 09:10:05 +02:00
Andrew Kaster
12dd5f0804 CMake: Include utils from places that were implicitly dependent on it
These files use functions that are declared in utils.cmake, but were
relying on implicit inclusion from other files.
2025-07-07 09:10:05 +02:00
Aliaksandr Kalenik
85001185a7 LibWeb: Remove unnecessary apply_own_clip_rect() in PaintableWithLines
Own clip rect is alredy applied in `PaintableBox::before_paint()` for
all paintables with lines, so there's no need to do it once again in
`PaintableWithLines::paint()`.
2025-07-06 21:56:02 +01:00
Aliaksandr Kalenik
af79781399 LibWeb: Remove unnecessary apply_own_clip_rect() in ImagePaintable
Own clip rect is alredy applied in `PaintableBox::before_paint()` for
all image paintables, so there's no need to do it once again in
`ImagePaintable::paint()`.
2025-07-06 21:56:02 +01:00
Aliaksandr Kalenik
8f39aa0d4a LibWeb: Verify that save and restore are balanced within StackingContext
Unbalanced save and restore means that effects only relevant to a
stacking context leak outside, which is never expected behavior. Having
a `VERIFY()` for that makes it much easier to catch such issues.
2025-07-06 22:18:27 +02:00
Shannon Booth
9e3a476890 LibWeb: Abort ongoing navigations when firing certain navigate events
Implements specification change:

https://github.com/whatwg/html/commit/335d7f4

Which fixes a crash in the imported test.
2025-07-06 21:43:56 +02:00
Aliaksandr Kalenik
809e465e05 LibWeb: Delete before_children_paint and after_children_paint hooks
These were only used in SVGSVGPaintable to apply scroll frame id, which
is already handled by `before_paint()` and `after_paint()` hooks in
PaintableBox.
2025-07-06 19:21:46 +02:00
Aliaksandr Kalenik
4ddbba64cc LibWeb: Delete unused includes in DisplayListRecorder.h 2025-07-06 19:21:13 +02:00
Aliaksandr Kalenik
3dffd71695 LibWeb: Verify that save/restore are balanced within paintable
Unbalanced save/restore within display list items recorded for a
paintable means that some state only relevant for the paintable leaks to
subsequent paintables, which is never expected behavior.
2025-07-06 19:21:13 +02:00
Aliaksandr Kalenik
ac4151a00b LibWeb: Fix ScopedCornerRadiusClip emitting unbalanced restore()
...when `m_do_apply` is false.
2025-07-06 19:21:13 +02:00
Aliaksandr Kalenik
9e232a70c3 LibWeb: Allow descendant boxes to contribute in overflow rect of parent
...with inline children. This fixes an issue when we ignore abspos boxes
contained by PaintableWithLines while calculating overflow rect size.

Lots of layout tests are affected, because now PaintableWithLines has
overflow rect.

`Text/input/DOM/Element-set-scroll-left.html` is also affected and now
matches other browsers.
2025-07-06 17:10:18 +02:00
Timothy Flynn
5baa85cbee LibWeb: Add missing ValueInlines include to CanvasSettings.cpp
This missing include is causing an error in distribution builds.
2025-07-06 08:16:01 -04:00
Luke Wilde
985a481b5a LibWeb/CSP: Implement the object-src directive 2025-07-06 13:40:04 +12:00
Luke Wilde
1b12aa4d8e LibWeb/CSP: Implement the media-src directive 2025-07-06 13:40:04 +12:00
Luke Wilde
5addbcd61b LibWeb/CSP: Implement the manifest-src directive 2025-07-06 13:40:04 +12:00
Luke Wilde
002e993f68 LibWeb/CSP: Add [[nodiscard]] to result enums
This makes it so we don't have to remember to specify [[nodiscard]] on
functions that return them.
2025-07-06 13:40:04 +12:00
Tim Ledbetter
d7deb6d58f LibWeb: Make document origin opaque by default
This aligns our behavior with the specification, which says the default
value for a Document's origin is opaque unless otherwise specified
2025-07-06 13:39:45 +12:00
Tim Ledbetter
b3fa54a791 LibWeb: Set origin of new document in Document.parseHTMLUnsafe()
Previously, a crash would occur when accessing the origin of a document
created with this method.
2025-07-06 13:39:45 +12:00
Tim Ledbetter
66ca4496c3 LibWeb: Set Document origin for DOMParser created documents
Previously, a crash would occur when accessing the origin of a document
created with DOMParser.
2025-07-06 13:39:45 +12:00
Tim Ledbetter
05ef650a59 LibWeb: Respect presentation attributes that apply to not all elements
Some SVG presentation attributes are only supported on certain
elements. We now support these special cases for attributes and
elements that we currently have implemented.
2025-07-05 19:07:06 -04:00
Jelle Raaijmakers
2cc8f0821c LibWeb: Don't hit test anonymous containers if there are no fragments
We were always delegating hit tests to PaintableBox if a
PaintableWithLines has no fragments, which means that anonymous
containers could overlap with previous siblings and prioritize their
border box rect. Instead, the nearest non-anonymous ancestor should take
care of hit testing the children so the correct order is maintained.

To achieve this, we no longer do an early hit test in
PaintableWithLines::hit_test() if there are no fragments and default
to the later PaintableBox::hit_test() call that does take anonymous
containers into account.

Fixes the issue seen in #4864.
2025-07-05 23:56:42 +01:00
Jelle Raaijmakers
c24be6a39d LibWeb: Extract hit testing on children into a separate method
This way we can reuse the logic between PaintableWithLines and
PaintableBox. It also introduces the .is_positioned() check for the
children of a PaintableWithLines, which makes sure to skip positioned
child nodes since those are handled by the StackingContext.
2025-07-05 23:56:42 +01:00
Jelle Raaijmakers
e3864f9a9e LibWeb: Do not hit test anonymous containers' box for inline content
A PaintableWithLines will first try to see if there are any fragments
that have a hit. If not, it falls back to hit testing against its border
box rect.

However, inline content is often hoisted out of its parent into an
anonymous container to maintain the invariant that all layout nodes
either have inline or block level children. If that's the case, we
should not check the border box rect of the anonymous container, because
we might trigger a hit too early if the node has previous siblings in
its original parent node that overlap with their bounds.

By ignoring anonymous nodes, we leave the border box hit testing to the
nearest non-anonymous ancestor, which correctly applies the hit testing
order to its children.

Note that the border box rect checks whether the _untransformed_ point
is inside of it, which mirrors the behavior of PaintableBox::hit_test().
2025-07-05 23:56:42 +01:00
Jelle Raaijmakers
1ec3b1c6df LibWeb: Simplify Document::elements_from_point()
We should not need to check if the result of a hit test is actually
visible for hit testing, because if it wasn't, it should not have been
returned from PaintableBox::hit_test() in the first place.
2025-07-05 23:56:42 +01:00
Jelle Raaijmakers
22dacde2c5 LibWeb: Simplify break loop condition in LineBuilder
No functional changes.
2025-07-05 23:56:42 +01:00
Jelle Raaijmakers
e1c93c0ee8 LibWeb: Import WPT elementsFromPoint test
This specific test failed for some of the previous iterations of this
changeset, so let's import it and use it as a regression test.
2025-07-05 23:56:42 +01:00
Timothy Flynn
01ebf1eb07 AK: Replace surrogates in String::from_utf8_with_replacement_character
We are expected to replace lonely surrogates with U+FFFD when decoding
UTF-8 text.
2025-07-06 04:30:17 +12:00
Timothy Flynn
51afbf5280 AK: Simplify BOM parsing in String::from_utf8_with_replacement_character 2025-07-06 04:30:17 +12:00
Gingeh
f098bd029c LibTextCodec: Replace unmatched utf16 surrogates 2025-07-05 09:58:57 -04:00
Shannon Booth
1b8a77f98c LibWeb/HTML: Avoid potential overflow of index for DOMStringList
The included WPT test passes through -1 which ends up modolo'ing
to u32 max at the IDL conversion layer, resulting in an unsigned
overflow when checking bounds.
2025-07-05 12:28:37 +01:00
Luke Wilde
715061fb79 LibWeb/CSP: Implement the img-src directive 2025-07-05 21:21:44 +12:00
Luke Wilde
1689353beb LibWeb/CSP: Implement the frame-src directive 2025-07-05 21:21:44 +12:00
Luke Wilde
e899438907 LibWeb/CSP: Implement the font-src directive 2025-07-05 21:21:44 +12:00
Luke Wilde
959bb5cc18 LibWeb/CSP: Implement the connect-src directive 2025-07-05 21:21:44 +12:00
Luke Wilde
203c2a6b30 LibWeb/CSP: Use GC::Heap instead of JS::Realm for directive checks 2025-07-05 21:21:44 +12:00
Psychpsyo
baf2063e31 LibWeb: Fix selection when start node is inside end node
Fixes a regression introduced in
bc8870d019 (in a performant way this
time)
2025-07-04 20:19:50 +02:00
Sam Atkins
202c55bf28 LibWeb/CSS: Implement the :state(foo) pseudo-class
This matches custom elements that have `foo` in their custom states set.

The 2 test failures here are because we don't support `::part()` yet.
2025-07-04 18:10:28 +01:00
Sam Atkins
5387c923ca LibWeb/CSS: Use first_is_one_of() in can_selector_use_fast_matches()
Makes things a bit easier to read. I've also sorted the pseudo-classes.
2025-07-04 18:10:28 +01:00
Sam Atkins
b6ffea8990 LibWeb: Give Element a CustomStateSet, exposed by ElementInternals 2025-07-04 18:10:28 +01:00
Sam Atkins
e63d81b36e LibWeb: Add CustomStateSet IDL type 2025-07-04 18:10:28 +01:00
Sam Atkins
bc94431b99 IDLGenerators: Add a callback for when a setlike's set is modified
For simplicity, this requires that the setlike Foo class has a
`void on_set_modified_from_js(Badge<Bindings::FooPrototype>)` method.

This will be called after the set is modified from a generated `add()`,
`delete()`, or `clear()` method.
2025-07-04 18:10:28 +01:00
Sam Atkins
be21d952b1 IDLGenerators: Generate impl_from() for types that have setlike
Found by this interface, which has nothing else in it:

```
[Exposed=Window]
interface CustomStateSet {
  setlike<DOMString>;
};
```
2025-07-04 18:10:28 +01:00
Sam Atkins
efcbec250f IDLGenerators: Support string types in setlike 2025-07-04 18:10:28 +01:00
Sam Atkins
0f859fd126 IDLGenerators: Remove redundant function forward declaration 2025-07-04 18:10:28 +01:00
Sam Atkins
9e1bbe7edd IDLGenerators: Correct the parameter type check for setlike methods 2025-07-04 18:10:28 +01:00
Sam Atkins
f2dd66e039 IDLGenerators: Remove unused numeric_type definition 2025-07-04 18:10:28 +01:00
Philipp Dreher
dcc9318042 Documentation: Update Testing.md to reflect changes in CMake presets 2025-07-04 16:29:28 +01:00
Psychpsyo
93ae57114d LibWeb: Stop clipping the root element's background 2025-07-04 16:18:57 +01:00
Tim Ledbetter
5413716802 LibWeb: Don't crash when setting offscreen canvas size to 0
Previously, this would crash because `Gfx::Bitmap` can't have a zero
size.
2025-07-04 16:10:38 +01:00
Rocco Corsi
f882c446cb Documentation: Update missing distribution packages for building
Ubuntu missing: python3-venv
Fedora missing: git
Manjaro OK
OpenSUSE missing: git and libpulse-devel
2025-07-04 15:58:36 +01:00
Gingeh
1b7323fc2d LibWeb: Interpolate legacy colors in sRGB 2025-07-04 15:28:08 +01:00
Aliaksandr Kalenik
c18314b942 LibWeb+LibGfx: Replace BackingStore with PaintingSurface
Now, when Skia backend context is available by the time backing stores
are allocated, there is no need to have a separate BackingStore class.

This allows us to get rid of BackingStore -> PaintingSurface cache.
2025-07-04 16:12:47 +02:00
Aliaksandr Kalenik
082053d781 LibWeb+WebContent+WebWorker: Move backing store allocation in Navigable
Making navigables responsible for backing store allocation will allow us
to have separate backing stores for iframes and run paint updates for
them independently, which is a step toward isolating them into separate
processes.

Another nice side effect is that now Skia backend context is ready by
the time backing stores are allocated, so we will be able to get rid of
BackingStore class in the upcoming changes and allocate PaintingSurface
directly.
2025-07-04 16:12:47 +02:00
Aliaksandr Kalenik
b73525ba0e LibWeb+WebContent: Delete unused "has focus" flag from paint config 2025-07-04 16:12:47 +02:00
Timothy Flynn
418409aa6f AK: Fix usage of constexpr within Utf16View and related utilities
* Error and ErrorOr are not themelves constexpr, so a function returning
  these types cannot be constexpr.

* The UDL was trying to call Utf16View::validate, which is not constexpr
  itself. The compiler will actually already raise an error if a UTF-16
  literal is invalid, so let's just avoid the call altogether.
2025-07-05 01:25:22 +12:00
Callum Law
778759517e LibWeb: Support calcs which resolve to numbers as hue values in colors
Gains us 5 new WPT tests.
2025-07-04 13:18:55 +01:00
Callum Law
9ab7c5d08d LibWeb: Support relative lengths in calc color values
Gains us ~40 WPT tests.
2025-07-04 13:18:55 +01:00
Callum Law
62d138ebf7 LibWeb: Allow passing a resolution context to CSSStyleValue::to_color
This will be used for resolving any calculated style values within the
various `CSSColorValue` sub-classes.

No functionality changes.
2025-07-04 13:18:55 +01:00
Callum Law
b468923372 LibWeb: Allow creating Length::ResolutionContext with provided root
Previously we could not create a `Length::ResolutionContext` using the
`for_layout_node` method if the provided node's document did not have a
layout node.

We now provide a workaround for this in the case that the
provided layout is that root layout node.

This is useful for instance if we want to create a length resolution
context when calling `NodeWithStyle::apply_style` on the root node.
2025-07-04 13:18:55 +01:00
Ryan Liptak
1fd0bf9feb LibWeb: Add simple named character reference test to TestHTMLTokenizer 2025-07-04 11:57:19 +02:00
Ryan Liptak
7096a2892e LibWeb/HTML: Use lookahead when possible for named character references
When there is an active insertion point, it's necessary to tokenize
code-point-by-code-point to handle the case of document.write being
used to insert a named character reference one code point at a time.

However, when there is no insertion point defined, looking ahead at the
input and doing the matching all-at-once is more efficient since it
allows:

- Avoiding the work done in next_code_point between each code point
  being matched (leading to better CPU cache usage in theory)
- Skipping ahead to the end of the match all at once, which does less
  work overall than the equivalent number of next_code_point calls
  (that is, skip(N) does less work than next_code_point called N times)

In my benchmarking, this provides a small performance boost (fewer
instructions, fewer cpu cycles, fewer branch misses) essentially for
free.
2025-07-04 11:11:19 +02:00
ayeteadoe
f737ec2570 CMake: Rename SERENITY_* helper variables to LADYBIRD_* 2025-07-03 23:19:41 +02:00
ayeteadoe
d897bfae91 CMake: Rename all_generated target to better convey intent 2025-07-03 23:19:41 +02:00
ayeteadoe
25f5936dee CMake: Rename serenity_* helper functions/macros to ladybird_* 2025-07-03 23:19:41 +02:00
ayeteadoe
100b204a68 CMake: Move lagom target creation helper functions into Meta/CMake 2025-07-03 23:19:41 +02:00
Tim Ledbetter
cb4a5eca2e Meta: Add formatter to PropertyID code generator 2025-07-03 21:17:16 +01:00
Jelle Raaijmakers
c03210e858 LibWeb: Dump PaintableBox dimensions for inline layout nodes
We were only dumping a PaintableBox' dimensions if its layout node was a
Layout::Box as well, causing us to not dump the dimensions of paintables
for inline nodes in the paintable tree.
2025-07-03 22:16:48 +02:00
Aliaksandr Kalenik
5874b7a76f LibWeb: Skip update_associated_selection() when there's no selection
This change fixes at least two issues:
- `update_associated_selection()` is responsible for selectionchange
  dispatch, and we were incorrectly dispatching this event on ranges
  that were not associated with a selection.
- `Range::get_client_rects()` was using `update_associated_selection()`
  to refresh the selection state in the paintable tree for the current
  range, but since a range might not be associated with a selection,
  this could make the painted selection reflect the state of an
  arbitrary range instead of the actual selection range.

Fixes a bug on Discord where any text typed into the message input would
get selected.
2025-07-03 22:16:39 +02:00
Timothy Flynn
69074a3841 AK: Avoid double allocations when converting UTF-16 LE/BE to UTF-8
We can form the UTF-8 string in-place.
2025-07-03 11:45:23 -04:00
Timothy Flynn
62d9a84b8d AK+Everywhere: Replace custom number parsers with fast_float
Our floating point number parser was based on the fast_float library:
https://github.com/fastfloat/fast_float

However, our implementation only supports 8-bit characters. To support
UTF-16, we will need to be able to convert char16_t-based strings to
numbers as well. This works out-of-the-box with fast_float.

We can also use fast_float for integer parsing.
2025-07-03 09:51:56 -04:00
Timothy Flynn
9fc3e72db2 AK+Everywhere: Allow lonely UTF-16 surrogates by default
By definition, the web allows lonely surrogates by default. Let's have
our string APIs reflect this, so we don't have to pass an allow option
all over the place.
2025-07-03 09:51:56 -04:00
Timothy Flynn
86b1c78c1a AK+Everywhere: Prepare Utf16View for integration with a UTF-16 string
To prepare for an upcoming Utf16String, this migrates Utf16View to store
its data as a char16_t. Most function definitions are moved inline and
made constexpr.

This also adds a UDL to construct a Utf16View from a string literal:

    auto string = u"hello"sv;

This let's us remove the NTTP Utf16View constructor, as we have found
that such constructors bloat binary size quite a bit.
2025-07-03 09:51:56 -04:00
Timothy Flynn
c17b067e1d AK: Completely remove endianness from Utf16View APIs
These were mostly removed in 7628ddfaf7.
This removes the few remaining cases, as no callers are providing any
non-host endianness. This is just to prevent weird API dissymmetry
between Utf16View and an upcoming Utf16String.
2025-07-03 09:51:56 -04:00
Timothy Flynn
a0eb47e2fc AK: Add hash traits for Utf16View
This is based on the hash in JS::Utf16StringImpl::compute_hash.
2025-07-03 09:51:56 -04:00
Timothy Flynn
2abc955ca9 AK: Allow treating UTF-16 views with lonely surrogates as valid
Much of the web requires us to allow lonely surrogates in UTF-16 data.
The default behavior to disallow such code units has not been changed
here - that will be changed in an upcoming commit.
2025-07-03 09:51:56 -04:00
Timothy Flynn
d978a582a0 AK: Add a Utf16View ASCII validator 2025-07-03 09:51:56 -04:00
Timothy Flynn
35a1832d08 Tests/AK: Rename TestUtf16 / TestUtf8 to TestUtf16View / TestUtf8View
These are the files they actually test, so let's rename them to avoid
confusion with an upcoming Utf16String test.
2025-07-03 09:51:56 -04:00
Timothy Flynn
d38b2194ea AK: Remove errant did_destroy_fly_string_data declaration
This declaration is in the AK namespace. The real declaration is in
StringData.h, in the AK::Detail namespace. as is its implementation
in FlyString.cpp. So the declaration removed here was actually unused.

(This was confusing while implementing a UTF-16 flyweight string.)
2025-07-03 09:51:56 -04:00
Timothy Flynn
5720d626ce AK: Extract some StringBase helpers for use in an outside class 2025-07-03 09:51:56 -04:00
Timothy Flynn
66006d3812 AK+LibJS: Extract some UTF-16 helpers for use in an outside class
An upcoming Utf16String will need access to these helpers. Let's make
them publicly available.
2025-07-03 09:51:56 -04:00
Timothy Flynn
b6dc5050d2 AK: Define a formatter for char16_t 2025-07-03 09:51:56 -04:00
Aliaksandr Kalenik
2618956b6f LibWeb: Delete unused Range::inverted() 2025-07-03 15:00:49 +02:00
Aliaksandr Kalenik
481ab338b4 LibWeb: Delete unused Range::normalized() 2025-07-03 15:00:49 +02:00
Aliaksandr Kalenik
bc8870d019 LibWeb: Make recompute_selection_states() go faster
...by avoiding `is_before()` call on every loop iteration in step 5.

This change makes switching channels on Discord go a lot faster.
2025-07-03 13:48:18 +02:00
Shannon Booth
c63e77142a Tests/LibWeb: Import webstorage symbol-props WPT test
I noticed a subtest in this test failing along with every
other browser. After investigation, the failure was due
to testing the previous specification before:

https://github.com/whatwg/webidl/commit/3fb6ab4

So this imports the now adjusted WPT test as of:

https://github.com/web-platform-tests/wpt/commit/bb3f032
2025-07-03 12:45:31 +01:00
Sam Atkins
994bbcaa75 LibWeb/Painting: Don't paint invisible paintables
This check technically isn't necessary in
`SVGForeignObjectPaintable::paint()` because
`PaintableWithLines::paint(context, phase);` does the check already, but
I've added it there anyway to save some debugging time if someone does
add more code there. :^)
2025-07-03 12:39:05 +02:00
Tim Ledbetter
6ee91c4189 LibWeb: Use correct previous word location when moving selection offset
Previously, this incorrect offset could cause a crash when moving the
selection to the previous word.
2025-07-03 10:28:38 +01:00
Jelle Raaijmakers
1eb581815a Tests: Unskip selection-over-multiple-code-units.html test
The flake was reproducible by running the entire LibWeb test suite over
and over again with sanitizers enabled. By making the test async and run
at window `load` time instead of document `DOMContentLoaded` time, I've
not been able to reproduce the issue locally.

Ideally I was able to find the underlying cause for this bug, but for
now I'd rather run this regression test.
2025-07-03 10:27:39 +01:00
Tim Ledbetter
923deb0c01 LibWeb: Parse border-image shorthand property 2025-07-03 10:19:44 +01:00
Tim Ledbetter
c0390f759c LibWeb: Parse the border-image-repeat property 2025-07-03 10:19:44 +01:00
Tim Ledbetter
98e63e3dd5 LibWeb: Parse the border-image-outset property 2025-07-03 10:19:44 +01:00
Tim Ledbetter
245905b833 LibWeb: Parse the border-image-slice property 2025-07-03 10:19:44 +01:00
Tim Ledbetter
70c2621634 LibWeb: Parse the border-image-source property 2025-07-03 10:19:44 +01:00
Chase Knowlden
ac22e71184 LibWeb: Make offset for HTML style and script elements one after 2025-07-03 10:11:11 +01:00
Sam Atkins
ffd5503dcb LibWeb/DOM: Serialize pseudo-elements in the correct order
Make Element responsible for serializing all its children, so it can put
them in order.
2025-07-03 09:56:56 +01:00
Sam Atkins
4df472988c LibWeb/DOM: Only list pseudo-elements that actually exist
This stops `::before` and `::after` nodes showing up for every single
element in the inspector tree. Unfortunately there's no way for us to
detect that one of these doesn't exist in layout but has *some* style
specified for it, but that seems like a rare use case.
2025-07-03 09:56:56 +01:00
Sam Atkins
140a099fe6 LibDevTools: Remove use-after-move in actor_for_node() 2025-07-03 09:56:56 +01:00
Tim Ledbetter
af60e36122 LibWeb/CSS: Don't remove whitespace early when parsing descriptor values 2025-07-03 08:22:30 +01:00
Tim Ledbetter
9d1373de86 Tests/LibWeb: Import unicode range parsing test from WPT 2025-07-03 08:22:30 +01:00
Timothy Flynn
c12728632d LibDevTools: Handle pseudo elements during DOM node serialization
We need to tell DevTools whether elements are pseudo elements, and we
need to set the element's type and visibility to that of its parent.
2025-07-02 15:27:54 -04:00
Timothy Flynn
d0b4673640 LibDevTools: Handle null DOM node properties for inspected nodes
In particular, if a node does not have a computed style, we must still
include the "computed" object in the response. Otherwise, DevTools will
continue to display the properties from the previously selected node.
2025-07-02 15:27:54 -04:00
Timothy Flynn
b55d2909f6 LibWebView+UI: Launch the DevTools server if --devtools is specified
This replaces the --devtools-port flag with a --devtools flag, which
optionally accepts a port. If the --devtools flag is set, we will now
automatically launch the DevTools server.
2025-07-02 15:27:54 -04:00
Luke Wilde
e85b809f8d LibWeb+Meta: Move WebGL rendering context implementations in tree
This copies the latest generated code in tree and then removes code
generation for the WebGL rendering contexts. This is because it didn't
add much value, and we can maintain the generated output instead of
both that and the generator itself.
2025-07-02 19:00:49 +02:00
Tim Ledbetter
8fce09f521 Tests: Replace background-near-zero-svg test with WPT import 2025-07-02 18:44:21 +02:00
Tim Ledbetter
a959d4dca2 test-web: Match WPT runner reftest-wait behavior
When a test has a `reftest-wait` class, we now wait for fonts to load
and then for 2 `requestAnimationFrame` callbacks. This matches the
behavior of the WPT runner and allows more imported WPT tests to work
correctly.
2025-07-02 18:44:21 +02:00
Timothy Flynn
504be366a2 Meta: Pin harfbuzz to 10.2.0 for now
Several of us (including our WPT runner) are getting linker errors with
11.2.0, as Qt is pulling in the system harfbuzz.
2025-07-02 17:02:06 +02:00
Sam Atkins
b2dea4577a LibWeb/Painting: Only calculate light/dark border color that's used
We previously calculated both before deciding which one we wanted.
2025-07-02 15:11:04 +02:00
Sam Atkins
c7166527ce LibWeb/Painting: Keep alpha for inset/outset border colors
Also return the original color when needed, instead of reconstructing it
from HSV.
2025-07-02 15:11:04 +02:00
Ali Mohammad Pur
408694ab4f Meta: Update vcpkg baseline
This bump includes a new version of meson that unbreaks the build on
macOS 26 with xcode 26.
2025-07-02 13:27:02 +02:00
Tim Ledbetter
53adf3be1e Meta: Ensure local WPT repository is up to date before importing
The current import process assumes that the local WPT repository is up
to date. Let's make sure that's true before importing a new test.
2025-07-02 12:02:09 +01:00
Jelle Raaijmakers
180bb0fc5d Everywhere: Remove LibRIFF 2025-07-02 12:01:12 +01:00
Gingeh
fa410a67d9 LibWeb: Don't crash with near-zero background sizes 2025-07-02 11:45:34 +01:00
Tim Ledbetter
78b6032940 LibWeb: Validate operator count when parsing a calculation
Previously, we would allow calc values such as `calc(min(1 2))`, which
would be simplified to `calc(3)` because we assumed that numbers not
separated by an operator represented a sum. We now validate that the
number of operators we see is as we would expect before collecting
these values into a sum node.
2025-07-02 10:12:58 +01:00
ayeteadoe
43778e9493 Meta: Fix vcpkg angle port on Windows 2025-07-01 14:17:17 -06:00
Gingeh
b8f78e3bc1 LibWeb: Don't crash with invalid transform-origin values 2025-07-01 14:19:10 +01:00
Gingeh
0e3386bb4c LibWeb: Throw SyntaxError when FontFaceSet contains var 2025-07-01 11:50:05 +01:00
Gingeh
863092afdc LibWeb: Don't crash with non-<col> table-column 2025-07-01 11:18:14 +02:00
Tim Ledbetter
5b522c096e LibWeb: Add border-*-radius logical properties 2025-07-01 11:16:37 +02:00
Jelle Raaijmakers
e77561d3a9 LibWeb/WebGL: Use robust versions of API calls provided by ANGLE
In 454bf0b7cd, we've incorrectly
attributed the finding.

Credit goes to https://github.com/intrigus-lgtm instead for finding the
issue and reporting it to us.
2025-07-01 09:53:03 +02:00
Shannon Booth
02e6618554 Tests: Disable flaky selection-over-multiple-code-units test
This is flaky in CI.
2025-07-01 03:42:28 +01:00
Tim Ledbetter
844dcd3310 LibWeb: Ignore non-finite OffscreenCanvas shadow offset values 2025-07-01 13:53:27 +12:00
Tim Ledbetter
7507906c68 Meta: Normalize relative URLs before fetching them in the WPT importer
Previously, fetching URLs with `..` components would fail.
2025-07-01 11:43:59 +12:00
Tim Ledbetter
7724a96efa LibWeb: Don't expose XMLHttpRequest.responseXML in workers 2025-07-01 01:03:58 +02:00
Luke Wilde
07231e74c7 LibWeb: Set Fetch destination of <link rel="stylesheet"> requests 2025-07-01 10:24:24 +12:00
Luke Wilde
1edf7a8aa2 LibWeb/CSP: Implement URL matching algorithms
These are used by all the *-src attributes, to check if a given URL,
origin and redirect count matches a source list entry specified in
the *-src attribute's values, if it's allowed to.
2025-07-01 10:24:24 +12:00
Luke Wilde
38f80913a4 LibWeb: Implement Content Security Policy directive expression parser
This follows the implementation method that was used for the
implementation of ISO8601 parsing for Temporal in LibJS. Doing it this
way allows us to have state transactions, and thus pick out individual
parse nodes that the specification steps want to use.
2025-07-01 10:24:24 +12:00
Luke Wilde
050f984625 LibWeb/CSP: Add Keyword Sources FlyStrings 2025-07-01 10:24:24 +12:00
Luke Wilde
31a8004ddb AK: Add the ability to consume specifically by a predicate
This will be used by Content Security Policy to consume the next
character, if it matches a whole range of characters, such as
is_ascii_alpha.
2025-07-01 10:24:24 +12:00
Andreas Kling
b3d9e39bad LibWeb: Avoid infinite loop in HTMLElement.scrollParent
We were failing to actually climb up the containing block chain,
causing this API to infinite loop for anything but the most
trivial cases.

By fixing the loop structure, we also make a bunch of the already
imported WPT tests pass. :^)
2025-06-30 20:38:21 +01:00
ayeteadoe
8d1c860fcd LibWeb: Add OffscreenCanvas to ImageBitmap invalid-types-no-crash test 2025-06-30 12:35:54 -06:00
ayeteadoe
3bce1934b1 Meta: Fix CMake configure warning in unix angle vcpkg port
Fixes Unexpected UNKNOWN_READ_ACCESS on WIN32 variable
2025-06-30 12:24:36 -06:00
Luke Wilde
454bf0b7cd LibWeb/WebGL: Use robust versions of API calls provided by ANGLE
The primary purpose of these is to add bounds checking to older OpenGL
API calls that take arbitrarily sized buffers, but don't know the size
of the buffer and thus rely on the application being certain the buffer
is large enough.

Since these API calls are exposed to arbitrary JS which can make
arbitrarily sized buffers, it is not safe to use the non-robust
variants, as we cannot know the size of the buffer ahead of time, nor
the amount of data required by the API call.

The robust variants provided by ANGLE adds a buffer size parameter,
where it'll calculate the amount of data it needs for that API call
for us and return an error if it's bigger than the given buffer size.

Credit to https://github.com/s41nt0l3xus for finding this during a CTF
and providing a write up that exploits this.
See: 92efbaed6c/gpnctf-2025/WebGL-bird
2025-06-30 11:54:23 -06:00
Luke Wilde
286fa7b3ca Meta: Update ANGLE to chromium/7258 2025-06-30 11:54:23 -06:00
Andrew Kaster
20ad31b6c8 AK: Copy escape char when forking SourceGenerator
Nobody that calls fork() actually passes a non-default escape char,
but in the case that we start doing that, let's avoid nasty surprises
2025-06-30 11:39:16 -06:00
Bastiaan van der Plaat
1a7932601a IDLGenerators: Fix Exposed extended attribute codegen 2025-06-30 11:39:16 -06:00
Bastiaan van der Plaat
6812aa00ca AK: Add SourceGenerator mapping clone method
This is useful when you want to build an independent string using
the same names and replacements as an existing generator.
2025-06-30 11:39:16 -06:00
Bastiaan van der Plaat
41a6ebfba2 LibIDL: Save parsed stringifier_extended_attributes 2025-06-30 11:39:16 -06:00
Bastiaan van der Plaat
da620d6ccf LibIDL+LibWeb: Move parse_exposure_set from code generator to LibIDL 2025-06-30 11:39:16 -06:00
ayeteadoe
dbba6c0df9 LibWeb: Enable in Windows CI 2025-06-30 10:50:36 -06:00
ayeteadoe
c14173f651 LibJS: Enable EXPLICIT_SYMBOL_EXPORT 2025-06-30 10:50:36 -06:00
ayeteadoe
83846b3861 LibGC: Enable EXPLICIT_SYMBOL_EXPORT 2025-06-30 10:50:36 -06:00
Andrew Kaster
1d62bf7049 LibWeb: Stub out createImageBitmap with an OffscreenCanvas image
This fixes build breakage caused by an interaction b/w PRs #4801
and #3788
2025-06-30 10:32:53 -06:00
ayeteadoe
81ccb655b4 LibWeb: Implement HTML::ImageBitmap creation from HTML::ImageData 2025-06-30 10:07:28 -06:00
Totto16
8404df55d8 LibWeb: Add OffscreenCanvas tests
The tests cover working in Worker and some basic functionality
2025-06-30 09:46:21 -06:00
Totto16
f1a096d6e4 LibWeb: Add OffscreenCanvas to IDL types
Add OffscreenCanvas to TexImageSource and CanvasImageSource.
Implement all the necessary features to make it work in all cases where
these types are used.
2025-06-30 09:46:21 -06:00
Totto16
2ad3ce5d37 LibWeb: Implement basics for OffscreenCanvas
This implements the basic interface, classes and functions for
OffscreenCanvas. Many are still stubbed out and have many FIXMEs in
them, but it is a basic skeleton.
2025-06-30 09:46:21 -06:00
Totto16
193ab3757b LibWeb: Factor out canvas rendering options algorihtms
Factor out canvas parsing algorihtm for CanvasRenderingContext2DSettings
from JS::Value. This was only used in one place but needs to be usable
from other places too in the future.
2025-06-30 09:46:21 -06:00
Totto16
49500ac386 LibWeb: Factor out canvas serialization algorihtm
Factor out canvas serialization algorihtm from HTMLCanvasElement to
seperate file. This makes it usable by other things too.
2025-06-30 09:46:21 -06:00
ayeteadoe
8ef7df2a95 Meta: Patch angle vcpkg to build on Windows 2025-06-30 08:00:38 -06:00
Andrew Kaster
435aee2b1e Meta: Patch angle vcpkg to build on Linux
This involves removing x11 dependencies, and not setting angle_use_x11.
2025-06-30 08:00:38 -06:00
Callum Law
8e9753eadb LibWeb: Correctly compute consistent type when simplifying hypot
Previously we would never get a valid `consistent_type` as we were
trying to make the node types consistent with the initial empty type
which isn't possible.

Gains us 7 WPT tests.
2025-06-30 14:53:04 +02:00
Tim Ledbetter
04a3a227c3 LibWeb: Add the border-inline-* shorthand properties 2025-06-30 14:52:18 +02:00
Tim Ledbetter
90da2f5418 LibWeb: Add the border-block-* shorthand properties 2025-06-30 14:52:18 +02:00
Callum Law
2eb44229b4 LibWeb: Implement Selection.modify 2025-06-30 10:44:32 +01:00
Shannon Booth
bd67a5afaa LibURL: Differentiate cross site opaque origins
Previously if we had two opaque origins both URLs were
being treated as same site.
2025-06-30 08:06:37 +01:00
ayeteadoe
1a3a9eee7a Meta: Add help to generate_python_encoding_indexes.py 2025-06-30 14:03:55 +12:00
ayeteadoe
2682f370dd Meta: Rewrite GeneratePublicSuffixData in python 2025-06-30 14:03:55 +12:00
Shannon Booth
b49b1b35e4 LibURL: Correct logic for domains not matched by PSL in public_suffix
For the AO defined in the URL specification, in the case the
domain does not match against the PSL, we should be returning
the TLD. This fixes a crash for a bunch of WPT tests using the
Document.domain setter when the test is being served by WPT
locally.

We should be doing similar logic in registrable_domain, but that
unfortunately runs into some other issues, so just leave a FIXME
for now.
2025-06-29 12:47:57 +01:00
Shannon Booth
a2b523eeb8 LibURL: Replace use of URL::get_public_suffix
It is confusing to have both URL::Host::public_suffix and
URL:get_public_suffix, both with slightly different semantics.

Instead, use PublicSuffixData for cases that just want a direct
match against the list, and URL::Host::public_suffix in LibWeb
land as the URL spec defined AO.
2025-06-29 12:47:57 +01:00
Shannon Booth
e6ecafea84 LibURL: Remove ErrorOr from get_public_suffix
The caller only expects ASCII and let's ignore any OOM.
2025-06-29 12:47:57 +01:00
Shannon Booth
c3618b891f Meta+LibURL: Always enable public suffix data
We should not encourage no public suffix data as a supported
configuration.
2025-06-29 12:47:57 +01:00
Semyon Danilov
9e7b40747f LibWebView: Add Arial Unicode MS to the list of Sans Serif fallbacks 2025-06-28 12:10:35 +01:00
Tim Ledbetter
ac25f47e8f LibWeb/SVG: Disallow negative stroke-dasharray values 2025-06-27 23:00:13 +02:00
Tim Ledbetter
0c8a90166f LibWeb/SVG: Disallow negative values for SVG radius properties 2025-06-27 22:16:42 +02:00
Tom Lynch
831ba5d655 LibWeb: Fix text-shadow position with non 100% window scale 2025-06-27 19:12:01 +02:00
Tim Ledbetter
d7bdbeb446 LibWeb: Disable ligatures if text-rendering is set to optimizeSpeed
If `font-variant-ligatures` is set to `normal` and `text-rendering` is
set to `optimizeSpeed` then all ligatures are now disabled.
2025-06-27 16:51:30 +01:00
Tim Ledbetter
b4097623e5 LibWeb: Disable font kerning if text-rendering is set to optimizeSpeed
If `font-kerning` is set to `normal` and `text-rendering` is
set to `optimizeSpeed` then kerning is now disabled.
2025-06-27 16:51:30 +01:00
Tim Ledbetter
68035a2b8d LibWeb/CSS: Add the text-rendering property 2025-06-27 16:51:30 +01:00
circl
7152821c8f LibWeb: Don't mark <input type="color"> as closed until the picker is
The color picker implementation allows for live updates to the input
element until the final color is confirmed by the user, but previously
it was marked as closed immediately after the first update.
2025-06-27 15:12:47 +01:00
Tim Ledbetter
a14471b89b LibWeb: Explicitly disable ligatures if font_variant_ligatures is none 2025-06-27 10:06:20 +02:00
Shannon Booth
20d369b96d LibWeb/HTML: Implement the exception checks for Document.domain setter 2025-06-27 18:45:48 +12:00
Shannon Booth
68b57daf84 LibURL: Remove uneeded FIXME for UTF-8 decode in URL parsing
I believe this is in the specification since the spec technically
requires passing through a valid unicode string. However, our
implementation already handles a non valid unicode string, and will
do the replacement character substitution.
2025-06-27 18:45:48 +12:00
Shannon Booth
1f4bbc2bfb LibURL: Publicly expose ability to parse a host
This is used by the HTML specification.
2025-06-27 18:45:48 +12:00
Tim Ledbetter
c5eca713e9 Meta: Ignore tag namespace when rewriting paths in the WPT importer
This allows us to import SVG tests, which distinguish between HTML and
SVG script tags using namespaces.
2025-06-27 08:36:15 +02:00
ayeteadoe
c5362e832d Tests/LibWasm: Enable in Windows CI 2025-06-26 19:35:14 -06:00
ayeteadoe
f5dc72a492 LibWasm: Enable in Windows CI 2025-06-26 19:35:14 -06:00
ayeteadoe
55a077d5a1 LibMedia: Enable in Windows CI 2025-06-26 19:35:14 -06:00
ayeteadoe
931d0fa562 LibWebSocket: Enable in Windows CI 2025-06-26 19:35:14 -06:00
ayeteadoe
766cc4560f LibRequests: Enable in Windows CI 2025-06-26 19:35:14 -06:00
ayeteadoe
0d45d08db7 LibHTTP: Enable in Windows CI 2025-06-26 19:35:14 -06:00
ayeteadoe
e28c956629 Tests/LibGfx: Enable non file input tests in Windows CI
All the file-based tests left out build, but they all fail at run time
with the error "No such file or directory" or a Core::File-based
assertion failure for the Benchmark test
2025-06-26 19:35:14 -06:00
ayeteadoe
2119ea982e LibGfx: Enable in Windows CI 2025-06-26 19:35:14 -06:00
ayeteadoe
2f7a83304f Meta: Patch libjxl port to not link with libm when building with msvc
The libjxl port is required to add the `msvc-remove-libm` patch.
Otherwise LibGfx attempts to link with 'm.lib' which is not valid
for MSVC as the CRT bundles math functions implicitly unlike on Unix
2025-06-26 19:35:14 -06:00
ayeteadoe
35c34a87c0 Meta: Add libjxl overlay port
We need some msvc-only cusotmization here to get LibGfx building
2025-06-26 19:35:14 -06:00
ayeteadoe
91e7664849 CMake: Allow Windows to build Lib/Test GUI targets 2025-06-26 19:35:14 -06:00
Tim Ledbetter
8828e0d791 LibWeb: Avoid updating muted state on muted content attribute changes
The `muted` content attribute should only affect the state of the
`muted` IDL property when the media element is first created. The
attribute should have no dynamic effect.
2025-06-27 09:14:54 +12:00
Tim Ledbetter
ed6f2f9b81 LibWeb: Ensure audio tracks are set to the correct volume before playing
Previously, a video or audio element with the `autoplay` and `muted`
attributes set, would not mute the audio before playing.
2025-06-26 09:56:39 -04:00
ayeteadoe
838ca8d172 Meta: Rewrite GenerateEncodingIndexes in python 2025-06-25 18:50:14 -06:00
ayeteadoe
3836d0e219 Meta: Create python version of invoke_generator
This allows for the C++ and Python generators to share the same core
implementation, which will simplify the generator migration process
2025-06-25 18:50:14 -06:00
Rocco Corsi
92b69e7885 Test: Enable text/html tests for MimeType sniffing by filenames 2025-06-25 18:49:43 -06:00
Rocco Corsi
cdb623b663 LibCore: Remove .xht from common_extensions in MimeType text/html
Extension .xht was part of common_extensions for two MimeType Array
entries: application/xhtml+xml and text/html. Should only be part of
one.
2025-06-25 18:49:43 -06:00
Timothy Flynn
3171d57639 LibWeb: Restore flags to prevent formatting timestamps as local time
The flag to stringify these timestamps as UTC was errantly dropped in
6fb2be96bf. This was causing test-web to
fail in time zones other than GMT+0.
2025-06-25 23:41:04 +02:00
Timothy Flynn
efa9737cf7 AK+LibJS: Do not set UTF-16 code point length to its code unit length 2025-06-25 22:20:47 +02:00
Aliaksandr Kalenik
594194eb60 LibWeb: Skip serialization of implicit grid lines created during layout
StyleValues created for grid-template-rows and grid-template-columns by
GFC should not include `-start`/`-end` lines implicitly created by grid
areas.
2025-06-25 20:45:48 +02:00
ayeteadoe
185be4011b CI: Make Windows CI label name consistent with the preset name 2025-06-25 10:12:34 -06:00
Tim Ledbetter
7a6e4f5ec8 LibWeb: Treat a CSS declaration with a "--" property name as invalid 2025-06-25 17:09:29 +01:00
Tim Ledbetter
bf37f3400e LibWeb: Don't treat "--" as a valid custom property name
This is reserved for future use by CSS.
2025-06-25 17:09:29 +01:00
Shannon Booth
38765fd617 LibURL: Use a nonce to distinguish opaque origins
Opaque origins are meant to be unique in terms of equality from
one another. Since this uniqueness needs to be across processes,
use a nonce to implement the uniqueness check.
2025-06-25 16:47:09 +01:00
Shannon Booth
ee8e4d1eec LibCrypto: Remove dependency on LibCore
This is not required.
2025-06-25 16:47:09 +01:00
Jelle Raaijmakers
2687246808 LibGfx: Use NonnullRefPtr<Bitmap> for frame descriptors
This makes it a bit easier to reason about where bitmaps should be
available.
2025-06-25 22:54:48 +12:00
mikiubo
ff78746be1 LibWeb: Set readyState to complete for DOMParser documents
Documents created via DOMParser.parseFromString()
are parsed synchronously and do not participate in the
browsing context's loading pipeline.

This patch ensures that if the document has no browsing context
(i.e. was parsed via DOMParser),
its readiness is set to "complete" synchronously.

Fixes WPT:
domparsing/xmldomparser.html
2025-06-25 20:49:03 +12:00
Tim Ledbetter
b00e57139f LibWeb/CSS: Treat block at-rules with no block as invalid 2025-06-25 09:02:45 +02:00
Tim Ledbetter
48f56cad08 LibWeb: Handle non-numeric font-weight values in keyframes
Previously, using `font-weight` with a keyword or `calc()` value inside
a keyframe rule would cause a crash.
2025-06-25 09:01:56 +02:00
Tim Ledbetter
e69d9fb331 LibGfx: Destroy FontConfig string iterator after use
This avoids a memory leak in `FontDatabase::font_directories()`.
2025-06-25 08:59:49 +02:00
Ali Mohammad Pur
d49106c007 LibDNS: Send the dnssec queries in parallel 2025-06-25 08:20:40 +02:00
Ali Mohammad Pur
833617c8fe LibDNS+dns: Avoid multi-question queries
This is not supported by much of anything (correctly), so send the
requests in parallel instead.
2025-06-25 08:20:40 +02:00
Ali Mohammad Pur
e47b1cc1a2 LibCore: Accept any Promise<T> in Promise::after() 2025-06-25 08:20:40 +02:00
Callum Law
536f8c395c LibWeb: Set numeric type of asin, acos, atan calculation results
Previously we were omitting the numeric type which meant these functions
weren't valid in some cases e.g. within rotate() functions.
2025-06-25 05:19:07 +01:00
devgianlu
4e747f525a LibCrypto+LibWeb: Check RSA keys validity on SubtleCrypto import_key
Fix various TODO by checking the validity of RSA keys when they are
imported.

Also add some internal tests since WPT doesn't seem to provide them.
2025-06-25 12:21:28 +12:00
devgianlu
1bf4e712ec LibWeb/Crypto: Do not swap endianness when importing base64 keys
This is wrong and leads to invalid numbers. We've been kind of
unfortunate in not catching this earlier because we skipped the key
validation part.

Many tests would fail with the next commits if this wasn't fixed.
2025-06-25 12:21:28 +12:00
devgianlu
d55f759bbb LibCrypto: Add LCM functionality to UnsignedBigInteger 2025-06-25 12:21:28 +12:00
devgianlu
adaa8e418a LibWeb/Crypto: Replace noop errors with VERIFY_NOT_REACHED 2025-06-25 12:21:28 +12:00
devgianlu
67e833a0c7 LibCrypto: Remove unused methods on RSAPublicKey 2025-06-25 12:21:28 +12:00
devgianlu
289f2b24bf LibCrypto+LibWeb: De-templetize RSA and EC key types
There is no need to have `RSAPrivateKey`, `RSAPublicKey`, `ECPrivateKey`
and `ECPublicKey` to be templatize to utilize different implementation
of numbers.
2025-06-25 12:21:28 +12:00
devgianlu
7f44b88eea LibCrypto+LibWeb: Check EC keys validity on SubtleCrypto import_key
Fix various TODO by checking the validity of ECDSA and ECDH keys when
they are imported. There are no checks in place for raw import because
the spec doesn't contemplate them yet.

Also add some internal tests since WPT doesn't seem to provide them.
2025-06-25 12:21:28 +12:00
devgianlu
a90950cac7 LibWeb: Update AesCbc::decrypt after spec fix 2025-06-25 12:21:28 +12:00
devgianlu
23c9b94e7b LibWeb: Remove bogus FIXME in Crypto::get_random_values
This is not supposed to support SharedArrayBuffers since they don't
implement ArrayBufferView.
2025-06-25 12:21:28 +12:00
devgianlu
d8d69c1650 LibCrypto: Remove unused VerificationConsistency enum 2025-06-25 12:21:28 +12:00
Andrew Kaster
0205f05319 CI: Add a sanity check to the JS artifacts workflow
This workflow has been broken in the past, so let's add a sanity check
to ensure that the REPL works.
2025-06-24 13:28:58 -06:00
Andrew Kaster
6cfb98fa7d CI: Add arm64 Linux JS artifact to GitHub Actions workflow 2025-06-24 13:28:58 -06:00
Tim Ledbetter
48f1bf7ef3 LibWeb: Remove Document::parse_url()
This is no longer used.
2025-06-24 19:55:43 +02:00
Tim Ledbetter
ff3d3840ac LibWeb: Replace usages of Document::parse_url()
The spec has been updated to use `encoding_parse_url()` and
`encoding_parse_and_serialize_url()` instead.
2025-06-24 19:55:43 +02:00
Aliaksandr Kalenik
8d6f2390f6 LibWeb: Set grid-auto-* to initial values when parsing grid-template
...as `grid` property value.
2025-06-24 19:14:08 +02:00
Ali Mohammad Pur
b0e471228d LibRegex: Avoid use-after-return of MatchState in 'is_an_eligible_jump'
The opcode may have last been accessed by
block_satisfies_atomic_rewrite_precondition, which would set it to a
state that no longer exists.
Set the state to the correct one unconditionally to ensure we're looking
at the right value.
Fixes #5145.
2025-06-24 18:43:01 +02:00
Ali Mohammad Pur
2947ae7d6e LibRegex: Move required bytecode.flatten() outside optimization function
Not running the optimization passes should not leave the bytecode in a
broken state. Fixes #5146.
2025-06-24 18:43:01 +02:00
Sam Atkins
423cdd447d LibWeb+LibGfx: Apply editorial punctuation/whitespace/markup fixes
Corresponds to d426109ea1
and fd08f81d06
2025-06-25 03:12:19 +12:00
Sam Atkins
a35d14eab3 LibWeb/HTML: Add or update spec steps in HTML parser
Partly corresponds to this which adds numbering to some substeps:
d426109ea1

This is not a complete review of all the spec steps to check that
they're up to date - I just updated the parts affected by that above
commit, and then added some `->` marks to places I noticed it was
missing. There may be actual spec differences still.

An actual change that needs tackling later is that `handle_in_head()`'s
branch for `<template>` has some new steps related to custom element
registries.
2025-06-25 03:12:19 +12:00
Sam Atkins
2e2b456009 LibWeb/DOM: Update spec steps for scrolling into view
Corresponds to dad91f49ef

The spec text doesn't actually require any changes from us, but I
noticed we were incorrectly calling `is_shadow_including_ancestor_of()`
instead of `is_shadow_including_inclusive_ancestor_of()`, so that's
fixed.
2025-06-25 03:12:19 +12:00
Tim Ledbetter
1c2b6ae03e LibWeb: Don't attempt to set the frozen base url on a null base element 2025-06-25 01:33:45 +12:00
Andrew Kaster
72a384bc1f AK: Set the console output code page to UTF-8
This fixes the broken emoji output from test-js.
2025-06-24 15:27:38 +02:00
Sam Atkins
8b6c32e3ab Tests: Import tests for scrollParent() and offsetParent() 2025-06-24 15:26:35 +02:00
Tim Ledbetter
2ff9e1d038 LibWeb: Apply clip rect before painting images
Previously, the clip property was ignored when painting images.
2025-06-24 12:56:28 +01:00
Tim Ledbetter
212d748ded LibWeb: Apply clip rect before painting background and foreground items 2025-06-24 12:56:28 +01:00
Callum Law
6584ae0080 LibWeb: Treat CSS selectors containing undeclared namespaces as invalid
Selectors containing undeclared namespaces should be considered invalid,
not just not matching any elements.

Gains us 3 new WPT passes.
2025-06-24 12:51:12 +01:00
Callum Law
5fcf3d0b05 LibWeb: Combine shared stylesheet parsing functionality
No functionality changes
2025-06-24 12:51:12 +01:00
Luiz
da14e072b7 LibWeb: Correctly handle serialization of PseudoElements
Previusly the implementation only was serializing PseudoElements if they
were the last element in the CompoundSelector. This caused bugs on
Javascript code that referenced their selectorText, where it would be
wrong.
2025-06-24 12:44:44 +01:00
Gingeh
b85a8a23a7 LibWeb: Handle percentage font-size values 2025-06-24 12:42:26 +01:00
Tim Ledbetter
b46378085d LibWeb: Absolutize keyframe values before interpolating 2025-06-24 12:36:47 +01:00
Jelle Raaijmakers
71f03cb785 LibWeb: Implement emulated Geolocation position retrieval
This implements enough of the Geolocation spec that it is now possible
for websites to retrieve the current geo position or try to watch for
updates (which currently never happen).

As it stands now, it only returns a single emulated position that points
to San Francisco.
2025-06-24 11:33:41 +02:00
Jelle Raaijmakers
53c35c5d3b LibWeb: Bring update_the_visibility_state() steps in sync with the spec
No functional changes.
2025-06-24 11:33:41 +02:00
Shannon Booth
1fed3d27c1 LibWeb/HTML: Don't set opaque origin on innerHTML document
This appears to no longer be necessary now that we are properly
handling the loading of image data for the <img> element.
2025-06-24 09:56:14 +02:00
Shannon Booth
0bdcaf02d3 LibWeb/HTML: Only update the image data on fully loaded document
Documents created by DOMParser and fragment documents do not
have an origin set on the document by the spec. These documents
also happen to never become fully active.

By properly implementing the steps for the <img> element to only
update the image data for documents which are fully active, this
fixes a crash for img elements in these types of documents.

Unfortunately, this is not a full fix for the microtask queue case.
This is because it seems possible for node document for an <img>
element to be changed during the microtask queue for that document.
It is not clear to me how this can be fixed in a nice way.
2025-06-24 09:56:14 +02:00
Shannon Booth
bc85a9bace LibWeb/HTML: Don't return any errors for update_the_img_data
There should not be any exceptions to propagate, so let's update
the return type accordingly.
2025-06-24 09:56:14 +02:00
Shannon Booth
3383a781f6 LibWeb/DOM: Support changing document to observe in DocumentObserver 2025-06-24 09:56:14 +02:00
stasoid
0e74736a53 LibTLS: Port to Windows 2025-06-23 18:58:01 -06:00
stasoid
6be0816172 LibCore: Add Windows implementation of TCPSocket::connect 2025-06-23 18:58:01 -06:00
stasoid
c14e6473d6 LibCore: Add Windows impl of System::socket, getaddrinfo, connect 2025-06-23 18:58:01 -06:00
Andrew Kaster
fbf8ffe872 AK: Only propagate delayload of dbghelp.dll for static builds
When AK is a shared library, the flag should be applied to the link
of the dll. When it's a static library, we need to apply it to the
executable that links against it instead.

Co-Authored-By: ayeteadoe <ayeteadoe@gmail.com>
2025-06-23 23:04:45 +02:00
Gingeh
4292344729 LibWeb: Don't skip last keyframe 2025-06-23 21:01:26 +02:00
InvalidUsernameException
f8f399c9c0 CI: Fix path to test-dumps folder of LibWeb tests for artifact upload
The CI runs are supposed to upload test dumps for failed LibWeb tests as
artifacts. However, the path for the artifact upload was wrong, it
likely regressed in 9a5b31ccd1.
2025-06-23 11:35:37 -06:00
Andrew Kaster
d9c85288d9 LibTLS: Remove blocking option and simplify Options struct
The complex macro for options with defaults doesn't make sense
now that there's only one option.
2025-06-23 17:49:21 +02:00
Andrew Kaster
955d747431 LibTLS: Use non-blocking TLS socket in the handshake test
None of our real code use cases actually use blocking mode. So we
should be testing non-blocking.
2025-06-23 17:49:21 +02:00
Callum Law
89a08cb7cf LibWeb: Update CSSRule parent style sheet whenever parent rule changes 2025-06-23 15:21:36 +01:00
Callum Law
f336667771 LibWeb: Don't carry quirks across to logical aliases 2025-06-23 15:19:07 +01:00
Callum Law
b0cdc3f03b LibWeb: Respect writing-mode and direction when mapping logical aliases 2025-06-23 15:19:07 +01:00
Callum Law
34a52baeed LibWeb: Add generic functionality for logical alias computed values 2025-06-23 15:19:07 +01:00
Callum Law
cfc8d3031b LibWeb: Map logical aliases at cascade time
Previously we would incorrectly map these in
`CSSStyleProperties::convert_declarations_to_specified_order`, aside
from being too early (as it meant we didn't maintain them as distinct
from their physical counterparts in CSSStyleProperties), this meant
that we didn't yet have the required context to map them correctly.

We now map them as part of the cascade process. To compute the mapping
context we do a cascade without mapping, and extract the relevant
properties (writing-direction and direction).
2025-06-23 15:19:07 +01:00
Callum Law
4e87f85458 LibWeb: Convert logical property shorthands to full-fledged shorthands
No functionality changes. This is just prep work for later commits
around moving logical alias mapping to cascade time
2025-06-23 15:19:07 +01:00
Callum Law
12581fa995 LibWeb: Resolve conflicts in compute_keyframe_values correctly
As conflict resolution depends on whether the property was set directly
or via a shorthand, we have to store the non-expanded values in the
resolved keyframe properties.
2025-06-23 15:19:07 +01:00
Tom Lynch
b3d459f4de LibGfx: Nearest neighbor scaling for ScalingMode::SmoothPixels 2025-06-23 16:05:52 +02:00
Tim Ledbetter
9b6da84fff LibWeb/CSS: Implement the font-kerning property
This sets whether the kerning information stored on the current font is
used.
2025-06-23 13:26:48 +01:00
Callum Law
80ea865b19 LibWeb: Use correct error for invalid rule in nested insertRule
When we try to insert a disallowed (non-nested) statement into a
CSSGroupingRule we should throw a `HierarchyRequestError` as it being
disallowed is a "constraint specified by CSS". Previously we would rely
on `Parser::is_valid_in_the_current_context` and throw a Syntax error.

There are more constraints to be implemented.
2025-06-23 12:52:40 +01:00
Callum Law
ef7ba02842 LibWeb: Throw error in insertRule when rule violates constraints 2025-06-23 12:52:40 +01:00
Callum Law
6144154e4f LibWeb: Ensure valid placement of @import and @namespace rules
These rules should appear before all other rules (excluding @layer
statements and @charset) with @import appearing first.
2025-06-23 12:52:40 +01:00
Glenn Skrzypczak
6b84cd8d11 LibWeb/HTML: Correctly set base elements frozen base url
This commit implements the fallback to the documents fallback base url
if the href of the first base element is a data or javascript url.

Additionally the frozen base url is set, if a base element becomes the
first base element with an href content attribute because the previous
one got removed.
2025-06-23 18:56:42 +12:00
Aliaksandr Kalenik
4ed9f6fcc0 LibWeb: Collapse auto-fit tracks in middle of tracks definition [GFC]
`collapse_auto_fit_tracks_if_needed()` had a check that does collapsing
only if auto-fit is used like
`grid-template-columns: repeat(auto-fit, 1px);`, and it didn't work for
valid cases when `repeat(auto-fit)` is placed in the middle of
definition like `grid-template-columns: 1px repeat(auto-fit, 1px) 1px;`.
2025-06-23 02:29:45 +02:00
Aliaksandr Kalenik
c333d0876c LibWeb: Simplify resolve_definite_track_size() [GFC] 2025-06-23 02:29:45 +02:00
Aliaksandr Kalenik
b315e80142 LibWeb: Don't use get_free_space() to count auto-fill/fit tracks [GFC]
Spec says that definite grid container size should be used as free space
so there's no need to use `get_free_space()` that does iteration over
tracks and subtracts definite sizes from available space.
2025-06-23 02:29:45 +02:00
Tim Ledbetter
ea29877385 Meta: Add --force option to WPT import script to update existing tests 2025-06-22 23:53:14 +02:00
Tim Ledbetter
689dff3ee8 Tests: Synchronize imported tests with the WPT repository 2025-06-22 23:51:34 +02:00
Tim Ledbetter
11e5cd5048 Meta: Don't lint imported WPT crash tests with prettier 2025-06-22 23:51:34 +02:00
Andrew Kaster
ca293af184 AK: Propagate delayload linker option for dbghelp.dll
When building a static liblagom-ak.a, the delayload link option gets
dropped on the floor if it's a PRIVATE link option. Use an interface
one instead.

This fixes the TestDelayLoadWindows unit test in static windows
builds.
2025-06-22 13:33:33 -06:00
Andrew Kaster
5783caf68e CMake: Add windows vcpkg triplet files to minimize port builds
Now we won't be building both debug and release for all ports when
using a release, distribution, or sanitizer preset.

Eventually we can use this to build all our ports with clang-cl.exe.
That doesn't work at all out of the box, and needs a bunch of extra
legwork. Likely legwork for every port we build.
2025-06-22 13:33:33 -06:00
Andrew Kaster
ffd946d47d CMake: Use cmake_path to check if vcpkg triplets are ours
This makes the check work with possibly-normalized windows paths
2025-06-22 13:33:33 -06:00
Andrew Kaster
b4cc34d0ae CMake: Prepend space to VCPKG_{C,CXX}_FLAGS in icu port overlay
When updating these variables, the appender is responsible for the
preceeding space. Otherwise, flags get jammed together.
2025-06-22 13:33:33 -06:00
Aliaksandr Kalenik
6ec6e755b2 LibWeb: Merge consecutive grid lines in GridTrackSizeList
Fixes a bug where consecutively defined grid lines were not merged
during serialization.
2025-06-22 21:15:40 +02:00
Jelle Raaijmakers
1be79a2b7b CI: Move nightly Windows build to nightly-lagom
Since lagom-template supports Windows builds now, we no longer need a
separate nightly-windows workflow.
2025-06-22 12:47:28 +02:00
Jelle Raaijmakers
60ced8197e CI: Move Windows CI to a separate workflow
Having the pull_request 'labeled' event trigger the main CI is much too
impactful, since it cancels running jobs and does not start anything if
the label is anything else than 'windows'. Let's go with a different
approach and put the Windows CI job in a separate workflow.

How this works:

  * Jobs are only run if the 'windows' label is present on the PR.
  * If a PR is opened or updated, existing jobs are canceled.
  * If a PR is (un)labeled, existing jobs are only canceled if the label
    was 'windows'. Other labels cause the job to be rescheduled.

As far as I can see, there's no way to prevent the job from being
rescheduled when labels other than 'windows' are being added or removed.
However, by not canceling the existing Windows job, we can try to create
a cache so the next run will be much quicker.
2025-06-22 12:47:28 +02:00
Jelle Raaijmakers
c6d848b100 CI: Disable the Windows CI job by using a boolean exclusion
Each matrix item now defines whether it is enabled, and if not, the job
conditionally disables itself. Apparantly we cannot use expressions in
`matrix.exclude`, but it should work in the items' definitions.

This has the added benefit that this makes the job show up as "skipped",
which could serve as a hint that it could be run on a PR.
2025-06-22 10:35:11 +02:00
Jelle Raaijmakers
b9d630edbc CI: Trigger Windows build on PR label 'windows'
Our CI matrix now includes Windows if the 'windows' label is added to
the PR. The job still takes too long to include it for every PR, but it
is certainly useful to have it run on Windows-specific PRs and PRs that
might break Windows builds.
2025-06-22 09:17:11 +02:00
Jelle Raaijmakers
433bbcfe19 CI: Make lagom-template.yml work for Windows builds 2025-06-22 09:17:11 +02:00
Jelle Raaijmakers
8493f74be1 CI: Remove PR-specific step from nightly Windows build 2025-06-22 09:17:11 +02:00
Jelle Raaijmakers
d73d768c12 AK: Define tzname for Windows in Time.cpp
Unbreaks the Windows build.

Co-authored-by: R-Goc <ryszardgoc@gmail.com>
2025-06-22 09:17:11 +02:00
Psychpsyo
3ab14f5595 Meta: Enforce doctypes on layout tests 2025-06-21 22:58:01 +02:00
Aliaksandr Kalenik
e6dabdcebe LibWeb: Serialize grid line names in GridFormattingContext
`getComputedStyle()` for grid tracks returns style value produced during
layout. This is needed to return resolved track sizes values which are
thrown away after layout is done. Now GFC produces more correct style
value by not ignoring grid line names.
2025-06-21 22:07:08 +02:00
Aliaksandr Kalenik
af602b2555 LibWeb: Align CSS Grid properties parsing with the specification
Reimplements `grid`, `grid-template`, `grid-template-rows`, and
`grid-template-columns` in a way that uses a separate function for each
grammar rule defined in the specification. This change results in many
additional passing tests from the already imported WPT suite. Most of
the remaining test failures are related to incorrect serialization of
grid properties.
2025-06-21 22:07:08 +02:00
Aliaksandr Kalenik
7b077595c3 Tests: Reimport css/css-grid/parsing/grid-template-columns-computed.html
Sync this test with upstream WPT where they added a new subtest in this
file.
2025-06-21 22:07:08 +02:00
Philipp Dreher
c414f0c43e Meta: Switch to different source for pre-commit feature in dev-container 2025-06-21 20:18:23 +02:00
Tim Ledbetter
dede92aa78 Tests: Update WPT testharness.js to the most recent version
This ensures that our test output looks the same as that shown in the
WPT runner.
2025-06-21 14:58:02 +02:00
Psychpsyo
c0e44820e9 Tests: Add doctypes to remaining test cases 2025-06-21 14:09:47 +02:00
Callum Law
d7036daa89 LibWeb: Disallow trailing tokens in @supports(<declaration>) 2025-06-21 11:49:43 +01:00
Jelle Raaijmakers
22bda8e5e2 LibWeb: Stub Geolocation API 2025-06-21 10:00:29 +02:00
Jelle Raaijmakers
f3c1dfb2f1 LibWeb: Import geolocation/idlharness.https.window.html WPT test 2025-06-21 10:00:29 +02:00
Jelle Raaijmakers
63fd4cf9e4 LibWeb: Add the EpochTimestamp IDL typedef 2025-06-21 10:00:29 +02:00
Jelle Raaijmakers
8f3fe0c39e LibWeb: Support nullable attributes in generated toJSON()
Any optional or nullable attribute will end up in an `if/else` branch
when we collect the attribute values, and this is inherently
incompatibly with an `auto {attr}_wrapped = ...` expression. Define the
variable as an `JS::Value` before generating the wrap statement so we
can properly support `toJSON()` for an attribute like:

  readonly attribute double? altitude;
2025-06-21 10:00:29 +02:00
Jelle Raaijmakers
30efcd0d00 LibWeb: Prevent time-traveling leading inline metrics
In `InlineLevelIterator`, whenever we call `skip_to_next()` and enter a
node with box model metrics, we could potentially accumulate leading and
trailing metrics. This lead to a weird situation where an element with
`display: inline-block` could adopt the leading metrics of an inline
element that follows it, since we perform the call to
`add_extra_box_model_metrics_to_item()` too late.

Move `skip_to_next()` down so it no longer interferes with the `Item`
we're creating.

The test expectation for
`atomic-inline-with-percentage-vertical-align.html` is updated, although
neither the old nor new results are 100% accurate since either box jumps
one pixel to the right.
2025-06-20 19:59:32 +02:00
Jelle Raaijmakers
de24bc5d26 Meta: Update CA certificates to version 2025-05-20 2025-06-20 07:11:44 -04:00
Tim Ledbetter
9c28fe42e8 WebContent: Fix typo in find_element_from_shadow_root() spec text
This typo was recently fixed in the WebDriver spec.
2025-06-20 09:27:22 +02:00
Tomasz Strejczek
7278a17e87 LibCore: Remove DateTime::to_string() and to_byte_string() 2025-06-19 18:42:45 -06:00
Tomasz Strejczek
6fb2be96bf Everywhere: Replace DateTime::to_string() with UnixDateTime::to_string()
Replace LibCore::DateTime::to_string() with
AK::UnixDateTime::to_string().
Remove unncessary #include <LibCore/DateTime.h>.
2025-06-19 18:42:45 -06:00
Tomasz Strejczek
8f8e51b1fc AK: Implement AK::UnixDateTime::to_string()
Copy implementation of LibCore::DateTime::to_string()
to AK.
Rename TestDuration.cpp to TestTime.cpp and add
there tests for to_string().
2025-06-19 18:42:45 -06:00
Andreas Kling
63d862219e LibWeb: Avoid expensive Vector::insert() in innerText & outerText
When expanding "required line breaks", we now write directly into the
final StringBuilder instead of doing a pass of Vector remove/insert
operations first.

This removes a hot profile item on https://serpapi.com/
2025-06-19 17:31:22 +02:00
Chase Knowlden
326a8399a4 Meta: Update vcpkg to latest master 2025-06-19 16:20:59 +02:00
Tim Ledbetter
70f9eb9d8f LibWeb: Remove Document::validate_qualified_name()
This is no longer used and appears to have been removed from the
specification.
2025-06-19 15:06:58 +02:00
Tim Ledbetter
16dbb44de2 LibWeb: Update DOMImplementation.createDocumentType() name validation
This now follows the latest specification steps.
2025-06-19 07:55:47 -04:00
Sam Atkins
f98312d022 LibWeb/DOM: Move pseudo-element scroll offsets into PseudoElement 2025-06-19 12:35:31 +01:00
Sam Atkins
2c7310553a LibWeb/Layout: Reuse create_pseudo_element_if_needed() for ::backdrop 2025-06-19 12:35:31 +01:00
Sam Atkins
9c656dd7d1 LibWeb/Layout: Only apply ::before/::after creation rules to them 2025-06-19 12:35:31 +01:00
Sam Atkins
c1d4323cf7 LibWeb: Support counter-* properties on pseudo-elements
There are multiple things happening here which are interconnected:

- We now use AbstractElement to refer to the source of a counter, which
  means we also need to pass that around to compute `content`.

- Give AbstractElement new helper methods that are needed by
  CountersSet, so it doesn't have to care whether it's dealing with a
  true Element or PseudoElement.

- The CountersSet algorithms now walk the layout tree instead of DOM
  tree, so TreeBuilder needs to wait until the layout node exists
  before it resolves counters for it.

- Resolve counters when creating a pseudo-element's layout node. We
  awkwardly compute the `content` value up to twice: Once to figure out
  what kind of node we need to make, and then if it's a string, we do
  so again after counters are resolved so we can get the true value of
  any `counter()` functions. This will need adjusting in the future but
  it works for now.
2025-06-19 12:35:31 +01:00
Sam Atkins
a6df9e1bac LibWeb/Layout: Store computed style for ::marker
This lets us refer to its properties later, for example to resolve its
counters.
2025-06-19 12:35:31 +01:00
Sam Atkins
67241d6419 LibWeb/DOM: Give PseudoElement a CountersSet
This is not yet used
2025-06-19 12:35:31 +01:00
Sam Atkins
23520509cc LibWeb/Layout: Expose which pseudo-element a node was generated for 2025-06-19 12:35:31 +01:00
Sam Atkins
46e95db355 LibWeb: Make Element::get_pseudo_element() public 2025-06-19 12:35:31 +01:00
Sam Atkins
498e143687 LibWeb/DOM: Stop including Element.h from AbstractElement.h
We only need the forward declaration here, and this will let us include
AbstractElement from Element.
2025-06-19 12:35:31 +01:00
Sam Atkins
dfce9974b5 LibWeb: Remove GeneratedPseudoElement enum
This doesn't currently provide any value over just using PseudoElement,
and makes it harder to work with PseudoElement in other places.
2025-06-19 12:35:31 +01:00
Sam Atkins
a57595faf5 LibWeb: Make [resolve,inherit]_counters() take AbstractElement
This is one of those cases where the spec says "element" and
means "element or pseudo-element". The easiest way to handle both is to
make these be free functions that take an AbstractElement, and then
give AbstractElement some helper methods so that the caller doesn't
have to care which it's dealing with.

There are some FIXMEs here because PseudoElement doesn't have a
CountersSet yet, and because the CountersSet currently uses a
UniqueNodeID to identify counter sources, which doesn't support
pseudo-elements.
2025-06-19 12:35:31 +01:00
Sam Atkins
ce380a59c7 LibWeb/DOM: Rename ElementReference to AbstractElement
This isn't some kind of identifier, it's a handle on an actual Element
or PseudoElement.
2025-06-19 12:35:31 +01:00
Sam Atkins
e7c2f0dd52 LibWeb: Make PseudoElement a class in its own right
It's getting a bit large and complicated to be a struct hidden in
DOM::Element.
2025-06-19 12:35:31 +01:00
Jelle Raaijmakers
e56146edec LibWeb: Limit scroll bar thumb movement based on grab point
We were calculating the scroll delta based on the last known mouse
position, even if that position ventured far beyond the scroll bar's
rect. This caused weird behavior such as scrolling when the mouse was
clearly not on the scrollbar.

This reworks the scrollbar logic to use the mouse's absolute position
instead of a delta, and to always calculate and set the absolute scroll
offset. This makes it much easier to reason about the scrollbar's
position, plus we don't need the last mouse position anymore.

As far as I can tell, our scroll bar behavior now closely resembles
Firefox' behavior.
2025-06-19 07:03:54 -04:00
Tim Ledbetter
727b4f5e89 LibWeb: Update attribute name validation in Document.createAttribute()
This now follows the latest specification steps.
2025-06-19 11:00:53 +01:00
Tim Ledbetter
ba641d4784 LibWeb: Update attribute name validation in Element.setAttribute()
This now follows the latest specification steps.
2025-06-19 11:00:53 +01:00
Tim Ledbetter
acf2d773d5 LibWeb: Update attribute name validation in Element.toggleAttribute
This now follows the latest specification steps.
2025-06-19 11:00:53 +01:00
Tim Ledbetter
4593c28769 LibWeb: Update validate_and_extract and its users to the latest spec 2025-06-19 11:00:53 +01:00
Tim Ledbetter
c6cc7e1874 Tests: Update dom/nodes/attributes.html WPT test 2025-06-19 11:00:53 +01:00
Tim Ledbetter
07b3b70a10 LibWeb: Return the correct computed value for opacity properties 2025-06-19 10:27:35 +02:00
Tim Ledbetter
269d5bb40e LibWeb: Resolve percentages for opacity properties at parse time 2025-06-19 10:27:35 +02:00
Jelle Raaijmakers
86c8dbbf90 CI: Restore cache action checks on inputs.ccache_path
These got removed by accident.
2025-06-18 18:58:00 +02:00
Jelle Raaijmakers
573696b10f CI: Use GitHub's actions cache instead of Blacksmith's for now
We were seeing lower ccache hitrates using Blacksmith's cache, and after
some investigation it turned out that actions running on our `master`
branch were pulling the caches from PRs. Blacksmith is looking into
this - for now revert to GitHub's cache until the issue is resolved.
2025-06-18 12:39:45 -04:00
Gingeh
e96338dd63 LibWeb: Don't play initially-paused animations 2025-06-18 17:17:29 +02:00
Aliaksandr Kalenik
6169e91994 LibWeb: Delete redundant GridFitContent class from track representation
GridSize already supports the FitContent type, so there is no need to
additionally wrap it in a GridFitContent class.
2025-06-18 15:51:10 +01:00
Tim Ledbetter
e0af205d69 LibWeb/CSS: Implement the empty-cells property
This property sets whether table borders and backgrounds are painted
if a given table cell has no visible content.
2025-06-18 14:55:03 +01:00
Sam Atkins
a0cef5a7da Meta: Only run WPT.sh cleanup routines on Linux
These use the `readarray` command which isn't available in the older
version of Bash available on macOS. However, they're also not needed on
macOS, so let's skip them entirely.

Ref: https://github.com/LadybirdBrowser/ladybird/issues/5118
2025-06-18 13:52:46 +01:00
Luke Wilde
ffae0d8b2d LibGfx/AVIF: Always reduce decoding output to a bit depth of 8
Gfx::Bitmap only supports a bit depth of 8, therefore we refused to
load AVIF images which didn't have this bit depth.

However, we can tell the libavif decoder to reduce the output depth by
setting avifRGBImage.depth to 8. This allows us to support any input
depth.

Makes images load on https://www.ikea.com/ which uses Cloudflare Images
to re-encode their images to 16-bit AVIF.
2025-06-18 14:27:24 +02:00
Shannon Booth
5f5975c81d LibWeb/HTML: Iterate safely in perform_a_microtask_checkpoint()
This list we are iterating over is removed from when there are
no more GC references to an ESO. This may be triggered by a GC
allocation. Since
UniversalGlobalScopeMixin::notify_about_rejected_promises performs
GC allocations (by, for example, allocating a GC function), it
is not safe to simply iterate over this list.

Fix this by taking a strong reference to all registered ESOs by
copying them across to a RootVector before iteration.

Fixes: #4652
2025-06-18 13:08:30 +02:00
Shannon Booth
00002c6443 LibWeb/HTML: Unregister ESO during finalize phase
It is generally safer for GC cells to do cleanup work during the
finalize phase.
2025-06-18 13:08:30 +02:00
Jelle Raaijmakers
3c0b125c1c Tests: Force layout in test to prevent flakiness 2025-06-18 12:52:24 +02:00
stelar7
3815a7c1eb LibWeb: Implement cleanup_indexed_database_transactions 2025-06-18 19:05:41 +12:00
Tim Ledbetter
fa1e02e5d7 LibWeb: Allow calc() values in cubic-bezier() easing functions 2025-06-18 08:57:06 +02:00
Tim Ledbetter
c5a3eaaf45 LibWeb: Allow calc() values in steps() easing functions 2025-06-18 08:57:06 +02:00
Veeti Paananen
21b531598d LibWeb/CSS: Fix reference bug when canonicalizing linear easing stops
+2 WPT tests
2025-06-18 08:53:10 +02:00
Gingeh
5e1e0d4e18 LibWeb: Remove some popover AD-HOC comments
Spec PR: https://github.com/whatwg/html/pull/11253
2025-06-18 08:51:22 +02:00
Shannon Booth
fc62a05c98 LibWeb/DOM: Set Document's origin in JS constructor
We were missing this spec step, which meant that the created
document had no origin, causing a crash when accessed for same-origin
checks.
2025-06-18 08:49:01 +02:00
Tomasz Strejczek
e03c558a0a AK: Implement demangle() for MSVC ABI
This implements demangle() using Windows API. Also some rudimentary
test is provided.
2025-06-17 18:39:18 -06:00
Carter Snook
1861f24979 LibJS: Avoid Symbol methods for RegExp on primitives
Normative PR: https://github.com/tc39/ecma262/pull/3009 (unmerged as of this commit)

There are a few test262 tests for this, see https://test262.fyi/#built-ins/String/prototype
JSC and Rhino have have already added these changes.
2025-06-17 17:54:36 -06:00
Colin Reeder
d4a5d16d27 LibGfx: Explicitly link against fontconfig 2025-06-17 16:55:50 -06:00
Colin Reeder
b7b5e71767 LibWeb: Explicitly link against GL 2025-06-17 16:55:50 -06:00
Colin Reeder
64f3765cce CMake: Add CMake script for finding libwebp 2025-06-17 16:55:50 -06:00
Ben Eidson
15aa7dce29 LibWeb/WebAudio: Implement AudioNode::connect()
Sets up the basic infrastructure for the audio node graph and
implements the AudioNode `connect()` method with its related overides.
AudioNodes store vectors of AudioNodeConnections and
AudioParamConnections to represent links between nodes.
2025-06-17 16:54:19 -06:00
Totto16
cee874caaf LibWeb: Factor out CanvasSettings mixin into separate file
This refactors this mixin, that was introduced in #4506 to be the same
as all other mixins, so that it can be used for #3788
2025-06-17 16:54:04 -06:00
stasoid
47da627653 Tests: Enable LibTest, LibTextCodec and LibUnicode tests on Windows 2025-06-17 16:19:22 -06:00
Daniel Bertalan
edeef940b6 LibJS: Fix pointer authentication failure in TypedArray
`TypedArray` objects need to know their own constructor objects to allow
copying. This was implemented by storing a function pointer to the
`Intrinsic` object's method which returns the constructor object.

The problem is that function pointers aren't polymorphic, we can't
legally just cast e.g. a `Derived* (*ptr)(void)` to `Base*
(*ptr)(void)` (this is why the code needed a `bit_cast` to even
compile). But this wasn't actually a problem in practice because their
ABIs were the same. But with pointer authentication (Apple's `arm64e`
ABI) this signature mismatch becomes a hard failure and crashes the
process.

Fix this by adding a virtual function that returns the intrinsic
constructor (actually, a `NativeFunction`, as typed arrays constructors
don't inherit from the base `TypedArray` constructor) instead of the
function pointer.

With this, test-js passes and Ladybird launches correctly when built
(with a lot of vcpkg hacks) for arm64e.
2025-06-17 15:44:37 -06:00
stasoid
460b257449 LibIPC: Enable in Windows CI 2025-06-17 15:36:47 -06:00
stasoid
8af2a49b5c LibIPC: Make TransportSocketWindows responsible for reading entire
messages. Port of a371f84 to Windows.
2025-06-17 15:36:47 -06:00
stasoid
ccf303eefc LibIPC: Move AutoCloseFileDescriptor to its own header 2025-06-17 15:36:47 -06:00
ayeteadoe
1893f89799 Meta: Update Windows Nightly CI to Windows 2025 Image with Sanitizers
Github Actions just updated windows-2025 to LLVM 20, which is the
minimum version required for us to build and run tests with sanitizers

Now that we've added support, enable the Sanitizer build in CI.
2025-06-17 15:33:26 -06:00
ayeteadoe
d9d6e55102 Tests: Disable test-js on Windows
It doesn't quite work in CI the same way it does with the VS Preview
locally.
2025-06-17 15:33:26 -06:00
ayeteadoe
56d7d50566 Meta: Add Windows sanitizer presets
Windows Clang supports both ASAN and UBSAN
2025-06-17 15:33:26 -06:00
ayeteadoe
35d39e6cbc CMake: Add support for building with sanitizers on Windows 2025-06-17 15:33:26 -06:00
ayeteadoe
3fd05306fc AK: Add abstraction for forcing empty base optimization on Windows
Without this annotation, the MSVC ABI is reluctant to apply EBO even
in cases that are basically guaranteed on the Itanium ABI by modern
compilers. This fixes an UBSAN issue with Variant on Windows.
2025-06-17 15:33:26 -06:00
stasoid
75b0e9a199 LibCore: Fix race condition in PosixSocketHelper::read on Windows
CancelIo introduces a race condition: if data arrives between calls to
WSARecv and CancelIo it will be lost.
See also: https://vstinner.github.io/asyncio-proactor-wsarecv-cancellation-data-loss.html
2025-06-17 20:56:32 +02:00
Shannon Booth
e0d7278820 LibURL+LibWeb: Make URL::Origin default constructor private
Instead, porting over all users to use the newly created
Origin::create_opaque factory function. This also requires porting
over some users of Origin to avoid default construction.
2025-06-17 20:54:03 +02:00
Shannon Booth
5deb8ba2f8 LibWeb: Explicitly set Document's origin
As part of the effort of removing the default constructor of
Origin, since document has the origin set after construction,
port Document's origin over to an Optional<Origin>.

This exposes that we were never setting the origin of the document
during fragment parsing. For now, to maintain previous behaviour,
let's explicitly set it to an opaque origin.
2025-06-17 20:54:03 +02:00
Shannon Booth
de79eb4410 LibWeb: Give NonFetchSchemeNavigationParams a constructor 2025-06-17 20:54:03 +02:00
Shannon Booth
0d905b1846 LibWeb: Give NavigationParams a constructor
This allows for NavigationParams to hold non-default constructable
types.
2025-06-17 20:54:03 +02:00
Shannon Booth
766cbf4937 LibGfx: Remove dependency on LibURL
This was previously a dependency (from ICC, if I recall correctly),
but this no longer appears to be the case.
2025-06-17 20:54:03 +02:00
Shannon Booth
1a34485460 LibWeb/HTML: Serialize time origin in environments
Which is caught from changing across to this form of initializing
the object.
2025-06-17 20:54:03 +02:00
Luke Wilde
f12b6b258f LibJS: Don't use presence of function params to identify function scope
Instead, we can just use the scope type to determine if a scope is a
function scope.

This fixes using `this` for parameter default values in arrow functions
crashing. This happened by `uses_this_from_environment` was not set in
`set_uses_this`, as it didn't think it was in a function scope whilst
parsing parameters.

Fixes closing modal dialogs causing a crash on https://www.ikea.com/

No test262 diff.

Reverts the functional part of 08cfd5f, because it was a workaround for
this issue.
2025-06-17 20:48:45 +02:00
Sam Atkins
26105b8b11 AK: Add a Formatter for Checked
This goes in Format.h instead of Checked.h, to avoid an include cycle.
2025-06-17 20:44:01 +02:00
Aliaksandr Kalenik
b9b6927b85 LibWeb: Fix swapped strings for auto-fill and auto-fit in GridRepeat
...serialization.
2025-06-17 17:43:04 +01:00
Jelle Raaijmakers
e8e6dbcee0 LibWeb: Fix document element's .scrollHeight and .scrollWidth
We were using the viewport's size as the viewport scrolling area, but
those are completely different things.
2025-06-17 17:17:34 +01:00
Jelle Raaijmakers
8f139d065c LibWeb: Simplify ViewportPaintable::assign_scroll_frames()
No functional changes.
2025-06-17 17:17:34 +01:00
Jelle Raaijmakers
e104d896eb LibWeb: Rename Navigable::m_size to ::m_viewport_size
All other viewport-related dimensions are referenced to by 'viewport',
so let's rename the member that stores the viewport size to prevent
further confusion.
2025-06-17 17:17:34 +01:00
Jelle Raaijmakers
46a46a1c61 LibGfx+LibWeb: Append glyphs in LineBoxFragment run more efficiently
Since we know the number of glyphs we're going to append, ensure the
LineBoxFragment run's capacity once and perform unchecked appends.
2025-06-17 17:03:33 +02:00
Jelle Raaijmakers
5ac067c804 LibGfx: Inline Font::pixel_metrics()
Calls to this method were showing up in profiles.
2025-06-17 17:03:33 +02:00
Jelle Raaijmakers
df20ac0f3c LibGfx: Optimize Gfx::measure_text_width()
Instead of constructing a GlyphRun, just add the X advances of all
glyphs to determine a text's width.
2025-06-17 17:03:33 +02:00
Jelle Raaijmakers
631c857301 LibGfx: Only determine glyphs info once in TextLayout
We were calling into `hb_buffer_get_glyph_infos()` twice and setting up
an unused `Vector<hb_glyph_info_t>`.
2025-06-17 17:03:33 +02:00
Jelle Raaijmakers
c91718148d LibWeb: Undo curious case of line wrapping 2025-06-17 17:03:33 +02:00
Jelle Raaijmakers
e80914a399 LibGfx: Use Vector::extend() to extend fonts in FontCascadeList
This only grows the capacity once, if required.
2025-06-17 17:03:33 +02:00
Jelle Raaijmakers
4a514020e0 LibWeb: Remove unused include from InlineLevelIterator 2025-06-17 17:03:33 +02:00
Sam Atkins
0e168ce631 Tests: Reimport dom/nodes/moveBefore tests
Apart from these moving out of `tentative/`, the
custom-element-move-reactions.html test was updated to be less flaky:
5e87cd92c0
2025-06-17 13:59:01 +02:00
Sam Atkins
7fe854c131 LibWeb/CSS: Link CalculationContext to new spec definition
Corresponds to ad244f3413

There's nothing that we need to do differently I think, but it's nice to
have a clear spec definition to refer to. :^)
2025-06-17 12:38:27 +01:00
Sam Atkins
a263ba78ed LibWeb/CSS: Add FIXME that color-mix() now takes 1+ colors, not 2
Corresponds to 83c7bffe51
2025-06-17 12:38:27 +01:00
Sam Atkins
af9a227ca3 LibWeb/HTML: Implement HTMLElement.scrollParent
Corresponds to d3effb701c

What a "fixed position container" is isn't clear to me, and we don't
seem to use that elsewhere, so I've left the steps using that as FIXMEs
for now.

There's no test coverage for this in WPT yet and I'm not confident
enough in the specific behaviour to write one myself. So, waiting on
https://github.com/web-platform-tests/wpt/issues/53214
2025-06-17 12:38:27 +01:00
Sam Atkins
5d5f16845c LibWeb/HTML: Bring HTMLElement::offset_parent() up to date 2025-06-17 12:38:27 +01:00
Sam Atkins
3fbd3146a1 LibWeb/DOM: Implement "is closed-shadow-hidden" algorithm 2025-06-17 12:38:27 +01:00
Sam Atkins
1435480d76 LibWeb/CSS: Add fixme for sRGB color interpolation
Corresponds to a0a9886063
2025-06-17 12:38:27 +01:00
Jelle Raaijmakers
046d1169de LibWeb: Only calculate enclosing rect for fragments if we use it
This would show up in profiles for pages with lots of fragments. No
functional changes.
2025-06-17 11:55:28 +02:00
Jelle Raaijmakers
7dc8062283 LibWeb: Store visibility for Paintables
For every invocation of `::before_paint()` and `::after_paint()`, we
would reach into the node's computed values to determine its visibility.
Let's just do this once during construction of the paintable instead,
since this was showing up in profiles.
2025-06-17 11:55:28 +02:00
Jelle Raaijmakers
1871843acb LibWeb: Reformat Node/PaintableBox::has_css_transform()
Slightly more visually pleasing. No functional changes.
2025-06-17 11:55:28 +02:00
Jelle Raaijmakers
ade5709939 LibWeb: Lazily obtain the Z-index for children in StackingContext
In `StackingContext::paint_descendants()`, we don't need to obtain the
computed values nor the Z-index of a child unless certain other
conditions are true. Let these conditions short-circuit before actually
reaching into the computed values, which shows up in profiles.
2025-06-17 11:55:28 +02:00
Jelle Raaijmakers
7d1ee3a2fa LibGfx+LibWeb: Perform unchecked appends related to text layout
Use unchecked appends in places where we know for certain the vector has
enough capacity.
2025-06-17 11:55:28 +02:00
Jelle Raaijmakers
2cba208366 LibWeb: Skip unnecessary alt text rendering work if alt is empty
Both text shaping and drawing operations were showing up in profiles,
even though the alt text was an empty string.
2025-06-17 11:55:28 +02:00
Jelle Raaijmakers
6710aa102a LibGfx: Return NonnullRefPtr in Gfx::shape_text()
We always return a glyph run here.
2025-06-17 11:55:28 +02:00
Jelle Raaijmakers
c999dd0c9f LibWeb: Remove unused includes
No functional changes.
2025-06-17 11:55:28 +02:00
Tim Ledbetter
59a2e10a4e LibWeb: Distinguish between empty block at-rules and statement at-rules 2025-06-17 08:58:00 +01:00
Tim Ledbetter
701fcb9e87 LibWeb: Allow anonymous layer block rule with no declarations 2025-06-17 08:58:00 +01:00
Tim Ledbetter
30cdacc05a LibWeb: Add flow relative values for the clear property
Currently `inline-start` and `inline-end` are always treated as `left`
and `right` respectively.
2025-06-17 09:26:26 +02:00
Tim Ledbetter
28b24b72bc LibWeb: Don't resolve flow-relative values for float too early
This allows `getComputedStyle()` to return the correct value if `float`
is set to `inline-start` or `inline-end`
2025-06-17 09:26:26 +02:00
dependabot[bot]
3f5c339d59 CI: Bump dawidd6/action-download-artifact from 9 to 11
Bumps [dawidd6/action-download-artifact](https://github.com/dawidd6/action-download-artifact) from 9 to 11.
- [Release notes](https://github.com/dawidd6/action-download-artifact/releases)
- [Commits](https://github.com/dawidd6/action-download-artifact/compare/v9...v11)

---
updated-dependencies:
- dependency-name: dawidd6/action-download-artifact
  dependency-version: '11'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-06-17 09:25:36 +02:00
Tim Ledbetter
6c6219db05 LibWeb: Use shorthand keywords for contain used value where possible
The used value of `contain` is now set to `strict` or `content` when
the relevant set of containment keywords are specified.
2025-06-17 08:17:33 +01:00
Tim Ledbetter
96d8bed35b LibWeb/CSS: Serialize contain values in canonical order 2025-06-17 08:17:33 +01:00
R-Goc
8534370dbc Meta: Remove incorrect flag from lagom
This commit removes the /J flag when compiling with clang-cl. The /J
flag changes the default char type from signed char to unsigned char
which is the opposite of what we want. Now char will be signed, which is
the default on msvc and what we set on linux.
2025-06-16 11:48:41 -06:00
R-Goc
cdc851141d Meta: Increase compilation speed with clang-cl
This commit increases compilation speed when using clang-cl. It also
decreases object size as well as adds -fstrict-aliasing to match the
default on linux. The linker option added is not recognized by link.exe
so we enable lld-link by default, which will also increase compilation
speed by itself, and allow for LTO.
2025-06-16 11:48:41 -06:00
R-Goc
af056581f6 Meta: Format common_compile_options.cmake
This commit formats common_compile_options to use 4 space indenting
consistently.
2025-06-16 11:48:41 -06:00
Viktor Szépe
19f88f96dc Everywhere: Fix typos - act III 2025-06-16 14:20:48 +01:00
Manuel Zahariev
51b4b4a270 LibWeb: Tests for recalculating ordinals after list manipulation
FIXME: Rendering modifications to a list is sometimes not pixel-perfect
       vs. reference (likely a bug). After this is fixed, screenshot
       tests from this commit will likely fail + can be moved to
       ref tests.
2025-06-16 12:44:58 +01:00
Manuel Zahariev
20546725be LibWeb: Tests for rendering lists and their ordinals
The following tests also expose bugs before this PR:
- Layout/input/ol-render-item-values.html: negative ordinal values
- Layout/input/ol-render-deep-hybrid-list-item-list.html: ordinals
  deep into the list owner subtree
2025-06-16 12:44:58 +01:00
Manuel Zahariev
00d43b39d1 LibWeb: Retain calculated Element::ordinal_value for lists
`Element::ordinal_value` is called for every `li` element in
a list (ul, ol, menu).

Before:
  `ordinal_value` iterates through all of the children of the list
  owner. It is called once for each element: complexity $O(n^2)$.

After:
  - Save the result of the first calculation in `m_ordinal_value`
  then return it in subsequent calls.
  - Tree modifications are intercepted and trigger invalidation
    of the first node's `m_ordinal_value`:
    - insert_before
    - append
    - remove
  Results in noticeable performance improvement rendering' large
  lists: from 20s to 4s for 20K elements.
2025-06-16 12:44:58 +01:00
Manuel Zahariev
d27b43c1ee LibWeb: Add specialized fast_is for lists
Before:
  `is<HTMLOLListElement>` and other similar calls in this commit
  are resolved to `dynamic_cast`, which incurs runtime overhead
  for resolving the type. The Performance hit becomes apparent
  when rendering large lists. Callgrind analysis points to a
  significant performance hit from calls to `is<...>` in
  `Element::list_owner`.

Reference: Michael Gibbs and Bjarne Stroustrup (2006) Fast dynamic
casting. Softw. Pract. Exper. 2006; 36:139–156

After:
  Implement inline `fast_is` virtual method that immediately
  resolves the type. Results in noticeable performance improvement
  2x-ish for lists with 20K entries.

Bonus: Convert starting value for LI elements to signed integer
    The spec requires the start attribute and starting value to be
    "integer". Firefox and Chrome support a negative start attribute.

FIXME: At the time of this PR, about 134 other objects resolve
`is<...>` to `dynamic_cast`. It may be a good idea to coordinate
similar changes to at least [some of] the ones that my have impact
on performance (maybe open a new issue?).
2025-06-16 12:44:58 +01:00
Callum Law
12c9da2d3f LibWeb: Serialize grid/grid-template as "none" when applicable
This exposes a bunch of false-positives in the
grid-{shorthand,template}-invalid.html WPT tests, but gains us some
new passes as well.
2025-06-16 12:37:40 +01:00
Callum Law
7d81823eb3 LibWeb: Handle CSS-wide keywords in style_property_for_sided_shorthand
CSS-wide keywords should not be concatenated in the same way as other
values unless they are all the same.
2025-06-16 12:37:40 +01:00
Callum Law
62da650992 LibWeb: Don't serialize longhands if we directly serialized shorthand
The spec assumes that we only store values against expanded longhands,
there are however limited circumstances where we store against
shorthands directly in addition to the expanded longhands. For example
if the value of the shorthand is unresolved we store an
UnresolvedStyleValue against the shorthand directly and a
PendingSubstitutionStyleValue against each of the longhands.

This commit updates the logic so that in the case we serialize a
shorthand directly we should also mark it's longhands as serialized to
avoid serializing them separately.

This also avoids the scenario where we tried to create and serialize a
ShorthandStyleValue with PendingSubstitutionStyleValue longhands, so we
can remove the check and related FIXME for that.
2025-06-16 12:37:40 +01:00
Callum Law
f8f4da3b90 LibWeb: Don't serialize shorthand with non-uniform CSS-wide keywords 2025-06-16 12:37:40 +01:00
Callum Law
3c6b8d5a2c LibWeb: Propagate CSS-wide keyword to transition longhands
Previously we would treat CSS-wide keywords as equivalent to "none"
2025-06-16 12:37:40 +01:00
Callum Law
335190e925 LibWeb: Handle nested shorthands in all-same-CSS-wide-keyword to_string
Previously we only checked direct sub-properties, not accounting for the
nested case.
2025-06-16 12:37:40 +01:00
Prajjwal
e1d2582680 LibWeb: Resolve FIXME in media select resource algorithm
Fixes at least three WPT test that were previously timing out:
- html/semantics/embedded-content/media-elements/error-codes/error.html
- html/semantics/embedded-content/media-elements/location-of-the-media-resource/currentSrc.html
- html/semantics/embedded-content/the-video-element/video_crash_empty_src.html
2025-06-16 23:28:10 +12:00
aplefull
bfc79a403d LibGfx: Fix ICC v2 profiles with table-based L* curves
Skia's SkColorSpace::Make() doesn't seem to like ICC v2 profiles
containing table-based L* transfer curves. Now we use
skcms_ApproximateCurve() to convert these tables to parametric curves
that Skia supports in case Skia's SkColorSpace::Make() fails.
2025-06-16 11:31:42 +02:00
aplefull
c4fadc1abf LibMedia: Add support for YUVJ pixel formats in FFmpegVideoDecoder 2025-06-16 10:26:41 +02:00
Lucas CHOLLET
b844f3219e AK: Avoid a copy in StringBuilder's default constructor 2025-06-16 09:44:29 +02:00
Tim Ledbetter
7faeef8d0d LibWeb: Treat font-variant values with unknown keywords as invalid 2025-06-15 16:44:51 +02:00
Tim Ledbetter
d89a67ffee LibWeb: Don't serialize omitted box-shadow and text-shadow values 2025-06-15 16:05:12 +02:00
Tim Ledbetter
68d3ddb1a7 LibWeb: Parse the transform-origin z-value 2025-06-15 16:01:54 +02:00
Tim Ledbetter
a8d5758777 LibWeb: Only resolve transform-origin keywords for the computed value
Previously, we were resolving these keywords at parse time, which gave
an incorrect serialization of the specified value.
2025-06-15 16:01:54 +02:00
Tim Ledbetter
a3f6e71e33 LibWeb/CSS: Disallow third argument in 2D scale functions 2025-06-15 15:59:02 +02:00
Tete17
e7906f4332 LibWeb: Import decompression-corrupt-input.tentative.any.html tests
It is now fully green :)
2025-06-14 18:26:56 -04:00
Tete17
81bfb51756 LibCompress: Handle the error state where a dictionary is needed
For zlib is not necessarily an error state but the web standards do not
support this feature and the WPT tests explicitly check for this case
to be handled as an error.
2025-06-14 18:26:56 -04:00
Tete17
7a235537e8 LibCompress: Error out when encounters and incomplete stream
If we find ourselves in a situation where zlib can't make any progress,
we don't have any more data to feed in and no output has been produced,
we need to raise an error as the compressed data is incomplete.

This used to lead to an infinite busy loop where we keep calling
zlib to decompressed but is not able. This causes the promise on the
read side of the transformer to never fulfill.

This gives us at least 24 more WPT tests :)
2025-06-14 18:26:56 -04:00
Tim Ledbetter
39cef6eeb5 LibWeb: Disallow default as a keyframe name 2025-06-14 17:56:10 -04:00
Tim Ledbetter
64728aef6c LibWeb: Disallow non-ASCII font-language-override values 2025-06-14 16:05:04 -04:00
Tim Ledbetter
cb818c8245 AK: Add FlyString::is_ascii()
This matches the method already available present in String.
2025-06-14 16:05:04 -04:00
Tim Ledbetter
c55f281475 LibWeb: Disallow empty font-language-override string values 2025-06-14 16:05:04 -04:00
rmg-x
a4d931d14a LibCore+LibIPC: Move various encode/decode specializations to LibIPC
This removes a dependency on LibIPC from LibCore.
2025-06-14 16:03:26 -04:00
rmg-x
18f28f398b LibCore+LibIPC: Remove badge on File::leak_fd
This removes a dependency on LibIPC from LibCore.
2025-06-14 16:03:26 -04:00
Daniel Bertalan
d06809dee6 AK: Use __is_trivially_destructible built-in with new enough GCC
GCC 16 trunk has started diagnosing calls to `__has_trivial_destructor`
if the destructor is inaccessible. At the same time, they added a
Clang-compatible `__is_trivially_destructible` built-in trait, so let's
just use that.
2025-06-14 16:02:40 -04:00
Tim Ledbetter
028bcd3d67 LibWeb/CSS: Backtrack the parser if a property does not accept a value 2025-06-14 08:22:56 +02:00
Tim Ledbetter
26293114d8 LibWeb/CSS: Treat repeated text-decoration-line values as invalid 2025-06-14 08:19:47 +02:00
Aliaksandr Kalenik
fdecdb9410 LibWeb/CSS: Remove unused default constructors in GridTrackSize.h 2025-06-13 19:57:00 +02:00
Aliaksandr Kalenik
237356c5ca LibWeb: Return const& from GridSize::length_percentage() 2025-06-13 19:57:00 +02:00
Aliaksandr Kalenik
97639d1d74 LibWeb: Return const& from GridFitContent::max_grid_size() 2025-06-13 19:57:00 +02:00
Aliaksandr Kalenik
1009a6e8c4 LibWeb: Return const& from GridMinMax getters 2025-06-13 19:57:00 +02:00
Aliaksandr Kalenik
9c7c33e0aa LibWeb: Return const& from GridRepeat::grid_track_size_list() 2025-06-13 19:57:00 +02:00
Aliaksandr Kalenik
cdf3e52172 LibWeb: Return const& from GridTrackSizeList::list() 2025-06-13 19:57:00 +02:00
Aliaksandr Kalenik
286771457a LibWeb/CSS: Use default operator== where possible in GridTrackSize
No behavior change.
2025-06-13 19:57:00 +02:00
Aliaksandr Kalenik
8d83dce1d7 LibWeb: Use variant to represent CSS::ExplicitGridTrack
No behavior change.
2025-06-13 19:57:00 +02:00
Jelle Raaijmakers
a321eca9d7 LibWeb: Change default :focus-visible outline to a solid accent color 2025-06-13 17:39:11 +02:00
Jelle Raaijmakers
15c436b332 LibWeb: Implement basic focus indication for :focus-visible
This causes links to no longer show an outline when clicked; only when
using keyboard navigation with the tab key will the outline show up.
2025-06-13 17:39:11 +02:00
Jelle Raaijmakers
66813aea79 LibWeb: Run focusing steps on navigation with the tab key
We run these steps when focusing with a mouse pointer, and it seems
sensible to implement the same behavior for keyboard navigation so we
e.g. correctly unwind the previous focus chain.
2025-06-13 17:39:11 +02:00
Jelle Raaijmakers
7016921067 LibWeb: Remember last focus trigger in Document
We will need this to implement focus indication.
2025-06-13 17:39:11 +02:00
Jelle Raaijmakers
e4586abc18 LibWeb: Return EventResult in EventHandler::focus_next/previous_element
No functional changes.
2025-06-13 17:39:11 +02:00
Jelle Raaijmakers
dd4d7d0939 LibGfx: Ensure capacity for glyph runs in TextLayout
We can reserve the capacity for new glyph runs since we already know the
glyph count.
2025-06-13 17:31:18 +02:00
Timothy Flynn
911ea2b379 LibCore: Ensure we don't replace an already-installed event loop manager
Once an event loop manager is installed, we want to be sure we only use
that manager in the current process going forward. Mixing event loop
implementations can only cause problems.

More to the point, this ensures that we have installed the AppKit or Qt
event loop managers before the first time EventLoopManager::the() is
invoked. Now that we defer this installation until we know whether we
are running headlessly, we want to be extra sure that we have done so
before any services using the event loop have started.
2025-06-13 17:06:16 +02:00
Callum Law
64d79d4c3f LibWeb: Avoid overwriting resolved values in compute_keyframe_values
When we have an unresolved value for a shorthand (e.g. `border-style:
var(--border-style)`, `keyframe_values` will contain an
`UnresolvedStyleValue` for the shorthand and
`PendingSubstitutionStyleValue`s for each of it's longhands.

When we come across the shorthand's `UnresolvedStyleValue` we will
resolve the value and set all of the relevant longhands.

If the longhand's `PendingSubstitutionStyleValue` was processed after
(which isn't always the case as the iteration order depends on a
HashMap) would overwrite the correctly resolved longhand.

To avoid this we just skip any `PendingSubstitutionStyleValue`s we come
across and rely on the resolution of the shorthand to set those
properties.

Resolves a crash @tcl3 was experiencing when adding a new
"border-image-repeat" property.
2025-06-13 17:06:00 +02:00
Luke Wilde
2dead9231d RequestServer: Handle client disappearance more gracefully
Without these fixes, RequestServer was likely to crash if the client
crashed (e.g. WebContent). This was because there was no error handling
for when writing to the client failed.

This is particularly an issue because RequestServer has shared
instances, so it would then crash every other client of RequestServer.
Then, because another RequestServer instance is not currently spun up,
it becomes impossible to start any clients that need a RequestServer
instance. Recreating a RequestServer should also be handled, but that's
not in the scope of this change.

We can tell curl that we failed to write data to the client and that
the request should be aborted by returning `CURL_WRITEFUNC_ERROR` from
the write callback.

It is also possible for requests to be destroyed with buffered data,
which is normal to happen if the client disappears
(i.e. ConnectionFromClient is destroyed) or the request is cancelled by
the client. We log a warning in case this is not expected, to assist
with debugging related issues.
2025-06-13 17:03:57 +02:00
Jelle Raaijmakers
01ede6cc58 AK: Add fast paths for Utf8View::*_offset_of() methods
If all code points in the string are represented by a single byte, we
can simply take the fast path of returning the input for these methods.
2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
7beecaa43d LibWeb: Rename PaintableFragment::m_start and ::m_length
Make it extra clear that we're dealing with byte offsets here. No
functional changes.
2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
3df83dade8 LibWeb: Treat DOM::Range offsets as UTF-16 code unit offsets
We generated `PaintableFragment`s with a start and length represented in
UTF-8 byte offsets, but failed to consider that the offsets in a
`DOM::Range` are actually expressed in UTF-16 code units.

This is a bit of a mess: almost all web specs use UTF-16 code units as
the unit for indexing into text nodes, but we almost exclusively use
UTF-8 in our code base. Arguably the best thing would for us to use
UTF-16 everywhere as well: it prevents these mismatches in our
implementations for the price of a bit more memory usage - and even that
could potentially be optimized for.

But for now, try to do the correct thing and lazily allocate UTF-16 data
in a `PaintableFragment` whenever we need to index into it or if we're
asked to determine the code unit offset of a pixel position.
2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
dbbdf2cebc LibWeb: Improve caret positioning behavior inside fragments
When clicking on a glyph or starting a selection on it, we would use the
glyph's offset/index as the position which represents the left side of
the glyph, or the position between the glyph and the glyph before it.

Instead of looking at which glyph is under the mouse pointer, look at
which glyph boundary is closer. Now, if you click to the right of a
glyph (but still on that glyph), it correctly selects the next glyph's
offset as the position.
2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
408165d2f4 AK: Return early in utf8_to_utf16() for empty strings
No need to validate an empty string.
2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
6f926e6977 AK: Add Utf8View::code_point_offset_of() 2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
cea9012b5b LibWeb: Simplify Selection::cursor_position()
No functional changes.
2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
2d6da6e112 AK: Remove superfluous check from Utf16View::subtring_view()
The `Span::slice()` operation just below it performs the exact same
check.
2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
0d543b604b AK: Make more use of lazily calculated code point count in Utf16View
In 0c93a07fb1, a lazily calculated code
point count was introduced but was not used in all places where we need
that count. No functional changes.
2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
9126507dc6 LibWeb: Make fragment start/length size_t instead of int
These must always be unsigned. No functional changes.
2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
b42c2c5e8f LibWeb: Use code unit offsets in Document::find_matching_text()
We were passing in byte offsets instead of UTF-16 code unit offsets,
which could lead to crashes if the offsets found exceeded the number of
code units in text fragments on the page.

Fixes #4908.

Co-authored-by: Tim Ledbetter <tim.ledbetter@ladybird.org>
2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
cc0a28ee7d AK: Add Utf16View::find_code_unit_offset(_ignoring_case) 2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
7d7f6fa494 AK: Remove superfluous check from Utf16View::equals_ignoring_case()
Returning true if both lengths are 0 is already handled by the default
case.
2025-06-13 15:08:26 +02:00
Jelle Raaijmakers
b558b4dba6 AK: Add Span<T>::index_of(ReadonlySpan)
This will be used for case-sensitive substring index matches in a later
commit.
2025-06-13 15:08:26 +02:00
rmg-x
5e9ceac16c LibDNS: Add debug messages for error response codes in resolver 2025-06-13 11:42:01 +02:00
Timothy Flynn
de34143a4e LibWeb: Do not spin the event loop awaiting text track state changes
The text track processing model would previously spin forever waiting
for the track URL to change. It would then recursively invoke itself
to handle the new URL, again entering the spin loop. This meant that
tracks could easily cause event loop hangs.

We now have an observer system to be notified when the track state
changes instead. This lets us exit the processing model and move on.
2025-06-12 12:25:23 -04:00
Timothy Flynn
24ac860998 LibWeb: Set the "loading" flag for HTMLTrackElement sooner
We don't want to wait for the queued task to run to indicate that the
processing model is in progress.
2025-06-12 12:25:23 -04:00
Timothy Flynn
8da6731048 LibWeb: Do not capture local lambda by reference in HTMLTrackElement
This is UAF. It will cause a crash in an upcoming commit.
2025-06-12 12:25:23 -04:00
Timothy Flynn
c6a94fe513 LibWeb: Do not return a GC::Root from HTMLTrackElement's track getter
There's no need to create a root each time the getter is called. We
should also allocate it in the `initialize` overload rather than the
constructor.
2025-06-12 12:25:23 -04:00
Aliaksandr Kalenik
642dd751cf test-web: Disable SQL database usage
We have a test for localStorage that repeatedly adds new items until the
quota is exceeded:
`webstorage/storage_local_setitem_quotaexceedederr.window.html`.

This test becomes significantly slower when localStorage is backed by
SQL database. Let's disable database usage in test mode for now, as this
test is likely to be flaky on CI due to timeouts.
2025-06-12 17:04:35 +02:00
Aliaksandr Kalenik
84b9224121 Everywhere: Implement persistence of localStorage using sqlite
This change follows the pattern of our cookies persistence
implementation: the "browser" process is responsible for interacting
with the sqlite database, and WebContent communicates all storage
operations via IPC.

The new database table uses (storage_endpoint, storage_key, bottle_key)
as the primary key. This design follows concepts from the
https://storage.spec.whatwg.org/ and is intended to support reuse of the
persistence layer for other APIs (e.g., CacheStorage, IndexedDB). For
now, `storage_endpoint` is always "localStorage", `storage_key` is the
website's origin, and `bottle_key` is the name of the localStorage key.
2025-06-12 17:04:35 +02:00
Aliaksandr Kalenik
f53559cb55 LibWeb: Change Storage{Bottle,Bucket,Shelf} to be GC-allocated
In upcoming changes StorageBottle will own pointers to GC-allocated
objects, so it needs to be a GC-allocated object itself to avoid
introducing more GC roots.
2025-06-12 17:04:35 +02:00
Aliaksandr Kalenik
70a29f36c6 WebContent: Delete unused get_local{session}_storage_entries() IPC calls 2025-06-12 17:04:35 +02:00
Callum Law
d31a58a7d6 LibWeb: Add support for the 'all' CSS property
The "longhands" array is populated in the code generator to avoid the
overhead of manually maintaining the list in Properties.json

There is one subtest that still fails in
'cssstyledeclaration-csstext-all-shorthand', this is related to
us not maintaining the relative order of CSS declarations for custom vs
non-custom properties.
2025-06-12 15:25:35 +01:00
Jelle Raaijmakers
0762d57f65 LibWeb: Remove accidentally added test expectation
This was added in 4b6489917b.
2025-06-12 13:09:26 +02:00
Jelle Raaijmakers
4b6489917b LibGfx: Disable tech(variations) font support for now
We apparently don't support it in the right way, since it causes the
wrong font to display on https://ladybird.org.
2025-06-12 11:04:37 +01:00
Andrew Kaster
aab0f3c23f CMake: Re-enable SIL verification for swift source files
The associated Swift bug has been fixed on main.
2025-06-11 11:54:52 -06:00
Andrew Kaster
b6d0069015 Documentation: Update swift preset documentation 2025-06-11 11:54:52 -06:00
Andrew Kaster
ab661467e7 Meta: Support Swift_Release preset in ladybird.py 2025-06-11 11:54:52 -06:00
Andrew Kaster
a0173b342f CMake: Add preset with swift interop enabled 2025-06-11 11:54:52 -06:00
Andrew Kaster
0b7a6ef4c9 Meta: Record desired swift toolchain version in .swift-version
This makes it easier to ensure everyone is using the same version of
Swift when building the project, especially for CI environments.

`swiftly install` will automatically read this file and install the
specified version if it is not already installed. It also tells swiftly
what version to use for the project, independent of the global default
version.
2025-06-11 11:54:52 -06:00
Andrew Kaster
3b9756d9b1 Meta: Add optional cwd argument to run_command helper
This just passes it through to subprocess.Popen, so it can be used to
run commands in a specific directory if needed.
2025-06-11 11:54:52 -06:00
Andrew Kaster
a267743095 LibGfx: Avoid importing FilterImpl into swift
This header uses skia directly, and is not needed in swift.
2025-06-11 11:54:52 -06:00
Ali Mohammad Pur
4b5664f867 LibWebView+RequestSever: Wire up a validate-DNSSEC setting option to RS 2025-06-11 18:16:29 +02:00
Ali Mohammad Pur
b24fb0a836 LibDNS: Add support for local DNSSEC validation 2025-06-11 18:16:29 +02:00
Ali Mohammad Pur
59b6293182 LibCore: Add a Promise::after(promises) API
This is equivalent to Promise.all() in js, more or less.
2025-06-11 18:16:29 +02:00
Ali Mohammad Pur
6c312188dc AK: Let CountingStream take an initial value for the counter 2025-06-11 18:16:29 +02:00
Ali Mohammad Pur
3dd246a8e1 LibCrypto: Add support for raw EC keys and SECPxxxr1 signatures 2025-06-11 18:16:29 +02:00
Ali Mohammad Pur
b374322e38 LibTLS: Make TLSv12::can_read_without_blocking() respect the timeout arg
Previously this function's return value was not reliable, as available
data on the underlying socket did not necessarily translate to available
application data on the TLS socket.
2025-06-11 18:16:29 +02:00
Sam Atkins
00f76ccbf4 LibWeb/CSS: Add alternative src() syntax for URLs
url() has some limitations because of allowing unquoted URLs as its
contents. For example, it can't use `var()`. To get around this, there's
an alternative `src()` function which behaves the same as `url()` except
that it is parsed as a regular function, which makes `var()` and friends
work properly.

There's no WPT test for this as far as I can tell, so I added our own.
2025-06-11 16:26:23 +02:00
Andreas Kling
ea0bfda1b9 LibWeb: Cache the font in StyleComputer::initial_font()
This function is bogus, but it's still getting called a lot during media
query evaluation, so let's at least cache the font instead of recreating
it every single time.
2025-06-11 16:25:42 +02:00
Andreas Kling
07ff75bbec LibWeb: Don't traverse entire layout tree in every HTML::EventLoop tick
Instead, collect a list of all the elements with content-visibility:auto
after layout.

This way we can skip the tree traversal when updating the rendering.

This was previously eating up ~300 µs of the 60fps frame budget on
our GitHub repo pages (and even more on large pages).
2025-06-11 16:25:42 +02:00
Timothy Flynn
df0dc32006 LibWebView: Defer creating services until after application init
In particular, we need to defer creating the process manager until after
we have decided whether or not to create a UI-specific event loop. If we
create the process manager sooner, its event loop signal registration
does not work, and we don't handle child processes exiting.
2025-06-11 08:26:29 -04:00
Timothy Flynn
39da2d9a2f LibWebView+UI: Migrate some UI process init to LibWebView
No need to do this setup in every UI's main().
2025-06-11 07:26:32 -04:00
Timothy Flynn
6430b215af LibWebView: Make WEB_VIEW_APPLICATION switch back to a private section
Let's not leave everything after the WEB_VIEW_APPLICATION invocation
public.
2025-06-11 07:26:32 -04:00
Timothy Flynn
b425ce93b1 LibWebView+UI: Don't declare a magic ctor for Application subclasses
You would have to just know that you need to define the constructor with
this declaration. Let's allow subclasses to define constructors as they
see fit.
2025-06-11 07:26:32 -04:00
Timothy Flynn
3a4f2faf2e Meta: Use Optional[str] instead of str | None for python 3.9 compat 2025-06-10 18:59:01 -04:00
Timothy Flynn
fa164083fd LibWebView+UI: Do not create a QApplication in headless mode
This is causing errors on the WPT runner, which does not have a display
output. To do this requires shuffling around the Main::Arguments struct,
as we now need access to it from overridden WebView::Application methods
after construction.
2025-06-10 23:10:48 +01:00
Timothy Flynn
f66cac3417 LibWebView+UI: Define concrete Application::the accessor automatically
This avoids assuming that the Qt Application is a QApplication, which
will not be the case in an upcoming commit.
2025-06-10 23:10:48 +01:00
ayeteadoe
f2a10bda32 CMake: Simplify preset structure for Windows
As we now are only officially supporting the Ninja generator for
Windows, the old preset structure can now be simplified. Also, we
now follow the naming conventions of the non-hidden presets.
2025-06-10 11:29:29 -06:00
Timothy Flynn
9a5b31ccd1 LibWebView+Tests+UI: Migrate headless-browser to test-web
Now that headless mode is built into the main Ladybird executable, the
headless-browser's only purpose is to run tests. So let's move it to the
testing directory and rename it to test-web (a la test-js / test-wasm).
2025-06-10 12:04:59 -04:00
Timothy Flynn
c011dc766f LibWebView+WebDriver+UI: Migrate headless browsing to main Ladybird exe
We currently create a separate headless-browser application to serve two
purposes:

1. Allow headless browsing to take a screenshot of a page or print its
   layout tree / internal text.
2. Run the LibWeb test framework.

This patch migrates (1) to the main Ladybird executable. The --headless
flag enables this mode. This matches the behavior of other browsers, and
means we have one less executable to ship at distribution time.

We want to avoid creating too many AppKit / Qt facilities in headless
mode. So this involves some shuffling of application init to ensure we
don't create them until after we've parsed the command line arguments.
Namely, we avoid creating the NSApp in AppKit and QCoreApplication in
Qt. Doing so also requires that we don't create the application event
loop until we've parsed the command line as well, because the loop we
create depends on whether we're creating those UI facilities.
2025-06-10 12:04:59 -04:00
Timothy Flynn
3894d8efec headless-browser: Don't go through Application to create web views
We currently create web views through the headless Application, so that
the Application can store the views for easy iteration/management. We
would like to move HeadlessWebView into LibWebView to make headlessness
a feature of the primary Ladybird binaries. In order to do so, we need
to remove this indirection, as we won't have this test-only Application
class in Ladybird.
2025-06-10 12:04:59 -04:00
Timothy Flynn
0416961133 LibWebView: Forward declare WebView option structures 2025-06-10 12:04:59 -04:00
Timothy Flynn
fc4a7477a8 UI: Remove outdated references to LADYBIRD_SOURCES
This list is no longer set.
2025-06-10 12:04:59 -04:00
Sam Atkins
3d630e676e LibWeb/WebIDL: Bring IDL::construct() up to date with the spec
As with a few other functions in this file, this is a combination of the
current spec, and a PR that integrates shadow realms.
2025-06-10 11:57:00 +02:00
Timothy Flynn
1b7b531d61 Meta: Use "extend-select" to enable non-default python linters
This way we don't have to track the defaults.
2025-06-09 17:49:35 -04:00
Timothy Flynn
ba58c7ecf9 Meta: Remove black configuration
I left this here originally thinking that black and ruff are compatible,
so either could be used as a local formatter. But it turns that while
code formatted with ruff will be unchanged by black, the reverse is not
always true. So let's just enforce using ruff.
2025-06-09 17:49:35 -04:00
Luke Wilde
3139f6a25a LibWeb/WebGL: Use eglWaitUntilWorkScheduledANGLE instead of glFlush
With the Metal backend, glFlush flushes the command buffer, but doesn't
wait for the commands to be scheduled on the GPU.

eglWaitUntilWorkScheduledANGLE does wait, hence the name.

This fixes flickering on Rive animations rendered with WebGL.
2025-06-09 15:40:41 -06:00
Luke Wilde
426cd455bc LibWeb/WebGL: Enable robust resource initialization
By default, allocated resources are uninitialized. This setting
enables their initialization.
2025-06-09 15:40:41 -06:00
Luke Wilde
2a11670ef0 LibWeb/WebGL: Specifically request ANGLE Metal backend on macOS 2025-06-09 15:40:41 -06:00
Luke Wilde
0c2dd57d62 LibWeb/WebGL: Use WebGL version to determine ES version and extensions 2025-06-09 15:40:41 -06:00
Andrew Kaster
e3b23e6f73 Meta: Enable metal feature for angle 2025-06-09 15:40:41 -06:00
Andrew Kaster
d5a84b402b LibWeb: Support GL_TEXTURE_2D for the ANGLE target
This will be the returned egl configuration attribute for
EGL_BIND_TO_TEXTURE_TARGET_ANGLE once we transition to using the
Metal ANGLE backend directly.
2025-06-09 15:40:41 -06:00
Andrew Kaster
41dbdbc816 CMake: Add metal feature to angle port 2025-06-09 15:40:41 -06:00
Luke Wilde
d9563cf9d8 vcpkg: Update ANGLE to chromium/7085 2025-06-09 15:40:41 -06:00
Andrew Kaster
13214d1b29 CMake: Add angle overlay port 2025-06-09 15:40:41 -06:00
Timothy Flynn
c204149bbd Meta+CI: Enforce python linting with ruff
We could use flake8 for linting, but ruff is compatible with black
formatting out-of-the-box. It also seems to catch more than flake8,
such as unnecessary f-strings.
2025-06-09 11:25:14 -04:00
Timothy Flynn
18718e0876 Meta: Sort all python imports 2025-06-09 11:25:14 -04:00
Timothy Flynn
c53ee261dd Meta: Do not use mutable default arguments in ladybird.py
Caught by ruff.
2025-06-09 11:25:14 -04:00
Timothy Flynn
8bfbb944d1 Meta: Remove unnecessary enumerate invocation
Caught by ruff.
2025-06-09 11:25:14 -04:00
Timothy Flynn
58cfa2e40e LibWeb: Remove unnecessary f-string
Caught via ruff.
2025-06-09 11:25:14 -04:00
Timothy Flynn
34e178d0e7 LibGfx: Convert single quote string to double quotes
Caught via ruff. Not sure why black didn't catch this one previously.
2025-06-09 11:25:14 -04:00
Timothy Flynn
7d4b010f30 Meta: Remove unused import from ladybird.py
Caught via ruff.
2025-06-09 11:25:14 -04:00
AmusedNetwork
7c85e57c32 LibWeb: Unit test for Anchor element covered by pseudo-element 2025-06-09 16:20:43 +01:00
AmusedNetwork
836955ef57 LibWeb: Fix incorrect event handling with pseudo-elements
When a ::before or ::after pseudo-element covered an anchor element
events were not successfully sent to the underlying anchor.

This fix allows before and after pseudo-elements
to be dispatched correctly.

Fixes #5020
2025-06-09 16:20:43 +01:00
Ben Eidson
bd68a99f14 LibWeb/MimeSniff: Add MP3 without ID3 sniffing
Removes the associated FIXME in match_an_audio_or_video_type_pattern().
Sniffing process is a simplified version of the full spec, as it only
checks one frame of the mp3. To fully align with the spec, it would
also have to check a second frame by calculating frame size as
described in the spec.
2025-06-09 07:50:26 -06:00
Callum Law
a9eecf76df LibWeb: Dont compute style when CSSStyleProperties lacks owner node
Some instances of CSSStyleProperties can lack an owner node, for
instance the return value of a call to `window.getComputedStyle` where
the specified pseudo-element is invalid. In this case we should treat
the computed style as empty, as there is no node to compute the style
for.
2025-06-09 12:28:41 +01:00
Callum Law
fc46abb83f LibWeb: Make element_reference optional in create_resolved_style 2025-06-09 12:28:41 +01:00
Callum Law
610ad25555 LibWeb: Update m_inline_style when element style attribute is removed
Previously we would just throw it away and construct a new (empty) one
when required. This doesn't work as any existing references to the old
instance will contain out of date information. Now we retain and update
the existing instance instead.
2025-06-09 12:06:44 +01:00
Callum Law
f53bec3a67 LibWeb: Throw error on insertRule with disallowed @namespace rule
Resolves a FIXME in `CSSRuleList::insert_a_css_rule`. Gets us a bit
closer to passing https://wpt.live/css/cssom/at-namespace.html but that
requires more work around parsing of selectors with namespaces (namely
disallowing use of undeclared selectors), which I have added a FIXME
for.
2025-06-09 11:56:24 +01:00
Callum Law
3421cd76fa LibWeb: Store CSSStyleProperties properties in "specified order"
The spec requires us to store properties in their shorthand-expanded
form and in the "specified" order, removing duplicates prefering based
on "cascading order". We already enforced this in `set_property` but
not at creation time (e.g. in stylesheets) or in `set_css_text` (e.g.
updating style attribute).

This commit enforces the spec requirements at all the relevant points.

We no longer include logical properties in the return value of
`getComputedStyle` as they are mapped to their physical equivalents in
`StyleComputer::for_each_property_expanding_shorthands`, but resolving
that requires a relatively large rework of how we handle logical
properties, (namely moving when we map them to their physical
equivalents from parse time to style computation time).

This also exposes two false positive tests in
wpt-import/css/cssom/border-shorthand-serialization.html related to us
not yet supporting the border-image css property.
2025-06-09 10:43:50 +01:00
Callum Law
048a0c9106 LibWeb: Support nested shorthands when serializing CSS declaration 2025-06-09 10:43:50 +01:00
Callum Law
0a53aaa3b6 LibWeb: Omit initial values from background CSS property serialization 2025-06-09 10:43:50 +01:00
Callum Law
06e3f298d0 LibWeb: Update CSSStyleProperties::serialized shorthand steps with spec 2025-06-09 10:43:50 +01:00
Aliaksandr Kalenik
346c083d58 LibWeb: Don't drop messages received before MessagePort is enabled
This change implements following behavior defined in the spec:
https://html.spec.whatwg.org/multipage/web-messaging.html#examples-5
> The start() method, whether called explicitly or implicitly (by
setting onmessage), starts the flow of messages: messages posted on
message ports are initially paused, so that they don't get dropped on
the floor before the script has had a chance to set up its handlers.

Now we don't read bytes from the underlying transport socket until the
message port transitions to the enabled state. This required the
following places to explicitly enable the message port, because now,
when it actually matters, we must do so, or otherwise sent messages will
get stuck:
- `onmessage` attribute setter in DedicatedWorkerGlobalScope, because
  it implicitly sets the onmessage handler for the worker's underlying
  port.
- Stream API operations where the message port enabling steps were
  previously marked as FIXMEs.
2025-06-08 18:26:13 +02:00
Aliaksandr Kalenik
d8c86a2b09 LibWeb: Stub CacheStorage::has()
This is a step to get https://web.telegram.org/a/ login working.
2025-06-08 18:26:13 +02:00
rmg-x
f5de4c3dd6 LibWeb/ContentSecurityPolicy: Remove noisy "unknown directive" log 2025-06-08 00:46:49 +02:00
Andreas Kling
3e1ee37c6a LibWeb: Don't claim that inline layout nodes can contain abspos elements
We assume elsewhere that any abspos element's containing block must be
some kind of Layout::Box, so let's enforce that when deciding if a box
can be such a container.

This fixes a bad downcast on https://serpapi.com/
2025-06-07 16:51:07 +02:00
Sam Atkins
ea33bdc975 LibWeb: Move non-DOM-related methods from DOM::Node to TreeNode
Motivated by wanting to do `is_before()` on a Layout::Node, and thought
I might as well move as many as possible while I was at it.
2025-06-07 16:51:00 +02:00
Psychpsyo
5fad6b1938 Meta: Add doctypes to more layout tests 2025-06-07 11:09:53 +01:00
Gingeh
9ef9f8d38f LibWeb: Implement the request-close command
See: https://github.com/whatwg/html/pull/11045
2025-06-07 04:06:01 +01:00
Gingeh
fc35229dab LibWeb: Implement the ToggleEvent.source attribute
See: https://github.com/whatwg/html/pull/11186
2025-06-07 04:06:01 +01:00
Timothy Flynn
82f9b51da6 LibDevTools: Set target type for frame actors
Required for Firefox 139.
2025-06-06 17:08:41 -04:00
Jelle Raaijmakers
c2ab0dafb2 CI: Set explicit job names for matrix strategy workflows
By default, matrix jobs generate a name for themselves by concatenating
their job name and all matrix variables into a big string. Changing the
runner labels causes the job name to change, which means we need to go
into GitHub and change the required checks since those are name-based.

Give all matrix workflows an explicit, more stable name.
2025-06-06 12:03:57 +02:00
Jelle Raaijmakers
53e8ee5443 CI: Run CI and JS artifact build on self-hosted runner
The GitHub-provided runner frequently times out and is plain slow most
of the time. And since Blacksmith does not yet offer macOS runners,
let's use our self-hosted runner that is currently idle most of the time
(when it's not running JS benchmarks).
2025-06-06 12:03:57 +02:00
Jelle Raaijmakers
c5a08e946a CI: Standardize usage of runner_labels across workflows
This is now always a JSON array of runner labels, inside a string. We
need it to be a string because `workflow_call` works with inputs that
do not natively support an array type.

No functional changes.
2025-06-06 12:03:57 +02:00
R-Goc
9ec26058d1 LibTest/Tests: Build and run test-js on windows
This commit allows test-js to build and run, also in CI.

Co-authored-by: Andrew Kaster <andrew@ladybird.org>
2025-06-05 22:00:55 -06:00
R-Goc
6c8623320f LibCore: Implement chdir on Windows
This commit adds a wrapper around chdir in LibCore.

Co-authored-by: Andrew Kaster <andrew@ladybird.org>
2025-06-05 22:00:55 -06:00
R-Goc
0de3a95433 LibGC: Pass correct args to VirtualFree
VirtualFree expects zero to be passed as size for MEM_RELEASE.
2025-06-05 22:00:55 -06:00
Aliaksandr Kalenik
859991ca7b LibWeb: Skip painter allocation for a navigable created for SVG
Traversable navigable created for rendering svg element doesn't perform
any actual rendering, so there is no need to allocate a painter for it.
2025-06-06 03:56:57 +02:00
Aliaksandr Kalenik
ed1337add1 LibJS: Don't start rendering thread for a navigable created for SVG
Traversable navigable created for rendering svg element doesn't perform
any actual rendering, so there is no need to spawn a rendering thread.
2025-06-06 03:56:57 +02:00
Aliaksandr Kalenik
39fff3cf8a LibWeb: Don't early return when masking area of StackingContext is empty
An early return was occurring between the emission of
PushStackingContext and PopStackingContext, resulting in a
PushStackingContext without a corresponding PopStackingContext in the
display list, which caused broken painting.

Fixes black screen on Discord login page.
2025-06-06 00:52:19 +02:00
Aliaksandr Kalenik
7efdd1c1ec LibWeb: Stub CacheStorage interface
With this change we can again open login form https://discord.com/login
instead of failing in js because `caches.open()` is not defined.
2025-06-05 23:02:21 +02:00
stasoid
28bfe701b7 Tests/LibThreading: Port to Windows 2025-06-05 10:16:03 -06:00
stasoid
b64a4a83a1 Meta: Make pthread and mman available for all tests on Windows
by default (same code as in lagom_lib).
2025-06-05 10:16:03 -06:00
InvalidUsernameException
1d0cfdc839 LibWeb: Consider margins during fit-content sizing in BFC
`BlockFormattingContext::compute_width()` stores the left and right
margins in the layout state at the very end of the function. However,
before doing so, it calls `FormattingContext::calculate_inner_width()`
which ends up calling `FormattingContext::calculate_stretch_fit_width()`
if the current box has `width: fit-content`.

Due to this, `calculate_stretch_fit_width()` would always see the
margins from the layout state as zero and therefore not take them into
account. Subsequently, the calculated width ended up being wrong.

Saving margins on the layout state earlier, before calling
`calculate_inner_width()`, makes sure that the width is calculated
correctly.
2025-06-05 17:56:19 +02:00
InvalidUsernameException
ede84567f1 Tests/LibWeb: Regression test for auto margin on max-width container
An earlier variant of the commit following this one introduced a
regression for the behavior tested here, but did not fail any in-tree
tests. So lets add an explicit regression test to make that easier to
catch in the future.
2025-06-05 17:56:19 +02:00
Jelle Raaijmakers
777228acca CI: Only run stalebot on the Ladybird repository
Let's not annoy people who fork the repository with a job that will
never be able to run.
2025-06-05 16:51:39 +02:00
Timothy Flynn
6e8057057e headless-browser: Ensure headless-browser depends on its resource files
In a clean environment, building only headless-browser neglected to
install the resource files needed to run the browser. These were only
installed by the main Ladybird target.
2025-06-05 13:52:49 +01:00
stelar7
7f2362643c LibWeb: Use a BFC for MathML
While this is not correct, it makes MathML text render atleast
2025-06-05 12:37:52 +01:00
Sam Atkins
5a1c73d7e2 LibGfx+LibWeb: Update definitions of supported font formats and features
Based very scientifically on what's listed here:
https://harfbuzz.github.io/what-does-harfbuzz-do.html

I've moved the code into LibGfx because including a HarfBuzz header
directly from LibWeb is a little unpleasant. But the Gfx::FontTech enum
follows the CSS definitions for font features for simplicity.

TrueType collections are supported. SVG and Embedded OpenType are not,
but they're not widely supported by other browsers so that's fine.

Most of the features are completely supported by HarfBuzz, so we can
just return true. Graphite support is optional (and it appears we use a
build of HarfBuzz without it) but there's a define we can check.
Incremental Font Transfer is a whole separate thing that we definitely
don't support yet.
2025-06-05 12:10:29 +01:00
Sam Atkins
ea101c6336 LibWeb/CSS: Limit string values for font format() to the spec's set
A couple of differences from before:
- Only the fixed set of strings are allowed. Some formats can only be an
  ident (eg, svg).
- We don't allow these foo-variations values in ident form.
- The comparison is done case-insensitively. It's unclear if this is
  more or less correct, but as most things in CSS are insensitive,
  including idents, it makes sense that these would be too.
2025-06-05 12:10:29 +01:00
Sam Atkins
d611806f18 LibWeb/CSS: Parse and use tech() in @font-face { src } 2025-06-05 12:10:29 +01:00
Sam Atkins
5b42f8d707 LibWeb/HTML: Compare paragraph align="" values insensitively
This is the one place we weren't comparing align keywords insensitively.
2025-06-05 12:10:17 +01:00
Sam Atkins
6f4df83917 LibWeb: Always compare attribute names directly
Attributes are already stored with their names in lowercase, so we can
do a direct comparison instead of a case-insensitive one.
2025-06-05 12:10:17 +01:00
Sam Atkins
bc8a97589f LibWeb/SVG: Add stop-color and stop-opacity to AttributeNames 2025-06-05 12:10:17 +01:00
Aliaksandr Kalenik
3b68fd0b8e LibJS: Make array_like_size() non-virtual in IndexedPropertyStorage 2025-06-05 03:43:43 +02:00
Aliaksandr Kalenik
1d4f63e4cd LibJS: Add simple storage fast path in internal_define_own_property()
...of Array. If array has simple storage, which implies that attributes
of all indexed properties are default, and newly added property also
has default attribute, we can do a fast path and skip lots of checks
that happen in `Object::internal_define_own_property()`.
2025-06-05 03:43:43 +02:00
Aliaksandr Kalenik
20655b8ebf LibJS: Add simple storage fast path in internal_get_own_property()
...of Array. This allows us to avoid lots of unnecessary for simple
arrays checks that happen in `Object::internal_get_own_property()`.
2025-06-05 03:43:43 +02:00
Nicolas Danelon
f6f7c69023 Meta: Add missing 'args' argument to install command parser
The install command was failing with 'Namespace object has no
attribute args' error because the argument parser for the
install command was missing the 'args' parameter that allows
passing additional arguments to the build system.

This fix adds the missing argument to match the behavior of
other commands like build, run, and debug.
2025-06-04 17:34:21 -04:00
Timothy Flynn
128675770c LibJS: Implement Intl.Locale.prototype.variants
This is a normative change in the ECMA-402 spec. See:
https://github.com/tc39/ecma402/commit/e8c995a
2025-06-04 17:11:35 -04:00
Timothy Flynn
324bd0f163 LibJS: Update the Intl.Locale prototype to the latest editorial spec
This has been refactored a bit recently.
2025-06-04 17:11:35 -04:00
Timothy Flynn
208a5e6763 LibJS: Update the Intl.Locale constructor to the latest editorial spec
This has been refactored a bit recently. There are upcoming normative
changes that do not apply cleanly without this update.
2025-06-04 17:11:35 -04:00
wesinator
4c4af5492d Base: BrowserContentFilters.txt - add 51.la tracking domains
51.la is a CN language tracking site
2025-06-04 20:40:31 +01:00
Callum Law
670c247937 LibWeb: Resolve FIXME around shorthand properties in remove_property()
This exposes some false-positive sub-tests in the font-computed.html
test which are now correctly marked as failed.
2025-06-04 16:34:31 +01:00
Ruben
88da6250f9 LibWeb: Use the correct definition of separated-borders mode
We previously checked the cell's computed values for the border-collapse
property, but a cell is only in separated-borders mode if the table has
border-collapse set to separate. Curiously in some other placed where
this mode is checked we already did the correct thing.
2025-06-04 15:02:42 +01:00
Callum Law
50cce72ab9 LibWeb: Implement text-wrap CSS property
This resolves an issue introduced in 94f5a51 with the
tab-size-text-wrap test
2025-06-04 12:48:36 +01:00
Callum Law
9ba74316d2 LibWeb: Implement text-wrap-style CSS property 2025-06-04 12:48:36 +01:00
Timothy Flynn
7d99a92135 LibWeb: Absolutize CSS image URLs for computed style resolution
For getComputedStyle(), we must return an absolute URL for image style
values. We currently return the raw parsed URL.

This fixes loading the marker icons on https://usermap.serenityos.org.
2025-06-03 19:30:43 -04:00
Timothy Flynn
3ae2220534 LibWeb: Add missing FlyString include to CSS/URL.h
clangd is complaining about this.
2025-06-03 19:30:43 -04:00
Andreas Kling
6dba720370 LibWeb: Invalidate layout tree at nearest non-anonymous ancestor
When marking a part of the layout tree for rebuild, if the subtree root
that we're marking has an anonymous parent, we now mark from the nearest
non-anonymous ancestor instead.

This ensures that subtrees inside anonymous wrappers don't just get
duplicated (i.e recreated but inserted instead of replaced).
2025-06-04 00:43:23 +02:00
Aliaksandr Kalenik
93cd17db74 LibJS: Add fast path internal_has_property() for Array
If array has packed index property storage without holes, we could check
if indexed property is present simple by checking if it's less than
array's length.

Makes the following program go 1.1x faster:
```js
function f() {
    let array = [];
    for (let i = 0; i < 3_000; i++) {
        array.push(i);
    }

    for (let i = 0; i < 10_000; i++) {
        array.map(x => x * 2);
    }
}

f();
```
2025-06-03 23:18:41 +02:00
Aliaksandr Kalenik
22e0b732db LibJS: Add missing update for holes count in IndexedPropertyStorage
This one is required to cover the case when new empty elements are
introduced by assigning to element with index > length, like:
```js
var x = [];
x[0] = 1;
x[2] = 2;
```
2025-06-03 23:18:41 +02:00
aplefull
3781c132aa LibWeb: Fix grid item placement when only grid-column-end is specified 2025-06-03 22:22:24 +02:00
Rocco Corsi
4b3dccd0f2 LibWeb: Remove Unicode Cyrillic e char (04+35) in variable name
Static analysis tool cppcheck reports that
LibWeb/Internals/Internals.cpp:65 has a variable named
hit_tеsting_result with a Cyrillic e in the 'testing' portion of the
name, instead of the more common ASCII e. No other use of Unicode
characters for identifiers in the Ladybird code base noted by cppcheck,
so assuming that this is unintended use.
2025-06-03 21:22:27 +02:00
Aliaksandr Kalenik
1274f4e2f7 LibJS: Optimize Function.prototype.apply()
...by avoiding `CreateListFromArrayLike` in cases when we could directly
use elements of underlying object's indexed properties storage.

Makes this program go 2.1x faster:
```js
function target(a, b, c) {
    return a + b + c;
}

const args = [1, 2, 3];
let result = 0;

(function() {
    for (let i = 0; i < 10_000_000; i++) {
        result += target.apply(null, args);
    }
})();
```
2025-06-03 17:16:01 +02:00
Aliaksandr Kalenik
3f7c4dd5f6 LibJS: Maintain number of empty elements in SimpleIndexedPropertyStorage
This will be used in upcoming changes to do a fast path when array does
not have any holes.
2025-06-03 17:16:01 +02:00
Psychpsyo
4c54a28c45 Meta: Add doctypes to a few more layout tests 2025-06-03 11:03:19 +01:00
Manuel Zahariev
f972342c27 LibWeb/CSS: Unit tests for changes to counter definitions 2025-06-03 03:51:42 +02:00
Manuel Zahariev
99c6eb0c35 LibWeb/CSS: Invalidate layout tree for changes to counter definitions
A change to a counter "definition" propagates to all subsequent
instances of this counter: descendents, siblings and their descendents
(the "next tree slice"). Rebuilding the layout tree (from the parent
node) covers at least the "next_tree_slice".
2025-06-03 03:51:42 +02:00
Timothy Flynn
8145572180 LibJS+LibUnicode: Support ambiguous time zone transitions
For example, time zone transitions can result in repeated or skipped
wall times. Temporal wants us to handle these transitions.
2025-06-03 09:09:21 +12:00
Timothy Flynn
c8b4dc4847 LibJS: Require strict matching with a precise ZonedDateTime offset
This is a normative change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/1117eaf
2025-06-03 09:09:21 +12:00
Timothy Flynn
f091047159 LibJS+LibUnicode: Implement retrieval of collator keyword values
Completely missed this when implementing Intl.Collator!
2025-06-03 09:03:33 +12:00
Timothy Flynn
422d72e85d LibUnicode: Provide string length to ICU string enumeration callbacks
Some callers need the raw nul-terminated c-string in this callback, to
pass to some other ICU method. But other callers will want a StringView.
We know the length already in `icu_string_enumeration_to_list`, so let's
just pass it along to avoid `strlen`.
2025-06-03 09:03:33 +12:00
Timothy Flynn
21cff645a2 LibUnicode: Use ICU to convert Unicode keywords to their BCP 47 value
We were manually doing this for the calendar keyword, and would need to
do so for the collation keyword as well. I wasn't aware of this API
originally, so let's start using it.
2025-06-03 09:03:33 +12:00
aplefull
486602e796 LibRegex: Fix handling of + quantifier with zero-width matches
Small change that allows quantifiers using Fork* forms (e.g., +) to
succeed after one match, even if that match has zero width.
2025-06-02 15:52:26 +02:00
Timothy Flynn
2380fb0ca1 Meta: Default chosen compilers to the CC and CXX environment variables
This regressed when porting find_compiler.sh to python.
2025-06-02 08:04:07 -04:00
Saksham Mittal
c52c05555b LibWeb: Don't place cursor on certain <input> elements
For example, button inputs shouldn't have a cursor
displayed in their text since they're not editable,
and are not meant to be editable.

Fixes #4140

Co-authored-by: Sam Atkins <sam@ladybird.org>
2025-06-02 11:38:38 +01:00
Tim Ledbetter
17f14a277b LibWeb: Don't crash when interpolating single-value repeatable lists
Previously, when interpolating a repeatable list from a list with
multiple values to a single value, we would crash.
2025-06-02 11:33:01 +01:00
Timothy Flynn
8ded0c65dc LibJS+LibUnicode: Change time zones in a way that works on Windows
On Windows, ICU does not look at the TZ environment variable at all. So
to support changing time zones in test-js, let's set ICU's default time
zone directly.

Note that we no longer deal with "null" time zone strings. We just cache
whatever ICU thinks is the current time zone before attempting to change
it, for which we never have a null result.

Co-authored-by: Andrew Kaster <andrew@ladybird.org>
2025-06-01 18:48:58 -04:00
stasoid
8d33a97630 Tests/LibURL: Port to Windows 2025-06-01 16:42:19 -06:00
Tim Ledbetter
e2d0d8e2b9 LibWeb/CSS: Implement the scrollbar-color property
This allows the user to set the scrollbar thumb and track colors.
2025-06-02 00:17:51 +02:00
Aliaksandr Kalenik
285bc005cb LibJS: Do more comprehensive check if next() fast path is possible
Before this change each built-in iterator object has a boolean
`m_next_method_was_redefined`. If user code later changed the iterator’s
prototype (e.g. `Object.setPrototypeOf()`), we still believed the
built-in fast-path was safe and skipped the user supplied override,
producing wrong results.

With this change
`BuiltinIterator::as_builtin_iterator_if_next_is_not_redefined()` looks
up the current `next` property and verifies that it is still the
built-in native function.
2025-06-02 00:15:36 +02:00
Lucien Fiorini
0fcb574041 LibGfx+LibWeb: Turn Gfx::Filter into a SkImageFilter wrapper 2025-06-01 23:22:10 +02:00
InvalidUsernameException
417f4edc46 Tests/LibWeb: Print properties without indexes
The test CSSStyleDeclaration-has-indexed-property-getter is a frequent
source of merge conflicts between PRs that are adding to or otherwise
modifying the list of supported CSS properties.

This is primarily because the test prints out a numeric index of each
property along with the property. As far as I can tell the indexes are
inconsequential for what the test is trying to verify. So lets modify
the printout to only contain the properties without indexes.
2025-06-01 19:09:10 +01:00
Julien Le Bras
3ba6d129df LibJS: Cache string constants in Generator::add_constant
This mirrors the existing caching logic for int32 constants.
Avoids duplication of string constants in m_constants which could
result in stack overflows for large scripts with a lot of similar
strings.
2025-06-01 18:25:59 +02:00
Richard Gibson
9bf836e6c4 js: Don't escape printed strings with --disable-string-quotes 2025-06-01 09:51:09 -04:00
6223 changed files with 295054 additions and 72962 deletions

View File

@ -32,6 +32,7 @@ Checks: >
-bugprone-macro-parentheses,
-bugprone-reserved-identifier,-cert-dcl37-c,-cert-dcl51-cpp,
-cert-dcl21-cpp,
-misc-const-correctness,
-misc-include-cleaner,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,

View File

@ -4,7 +4,7 @@
// Features to add to the dev container. More info: https://containers.dev/implementors/features.
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {},
"ghcr.io/devcontainers-extra/features/pre-commit:2": {},
"./features/ladybird": {
"llvm_version": 20
},

View File

@ -5,6 +5,6 @@ set -e
dnf install -y git gh
# Ladybird dev dependencies
dnf install -y autoconf-archive automake ccache cmake curl google-noto-sans-mono-fonts liberation-sans-fonts libglvnd-devel \
nasm ninja-build patchelf perl-FindBin perl-IPC-Cmd perl-lib qt6-qtbase-devel qt6-qtmultimedia-devel qt6-qttools-devel \
qt6-qtwayland-devel tar unzip zip zlib-ng-compat-static
dnf install -y autoconf-archive automake ccache cmake curl google-noto-sans-mono-fonts liberation-sans-fonts \
libglvnd-devel libtool nasm ninja-build patchelf perl-FindBin perl-IPC-Cmd perl-lib qt6-qtbase-devel \
qt6-qtmultimedia-devel qt6-qttools-devel qt6-qtwayland-devel tar unzip zip zlib-ng-compat-static

View File

@ -24,7 +24,7 @@ install_llvm_key() {
### Install packages
apt update -y
apt install -y lsb-release git python3 autoconf autoconf-archive automake build-essential cmake libgl1-mesa-dev nasm ninja-build pkg-config qt6-base-dev qt6-tools-dev-tools qt6-multimedia-dev qt6-wayland ccache fonts-liberation2 zip unzip curl tar
apt install -y lsb-release git python3 autoconf autoconf-archive automake build-essential cmake libdrm-dev libgl1-mesa-dev libtool nasm ninja-build pkg-config qt6-base-dev qt6-tools-dev-tools qt6-multimedia-dev qt6-wayland ccache fonts-liberation2 zip unzip curl tar
### Ensure new enough host compiler is available
VERSION="0.0.0"

View File

@ -7,6 +7,11 @@ set -e
case "$(uname -m)" in
x86_64|x64)
export VCPKG_DEFAULT_TRIPLET=x64-linux-dynamic
;;
aarch64|arm64)
export VCPKG_DEFAULT_TRIPLET=arm64-linux-dynamic
export VCPKG_FORCE_SYSTEM_BINARIES=1
;;
*)
export VCPKG_FORCE_SYSTEM_BINARIES=1
@ -28,6 +33,7 @@ python3 ./Toolchain/BuildVcpkg.py
# Set the binary cache directory to the one we intend to use at container runtime
export VCPKG_ROOT="${PWD}/Build/vcpkg"
export VCPKG_BINARY_SOURCES="clear;files,${CACHE_DIR},readwrite"
export X_VCPKG_ASSET_SOURCES="clear;x-azurl,https://vcpkg-cache.app.ladybird.org/ladybird/source-assets/,,read"
# Check options to see which versions we should build
if [ "${RELEASE_TRIPLET}" = "true" ]; then

1
.github/FUNDING.yml vendored
View File

@ -1,3 +1,2 @@
custom: https://donorbox.org/ladybird
open_collective: ladybird
polar: LadybirdBrowser

View File

@ -3,8 +3,8 @@ description: 'Restores caches of downloaded files and build artifacts.'
author: 'Andrew Kaster <akaster@serenityos.org>'
inputs:
runner_label:
description: 'Name of runner instance'
runner_labels:
description: 'Runner selection labels'
required: true
os:
description: 'Operating System to restore caches for'
@ -42,10 +42,10 @@ inputs:
outputs:
ccache_primary_key:
description: 'Primary ccache key'
value: ${{ steps.cache-outputs.outputs.ccache_primary_key }}
value: ${{ steps.ccache.outputs.cache-primary-key }}
vcpkg_cache_primary_key:
description: 'Primary vcpkg binary cache key'
value: ${{ steps.cache-outputs.outputs.vcpkg_cache_primary_key }}
value: ${{ steps.vcpkg.outputs.cache-primary-key }}
runs:
using: "composite"
@ -56,72 +56,53 @@ runs:
run: |
echo "timestamp=$(date -u "+%Y%m%d%H%M_%S")" >> "$GITHUB_OUTPUT"
- name: 'Compiler Cache (blacksmith)'
uses: useblacksmith/cache/restore@v5
id: 'ccache-blacksmith'
if: ${{ inputs.ccache_path != '' && startsWith(inputs.runner_label, 'blacksmith') }}
with:
path: ${{ inputs.ccache_path }}
key: '"ccache" | "${{ inputs.os }}" | "${{ inputs.arch }}" | "${{ inputs.toolchain }}" | "${{ inputs.cache_key_extra }}" | "${{ inputs.ccache_version }}" | ${{ steps.date-stamp.outputs.timestamp }}'
restore-keys: |
ccache | ${{ inputs.os }} | ${{ inputs.arch }} | ${{ inputs.toolchain }} | ${{ inputs.cache_key_extra }} | ${{ inputs.ccache_version }}
"ccache" | "${{ inputs.os }}" | "${{ inputs.arch }}" | "${{ inputs.toolchain }}" | "${{ inputs.cache_key_extra }}" | "${{ inputs.ccache_version }}"
- name: 'Compiler Cache (GitHub runner)'
- name: 'Compiler Cache'
uses: actions/cache/restore@v4
id: 'ccache-gh'
if: ${{ inputs.ccache_path != '' && !startsWith(inputs.runner_label, 'blacksmith') }}
id: 'ccache'
if: ${{ inputs.ccache_path != '' }}
with:
path: ${{ inputs.ccache_path }}
key: '"ccache" | "${{ inputs.os }}" | "${{ inputs.arch }}" | "${{ inputs.toolchain }}" | "${{ inputs.cache_key_extra }}" | "${{ inputs.ccache_version }}" | ${{ steps.date-stamp.outputs.timestamp }}'
restore-keys: |
ccache | ${{ inputs.os }} | ${{ inputs.arch }} | ${{ inputs.toolchain }} | ${{ inputs.cache_key_extra }} | ${{ inputs.ccache_version }}
"ccache" | "${{ inputs.os }}" | "${{ inputs.arch }}" | "${{ inputs.toolchain }}" | "${{ inputs.cache_key_extra }}" | "${{ inputs.ccache_version }}"
- name: 'Configure Compiler Cache'
if: ${{ inputs.ccache_path != '' }}
if: ${{ inputs.os != 'Windows' && inputs.ccache_path != '' }}
shell: bash
env:
CCACHE_DIR: ${{ inputs.ccache_path }}
run: |
CCACHE_DIR=${{ inputs.ccache_path }} ccache -M 0
ccache -M 0
# Reset all ccache modification dates to a known epoch. This provides a baseline that we can prune against.
find ${{ inputs.ccache_path }} | tac | xargs touch -a -m -d "2018-10-10T09:53:07Z"
CCACHE_DIR=${{ inputs.ccache_path }} ccache -s
CCACHE_DIR=${{ inputs.ccache_path }} ccache -z
ccache -s
ccache -z
- name: 'Restore vcpkg cache (blacksmith)'
uses: useblacksmith/cache/restore@v5
if: ${{ inputs.vcpkg_cache_path != '' && startsWith(inputs.runner_label, 'blacksmith') }}
id: 'vcpkg-blacksmith'
with:
path: ${{ inputs.vcpkg_cache_path }}
key: '"vcpkg" | "${{ inputs.os }}" | "${{ inputs.arch }}" | "${{ inputs.toolchain }}" | "${{ inputs.cache_key_extra }}" | "${{ inputs.ccache_version }}" | ${{ steps.date-stamp.outputs.timestamp }}'
restore-keys: |
vcpkg | ${{ inputs.os }} | ${{ inputs.arch }} | ${{ inputs.toolchain }} | ${{ inputs.cache_key_extra }} | ${{ inputs.ccache_version }}
"vcpkg" | "${{ inputs.os }}" | "${{ inputs.arch }}" | "${{ inputs.toolchain }}" | "${{ inputs.cache_key_extra }}" | "${{ inputs.ccache_version }}"
- name: 'Restore vcpkg cache (GitHub runner)'
uses: actions/cache/restore@v4
if: ${{ inputs.ccache_path != '' && !startsWith(inputs.runner_label, 'blacksmith') }}
id: 'vcpkg-gh'
with:
path: ${{ inputs.vcpkg_cache_path }}
key: '"vcpkg" | "${{ inputs.os }}" | "${{ inputs.arch }}" | "${{ inputs.toolchain }}" | "${{ inputs.cache_key_extra }}" | "${{ inputs.ccache_version }}" | ${{ steps.date-stamp.outputs.timestamp }}'
restore-keys: |
vcpkg | ${{ inputs.os }} | ${{ inputs.arch }} | ${{ inputs.toolchain }} | ${{ inputs.cache_key_extra }} | ${{ inputs.ccache_version }}
"vcpkg" | "${{ inputs.os }}" | "${{ inputs.arch }}" | "${{ inputs.toolchain }}" | "${{ inputs.cache_key_extra }}" | "${{ inputs.ccache_version }}"
# FIXME: When all runners are using the useblacksmith/cache action and this step is removed, we should also be able
# to remove the quoteless cache restore keys in the cache actions above.
- name: 'Cache Outputs'
id: 'cache-outputs'
shell: bash
- name: 'Configure Compiler Cache (Windows)'
if: ${{ inputs.os == 'Windows' && inputs.ccache_path != '' }}
shell: pwsh
env:
CCACHE_DIR: ${{ inputs.ccache_path }}
run: |
if ${{ startsWith(inputs.runner_label, 'blacksmith') }} ; then
echo "ccache_primary_key=${{ steps.ccache-blacksmith.outputs.cache-primary-key }}" >> "$GITHUB_OUTPUT"
echo "vcpkg_cache_primary_key=${{ steps.vcpkg-blacksmith.outputs.cache-primary-key }}" >> "$GITHUB_OUTPUT"
else
echo "ccache_primary_key=${{ steps.ccache-gh.outputs.cache-primary-key }}" >> "$GITHUB_OUTPUT"
echo "vcpkg_cache_primary_key=${{ steps.vcpkg-gh.outputs.cache-primary-key }}" >> "$GITHUB_OUTPUT"
fi
ccache -M 0
# Reset all ccache modification dates to a known epoch. This provides a baseline that we can prune against.
Get-ChildItem -Path "${{ inputs.ccache_path }}" -Recurse | Sort-Object FullName -Descending | ForEach-Object {
$_.LastWriteTime = [DateTime]::Parse("2018-10-10T09:53:07Z")
$_.LastAccessTime = [DateTime]::Parse("2018-10-10T09:53:07Z")
}
ccache -s
ccache -z
- name: 'Restore vcpkg cache'
uses: actions/cache/restore@v4
if: ${{ inputs.vcpkg_cache_path != '' }}
id: 'vcpkg'
with:
path: ${{ inputs.vcpkg_cache_path }}
key: '"vcpkg" | "${{ inputs.os }}" | "${{ inputs.arch }}" | "${{ inputs.toolchain }}" | "${{ inputs.cache_key_extra }}" | "${{ inputs.ccache_version }}" | ${{ steps.date-stamp.outputs.timestamp }}'
restore-keys: |
"vcpkg" | "${{ inputs.os }}" | "${{ inputs.arch }}" | "${{ inputs.toolchain }}" | "${{ inputs.cache_key_extra }}" | "${{ inputs.ccache_version }}"

View File

@ -3,8 +3,8 @@ description: 'Saves caches of build artifacts.'
author: 'Andrew Kaster <akaster@serenityos.org>'
inputs:
runner_label:
description: 'Name of runner instance'
runner_labels:
description: 'Runner selection labels'
required: true
arch:
description: 'Target Architecture to restore caches for'
@ -28,44 +28,34 @@ inputs:
default: ''
runs:
using: "composite"
using: 'composite'
steps:
- name: 'Prune obsolete ccache files'
shell: bash
env:
CCACHE_DIR: ${{ inputs.ccache_path }}
if: ${{ inputs.ccache_path != '' }}
run: |
CCACHE_DIR=${{ inputs.ccache_path }} ccache --evict-older-than=1d
ccache --evict-older-than=1d
- name: 'Compiler Cache (blacksmith)'
uses: useblacksmith/cache/save@v5
if: ${{ inputs.ccache_path != '' && startsWith(inputs.runner_label, 'blacksmith') }}
with:
path: ${{ inputs.ccache_path }}
key: ${{ inputs.ccache_primary_key }}
- name: 'Compiler Cache (GitHub runner)'
- name: 'Compiler Cache'
uses: actions/cache/save@v4
if: ${{ inputs.ccache_path != '' && !startsWith(inputs.runner_label, 'blacksmith') }}
if: ${{ inputs.ccache_path != '' }}
with:
path: ${{ inputs.ccache_path }}
key: ${{ inputs.ccache_primary_key }}
- name: 'Cache Stats'
shell: bash
env:
CCACHE_DIR: ${{ inputs.ccache_path }}
if: ${{ inputs.ccache_path != '' }}
run: |
CCACHE_DIR=${{ inputs.ccache_path }} ccache -s
ccache -s
- name: 'vcpkg binary cache (blacksmith)'
uses: useblacksmith/cache/save@v5
if: ${{ inputs.vcpkg_cache_path != '' && startsWith(inputs.runner_label, 'blacksmith') }}
with:
path: ${{ inputs.vcpkg_cache_path }}
key: ${{ inputs.vcpkg_cache_primary_key }}
- name: 'vcpkg binary cache (GitHub runner)'
- name: 'vcpkg binary cache'
uses: actions/cache/save@v4
if: ${{ inputs.vcpkg_cache_path != '' && !startsWith(inputs.runner_label, 'blacksmith') }}
if: ${{ inputs.vcpkg_cache_path != '' }}
with:
path: ${{ inputs.vcpkg_cache_path }}
key: ${{ inputs.vcpkg_cache_primary_key }}

View File

@ -40,7 +40,7 @@ runs:
sudo apt-get update -y
sudo apt-get install -y autoconf autoconf-archive automake build-essential ccache cmake curl fonts-liberation2 \
gcc-14 g++-14 libcurl4-openssl-dev libegl1-mesa-dev libgl1-mesa-dev libpulse-dev libssl-dev \
gcc-14 g++-14 libcurl4-openssl-dev libdrm-dev libegl1-mesa-dev libgl1-mesa-dev libpulse-dev libssl-dev \
libstdc++-14-dev lld-20 llvm-20 nasm ninja-build qt6-base-dev qt6-tools-dev-tools tar unzip zip
if ${{ inputs.toolchain == 'Clang' }} ; then
@ -64,7 +64,7 @@ runs:
if: ${{ inputs.os == 'macOS' || inputs.os == 'Android' }}
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 16.3
xcode-version: 16.4
- name: 'Install Swift toolchain'
if: ${{ inputs.toolchain == 'Swift' }}
@ -107,7 +107,8 @@ runs:
echo "swiftly version: $(swiftly --version)" >&2
swiftly install --use main-snapshot-2025-05-26
# installs version listed in .swift-version
swiftly install
swiftly list
- name: 'Install Dependencies'
@ -116,7 +117,7 @@ runs:
run: |
set -e
brew update
brew install autoconf autoconf-archive automake bash ccache coreutils llvm@20 nasm ninja pkg-config qt unzip wabt
brew install autoconf autoconf-archive automake bash ccache coreutils libtool llvm@20 nasm ninja pkg-config qt unzip wabt
- name: 'Set required environment variables'
if: ${{ inputs.os == 'Linux' && inputs.arch == 'arm64' }}

40
.github/workflows/ci-flatpak.yml vendored Normal file
View File

@ -0,0 +1,40 @@
name: CI (Flatpak)
on:
pull_request:
types:
- opened
- synchronize
- reopened
- labeled
- unlabeled
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# Do not cancel in-progress runs if a labeling action took place (other than 'flatpak'). Otherwise, adding irrelevant
# labels causes existing runs to be canceled and a new (identical) run to be started.
cancel-in-progress: ${{ (github.event.action != 'labeled' && github.event.action != 'unlabeled') || github.event.label.name == 'flatpak' }}
jobs:
CI-Flatpak:
# Only run this job if the PR has the 'flatpak' label.
if: |
github.repository == 'LadybirdBrowser/ladybird'
&& contains(github.event.pull_request.labels.*.name, 'flatpak')
name: Flatpak ${{ matrix.arch }}
strategy:
fail-fast: false
matrix:
arch: ['x86_64']
runner_labels: ['["blacksmith-8vcpu-ubuntu-2404"]']
include:
- arch: 'aarch64'
runner_labels: '["blacksmith-8vcpu-ubuntu-2404-arm"]'
secrets: inherit
uses: ./.github/workflows/flatpak-template.yml
with:
arch: ${{ matrix.arch }}
runner_labels: ${{ matrix.runner_labels }}

33
.github/workflows/ci-windows.yml vendored Normal file
View File

@ -0,0 +1,33 @@
name: CI (Windows)
on:
pull_request:
types:
- opened
- synchronize
- reopened
- labeled
- unlabeled
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# Do not cancel in-progress runs if a labeling action took place (other than 'windows'). Otherwise, adding irrelevant
# labels causes existing runs to be canceled and a new (identical) run to be started.
cancel-in-progress: ${{ (github.event.action != 'labeled' && github.event.action != 'unlabeled') || github.event.label.name == 'windows' }}
jobs:
CI:
# Only run this job if the PR has the 'windows' label.
if: |
github.repository == 'LadybirdBrowser/ladybird'
&& contains(github.event.pull_request.labels.*.name, 'windows')
name: 'Windows, x86_64, Windows_Sanitizer_CI, ClangCL'
secrets: inherit
uses: ./.github/workflows/lagom-template.yml
with:
toolchain: 'ClangCL'
os_name: 'Windows'
runner_labels: '["windows-2025"]'
arch: 'x86_64'
build_preset: 'Windows_Sanitizer_CI'
clang_plugins: false

View File

@ -10,44 +10,46 @@ jobs:
# CI matrix - runs the job in lagom-template.yml with different configurations.
Lagom:
if: github.repository == 'LadybirdBrowser/ladybird'
name: ${{ matrix.os_name }}, ${{ matrix.arch }}, ${{ matrix.build_preset }}, ${{ matrix.toolchain }}
strategy:
fail-fast: false
matrix:
os_name: ['Linux']
arch: ['x86_64']
build_preset: ['Sanitizer_CI']
build_preset: ['Sanitizer']
toolchain: ['GNU']
clang_plugins: [false]
runner: ['blacksmith-16vcpu-ubuntu-2404']
runner_labels: ['["blacksmith-16vcpu-ubuntu-2404"]']
include:
- os_name: 'Linux'
arch: 'x86_64'
build_preset: 'Sanitizer_CI'
build_preset: 'Sanitizer'
toolchain: 'Clang'
clang_plugins: true
runner: 'blacksmith-16vcpu-ubuntu-2404'
runner_labels: '["blacksmith-16vcpu-ubuntu-2404"]'
- os_name: 'macOS'
arch: 'arm64'
build_preset: 'Sanitizer_CI'
build_preset: 'Sanitizer'
toolchain: 'Clang'
clang_plugins: false
runner: 'macos-15'
runner_labels: '["macos-15", "self-hosted"]'
- os_name: 'Linux'
arch: 'x86_64'
build_preset: 'Fuzzers_CI'
build_preset: 'Fuzzers'
toolchain: 'Clang'
clang_plugins: false
runner: 'blacksmith-16vcpu-ubuntu-2404'
runner_labels: '["blacksmith-16vcpu-ubuntu-2404"]'
secrets: inherit
uses: ./.github/workflows/lagom-template.yml
with:
toolchain: ${{ matrix.toolchain }}
os_name: ${{ matrix.os_name }}
runner: ${{ matrix.runner }}
runner_labels: ${{ matrix.runner_labels }}
arch: ${{ matrix.arch }}
build_preset: ${{ matrix.build_preset }}
clang_plugins: ${{ matrix.clang_plugins }}

View File

@ -23,7 +23,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Login to GitHub Container Registry
uses: docker/login-action@v3

30
.github/workflows/flatpak-template.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: Flatpak Build
on:
workflow_call:
inputs:
arch:
required: true
type: string
runner_labels:
required: true
type: string
jobs:
flatpak:
runs-on: ${{ fromJSON(inputs.runner_labels) }}
container:
image: ghcr.io/flathub-infra/flatpak-github-actions:kde-6.9
options: --privileged
steps:
- uses: actions/checkout@v5
- uses: flatpak/flatpak-github-actions/flatpak-builder@v6
with:
bundle: Ladybird.flatpak
manifest-path: Meta/CMake/flatpak/org.ladybird.Ladybird.json
cache: 'true'
arch: ${{ inputs.arch }}
# Note: default cache key is 'flatpak-builder-${arch}-${sha256(manifestPath)}'
upload-artifact: 'true'

View File

@ -3,6 +3,12 @@ name: Package the js repl as a binary artifact
on:
push:
branches: [master]
workflow_dispatch:
inputs:
reference_to_build:
description: 'Branch, tag or commit hash to build'
required: true
type: string
env:
LADYBIRD_SOURCE_DIR: ${{ github.workspace }}
@ -11,25 +17,37 @@ env:
jobs:
build-and-package:
runs-on: ${{ matrix.runner }}
runs-on: ${{ fromJSON(matrix.runner_labels) }}
if: github.repository == 'LadybirdBrowser/ladybird'
name: ${{ matrix.os_name }}, ${{ matrix.arch }}
strategy:
fail-fast: false
matrix:
os_name: ['Linux']
arch: ['x86_64']
toolchain: ['Clang']
package_type: ['Linux-x86_64']
runner: ['blacksmith-8vcpu-ubuntu-2404']
runner_labels: ['["blacksmith-8vcpu-ubuntu-2404"]']
include:
- os_name: 'macOS'
arch: 'arm64'
toolchain: 'Clang'
package_type: 'macOS-arm64'
runner: 'macos-15'
runner_labels: '["macos-15", "self-hosted"]'
- os_name: 'Linux'
arch: 'arm64'
toolchain: 'Clang'
package_type: 'Linux-aarch64'
runner_labels: '["blacksmith-8vcpu-ubuntu-2404-arm"]'
steps:
- name: Checkout LadybirdBrowser/ladybird
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
ref: ${{ inputs.reference_to_build }}
- name: "Set up environment"
uses: ./.github/actions/setup
@ -41,19 +59,20 @@ jobs:
uses: ./.github/actions/cache-restore
id: 'cache-restore'
with:
runner_label: ${{ matrix.runner }}
runner_labels: ${{ matrix.runner_labels }}
os: ${{ matrix.os_name }}
arch: ${{ matrix.arch }}
cache_key_extra: 'LibJS Artifacts'
cache_key_extra: 'LibJS and LibWasm Artifacts'
ccache_path: ${{ env.CCACHE_DIR }}
download_cache_path: ${{ github.workspace }}/Build/caches
vcpkg_cache_path: ${{ github.workspace }}/Build/caches/vcpkg-binary-cache
- name: Create build directory Ubuntu
run: |
cmake --preset Distribution_CI \
cmake --preset Distribution \
-DCMAKE_C_COMPILER=clang-20 \
-DCMAKE_CXX_COMPILER=clang++-20 \
-DENABLE_CI_BASELINE_CPU=ON \
-DENABLE_GUI_TARGETS=OFF
if: ${{ matrix.os_name == 'Linux' }}
@ -63,30 +82,68 @@ jobs:
# See: https://github.com/microsoft/vcpkg/discussions/19454
- name: Create build directory macOS
run: |
cmake --preset Distribution_CI \
cmake --preset Distribution \
-DCMAKE_OSX_DEPLOYMENT_TARGET="11.0" \
-DENABLE_GUI_TARGETS=OFF
if: ${{ matrix.os_name == 'macOS' }}
- name: Build and package js
- name: Build js
working-directory: Build/distribution
run: |
ninja js
- name: Build wasm
working-directory: Build/distribution
run: |
ninja wasm
- name: Package js and wasm
working-directory: Build/distribution
run: |
cpack
- name: Save Caches
uses: ./.github/actions/cache-save
with:
runner_label: ${{ matrix.runner }}
runner_labels: ${{ matrix.runner_labels }}
arch: 'Lagom'
ccache_path: ${{ env.CCACHE_DIR }}
ccache_primary_key: ${{ steps.cache-restore.outputs.ccache_primary_key }}
vcpkg_cache_path: ${{ github.workspace }}/Build/caches/vcpkg-binary-cache
vcpkg_cache_primary_key: ${{ steps.cache-restore.outputs.vcpkg_cache_primary_key }}
- name: Sanity-check the js repl
shell: bash
run: |
set -e
tar -xvzf Build/distribution/ladybird-js-${{ matrix.package_type }}.tar.gz
./bin/js -c "console.log('Hello, World\!');" > js-repl-out.txt
if ! grep -q "\"Hello, World\!\"" js-repl-out.txt; then
echo "Sanity check failed: \"Hello, World\!\" not found in output."
exit 1
fi
- name: Sanity-check the wasm repl
shell: bash
run: |
set -e
tar -xvzf Build/distribution/ladybird-wasm-${{ matrix.package_type }}.tar.gz
./bin/wasm -e run_sanity_check -w ${{ github.workspace }}/Libraries/LibWasm/Tests/CI/ci-sanity-check.wasm > wasm-repl-out.txt
if ! grep -q "Hello, World\!" wasm-repl-out.txt; then
echo "Sanity check failed: Hello, World\! not found in output."
exit 1
fi
- name: Upload js package
uses: actions/upload-artifact@v4
with:
name: ladybird-js-${{ matrix.package_type }}
path: Build/distribution/ladybird-js*.tar.gz
path: Build/distribution/ladybird-js-*.tar.gz
retention-days: 7
- name: Upload wasm package
uses: actions/upload-artifact@v4
with:
name: ladybird-wasm-${{ matrix.package_type }}
path: Build/distribution/ladybird-wasm-*.tar.gz
retention-days: 7

View File

@ -8,21 +8,23 @@ on:
jobs:
js-benchmarks:
runs-on: ['js-benchmarks', 'self-hosted', '${{ matrix.runner }}']
runs-on: ${{ fromJSON(matrix.runner_labels) }}
if: ${{ github.repository == 'LadybirdBrowser/ladybird' && github.event.workflow_run.conclusion == 'success' }}
name: ${{ matrix.os_name }}, ${{ matrix.arch }}
strategy:
fail-fast: false
matrix:
os_name: ['Linux']
runner: ['ubuntu-24.04-internal']
arch: ['x86_64']
package_type: ['Linux-x86_64']
runner_labels: ['["ubuntu-24.04-internal", "js-benchmarks", "self-hosted"]']
include:
- os_name: 'macOS'
runner: 'macos-15'
arch: 'arm64'
package_type: 'macOS-arm64'
runner_labels: '["macos-15", "js-benchmarks", "self-hosted"]'
permissions:
actions: read
@ -30,10 +32,18 @@ jobs:
steps:
- name: 'Checkout LadybirdBrowser/js-benchmarks'
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: LadybirdBrowser/js-benchmarks
path: js-benchmarks
ref: master
- name: 'Determine js-benchmarks commit hash'
id: js-benchmarks-commit
shell: bash
run: |
cd js-benchmarks
echo "sha=$(git rev-parse HEAD)" >> "${GITHUB_OUTPUT}"
- name: 'Install dependencies'
if: ${{ matrix.os_name == 'Linux' }}
@ -43,8 +53,8 @@ jobs:
sudo apt-get install -y python3-venv
- name: 'Download JS repl artifact'
id: download-artifact
uses: dawidd6/action-download-artifact@v9
id: download-js-artifact
uses: dawidd6/action-download-artifact@v11
with:
run_id: ${{ github.event.workflow_run.id }}
name: ladybird-js-${{ matrix.package_type }}
@ -56,14 +66,46 @@ jobs:
cd js-repl
tar -xvzf ladybird-js-${{ matrix.os_name }}-${{ matrix.arch }}.tar.gz
- name: 'Run the JS benchmarks'
- name: 'Determine JS repl build commit hash'
id: js-build-commit
shell: bash
run: |
commit_hash=$(cat js-repl/COMMIT)
echo "sha=${commit_hash}" >> "${GITHUB_OUTPUT}"
- name: 'Download Wasm repl artifact'
id: download-wasm-artifact
uses: dawidd6/action-download-artifact@v11
with:
run_id: ${{ github.event.workflow_run.id }}
name: ladybird-wasm-${{ matrix.package_type }}
path: wasm-repl
- name: 'Extract Wasm repl'
shell: bash
run: |
cd wasm-repl
tar -xvzf ladybird-wasm-${{ matrix.os_name }}-${{ matrix.arch }}.tar.gz
- name: 'Run the benchmarks'
shell: bash
run: |
cd js-benchmarks
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt
./run.py --executable=${{ github.workspace }}/js-repl/bin/js --iterations=5
run_options="--iterations=5"
if [ "${{ github.event.workflow_run.event }}" = "workflow_dispatch" ]; then
# Upstream was run manually; we might run into failing benchmarks as a result of older builds.
run_options="${run_options} --continue-on-failure"
fi
./run.py \
--executable=${{ github.workspace }}/js-repl/bin/js \
--wasm-executable=${{ github.workspace }}/wasm-repl/bin/wasm \
${run_options}
- name: 'Save results as an artifact'
uses: actions/upload-artifact@v4
@ -76,7 +118,8 @@ jobs:
shell: bash
run: |
echo '{
"commit": "${{ github.event.workflow_run.head_sha }}",
"commit": "${{ steps.js-build-commit.outputs.sha }}",
"benchmarks_commit": "${{ steps.js-benchmarks-commit.outputs.sha }}",
"os": "${{ matrix.os_name }}",
"arch": "${{ matrix.arch }}",
"artifact": "js-benchmarks-results-${{ matrix.os_name }}-${{ matrix.arch }}",

View File

@ -9,7 +9,7 @@ on:
os_name:
required: true
type: string
runner:
runner_labels:
required: true
type: string
arch:
@ -28,7 +28,7 @@ env:
# github.workspace = /home/runner/work/ladybird/ladybird
LADYBIRD_SOURCE_DIR: ${{ github.workspace }}
CCACHE_DIR: ${{ github.workspace }}/.ccache
VCPKG_ROOT: ${{ github.workspace }}/Build/vcpkg
VCPKG_ROOT: ${{ github.workspace }}/Build/vcpkg
# Use the compiler version for the ccache compiler hash. Otherwise, if plugins are enabled, the plugin .so files
# are included in the hash. This results in clean builds on every run as the .so files are rebuilt.
@ -38,16 +38,16 @@ env:
jobs:
CI:
runs-on: ${{ inputs.runner }}
runs-on: ${{ fromJSON(inputs.runner_labels) }}
steps:
# Pull requests can trail behind `master` and can cause breakage if merging before running the CI checks on an updated branch.
# Luckily, GitHub creates and maintains a merge branch that is updated whenever the target or source branch is modified. By
# checking this branch out, we gain a stabler `master` at the cost of reproducibility.
- uses: actions/checkout@v4
- uses: actions/checkout@v5
if: ${{ github.event_name != 'pull_request' }}
- uses: actions/checkout@v4
- uses: actions/checkout@v5
if: ${{ github.event_name == 'pull_request' }}
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
@ -62,9 +62,10 @@ jobs:
# === PREPARE FOR BUILDING ===
- name: Assign Build Parameters
if: ${{ inputs.os_name != 'Windows' }}
id: 'build-parameters'
run: |
CMAKE_OPTIONS="-DENABLE_QT=ON"
CMAKE_OPTIONS="-DENABLE_CI_BASELINE_CPU=ON"
if ${{ inputs.toolchain == 'Swift' }} ; then
echo "host_cc=$(swiftly use --print-location)/usr/bin/clang" >> "$GITHUB_OUTPUT"
echo "host_cxx=$(swiftly use --print-location)/usr/bin/clang++" >> "$GITHUB_OUTPUT"
@ -103,29 +104,28 @@ jobs:
uses: ./.github/actions/cache-restore
id: 'cache-restore'
with:
runner_label: ${{ inputs.runner }}
runner_labels: ${{ inputs.runner_labels }}
os: ${{ inputs.os_name }}
arch: ${{ inputs.arch }}
toolchain: ${{ inputs.toolchain }}
cache_key_extra: ${{ steps.build-parameters.outputs.ccache_key }}
cache_key_extra: ${{ inputs.os_name == 'Windows' && inputs.build_preset || steps.build-parameters.outputs.ccache_key }}
ccache_path: ${{ env.CCACHE_DIR }}
download_cache_path: ${{ github.workspace }}/Build/caches
vcpkg_cache_path: ${{ github.workspace }}/Build/caches/vcpkg-binary-cache
- name: Set dynamic environment variables
if: ${{ inputs.os_name != 'Windows' }}
run: |
# Note: Required for vcpkg to use this compiler for its own builds.
echo "CC=${{ steps.build-parameters.outputs.host_cc }}" >> "$GITHUB_ENV"
echo "CXX=${{ steps.build-parameters.outputs.host_cxx }}" >> "$GITHUB_ENV"
# https://github.com/actions/runner-images/issues/9330
- name: Enable Microphone Access (macOS 14)
if: ${{ inputs.os_name == 'macOS' }}
run: sqlite3 $HOME/Library/Application\ Support/com.apple.TCC/TCC.db "INSERT OR IGNORE INTO access VALUES ('kTCCServiceMicrophone','/usr/local/opt/runner/provisioner/provisioner',1,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,1687786159,NULL,NULL,'UNUSED',1687786159);"
- name: Create Build Environment
if: ${{ inputs.build_preset != 'Fuzzers_CI' }}
if: ${{ inputs.os_name != 'Windows' && inputs.build_preset != 'Fuzzers' }}
working-directory: ${{ github.workspace }}
env:
VCPKG_CACHE_SAS: ${{ github.ref == 'refs/heads/master' && secrets.VCPKG_CACHE_SAS || '' }}
VCPKG_CACHE_MODE: ${{ github.ref == 'refs/heads/master' && 'write' || '' }}
run: |
cmake --preset ${{ inputs.build_preset }} -B Build \
${{ steps.build-parameters.outputs.cmake_options }} \
@ -133,13 +133,24 @@ jobs:
-DCMAKE_C_COMPILER=${{ steps.build-parameters.outputs.host_cc }} \
-DCMAKE_CXX_COMPILER=${{ steps.build-parameters.outputs.host_cxx }}
- name: Create Build Environment
if: ${{ inputs.build_preset == 'Fuzzers_CI' }}
- name: Create Build Environment (Windows)
if: ${{ inputs.os_name == 'Windows' }}
working-directory: ${{ github.workspace }}
env:
VCPKG_CACHE_SAS: ${{ github.ref == 'refs/heads/master' && secrets.VCPKG_CACHE_SAS || '' }}
VCPKG_CACHE_MODE: ${{ github.ref == 'refs/heads/master' && 'write' || '' }}
run: |
set -e
cmake --preset ${{ inputs.build_preset }} -B Build `
-DENABLE_CI_BASELINE_CPU=ON
cmake --preset=Distribution_CI -S Meta/Lagom -B ${{ github.workspace }}/Build/tools-build \
- name: Create Build Environment (Fuzzers)
if: ${{ inputs.build_preset == 'Fuzzers' }}
working-directory: ${{ github.workspace }}
env:
VCPKG_CACHE_SAS: ${{ github.ref == 'refs/heads/master' && secrets.VCPKG_CACHE_SAS || '' }}
VCPKG_CACHE_MODE: ${{ github.ref == 'refs/heads/master' && 'write' || '' }}
run: |
cmake --preset=Distribution -S Meta/Lagom -B ${{ github.workspace }}/Build/tools-build \
-DLAGOM_TOOLS_ONLY=ON \
-DINSTALL_LAGOM_TOOLS=ON \
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/Build/tools-install \
@ -159,24 +170,20 @@ jobs:
- name: Build
working-directory: ${{ github.workspace }}/Build
run: |
set -e
cmake --build .
cmake --install . --strip --prefix ${{ github.workspace }}/Install
- name: Enable the Ladybird AppKit chrome
if: ${{ inputs.os_name == 'macOS' && inputs.build_preset == 'Sanitizer_CI' }}
- name: Build - macOS with Qt
if: ${{ inputs.os_name == 'macOS' && inputs.build_preset == 'Sanitizer' }}
working-directory: ${{ github.workspace }}
run: cmake -B Build -DENABLE_QT=OFF
- name: Build the Ladybird AppKit chrome
if: ${{ inputs.os_name == 'macOS' && inputs.build_preset == 'Sanitizer_CI' }}
working-directory: ${{ github.workspace }}/Build
run: cmake --build .
run: |
cmake --preset ${{ inputs.build_preset }} -B Build -DENABLE_QT=ON
cmake --build Build
- name: Save Caches
uses: ./.github/actions/cache-save
with:
runner_label: ${{ inputs.runner }}
runner_labels: ${{ inputs.runner_labels }}
arch: ${{ inputs.arch }}
ccache_path: ${{ env.CCACHE_DIR }}
ccache_primary_key: ${{ steps.cache-restore.outputs.ccache_primary_key }}
@ -186,33 +193,33 @@ jobs:
# === TEST ===
- name: Test
if: ${{ inputs.build_preset == 'Sanitizer_CI' }}
if: ${{ contains(inputs.build_preset, 'Sanitizer') }}
working-directory: ${{ github.workspace }}
run: ctest --preset Sanitizer --output-on-failure --test-dir Build --timeout 1800
run: ctest --preset ${{ inputs.build_preset }} --output-on-failure --test-dir Build --timeout 1800
env:
TESTS_ONLY: 1
# NOTE: These are appended to the preset's options.
ASAN_OPTIONS: 'log_path=${{ github.workspace }}/asan.log'
UBSAN_OPTIONS: 'log_path=${{ github.workspace }}/ubsan.log'
ASAN_OPTIONS: 'log_path="${{ github.workspace }}/asan.log"'
UBSAN_OPTIONS: 'log_path="${{ github.workspace }}/ubsan.log"'
- name: Test
if: ${{ inputs.build_preset != 'Fuzzers_CI' && inputs.build_preset != 'Sanitizer_CI' }}
if: ${{ inputs.build_preset != 'Fuzzers' && !contains(inputs.build_preset, 'Sanitizer') }}
working-directory: ${{ github.workspace }}
run: ctest --output-on-failure --test-dir Build --timeout 1800
env:
TESTS_ONLY: 1
- name: Upload LibWeb Test Artifacts
if: ${{ always() && inputs.build_preset != 'Fuzzers_CI' }}
if: ${{ always() && inputs.build_preset != 'Fuzzers' }}
uses: actions/upload-artifact@v4
with:
name: libweb-test-artifacts-${{ inputs.os_name }}-${{inputs.build_preset}}-${{inputs.toolchain}}-${{inputs.clang-plugins}}
path: ${{ github.workspace }}/Build/UI/Headless/test-dumps
name: libweb-test-artifacts-${{ inputs.os_name }}-${{ inputs.build_preset }}-${{ inputs.toolchain }}-${{ inputs.clang-plugins }}
path: ${{ github.workspace }}/Build/Lagom/Tests/LibWeb/test-web/test-dumps/
retention-days: 0
if-no-files-found: ignore
- name: Sanitizer Output
if: ${{ !cancelled() && inputs.build_preset == 'Sanitizer_CI' }}
if: ${{ !cancelled() && inputs.build_preset == 'Sanitizer' }}
working-directory: ${{ github.workspace }}
run: |
log_output=$(find . -maxdepth 1 \( -name 'asan.log.*' -o -name 'ubsan.log.*' \) -exec cat {} \; )
@ -224,7 +231,7 @@ jobs:
fi
- name: Lints
if: ${{ inputs.os_name == 'Linux' && inputs.build_preset == 'Sanitizer_CI' }}
if: ${{ inputs.os_name == 'Linux' && inputs.build_preset == 'Sanitizer' }}
working-directory: ${{ github.workspace }}
run: |
set -e

View File

@ -22,28 +22,28 @@ jobs:
rm -rf "${{ github.workspace }}/*"
- name: Checkout LadybirdBrowser/ladybird
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Checkout LadybirdBrowser/libjs-test262
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: LadybirdBrowser/libjs-test262
path: libjs-test262
- name: Checkout LadybirdBrowser/libjs-data
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: LadybirdBrowser/libjs-data
path: libjs-data
- name: Checkout tc39/test262
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: tc39/test262
path: test262
- name: Checkout tc39/test262-parser-tests
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: tc39/test262-parser-tests
path: test262-parser-tests
@ -51,7 +51,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y ninja-build unzip clang-20 clang++-20 jq curl zip tar autoconf autoconf-archive automake nasm pkg-config libgl1-mesa-dev rsync
sudo apt-get install -y ninja-build unzip clang-20 clang++-20 jq curl zip tar autoconf autoconf-archive automake nasm pkg-config libgl1-mesa-dev rsync libtool
test -e /opt/wabt-1.0.35 || (
cd /tmp
@ -64,7 +64,7 @@ jobs:
./Toolchain/BuildVcpkg.py --ci
- name: Setup Python
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: '3.x'
@ -77,7 +77,7 @@ jobs:
- name: Restore Caches
uses: ./.github/actions/cache-restore
with:
runner_label: test262-runner
runner_labels: '["test262-runner"]'
os: 'Linux'
arch: 'Lagom'
download_cache_path: ${{ github.workspace }}/libjs-test262/Build/caches
@ -96,7 +96,7 @@ jobs:
env PATH="/opt/wabt-1.0.35/bin:$PATH" \
CC=clang-20 \
CXX=clang++-20 \
cmake --preset CI -B libjs-test262/Build \
cmake --preset Release -B libjs-test262/Build \
-DCMAKE_C_COMPILER=clang-20 \
-DCMAKE_CXX_COMPILER=clang++-20 \
-DWASM_SPEC_TEST_SKIP_FORMATTING=ON \

View File

@ -8,14 +8,14 @@ jobs:
if: github.repository == 'LadybirdBrowser/ladybird'
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Set Up Environment
shell: bash
run: |
set -e
brew install black curl llvm@20 ninja optipng shellcheck swift-format unzip
brew install curl llvm@20 ninja optipng ruff shellcheck swift-format unzip
# Note: gn isn't available in homebrew :(
# Corresponds to https://gn.googlesource.com/gn/+/225e90c5025bf74f41dbee60d9cde4512c846fe7

View File

@ -12,7 +12,7 @@ jobs:
steps:
- name: Lint PR commits
uses: actions/github-script@v7
uses: actions/github-script@v8
with:
script: |
const excludedBotIds = [

View File

@ -27,7 +27,7 @@ jobs:
os: [macos-14]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Set Up Environment
uses: ./.github/actions/setup
@ -36,13 +36,13 @@ jobs:
arch: 'Lagom'
- name: Set Up Java
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: 17
- name: Set Up Gradle
uses: gradle/actions/setup-gradle@v4
uses: gradle/actions/setup-gradle@v5
# === PREPARE FOR BUILDING ===
@ -95,7 +95,7 @@ jobs:
run: ./gradlew connectedAndroidTest
env:
GRADLE_OPTS: '-Xmx3072m'
SERENITY_CACHE_DIR: ${{ github.workspace }}/Build/caches
LADYBIRD_CACHE_DIR: ${{ github.workspace }}/Build/caches
- name: Save Caches
uses: ./.github/actions/cache-save

View File

@ -13,58 +13,86 @@ jobs:
# CI matrix - runs the job in lagom-template.yml with different configurations.
Lagom:
if: github.repository == 'LadybirdBrowser/ladybird'
name: ${{ matrix.os_name }}, ${{ matrix.arch }}, ${{ matrix.build_preset }}, ${{ matrix.toolchain }}
strategy:
fail-fast: false
matrix:
os_name: ['Linux']
arch: ['arm64']
build_preset: ['Sanitizer_CI']
build_preset: ['Sanitizer']
toolchain: ['Clang']
clang_plugins: [false]
runner: ['blacksmith-8vcpu-ubuntu-2404-arm']
runner_labels: ['["blacksmith-8vcpu-ubuntu-2404-arm"]']
include:
- os_name: 'Linux'
arch: 'x86_64'
build_preset: 'Distribution_CI'
build_preset: 'Distribution'
toolchain: 'GNU'
clang_plugins: false
runner: 'blacksmith-8vcpu-ubuntu-2404'
runner_labels: '["blacksmith-8vcpu-ubuntu-2404"]'
- os_name: 'macOS'
arch: 'arm64'
build_preset: 'Distribution_CI'
build_preset: 'Distribution'
toolchain: 'Clang'
clang_plugins: false
runner: 'macos-15'
runner_labels: '["macos-15"]'
- os_name: 'Linux'
arch: 'arm64'
build_preset: 'Distribution_CI'
build_preset: 'Distribution'
toolchain: 'Clang'
clang_plugins: false
runner: 'blacksmith-8vcpu-ubuntu-2404-arm'
runner_labels: '["blacksmith-8vcpu-ubuntu-2404-arm"]'
- os_name: 'Linux'
arch: 'x86_64'
build_preset: 'Sanitizer_CI'
build_preset: 'Sanitizer'
toolchain: 'Swift'
clang_plugins: false
runner: 'blacksmith-8vcpu-ubuntu-2404'
runner_labels: '["blacksmith-8vcpu-ubuntu-2404"]'
- os_name: 'macOS'
arch: 'arm64'
build_preset: 'Sanitizer_CI'
build_preset: 'Sanitizer'
toolchain: 'Swift'
clang_plugins: false
runner: 'macos-15'
runner_labels: '["macos-15"]'
- os_name: 'Windows'
arch: 'x86_64'
build_preset: 'Windows_Sanitizer_CI'
toolchain: 'ClangCL'
clang_plugins: false
runner_labels: '["windows-2025"]'
secrets: inherit
uses: ./.github/workflows/lagom-template.yml
with:
toolchain: ${{ matrix.toolchain }}
os_name: ${{ matrix.os_name }}
runner: ${{ matrix.runner }}
runner_labels: ${{ matrix.runner_labels }}
arch: ${{ matrix.arch }}
build_preset: ${{ matrix.build_preset }}
clang_plugins: ${{ matrix.clang_plugins }}
flatpak:
if: github.repository == 'LadybirdBrowser/ladybird'
name: Flatpak ${{ matrix.arch }}
strategy:
fail-fast: false
matrix:
arch: [ 'x86_64' ]
runner_labels: [ '["blacksmith-8vcpu-ubuntu-2404"]' ]
include:
- arch: 'aarch64'
runner_labels: '["blacksmith-8vcpu-ubuntu-2404-arm"]'
secrets: inherit
uses: ./.github/workflows/flatpak-template.yml
with:
arch: ${{ matrix.arch }}
runner_labels: ${{ matrix.runner_labels }}

View File

@ -1,74 +0,0 @@
name: Nightly Windows
on:
# Automatically run at the end of every day.
schedule:
- cron: '0 0 * * *'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# runner.workspace = /home/runner/work/ladybird
# github.workspace = /home/runner/work/ladybird/ladybird
LADYBIRD_SOURCE_DIR: ${{ github.workspace }}
VCPKG_ROOT: ${{ github.workspace }}/Build/vcpkg
jobs:
CI:
if: github.repository == 'LadybirdBrowser/ladybird'
runs-on: windows-2022
steps:
- uses: actions/checkout@v4
if: ${{ github.event_name != 'pull_request' }}
- uses: actions/checkout@v4
if: ${{ github.event_name == 'pull_request' }}
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- name: Set Up Environment
uses: ./.github/actions/setup
with:
os: 'Windows'
arch: 'x86_64'
toolchain: 'ClangCL'
- name: Restore Caches
uses: ./.github/actions/cache-restore
id: 'cache-restore'
with:
runner_label: windows-2022
os: Windows
arch: x86_64
toolchain: ClangCL
cache_key_extra: windows_ci_ninja
download_cache_path: ${{ github.workspace }}/Build/caches
vcpkg_cache_path: ${{ github.workspace }}/Build/caches/vcpkg-binary-cache
- name: Create Build Environment
working-directory: ${{ github.workspace }}
run: |
cmake --preset windows_ci_ninja
- name: Build
working-directory: ${{ github.workspace }}
run: |
cmake --build --preset windows_ci_ninja
- name: Save Caches
uses: ./.github/actions/cache-save
with:
runner_label: windows-2022
arch: x86_64
vcpkg_cache_path: ${{ github.workspace }}/Build/caches/vcpkg-binary-cache
vcpkg_cache_primary_key: ${{ steps.cache-restore.outputs.vcpkg_cache_primary_key }}
- name: Test
working-directory: ${{ github.workspace }}
run: ctest --preset windows_ci_ninja --timeout 1800
env:
TESTS_ONLY: 1

View File

@ -11,7 +11,7 @@ jobs:
if: github.repository == 'LadybirdBrowser/ladybird'
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: fregante/setup-git-user@v2

View File

@ -10,6 +10,7 @@ on:
jobs:
stale:
runs-on: blacksmith-2vcpu-ubuntu-2404
if: github.repository == 'LadybirdBrowser/ladybird'
permissions:
actions: write # required for cache management (see https://github.com/actions/stale/issues/1133)
pull-requests: write

2
.gitignore vendored
View File

@ -27,7 +27,7 @@ output/
.vim/
.exrc
.helix/
.swift-version
.flatpak-builder/
# Environments
.venv/

View File

@ -2,11 +2,6 @@ Libraries/LibJS/Tests/invalid-lhs-in-assignment.js
Libraries/LibJS/Tests/unicode-identifier-escape.js
Libraries/LibJS/Tests/modules/failing.mjs
# FIXME: Remove once prettier is updated to support using declarations.
Libraries/LibJS/Tests/builtins/DisposableStack/DisposableStack.prototype.@@dispose.js
Libraries/LibJS/Tests/modules/top-level-dispose.mjs
Libraries/LibJS/Tests/using-declaration.js
Libraries/LibJS/Tests/using-for-loops.js
Tests/LibWeb/Crash/wpt-import/
Tests/LibWeb/Ref/input/wpt-import
Tests/LibWeb/Text/input/wpt-import

1
.swift-version Normal file
View File

@ -0,0 +1 @@
main-snapshot-2025-06-22

View File

@ -32,6 +32,7 @@
# For more information, please refer to <http://unlicense.org/>
import os
import ycm_core
DIR_OF_THIS_SCRIPT = os.path.abspath(os.path.dirname(__file__))

View File

@ -22,9 +22,11 @@
# define PRINT_ERROR(s) (void)::fputs((s), stderr)
#endif
#if defined(AK_HAS_STD_STACKTRACE)
# include <stacktrace>
# include <string>
#if defined(AK_HAS_CPPTRACE)
# include <cpptrace/cpptrace.hpp>
# include <cpptrace/formatting.hpp>
# include <cstdlib>
# include <iostream>
#elif defined(AK_HAS_BACKTRACE_HEADER)
# include <AK/StringBuilder.h>
# include <AK/StringView.h>
@ -39,22 +41,25 @@
extern "C" {
#if defined(AK_HAS_STD_STACKTRACE)
void dump_backtrace()
#if defined(AK_HAS_CPPTRACE)
void dump_backtrace(unsigned frames_to_skip, unsigned max_depth)
{
// We assume the stacktrace implementation demangles symbols, as does microsoft/STL
PRINT_ERROR(std::to_string(std::stacktrace::current(2)).c_str());
PRINT_ERROR("\n");
// We should be using cpptrace for everything but android.
auto stacktrace = cpptrace::generate_trace(frames_to_skip, max_depth);
auto* var = getenv("LADYBIRD_BACKTRACE_SNIPPETS");
bool print_snippets = var && strnlen(var, 1) > 0;
static auto formatter = cpptrace::formatter {}.snippets(print_snippets);
formatter.print(std::cerr, stacktrace);
}
#elif defined(AK_HAS_BACKTRACE_HEADER)
void dump_backtrace()
void dump_backtrace(unsigned frames_to_skip, [[maybe_unused]] unsigned max_depth)
{
// Grab symbols and dso name for up to 256 frames
void* trace[256] = {};
int const num_frames = backtrace(trace, array_size(trace));
unsigned const num_frames = backtrace(trace, array_size(trace));
char** syms = backtrace_symbols(trace, num_frames);
for (auto i = 0; i < num_frames; ++i) {
for (auto i = frames_to_skip; i < num_frames; ++i) {
// If there is a C++ symbol name in the line of the backtrace, demangle it
StringView sym(syms[i], strlen(syms[i]));
StringBuilder error_builder;
@ -93,7 +98,7 @@ void dump_backtrace()
free(syms);
}
#else
void dump_backtrace()
void dump_backtrace([[maybe_unused]] unsigned frames_to_skip, [[maybe_unused]] unsigned max_depth)
{
PRINT_ERROR("dump_backtrace() is not supported with the current compilation options.\n");
}
@ -104,16 +109,27 @@ bool ak_colorize_output(void)
#if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID)
return true;
#elif defined(AK_OS_WINDOWS)
return false;
HANDLE hStdErr = GetStdHandle(STD_ERROR_HANDLE);
if (hStdErr == INVALID_HANDLE_VALUE) {
return false;
}
DWORD dwMode = 0;
if (!GetConsoleMode(hStdErr, &dwMode)) {
return false;
}
DWORD mask = ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
return (dwMode & mask) == mask;
#else
return isatty(STDERR_FILENO) == 1;
#endif
}
void ak_trap(void)
NEVER_INLINE void ak_trap(void)
{
#if defined(AK_HAS_BACKTRACE_HEADER) || defined(AK_HAS_STD_STACKTRACE)
dump_backtrace();
#if defined(AK_HAS_BACKTRACE_HEADER) || defined(AK_HAS_CPPTRACE)
// Skip 3 frames to get to caller. That is dump_backtrace, ak_trap, and ak_verification_failed.
dump_backtrace(3, 100);
#endif
__builtin_trap();
}
@ -136,7 +152,6 @@ static AssertionHandlerFunc get_custom_assertion_handler()
# pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
auto handler = reinterpret_cast<AssertionHandlerFunc>(GetProcAddress(module, "ak_assertion_handler"));
# pragma clang diagnostic pop
FreeLibrary(module);
return handler;
}
return nullptr;

View File

@ -6,11 +6,12 @@
#pragma once
extern "C" void dump_backtrace();
// All the functions for stack traces are never inline as we want a consistent number of frames
extern "C" __attribute__((noinline)) void dump_backtrace(unsigned frames_to_skip = 1, unsigned max_depth = 100);
extern "C" bool ak_colorize_output(void);
extern "C" __attribute__((noreturn)) void ak_trap(void);
extern "C" __attribute__((noreturn, noinline)) void ak_trap(void);
extern "C" __attribute__((noreturn)) void ak_verification_failed(char const*);
extern "C" __attribute__((noreturn, noinline)) void ak_verification_failed(char const*);
#define __stringify_helper(x) #x
#define __stringify(x) __stringify_helper(x)
#define VERIFY(...) \
@ -25,7 +26,7 @@ static constexpr bool TODO = false;
#define TODO_PPC64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
#define TODO_PPC() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
extern "C" __attribute__((noreturn)) void ak_assertion_failed(char const*);
extern "C" __attribute__((noreturn, noinline)) void ak_assertion_failed(char const*);
#ifndef NDEBUG
# define ASSERT(...) \
(__builtin_expect(/* NOLINT(readability-simplify-boolean-expr) */ !(__VA_ARGS__), 0) \

View File

@ -147,14 +147,14 @@ public:
# pragma GCC diagnostic pop
#endif
[[nodiscard]] Bytes bytes()
[[nodiscard]] Bytes bytes() LIFETIME_BOUND
{
return { data(), size() };
}
[[nodiscard]] ReadonlyBytes bytes() const { return { data(), size() }; }
[[nodiscard]] ReadonlyBytes bytes() const LIFETIME_BOUND { return { data(), size() }; }
[[nodiscard]] AK::Bytes span() { return { data(), size() }; }
[[nodiscard]] AK::ReadonlyBytes span() const { return { data(), size() }; }
[[nodiscard]] AK::Bytes span() LIFETIME_BOUND { return { data(), size() }; }
[[nodiscard]] AK::ReadonlyBytes span() const LIFETIME_BOUND { return { data(), size() }; }
[[nodiscard]] u8* offset_pointer(size_t offset) { return data() + offset; }
[[nodiscard]] u8 const* offset_pointer(size_t offset) const { return data() + offset; }
@ -243,7 +243,7 @@ public:
}
/// Like get_bytes_for_writing, but crashes if allocation fails.
Bytes must_get_bytes_for_writing(size_t length)
Bytes must_get_bytes_for_writing(size_t length) LIFETIME_BOUND
{
return MUST(get_bytes_for_writing(length));
}
@ -306,8 +306,8 @@ public:
__builtin_memset(data(), 0, m_size);
}
operator Bytes() { return bytes(); }
operator ReadonlyBytes() const { return bytes(); }
operator Bytes() LIFETIME_BOUND { return bytes(); }
operator ReadonlyBytes() const LIFETIME_BOUND { return bytes(); }
ALWAYS_INLINE size_t capacity() const { return m_inline ? inline_capacity : m_outline_capacity; }
ALWAYS_INLINE bool is_inline() const { return m_inline; }

View File

@ -126,9 +126,9 @@ public:
}
template<Arithmetic T>
Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes) const
Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes, int base = 10) const
{
return view().to_number<T>(trim_whitespace);
return view().to_number<T>(trim_whitespace, base);
}
[[nodiscard]] ByteString to_lowercase() const;
@ -175,7 +175,7 @@ public:
using SearchDirection = StringUtils::SearchDirection;
[[nodiscard]] Optional<size_t> find_any_of(StringView needles, SearchDirection direction = SearchDirection::Forward) const { return StringUtils::find_any_of(*this, needles, direction); }
[[nodiscard]] StringView find_last_split_view(char separator) const& { return view().find_last_split_view(separator); }
[[nodiscard]] StringView find_last_split_view(char separator) const& LIFETIME_BOUND { return view().find_last_split_view(separator); }
[[nodiscard]] StringView find_last_split_view(char separator) const&& = delete;
[[nodiscard]] ByteString substring(size_t start, size_t length) const;
@ -194,7 +194,7 @@ public:
[[nodiscard]] bool copy_characters_to_buffer(char* buffer, size_t buffer_size) const;
[[nodiscard]] ALWAYS_INLINE ReadonlyBytes bytes() const& { return m_impl->bytes(); }
[[nodiscard]] ALWAYS_INLINE ReadonlyBytes bytes() const& LIFETIME_BOUND { return m_impl->bytes(); }
[[nodiscard]] ALWAYS_INLINE ReadonlyBytes bytes() const&& = delete;
[[nodiscard]] ALWAYS_INLINE char const& operator[](size_t i) const
@ -283,7 +283,7 @@ public:
return vformatted(fmtstr.view(), variadic_format_parameters);
}
[[nodiscard]] StringView view() const& { return { characters(), length() }; }
[[nodiscard]] StringView view() const& LIFETIME_BOUND { return { characters(), length() }; }
[[nodiscard]] StringView view() const&& = delete;
[[nodiscard]] ByteString replace(StringView needle, StringView replacement, ReplaceMode replace_mode = ReplaceMode::All) const { return StringUtils::replace(*this, needle, replacement, replace_mode); }

View File

@ -42,8 +42,8 @@ public:
// Includes NUL-terminator.
char const* characters() const { return &m_inline_buffer[0]; }
ALWAYS_INLINE ReadonlyBytes bytes() const { return { characters(), length() }; }
ALWAYS_INLINE StringView view() const { return { characters(), length() }; }
ALWAYS_INLINE ReadonlyBytes bytes() const LIFETIME_BOUND { return { characters(), length() }; }
ALWAYS_INLINE StringView view() const LIFETIME_BOUND { return { characters(), length() }; }
char const& operator[](size_t i) const
{

View File

@ -7,7 +7,6 @@ set(SOURCES
ConstrainedStream.cpp
CountingStream.cpp
Error.cpp
FloatingPointStringConversions.cpp
FlyString.cpp
Format.cpp
GenericLexer.cpp
@ -25,10 +24,14 @@ set(SOURCES
String.cpp
StringBase.cpp
StringBuilder.cpp
StringConversions.cpp
StringFloatingPointConversions.cpp
StringUtils.cpp
StringView.cpp
Time.cpp
Utf16FlyString.cpp
Utf16String.cpp
Utf16StringData.cpp
Utf16View.cpp
Utf32View.cpp
Utf8View.cpp
@ -36,21 +39,42 @@ set(SOURCES
)
if (WIN32)
list(APPEND SOURCES LexicalPathWindows.cpp)
list(APPEND SOURCES
LexicalPathWindows.cpp
DemangleWindows.cpp
)
else()
list(APPEND SOURCES LexicalPath.cpp)
endif()
serenity_lib(AK ak)
ladybird_lib(AK ak)
include(stacktrace)
find_package(cpptrace CONFIG)
find_package(Backtrace)
if(cpptrace_FOUND AND LADYBIRD_ENABLE_CPPTRACE)
target_link_libraries(AK PRIVATE cpptrace::cpptrace)
target_compile_definitions(AK PRIVATE AK_HAS_CPPTRACE=1)
elseif(Backtrace_FOUND)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.30)
target_link_libraries(AK PRIVATE Backtrace::Backtrace)
else()
target_include_directories(AK PRIVATE ${Backtrace_INCLUDE_DIRS})
target_link_libraries(AK PRIVATE ${Backtrace_LIBRARIES})
endif()
else()
message(WARNING "Cpptrace and Backtrace.h not found. Stack traces will not be available.")
endif()
configure_file(Backtrace.h.in Backtrace.h @ONLY)
link_stacktrace_library(AK STD_DEFINITION AK_HAS_STD_STACKTRACE)
find_package(simdutf REQUIRED)
swizzle_target_properties_for_swift(simdutf::simdutf)
target_link_libraries(AK PRIVATE simdutf::simdutf)
find_package(FastFloat CONFIG REQUIRED)
swizzle_target_properties_for_swift(FastFloat::fast_float)
target_link_libraries(AK PRIVATE FastFloat::fast_float)
# FIXME: Make this generic for all imported shared library dependencies and apply globally
if (BUILD_SHARED_LIBS AND NOT CMAKE_SKIP_INSTALL_RULES AND NOT "${VCPKG_INSTALLED_DIR}" STREQUAL "")
install(IMPORTED_RUNTIME_ARTIFACTS simdutf::simdutf
@ -73,6 +97,19 @@ if (WIN32)
# FIXME: Windows on ARM
target_link_libraries(AK PRIVATE clang_rt.builtins-x86_64.lib)
target_link_libraries(AK PRIVATE Bcrypt.lib)
target_link_libraries(AK PRIVATE delayimp.lib)
set(DELAYLOAD_DBGHLP_VISIBILITY PRIVATE)
if (NOT BUILD_SHARED_LIBS)
set(DELAYLOAD_DBGHLP_VISIBILITY INTERFACE)
endif()
target_link_options(AK ${DELAYLOAD_DBGHLP_VISIBILITY} /DELAYLOAD:dbghelp.dll)
# FIXME: Add support for building LibUnicode in sanitize
# lld-link: error: /failifmismatch: mismatch detected for 'annotate_string':
# >>> lagom-ak.lib(Utf16View.cpp.obj) has value 1
# >>> lagom-unicode.lib(IDNA.cpp.obj) has value 0
if (ENABLE_WINDOWS_CI)
target_compile_options(AK PRIVATE -fno-sanitize=address)
endif()
elseif (APPLE)
set(ASSERTION_HANDLER_VISIBILITY PRIVATE)
if (NOT BUILD_SHARED_LIBS)

View File

@ -34,7 +34,7 @@
namespace AK {
template<typename Destination, typename Source, bool destination_is_wider = (sizeof(Destination) >= sizeof(Source)), bool destination_is_signed = NumericLimits<Destination>::is_signed(), bool source_is_signed = NumericLimits<Source>::is_signed()>
template<typename Destination, typename Source, bool destination_is_wider = (NumericLimits<Destination>::max() >= NumericLimits<Source>::max()), bool destination_is_signed = NumericLimits<Destination>::is_signed(), bool source_is_signed = NumericLimits<Source>::is_signed()>
struct TypeBoundsChecker;
template<typename Destination, typename Source>
@ -98,7 +98,7 @@ template<typename Destination, typename Source>
struct TypeBoundsChecker<Destination, Source, true, true, false> {
static constexpr bool is_within_range(Source value)
{
if (sizeof(Destination) > sizeof(Source))
if (NumericLimits<Destination>::max() > NumericLimits<Source>::max())
return true;
return value <= static_cast<Source>(NumericLimits<Destination>::max());
}

View File

@ -15,18 +15,6 @@ ConstrainedStream::ConstrainedStream(MaybeOwned<Stream> stream, u64 limit)
{
}
ErrorOr<Bytes> ConstrainedStream::read_some(Bytes bytes)
{
if (bytes.size() >= m_limit)
bytes = bytes.trim(m_limit);
auto result = TRY(m_stream->read_some(bytes));
m_limit -= result.size();
return result;
}
ErrorOr<void> ConstrainedStream::discard(size_t discarded_bytes)
{
if (discarded_bytes >= m_limit)

View File

@ -16,7 +16,12 @@ class ConstrainedStream : public Stream {
public:
ConstrainedStream(MaybeOwned<Stream>, u64 limit);
virtual ErrorOr<Bytes> read_some(Bytes) override;
virtual ErrorOr<Bytes> read_some(Bytes bytes) override
{
auto result = TRY(m_stream->read_some(bytes.trim(m_limit)));
m_limit -= result.size();
return result;
}
virtual ErrorOr<void> discard(size_t discarded_bytes) override;
virtual ErrorOr<size_t> write_some(ReadonlyBytes) override;
virtual bool is_eof() const override;

View File

@ -8,8 +8,9 @@
namespace AK {
CountingStream::CountingStream(MaybeOwned<Stream> stream)
CountingStream::CountingStream(MaybeOwned<Stream> stream, size_t offset)
: m_stream(move(stream))
, m_read_bytes(offset)
{
}

View File

@ -13,7 +13,7 @@ namespace AK {
class CountingStream : public Stream {
public:
CountingStream(MaybeOwned<Stream>);
CountingStream(MaybeOwned<Stream>, size_t offset = 0);
u64 read_bytes() const;

View File

@ -102,6 +102,10 @@
# cmakedefine01 HTML_SCRIPT_DEBUG
#endif
#ifndef HTTP_CACHE_DEBUG
# cmakedefine01 HTTP_CACHE_DEBUG
#endif
#ifndef HTTPJOB_DEBUG
# cmakedefine01 HTTPJOB_DEBUG
#endif

View File

@ -26,11 +26,7 @@ inline ByteString demangle(StringView name)
return string;
}
#else
inline ByteString demangle(StringView name)
{
// FIXME: Implement AK::demangle on Windows
return name;
}
ByteString demangle(StringView name);
#endif
}

32
AK/DemangleWindows.cpp Normal file
View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2025, Tomasz Strejczek
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/ByteString.h>
#include <AK/StringView.h>
#include <Windows.h>
#include <dbghelp.h>
#pragma comment(lib, "dbghelp.lib") // /DELAYLOAD:dbghelp.dll is configured in CMakeLists.txt
#include <AK/Demangle.h>
namespace AK {
ByteString demangle(StringView name)
{
// The buffer size is arbitrary but should be large enough for most cases.
// Unfortunately, there is no way to know the exact size needed beforehand.
// Also calling UnDecorateSymbolName with a too small buffer will not return an error, it will just truncate the result.
char buffer[4096] = {};
// UNDNAME_COMPLETE asks for the full decoration (equivalent to the Itanium demangle method in libgcc/libcxxabi)
auto chars_written = UnDecorateSymbolName(name.to_byte_string().characters(), buffer, sizeof(buffer), UNDNAME_COMPLETE);
return ByteString(chars_written > 0 ? StringView { buffer, static_cast<size_t>(chars_written) } : name);
}
} // namespace AK

View File

@ -23,8 +23,8 @@ public:
m_node = m_node->next;
return *this;
}
ElementType& operator*() { return m_node->value; }
ElementType* operator->() { return &m_node->value; }
ElementType& operator*() { return m_node->value(); }
ElementType* operator->() { return &m_node->value(); }
[[nodiscard]] bool is_end() const { return !m_node; }
static DoublyLinkedListIterator universal_end() { return DoublyLinkedListIterator(nullptr); }
@ -37,25 +37,39 @@ private:
typename ListType::Node* m_node;
};
template<typename T>
template<typename T, size_t node_cache_size>
class DoublyLinkedList {
private:
struct Node {
template<typename U>
explicit Node(U&& v)
: value(forward<U>(v))
{
new (m_value) T(forward<U>(v));
static_assert(
requires { T(v); }, "Conversion operator is missing.");
}
T value;
T const& value() const { return *bit_cast<T const*>(&m_value); }
T& value() { return *bit_cast<T*>(&m_value); }
Node* next { nullptr };
Node* prev { nullptr };
private:
alignas(T) u8 m_value[sizeof(T)];
};
public:
DoublyLinkedList() = default;
~DoublyLinkedList() { clear(); }
~DoublyLinkedList()
{
clear();
if constexpr (node_cache_size > 0) {
for (size_t i = 0; i < m_node_cache.used_count; ++i)
delete m_node_cache.nodes[i];
m_node_cache.used_count = 0;
}
}
[[nodiscard]] bool is_empty() const { return !m_head; }
@ -63,32 +77,42 @@ public:
{
for (auto* node = m_head; node;) {
auto* next = node->next;
delete node;
drop_node(node);
node = next;
}
m_head = nullptr;
m_tail = nullptr;
m_size = 0;
}
[[nodiscard]] T& first()
{
VERIFY(m_head);
return m_head->value;
return m_head->value();
}
[[nodiscard]] T const& first() const
{
VERIFY(m_head);
return m_head->value;
return m_head->value();
}
[[nodiscard]] T& last()
{
VERIFY(m_head);
return m_tail->value;
return m_tail->value();
}
[[nodiscard]] T const& last() const
{
VERIFY(m_head);
return m_tail->value;
return m_tail->value();
}
[[nodiscard]] T& unchecked_last()
{
return m_tail->value();
}
[[nodiscard]] T const& unchecked_last() const
{
return m_tail->value();
}
template<typename U>
@ -96,9 +120,10 @@ public:
{
static_assert(
requires { T(value); }, "Conversion operator is missing.");
auto* node = new (nothrow) Node(forward<U>(value));
auto* node = make_node(forward<U>(value));
if (!node)
return Error::from_errno(ENOMEM);
m_size += 1;
if (!m_head) {
VERIFY(!m_tail);
m_head = node;
@ -117,9 +142,10 @@ public:
ErrorOr<void> try_prepend(U&& value)
{
static_assert(IsSame<T, U>);
auto* node = new (nothrow) Node(forward<U>(value));
auto* node = make_node(forward<U>(value));
if (!node)
return Error::from_errno(ENOMEM);
m_size += 1;
if (!m_head) {
VERIFY(!m_tail);
m_head = node;
@ -189,12 +215,95 @@ public:
VERIFY(node == m_tail);
m_tail = node->prev;
}
delete node;
m_size -= 1;
drop_node(node);
}
T take_first()
{
VERIFY(m_head);
auto value = move(m_head->value());
auto* old_head = m_head;
m_head = m_head->next;
if (m_head)
m_head->prev = nullptr;
else
m_tail = nullptr; // We removed the only element, no more elements left.
drop_node(old_head);
m_size -= 1;
return value;
}
T take_last()
{
VERIFY(m_tail);
auto value = move(m_tail->value());
auto* old_tail = m_tail;
m_tail = m_tail->prev;
if (m_tail)
m_tail->next = nullptr;
else
m_head = nullptr; // We removed the only element, no more elements left.
drop_node(old_tail);
m_size -= 1;
return value;
}
size_t size() const { return m_size; }
template<typename F>
void ensure_capacity(size_t new_capacity, F make_default_value = [] -> T { return T {}; })
{
if constexpr (node_cache_size == 0)
return;
if (m_size >= new_capacity)
return;
auto const rest = min(new_capacity - m_size, node_cache_size);
for (size_t i = m_node_cache.used_count; i <= rest; ++i)
m_node_cache.nodes[m_node_cache.used_count++] = make_node(make_default_value());
}
private:
void drop_node(Node* node)
{
if constexpr (node_cache_size > 0) {
if (m_node_cache.used_count + 1 < node_cache_size) {
node->value().~T();
m_node_cache.nodes[m_node_cache.used_count++] = node;
return;
}
}
node->value().~T();
delete node;
}
template<typename... Args>
Node* make_node(Args&&... args)
{
if constexpr (node_cache_size > 0) {
if (m_node_cache.used_count > 0) {
auto* node = m_node_cache.nodes[--m_node_cache.used_count];
new (node) Node(forward<Args>(args)...);
return node;
}
}
return new (nothrow) Node(forward<Args>(args)...);
}
Node* m_head { nullptr };
Node* m_tail { nullptr };
size_t m_size { 0 };
struct NonemptyNodeCache {
Array<Node*, node_cache_size> nodes;
size_t used_count { 0 };
};
using NodeCache = Conditional<(node_cache_size > 0), NonemptyNodeCache, Empty>;
NO_UNIQUE_ADDRESS NodeCache m_node_cache;
};
}

File diff suppressed because it is too large Load Diff

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2022, David Tuin <davidot@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/StringView.h>
namespace AK {
static constexpr char floating_point_decimal_separator = '.';
enum class FloatingPointError {
None,
NoOrInvalidInput,
OutOfRange,
RoundedDownToZero
};
template<FloatingPoint T>
struct FloatingPointParseResults {
char const* end_ptr { nullptr };
FloatingPointError error = FloatingPointError::None;
T value {};
[[nodiscard]] bool parsed_value() const
{
// All other errors do indicate out of range but did produce a valid value.
return error != FloatingPointError::NoOrInvalidInput;
}
};
/// This function finds the first floating point within [start, end). The accepted format is
/// intentionally as lenient as possible. If your format is stricter you must validate it
/// first. The format accepts:
/// - An optional sign, both + and - are supported
/// - 0 or more decimal digits, with leading zeros allowed [1]
/// - A decimal point '.', which can have no digits after it
/// - 0 or more decimal digits, unless the first digits [1] doesn't have any digits,
/// then this must have at least one
/// - An exponent 'e' or 'E' followed by an optional sign '+' or '-' and at least one digit
/// This function additionally detects out of range values which have been rounded to
/// [-]infinity or 0 and gives the next character to read after the floating point.
template<FloatingPoint T = double>
FloatingPointParseResults<T> parse_first_floating_point(char const* start, char const* end);
/// This function finds the first floating point starting at start up to the first '\0'.
/// The format is identical to parse_first_floating_point above.
template<FloatingPoint T = double>
FloatingPointParseResults<T> parse_first_floating_point_until_zero_character(char const* start);
/// This function will return either a floating point, or an empty optional if the given StringView
/// does not a floating point or contains more characters beyond the floating point. For the format
/// check the comment on parse_first_floating_point.
template<FloatingPoint T = double>
Optional<T> parse_floating_point_completely(char const* start, char const* end);
/// This function finds the first floating point as a hex float within [start, end).
/// The accepted format is intentionally as lenient as possible. If your format is
/// stricter you must validate it first. The format accepts:
/// - An optional sign, both + and - are supported
/// - Optionally either 0x or OX
/// - 0 or more hexadecimal digits, with leading zeros allowed [1]
/// - A decimal point '.', which can have no digits after it
/// - 0 or more hexadecimal digits, unless the first digits [1] doesn't have any digits,
/// then this must have at least one
/// - An exponent 'p' or 'P' followed by an optional sign '+' or '-' and at least one decimal digit
/// NOTE: The exponent is _not_ hexadecimal and gives powers of 2 not 16.
/// This function additionally detects out of range values which have been rounded to
/// [-]infinity or 0 and gives the next character to read after the floating point.
template<FloatingPoint T = double>
FloatingPointParseResults<T> parse_first_hexfloat_until_zero_character(char const* start);
}
#if USING_AK_GLOBALLY
using AK::parse_first_floating_point;
using AK::parse_first_hexfloat_until_zero_character;
using AK::parse_floating_point_completely;
#endif

View File

@ -40,8 +40,8 @@ public:
String to_string() const;
[[nodiscard]] Utf8View code_points() const;
[[nodiscard]] ReadonlyBytes bytes() const { return m_data.bytes(); }
[[nodiscard]] StringView bytes_as_string_view() const { return m_data.bytes(); }
[[nodiscard]] ReadonlyBytes bytes() const LIFETIME_BOUND { return m_data.bytes(); }
[[nodiscard]] StringView bytes_as_string_view() const LIFETIME_BOUND { return m_data.bytes(); }
[[nodiscard]] ALWAYS_INLINE bool operator==(FlyString const& other) const { return m_data.raw(Badge<FlyString> {}) == other.m_data.raw(Badge<FlyString> {}); }
[[nodiscard]] bool operator==(String const& other) const { return m_data == other; }
@ -65,6 +65,7 @@ public:
[[nodiscard]] FlyString to_ascii_lowercase() const;
[[nodiscard]] FlyString to_ascii_uppercase() const;
[[nodiscard]] bool is_ascii() const { return bytes_as_string_view().is_ascii(); }
[[nodiscard]] bool starts_with_bytes(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
@ -100,8 +101,6 @@ private:
constexpr bool is_invalid() const { return m_data.raw(Badge<FlyString> {}) == 0; }
};
void did_destroy_fly_string_data(Badge<Detail::StringData>, Detail::StringData const&);
template<>
class Optional<FlyString> : public OptionalBase<FlyString> {
template<typename U>
@ -201,6 +200,7 @@ private:
template<>
struct Traits<FlyString> : public DefaultTraits<FlyString> {
static unsigned hash(FlyString const&);
static constexpr bool may_have_slow_equality_check() { return false; }
};
template<>

View File

@ -494,22 +494,6 @@ ErrorOr<void> FormatBuilder::put_f64_with_precision(
StringBuilder string_builder;
FormatBuilder format_builder { string_builder };
if (isnan(value) || isinf(value)) [[unlikely]] {
if (value < 0.0)
TRY(string_builder.try_append('-'));
else if (sign_mode == SignMode::Always)
TRY(string_builder.try_append('+'));
else if (sign_mode == SignMode::Reserved)
TRY(string_builder.try_append(' '));
if (isnan(value))
TRY(string_builder.try_append(upper_case ? "NAN"sv : "nan"sv));
else
TRY(string_builder.try_append(upper_case ? "INF"sv : "inf"sv));
TRY(put_string(string_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill));
return {};
}
bool is_negative = value < 0.0;
if (is_negative)
value = -value;
@ -584,32 +568,26 @@ ErrorOr<void> FormatBuilder::put_f32_or_f64(
SignMode sign_mode,
RealNumberDisplayMode display_mode)
{
if (precision.has_value() || base != 10)
return put_f64_with_precision(value, base, upper_case, zero_pad, use_separator, align, min_width, precision.value_or(6), fill, sign_mode, display_mode);
// No precision specified, so pick the best precision with roundtrip guarantees.
StringBuilder builder;
// Special cases: NaN, inf, -inf, 0 and -0.
auto const is_nan = isnan(value);
auto const is_inf = isinf(value);
auto const is_zero = value == static_cast<T>(0.0) || value == static_cast<T>(-0.0);
if (is_nan || is_inf || is_zero) {
if (is_nan || is_inf) {
StringBuilder special_case_builder;
if (value < 0)
TRY(builder.try_append('-'));
TRY(special_case_builder.try_append('-'));
else if (sign_mode == SignMode::Always)
TRY(builder.try_append('+'));
TRY(special_case_builder.try_append('+'));
else if (sign_mode == SignMode::Reserved)
TRY(builder.try_append(' '));
TRY(special_case_builder.try_append(' '));
if (is_nan)
TRY(builder.try_append(upper_case ? "NAN"sv : "nan"sv));
TRY(special_case_builder.try_append(upper_case ? "NAN"sv : "nan"sv));
else if (is_inf)
TRY(builder.try_append(upper_case ? "INF"sv : "inf"sv));
else
TRY(builder.try_append('0'));
TRY(special_case_builder.try_append(upper_case ? "INF"sv : "inf"sv));
return put_string(builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill);
return put_string(special_case_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill);
}
auto const [sign, mantissa, exponent] = convert_floating_point_to_decimal_exponential_form(value);
@ -626,6 +604,68 @@ ErrorOr<void> FormatBuilder::put_f32_or_f64(
Array<u8, 20> mantissa_digits;
auto mantissa_length = convert_to_decimal_digits_array(mantissa, mantissa_digits);
auto const n = exponent + static_cast<i32>(mantissa_length);
auto mantissa_text = StringView { mantissa_digits.span().slice(0, mantissa_length) };
// NOTE: Range from ECMA262, seems like an okay default.
if (n < -5 || n > 21) {
StringBuilder scientific_notation_builder;
if (sign)
TRY(scientific_notation_builder.try_append('-'));
else if (sign_mode == SignMode::Always)
TRY(scientific_notation_builder.try_append('+'));
else if (sign_mode == SignMode::Reserved)
TRY(scientific_notation_builder.try_append(' '));
auto const exponent_sign = n < 0 ? '-' : '+';
Array<u8, 5> exponent_digits;
auto const exponent_length = convert_to_decimal_digits_array(abs(n - 1), exponent_digits);
auto const exponent_text = StringView { exponent_digits.span().slice(0, exponent_length) };
if (precision.has_value())
mantissa_text = mantissa_text.substring_view(0, min(*precision + 1, mantissa_text.length())).trim("0"sv, TrimMode::Right);
if (mantissa_text.length() == 1) {
// <mantissa>e<exponent>
TRY(scientific_notation_builder.try_append(mantissa_text));
TRY(scientific_notation_builder.try_append('e'));
TRY(scientific_notation_builder.try_append(exponent_sign));
TRY(scientific_notation_builder.try_append(exponent_text));
} else {
// <mantissa>.<mantissa[1..]>e<exponent>
TRY(scientific_notation_builder.try_append(mantissa_text.substring_view(0, 1)));
TRY(scientific_notation_builder.try_append('.'));
TRY(scientific_notation_builder.try_append(mantissa_text.substring_view(1)));
TRY(scientific_notation_builder.try_append('e'));
TRY(scientific_notation_builder.try_append(exponent_sign));
TRY(scientific_notation_builder.try_append(exponent_text));
}
return put_string(scientific_notation_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill);
}
if (precision.has_value() || base != 10)
return put_f64_with_precision(value, base, upper_case, zero_pad, use_separator, align, min_width, precision.value_or(6), fill, sign_mode, display_mode);
if (value == static_cast<T>(0.0)) {
StringBuilder zero_builder;
if (value < 0)
TRY(zero_builder.try_append('-'));
else if (sign_mode == SignMode::Always)
TRY(zero_builder.try_append('+'));
else if (sign_mode == SignMode::Reserved)
TRY(zero_builder.try_append(' '));
TRY(zero_builder.try_append('0'));
return put_string(zero_builder.string_view(), align, min_width, NumericLimits<size_t>::max(), fill);
}
// No precision specified, so pick the best precision with roundtrip guarantees.
StringBuilder builder;
if (sign)
TRY(builder.try_append('-'));
else if (sign_mode == SignMode::Always)
@ -633,48 +673,22 @@ ErrorOr<void> FormatBuilder::put_f32_or_f64(
else if (sign_mode == SignMode::Reserved)
TRY(builder.try_append(' '));
auto const n = exponent + static_cast<i32>(mantissa_length);
auto const mantissa_text = StringView { mantissa_digits.span().slice(0, mantissa_length) };
size_t integral_part_end = 0;
// NOTE: Range from ECMA262, seems like an okay default.
if (n >= -5 && n <= 21) {
if (exponent >= 0) {
TRY(builder.try_append(mantissa_text));
TRY(builder.try_append_repeated('0', exponent));
integral_part_end = builder.length();
} else if (n > 0) {
TRY(builder.try_append(mantissa_text.substring_view(0, n)));
integral_part_end = builder.length();
TRY(builder.try_append('.'));
TRY(builder.try_append(mantissa_text.substring_view(n)));
} else {
TRY(builder.try_append("0."sv));
TRY(builder.try_append_repeated('0', -n));
TRY(builder.try_append(mantissa_text));
integral_part_end = 1;
}
} else {
auto const exponent_sign = n < 0 ? '-' : '+';
Array<u8, 5> exponent_digits;
auto const exponent_length = convert_to_decimal_digits_array(abs(n - 1), exponent_digits);
auto const exponent_text = StringView { exponent_digits.span().slice(0, exponent_length) };
integral_part_end = 1;
if (mantissa_length == 1) {
// <mantissa>e<exponent>
TRY(builder.try_append(mantissa_text));
TRY(builder.try_append('e'));
TRY(builder.try_append(exponent_sign));
TRY(builder.try_append(exponent_text));
} else {
// <mantissa>.<mantissa[1..]>e<exponent>
TRY(builder.try_append(mantissa_text.substring_view(0, 1)));
TRY(builder.try_append('.'));
TRY(builder.try_append(mantissa_text.substring_view(1)));
TRY(builder.try_append('e'));
TRY(builder.try_append(exponent_sign));
TRY(builder.try_append(exponent_text));
}
if (exponent >= 0) {
TRY(builder.try_append(mantissa_text));
TRY(builder.try_append_repeated('0', exponent));
integral_part_end = builder.length();
} else if (n > 0) {
TRY(builder.try_append(mantissa_text.substring_view(0, n)));
integral_part_end = builder.length();
TRY(builder.try_append('.'));
TRY(builder.try_append(mantissa_text.substring_view(n)));
} else {
TRY(builder.try_append("0."sv));
TRY(builder.try_append_repeated('0', -n));
TRY(builder.try_append(mantissa_text));
integral_part_end = 1;
}
if (use_separator && integral_part_end > 3) {
@ -990,6 +1004,21 @@ ErrorOr<void> Formatter<char>::format(FormatBuilder& builder, char value)
return formatter.format(builder, { &value, 1 });
}
}
ErrorOr<void> Formatter<char16_t>::format(FormatBuilder& builder, char16_t value)
{
if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) {
Formatter<u16> formatter { *this };
return formatter.format(builder, value);
} else {
StringBuilder codepoint;
codepoint.append_code_point(value);
Formatter<StringView> formatter { *this };
return formatter.format(builder, codepoint.string_view());
}
}
ErrorOr<void> Formatter<char32_t>::format(FormatBuilder& builder, char32_t value)
{
if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) {
@ -1003,6 +1032,7 @@ ErrorOr<void> Formatter<char32_t>::format(FormatBuilder& builder, char32_t value
return formatter.format(builder, codepoint.string_view());
}
}
ErrorOr<void> Formatter<bool>::format(FormatBuilder& builder, bool value)
{
if (m_mode == Mode::Binary || m_mode == Mode::BinaryUppercase || m_mode == Mode::Decimal || m_mode == Mode::Octal || m_mode == Mode::Hexadecimal || m_mode == Mode::HexadecimalUppercase) {
@ -1015,6 +1045,7 @@ ErrorOr<void> Formatter<bool>::format(FormatBuilder& builder, bool value)
return formatter.format(builder, value ? "true"sv : "false"sv);
}
}
ErrorOr<void> Formatter<long double>::format(FormatBuilder& builder, long double value)
{
u8 base;
@ -1272,7 +1303,7 @@ void set_rich_debug_enabled(bool value)
static int main_thread_id = GetCurrentThreadId();
static int enable_escape_sequences()
static int initialize_console_settings()
{
HANDLE console_handle = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (console_handle == INVALID_HANDLE_VALUE) {
@ -1288,16 +1319,21 @@ static int enable_escape_sequences()
return 0;
}
// Enable Virtual Terminal Processing to allow ANSI escape codes
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
mode |= ENABLE_PROCESSED_OUTPUT;
if (!SetConsoleMode(console_handle, mode)) {
dbgln("Unable to set console mode");
return 0;
}
// Set the output code page to UTF-8 to support Emoji and other Unicode characters
(void)SetConsoleOutputCP(CP_UTF8);
return 0;
}
static int dummy = enable_escape_sequences();
static int dummy = initialize_console_settings();
#endif

View File

@ -547,8 +547,12 @@ struct Formatter<char> : StandardFormatter {
ErrorOr<void> format(FormatBuilder&, char);
};
template<>
struct Formatter<char16_t> : StandardFormatter {
ErrorOr<void> format(FormatBuilder&, char16_t);
};
template<>
struct Formatter<char32_t> : StandardFormatter {
ErrorOr<void> format(FormatBuilder& builder, char32_t);
ErrorOr<void> format(FormatBuilder&, char32_t);
};
template<>
struct Formatter<bool> : StandardFormatter {
@ -603,6 +607,16 @@ struct Formatter<nullptr_t> : Formatter<FlatPtr> {
}
};
template<typename T>
struct Formatter<Checked<T>> : Formatter<T> {
ErrorOr<void> format(FormatBuilder& builder, Checked<T> value)
{
if (value.has_overflow())
return builder.put_string("{ OVERFLOW }"sv);
return Formatter<T>::format(builder, value.value());
}
};
ErrorOr<void> vformat(StringBuilder&, StringView fmtstr, TypeErasedFormatParams&);
void vout(FILE*, StringView fmtstr, TypeErasedFormatParams&, bool newline = false);
@ -701,6 +715,17 @@ void set_log_tag_name(char const*);
warnln(fmt, ##__VA_ARGS__); \
} while (0)
#define dbgln_if(flag, fmt, ...) \
do { \
if constexpr (flag) \
dbgln(fmt, ##__VA_ARGS__); \
} while (0)
#define dbgln_dump(expr) \
do { \
dbgln(#expr ": {}", (expr)); \
} while (0)
void vdbg(StringView fmtstr, TypeErasedFormatParams&, bool newline = false);
template<typename... Parameters>
@ -828,11 +853,4 @@ using AK::dbgln;
using AK::CheckedFormatString;
using AK::FormatIfSupported;
using AK::FormatString;
# define dbgln_if(flag, fmt, ...) \
do { \
if constexpr (flag) \
dbgln(fmt, ##__VA_ARGS__); \
} while (0)
#endif

View File

@ -18,7 +18,11 @@ namespace Detail {
template<size_t inline_capacity>
class ByteBuffer;
template<typename CharType>
class GenericLexer;
class StringData;
class Utf16StringData;
}
@ -35,7 +39,6 @@ class CountingStream;
class Duration;
class Error;
class FlyString;
class GenericLexer;
class IPv4Address;
class IPv6Address;
class JsonArray;
@ -52,6 +55,8 @@ class String;
class StringBuilder;
class StringView;
class UnixDateTime;
class Utf16FlyString;
class Utf16String;
class Utf16View;
class Utf32CodePointIterator;
class Utf32View;
@ -60,6 +65,9 @@ class Utf8View;
using ByteBuffer = Detail::ByteBuffer<32>;
using GenericLexer = Detail::GenericLexer<char>;
using Utf16GenericLexer = Detail::GenericLexer<char16_t>;
template<typename T>
class Span;
@ -81,7 +89,7 @@ class Atomic;
template<typename T, typename TSizeCalculationPolicy = DefaultSizeCalculationPolicy>
class SinglyLinkedList;
template<typename T>
template<typename T, size_t node_cache_size = 0>
class DoublyLinkedList;
template<typename T, size_t capacity>
@ -141,7 +149,11 @@ class OwnPtr;
template<typename T>
class WeakPtr;
template<typename T, size_t inline_capacity = 0>
enum class FastLastAccess : u8 {
No,
Yes,
};
template<typename T, size_t inline_capacity = 0, FastLastAccess = FastLastAccess::No>
requires(!IsRvalueReference<T>) class Vector;
template<typename T, typename ErrorType = Error>
@ -166,6 +178,7 @@ using AK::CountingStream;
using AK::DoublyLinkedList;
using AK::Error;
using AK::ErrorOr;
using AK::FastLastAccess;
using AK::FixedArray;
using AK::FlyString;
using AK::Function;
@ -198,6 +211,9 @@ using AK::StringView;
using AK::TrailingCodePointTransformation;
using AK::Traits;
using AK::UnixDateTime;
using AK::Utf16FlyString;
using AK::Utf16GenericLexer;
using AK::Utf16String;
using AK::Utf16View;
using AK::Utf32CodePointIterator;
using AK::Utf32View;

View File

@ -100,7 +100,7 @@ public:
clear(false);
}
[[nodiscard]] ReadonlyBytes raw_capture_range() const
[[nodiscard]] ReadonlyBytes raw_capture_range() const LIFETIME_BOUND
{
if (!m_size)
return {};

View File

@ -4,162 +4,10 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Assertions.h>
#include <AK/ByteString.h>
#include <AK/CharacterTypes.h>
#include <AK/GenericLexer.h>
#include <AK/ScopeGuard.h>
#include <AK/StringBuilder.h>
#include <AK/Utf16View.h>
namespace AK {
// Consume a number of characters
StringView GenericLexer::consume(size_t count)
{
size_t start = m_index;
size_t length = min(count, m_input.length() - m_index);
m_index += length;
return m_input.substring_view(start, length);
}
// Consume the rest of the input
StringView GenericLexer::consume_all()
{
auto rest = m_input.substring_view(m_index, m_input.length() - m_index);
m_index = m_input.length();
return rest;
}
// Consume until a new line is found
StringView GenericLexer::consume_line()
{
size_t start = m_index;
while (!is_eof() && peek() != '\r' && peek() != '\n')
m_index++;
size_t length = m_index - start;
consume_specific('\r');
consume_specific('\n');
return m_input.substring_view(start, length);
}
// Consume and return characters until `stop` is peek'd
StringView GenericLexer::consume_until(char stop)
{
size_t start = m_index;
while (!is_eof() && peek() != stop)
m_index++;
size_t length = m_index - start;
return m_input.substring_view(start, length);
}
// Consume and return characters until the string `stop` is found
StringView GenericLexer::consume_until(char const* stop)
{
size_t start = m_index;
while (!is_eof() && !next_is(stop))
m_index++;
size_t length = m_index - start;
return m_input.substring_view(start, length);
}
// Consume and return characters until the string `stop` is found
StringView GenericLexer::consume_until(StringView stop)
{
size_t start = m_index;
while (!is_eof() && !next_is(stop))
m_index++;
size_t length = m_index - start;
return m_input.substring_view(start, length);
}
/*
* Consume a string surrounded by single or double quotes. The returned
* StringView does not include the quotes. An escape character can be provided
* to capture the enclosing quotes. Please note that the escape character will
* still be in the resulting StringView
*/
StringView GenericLexer::consume_quoted_string(char escape_char)
{
if (!next_is(is_quote))
return {};
char quote_char = consume();
size_t start = m_index;
while (!is_eof()) {
if (next_is(escape_char))
m_index++;
else if (next_is(quote_char))
break;
m_index++;
}
size_t length = m_index - start;
if (peek() != quote_char) {
// Restore the index in case the string is unterminated
m_index = start - 1;
return {};
}
// Ignore closing quote
ignore();
return m_input.substring_view(start, length);
}
template<Integral T>
ErrorOr<T> GenericLexer::consume_decimal_integer()
{
using UnsignedT = MakeUnsigned<T>;
ArmedScopeGuard rollback { [&, rollback_position = m_index] {
m_index = rollback_position;
} };
bool has_minus_sign = false;
if (next_is('+') || next_is('-'))
if (consume() == '-')
has_minus_sign = true;
StringView number_view = consume_while(is_ascii_digit);
if (number_view.is_empty())
return Error::from_errno(EINVAL);
auto maybe_number = StringUtils::convert_to_uint<UnsignedT>(number_view, TrimWhitespace::No);
if (!maybe_number.has_value())
return Error::from_errno(ERANGE);
auto number = maybe_number.value();
if (!has_minus_sign) {
if (NumericLimits<T>::max() < number) // This is only possible in a signed case.
return Error::from_errno(ERANGE);
rollback.disarm();
return number;
} else {
if constexpr (IsUnsigned<T>) {
if (number == 0) {
rollback.disarm();
return 0;
}
return Error::from_errno(ERANGE);
} else {
static constexpr UnsignedT max_value = static_cast<UnsignedT>(NumericLimits<T>::max()) + 1;
if (number > max_value)
return Error::from_errno(ERANGE);
rollback.disarm();
return -number;
}
}
}
LineTrackingLexer::Position LineTrackingLexer::position_for(size_t index) const
{
// Sad case: we have no idea where the nearest newline is, so we have to
@ -168,8 +16,8 @@ LineTrackingLexer::Position LineTrackingLexer::position_for(size_t index) const
auto next_newline = m_input.find('\n', m_largest_known_line_start_position);
if (!next_newline.has_value()) {
// No more newlines, add the end of the input as a line start to avoid searching again.
m_line_start_positions->insert(m_input.length(), m_line_start_positions->size());
m_largest_known_line_start_position = m_input.length();
m_line_start_positions->insert(input_length(), m_line_start_positions->size());
m_largest_known_line_start_position = input_length();
break;
}
m_line_start_positions->insert(next_newline.value() + 1, m_line_start_positions->size());
@ -190,95 +38,4 @@ LineTrackingLexer::Position LineTrackingLexer::position_for(size_t index) const
return { index, line, column };
}
template ErrorOr<u8> GenericLexer::consume_decimal_integer<u8>();
template ErrorOr<i8> GenericLexer::consume_decimal_integer<i8>();
template ErrorOr<u16> GenericLexer::consume_decimal_integer<u16>();
template ErrorOr<i16> GenericLexer::consume_decimal_integer<i16>();
template ErrorOr<u32> GenericLexer::consume_decimal_integer<u32>();
template ErrorOr<i32> GenericLexer::consume_decimal_integer<i32>();
template ErrorOr<u64> GenericLexer::consume_decimal_integer<u64>();
template ErrorOr<i64> GenericLexer::consume_decimal_integer<i64>();
Optional<ByteString> GenericLexer::consume_and_unescape_string(char escape_char)
{
auto view = consume_quoted_string(escape_char);
if (view.is_null())
return {};
StringBuilder builder;
for (size_t i = 0; i < view.length(); ++i)
builder.append(consume_escaped_character(escape_char));
return builder.to_byte_string();
}
auto GenericLexer::consume_escaped_code_point(bool combine_surrogate_pairs) -> Result<u32, UnicodeEscapeError>
{
if (!consume_specific("\\u"sv))
return UnicodeEscapeError::MalformedUnicodeEscape;
if (next_is('{'))
return decode_code_point();
return decode_single_or_paired_surrogate(combine_surrogate_pairs);
}
auto GenericLexer::decode_code_point() -> Result<u32, UnicodeEscapeError>
{
bool starts_with_open_bracket = consume_specific('{');
VERIFY(starts_with_open_bracket);
u32 code_point = 0;
while (true) {
if (!next_is(is_ascii_hex_digit))
return UnicodeEscapeError::MalformedUnicodeEscape;
auto new_code_point = (code_point << 4u) | parse_ascii_hex_digit(consume());
if (new_code_point < code_point)
return UnicodeEscapeError::UnicodeEscapeOverflow;
code_point = new_code_point;
if (consume_specific('}'))
break;
}
if (is_unicode(code_point))
return code_point;
return UnicodeEscapeError::UnicodeEscapeOverflow;
}
auto GenericLexer::decode_single_or_paired_surrogate(bool combine_surrogate_pairs) -> Result<u32, UnicodeEscapeError>
{
constexpr size_t surrogate_length = 4;
auto decode_one_surrogate = [&]() -> Optional<u16> {
u16 surrogate = 0;
for (size_t i = 0; i < surrogate_length; ++i) {
if (!next_is(is_ascii_hex_digit))
return {};
surrogate = (surrogate << 4u) | parse_ascii_hex_digit(consume());
}
return surrogate;
};
auto high_surrogate = decode_one_surrogate();
if (!high_surrogate.has_value())
return UnicodeEscapeError::MalformedUnicodeEscape;
if (!Utf16View::is_high_surrogate(*high_surrogate))
return *high_surrogate;
if (!combine_surrogate_pairs || !consume_specific("\\u"sv))
return *high_surrogate;
auto low_surrogate = decode_one_surrogate();
if (!low_surrogate.has_value())
return UnicodeEscapeError::MalformedUnicodeEscape;
if (Utf16View::is_low_surrogate(*low_surrogate))
return Utf16View::decode_surrogate_pair(*high_surrogate, *low_surrogate);
retreat(6);
return *high_surrogate;
}
}

View File

@ -6,60 +6,96 @@
#pragma once
#include <AK/Assertions.h>
#include <AK/Forward.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/RedBlackTree.h>
#include <AK/Result.h>
#include <AK/String.h>
#include <AK/ScopeGuard.h>
#include <AK/StringView.h>
#include <AK/Utf16View.h>
namespace AK {
constexpr auto is_any_of(StringView values)
{
return [values](auto c) { return values.contains(c); };
}
constexpr auto is_not_any_of(StringView values)
{
return [values](auto c) { return !values.contains(c); };
}
constexpr auto is_path_separator = is_any_of("/\\"sv);
constexpr auto is_quote = is_any_of("'\""sv);
enum class UnicodeEscapeError {
MalformedUnicodeEscape,
UnicodeEscapeOverflow,
};
namespace Detail {
template<typename CharType>
class GenericLexer {
static_assert(IsOneOf<CharType, char, char16_t>);
public:
constexpr explicit GenericLexer(StringView input)
using ViewType = Detail::Conditional<IsSame<CharType, char>, StringView, Utf16View>;
constexpr explicit GenericLexer(ViewType input)
: m_input(input)
{
}
constexpr size_t tell() const { return m_index; }
constexpr size_t tell_remaining() const { return m_input.length() - m_index; }
constexpr size_t tell_remaining() const { return input_length() - m_index; }
StringView remaining() const { return m_input.substring_view(m_index); }
StringView input() const { return m_input; }
constexpr ViewType remaining() const { return m_input.substring_view(m_index); }
constexpr ViewType input() const { return m_input; }
constexpr bool is_eof() const { return m_index >= m_input.length(); }
constexpr bool is_eof() const { return m_index >= input_length(); }
constexpr char peek(size_t offset = 0) const
constexpr CharType peek(size_t offset = 0) const
{
return (m_index + offset < m_input.length()) ? m_input[m_index + offset] : '\0';
return (m_index + offset < input_length()) ? code_unit_at(m_index + offset) : '\0';
}
Optional<StringView> peek_string(size_t length, size_t offset = 0) const
constexpr Optional<ViewType> peek_string(size_t length, size_t offset = 0) const
{
if (m_index + offset + length > m_input.length())
if (m_index + offset + length > input_length())
return {};
return m_input.substring_view(m_index + offset, length);
}
constexpr bool next_is(char expected) const
constexpr bool next_is(CharType expected) const
{
return peek() == expected;
}
constexpr bool next_is(StringView expected) const
constexpr bool next_is(char expected) const
requires(IsSame<CharType, char16_t>)
{
for (size_t i = 0; i < expected.length(); ++i)
if (peek(i) != expected[i])
return false;
return true;
return peek() == expected;
}
constexpr bool next_is(char const* expected) const
constexpr bool next_is(ViewType expected) const
{
for (size_t i = 0; expected[i] != '\0'; ++i)
if (peek(i) != expected[i])
return false;
return true;
size_t length = 0;
if constexpr (IsSame<CharType, char16_t>)
length = expected.length_in_code_units();
else
length = expected.length();
return peek_string(length) == expected;
}
constexpr bool next_is(StringView expected) const
requires(IsSame<CharType, char16_t>)
{
return peek_string(expected.length()) == expected;
}
constexpr void retreat()
@ -74,39 +110,51 @@ public:
m_index -= count;
}
constexpr char consume()
constexpr CharType consume()
{
VERIFY(!is_eof());
return m_input[m_index++];
return code_unit_at(m_index++);
}
template<typename T>
constexpr bool consume_specific(T const& next)
constexpr bool consume_specific(CharType next)
{
if (!next_is(next))
return false;
if constexpr (requires { next.length(); }) {
ignore(next.length());
} else {
ignore(sizeof(next));
}
ignore();
return true;
}
bool consume_specific(ByteString next) = delete;
bool consume_specific(String const& next)
constexpr bool consume_specific(char next)
requires(IsSame<CharType, char16_t>)
{
return consume_specific(next.bytes_as_string_view());
return consume_specific(static_cast<char16_t>(next));
}
constexpr bool consume_specific(char const* next)
constexpr bool consume_specific(ViewType next)
{
return consume_specific(StringView { next, __builtin_strlen(next) });
if (!next_is(next))
return false;
if constexpr (IsSame<CharType, char16_t>)
ignore(next.length_in_code_units());
else
ignore(next.length());
return true;
}
constexpr char consume_escaped_character(char escape_char = '\\', StringView escape_map = "n\nr\rt\tb\bf\f"sv)
constexpr bool consume_specific(StringView next)
requires(IsSame<CharType, char16_t>)
{
if (!next_is(next))
return false;
ignore(next.length());
return true;
}
constexpr CharType consume_escaped_character(CharType escape_char = '\\', StringView escape_map = "n\nr\rt\tb\bf\f"sv)
{
if (!consume_specific(escape_char))
return consume();
@ -121,52 +169,180 @@ public:
return c;
}
StringView consume(size_t count);
StringView consume_all();
StringView consume_line();
StringView consume_until(char);
StringView consume_until(char const*);
StringView consume_until(StringView);
StringView consume_quoted_string(char escape_char = 0);
Optional<ByteString> consume_and_unescape_string(char escape_char = '\\');
// Consume a number of characters
constexpr ViewType consume(size_t count)
{
auto start = m_index;
auto length = min(count, input_length() - m_index);
m_index += length;
return m_input.substring_view(start, length);
}
// Consume the rest of the input
constexpr ViewType consume_all()
{
auto rest = m_input.substring_view(m_index, input_length() - m_index);
m_index = input_length();
return rest;
}
// Consume until a new line is found
constexpr ViewType consume_line()
{
auto start = m_index;
while (!is_eof() && peek() != '\r' && peek() != '\n')
m_index++;
auto length = m_index - start;
consume_specific('\r');
consume_specific('\n');
return m_input.substring_view(start, length);
}
// Consume and return characters until `stop` is peeked
constexpr ViewType consume_until(CharType stop)
{
auto start = m_index;
while (!is_eof() && peek() != stop)
m_index++;
auto length = m_index - start;
return m_input.substring_view(start, length);
}
constexpr ViewType consume_until(char stop)
requires(IsSame<CharType, char16_t>)
{
return consume_until(static_cast<char16_t>(stop));
}
// Consume and return characters until the string `stop` is found
constexpr ViewType consume_until(ViewType stop)
{
auto start = m_index;
while (!is_eof() && !next_is(stop))
m_index++;
auto length = m_index - start;
return m_input.substring_view(start, length);
}
// Consume a string surrounded by single or double quotes. The returned ViewType does not include the quotes. An
// escape character can be provided to capture the enclosing quotes. Please note that the escape character will
// still be in the resulting ViewType.
constexpr ViewType consume_quoted_string(CharType escape_char = 0)
{
if (!next_is(is_quote))
return {};
auto quote_char = consume();
auto start = m_index;
while (!is_eof()) {
if (next_is(escape_char))
m_index++;
else if (next_is(quote_char))
break;
m_index++;
}
auto length = m_index - start;
if (peek() != quote_char) {
// Restore the index in case the string is unterminated
m_index = start - 1;
return {};
}
// Ignore closing quote
ignore();
return m_input.substring_view(start, length);
}
template<Integral T>
ErrorOr<T> consume_decimal_integer();
ErrorOr<T> consume_decimal_integer()
{
using UnsignedT = MakeUnsigned<T>;
enum class UnicodeEscapeError {
MalformedUnicodeEscape,
UnicodeEscapeOverflow,
};
ArmedScopeGuard rollback { [&, rollback_position = m_index]() {
m_index = rollback_position;
} };
Result<u32, UnicodeEscapeError> consume_escaped_code_point(bool combine_surrogate_pairs = true);
bool has_minus_sign = false;
if (next_is('+') || next_is('-'))
if (consume() == '-')
has_minus_sign = true;
auto number_view = consume_while(is_ascii_digit);
if (number_view.is_empty())
return Error::from_errno(EINVAL);
auto maybe_number = number_view.template to_number<UnsignedT>(TrimWhitespace::No);
if (!maybe_number.has_value())
return Error::from_errno(ERANGE);
auto number = maybe_number.value();
if (!has_minus_sign) {
if (NumericLimits<T>::max() < number) // This is only possible in a signed case.
return Error::from_errno(ERANGE);
rollback.disarm();
return number;
}
if constexpr (IsUnsigned<T>) {
if (number != 0)
return Error::from_errno(ERANGE);
rollback.disarm();
return 0;
} else {
static constexpr UnsignedT max_value = static_cast<UnsignedT>(NumericLimits<T>::max()) + 1;
if (number > max_value)
return Error::from_errno(ERANGE);
rollback.disarm();
return -number;
}
}
Result<u32, UnicodeEscapeError> consume_escaped_code_point(bool combine_surrogate_pairs = true)
{
if (!consume_specific("\\u"sv))
return UnicodeEscapeError::MalformedUnicodeEscape;
if (next_is('{'))
return decode_code_point();
return decode_single_or_paired_surrogate(combine_surrogate_pairs);
}
constexpr void ignore(size_t count = 1)
{
count = min(count, m_input.length() - m_index);
count = min(count, input_length() - m_index);
m_index += count;
}
constexpr void ignore_until(CharType stop)
{
while (!is_eof() && peek() != stop)
++m_index;
}
constexpr void ignore_until(char stop)
requires(IsSame<CharType, char16_t>)
{
while (!is_eof() && peek() != stop) {
++m_index;
}
return ignore_until(static_cast<char16_t>(stop));
}
constexpr void ignore_until(char const* stop)
{
while (!is_eof() && !next_is(stop)) {
++m_index;
}
}
/*
* Conditions are used to match arbitrary characters. You can use lambdas,
* ctype functions, or is_any_of() and its derivatives (see below).
* A few examples:
* - `if (lexer.next_is(isdigit))`
* - `auto name = lexer.consume_while([](char c) { return isalnum(c) || c == '_'; });`
* - `lexer.ignore_until(is_any_of("<^>"));`
*/
// Conditions are used to match arbitrary characters. You can use lambdas, ctype functions, or is_any_of() and its
// derivatives (see below).
//
// A few examples:
// - `if (lexer.next_is(isdigit))`
// - `auto name = lexer.consume_while([](char c) { return isalnum(c) || c == '_'; });`
// - `lexer.ignore_until(is_any_of("<^>"));`
// Test the next character against a Condition
template<typename TPredicate>
@ -177,28 +353,38 @@ public:
// Consume and return characters while `pred` returns true
template<typename TPredicate>
StringView consume_while(TPredicate pred)
constexpr ViewType consume_while(TPredicate pred)
{
size_t start = m_index;
auto start = m_index;
while (!is_eof() && pred(peek()))
++m_index;
size_t length = m_index - start;
auto length = m_index - start;
return m_input.substring_view(start, length);
}
// Consume and return characters until `pred` return true
template<typename TPredicate>
StringView consume_until(TPredicate pred)
constexpr ViewType consume_until(TPredicate pred)
{
size_t start = m_index;
auto start = m_index;
while (!is_eof() && !pred(peek()))
++m_index;
size_t length = m_index - start;
auto length = m_index - start;
return m_input.substring_view(start, length);
}
template<typename TPredicate>
constexpr bool consume_specific_with_predicate(TPredicate pred)
{
if (is_eof() || !pred(peek()))
return false;
ignore();
return true;
}
// Ignore characters while `pred` returns true
template<typename TPredicate>
constexpr void ignore_while(TPredicate pred)
@ -216,13 +402,88 @@ public:
}
protected:
Result<u32, UnicodeEscapeError> decode_code_point();
Result<u32, UnicodeEscapeError> decode_single_or_paired_surrogate(bool combine_surrogate_pairs = true);
Result<u32, UnicodeEscapeError> decode_code_point()
{
bool starts_with_open_bracket = consume_specific('{');
VERIFY(starts_with_open_bracket);
StringView m_input;
u32 code_point = 0;
while (true) {
if (!next_is(is_ascii_hex_digit))
return UnicodeEscapeError::MalformedUnicodeEscape;
auto new_code_point = (code_point << 4u) | parse_ascii_hex_digit(consume());
if (new_code_point < code_point)
return UnicodeEscapeError::UnicodeEscapeOverflow;
code_point = new_code_point;
if (consume_specific('}'))
break;
}
if (is_unicode(code_point))
return code_point;
return UnicodeEscapeError::UnicodeEscapeOverflow;
}
Result<u32, UnicodeEscapeError> decode_single_or_paired_surrogate(bool combine_surrogate_pairs = true)
{
constexpr size_t surrogate_length = 4;
auto decode_one_surrogate = [&]() -> Optional<u16> {
u16 surrogate = 0;
for (size_t i = 0; i < surrogate_length; ++i) {
if (!next_is(is_ascii_hex_digit))
return {};
surrogate = (surrogate << 4u) | parse_ascii_hex_digit(consume());
}
return surrogate;
};
auto high_surrogate = decode_one_surrogate();
if (!high_surrogate.has_value())
return UnicodeEscapeError::MalformedUnicodeEscape;
if (!UnicodeUtils::is_utf16_high_surrogate(*high_surrogate))
return *high_surrogate;
if (!combine_surrogate_pairs || !consume_specific("\\u"sv))
return *high_surrogate;
auto low_surrogate = decode_one_surrogate();
if (!low_surrogate.has_value())
return UnicodeEscapeError::MalformedUnicodeEscape;
if (UnicodeUtils::is_utf16_low_surrogate(*low_surrogate))
return UnicodeUtils::decode_utf16_surrogate_pair(*high_surrogate, *low_surrogate);
retreat(6);
return *high_surrogate;
}
constexpr size_t input_length() const
{
if constexpr (IsSame<CharType, char16_t>)
return m_input.length_in_code_units();
else
return m_input.length();
}
constexpr CharType code_unit_at(size_t index) const
{
if constexpr (IsSame<CharType, char16_t>)
return m_input.code_unit_at(index);
else
return m_input[index];
}
ViewType m_input;
size_t m_index { 0 };
};
}
class LineTrackingLexer : public GenericLexer {
public:
struct Position {
@ -256,19 +517,6 @@ protected:
mutable size_t m_largest_known_line_start_position { 0 };
};
constexpr auto is_any_of(StringView values)
{
return [values](auto c) { return values.contains(c); };
}
constexpr auto is_not_any_of(StringView values)
{
return [values](auto c) { return !values.contains(c); };
}
constexpr auto is_path_separator = is_any_of("/\\"sv);
constexpr auto is_quote = is_any_of("'\""sv);
}
#if USING_AK_GLOBALLY

View File

@ -26,6 +26,7 @@ private:
};
struct EntryTraits {
static constexpr bool may_have_slow_equality_check() { return KeyTraits::may_have_slow_equality_check(); }
static unsigned hash(Entry const& entry) { return KeyTraits::hash(entry.key); }
static bool equals(Entry const& a, Entry const& b) { return KeyTraits::equals(a.key, b.key); }
};
@ -64,6 +65,12 @@ public:
ErrorOr<HashSetResult> try_set(K const& key, V&& value, HashSetExistingEntryBehavior existing_entry_behavior = HashSetExistingEntryBehavior::Replace) { return m_table.try_set({ key, move(value) }, existing_entry_behavior); }
ErrorOr<HashSetResult> try_set(K&& key, V&& value, HashSetExistingEntryBehavior existing_entry_behavior = HashSetExistingEntryBehavior::Replace) { return m_table.try_set({ move(key), move(value) }, existing_entry_behavior); }
void update(HashMap const& other)
{
for (auto const& [key, value] : other)
set(key, value);
}
bool remove(K const& key)
{
auto it = find(key);
@ -93,6 +100,14 @@ public:
});
}
template<typename TUnaryPredicate>
Vector<Entry> take_all_matching(TUnaryPredicate const& predicate)
{
return m_table.take_all_matching([&](auto& entry) {
return predicate(entry.key, entry.value);
});
}
using HashTableType = HashTable<Entry, EntryTraits, IsOrdered>;
using IteratorType = typename HashTableType::Iterator;
using ConstIteratorType = typename HashTableType::ConstIterator;
@ -261,14 +276,9 @@ public:
}
template<typename Callback>
V& ensure(K const& key, Callback initialization_callback)
V& ensure(K const& key, Callback initialization_callback, HashSetExistingEntryBehavior existing_entry_behavior = HashSetExistingEntryBehavior::Keep)
{
auto it = find(key);
if (it != end())
return it->value;
auto result = set(key, initialization_callback());
VERIFY(result == HashSetResult::InsertedNewEntry);
return find(key)->value;
return m_table.ensure(KeyTraits::hash(key), [&](auto& entry) { return KeyTraits::equals(entry.key, key); }, [&] -> Entry { return { key, initialization_callback() }; }, existing_entry_behavior).value;
}
template<typename Callback>
@ -316,6 +326,27 @@ public:
return hash_map_clone;
}
bool operator==(HashMap const& other) const
{
if (size() != other.size())
return false;
if (is_empty())
return true;
for (auto const& [key, value] : *this) {
auto it = other.find(key);
if (it == other.end())
return false;
if (!ValueTraits::equals(value, it->value))
return false;
}
return true;
}
bool operator!=(HashMap const& other) const
{
return !(*this == other);
}
private:
HashTableType m_table;
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2023, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -123,8 +123,29 @@ class HashTable {
static constexpr size_t grow_at_load_factor_percent = 80;
static constexpr size_t grow_capacity_increase_percent = 60;
struct StoredHash {
void set([[maybe_unused]] u32 h)
{
if constexpr (TraitsForT::may_have_slow_equality_check()) {
hash = h;
}
}
bool check(u32 h)
{
if constexpr (TraitsForT::may_have_slow_equality_check()) {
// If equality checks may be slow, we always store the hash and compare it first.
return hash == h;
} else {
// If equality checks are fast, we don't store the hash and always return true.
return true;
}
}
u32 hash;
};
struct Bucket {
BucketState state;
StoredHash hash;
alignas(T) u8 storage[sizeof(T)];
T* slot() { return reinterpret_cast<T*>(storage); }
T const* slot() const { return reinterpret_cast<T const*>(storage); }
@ -134,6 +155,7 @@ class HashTable {
OrderedBucket* previous;
OrderedBucket* next;
BucketState state;
StoredHash hash;
alignas(T) u8 storage[sizeof(T)];
T* slot() { return reinterpret_cast<T*>(storage); }
T const* slot() const { return reinterpret_cast<T const*>(storage); }
@ -346,8 +368,8 @@ public:
if (m_capacity == 0)
return;
if constexpr (!IsTriviallyDestructible<T>) {
for (auto* bucket : *this)
bucket->~T();
for (auto& bucket : *this)
bucket.~T();
}
__builtin_memset(m_buckets, 0, size_in_bytes(m_capacity));
m_size = 0;
@ -370,6 +392,34 @@ public:
return MUST(try_set(forward<U>(value), existing_entry_behavior));
}
template<typename U = T>
T& ensure(U&& value, HashSetExistingEntryBehavior existing_entry_behavior = HashSetExistingEntryBehavior::Replace)
{
return MUST(try_set(forward<U>(value), existing_entry_behavior));
}
template<typename TUnaryPredicate, typename InitializationCallback>
[[nodiscard]] T& ensure(unsigned hash, TUnaryPredicate predicate, InitializationCallback initialization_callback, HashSetExistingEntryBehavior existing_entry_behavior)
{
if (should_grow())
rehash(m_capacity * (100 + grow_capacity_increase_percent) / 100);
auto [result, bucket] = lookup_for_writing<T>(hash, move(predicate), existing_entry_behavior);
switch (result) {
case HashSetResult::InsertedNewEntry:
new (bucket.slot()) T(initialization_callback());
break;
case HashSetResult::ReplacedExistingEntry:
(*bucket.slot()) = T(initialization_callback());
break;
case HashSetResult::KeptExistingEntry:
break;
default:
__builtin_unreachable();
}
return *bucket.slot();
}
template<typename TUnaryPredicate>
[[nodiscard]] Iterator find(unsigned hash, TUnaryPredicate predicate)
{
@ -478,6 +528,25 @@ public:
return has_removed_anything;
}
template<typename TUnaryPredicate>
Vector<T> take_all_matching(TUnaryPredicate const& predicate)
{
Vector<T> values;
for (size_t i = 0; i < m_capacity; ++i) {
auto& bucket = m_buckets[i];
if (bucket.state == BucketState::Free || !predicate(*bucket.slot()))
continue;
values.append(move(*bucket.slot()));
delete_bucket(bucket);
// If a bucket was shifted up, reevaluate this bucket index
if (bucket.state != BucketState::Free)
--i;
}
return values;
}
T take_last()
requires(IsOrdered)
{
@ -564,15 +633,15 @@ private:
if (is_empty())
return nullptr;
hash %= m_capacity;
size_t bucket_index = hash % m_capacity;
for (;;) {
auto* bucket = &m_buckets[hash];
auto* bucket = &m_buckets[bucket_index];
if (bucket->state == BucketState::Free)
return nullptr;
if (predicate(*bucket->slot()))
if (bucket->hash.check(hash) && predicate(*bucket->slot()))
return bucket;
if (++hash == m_capacity) [[unlikely]]
hash = 0;
if (++bucket_index == m_capacity) [[unlikely]]
bucket_index = 0;
}
}
@ -601,8 +670,13 @@ private:
return static_cast<BucketState>(probe_length + 1);
}
template<typename U = T>
HashSetResult write_value(U&& value, HashSetExistingEntryBehavior existing_entry_behavior)
struct LookupForWritingResult {
HashSetResult result;
BucketType& bucket;
};
template<typename U, typename TUnaryPredicate>
LookupForWritingResult lookup_for_writing(u32 const hash, TUnaryPredicate predicate, HashSetExistingEntryBehavior existing_entry_behavior)
{
auto update_collection_for_new_bucket = [&](BucketType& bucket) {
if constexpr (IsOrdered) {
@ -644,27 +718,26 @@ private:
}
};
auto bucket_index = TraitsForT::hash(value) % m_capacity;
auto bucket_index = hash % m_capacity;
size_t probe_length = 0;
for (;;) {
auto* bucket = &m_buckets[bucket_index];
// We found a free bucket, write to it and stop
if (bucket->state == BucketState::Free) {
new (bucket->slot()) T(forward<U>(value));
bucket->state = bucket_state_for_probe_length(probe_length);
bucket->hash.set(hash);
update_collection_for_new_bucket(*bucket);
++m_size;
return HashSetResult::InsertedNewEntry;
return { HashSetResult::InsertedNewEntry, *bucket };
}
// The bucket is already used, does it have an identical value?
if (TraitsForT::equals(*bucket->slot(), static_cast<T const&>(value))) {
if (bucket->hash.check(hash) && predicate(*bucket->slot())) {
if (existing_entry_behavior == HashSetExistingEntryBehavior::Replace) {
(*bucket->slot()) = forward<U>(value);
return HashSetResult::ReplacedExistingEntry;
return { HashSetResult::ReplacedExistingEntry, *bucket };
}
return HashSetResult::KeptExistingEntry;
return { HashSetResult::KeptExistingEntry, *bucket };
}
// Robin hood: if our probe length is larger (poor) than this bucket's (rich), steal its position!
@ -676,8 +749,9 @@ private:
update_collection_for_swapped_buckets(bucket, &bucket_to_move);
// Write new bucket
new (bucket->slot()) T(forward<U>(value));
BucketType* inserted_bucket = bucket;
bucket->state = bucket_state_for_probe_length(probe_length);
bucket->hash.set(hash);
probe_length = target_probe_length;
if constexpr (IsOrdered)
bucket->next = nullptr;
@ -707,7 +781,7 @@ private:
}
}
return HashSetResult::InsertedNewEntry;
return { HashSetResult::InsertedNewEntry, *inserted_bucket };
}
// Try next bucket
@ -717,6 +791,26 @@ private:
}
}
template<typename U = T>
HashSetResult write_value(U&& value, HashSetExistingEntryBehavior existing_entry_behavior)
{
u32 const hash = TraitsForT::hash(value);
auto [result, bucket] = lookup_for_writing<U>(hash, [&](auto& candidate) { return TraitsForT::equals(candidate, static_cast<T const&>(value)); }, existing_entry_behavior);
switch (result) {
case HashSetResult::ReplacedExistingEntry:
(*bucket.slot()) = forward<U>(value);
break;
case HashSetResult::InsertedNewEntry:
new (bucket.slot()) T(forward<U>(value));
break;
case HashSetResult::KeptExistingEntry:
break;
default:
__builtin_unreachable();
}
return result;
}
void delete_bucket(auto& bucket)
{
VERIFY(bucket.state != BucketState::Free);

View File

@ -12,6 +12,7 @@
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/StringConversions.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
@ -140,17 +141,38 @@ public:
auto separator_part = parts[parts.size() - 2].trim_whitespace();
if (separator_part.is_empty())
return false;
auto separator_value = StringUtils::convert_to_uint_from_hex(separator_part);
auto separator_value = AK::parse_hexadecimal_number<u32>(separator_part);
if (!separator_value.has_value() || separator_value.value() != 0xffff)
return false;
// TODO: this allows multiple compression tags "::" in the prefix, which is technically not legal
for (size_t i = 0; i < parts.size() - 2; i++) {
bool found_compressed = false;
for (size_t i = 0; i < parts.size() - 2;) {
auto part = parts[i].trim_whitespace();
if (part.is_empty())
if (part.is_empty()) {
if (found_compressed)
return false;
bool is_leading = (i == 0);
int empty_parts = 1;
for (size_t j = i + 1; j < parts.size() - 2; j++) {
if (!parts[j].trim_whitespace().is_empty())
break;
empty_parts++;
}
if (is_leading) {
if (empty_parts != 2)
return false;
} else if (empty_parts != 1) {
return false;
}
found_compressed = true;
i += empty_parts;
continue;
auto value = StringUtils::convert_to_uint_from_hex(part);
}
auto value = AK::parse_hexadecimal_number<u32>(part);
if (!value.has_value() || value.value() != 0)
return false;
i++;
}
return true;
};
@ -203,7 +225,7 @@ public:
} else {
i++;
}
auto part = StringUtils::convert_to_uint_from_hex(trimmed_part);
auto part = AK::parse_hexadecimal_number<u32>(trimmed_part);
if (!part.has_value() || part.value() > 0xffff)
return {};

View File

@ -5,10 +5,10 @@
*/
#include <AK/CharacterTypes.h>
#include <AK/FloatingPointStringConversions.h>
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
#include <AK/JsonParser.h>
#include <AK/StringConversions.h>
#include <math.h>
namespace AK {
@ -219,18 +219,14 @@ ErrorOr<JsonValue> JsonParser::parse_number()
// use that in the floating point parser.
// The first part should be just ascii digits
StringView view = m_input.substring_view(start_index);
auto view = m_input.substring_view(start_index);
char const* start = view.characters_without_null_termination();
auto parse_result = parse_first_floating_point(start, start + view.length());
auto parse_result = parse_first_number<double>(view, TrimWhitespace::No);
if (!parse_result.has_value())
return Error::from_string_literal("JsonParser: Invalid floating point");
if (parse_result.parsed_value()) {
auto characters_parsed = parse_result.end_ptr - start;
m_index = start_index + characters_parsed;
return JsonValue(parse_result.value);
}
return Error::from_string_literal("JsonParser: Invalid floating point");
m_index = start_index + parse_result->characters_parsed;
return JsonValue { parse_result->value };
};
if (peek() == '0') {

View File

@ -28,7 +28,18 @@ public:
requires(Unsigned<ValueType>)
{
// First byte is unrolled for speed
auto byte = TRY(stream.read_value<u8>());
u8 byte;
do {
auto result = stream.read_some({ &byte, 1 });
if (result.is_error() && result.error().is_errno() && (result.error().code() == EAGAIN || result.error().code() == EINTR))
continue;
if (result.is_error())
return result.release_error();
if (result.value().size() != 1)
return Error::from_string_literal("EOF reached before expected end");
break;
} while (true);
if ((byte & 0x80) == 0)
return LEB128<ValueType> { byte };

View File

@ -32,10 +32,10 @@ public:
ByteString const& string() const { return m_string; }
StringView dirname() const { return m_dirname; }
StringView basename(StripExtension s = StripExtension::No) const { return s == StripExtension::No ? m_basename : m_title; }
StringView title() const { return m_title; }
StringView extension() const { return m_extension; }
StringView dirname() const LIFETIME_BOUND { return m_dirname; }
StringView basename(StripExtension s = StripExtension::No) const LIFETIME_BOUND { return s == StripExtension::No ? m_basename : m_title; }
StringView title() const LIFETIME_BOUND { return m_title; }
StringView extension() const LIFETIME_BOUND { return m_extension; }
Vector<StringView> const& parts_view() const { return m_parts; }
[[nodiscard]] Vector<ByteString> parts() const;

View File

@ -44,17 +44,6 @@ ErrorOr<void> FixedMemoryStream::truncate(size_t)
return Error::from_errno(EBADF);
}
ErrorOr<Bytes> FixedMemoryStream::read_some(Bytes bytes)
{
auto to_read = min(remaining(), bytes.size());
if (to_read == 0)
return Bytes {};
m_bytes.slice(m_offset, to_read).copy_to(bytes);
m_offset += to_read;
return bytes.trim(to_read);
}
ErrorOr<void> FixedMemoryStream::read_until_filled(AK::Bytes bytes)
{
if (remaining() < bytes.size())

View File

@ -30,7 +30,12 @@ public:
virtual bool is_open() const override;
virtual void close() override;
virtual ErrorOr<void> truncate(size_t) override;
virtual ErrorOr<Bytes> read_some(Bytes bytes) override;
virtual ErrorOr<Bytes> read_some(Bytes bytes) override
{
auto read = m_bytes.slice(m_offset).copy_trimmed_to(bytes);
m_offset += read;
return bytes.trim(read);
}
virtual ErrorOr<void> read_until_filled(Bytes bytes) override;
virtual ErrorOr<size_t> seek(i64 offset, SeekMode seek_mode = SeekMode::SetPosition) override;

View File

@ -169,6 +169,7 @@ struct Traits<NonnullOwnPtr<T>> : public DefaultTraits<NonnullOwnPtr<T>> {
using ConstPeekType = T const*;
static unsigned hash(NonnullOwnPtr<T> const& p) { return ptr_hash(p.ptr()); }
static bool equals(NonnullOwnPtr<T> const& a, NonnullOwnPtr<T> const& b) { return a.ptr() == b.ptr(); }
static constexpr bool may_have_slow_equality_check() { return false; }
};
template<typename T, typename U>

View File

@ -50,6 +50,7 @@ private:
template<typename T>
struct Traits<NonnullRawPtr<T>> : public DefaultTraits<NonnullRawPtr<T>> {
static unsigned hash(NonnullRawPtr<T> const& handle) { return Traits<T>::hash(handle); }
static constexpr bool may_have_slow_equality_check() { return false; }
};
namespace Detail {

View File

@ -276,6 +276,7 @@ struct Traits<NonnullRefPtr<T>> : public DefaultTraits<NonnullRefPtr<T>> {
using ConstPeekType = T const*;
static unsigned hash(NonnullRefPtr<T> const& p) { return ptr_hash(p.ptr()); }
static bool equals(NonnullRefPtr<T> const& a, NonnullRefPtr<T> const& b) { return a.ptr() == b.ptr(); }
static constexpr bool may_have_slow_equality_check() { return false; }
};
}

View File

@ -1,6 +1,7 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2021, Daniel Bertalan <dani@danielbertalan.dev>
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -10,6 +11,7 @@
#include <AK/Assertions.h>
#include <AK/Noncopyable.h>
#include <AK/StdLibExtras.h>
#include <AK/Traits.h>
#include <AK/Try.h>
#include <AK/Types.h>
#include <AK/kmalloc.h>
@ -122,6 +124,14 @@ public:
return TRY(callback());
}
template<typename Callable>
[[nodiscard]] ALWAYS_INLINE constexpr T& ensure(Callable callable) &
{
if (!static_cast<Self&>(*this).has_value())
static_cast<Self&>(*this) = callable();
return static_cast<Self&>(*this).value();
}
[[nodiscard]] ALWAYS_INLINE constexpr T const& operator*() const { return static_cast<Self const&>(*this).value(); }
[[nodiscard]] ALWAYS_INLINE constexpr T& operator*() { return static_cast<Self&>(*this).value(); }
@ -400,7 +410,7 @@ requires(IsLvalueReference<T>) class [[nodiscard]] Optional<T> {
friend class Optional;
template<typename U>
constexpr static bool CanBePlacedInOptional = IsSame<RemoveReference<T>, RemoveReference<AddConstToReferencedType<U>>> && (IsBaseOf<RemoveCVReference<T>, RemoveCVReference<U>> || IsSame<RemoveCVReference<T>, RemoveCVReference<U>>);
constexpr static bool CanBePlacedInOptional = IsSame<RemoveReference<T>, RemoveReference<AddConstToReferencedType<U>>> && (IsBaseOf<RemoveReference<T>, RemoveReference<U>> || IsSame<RemoveCVReference<T>, RemoveCVReference<U>>);
public:
using ValueType = T;
@ -522,7 +532,7 @@ public:
}
template<typename U>
requires(IsBaseOf<RemoveCVReference<T>, U>) [[nodiscard]] ALWAYS_INLINE constexpr AddConstToReferencedType<T> value_or(U& fallback) const
requires(IsBaseOf<RemoveReference<T>, U>) [[nodiscard]] ALWAYS_INLINE constexpr AddConstToReferencedType<T> value_or(U& fallback) const
{
if (m_pointer)
return value();
@ -603,6 +613,14 @@ public:
return TRY(callback());
}
template<typename Callback>
[[nodiscard]] ALWAYS_INLINE constexpr T ensure(Callback callback) &
{
if (m_pointer == nullptr)
m_pointer = &callback();
return *m_pointer;
}
template<typename F, typename MappedType = decltype(declval<F>()(declval<T&>())), auto IsErrorOr = IsSpecializationOf<MappedType, ErrorOr>, typename OptionalType = Optional<ConditionallyResultType<IsErrorOr, MappedType>>>
ALWAYS_INLINE constexpr Conditional<IsErrorOr, ErrorOr<OptionalType>, OptionalType> map(F&& mapper)
{
@ -656,6 +674,18 @@ ALWAYS_INLINE constexpr bool operator==(Optional<T> const& first, OptionalNone)
return !first.has_value();
}
template<typename T>
struct Traits<Optional<T>> : public DefaultTraits<Optional<T>> {
static unsigned hash(Optional<T> const& optional)
{
// Arbitrary-ish value for an empty optional, but not 0 as that is a common 'hash' for many T's.
if (!optional.has_value())
return 13;
return Traits<T>::hash(optional.value());
}
};
}
#if USING_AK_GLOBALLY

View File

@ -198,6 +198,7 @@ struct Traits<OwnPtr<T>> : public DefaultTraits<OwnPtr<T>> {
using ConstPeekType = T const*;
static unsigned hash(OwnPtr<T> const& p) { return ptr_hash(p.ptr()); }
static bool equals(OwnPtr<T> const& a, OwnPtr<T> const& b) { return a.ptr() == b.ptr(); }
static constexpr bool may_have_slow_equality_check() { return false; }
};
template<typename T>

View File

@ -249,6 +249,22 @@
# define NO_UNIQUE_ADDRESS [[no_unique_address]]
#endif
#if defined(AK_OS_WINDOWS)
// https://learn.microsoft.com/en-us/cpp/cpp/empty-bases?view=msvc-170
# define AK_COMPACT_EMPTY_BASES __declspec(empty_bases)
#else
# define AK_COMPACT_EMPTY_BASES
#endif
#if defined(LIFETIME_BOUND)
# undef LIFETIME_BOUND
#endif
#if defined(AK_COMPILER_CLANG)
# define LIFETIME_BOUND [[clang::lifetimebound]]
#else
# define LIFETIME_BOUND
#endif
// GCC doesn't have __has_feature but clang does
#ifndef __has_feature
# define __has_feature(...) 0

View File

@ -298,6 +298,7 @@ struct Traits<RefPtr<T>> : public DefaultTraits<RefPtr<T>> {
using ConstPeekType = T const*;
static unsigned hash(RefPtr<T> const& p) { return ptr_hash(p.ptr()); }
static bool equals(RefPtr<T> const& a, RefPtr<T> const& b) { return a.ptr() == b.ptr(); }
static constexpr bool may_have_slow_equality_check() { return false; }
};
template<typename T, typename U>

View File

@ -24,9 +24,12 @@ public:
bool is_empty() const { return m_size == 0; }
using Iterator = SimpleIterator<SegmentedVector, VisibleType>;
using ConstIterator = SimpleIterator<SegmentedVector const, VisibleType const>;
Iterator begin() { return Iterator::begin(*this); }
ConstIterator begin() const { return ConstIterator::begin(*this); }
Iterator end() { return Iterator::end(*this); }
ConstIterator end() const { return ConstIterator::end(*this); }
ALWAYS_INLINE VisibleType const& at(size_t i) const
{

View File

@ -12,9 +12,6 @@
#ifdef AK_OS_WINDOWS
// Forward declare to avoid pulling Windows.h into every file in existence.
extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long);
# ifndef sched_yield
# define sched_yield() Sleep(0)
# endif
#else
# include <sched.h>
#endif
@ -57,7 +54,11 @@ public:
}
// Someone else was faster, wait until they're done
while (obj == (T*)0x1) {
#if defined(AK_OS_WINDOWS)
Sleep(0);
#else
sched_yield();
#endif
obj = obj_var.load(AK::memory_order_acquire);
}
if constexpr (allow_create) {

View File

@ -44,7 +44,7 @@ public:
[[nodiscard]] SourceGenerator fork()
{
return SourceGenerator { m_builder, MUST(m_mapping.clone()), m_opening, m_closing };
return SourceGenerator { m_builder, MUST(m_mapping.clone()), m_opening, m_closing, m_escape };
}
void set(StringView key, String value)
@ -66,7 +66,9 @@ public:
return result.release_value();
}
StringView as_string_view() const { return m_builder.string_view(); }
[[nodiscard]] MappingType clone_mapping() const { return MUST(m_mapping.clone()); }
StringView as_string_view() const LIFETIME_BOUND { return m_builder.string_view(); }
void append(StringView pattern)
{

View File

@ -228,6 +228,14 @@ public:
return TypedTransfer<T>::compare(data(), other.data(), other.size());
}
[[nodiscard]] constexpr bool ends_with(ReadonlySpan<T> other) const
{
if (size() < other.size())
return false;
return TypedTransfer<T>::compare(offset_pointer(size() - other.size()), other.data(), other.size());
}
[[nodiscard]] constexpr size_t matching_prefix_length(ReadonlySpan<T> other) const
{
auto maximum_length = min(size(), other.size());
@ -307,6 +315,24 @@ public:
return { data(), size() };
}
Optional<size_t> index_of(ReadonlySpan<T> other, size_t start_offset = 0) const
{
Checked maximum_offset { start_offset };
maximum_offset += other.size();
if (maximum_offset.has_overflow() || maximum_offset.value() > size())
return {};
if (other.is_empty())
return start_offset;
for (size_t index = start_offset; index <= size() - other.size(); ++index) {
if (TypedTransfer<T>::compare(data() + index, other.data(), other.size()))
return index;
}
return {};
}
template<typename TUnaryPredicate>
Optional<T&> last_matching(TUnaryPredicate const& predicate)
{

View File

@ -521,7 +521,7 @@ template<typename T>
inline constexpr bool IsDestructible = requires { declval<T>().~T(); };
template<typename T>
#if defined(AK_COMPILER_CLANG)
#if __has_builtin(__is_trivially_destructible)
inline constexpr bool IsTriviallyDestructible = __is_trivially_destructible(T);
#else
inline constexpr bool IsTriviallyDestructible = __has_trivial_destructor(T) && IsDestructible<T>;

View File

@ -12,28 +12,6 @@
namespace AK {
ErrorOr<void> Stream::read_until_filled(Bytes buffer)
{
size_t nread = 0;
while (nread < buffer.size()) {
if (is_eof())
return Error::from_string_literal("Reached end-of-file before filling the entire buffer");
auto result = read_some(buffer.slice(nread));
if (result.is_error()) {
if (result.error().is_errno() && result.error().code() == EINTR) {
continue;
}
return result.release_error();
}
nread += result.value().size();
}
return {};
}
ErrorOr<ByteBuffer> Stream::read_until_eof(size_t block_size)
{
return read_until_eof_impl(block_size);

View File

@ -29,7 +29,27 @@ public:
virtual ErrorOr<Bytes> read_some(Bytes) = 0;
/// Tries to fill the entire buffer through reading. Returns whether the
/// buffer was filled without an error.
virtual ErrorOr<void> read_until_filled(Bytes);
virtual ErrorOr<void> read_until_filled(Bytes buffer)
{
size_t nread = 0;
while (nread < buffer.size()) {
if (is_eof())
return Error::from_string_literal("Reached end-of-file before filling the entire buffer");
auto result = read_some(buffer.slice(nread));
if (result.is_error()) {
if (result.error().is_errno() && result.error().code() == EINTR) {
continue;
}
return result.release_error();
}
nread += result.value().size();
}
return {};
}
/// Reads the stream until EOF, storing the contents into a ByteBuffer which
/// is returned once EOF is encountered. The block size determines the size
/// of newly allocated chunks while reading.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -14,6 +14,7 @@
#include <AK/MemMem.h>
#include <AK/Stream.h>
#include <AK/String.h>
#include <AK/StringNumber.h>
#include <AK/Utf16View.h>
#include <AK/Vector.h>
#include <stdlib.h>
@ -24,16 +25,22 @@ namespace AK {
String String::from_utf8_with_replacement_character(StringView view, WithBOMHandling with_bom_handling)
{
if (auto bytes = view.bytes(); with_bom_handling == WithBOMHandling::Yes && bytes.size() >= 3 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF)
if (auto bytes = view.bytes(); with_bom_handling == WithBOMHandling::Yes && bytes.starts_with({ { 0xEF, 0xBB, 0xBF } }))
view = view.substring_view(3);
if (Utf8View(view).validate())
Utf8View utf8_view { view };
if (utf8_view.validate(AllowLonelySurrogates::No))
return String::from_utf8_without_validation(view.bytes());
StringBuilder builder;
StringBuilder builder(view.length());
for (auto c : Utf8View { view })
builder.append_code_point(c);
for (auto code_point : utf8_view) {
if (is_unicode_surrogate(code_point))
builder.append_code_point(UnicodeUtils::REPLACEMENT_CODE_POINT);
else
builder.append_code_point(code_point);
}
return builder.to_string_without_validation();
}
@ -48,6 +55,11 @@ String String::from_utf8_without_validation(ReadonlyBytes bytes)
return result;
}
String String::from_ascii_without_validation(ReadonlyBytes bytes)
{
return from_utf8_without_validation(bytes);
}
ErrorOr<String> String::from_utf8(StringView view)
{
if (!Utf8View { view }.validate())
@ -61,49 +73,57 @@ ErrorOr<String> String::from_utf8(StringView view)
return result;
}
ErrorOr<String> String::from_utf16_le(ReadonlyBytes bytes)
ErrorOr<String> String::from_utf16_le_with_replacement_character(ReadonlyBytes bytes)
{
if (!validate_utf16_le(bytes))
return Error::from_string_literal("String::from_utf16_le: Input was not valid UTF-16LE");
if (bytes.is_empty())
return String {};
char16_t const* utf16_data = reinterpret_cast<char16_t const*>(bytes.data());
size_t utf16_length = bytes.size() / 2;
size_t max_utf8_length = simdutf::utf8_length_from_utf16(utf16_data, utf16_length);
Vector<u8> buffer;
buffer.resize(max_utf8_length);
auto utf8_length = simdutf::convert_utf16le_to_utf8(utf16_data, utf16_length, reinterpret_cast<char*>(buffer.data()));
return String::from_utf8_without_validation(ReadonlyBytes { buffer.data(), utf8_length });
}
ErrorOr<String> String::from_utf16_be(ReadonlyBytes bytes)
{
if (!validate_utf16_be(bytes))
return Error::from_string_literal("String::from_utf16_be: Input was not valid UTF-16BE");
if (bytes.is_empty())
return String {};
char16_t const* utf16_data = reinterpret_cast<char16_t const*>(bytes.data());
size_t utf16_length = bytes.size() / 2;
size_t max_utf8_length = simdutf::utf8_length_from_utf16(utf16_data, utf16_length);
Vector<u8> buffer;
buffer.resize(max_utf8_length);
auto utf8_length = simdutf::convert_utf16be_to_utf8(utf16_data, utf16_length, reinterpret_cast<char*>(buffer.data()));
return String::from_utf8_without_validation(ReadonlyBytes { buffer.data(), utf8_length });
}
auto const* utf16_data = reinterpret_cast<char16_t const*>(bytes.data());
auto utf16_length = bytes.size() / 2;
ErrorOr<String> String::from_utf16(Utf16View const& utf16)
{
if (!utf16.validate())
return Error::from_string_literal("String::from_utf16: Input was not valid UTF-16");
if (utf16.is_empty())
return String {};
Vector<char16_t> well_formed_utf16;
if (!validate_utf16_le(bytes)) {
well_formed_utf16.resize(bytes.size());
simdutf::to_well_formed_utf16le(utf16_data, utf16_length, well_formed_utf16.data());
utf16_data = well_formed_utf16.data();
}
auto utf8_length = simdutf::utf8_length_from_utf16le(utf16_data, utf16_length);
String result;
auto utf8_length = simdutf::utf8_length_from_utf16(utf16.char_data(), utf16.length_in_code_units());
TRY(result.replace_with_new_string(utf8_length, [&](Bytes buffer) -> ErrorOr<void> {
[[maybe_unused]] auto result = simdutf::convert_utf16_to_utf8(utf16.char_data(), utf16.length_in_code_units(), reinterpret_cast<char*>(buffer.data()));
[[maybe_unused]] auto result = simdutf::convert_utf16le_to_utf8(utf16_data, utf16_length, reinterpret_cast<char*>(buffer.data()));
ASSERT(result == buffer.size());
return {};
}));
return result;
}
ErrorOr<String> String::from_utf16_be_with_replacement_character(ReadonlyBytes bytes)
{
if (bytes.is_empty())
return String {};
auto const* utf16_data = reinterpret_cast<char16_t const*>(bytes.data());
auto utf16_length = bytes.size() / 2;
Vector<char16_t> well_formed_utf16;
if (!validate_utf16_le(bytes)) {
well_formed_utf16.resize(bytes.size());
simdutf::to_well_formed_utf16be(utf16_data, utf16_length, well_formed_utf16.data());
utf16_data = well_formed_utf16.data();
}
auto utf8_length = simdutf::utf8_length_from_utf16be(utf16_data, utf16_length);
String result;
TRY(result.replace_with_new_string(utf8_length, [&](Bytes buffer) -> ErrorOr<void> {
[[maybe_unused]] auto result = simdutf::convert_utf16be_to_utf8(utf16_data, utf16_length, reinterpret_cast<char*>(buffer.data()));
ASSERT(result == buffer.size());
return {};
}));
@ -303,7 +323,7 @@ ErrorOr<String> String::reverse() const
for (auto code_point : this->code_points())
code_points.unchecked_append(code_point);
auto builder = TRY(StringBuilder::create(code_point_length * sizeof(u32)));
StringBuilder builder(code_point_length * sizeof(u32));
while (!code_points.is_empty())
TRY(builder.try_append_code_point(code_points.take_last()));
@ -478,6 +498,21 @@ String String::bijective_base_from(size_t value, Case target_case, unsigned base
return MUST(from_utf8(ReadonlyBytes(buffer.data(), i)));
}
String String::greek_letter_from(size_t value)
{
static StringView const map = "αβγδεζηθικλμνξοπρστυφχψω"sv;
static unsigned const base = 24;
StringBuilder builder;
while (value > 0) {
value--;
builder.append(map.substring_view((value % base) * 2, 2));
value /= base;
}
return MUST(builder.to_string_without_validation().reverse());
}
String String::roman_number_from(size_t value, Case target_case)
{
if (value > 3999)
@ -534,42 +569,7 @@ String String::roman_number_from(size_t value, Case target_case)
template<Integral T>
String String::number(T value)
{
// Maximum number of base-10 digits for T + sign
constexpr size_t max_digits = sizeof(T) * 3 + 2;
char buffer[max_digits];
char* ptr = buffer + max_digits;
bool is_negative = false;
using UnsignedT = MakeUnsigned<T>;
UnsignedT unsigned_value;
if constexpr (IsSigned<T>) {
if (value < 0) {
is_negative = true;
// Handle signed min correctly
unsigned_value = static_cast<UnsignedT>(0) - static_cast<UnsignedT>(value);
} else {
unsigned_value = static_cast<UnsignedT>(value);
}
} else {
unsigned_value = value;
}
if (unsigned_value == 0) {
*--ptr = '0';
} else {
while (unsigned_value != 0) {
*--ptr = '0' + (unsigned_value % 10);
unsigned_value /= 10;
}
}
if (is_negative) {
*--ptr = '-';
}
size_t size = buffer + max_digits - ptr;
return from_utf8_without_validation(ReadonlyBytes { ptr, size });
return create_string_from_number<String, T>(value);
}
template String String::number(char);

View File

@ -64,14 +64,14 @@ public:
static ErrorOr<String> from_utf8(T&&) = delete;
[[nodiscard]] static String from_utf8_without_validation(ReadonlyBytes);
[[nodiscard]] static String from_ascii_without_validation(ReadonlyBytes);
static ErrorOr<String> from_string_builder(Badge<StringBuilder>, StringBuilder&);
[[nodiscard]] static String from_string_builder_without_validation(Badge<StringBuilder>, StringBuilder&);
// Creates a new String from a sequence of UTF-16 encoded code points.
static ErrorOr<String> from_utf16(Utf16View const&);
static ErrorOr<String> from_utf16_le(ReadonlyBytes);
static ErrorOr<String> from_utf16_be(ReadonlyBytes);
static ErrorOr<String> from_utf16_le_with_replacement_character(ReadonlyBytes);
static ErrorOr<String> from_utf16_be_with_replacement_character(ReadonlyBytes);
// Creates a new String by reading byte_count bytes from a UTF-8 encoded Stream.
static ErrorOr<String> from_stream(Stream&, size_t byte_count);
@ -103,6 +103,7 @@ public:
Lower,
};
[[nodiscard]] static String bijective_base_from(size_t value, Case, unsigned base = 26, StringView map = {});
[[nodiscard]] static String greek_letter_from(size_t value);
[[nodiscard]] static String roman_number_from(size_t value, Case);
// Creates a new String by case-transforming this String. Using these methods require linking LibUnicode into your application.
@ -144,7 +145,7 @@ public:
[[nodiscard]] bool is_empty() const { return byte_count() == 0; }
// Returns a StringView covering the full length of the string. Note that iterating this will go byte-at-a-time, not code-point-at-a-time.
[[nodiscard]] StringView bytes_as_string_view() const& { return StringView(bytes()); }
[[nodiscard]] StringView bytes_as_string_view() const& LIFETIME_BOUND { return StringView(bytes()); }
[[nodiscard]] StringView bytes_as_string_view() const&& = delete;
[[nodiscard]] size_t count(StringView needle) const { return StringUtils::count(bytes_as_string_view(), needle); }
@ -195,9 +196,9 @@ public:
}
template<Arithmetic T>
Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes) const
Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes, int base = 10) const
{
return bytes_as_string_view().to_number<T>(trim_whitespace);
return bytes_as_string_view().to_number<T>(trim_whitespace, base);
}
static ErrorOr<String> vformatted(StringView fmtstr, TypeErasedFormatParams&);

View File

@ -14,7 +14,10 @@
namespace AK::Detail {
struct ShortString {
ReadonlyBytes bytes() const;
static constexpr ShortString create_empty();
static constexpr ShortString create_with_byte_count(size_t byte_count);
ReadonlyBytes bytes() const LIFETIME_BOUND;
size_t byte_count() const;
// NOTE: This is the byte count shifted left 1 step and or'ed with a 1 (the SHORT_STRING_FLAG)
@ -31,9 +34,13 @@ static_assert(sizeof(ShortString) == sizeof(StringData*));
class StringBase {
public:
// NOTE: If the least significant bit of the pointer is set, this is a short string.
static constexpr uintptr_t SHORT_STRING_FLAG = 1;
static constexpr unsigned SHORT_STRING_BYTE_COUNT_SHIFT_COUNT = 2;
// Creates an empty (zero-length) String.
constexpr StringBase()
: StringBase(ShortString { .byte_count_and_short_string_flag = SHORT_STRING_FLAG })
: StringBase(ShortString::create_empty())
{
}
@ -42,7 +49,7 @@ public:
constexpr StringBase(StringBase&& other)
: m_impl(other.m_impl)
{
other.m_impl = { .short_string = { .byte_count_and_short_string_flag = SHORT_STRING_FLAG } };
other.m_impl = { .short_string = ShortString::create_empty() };
}
StringBase& operator=(StringBase&&);
@ -64,9 +71,10 @@ public:
// Returns the underlying UTF-8 encoded bytes.
// NOTE: There is no guarantee about null-termination.
[[nodiscard]] ReadonlyBytes bytes() const;
[[nodiscard]] ReadonlyBytes bytes() const LIFETIME_BOUND;
[[nodiscard]] u32 hash() const;
[[nodiscard]] size_t byte_count() const;
[[nodiscard]] ALWAYS_INLINE size_t length_in_code_units() const { return byte_count(); }
[[nodiscard]] bool operator==(StringBase const&) const;
@ -79,6 +87,12 @@ public:
return replace_with_new_string(byte_count, forward<Func>(callback));
}
template<typename Func>
ALWAYS_INLINE ErrorOr<void> replace_with_new_string(Badge<Utf16View>, size_t byte_count, Func&& callback)
{
return replace_with_new_string(byte_count, forward<Func>(callback));
}
protected:
template<typename Func>
ErrorOr<void> replace_with_new_string(size_t byte_count, Func&& callback)
@ -108,10 +122,6 @@ private:
friend class ::AK::FlyString;
friend struct ::AK::Detail::ShortString;
// NOTE: If the least significant bit of the pointer is set, this is a short string.
static constexpr uintptr_t SHORT_STRING_FLAG = 1;
static constexpr unsigned SHORT_STRING_BYTE_COUNT_SHIFT_COUNT = 2;
explicit StringBase(NonnullRefPtr<Detail::StringData const>);
explicit constexpr StringBase(nullptr_t)
@ -131,8 +141,7 @@ private:
VERIFY(is_short_string());
VERIFY(byte_count <= MAX_SHORT_STRING_BYTE_COUNT);
m_impl = { .short_string = {} };
m_impl.short_string.byte_count_and_short_string_flag = (byte_count << SHORT_STRING_BYTE_COUNT_SHIFT_COUNT) | SHORT_STRING_FLAG;
m_impl = { .short_string = ShortString::create_with_byte_count(byte_count) };
return { m_impl.short_string.storage, byte_count };
}
@ -172,6 +181,19 @@ private:
} m_impl;
};
constexpr ShortString ShortString::create_empty()
{
return create_with_byte_count(0);
}
constexpr ShortString ShortString::create_with_byte_count(size_t byte_count)
{
ShortString string {};
string.byte_count_and_short_string_flag = (byte_count << StringBase::SHORT_STRING_BYTE_COUNT_SHIFT_COUNT) | StringBase::SHORT_STRING_FLAG;
return string;
}
inline ReadonlyBytes ShortString::bytes() const
{
return { storage, byte_count() };
@ -198,14 +220,14 @@ inline u32 StringBase::hash() const
return string_hash(reinterpret_cast<char const*>(bytes.data()), bytes.size());
}
if (!m_impl.data)
return string_hash(nullptr, 0);
return string_hash<char>(nullptr, 0);
return data_without_union_member_assertion()->hash();
}
inline size_t StringBase::byte_count() const
{
if (is_short_string())
return m_impl.short_string.byte_count_and_short_string_flag >> StringBase::SHORT_STRING_BYTE_COUNT_SHIFT_COUNT;
return m_impl.short_string.byte_count();
if (!m_impl.data)
return 0;
@ -235,7 +257,7 @@ inline StringBase& StringBase::operator=(StringBase&& other)
if (!is_short_string() && m_impl.data)
data_without_union_member_assertion()->unref();
m_impl = exchange(other.m_impl, { .short_string = { .byte_count_and_short_string_flag = SHORT_STRING_FLAG } });
m_impl = exchange(other.m_impl, { .short_string = ShortString::create_empty() });
return *this;
}

View File

@ -14,6 +14,8 @@
#include <AK/StringData.h>
#include <AK/StringView.h>
#include <AK/UnicodeUtils.h>
#include <AK/Utf16String.h>
#include <AK/Utf16StringData.h>
#include <AK/Utf16View.h>
#include <AK/Utf32View.h>
@ -21,44 +23,54 @@
namespace AK {
static constexpr auto STRING_BASE_PREFIX_SIZE = sizeof(Detail::StringData);
static ErrorOr<StringBuilder::Buffer> create_buffer(size_t capacity)
static constexpr size_t string_builder_prefix_size(StringBuilder::Mode mode)
{
StringBuilder::Buffer buffer;
if (capacity > StringBuilder::inline_capacity)
TRY(buffer.try_ensure_capacity(STRING_BASE_PREFIX_SIZE + capacity));
TRY(buffer.try_resize(STRING_BASE_PREFIX_SIZE));
return buffer;
switch (mode) {
case StringBuilder::Mode::UTF8:
return sizeof(Detail::StringData);
case StringBuilder::Mode::UTF16:
return Detail::Utf16StringData::offset_of_string_storage();
}
VERIFY_NOT_REACHED();
}
ErrorOr<StringBuilder> StringBuilder::create(size_t initial_capacity)
void StringBuilder::initialize_buffer(Mode mode, size_t capacity)
{
auto buffer = TRY(create_buffer(initial_capacity));
return StringBuilder { move(buffer) };
auto prefix_size = string_builder_prefix_size(mode);
if (capacity > StringBuilder::inline_capacity)
m_buffer.ensure_capacity(prefix_size + capacity);
m_buffer.resize(prefix_size);
}
StringBuilder::StringBuilder()
: StringBuilder(inline_capacity)
{
static constexpr auto prefix_size = string_builder_prefix_size(DEFAULT_MODE);
static_assert(inline_capacity > prefix_size);
initialize_buffer(m_mode, inline_capacity);
}
StringBuilder::StringBuilder(size_t initial_capacity)
: m_buffer(MUST(create_buffer(initial_capacity)))
{
initialize_buffer(m_mode, initial_capacity);
}
StringBuilder::StringBuilder(Buffer buffer)
: m_buffer(move(buffer))
StringBuilder::StringBuilder(Mode mode)
: m_mode(mode)
{
initialize_buffer(m_mode, inline_capacity);
}
inline ErrorOr<void> StringBuilder::will_append(size_t size)
StringBuilder::StringBuilder(Mode mode, size_t initial_capacity_in_code_units)
: m_mode(mode)
{
initialize_buffer(mode, initial_capacity_in_code_units * (mode == Mode::UTF8 ? 1 : 2));
}
inline ErrorOr<void> StringBuilder::will_append(size_t size_in_bytes)
{
Checked<size_t> needed_capacity = m_buffer.size();
needed_capacity += size;
needed_capacity += size_in_bytes;
VERIFY(!needed_capacity.has_overflow());
// Prefer to completely use the existing capacity first
if (needed_capacity <= m_buffer.capacity())
@ -70,9 +82,32 @@ inline ErrorOr<void> StringBuilder::will_append(size_t size)
return {};
}
ErrorOr<void> StringBuilder::ensure_storage_is_utf16()
{
if (!exchange(m_utf16_builder_is_ascii, false))
return {};
if (is_empty())
return {};
auto ascii_length = this->length();
TRY(m_buffer.try_resize(m_buffer.size() + ascii_length));
Bytes source { data(), ascii_length };
Span<char16_t> target { reinterpret_cast<char16_t*>(data()), ascii_length };
for (size_t i = ascii_length; i > 0; --i) {
auto index = i - 1;
auto ch = static_cast<char16_t>(source[index]);
target.overwrite(index, &ch, sizeof(char16_t));
}
return {};
}
size_t StringBuilder::length() const
{
return m_buffer.size() - STRING_BASE_PREFIX_SIZE;
return m_buffer.size() - string_builder_prefix_size(m_mode);
}
bool StringBuilder::is_empty() const
@ -82,6 +117,9 @@ bool StringBuilder::is_empty() const
void StringBuilder::trim(size_t count)
{
if (m_mode == Mode::UTF16)
count *= 2;
auto decrease_count = min(m_buffer.size(), count);
m_buffer.resize(m_buffer.size() - decrease_count);
}
@ -90,23 +128,81 @@ ErrorOr<void> StringBuilder::try_append(StringView string)
{
if (string.is_empty())
return {};
TRY(will_append(string.length()));
TRY(m_buffer.try_append(string.characters_without_null_termination(), string.length()));
if (m_mode == Mode::UTF8 || (m_utf16_builder_is_ascii && string.is_ascii())) {
TRY(will_append(string.length()));
TRY(m_buffer.try_append(string.characters_without_null_termination(), string.length()));
} else {
TRY(ensure_storage_is_utf16());
TRY(will_append(string.length() * 2));
for (auto code_point : Utf8View { string })
TRY(try_append_code_point(code_point));
}
return {};
}
void StringBuilder::append_ascii_without_validation(ReadonlyBytes string)
{
MUST(try_append_ascii_without_validation(string));
}
ErrorOr<void> StringBuilder::try_append_ascii_without_validation(ReadonlyBytes string)
{
if (string.is_empty())
return {};
if (m_mode == Mode::UTF8 || m_utf16_builder_is_ascii) {
TRY(m_buffer.try_append(string));
} else {
if (m_mode == Mode::UTF16) {
TRY(ensure_storage_is_utf16());
TRY(will_append(string.size() * 2));
} else {
TRY(will_append(string.size()));
}
for (auto code_point : Utf8View { string })
TRY(try_append_code_point(code_point));
}
return {};
}
ErrorOr<void> StringBuilder::try_append(char ch)
{
TRY(will_append(1));
TRY(m_buffer.try_append(ch));
if (m_mode == Mode::UTF8 || (m_utf16_builder_is_ascii && is_ascii(ch))) {
TRY(will_append(1));
TRY(m_buffer.try_append(ch));
} else {
TRY(ensure_storage_is_utf16());
TRY(try_append_code_unit(ch));
}
return {};
}
ErrorOr<void> StringBuilder::try_append_code_unit(char16_t ch)
{
if (m_mode == Mode::UTF8 || (m_utf16_builder_is_ascii && is_ascii(ch))) {
TRY(try_append_code_point(ch));
} else {
TRY(ensure_storage_is_utf16());
TRY(will_append(2));
TRY(m_buffer.try_append(&ch, sizeof(ch)));
}
return {};
}
ErrorOr<void> StringBuilder::try_append_repeated(char ch, size_t n)
{
TRY(will_append(n));
auto append_as_utf8 = m_mode == Mode::UTF8 || (m_utf16_builder_is_ascii && is_ascii(ch));
TRY(will_append(n * (append_as_utf8 ? 1 : 2)));
for (size_t i = 0; i < n; ++i)
TRY(try_append(ch));
return {};
}
@ -114,9 +210,39 @@ ErrorOr<void> StringBuilder::try_append_repeated(StringView string, size_t n)
{
if (string.is_empty())
return {};
TRY(will_append(string.length() * n));
if (m_mode == Mode::UTF8 || (m_utf16_builder_is_ascii && string.is_ascii())) {
TRY(will_append(string.length() * n));
} else {
auto utf16_length = simdutf::utf16_length_from_utf8(string.characters_without_null_termination(), string.length());
TRY(will_append(utf16_length * n * 2));
}
for (size_t i = 0; i < n; ++i)
TRY(try_append(string));
return {};
}
ErrorOr<void> StringBuilder::try_append_repeated(Utf16View const& string, size_t n)
{
if (string.is_empty())
return {};
if (m_mode == Mode::UTF8 || (m_utf16_builder_is_ascii && string.is_ascii())) {
if (string.has_ascii_storage()) {
TRY(will_append(string.length_in_code_units() * n));
} else {
auto utf8_length = simdutf::utf8_length_from_utf16(string.utf16_span().data(), string.length_in_code_units());
TRY(will_append(utf8_length * n));
}
} else {
TRY(will_append(string.length_in_code_units() * n * 2));
}
for (size_t i = 0; i < n; ++i)
TRY(try_append(string));
return {};
}
@ -140,6 +266,11 @@ void StringBuilder::append(char ch)
MUST(try_append(ch));
}
void StringBuilder::append_code_unit(char16_t ch)
{
MUST(try_append_code_unit(ch));
}
void StringBuilder::append_repeated(char ch, size_t n)
{
MUST(try_append_repeated(ch, n));
@ -150,6 +281,11 @@ void StringBuilder::append_repeated(StringView string, size_t n)
MUST(try_append_repeated(string, n));
}
void StringBuilder::append_repeated(Utf16View const& string, size_t n)
{
MUST(try_append_repeated(string, n));
}
ErrorOr<ByteBuffer> StringBuilder::to_byte_buffer() const
{
return ByteBuffer::copy(data(), length());
@ -157,6 +293,7 @@ ErrorOr<ByteBuffer> StringBuilder::to_byte_buffer() const
ByteString StringBuilder::to_byte_string() const
{
VERIFY(m_mode == Mode::UTF8);
if (is_empty())
return ByteString::empty();
return ByteString((char const*)data(), length());
@ -164,6 +301,7 @@ ByteString StringBuilder::to_byte_string() const
ErrorOr<String> StringBuilder::to_string()
{
VERIFY(m_mode == Mode::UTF8);
if (m_buffer.is_inline())
return String::from_utf8(string_view());
return String::from_string_builder({}, *this);
@ -171,6 +309,7 @@ ErrorOr<String> StringBuilder::to_string()
String StringBuilder::to_string_without_validation()
{
VERIFY(m_mode == Mode::UTF8);
if (m_buffer.is_inline())
return String::from_utf8_without_validation(string_view().bytes());
return String::from_string_builder_without_validation({}, *this);
@ -178,47 +317,102 @@ String StringBuilder::to_string_without_validation()
FlyString StringBuilder::to_fly_string_without_validation() const
{
VERIFY(m_mode == Mode::UTF8);
return FlyString::from_utf8_without_validation(string_view().bytes());
}
ErrorOr<FlyString> StringBuilder::to_fly_string() const
{
VERIFY(m_mode == Mode::UTF8);
return FlyString::from_utf8(string_view());
}
Utf16String StringBuilder::to_utf16_string()
{
VERIFY(m_mode == Mode::UTF16);
return Utf16String::from_string_builder({}, *this);
}
u8* StringBuilder::data()
{
return m_buffer.data() + STRING_BASE_PREFIX_SIZE;
return m_buffer.data() + string_builder_prefix_size(m_mode);
}
u8 const* StringBuilder::data() const
{
return m_buffer.data() + STRING_BASE_PREFIX_SIZE;
return m_buffer.data() + string_builder_prefix_size(m_mode);
}
StringView StringBuilder::string_view() const
{
return m_buffer.span().slice(STRING_BASE_PREFIX_SIZE);
VERIFY(m_mode == Mode::UTF8);
return m_buffer.span().slice(string_builder_prefix_size(m_mode));
}
Utf16View StringBuilder::utf16_string_view() const
{
VERIFY(m_mode == Mode::UTF16);
auto view = m_buffer.span().slice(string_builder_prefix_size(m_mode));
if (m_utf16_builder_is_ascii)
return { reinterpret_cast<char const*>(view.data()), view.size() };
return { reinterpret_cast<char16_t const*>(view.data()), view.size() / 2 };
}
void StringBuilder::clear()
{
m_buffer.resize(STRING_BASE_PREFIX_SIZE);
m_buffer.resize(string_builder_prefix_size(m_mode));
}
ErrorOr<void> StringBuilder::try_append_code_point(u32 code_point)
{
auto nwritten = TRY(AK::UnicodeUtils::try_code_point_to_utf8(code_point, [this](char c) { return try_append(c); }));
if (nwritten < 0) {
TRY(try_append(0xef));
TRY(try_append(0xbf));
TRY(try_append(0xbd));
if (!is_unicode(code_point)) {
TRY(try_append_code_point(UnicodeUtils::REPLACEMENT_CODE_POINT));
return {};
}
if (m_mode == Mode::UTF8 || (m_utf16_builder_is_ascii && is_ascii(code_point))) {
TRY(AK::UnicodeUtils::try_code_point_to_utf8(code_point, [this](char c) { return try_append(c); }));
} else {
TRY(ensure_storage_is_utf16());
TRY(AK::UnicodeUtils::try_code_point_to_utf16(code_point, [this](char16_t c) { return m_buffer.try_append(&c, sizeof(c)); }));
}
return {};
}
void StringBuilder::append_code_point(u32 code_point)
{
if (!is_unicode(code_point)) {
append_code_point(UnicodeUtils::REPLACEMENT_CODE_POINT);
return;
}
auto append_as_utf8 = m_mode == Mode::UTF8 || (m_utf16_builder_is_ascii && is_ascii(code_point));
if (!append_as_utf8) {
MUST(ensure_storage_is_utf16());
(void)(will_append(2));
if (code_point < UnicodeUtils::FIRST_SUPPLEMENTARY_PLANE_CODE_POINT) {
auto code_unit = static_cast<char16_t>(code_point);
m_buffer.append(&code_unit, sizeof(code_unit));
return;
}
(void)(will_append(2));
code_point -= UnicodeUtils::FIRST_SUPPLEMENTARY_PLANE_CODE_POINT;
auto code_unit = static_cast<u16>(UnicodeUtils::HIGH_SURROGATE_MIN | (code_point >> 10));
m_buffer.append(&code_unit, sizeof(code_unit));
code_unit = static_cast<u16>(UnicodeUtils::LOW_SURROGATE_MIN | (code_point & 0x3ff));
m_buffer.append(&code_unit, sizeof(code_unit));
return;
}
if (code_point <= 0x7f) {
m_buffer.append(static_cast<char>(code_point));
} else if (code_point <= 0x07ff) {
@ -230,17 +424,12 @@ void StringBuilder::append_code_point(u32 code_point)
m_buffer.append(static_cast<char>((((code_point >> 12) & 0x0f) | 0xe0)));
m_buffer.append(static_cast<char>((((code_point >> 6) & 0x3f) | 0x80)));
m_buffer.append(static_cast<char>((((code_point >> 0) & 0x3f) | 0x80)));
} else if (code_point <= 0x10ffff) {
} else {
(void)will_append(4);
m_buffer.append(static_cast<char>((((code_point >> 18) & 0x07) | 0xf0)));
m_buffer.append(static_cast<char>((((code_point >> 12) & 0x3f) | 0x80)));
m_buffer.append(static_cast<char>((((code_point >> 6) & 0x3f) | 0x80)));
m_buffer.append(static_cast<char>((((code_point >> 0) & 0x3f) | 0x80)));
} else {
(void)will_append(3);
m_buffer.append(0xef);
m_buffer.append(0xbf);
m_buffer.append(0xbd);
}
}
@ -248,18 +437,32 @@ ErrorOr<void> StringBuilder::try_append(Utf16View const& utf16_view)
{
if (utf16_view.is_empty())
return {};
if (utf16_view.has_ascii_storage())
return try_append_ascii_without_validation(utf16_view.bytes());
auto maximum_utf8_length = UnicodeUtils::maximum_utf8_length_from_utf16(utf16_view.span());
auto append_as_utf8 = m_mode == Mode::UTF8 || (m_utf16_builder_is_ascii && utf16_view.is_ascii());
if (!append_as_utf8) {
TRY(ensure_storage_is_utf16());
TRY(will_append(utf16_view.length_in_code_units() * 2));
for (size_t i = 0; i < utf16_view.length_in_code_units(); ++i)
TRY(try_append_code_unit(utf16_view.code_unit_at(i)));
return {};
}
auto remaining_view = utf16_view.utf16_span();
auto maximum_utf8_length = UnicodeUtils::maximum_utf8_length_from_utf16(remaining_view);
// Possibly over-allocate a little to ensure we don't have to allocate later.
TRY(will_append(maximum_utf8_length));
Utf16View remaining_view = utf16_view;
for (;;) {
auto uninitialized_data_pointer = static_cast<char*>(m_buffer.end_pointer());
auto* uninitialized_data_pointer = static_cast<char*>(m_buffer.end_pointer());
// Fast path.
auto result = simdutf::convert_utf16_to_utf8_with_errors(remaining_view.char_data(), remaining_view.length_in_code_units(), uninitialized_data_pointer);
auto result = simdutf::convert_utf16_to_utf8_with_errors(remaining_view.data(), remaining_view.size(), uninitialized_data_pointer);
if (result.error == simdutf::SUCCESS) {
auto bytes_just_written = result.count;
m_buffer.set_size(m_buffer.size() + bytes_just_written);
@ -268,13 +471,13 @@ ErrorOr<void> StringBuilder::try_append(Utf16View const& utf16_view)
// Slow path. Found unmatched surrogate code unit.
auto first_invalid_code_unit = result.count;
ASSERT(first_invalid_code_unit < remaining_view.length_in_code_units());
ASSERT(first_invalid_code_unit < remaining_view.size());
// Unfortunately, `simdutf` does not tell us how many bytes it just wrote in case of an error, so we have to calculate it ourselves.
auto bytes_just_written = simdutf::utf8_length_from_utf16(remaining_view.char_data(), first_invalid_code_unit);
auto bytes_just_written = simdutf::utf8_length_from_utf16(remaining_view.data(), first_invalid_code_unit);
do {
auto code_unit = remaining_view.code_unit_at(first_invalid_code_unit++);
auto code_unit = remaining_view[first_invalid_code_unit++];
// Invalid surrogate code units are U+D800 - U+DFFF, so they are always encoded using 3 bytes.
ASSERT(code_unit >= 0xD800 && code_unit <= 0xDFFF);
@ -282,11 +485,11 @@ ErrorOr<void> StringBuilder::try_append(Utf16View const& utf16_view)
uninitialized_data_pointer[bytes_just_written++] = (((code_unit >> 12) & 0x0f) | 0xe0);
uninitialized_data_pointer[bytes_just_written++] = (((code_unit >> 6) & 0x3f) | 0x80);
uninitialized_data_pointer[bytes_just_written++] = (((code_unit >> 0) & 0x3f) | 0x80);
} while (first_invalid_code_unit < remaining_view.length_in_code_units() && Utf16View::is_low_surrogate(remaining_view.data()[first_invalid_code_unit]));
} while (first_invalid_code_unit < remaining_view.size() && UnicodeUtils::is_utf16_low_surrogate(remaining_view.data()[first_invalid_code_unit]));
// Code unit might no longer be invalid, retry on the remaining data.
m_buffer.set_size(m_buffer.size() + bytes_just_written);
remaining_view = remaining_view.substring_view(first_invalid_code_unit);
remaining_view = remaining_view.slice(first_invalid_code_unit);
}
return {};
@ -353,7 +556,7 @@ ErrorOr<void> StringBuilder::try_append_escaped_for_json(StringView string)
return {};
}
auto StringBuilder::leak_buffer_for_string_construction(Badge<Detail::StringData>) -> Optional<Buffer::OutlineBuffer>
auto StringBuilder::leak_buffer_for_string_construction() -> Optional<Buffer::OutlineBuffer>
{
if (auto buffer = m_buffer.leak_outline_buffer({}); buffer.has_value()) {
clear();

View File

@ -16,44 +16,58 @@ namespace AK {
class StringBuilder {
public:
enum class Mode {
UTF8,
UTF16,
};
static constexpr auto DEFAULT_MODE = Mode::UTF8;
static constexpr size_t inline_capacity = 256;
using Buffer = Detail::ByteBuffer<inline_capacity>;
static ErrorOr<StringBuilder> create(size_t initial_capacity = inline_capacity);
StringBuilder();
explicit StringBuilder(size_t initial_capacity);
explicit StringBuilder(Mode);
StringBuilder(Mode, size_t initial_capacity_in_code_units);
~StringBuilder() = default;
ErrorOr<void> try_append(StringView);
ErrorOr<void> try_append(Utf16View const&);
ErrorOr<void> try_append(Utf32View const&);
ErrorOr<void> try_append_code_point(u32);
ErrorOr<void> try_append(char);
ErrorOr<void> try_append_code_unit(char16_t);
ErrorOr<void> try_append_code_point(u32);
ErrorOr<void> try_append(char const*, size_t);
ErrorOr<void> try_append_repeated(char, size_t);
ErrorOr<void> try_append_repeated(StringView, size_t);
ErrorOr<void> try_append_repeated(Utf16View const&, size_t);
ErrorOr<void> try_append_escaped_for_json(StringView);
ErrorOr<void> try_append_ascii_without_validation(ReadonlyBytes);
template<typename... Parameters>
ErrorOr<void> try_appendff(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
{
VariadicFormatParams<AllowDebugOnlyFormatters::No, Parameters...> variadic_format_params { parameters... };
return vformat(*this, fmtstr.view(), variadic_format_params);
}
ErrorOr<void> try_append(char const*, size_t);
ErrorOr<void> try_append_repeated(char, size_t);
ErrorOr<void> try_append_repeated(StringView, size_t);
ErrorOr<void> try_append_escaped_for_json(StringView);
void append(StringView);
void append(Utf16View const&);
void append(Utf32View const&);
void append(char);
void append_code_unit(char16_t);
void append_code_point(u32);
void append(char const*, size_t);
void appendvf(char const*, va_list);
void append_repeated(char, size_t);
void append_repeated(StringView, size_t);
void append_as_lowercase(char);
void append_repeated(Utf16View const&, size_t);
void append_escaped_for_json(StringView);
void append_as_lowercase(char);
void append_ascii_without_validation(ReadonlyBytes);
template<typename... Parameters>
void appendff(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
@ -70,9 +84,12 @@ public:
[[nodiscard]] FlyString to_fly_string_without_validation() const;
ErrorOr<FlyString> to_fly_string() const;
Utf16String to_utf16_string();
[[nodiscard]] ErrorOr<ByteBuffer> to_byte_buffer() const;
[[nodiscard]] StringView string_view() const;
[[nodiscard]] Utf16View utf16_string_view() const;
void clear();
[[nodiscard]] size_t length() const;
@ -98,16 +115,23 @@ public:
return {};
}
Optional<Buffer::OutlineBuffer> leak_buffer_for_string_construction(Badge<Detail::StringData>);
Optional<Buffer::OutlineBuffer> leak_buffer_for_string_construction(Badge<Detail::StringData>) { return leak_buffer_for_string_construction(); }
Optional<Buffer::OutlineBuffer> leak_buffer_for_string_construction(Badge<Detail::Utf16StringData>) { return leak_buffer_for_string_construction(); }
private:
explicit StringBuilder(Buffer);
void initialize_buffer(Mode, size_t capacity);
Optional<Buffer::OutlineBuffer> leak_buffer_for_string_construction();
ErrorOr<void> will_append(size_t);
ErrorOr<void> ensure_storage_is_utf16();
u8* data();
u8 const* data() const;
Buffer m_buffer;
Mode m_mode { DEFAULT_MODE };
bool m_utf16_builder_is_ascii { true };
};
}

154
AK/StringConversions.cpp Normal file
View File

@ -0,0 +1,154 @@
/*
* Copyright (c) 2022, David Tuin <davidot@serenityos.org>
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/StringConversions.h>
#include <AK/StringView.h>
#include <AK/Utf16View.h>
#include <fast_float/fast_float.h>
namespace AK {
#define ENUMERATE_INTEGRAL_TYPES \
__ENUMERATE_TYPE(i8) \
__ENUMERATE_TYPE(i16) \
__ENUMERATE_TYPE(i32) \
__ENUMERATE_TYPE(long) \
__ENUMERATE_TYPE(long long) \
__ENUMERATE_TYPE(u8) \
__ENUMERATE_TYPE(u16) \
__ENUMERATE_TYPE(u32) \
__ENUMERATE_TYPE(unsigned long) \
__ENUMERATE_TYPE(unsigned long long)
#define ENUMERATE_ARITHMETIC_TYPES \
ENUMERATE_INTEGRAL_TYPES \
__ENUMERATE_TYPE(float) \
__ENUMERATE_TYPE(double)
template<typename CharType, Arithmetic ValueType>
static constexpr Optional<ParseFirstNumberResult<ValueType>> from_chars(CharType const* string, size_t length, int base)
{
ValueType value { 0 };
fast_float::parse_options_t<CharType> options;
options.base = base;
options.format |= fast_float::chars_format::no_infnan;
if constexpr (IsSigned<ValueType> || IsFloatingPoint<ValueType>) {
options.format |= fast_float::chars_format::allow_leading_plus;
}
auto result = fast_float::from_chars_advanced(string, string + length, value, options);
if constexpr (IsFloatingPoint<ValueType>) {
if (result.ec == std::errc::result_out_of_range && (__builtin_isinf(value) || value == 0))
result.ec = {};
}
if (result.ec != std::errc {})
return {};
return ParseFirstNumberResult { value, static_cast<size_t>(result.ptr - string) };
}
template<Arithmetic T>
Optional<ParseFirstNumberResult<T>> parse_first_number(StringView string, TrimWhitespace trim_whitespace, int base)
{
if (trim_whitespace == TrimWhitespace::Yes)
string = StringUtils::trim_whitespace(string, TrimMode::Both);
return from_chars<char, T>(string.characters_without_null_termination(), string.length(), base);
}
template<Arithmetic T>
Optional<ParseFirstNumberResult<T>> parse_first_number(Utf16View const& string, TrimWhitespace trim_whitespace, int base)
{
if (string.has_ascii_storage())
return parse_first_number<T>(string.bytes(), trim_whitespace, base);
auto trimmed_string = trim_whitespace == TrimWhitespace::Yes ? string.trim_ascii_whitespace() : string;
return from_chars<char16_t, T>(trimmed_string.utf16_span().data(), trimmed_string.length_in_code_units(), base);
}
#define __ENUMERATE_TYPE(type) \
template Optional<ParseFirstNumberResult<type>> parse_first_number(StringView, TrimWhitespace, int);
ENUMERATE_ARITHMETIC_TYPES
#undef __ENUMERATE_TYPE
#define __ENUMERATE_TYPE(type) \
template Optional<ParseFirstNumberResult<type>> parse_first_number(Utf16View const&, TrimWhitespace, int);
ENUMERATE_ARITHMETIC_TYPES
#undef __ENUMERATE_TYPE
template<Arithmetic T>
Optional<T> parse_number(StringView string, TrimWhitespace trim_whitespace, int base)
{
if (trim_whitespace == TrimWhitespace::Yes)
string = StringUtils::trim_whitespace(string, TrimMode::Both);
auto result = parse_first_number<T>(string, TrimWhitespace::No, base);
if (!result.has_value())
return {};
if (result->characters_parsed != string.length())
return {};
return result->value;
}
template<Arithmetic T>
Optional<T> parse_number(Utf16View const& string, TrimWhitespace trim_whitespace, int base)
{
if (string.has_ascii_storage())
return parse_number<T>(string.bytes(), trim_whitespace, base);
auto trimmed_string = trim_whitespace == TrimWhitespace::Yes ? string.trim_ascii_whitespace() : string;
auto result = parse_first_number<T>(trimmed_string, TrimWhitespace::No, base);
if (!result.has_value())
return {};
if (result->characters_parsed != trimmed_string.length_in_code_units())
return {};
return result->value;
}
#define __ENUMERATE_TYPE(type) \
template Optional<type> parse_number(StringView, TrimWhitespace, int);
ENUMERATE_ARITHMETIC_TYPES
#undef __ENUMERATE_TYPE
#define __ENUMERATE_TYPE(type) \
template Optional<type> parse_number(Utf16View const&, TrimWhitespace, int);
ENUMERATE_ARITHMETIC_TYPES
#undef __ENUMERATE_TYPE
template<Integral T>
Optional<T> parse_hexadecimal_number(StringView string, TrimWhitespace trim_whitespace)
{
return parse_number<T>(string, trim_whitespace, 16);
}
template<Integral T>
Optional<T> parse_hexadecimal_number(Utf16View const& string, TrimWhitespace trim_whitespace)
{
return parse_number<T>(string, trim_whitespace, 16);
}
#define __ENUMERATE_TYPE(type) \
template Optional<type> parse_hexadecimal_number(StringView, TrimWhitespace);
ENUMERATE_INTEGRAL_TYPES
#undef __ENUMERATE_TYPE
#define __ENUMERATE_TYPE(type) \
template Optional<type> parse_hexadecimal_number(Utf16View const&, TrimWhitespace);
ENUMERATE_INTEGRAL_TYPES
#undef __ENUMERATE_TYPE
}

40
AK/StringConversions.h Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2022, David Tuin <davidot@serenityos.org>
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Concepts.h>
#include <AK/Optional.h>
#include <AK/StringUtils.h>
namespace AK {
template<typename T>
struct ParseFirstNumberResult {
T value { 0 };
size_t characters_parsed { 0 };
};
template<Arithmetic T>
Optional<ParseFirstNumberResult<T>> parse_first_number(StringView, TrimWhitespace = TrimWhitespace::Yes, int base = 10);
template<Arithmetic T>
Optional<ParseFirstNumberResult<T>> parse_first_number(Utf16View const&, TrimWhitespace = TrimWhitespace::Yes, int base = 10);
template<Arithmetic T>
Optional<T> parse_number(StringView, TrimWhitespace = TrimWhitespace::Yes, int base = 10);
template<Arithmetic T>
Optional<T> parse_number(Utf16View const&, TrimWhitespace = TrimWhitespace::Yes, int base = 10);
template<Integral T>
Optional<T> parse_hexadecimal_number(StringView, TrimWhitespace = TrimWhitespace::Yes);
template<Integral T>
Optional<T> parse_hexadecimal_number(Utf16View const&, TrimWhitespace = TrimWhitespace::Yes);
}

View File

@ -40,7 +40,7 @@ public:
auto byte_count = builder.length();
VERIFY(byte_count > MAX_SHORT_STRING_BYTE_COUNT);
auto buffer = builder.leak_buffer_for_string_construction({});
auto buffer = builder.leak_buffer_for_string_construction(Badge<StringData> {});
VERIFY(buffer.has_value()); // We should only arrive here if the buffer is outlined.
return adopt_ref(*new (buffer->buffer.data()) StringData(byte_count));
@ -83,7 +83,7 @@ public:
}
// NOTE: There is no guarantee about null-termination.
ReadonlyBytes bytes() const
ReadonlyBytes bytes() const LIFETIME_BOUND
{
if (m_substring) {
auto const& data = substring_data();
@ -92,7 +92,7 @@ public:
return { &m_bytes_or_substring_data[0], m_byte_count };
}
StringView bytes_as_string_view() const { return { bytes() }; }
StringView bytes_as_string_view() const LIFETIME_BOUND { return { bytes() }; }
bool operator==(StringData const& other) const
{

View File

@ -6,6 +6,7 @@
#pragma once
#include <AK/Concepts.h>
#include <AK/Types.h>
namespace AK {
@ -14,7 +15,8 @@ namespace AK {
// We can't use SipHash since that depends on runtime parameters,
// but some string hashes like IPC endpoint magic numbers need to be deterministic.
// Maybe use a SipHash with a statically-known key?
constexpr u32 string_hash(char const* characters, size_t length, u32 seed = 0)
template<OneOf<char, char16_t> T>
constexpr u32 string_hash(T const* characters, size_t length, u32 seed = 0)
{
u32 hash = seed;
for (size_t i = 0; i < length; ++i) {

52
AK/StringNumber.h Normal file
View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2025, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
namespace AK {
template<class StringType, Integral T>
StringType create_string_from_number(T value)
{
// Maximum number of base-10 digits for T + sign
constexpr size_t max_digits = sizeof(T) * 3 + 2;
char buffer[max_digits];
char* ptr = buffer + max_digits;
bool is_negative = false;
using UnsignedT = MakeUnsigned<T>;
UnsignedT unsigned_value;
if constexpr (IsSigned<T>) {
if (value < 0) {
is_negative = true;
// Handle signed min correctly
unsigned_value = static_cast<UnsignedT>(0) - static_cast<UnsignedT>(value);
} else {
unsigned_value = static_cast<UnsignedT>(value);
}
} else {
unsigned_value = value;
}
if (unsigned_value == 0) {
*--ptr = '0';
} else {
while (unsigned_value != 0) {
*--ptr = '0' + (unsigned_value % 10);
unsigned_value /= 10;
}
}
if (is_negative) {
*--ptr = '-';
}
size_t size = buffer + max_digits - ptr;
return StringType::from_ascii_without_validation(ReadonlyBytes { ptr, size });
}
}

View File

@ -7,7 +7,6 @@
#include <AK/ByteString.h>
#include <AK/CharacterTypes.h>
#include <AK/FloatingPointStringConversions.h>
#include <AK/MemMem.h>
#include <AK/Optional.h>
#include <AK/String.h>
@ -17,6 +16,8 @@
#include <AK/Vector.h>
#include <string.h>
#include <simdutf.h>
namespace AK {
namespace StringUtils {
@ -86,167 +87,6 @@ bool matches(StringView str, StringView mask, CaseSensitivity case_sensitivity,
return string_ptr == string_end && mask_ptr == mask_end;
}
template<typename T>
Optional<T> convert_to_int(StringView str, TrimWhitespace trim_whitespace)
{
auto string = trim_whitespace == TrimWhitespace::Yes
? str.trim_whitespace()
: str;
if (string.is_empty())
return {};
T sign = 1;
size_t i = 0;
auto const characters = string.characters_without_null_termination();
if (characters[0] == '-' || characters[0] == '+') {
if (string.length() == 1)
return {};
i++;
if (characters[0] == '-')
sign = -1;
}
T value = 0;
for (; i < string.length(); i++) {
if (characters[i] < '0' || characters[i] > '9')
return {};
if (__builtin_mul_overflow(value, 10, &value))
return {};
if (__builtin_add_overflow(value, sign * (characters[i] - '0'), &value))
return {};
}
return value;
}
template Optional<i8> convert_to_int(StringView str, TrimWhitespace);
template Optional<i16> convert_to_int(StringView str, TrimWhitespace);
template Optional<i32> convert_to_int(StringView str, TrimWhitespace);
template Optional<long> convert_to_int(StringView str, TrimWhitespace);
template Optional<long long> convert_to_int(StringView str, TrimWhitespace);
template<typename T>
Optional<T> convert_to_uint(StringView str, TrimWhitespace trim_whitespace)
{
auto string = trim_whitespace == TrimWhitespace::Yes
? str.trim_whitespace()
: str;
if (string.is_empty())
return {};
T value = 0;
auto const characters = string.characters_without_null_termination();
for (size_t i = 0; i < string.length(); i++) {
if (characters[i] < '0' || characters[i] > '9')
return {};
if (__builtin_mul_overflow(value, 10, &value))
return {};
if (__builtin_add_overflow(value, characters[i] - '0', &value))
return {};
}
return value;
}
template Optional<u8> convert_to_uint(StringView str, TrimWhitespace);
template Optional<u16> convert_to_uint(StringView str, TrimWhitespace);
template Optional<u32> convert_to_uint(StringView str, TrimWhitespace);
template Optional<unsigned long> convert_to_uint(StringView str, TrimWhitespace);
template Optional<unsigned long long> convert_to_uint(StringView str, TrimWhitespace);
template<typename T>
Optional<T> convert_to_uint_from_hex(StringView str, TrimWhitespace trim_whitespace)
{
auto string = trim_whitespace == TrimWhitespace::Yes
? str.trim_whitespace()
: str;
if (string.is_empty())
return {};
T value = 0;
auto const count = string.length();
T const upper_bound = NumericLimits<T>::max();
for (size_t i = 0; i < count; i++) {
char digit = string[i];
u8 digit_val;
if (value > (upper_bound >> 4))
return {};
if (digit >= '0' && digit <= '9') {
digit_val = digit - '0';
} else if (digit >= 'a' && digit <= 'f') {
digit_val = 10 + (digit - 'a');
} else if (digit >= 'A' && digit <= 'F') {
digit_val = 10 + (digit - 'A');
} else {
return {};
}
value = (value << 4) + digit_val;
}
return value;
}
template Optional<u8> convert_to_uint_from_hex(StringView str, TrimWhitespace);
template Optional<u16> convert_to_uint_from_hex(StringView str, TrimWhitespace);
template Optional<u32> convert_to_uint_from_hex(StringView str, TrimWhitespace);
template Optional<u64> convert_to_uint_from_hex(StringView str, TrimWhitespace);
template<typename T>
Optional<T> convert_to_uint_from_octal(StringView str, TrimWhitespace trim_whitespace)
{
auto string = trim_whitespace == TrimWhitespace::Yes
? str.trim_whitespace()
: str;
if (string.is_empty())
return {};
T value = 0;
auto const count = string.length();
T const upper_bound = NumericLimits<T>::max();
for (size_t i = 0; i < count; i++) {
char digit = string[i];
u8 digit_val;
if (value > (upper_bound >> 3))
return {};
if (digit >= '0' && digit <= '7') {
digit_val = digit - '0';
} else {
return {};
}
value = (value << 3) + digit_val;
}
return value;
}
template Optional<u8> convert_to_uint_from_octal(StringView str, TrimWhitespace);
template Optional<u16> convert_to_uint_from_octal(StringView str, TrimWhitespace);
template Optional<u32> convert_to_uint_from_octal(StringView str, TrimWhitespace);
template Optional<u64> convert_to_uint_from_octal(StringView str, TrimWhitespace);
template<typename T>
Optional<T> convert_to_floating_point(StringView str, TrimWhitespace trim_whitespace)
{
static_assert(IsSame<T, double> || IsSame<T, float>);
auto string = trim_whitespace == TrimWhitespace::Yes
? str.trim_whitespace()
: str;
char const* start = string.characters_without_null_termination();
return parse_floating_point_completely<T>(start, start + string.length());
}
template Optional<double> convert_to_floating_point(StringView str, TrimWhitespace);
template Optional<float> convert_to_floating_point(StringView str, TrimWhitespace);
bool equals_ignoring_ascii_case(StringView a, StringView b)
{
if (a.length() != b.length())
@ -373,15 +213,19 @@ StringView trim_whitespace(StringView str, TrimMode mode)
return trim(str, " \n\t\v\f\r"sv, mode);
}
Optional<size_t> find(StringView haystack, char needle, size_t start)
Optional<size_t> find(StringView haystack, char needle, size_t start_offset)
{
if (start >= haystack.length())
if (start_offset >= haystack.length())
return {};
for (size_t i = start; i < haystack.length(); ++i) {
if (haystack[i] == needle)
return i;
}
return {};
auto const* start = haystack.characters_without_null_termination() + start_offset;
auto const* end = haystack.characters_without_null_termination() + haystack.length();
auto const* result = simdutf::find(start, end, needle);
if (result == end)
return {};
return result - start + start_offset;
}
Optional<size_t> find(StringView haystack, StringView needle, size_t start)

View File

@ -76,16 +76,6 @@ struct MaskSpan {
namespace StringUtils {
bool matches(StringView str, StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive, Vector<MaskSpan>* match_spans = nullptr);
template<typename T = int>
Optional<T> convert_to_int(StringView, TrimWhitespace = TrimWhitespace::Yes);
template<typename T = unsigned>
Optional<T> convert_to_uint(StringView, TrimWhitespace = TrimWhitespace::Yes);
template<typename T = unsigned>
Optional<T> convert_to_uint_from_hex(StringView, TrimWhitespace = TrimWhitespace::Yes);
template<typename T = unsigned>
Optional<T> convert_to_uint_from_octal(StringView, TrimWhitespace = TrimWhitespace::Yes);
template<typename T>
Optional<T> convert_to_floating_point(StringView, TrimWhitespace = TrimWhitespace::Yes);
bool equals_ignoring_ascii_case(StringView, StringView);
bool ends_with(StringView a, StringView b, CaseSensitivity);
bool starts_with(StringView, StringView, CaseSensitivity);

View File

@ -47,8 +47,8 @@ StringView::StringView(ByteBuffer const& buffer)
Vector<StringView> StringView::split_view(char const separator, SplitBehavior split_behavior) const
{
StringView seperator_view { &separator, 1 };
return split_view(seperator_view, split_behavior);
StringView separator_view { &separator, 1 };
return split_view(separator_view, split_behavior);
}
Vector<StringView> StringView::split_view(StringView separator, SplitBehavior split_behavior) const
@ -212,7 +212,7 @@ String StringView::to_ascii_lowercase_string() const
String result;
MUST(result.replace_with_new_string({}, length(), [&](Bytes buffer) -> ErrorOr<void> {
MUST(result.replace_with_new_string(Badge<StringView> {}, length(), [&](Bytes buffer) -> ErrorOr<void> {
for (auto [i, character] : enumerate(bytes()))
buffer[i] = static_cast<u8>(AK::to_ascii_lowercase(character));
return {};
@ -227,7 +227,7 @@ String StringView::to_ascii_uppercase_string() const
String result;
MUST(result.replace_with_new_string({}, length(), [&](Bytes buffer) -> ErrorOr<void> {
MUST(result.replace_with_new_string(Badge<StringView> {}, length(), [&](Bytes buffer) -> ErrorOr<void> {
for (auto [i, character] : enumerate(bytes()))
buffer[i] = static_cast<u8>(AK::to_ascii_uppercase(character));
return {};

View File

@ -14,6 +14,7 @@
#include <AK/Optional.h>
#include <AK/Span.h>
#include <AK/StdLibExtras.h>
#include <AK/StringConversions.h>
#include <AK/StringHash.h>
#include <AK/StringUtils.h>
@ -44,10 +45,10 @@ public:
{
}
StringView(ByteBuffer const&);
StringView(String const&);
StringView(FlyString const&);
StringView(ByteString const&);
StringView(LIFETIME_BOUND ByteBuffer const&);
StringView(LIFETIME_BOUND String const&);
StringView(LIFETIME_BOUND FlyString const&);
StringView(LIFETIME_BOUND ByteString const&);
explicit StringView(ByteBuffer&&) = delete;
explicit StringView(String&&) = delete;
@ -152,8 +153,8 @@ public:
template<typename Callback>
auto for_each_split_view(char separator, SplitBehavior split_behavior, Callback callback) const
{
StringView seperator_view { &separator, 1 };
return for_each_split_view(seperator_view, split_behavior, callback);
StringView separator_view { &separator, 1 };
return for_each_split_view(separator_view, split_behavior, callback);
}
template<typename Callback>
@ -347,14 +348,9 @@ public:
}
template<Arithmetic T>
Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes) const
Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes, int base = 10) const
{
if constexpr (IsFloatingPoint<T>)
return StringUtils::convert_to_floating_point<T>(*this, trim_whitespace);
if constexpr (IsSigned<T>)
return StringUtils::convert_to_int<T>(*this, trim_whitespace);
else
return StringUtils::convert_to_uint<T>(*this, trim_whitespace);
return parse_number<T>(*this, trim_whitespace, base);
}
private:

View File

@ -9,7 +9,7 @@
#if __has_include(<swift/bridging>)
# include <swift/bridging>
// FIXME: Workaround for Xcode 14/15. When swif becomes required, we should bump the
// required Xcode verison to one that supports all the features we are using.
// required Xcode version to one that supports all the features we are using.
# ifndef SWIFT_UNCHECKED_SENDABLE
# define SWIFT_UNCHECKED_SENDABLE
# define SWIFT_NONCOPYABLE

View File

@ -6,10 +6,19 @@
*/
#include <AK/Checked.h>
#include <AK/DateConstants.h>
#include <AK/GenericLexer.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Time.h>
#include <AK/Utf16String.h>
#ifdef AK_OS_WINDOWS
# include <AK/Windows.h>
# define localtime_r(time, tm) localtime_s(tm, time)
# define gmtime_r(time, tm) gmtime_s(tm, time)
# define tzname _tzname
# define timegm _mkgmtime
#endif
namespace AK {
@ -117,6 +126,12 @@ i64 Duration::to_seconds() const
return m_seconds;
}
f64 Duration::to_seconds_f64() const
{
VERIFY(m_nanoseconds < 1'000'000'000);
return static_cast<double>(m_seconds) + (m_nanoseconds / 1'000'000'000.0);
}
i64 Duration::to_milliseconds() const
{
VERIFY(m_nanoseconds < 1'000'000'000);
@ -275,23 +290,34 @@ MonotonicTime MonotonicTime::now_coarse()
UnixDateTime UnixDateTime::from_iso8601_week(u32 week_year, u32 week)
{
auto january_1_weekday = day_of_week(week_year, 1, 1);
i32 offset_to_monday = (january_1_weekday <= 3) ? -january_1_weekday : 7 - january_1_weekday;
i32 first_monday_of_year = 1 + offset_to_monday;
i32 day_of_year = (first_monday_of_year + (week - 1) * 7) + 1;
auto day_of_week_january_4th = (day_of_week(week_year, 1, 4) + 6) % 7;
int ordinal_day = (7 * week) - day_of_week_january_4th - 3;
// FIXME: There should be a more efficient way to do this that doesn't require a loop.
u8 month = 1;
while (true) {
auto days = days_in_month(week_year, month);
if (day_of_year <= days)
break;
if (ordinal_day < 1)
return UnixDateTime::from_ordinal_date(week_year - 1, ordinal_day + days_in_year(week_year - 1));
if (auto days_in_week_year = days_in_year(week_year); static_cast<unsigned>(ordinal_day) > days_in_week_year)
return UnixDateTime::from_ordinal_date(week_year + 1, ordinal_day - days_in_week_year);
return UnixDateTime::from_ordinal_date(week_year, ordinal_day);
}
day_of_year -= days;
++month;
}
UnixDateTime UnixDateTime::from_ordinal_date(u32 year, u32 day)
{
static constexpr Array<u32, 12> month_starts_normal = { 1, 32, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 };
static constexpr Array<u32, 12> month_starts_leap = { 1, 32, 61, 92, 122, 153, 183, 214, 245, 275, 306, 336 };
return UnixDateTime::from_unix_time_parts(week_year, month, static_cast<u8>(day_of_year), 0, 0, 0, 0);
auto const& month_starts = is_leap_year(year) ? month_starts_leap : month_starts_normal;
// Estimate month using integer division (approx 30.6 days per month)
auto estimated_month = (day * 12 + 6) / 367; // Gives 0-based month index
// Correct month if estimate overshot
if (day < month_starts[estimated_month])
--estimated_month;
auto month = estimated_month + 1; // convert to 1-based month
auto day_of_month = day - month_starts[estimated_month] + 1;
return UnixDateTime::from_unix_time_parts(year, month, day_of_month, 0, 0, 0, 0);
}
UnixDateTime UnixDateTime::now()
@ -304,4 +330,442 @@ UnixDateTime UnixDateTime::now_coarse()
return UnixDateTime { now_time_from_clock(CLOCK_REALTIME_COARSE) };
}
ErrorOr<void> UnixDateTime::to_string_impl(StringBuilder& builder, StringView format, LocalTime local_time) const
{
struct tm tm;
auto timestamp = m_offset.to_timespec().tv_sec;
if (local_time == LocalTime::Yes)
(void)localtime_r(&timestamp, &tm);
else
(void)gmtime_r(&timestamp, &tm);
size_t const format_len = format.length();
for (size_t i = 0; i < format_len; ++i) {
if (format[i] != '%') {
TRY(builder.try_append(format[i]));
} else {
if (++i == format_len) {
builder.clear();
return {};
}
switch (format[i]) {
case 'a':
TRY(builder.try_append(short_day_names[tm.tm_wday]));
break;
case 'A':
TRY(builder.try_append(long_day_names[tm.tm_wday]));
break;
case 'b':
TRY(builder.try_append(short_month_names[tm.tm_mon]));
break;
case 'B':
TRY(builder.try_append(long_month_names[tm.tm_mon]));
break;
case 'C':
TRY(builder.try_appendff("{:02}", (tm.tm_year + 1900) / 100));
break;
case 'd':
TRY(builder.try_appendff("{:02}", tm.tm_mday));
break;
case 'D':
TRY(builder.try_appendff("{:02}/{:02}/{:02}", tm.tm_mon + 1, tm.tm_mday, (tm.tm_year + 1900) % 100));
break;
case 'e':
TRY(builder.try_appendff("{:2}", tm.tm_mday));
break;
case 'h':
TRY(builder.try_append(short_month_names[tm.tm_mon]));
break;
case 'H':
TRY(builder.try_appendff("{:02}", tm.tm_hour));
break;
case 'I': {
int display_hour = tm.tm_hour % 12;
if (display_hour == 0)
display_hour = 12;
TRY(builder.try_appendff("{:02}", display_hour));
break;
}
case 'j':
TRY(builder.try_appendff("{:03}", tm.tm_yday + 1));
break;
case 'l': {
int display_hour = tm.tm_hour % 12;
if (display_hour == 0)
display_hour = 12;
TRY(builder.try_appendff("{:2}", display_hour));
break;
}
case 'm':
TRY(builder.try_appendff("{:02}", tm.tm_mon + 1));
break;
case 'M':
TRY(builder.try_appendff("{:02}", tm.tm_min));
break;
case 'n':
TRY(builder.try_append('\n'));
break;
case 'p':
TRY(builder.try_append(tm.tm_hour < 12 ? "AM"sv : "PM"sv));
break;
case 'r': {
int display_hour = tm.tm_hour % 12;
if (display_hour == 0)
display_hour = 12;
TRY(builder.try_appendff("{:02}:{:02}:{:02} {}", display_hour, tm.tm_min, tm.tm_sec, tm.tm_hour < 12 ? "AM" : "PM"));
break;
}
case 'R':
TRY(builder.try_appendff("{:02}:{:02}", tm.tm_hour, tm.tm_min));
break;
case 'S':
TRY(builder.try_appendff("{:02}", tm.tm_sec));
break;
case 't':
TRY(builder.try_append('\t'));
break;
case 'T':
TRY(builder.try_appendff("{:02}:{:02}:{:02}", tm.tm_hour, tm.tm_min, tm.tm_sec));
break;
case 'u':
TRY(builder.try_appendff("{}", tm.tm_wday ? tm.tm_wday : 7));
break;
case 'U': {
int const wday_of_year_beginning = (tm.tm_wday + 6 * tm.tm_yday) % 7;
int const week_number = (tm.tm_yday + wday_of_year_beginning) / 7;
TRY(builder.try_appendff("{:02}", week_number));
break;
}
case 'V': {
int const wday_of_year_beginning = (tm.tm_wday + 6 + 6 * tm.tm_yday) % 7;
int week_number = ((tm.tm_yday + wday_of_year_beginning) / 7) + 1;
if (wday_of_year_beginning > 3) {
if (tm.tm_yday >= 7 - wday_of_year_beginning) {
--week_number;
} else {
int const days_of_last_year = days_in_year(tm.tm_year + 1900 - 1);
int const wday_of_last_year_beginning = (wday_of_year_beginning + 6 * days_of_last_year) % 7;
week_number = (days_of_last_year + wday_of_last_year_beginning) / 7 + 1;
if (wday_of_last_year_beginning > 3)
--week_number;
}
}
TRY(builder.try_appendff("{:02}", week_number));
break;
}
case 'w':
TRY(builder.try_appendff("{}", tm.tm_wday));
break;
case 'W': {
int const wday_of_year_beginning = (tm.tm_wday + 6 + 6 * tm.tm_yday) % 7;
int const week_number = (tm.tm_yday + wday_of_year_beginning) / 7;
TRY(builder.try_appendff("{:02}", week_number));
break;
}
case 'y':
TRY(builder.try_appendff("{:02}", (tm.tm_year + 1900) % 100));
break;
case 'Y':
TRY(builder.try_appendff("{}", tm.tm_year + 1900));
break;
case 'Z': {
auto const* timezone_name = tzname[tm.tm_isdst == 0 ? 0 : 1];
TRY(builder.try_append(StringView { timezone_name, strlen(timezone_name) }));
break;
}
case '%':
TRY(builder.try_append('%'));
break;
default:
TRY(builder.try_append('%'));
TRY(builder.try_append(format[i]));
break;
}
}
}
return {};
}
ErrorOr<String> UnixDateTime::to_string(StringView format, LocalTime local_time) const
{
StringBuilder builder;
TRY(to_string_impl(builder, format, local_time));
return builder.to_string();
}
Utf16String UnixDateTime::to_utf16_string(StringView format, LocalTime local_time) const
{
StringBuilder builder(StringBuilder::Mode::UTF16);
MUST(to_string_impl(builder, format, local_time));
return builder.to_utf16_string();
}
ByteString UnixDateTime::to_byte_string(StringView format, LocalTime local_time) const
{
StringBuilder builder;
MUST(to_string_impl(builder, format, local_time));
return builder.to_byte_string();
}
Optional<UnixDateTime> UnixDateTime::parse(StringView format, StringView string, bool from_gmt)
{
unsigned format_pos = 0;
struct tm tm = {};
tm.tm_isdst = -1;
auto parsing_failed = false;
GenericLexer string_lexer(string);
auto parse_number = [&] {
auto result = string_lexer.consume_decimal_integer<int>();
if (result.is_error()) {
parsing_failed = true;
return 0;
}
return result.value();
};
auto consume = [&](char c) {
if (!string_lexer.consume_specific(c))
parsing_failed = true;
};
auto consume_specific_ascii_case_insensitive = [&](StringView name) {
auto next_string = string_lexer.peek_string(name.length());
if (next_string.has_value() && next_string->equals_ignoring_ascii_case(name)) {
string_lexer.consume(name.length());
return true;
}
return false;
};
while (format_pos < format.length() && !string_lexer.is_eof()) {
if (format[format_pos] != '%') {
consume(format[format_pos]);
format_pos++;
continue;
}
format_pos++;
if (format_pos == format.length())
return {};
switch (format[format_pos]) {
case 'a': {
auto wday = 0;
for (auto name : short_day_names) {
if (consume_specific_ascii_case_insensitive(name)) {
tm.tm_wday = wday;
break;
}
++wday;
}
if (wday == 7)
return {};
break;
}
case 'A': {
auto wday = 0;
for (auto name : long_day_names) {
if (consume_specific_ascii_case_insensitive(name)) {
tm.tm_wday = wday;
break;
}
++wday;
}
if (wday == 7)
return {};
break;
}
case 'h':
case 'b': {
auto mon = 0;
for (auto name : short_month_names) {
if (consume_specific_ascii_case_insensitive(name)) {
tm.tm_mon = mon;
break;
}
++mon;
}
if (mon == 12)
return {};
break;
}
case 'B': {
auto mon = 0;
for (auto name : long_month_names) {
if (consume_specific_ascii_case_insensitive(name)) {
tm.tm_mon = mon;
break;
}
++mon;
}
if (mon == 12)
return {};
break;
}
case 'C': {
int num = parse_number();
tm.tm_year = (num - 19) * 100 + (tm.tm_year % 100);
break;
}
case 'd':
tm.tm_mday = parse_number();
break;
case 'D': {
int mon = parse_number();
consume('/');
int day = parse_number();
consume('/');
int year = parse_number();
tm.tm_mon = mon - 1;
tm.tm_mday = day;
tm.tm_year = year > 1900 ? year - 1900 : (year <= 99 && year > 69 ? year : 100 + year);
break;
}
case 'e':
tm.tm_mday = parse_number();
break;
case 'H':
tm.tm_hour = parse_number();
break;
case 'I': {
int num = parse_number();
tm.tm_hour = num % 12;
break;
}
case 'j':
// a little trickery here... we can get mktime() to figure out mon and mday using out of range values.
// yday is not used so setting it is pointless.
tm.tm_mday = parse_number();
tm.tm_mon = 0;
(void)mktime(&tm);
break;
case 'm': {
int num = parse_number();
tm.tm_mon = num - 1;
break;
}
case 'M':
tm.tm_min = parse_number();
break;
case 'n':
case 't':
string_lexer.consume_while(is_ascii_space);
break;
case 'r':
case 'p': {
auto ampm = string_lexer.consume(2);
if (ampm == "PM") {
if (tm.tm_hour < 12)
tm.tm_hour += 12;
} else if (ampm != "AM") {
return {};
}
break;
}
case 'R':
tm.tm_hour = parse_number();
consume(':');
tm.tm_min = parse_number();
break;
case 'S':
tm.tm_sec = parse_number();
break;
case 'T':
tm.tm_hour = parse_number();
consume(':');
tm.tm_min = parse_number();
consume(':');
tm.tm_sec = parse_number();
break;
case 'w':
tm.tm_wday = parse_number();
break;
case 'y': {
int year = parse_number();
tm.tm_year = year <= 99 && year > 69 ? 1900 + year : 2000 + year;
break;
}
case 'Y': {
int year = parse_number();
tm.tm_year = year - 1900;
break;
}
case 'x': {
auto hours = parse_number();
int minutes;
if (string_lexer.consume_specific(':')) {
minutes = parse_number();
} else {
minutes = hours % 100;
hours = hours / 100;
}
tm.tm_hour -= hours;
tm.tm_min -= minutes;
break;
}
case 'X': {
if (!string_lexer.consume_specific('.'))
return {};
auto discarded = parse_number();
(void)discarded; // NOTE: the tm structure does not support sub second precision, so drop this value.
break;
}
case '+': {
Optional<char> next_format_character;
if (format_pos + 1 < format.length()) {
next_format_character = format[format_pos + 1];
// Disallow another formatter directly after %+. This is to avoid ambiguity when parsing a string like
// "ignoreJan" with "%+%b", as it would be non-trivial to know that where the %b field begins.
if (next_format_character == '%')
return {};
}
auto discarded = string_lexer.consume_until([&](auto ch) { return ch == next_format_character; });
if (discarded.is_empty())
return {};
break;
}
case '%':
consume('%');
break;
default:
parsing_failed = true;
break;
}
if (parsing_failed)
return {};
format_pos++;
}
if (!string_lexer.is_eof() || format_pos != format.length())
return {};
if (from_gmt) {
// When from_gmt is true, the parsed time is in GMT and needs to be converted to Unix time
tm.tm_isdst = 0; // GMT doesn't have daylight saving time
auto gmt_time = timegm(&tm);
if (gmt_time == -1)
return {};
return UnixDateTime::from_seconds_since_epoch(gmt_time);
}
return UnixDateTime::from_unix_time_parts(
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, 0);
}
}

View File

@ -11,8 +11,12 @@
#include <AK/Badge.h>
#include <AK/Checked.h>
#include <AK/Platform.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Types.h>
#ifdef AK_OS_WINDOWS
# include <time.h>
// https://learn.microsoft.com/en-us/windows/win32/api/winsock/ns-winsock-timeval
struct timeval {
long tv_sec { 0 };
@ -73,14 +77,14 @@ constexpr int day_of_year(int year, unsigned month, int day)
// Month starts at 1. Month must be >= 1 and <= 12.
int days_in_month(int year, unsigned month);
constexpr int days_in_year(int year)
constexpr unsigned int days_in_year(int year)
{
return 365 + (is_leap_year(year) ? 1 : 0);
}
constexpr int weeks_in_year(int year)
constexpr unsigned int iso8061_weeks_in_year(int year)
{
return is_leap_year(year) ? 53 : 52;
return day_of_week(year, 12, 31) == 4 || day_of_week(year - 1, 12, 31) == 3 ? 53 : 52;
}
namespace Detail {
@ -238,6 +242,7 @@ public:
[[nodiscard]] i64 to_truncated_microseconds() const;
// Rounds away from zero (2.3s to 3s, -2.3s to -3s).
[[nodiscard]] i64 to_seconds() const;
[[nodiscard]] f64 to_seconds_f64() const;
[[nodiscard]] i64 to_milliseconds() const;
[[nodiscard]] i64 to_microseconds() const;
[[nodiscard]] i64 to_nanoseconds() const;
@ -390,6 +395,9 @@ public:
// Creates UNIX time from an ISO 8601 Week, such as 2025-W06, with year 2025 and week 6.
[[nodiscard]] static UnixDateTime from_iso8601_week(u32 year, u32 week);
// Creates UNIX time from an ordinal date, such as 2025-100, with year 2025 and day 100.
[[nodiscard]] static UnixDateTime from_ordinal_date(u32 year, u32 day);
// Creates UNIX time from a unix timestamp.
// Note that the returned time is probably not equivalent to the same timestamp in UTC time, since UNIX time does not observe leap seconds.
[[nodiscard]] constexpr static UnixDateTime from_unix_time_parts(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond)
@ -438,6 +446,45 @@ public:
// Never returns a point after this UnixDateTime, since fractional seconds are cut off.
[[nodiscard]] i64 truncated_seconds_since_epoch() const { return m_offset.to_truncated_seconds(); }
enum class LocalTime {
Yes,
No,
};
// %a: require short day name
// %A: require long day name
// %h/b: require short month name
// %B: require long month name
// %C: require short year number (hundreds) (ex: 19 -> 1900)
// %d: require day number
// %D: require month number/day number/short year number (ex: 12/31/24)
// %e: require day number
// %H: require hour (24h format)
// %I: require hour (12h format)
// %j: require defining date with day number ? (not sure)
// %m: require set to month entred - 1
// %M: require minutes
// %n: require newline
// %t: require tab
// %r/p: require AM | PM
// %R: require hours:minutes (ex: 13:57)
// %S: require seconds
// %T: require hours:minutes:seconds (ex: 13:57:34)
// %w: require week day number
// %y: require 2 digits year (69 < year < 99: in the 1900 else in 2000)
// %Y: require full year
// %x: require single number to represent hour and minutes
// %X: require sub second precision
// %Z: require timezone name
// %+: ignore until next '%'
// %%: require character '%'
ErrorOr<String> to_string(StringView format = "%Y-%m-%d %H:%M:%S"sv, LocalTime = LocalTime::Yes) const;
Utf16String to_utf16_string(StringView format = "%Y-%m-%d %H:%M:%S"sv, LocalTime = LocalTime::Yes) const;
ByteString to_byte_string(StringView format = "%Y-%m-%d %H:%M:%S"sv, LocalTime = LocalTime::Yes) const;
// Parses a string in the given format. Does not support time zone-related format specifiers.
// If 'from_gmt' is true, the string is parsed as a GMT time, otherwise it is parsed as a local time.
static Optional<UnixDateTime> parse(StringView format, StringView string, bool from_gmt = false);
// Offsetting a UNIX time by a duration yields another UNIX time.
constexpr UnixDateTime operator+(Duration const& other) const { return UnixDateTime { m_offset + other }; }
constexpr UnixDateTime& operator+=(Duration const& other)
@ -470,6 +517,8 @@ private:
: Detail::UnawareTime(offset)
{
}
ErrorOr<void> to_string_impl(StringBuilder&, StringView format, LocalTime) const;
};
// Monotonic time represents time returned from the CLOCK_MONOTONIC clock, which has an arbitrary fixed reference point.
@ -591,6 +640,25 @@ constexpr Duration operator""_sec(unsigned long long seconds) { return Duration:
}
template<>
struct Formatter<UnixDateTime> : StandardFormatter {
ErrorOr<void> format(FormatBuilder& builder, UnixDateTime const& value)
{
auto result_time = value.to_timespec().tv_sec;
struct tm tm;
#ifdef AK_OS_WINDOWS
if (gmtime_s(&tm, &result_time) != 0)
#else
if (gmtime_r(&result_time, &tm) == nullptr)
#endif
return Error::from_string_literal("Formatter<UnixDateTime>::format gmtime_r failed");
return builder.builder().try_appendff("{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
}
};
}
#if USING_AK_GLOBALLY
@ -600,6 +668,7 @@ using AK::days_in_month;
using AK::days_in_year;
using AK::days_since_epoch;
using AK::is_leap_year;
using AK::iso8061_weeks_in_year;
using AK::MonotonicTime;
using AK::seconds_since_epoch_to_year;
using AK::timespec_add;
@ -610,6 +679,5 @@ using AK::timeval_add;
using AK::timeval_sub;
using AK::timeval_to_timespec;
using AK::UnixDateTime;
using AK::weeks_in_year;
using AK::years_to_days_since_epoch;
#endif

View File

@ -23,6 +23,9 @@ struct DefaultTraits {
static constexpr bool equals(T const& a, T const& b) { return a == b; }
template<Concepts::HashCompatible<T> U>
static bool equals(T const& self, U const& other) { return self == other; }
// NOTE: Override this to say false if your type has a fast equality check.
// If equality checks are fast, we won't store hashes in HashTable/HashMap,
static constexpr bool may_have_slow_equality_check() { return true; }
};
template<typename T>
@ -38,6 +41,8 @@ template<Integral T>
struct Traits<T> : public DefaultTraits<T> {
static constexpr bool is_trivial() { return true; }
static constexpr bool is_trivially_serializable() { return true; }
// NOTE: Trivial types always have fast equality checks.
static constexpr bool may_have_slow_equality_check() { return false; }
static unsigned hash(T value)
{
if constexpr (sizeof(T) < 8)
@ -51,6 +56,7 @@ template<FloatingPoint T>
struct Traits<T> : public DefaultTraits<T> {
static constexpr bool is_trivial() { return true; }
static constexpr bool is_trivially_serializable() { return true; }
static constexpr bool may_have_slow_equality_check() { return false; }
static unsigned hash(T value)
{
if constexpr (sizeof(T) < 8)
@ -64,12 +70,16 @@ template<typename T>
requires(IsPointer<T> && !Detail::IsPointerOfType<char, T>) struct Traits<T> : public DefaultTraits<T> {
static unsigned hash(T p) { return ptr_hash(bit_cast<FlatPtr>(p)); }
static constexpr bool is_trivial() { return true; }
// NOTE: Trivial types always have fast equality checks.
static constexpr bool may_have_slow_equality_check() { return false; }
};
template<Enum T>
struct Traits<T> : public DefaultTraits<T> {
static unsigned hash(T value) { return Traits<UnderlyingType<T>>::hash(to_underlying(value)); }
static constexpr bool is_trivial() { return Traits<UnderlyingType<T>>::is_trivial(); }
// NOTE: Trivial types always have fast equality checks.
static constexpr bool may_have_slow_equality_check() { return !is_trivial(); }
static constexpr bool is_trivially_serializable() { return Traits<UnderlyingType<T>>::is_trivially_serializable(); }
};
@ -78,6 +88,8 @@ requires(Detail::IsPointerOfType<char, T>) struct Traits<T> : public DefaultTrai
static unsigned hash(T const value) { return string_hash(value, strlen(value)); }
static constexpr bool equals(T const a, T const b) { return strcmp(a, b); }
static constexpr bool is_trivial() { return true; }
// NOTE: Trivial types always have fast equality checks.
static constexpr bool may_have_slow_equality_check() { return false; }
};
}

View File

@ -59,7 +59,7 @@ private:
};
template<typename T, typename... TRest>
struct Tuple<T, TRest...> : Tuple<TRest...> {
struct AK_COMPACT_EMPTY_BASES Tuple<T, TRest...> : Tuple<TRest...> {
template<typename FirstT, typename... RestT>
Tuple(FirstT&& first, RestT&&... rest)
@ -113,7 +113,7 @@ private:
namespace AK {
template<typename... Ts>
struct Tuple : Detail::Tuple<Ts...> {
struct AK_COMPACT_EMPTY_BASES Tuple : Detail::Tuple<Ts...> {
using Types = TypeList<Ts...>;
using Detail::Tuple<Ts...>::Tuple;
using Indices = MakeIndexSequence<sizeof...(Ts)>;

View File

@ -16,9 +16,9 @@ namespace AK {
template<typename OutputType, typename InputType>
ALWAYS_INLINE bool is(InputType& input)
{
static_assert(!SameAs<OutputType, InputType>);
if constexpr (requires { input.template fast_is<OutputType>(); }) {
return input.template fast_is<OutputType>();
static_assert(!SameAs<RemoveCVReference<OutputType>, RemoveCVReference<InputType>>);
if constexpr (requires { input.template fast_is<RemoveCVReference<OutputType>>(); }) {
return input.template fast_is<RemoveCVReference<OutputType>>();
}
return dynamic_cast<CopyConst<InputType, OutputType>*>(&input);
}
@ -40,11 +40,10 @@ ALWAYS_INLINE CopyConst<InputType, OutputType>* as_if(InputType& input)
{
if (!is<OutputType>(input))
return nullptr;
if constexpr (IsBaseOf<InputType, OutputType>) {
if constexpr (requires { static_cast<CopyConst<InputType, OutputType>*>(&input); }) {
return static_cast<CopyConst<InputType, OutputType>*>(&input);
} else {
return dynamic_cast<CopyConst<InputType, OutputType>*>(&input);
}
return dynamic_cast<CopyConst<InputType, OutputType>*>(&input);
}
template<typename OutputType, typename InputType>

View File

@ -56,7 +56,7 @@ public:
static bool compare(T const* a, T const* b, size_t count)
{
if (count == 0)
if (count == 0 || a == b)
return true;
if constexpr (Traits<T>::is_trivial())

View File

@ -181,12 +181,12 @@ public:
}
}
Bytes bytes()
Bytes bytes() LIFETIME_BOUND
{
return Bytes(reinterpret_cast<u8*>(this), sizeof(Storage));
}
ReadonlyBytes bytes() const
ReadonlyBytes bytes() const LIFETIME_BOUND
{
return ReadonlyBytes(reinterpret_cast<u8 const*>(this), sizeof(Storage));
}

View File

@ -78,11 +78,92 @@ template<FallibleFunction<char> Callback>
return -1;
}
constexpr inline u16 HIGH_SURROGATE_MIN = 0xd800;
constexpr inline u16 HIGH_SURROGATE_MAX = 0xdbff;
constexpr inline u16 LOW_SURROGATE_MIN = 0xdc00;
constexpr inline u16 LOW_SURROGATE_MAX = 0xdfff;
constexpr inline u32 REPLACEMENT_CODE_POINT = 0xfffd;
constexpr inline u32 FIRST_SUPPLEMENTARY_PLANE_CODE_POINT = 0x10000;
enum class AllowLonelySurrogates {
No,
Yes,
};
[[nodiscard]] constexpr size_t code_unit_length_for_code_point(u32 code_point)
{
return code_point < FIRST_SUPPLEMENTARY_PLANE_CODE_POINT ? 1uz : 2uz;
}
[[nodiscard]] constexpr bool is_utf16_high_surrogate(u16 code_unit)
{
return (code_unit >= HIGH_SURROGATE_MIN) && (code_unit <= HIGH_SURROGATE_MAX);
}
[[nodiscard]] constexpr bool is_utf16_low_surrogate(u16 code_unit)
{
return (code_unit >= LOW_SURROGATE_MIN) && (code_unit <= LOW_SURROGATE_MAX);
}
[[nodiscard]] constexpr u32 decode_utf16_surrogate_pair(u16 high_surrogate, u16 low_surrogate)
{
VERIFY(is_utf16_high_surrogate(high_surrogate));
VERIFY(is_utf16_low_surrogate(low_surrogate));
return ((high_surrogate - HIGH_SURROGATE_MIN) << 10) + (low_surrogate - LOW_SURROGATE_MIN) + FIRST_SUPPLEMENTARY_PLANE_CODE_POINT;
}
template<typename Callback>
[[nodiscard]] constexpr size_t code_point_to_utf16(u32 code_point, Callback callback)
{
if (code_point < FIRST_SUPPLEMENTARY_PLANE_CODE_POINT) {
callback(static_cast<char16_t>(code_point));
return 1uz;
}
if (code_point <= 0x10ffff) {
code_point -= FIRST_SUPPLEMENTARY_PLANE_CODE_POINT;
auto code_unit = static_cast<u16>(HIGH_SURROGATE_MIN | (code_point >> 10));
callback(static_cast<char16_t>(code_unit));
code_unit = static_cast<u16>(LOW_SURROGATE_MIN | (code_point & 0x3ff));
callback(static_cast<char16_t>(code_unit));
return 2uz;
}
VERIFY_NOT_REACHED();
}
template<FallibleFunction<char16_t> Callback>
ALWAYS_INLINE ErrorOr<size_t> try_code_point_to_utf16(u32 code_point, Callback callback)
{
if (code_point < FIRST_SUPPLEMENTARY_PLANE_CODE_POINT) {
TRY(callback(static_cast<char16_t>(code_point)));
return 1uz;
}
if (code_point <= 0x10ffff) {
code_point -= FIRST_SUPPLEMENTARY_PLANE_CODE_POINT;
auto code_unit = static_cast<u16>(HIGH_SURROGATE_MIN | (code_point >> 10));
TRY(callback(static_cast<char16_t>(code_unit)));
code_unit = static_cast<u16>(LOW_SURROGATE_MIN | (code_point & 0x3ff));
TRY(callback(static_cast<char16_t>(code_unit)));
return 2uz;
}
VERIFY_NOT_REACHED();
}
/**
* Compute the maximum number of UTF-8 bytes needed to store a given UTF-16 string, accounting for unmatched UTF-16 surrogates.
* This function will overcount by at most 33%; 2 bytes for every valid UTF-16 codepoint between U+100000 and U+10FFFF.
*/
[[nodiscard]] static inline size_t maximum_utf8_length_from_utf16(ReadonlySpan<u16> code_units)
[[nodiscard]] static inline size_t maximum_utf8_length_from_utf16(ReadonlySpan<char16_t> code_units)
{
// # UTF-8 code point -> no. UTF-8 bytes needed
// U+0000 - U+007F => 1 UTF-8 bytes
@ -125,3 +206,7 @@ template<FallibleFunction<char> Callback>
}
}
#if USING_AK_GLOBALLY
using AK::UnicodeUtils::AllowLonelySurrogates;
#endif

103
AK/Utf16FlyString.cpp Normal file
View File

@ -0,0 +1,103 @@
/*
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/HashTable.h>
#include <AK/Singleton.h>
#include <AK/Utf16FlyString.h>
namespace AK {
struct Utf16FlyStringTableHashTraits : public Traits<Detail::Utf16StringData const*> {
static u32 hash(Detail::Utf16StringData const* string) { return string->hash(); }
static bool equals(Detail::Utf16StringData const* a, Detail::Utf16StringData const* b) { return *a == *b; }
};
static auto& all_utf16_fly_strings()
{
static Singleton<HashTable<Detail::Utf16StringData const*, Utf16FlyStringTableHashTraits>> table;
return *table;
}
namespace Detail {
void did_destroy_utf16_fly_string_data(Badge<Detail::Utf16StringData>, Detail::Utf16StringData const& data)
{
all_utf16_fly_strings().remove(&data);
}
}
template<typename ViewType>
Optional<Utf16FlyString> Utf16FlyString::create_fly_string_from_cache(ViewType const& string)
{
if (string.is_empty())
return {};
if constexpr (IsSame<ViewType, StringView>) {
if (string.length() <= Detail::MAX_SHORT_STRING_BYTE_COUNT && string.is_ascii())
return Utf16String::from_utf8_without_validation(string);
} else {
if (string.length_in_code_units() <= Detail::MAX_SHORT_STRING_BYTE_COUNT && string.is_ascii())
return Utf16String::from_utf16(string);
}
if (auto it = all_utf16_fly_strings().find(string.hash(), [&](auto const& entry) { return *entry == string; }); it != all_utf16_fly_strings().end())
return Utf16FlyString { Detail::Utf16StringBase(**it) };
return {};
}
Utf16FlyString Utf16FlyString::from_utf8(StringView string)
{
if (auto result = create_fly_string_from_cache(string); result.has_value())
return result.release_value();
return Utf16String::from_utf8(string);
}
Utf16FlyString Utf16FlyString::from_utf8_without_validation(StringView string)
{
if (auto result = create_fly_string_from_cache(string); result.has_value())
return result.release_value();
return Utf16String::from_utf8_without_validation(string);
}
Utf16FlyString Utf16FlyString::from_utf16(Utf16View const& string)
{
if (auto result = create_fly_string_from_cache(string); result.has_value())
return result.release_value();
return Utf16String::from_utf16(string);
}
Utf16FlyString::Utf16FlyString(Utf16String const& string)
{
if (string.has_short_ascii_storage()) {
m_data = string;
return;
}
auto const* data = string.data({});
if (data->is_fly_string()) {
m_data = string;
return;
}
if (auto it = all_utf16_fly_strings().find(data); it == all_utf16_fly_strings().end()) {
m_data = string;
all_utf16_fly_strings().set(data);
data->mark_as_fly_string({});
} else {
m_data.set_data({}, *it);
}
}
size_t Utf16FlyString::number_of_utf16_fly_strings()
{
return all_utf16_fly_strings().size();
}
}

294
AK/Utf16FlyString.h Normal file
View File

@ -0,0 +1,294 @@
/*
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Format.h>
#include <AK/Optional.h>
#include <AK/Traits.h>
#include <AK/Utf16String.h>
namespace AK {
class [[nodiscard]] Utf16FlyString {
AK_MAKE_DEFAULT_MOVABLE(Utf16FlyString);
AK_MAKE_DEFAULT_COPYABLE(Utf16FlyString);
public:
constexpr Utf16FlyString() = default;
static Utf16FlyString from_utf8(StringView);
static Utf16FlyString from_utf8(String const& string) { return from_utf8_without_validation(string); }
static Utf16FlyString from_utf8(FlyString const& string) { return from_utf8_without_validation(string); }
static Utf16FlyString from_utf8_without_validation(StringView);
static Utf16FlyString from_utf8_but_should_be_ported_to_utf16(StringView string) { return from_utf8_without_validation(string); }
static Utf16FlyString from_utf16(Utf16View const&);
template<typename T>
requires(IsOneOf<RemoveCVReference<T>, Utf16String, Utf16FlyString>)
static Utf16FlyString from_utf16(T&&) = delete;
Utf16FlyString(Utf16String const&);
[[nodiscard]] ALWAYS_INLINE Utf16View view() const LIFETIME_BOUND { return m_data.utf16_view(); }
ALWAYS_INLINE explicit operator Utf16String() const { return to_utf16_string(); }
ALWAYS_INLINE operator Utf16View() const& LIFETIME_BOUND { return view(); }
explicit operator Utf16View() const&& = delete;
ALWAYS_INLINE Utf16String to_utf16_string() const
{
Detail::Utf16StringBase copy { m_data };
return Utf16String { move(copy) };
}
ALWAYS_INLINE Utf16FlyString to_ascii_lowercase() const
{
auto view = m_data.utf16_view();
if (view.has_ascii_storage()) {
if (!any_of(view.ascii_span(), is_ascii_upper_alpha))
return *this;
} else {
if (!any_of(view.utf16_span(), is_ascii_upper_alpha))
return *this;
}
return view.to_ascii_lowercase();
}
ALWAYS_INLINE Utf16FlyString to_ascii_uppercase() const
{
auto view = m_data.utf16_view();
if (view.has_ascii_storage()) {
if (!any_of(view.ascii_span(), is_ascii_lower_alpha))
return *this;
} else {
if (!any_of(view.utf16_span(), is_ascii_lower_alpha))
return *this;
}
return view.to_ascii_uppercase();
}
ALWAYS_INLINE Utf16FlyString to_ascii_titlecase() const
{
return view().to_ascii_titlecase();
}
template<Arithmetic T>
ALWAYS_INLINE Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes, int base = 10) const
{
return m_data.to_number<T>(trim_whitespace, base);
}
ALWAYS_INLINE Utf16FlyString& operator=(Utf16String const& string)
{
*this = Utf16FlyString { string };
return *this;
}
[[nodiscard]] ALWAYS_INLINE bool operator==(Utf16FlyString const& other) const { return m_data.raw({}) == other.m_data.raw({}); }
[[nodiscard]] ALWAYS_INLINE bool operator==(Utf16String const& other) const { return m_data == other; }
[[nodiscard]] ALWAYS_INLINE bool operator==(Utf16View const& other) const { return m_data == other; }
[[nodiscard]] ALWAYS_INLINE bool operator==(StringView other) const { return m_data == other; }
[[nodiscard]] ALWAYS_INLINE int operator<=>(Utf16FlyString const& other) const { return m_data.operator<=>(other.m_data); }
[[nodiscard]] ALWAYS_INLINE int operator<=>(Utf16View const& other) const { return m_data.operator<=>(other); }
[[nodiscard]] ALWAYS_INLINE bool equals_ignoring_ascii_case(Utf16FlyString const& other) const
{
if (*this == other)
return true;
return m_data.equals_ignoring_ascii_case(other.m_data);
}
[[nodiscard]] ALWAYS_INLINE bool equals_ignoring_ascii_case(Utf16View const& other) const { return m_data.equals_ignoring_ascii_case(other); }
template<typename... Ts>
[[nodiscard]] ALWAYS_INLINE bool is_one_of(Ts&&... strings) const
{
return (this->operator==(forward<Ts>(strings)) || ...);
}
template<typename... Ts>
[[nodiscard]] ALWAYS_INLINE bool is_one_of_ignoring_ascii_case(Ts&&... strings) const
{
return (this->equals_ignoring_ascii_case(forward<Ts>(strings)) || ...);
}
[[nodiscard]] ALWAYS_INLINE u32 hash() const { return m_data.hash(); }
[[nodiscard]] ALWAYS_INLINE bool is_empty() const { return m_data.is_empty(); }
[[nodiscard]] ALWAYS_INLINE bool is_ascii() const { return m_data.is_ascii(); }
[[nodiscard]] ALWAYS_INLINE size_t length_in_code_units() const { return m_data.length_in_code_units(); }
[[nodiscard]] ALWAYS_INLINE size_t length_in_code_points() const { return m_data.length_in_code_points(); }
[[nodiscard]] ALWAYS_INLINE char16_t code_unit_at(size_t code_unit_offset) const { return m_data.code_unit_at(code_unit_offset); }
[[nodiscard]] ALWAYS_INLINE u32 code_point_at(size_t code_unit_offset) const { return m_data.code_point_at(code_unit_offset); }
[[nodiscard]] ALWAYS_INLINE size_t code_unit_offset_of(size_t code_point_offset) const { return m_data.code_unit_offset_of(code_point_offset); }
[[nodiscard]] ALWAYS_INLINE size_t code_point_offset_of(size_t code_unit_offset) const { return m_data.code_point_offset_of(code_unit_offset); }
constexpr Utf16FlyString(Badge<Optional<Utf16FlyString>>, nullptr_t)
: m_data(Badge<Utf16FlyString> {}, nullptr)
{
}
[[nodiscard]] constexpr bool is_invalid(Badge<Optional<Utf16FlyString>>) const { return m_data.raw({}) == 0; }
// This is primarily interesting to unit tests.
[[nodiscard]] static size_t number_of_utf16_fly_strings();
private:
ALWAYS_INLINE explicit Utf16FlyString(Detail::Utf16StringBase data)
: m_data(move(data))
{
}
template<typename ViewType>
static Optional<Utf16FlyString> create_fly_string_from_cache(ViewType const&);
Detail::Utf16StringBase m_data;
};
template<>
class Optional<Utf16FlyString> : public OptionalBase<Utf16FlyString> {
template<typename U>
friend class Optional;
public:
using ValueType = Utf16FlyString;
constexpr Optional() = default;
template<SameAs<OptionalNone> V>
constexpr Optional(V) { }
constexpr Optional(Optional<Utf16FlyString> const& other)
: m_value(other.m_value)
{
}
constexpr Optional(Optional&& other)
: m_value(move(other.m_value))
{
}
template<typename U = Utf16FlyString>
requires(!IsSame<OptionalNone, RemoveCVReference<U>>)
explicit(!IsConvertible<U&&, Utf16FlyString>) constexpr Optional(U&& value)
requires(!IsSame<RemoveCVReference<U>, Optional<Utf16FlyString>> && IsConstructible<Utf16FlyString, U &&>)
: m_value(forward<U>(value))
{
}
template<SameAs<OptionalNone> V>
constexpr Optional& operator=(V)
{
clear();
return *this;
}
constexpr Optional& operator=(Optional const& other)
{
if (this != &other)
m_value = other.m_value;
return *this;
}
constexpr Optional& operator=(Optional&& other)
{
if (this != &other)
m_value = other.m_value;
return *this;
}
constexpr void clear()
{
m_value = empty_value;
}
[[nodiscard]] constexpr bool has_value() const
{
return !m_value.is_invalid({});
}
[[nodiscard]] constexpr Utf16FlyString& value() &
{
VERIFY(has_value());
return m_value;
}
[[nodiscard]] constexpr Utf16FlyString const& value() const&
{
VERIFY(has_value());
return m_value;
}
[[nodiscard]] constexpr Utf16FlyString value() &&
{
return release_value();
}
[[nodiscard]] constexpr Utf16FlyString release_value()
{
VERIFY(has_value());
return exchange(m_value, empty_value);
}
private:
static constexpr Utf16FlyString empty_value { {}, nullptr };
Utf16FlyString m_value { empty_value };
};
template<>
struct Traits<Utf16FlyString> : public DefaultTraits<Utf16FlyString> {
static unsigned hash(Utf16FlyString const& string) { return string.hash(); }
static constexpr bool may_have_slow_equality_check() { return false; }
};
template<>
struct Formatter<Utf16FlyString> : Formatter<Utf16String> {
ErrorOr<void> format(FormatBuilder& builder, Utf16FlyString const& string)
{
return Formatter<Utf16String>::format(builder, string.to_utf16_string());
}
};
namespace Detail {
template<>
inline constexpr bool IsHashCompatible<Utf16View, Utf16FlyString> = true;
template<>
inline constexpr bool IsHashCompatible<Utf16FlyString, Utf16View> = true;
template<>
inline constexpr bool IsHashCompatible<Utf16String, Utf16FlyString> = true;
template<>
inline constexpr bool IsHashCompatible<Utf16FlyString, Utf16String> = true;
}
}
[[nodiscard]] ALWAYS_INLINE AK::Utf16FlyString operator""_utf16_fly_string(char const* string, size_t length)
{
AK::StringView view { string, length };
ASSERT(AK::Utf8View { view }.validate());
return AK::Utf16FlyString::from_utf8_without_validation(view);
}
[[nodiscard]] ALWAYS_INLINE AK::Utf16FlyString operator""_utf16_fly_string(char16_t const* string, size_t length)
{
return AK::Utf16FlyString::from_utf16({ string, length });
}

Some files were not shown because too many files have changed in this diff Show More