Commit Graph

72034 Commits

Author SHA1 Message Date
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