Commit Graph

1686 Commits

Author SHA1 Message Date
Andreas Kling
34d954e2d7 LibRegex: Add ECMAScriptRegex and migrate callers
Add `ECMAScriptRegex`, LibRegex's C++ facade for ECMAScript regexes.

The facade owns compilation, execution, captures, named groups, and
error translation for the Rust backend, which lets callers stop
depending on the legacy parser and matcher types directly. Use it in the
remaining non-LibJS callers: URLPattern, HTML input pattern handling,
and the places in LibHTTP that only needed token validation.

Where a full regex engine was unnecessary, replace those call sites with
direct character checks. Also update focused LibURL, LibHTTP, and WPT
coverage for the migrated callers and corrected surrogate handling.
2026-03-27 17:32:19 +01:00
Jelle Raaijmakers
450c15c63b LibWeb: Finalize session history entry during async sniff bytes
In e97de2e7e3 we added a guard to prevent
crashes, but we should've still finalized the session history entry.
2026-03-27 05:18:30 +01:00
Aliaksandr Kalenik
ce81f16530 LibWeb: Remove SessionHistoryEntry::clone() and DocumentState::clone()
With apply_to() now self-contained (carrying its own replacement
DocumentState rather than reading from the live entry), the clone at
the traversal call site is no longer needed.

The clone previously served two purposes:
1. Input snapshot: freeze entry fields before deferred population.
   Now solved by changing populate_session_history_entry_document() to
   take explicit input parameters, snapshotted before the
   deferred_invoke.
2. Output isolation: absorb apply_to() and post-population adjustments
   without mutating the live entry during unload. Now solved by storing
   the PopulateSessionHistoryEntryDocumentOutput on the continuation
   state and deferring all mutations (including the origin-based
   classic_history_api_state reset and navigable_target_name clear)
   to after_potential_unload.

The post-population adjustments run unconditionally in
after_potential_unload, covering both the population path and the
non-population path (e.g. traversal to an already-populated error
entry).
2026-03-27 02:34:55 +01:00
Aliaksandr Kalenik
49690f1e1e LibWeb: Separate input/output in populate_session_history_entry_document
Previously, populate_session_history_entry_document() took a
SessionHistoryEntry as both input and output — reading URL and
document_state fields while also mutating the entry across a chain of
async functions. This made it very hard to reason about data flow.

Refactor the internal helpers
(create_navigation_params_from_a_srcdoc_resource,
create_navigation_params_by_fetching, NavigationParamsFetchStateHolder,
perform_navigation_params_fetch) to take individual field values instead
of reading from the entry, and accumulate redirect mutations on the
state holder rather than writing them to the entry immediately.

Introduce PopulateSessionHistoryEntryDocumentOutput, a GC cell that
collects all mutations (document, redirect URL, classic history API
state, replacement document state, resource cleared flag, and
finalization data). The completion_steps callback now receives this
output object (or nullptr on cancellation), and callers apply it to the
entry via apply_to().

The replacement DocumentState for the redirect path is built eagerly at
redirect time from values captured on the state holder, making
apply_to() fully self-contained — it never reads from the target entry's
live document_state. This is important for the traversal path where the
entry may be mutated during unload (e.g. window.name writes
navigable_target_name through the active session history entry).
2026-03-27 02:34:55 +01:00
Jelle Raaijmakers
95955f40b1 LibWeb: Bail from apply_the_history_step() if document lost navigable
We pump the event loop just before these steps which can cause the
displayed document to be destroyed and lose its navigable. This was a
cause for crashes in the `encoding` WPT tests.
2026-03-26 18:48:27 +01:00
Jelle Raaijmakers
e97de2e7e3 LibWeb: Check for an active browsing context in the sniff bytes callback
The navigable can lose its browsing context while waiting for network
tasks to complete. Fixes a crash seen in the `encoding` WPT tests.
2026-03-26 18:48:27 +01:00
Jelle Raaijmakers
a5000d07c0 LibWeb: Prevent running permanently unrunnable tasks in EventLoop
In `::spin_processing_tasks_with_source_until()`, we would first take a
set of tasks based on a filter, and then run them one by one. If there
was more than one task matched and put in that vector, they could
interfere with each other's runnability by making later tasks
permanently unrunnable.

The `::take_tasks_matching()` API is a footgun - remove it in favor of
an API that takes tasks one by one, performing the runnability check
just in time.
2026-03-26 18:48:27 +01:00
Jelle Raaijmakers
f5d76ec2d0 LibWeb: Simplify TaskQueue::remove_tasks_matching()
No functional changes.
2026-03-26 18:48:27 +01:00
Jelle Raaijmakers
94062e4c5b LibWeb: Set the is_closing flag in close_top_level_traversable()
`close_top_level_traversable()` checks the `is_closing` flag to prevent
duplicate closes, but it is only set by callers of
`definitely_close_top_level_traversable()`. The flag is a bit in between
specs as things move from browsing contexts to navigables, but its
purpose is clear: without setting it, the check is ineffective and
`definitely_close_top_level_traversable()` runs multiple times for the
same traversable when the page has child navigables. This queues
duplicate session history traversal steps, where the second step
accesses the already-destroyed active document and segfaults.
2026-03-26 18:48:27 +01:00
Tim Ledbetter
cbd01b8efc LibWeb: Use fallible FormAssociatedElement cast in form elements filter
The `HTMLFormControlsCollection` filter iterates all descendants of the
form's root, which may include non HTMLElement elements such as SVG
elements. The unchecked `as<FormAssociatedElement>` cast would crash on
these elements. Use `as_if` with a null check instead.

This fixes a regression introduced in 9af3e34875.
2026-03-26 08:31:00 +01:00
Glenn Skrzypczak
6074424486 LibWeb/HTML: Update the button activation behaviour steps
This commit updates the activation behaviour steps of the button
element in order to properly determine if a command is valid for
a target.
2026-03-25 23:14:10 +01:00
Glenn Skrzypczak
88167149f6 LibWeb/HTML: Properly get the attr-associated element
This replaces ad-hoc implementations of the get the attr-associated
element steps with a call to the proper implementation. This fixes
issue #8585.
2026-03-25 23:14:10 +01:00
Shannon Booth
346fa16b1e LibWeb: Don't cancel pending navigations in navigate to a javascript URL
Other browsers appear to only do this for form submission, not for
all javascript URL navigations. Let's remove the handling in the
general javascript URL navigation handling so that our behaviour
diference to other browsers is limited specifically to form
elements, instead of the general case.

Unfortunately this does (expectedly) cause the test added in
3e0ea4f62 to start timing out, so that test is marked as skipped.
2026-03-25 22:05:25 +01:00
Psychpsyo
bd91567863 Meta: Ensure that idl files link to draft specs 2026-03-25 16:02:04 +00:00
Luke Wilde
e21d622e61 LibWeb: Include FACEs in form submission 2026-03-25 13:18:15 +00:00
Luke Wilde
b0ecff765f LibWeb: Implement ElementInternals#setFormValue 2026-03-25 13:18:15 +00:00
Luke Wilde
ad653da637 LibWeb: Implement ElementInternals#validationMessage 2026-03-25 13:18:15 +00:00
Luke Wilde
dfb7e51218 LibWeb: Implement ElementInternals#setValidity 2026-03-25 13:18:15 +00:00
Luke Wilde
4daa2b33f1 LibWeb: Implement ElementInternals#labels 2026-03-25 13:18:15 +00:00
Luke Wilde
297110ffb1 LibWeb: Implement ElementInternals#form 2026-03-25 13:18:15 +00:00
Luke Wilde
05c7ba2282 LibWeb: Implement ElementInternals#willValidate 2026-03-25 13:18:15 +00:00
Luke Wilde
edbe8b5d90 LibWeb: Implement ElementInternals#validity 2026-03-25 13:18:15 +00:00
Luke Wilde
4d9018462e LibWeb: Implement ElementInternals#checkValidity 2026-03-25 13:18:15 +00:00
Luke Wilde
0b74aba287 LibWeb: Implement ElementInternals#reportValidity 2026-03-25 13:18:15 +00:00
Luke Wilde
9af3e34875 LibWeb: Return FACEs from HTML{FieldSet,Form}Element#elements 2026-03-25 13:18:15 +00:00
Luke Wilde
e111945611 LibWeb: Bar readonly FACEs from constraint validation 2026-03-25 13:18:15 +00:00
Luke Wilde
80302feec7 LibWeb: Implement reset algorithm for FACEs 2026-03-25 13:18:15 +00:00
Luke Wilde
4cea5d43e6 LibWeb: Queue form{Associated,Disabled}Callback where appropriate 2026-03-25 13:18:15 +00:00
Luke Wilde
0381c40cb4 LibWeb: Reset non-FACEs and don't associate them to a form during parse
(FACE stands for form-associated custom element)
2026-03-25 13:18:15 +00:00
Luke Wilde
df32da5e86 LibWeb: Make every HTMLElement potentially form-associated
This can be the case for form-associated custom elements, where any
HTML element can be form-associated.
2026-03-25 13:18:15 +00:00
Luke Wilde
cfd795f907 LibWeb+IDLGenerators: Support nullable union types 2026-03-25 13:18:15 +00:00
Timothy Flynn
58791db818 AK+LibWeb: Move generation of random UUIDs into AK
This will let us use this more outside of LibWeb more easily.

Stop handling tiny OOM while we are here.
2026-03-24 12:04:50 -04:00
Callum Law
f347be8206 LibWeb: Store underlying RatioStyleValue values as StyleValues
Previously we stored a fully formed `Ratio` - this restricted us from
supporting calculated values which will be implemented in a later commit
2026-03-24 14:00:01 +00:00
Callum Law
201b609450 LibWeb: Store MediaFeatureValue underlying value as StyleValue
This simplifies handling in some cases and gets us a step closer to
removing the `OrCalculated` classes
2026-03-24 14:00:01 +00:00
Callum Law
860ec7aea3 LibWeb: Store type of MediaFeatureValue explicitly
In a later commit we will be storing the value as a `StyleValue` and
thus won't be able to easily get it's type
2026-03-24 14:00:01 +00:00
Jelle Raaijmakers
dd6d17d60d LibWeb: Don't crash accessing stale nested navigable paintable
The scroll state collection loop in
record_display_list_and_scroll_state() called paintable() on hosted
documents, which asserts layout is up to date. This crashes when a
nested document has stale layout but a cached display list, e.g. a
render-blocked iframe whose DOM was modified by document.open().
Since scroll offsets are independent of layout freshness, use
unsafe_paintable() to skip the assertion.
2026-03-24 12:47:02 +01:00
Andreas Kling
b5babda288 LibWeb: Cache UniversalGlobalScopeMixin pointer on ESO
Avoid expensive cross-hierarchy dynamic_cast from JS::Object to
UniversalGlobalScopeMixin on every microtask checkpoint.

Since UniversalGlobalScopeMixin is not in the JS::Object
inheritance chain, as<UniversalGlobalScopeMixin>(JS::Object&)
falls through to dynamic_cast, which is very costly. Profiling
showed this taking ~14% of total CPU time.

Add EnvironmentSettingsObject::universal_global_scope() backed
by a pointer cached eagerly during initialization.
2026-03-24 08:28:47 +01:00
Shannon Booth
a0878ec057 LibWeb/HTML: Teach MessageEvent to work with origins
Corresponds to whatwg/html@748b068c7c

Which fixes the Origin.from() handling for MessageEvent's.
2026-03-23 22:32:43 +01:00
Shannon Booth
c5465e7ef1 LibWeb/HTML: Add some spec links to MessageEvent header 2026-03-23 22:32:43 +01:00
Aliaksandr Kalenik
4ea4d63008 Everywhere: Replace Unix socket IPC transport with Mach ports on macOS
On macOS, use Mach port messaging instead of Unix domain sockets for
all IPC transport. This makes the transport capable of carrying Mach
port rights as message attachments, which is a prerequisite for sending
IOSurface handles over the main IPC channel (currently sent via a
separate out-of-band path). It also avoids the need for the FD
acknowledgement protocol that TransportSocket requires, since Mach port
right transfers are atomic in the kernel.

Three connection establishment patterns:

- Spawned helper processes (WebContent, RequestServer, etc.) use the
  existing MachPortServer: the child sends its task port with a reply
  port, and the parent responds with a pre-created port pair.

- Socket-bootstrapped connections (WebDriver, BrowserProcess) exchange
  Mach port names over the socket, then drop the socket.

- Pre-created pairs for IPC tests and in-message transport transfer.

Attachment on macOS now wraps a MachPort instead of a file descriptor,
converting between the two via fileport_makeport()/fileport_makefd().

The LibIPC socket transport tests are disabled on macOS since they are
socket-specific.
2026-03-23 18:50:48 +01:00
Shannon Booth
9d7b18f517 LibWeb: Fix entry_realm() to correctly find the realm execution context
entry_realm() was using the topmost execution context, but the spec
defines the entry execution context as the most recently pushed *realm*
execution context — the one owned by the environment settings object.

In a synchronous cross-window call, JS function calls push additional
execution contexts above the entry realm, causing the wrong realm to
be returned. Fix this by walking the stack to find the context that
matches its environment settings object's realm execution context.
2026-03-23 09:00:39 +01:00
Glenn Skrzypczak
406a32c366 LibWeb/HTML: Make more events trusted
The beforeunload, promiserejection, beforetoggle and toggle events were
previously not tagged as trusted. This commit properly tags the event
so that we match the behaviour implemented by other browsers.
2026-03-23 02:33:56 +01:00
Glenn Skrzypczak
c6bd3173ef LibWeb/HTML: Make form submit event trusted
The form submit event was previously not tagged as trusted. This commit
properly tags the event so that we match the behaviour implemented by
other browsers and expected by WPT.
2026-03-23 02:33:56 +01:00
Jelle Raaijmakers
624d514f47 LibWeb: Remove tasks for destroyed documents when filtering on tasks
In TaskQueue::take_tasks_matching(), we were not discarding tasks for
destroyed documents as we now do in ::take_first_runnable() since commit
c8baa6e179.

This fixes some occurrences of missing browsing contexts / active
documents in TraversableNavigable::destroy_top_level_traversable().
2026-03-22 14:26:50 -05:00
Jelle Raaijmakers
eb293197f7 LibWeb: Simplify TaskQueue::has_rendering_tasks()
No functional changes.
2026-03-22 14:26:50 -05:00
Zaggy1024
704269f664 LibWeb: Use PlaybackManager's states to progress media ready state
Since we know whether we're buffering from the PlaybackManager state,
let's use that to update the ready state. This ensures that when we set
the ready state to HAVE_CURRENT_DATA, we actually have a frame.

Setting the ready state to HAVE_ENOUGH_DATA should probably still be
further conditioned on the buffer size in IncrementallyPopulatedStream,
but this is still an improvement for now.
2026-03-21 23:11:47 -05:00
Andreas Kling
b049f44969 LibWeb: Remove noisy debug log for disconnected script elements
This is another normal spec early return in prepare_script(), not an
error worth logging.
2026-03-21 08:41:13 -05:00
Andreas Kling
994f794487 LibWeb: Remove noisy debug log from HTMLScriptElement::prepare_script()
This is a normal spec-mandated early return, not an error condition.
The already-started flag exists because prepare_script() is called from
multiple paths (attribute changes, child insertions, DOM connection)
and only the first call should proceed.
2026-03-21 08:41:13 -05:00
Jelle Raaijmakers
7fed3f9801 LibWeb: Start fetching CSS image resources before document load event
Both Chromium and Gecko delay the document's load event for CSS image
resource requests (background-image, mask-image, etc). We now start
fetching CSS image resources as soon as their stylesheet is associated
with a document, rather than deferring until layout. This is done by
collecting ImageStyleValues during stylesheet parsing and initiating
their fetches when the stylesheet is added to the document.

Fixes #3448
2026-03-21 10:29:54 +01:00
Aliaksandr Kalenik
03f142f54d LibIPC+LibWeb: Preserve raw TransferDataEncoder attachments
Encode transfer-data attachments as raw IPC attachments instead of first
rewrapping them as IPC::File values.

This is preparatory refactoring for the upcoming Mach-port transport
introduction on macOS, where attachments should remain transport-native
rather than being normalized through file descriptors.
2026-03-21 00:45:12 +01:00