Commit graph

4189 commits

Author SHA1 Message Date
Andreas Kling
b81269e78b Libraries: Clean up UTF-16 source text paths
Store parser errors, source range filenames, source code filenames,
module source, and Rust parser errors as UTF-16 where they flow back
into JavaScript-visible strings. Keep byte-oriented source buffers
byte-backed.

Remove temporary PrimitiveString, ByteString, and UTF-8 detours from
JSON, RegExp, module debug logging, print formatting, and tests.
2026-06-22 19:51:25 +02:00
Andreas Kling
b6bef6b688 Libraries: Use UTF-16 for JS-visible runtime strings
Produce JS-visible string results as UTF-16 at their source, including
numeric formatting, BigInt and BigFraction formatting, URI encoding,
console formatting, parser errors, regular expression errors, Intl and
Temporal records, LibUnicode locale boundaries, and LibWeb bindings.

Handle fractional radix formatting through the UTF-16 builder view.
2026-06-22 19:51:25 +02:00
Andreas Kling
7025dd1fa7 Libraries: Parse JS strings from UTF-16
Thread UTF-16 string input through JSON, script parsing, Date parsing,
Intl option parsing, Temporal parsing, and the helper library boundaries
that feed those parsers. Preserve ASCII fast paths where the source data
is known to be ASCII.
2026-06-22 19:51:25 +02:00
Andreas Kling
503453eb9c AK: Remove UTF-16 mode from StringBuilder
Remove the UTF-16 storage mode and make StringBuilder solely build
UTF-8 strings again. The remaining UTF-16 adoption path now goes
through Utf16StringBuilder, keeping the direct-adoption optimization
with the type that owns UTF-16 construction.
2026-06-22 16:10:40 +02:00
Andreas Kling
a8193e7572 AK+UI: Stop using StringBuilder UTF-16 mode
Move the remaining call sites that constructed StringBuilder in UTF-16
mode over to Utf16StringBuilder or explicit UTF-8 to UTF-16 conversion.
Teach FormatBuilder to target Utf16StringBuilder directly so formatted
Utf16String construction no longer needs StringBuilder's UTF-16 mode.

Update the Utf16String tests to cover Utf16StringBuilder adoption and
clear behavior directly.
2026-06-22 16:10:40 +02:00
Andreas Kling
bf5f24ab36 AK: Add Utf16StringBuilder formatting helpers
Add vformat support for Utf16StringBuilder and expose appendff and
try_appendff helpers on the builder itself. This lets callers build a
Utf16String on the purpose-built UTF-16 path even when using formatting.

Use the new API for Utf16String::formatted and add AK coverage for
formatting directly into a Utf16StringBuilder.
2026-06-22 16:10:40 +02:00
Andreas Kling
488006d276 AK: Add Utf16StringBuilder
Add a purpose-built builder for constructing Utf16String values.
It keeps ASCII storage while possible, widens to UTF-16 when needed,
and can hand outline storage to Utf16StringData for direct adoption.

Add AK coverage for ASCII strings, UTF-16 widening, code points,
trimming, and long string construction.
2026-06-22 16:10:40 +02:00
Andreas Kling
97a6807ffa LibJS: Remove JS_BYTECODE_DEBUG
Remove the stale bytecode execution debug hook from Interpreter.cpp now
that bytecode dispatch always enters AsmInt directly. The remaining
bytecode dump flag is separate and still used by parser/codegen paths.
2026-06-14 20:27:59 +02:00
Andreas Kling
7426185b9d AK: Remove SANITIZE_PTRS support
Remove the unused SANITIZE_PTRS destructor poisoning blocks from AK
pointer wrappers. Also drop the stale Qt Creator configuration define
that referenced this old mode.
2026-06-13 22:49:15 +02:00
Andreas Kling
2a0bc6a6e0 AK: Avoid clearing pointer wrappers during destruction
Delete or unref directly from RefPtr, NonnullRefPtr, and NonnullOwnPtr
destructors instead of calling clear() or exchanging the member pointer.
This avoids storing null when the wrapper lifetime is ending.
2026-06-13 22:49:15 +02:00
Andreas Kling
ccc578e0c0 AK: Avoid clearing OwnPtr during destruction
Delete the owned object directly from OwnPtr destruction instead of
calling clear(). The object lifetime is ending, so there is no need to
store nullptr into m_ptr on this path.
2026-06-13 22:49:15 +02:00
Andreas Kling
079af3d120 AK: Remove custom deleters from OwnPtr
OwnPtr now always deletes the owned object directly from clear(). Remove
the unused deleter template parameter and the DefaultDelete helper that
only supported that parameter. Drop the dedicated custom deleter test.
2026-06-13 22:49:15 +02:00
Andreas Kling
956a2b96d5 LibWeb: Allocate layout and painting objects with mimalloc
Add class-local allocation macros for operator new/delete through AK's
malloc helpers. The macros can optionally choose a HeapPartition.
Add Layout and Painting partitions, plus basic partition stats helpers.

Use the new partitions for LibWeb layout and painting object hierarchies
and layout-state side data.
2026-06-13 19:08:08 +02:00
Sam Atkins
4050c32dab Everywhere: Make use of Badge with multiple or derived types
Now that Badge can have multiple types, and a Badge of a derived class
can convert into a Badge of the superclass, we can simplify a few method
signatures and overloads.
2026-06-11 21:55:56 +02:00
Sam Atkins
071b4f7062 AK: Allow derived types to create base badges
Derived classes can now mint their own badge and pass it to APIs that
accept a badge for an authorized base class.
2026-06-11 21:55:56 +02:00
Sam Atkins
ad3d65b834 AK: Allow Badge to accept multiple types
This lets public APIs name several authorized classes. Callers no longer
need duplicate overloads for one badge.
2026-06-11 21:55:56 +02:00
Andreas Kling
fc02ab95fe AK: Allocate string data in a dedicated heap partition
Add a string heap partition and route long AK string backing
allocations through it.

Give StringBuilder partition-aware outlined storage so adopted String
and Utf16String buffers are allocated from the string heap. Keep the
string heap thread-local because mimalloc heaps may only allocate from
their creating thread, while cross-thread frees are handled by mimalloc.
2026-06-10 20:38:18 +02:00
Andreas Kling
19dd5bef60 LibJS: Isolate object property storage
Add a JSObjectStorage heap partition and route heap-backed property
storage (both named and indexed element buffers) through it.

These buffers are directly shaped by script-visible object and array
operations, so keeping them separate from the general heap makes a
corruption primitive less useful against unrelated allocations.
2026-06-10 17:36:54 +02:00
Andreas Kling
45c499d185 LibJS: Isolate ArrayBuffer backing stores
Move owned ArrayBuffer and SharedArrayBuffer data blocks into the
ArrayBuffer heap partition. Keep unowned and host storage explicit, so
Wasm memory and external LibWeb buffers stay outside this partition.

Introduce DataBlock::OwnedBackingStore as the LibJS-owned byte storage
representation. Expose byte spans instead of a ByteBuffer object, giving
ArrayBuffer one allocation boundary that can later grow toward guarded
or caged storage.

Let callers that need ByteBuffer data copy from backing-store bytes.
Keep TransferArrayBuffer zero-copy by moving the DataBlock directly
instead of materializing a ByteBuffer in between.

Update the Wasm typed-array test helper to compare viewed byte ranges
after ArrayBuffer stops exposing ByteBuffer identity.
2026-06-10 14:50:10 +02:00
Andreas Kling
058c0ca6ed AK: Add partition-aware kmalloc overloads
Introduce HeapPartition and overload kmalloc and krealloc so allocation
sites can opt into a specific heap partition. Keep the default allocator
API unchanged. The only initial partition is General, which maps to the
regular allocator path.

Keep sanitizer builds on the system allocator so LeakSanitizer can still
trace AK container allocations. Remove the obsolete Serenity-specific
allocator branch while updating this file.
2026-06-10 14:50:10 +02:00
Shannon Booth
efe144552c Meta: Remove obsolete LibWeb BindingsGenerator
Remove the old C++ LibWeb bindings generator now that the build uses
the Python generator.
2026-06-08 01:11:40 +02:00
sideshowbarker
d13d29ee38 LibWeb: Suppress false-positive LSan report during WebWorker teardown
Problem: For several weeks now, CI Sanitizer runs have been logging
leaked RustCompiledRegex objects in the WebWorker process when a worker
is torn down while an off-thread script compile is still in flight.

Cause: compile_off_thread() (introduced in 4a7dc45b3f) parses and
compiles a fetched top-level script on a ThreadPool worker. The pool's a
process-lifetime singleton whose workers are never joined before exit —
and that leads to LSan reporting a false positive during teardown.

Fix: Suppress the false positive via __lsan_default_suppressions().
2026-06-07 11:34:57 +02:00
Timothy Flynn
d3d96ce399 AK: Remove Utf32View and surrounding support
It is now unused, so let's just remove it.
2026-06-06 18:42:18 +02:00
Andreas Kling
164ed80244 Meta: Enable exit-time destructor warnings for libraries
Enable -Wexit-time-destructors for all in-tree library targets and
update process-lifetime library statics so they no longer register
exit-time destructors. Long-lived caches, lookup tables, singleton
registries, and generated constants now use NeverDestroyed or leaked
references where the data is intended to live until process exit.

Update LibWeb, LibLine, and the binding generators so regenerated
sources follow the same rule instead of reintroducing destructed
statics.
2026-06-04 19:20:49 +02:00
Rocco Corsi
e3e78f4372 AK: Verify datetime fetching results and initialize struct tm
Cppcheck 2.17 tool found issue with struct tm under Windows

Checking AK/Time.cpp ...
Checking AK/Time.cpp: AK_OS_WINDOWS...
AK/Time.cpp:488:15: error: Uninitialized variable: &tm [uninitvar]
        (void)localtime_r(&timestamp, &tm);
              ^
32/39 files checked 87% done

Also the gmtime_X` and localtime_X calls were not checked for failures,
so those are now checked too.
2026-06-04 17:32:49 +02:00
Shannon Booth
de4b665298 AK: Fix rvalue Variant downcast to variant aliases
Pass the required TypeWrapper through the rvalue downcast<Variant<...>>
path, matching the existing const& overload.
2026-05-30 11:22:08 +02:00
R-Goc
520a7c8ebd AK+LibWeb: Centralize FFI helper functions
This commit creates a central FFIHelpers.h header which implements
common conversions from FFI.
2026-05-28 14:15:43 -05:00
Zaggy1024
ecae6f42cd AK: Add a method to remove an iterated node from a RedBlackTree
This will also advance the passed iterator so that it remains valid.
2026-05-28 10:30:20 -05:00
sideshowbarker
028eb0a966 AK: Don’t let float precision sneak past is_within_range bounds
Problem: is_within_range<I>(F value) — where I is an integer and F is a
floating-point type — is unexpectedly too permissive in some cases:

a. Values that are 1 past the integer range unexpectedly pass; e.g.,
   is_within_range<int>(2147483648.0f) returns true — even though
   2147483648 is INT_MAX + 1.

b. Fractional values whose magnitude exceeds the destination max
   unexpectedly pass; e.g., is_within_range<unsigned>(4294967295.5)
   returns true — even though 4294967295.5 > UINT_MAX.

c. Fractional values within the destination’s numeric range unexpectedly
   pass (e.g., is_within_range<int>(2.5) returns true) — even though
   they aren’t exactly representable as the destination type.

Cause: TypeBoundsChecker integer-bounds specializations compare against
NumericLimits<Destination>::max() and ::min() directly. When a caller’s
value is a float, the integer max/min get implicitly converted to a
float for the comparison. For Destination/Source pairs with the integer
extreme not exactly representable in the float, that conversion rounds
up to the next power-of-two boundary — so “value <= F(max)” accepts
values that are actually out of range by one (case a). And the
comparison itself doesn’t reject fractional values (cases b and c).

Fix: When Source is a floating-point type:

1. First gate (case a) — Compare against 2^digits; exactly representable
   in any IEEE float, and equals max + 1 for unsigned / -min for two’s-
   complement signed integers.

2. Second gate (cases b and c) – Round-trip check: cast value to
   Destination, then cast back — and require equality. Only integer-
   valued floats whose truncation matches the original pass.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/6212
2026-05-27 19:05:56 +02:00
Veeti Paananen
639584fecb AK: Skip Optional converting constructors when U is same as T
This template is causing an "error: satisfaction of atomic constraint
‘IsConstructible<T, const U&> [with T = X; X]’ depends on itself"
through a self referential CSSScopeRule on GCC 16.1. Tighten the
template requirements to avoid it.
2026-05-26 08:47:14 +02:00
Pavel Shliak
ac77a24ad9 AK: Remove unused IntrusiveListRelaxedConst 2026-05-22 09:32:01 +02:00
Pavel Shliak
89761127e0 AK: Remove unused Stack 2026-05-22 02:31:44 -05:00
Pavel Shliak
95af04b8d6 AK: Remove unused IntrusiveRedBlackTree 2026-05-22 09:31:37 +02:00
Pavel Shliak
99561b86c2 AK: Remove unused DisjointChunks 2026-05-22 09:31:25 +02:00
Pavel Shliak
9ebcc67144 AK: Remove unused FixedPoint 2026-05-22 02:30:45 -05:00
Zaggy1024
40d1957d6a AK+Tests: Add a Duration function to scale by a rational 2026-05-19 15:20:58 -05:00
Andreas Kling
b849af70b8 AK+LibWeb: Reject impossible Variant visit overloads
Make Variant::visit reject typed visitor overloads that cannot be
called for any variant alternative. This catches stale visitors after a
variant payload type changes instead of falling through to a generic
overload.

Update fetch body consumers that still expected ByteBuffer after the
body payload moved to Core::ImmutableBytes.
2026-05-18 01:21:34 +02:00
Tim Ledbetter
0533f6d1a6 AK+LibWeb: Add a fast_as<T>() method for quickly casting mixin types
`as_if<T>()` previously had a fast path that used `fast_is<T>()` and a
static cast. Mixin types couldn't use this fast path, since a static
cast from a sibling base is not valid, so would fall back to using a
slow dynamic cast instead.

This change adds a `fast_as<T>()` mechanism for mixin types to opt in
to and teaches `as_if<T>()` to use it. This means `as<T>()` and
`as_if<T>()` can be used with mixin types without incurring the
overhead of a dynamic cast
2026-05-15 13:45:42 +02:00
Zaggy1024
dd626013b9 AK: Allow AtomicRefCounted to destroy classes using virtual inheritance
This warning is suppressed in RefCounted.h as well.
2026-05-13 02:05:35 -05:00
Andreas Kling
584b2748ee LibWeb: Move RenderingThread into Compositor
Create Libraries/LibWeb/Compositor and make the existing rendering
thread the first owner in that subsystem. Rename RenderingThread to
CompositorThread so later commits can grow it into the presentation
owner without leaving that vocabulary in HTML.

Keep display-list rasterization and delivery behavior unchanged in this
commit. Add COMPOSITOR_DEBUG to AK/Debug.h.in in the same step so
compositor diagnostics live beside the rest of the project-wide debug
toggles from the start of the stack.
2026-05-12 20:57:08 +02:00
Tim Ledbetter
4115803fd9 AK: Use memchr for StringView::contains() 2026-05-11 11:33:24 +02:00
Tim Ledbetter
381910a51d AK: Use memchr for Utf8View::contains() ASCII fast path
The libc implementation of `memchr` uses SIMD, so is significantly
faster than looping over individual bytes.
2026-05-11 11:33:24 +02:00
Andreas Kling
1859ecbb24 AK: Add lower_bound_index to binary search helpers
Add a helper for finding the first position in a sorted container where
needle can be inserted while preserving sort order. This gives callers a
lower-bound insertion point.

Cover empty inputs, duplicate values, custom comparators, and constexpr
use in TestBinarySearch.
2026-05-11 11:01:46 +02:00
Ali Mohammad Pur
a33e148339 LibWasm+Meta: Add Cranelift AOT compilation backend
Add an optional Cranelift-based AOT compiler for WebAssembly functions,
enabled via -DENABLE_CRANELIFT_JIT=ON.
2026-05-10 16:41:42 +02:00
Andreas Kling
fb4095ae50 LibGC: Implement incremental sweeping for reduced GC pause times
Instead of sweeping all heap blocks in one go after marking, sweep
incrementally, one block at a time, interleaved with program execution.
This significantly reduces worst-case GC pause times by spreading
sweep work across multiple smaller time slices.

Sweep is driven by two complementary mechanisms:

1. Timer-based sweeping: A 16ms repeating timer drives background
   sweep work, processing blocks for up to 5ms per timer fire.

2. Allocation-directed sweeping: Each allocator sweeps its own
   pending blocks before creating new ones, ensuring forward
   progress even without timer events.

Each allocator maintains its own list of blocks pending sweep,
and allocators with pending work are tracked in a separate list
for efficient timer-driven sweeping.

Key implementation details:

- Newly allocated cells during sweep are marked immediately to
  prevent premature collection.

- Mark bits are cleared incrementally as each block is swept,
  rather than in a separate pass over the entire heap.

- Finalization and weak reference processing remain stop-the-world
  since they must complete atomically before any sweeping occurs.
2026-05-10 10:58:11 +02:00
Kevin Bortis
ba26f8eee7 AK: Reset UTF-16 StringBuilder ascii flag on clear()
StringBuilder::clear() did not reset m_utf16_builder_is_ascii. When a
UTF-16 mode builder processed a non-ASCII character then was cleared
and reused, subsequent ASCII content was stored as char16_t. The
to_utf16_string() path then corrupted the first code unit to null via
placement-new overlap in Utf16StringData::from_string_builder().

This caused the HTML parser's shared m_character_insertion_builder to
produce corrupted script text nodes when a non-ASCII character (e.g.
&times;) appeared in an earlier element, breaking inline script
execution with "Unexpected token Invalid" at line 1 column 1.
2026-05-09 09:49:02 -04:00
Timothy Flynn
2bd28cc4c0 AK: Keep Utf16StringData trailing storage out of tail padding
GCC 16 can clobber the first bytes of Utf16StringData payload when a
StringBuilder buffer is reused for string construction. The trailing
ASCII/UTF-16 storage previously started before sizeof(Utf16StringData),
inside tail padding, so placement-new of the header could zero the first
code unit.

This patch aligns the trailing storage union so payload begins after the
full header.
2026-05-08 18:00:59 -04:00
Aliaksandr Kalenik
4bbfe7eedd AK: Remove unused SegmentedVector
Display lists were the last user of SegmentedVector before the flat
command buffer replaced that storage. With no remaining includes, remove
the container and its unit test.
2026-05-08 20:45:17 +02:00
Undefine
542f3e5cca AK+Meta: Make AK / ObjC interop MacOS only
This is entirely unused but still could be useful in the AppKit port.
Originally this was meant for Swift interop which is why it had support
for other platforms, but now it's causing issues on systems like
FreeBSD, so lets just gate it behind the only platform it's useful for.
We also assume that Objective C blocks and Arc are supported for the
AppKit port to build so no need to check for that in CMake.
2026-05-05 22:08:24 +02:00
antoniospg
428fa59167 LibMedia+LibWeb: Implement HTMLMediaElement.getStartDate() 2026-05-05 14:45:00 -05:00