Commit Graph

3476 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
Andreas Kling
66fb0a8394 LibRegex/Rust: Add the ECMA-262 regex engine
Add LibRegex's new Rust ECMAScript regular expression engine.

Replace the old parser's direct pattern-to-bytecode pipeline with a
split architecture: parse patterns into a lossless AST first, then
lower that AST into bytecode for a dedicated backtracking VM. Keep the
syntax tree as the place for validation, analysis, and optimization
instead of teaching every transformation to rewrite partially built
bytecode.

Specialize this backend for the job LibJS actually needs. The old C++
engine shared one generic parser and matcher stack across ECMA-262 and
POSIX modes and supported both byte-string and UTF-16 inputs. The new
engine focuses on ECMA-262 semantics on WTF-16 data, which lets it
model lone surrogates and other JavaScript-specific behavior directly
instead of carrying POSIX and multi-encoding constraints through the
whole implementation.

Fill in the ECMAScript features needed to replace the old engine for
real web workloads: Unicode properties and sets, lookahead and
lookbehind, named groups and backreferences, modifier groups, string
properties, large quantifiers, lone surrogates, and the parser and VM
corner cases those features exercise.

Reshape the runtime around compile-time pattern hints and a hotter VM
loop. Pre-resolve Unicode properties, derive first-character,
character-class, and simple-scan filters, extract safe trailing
literals for anchored patterns, add literal and literal-alternation
fast paths, and keep reusable scratch storage for registers,
backtracking state, and modifier stacks. Teach `find_all` to stay
inside one VM so global searches stop paying setup costs on every
match.

Make those shortcuts semantics-aware instead of merely fast. In Unicode
mode, do not use literal fast paths for lone surrogates, since
ECMA-262 must not let `/\ud83d/u` match inside a surrogate pair.
Likewise, only derive end-anchor suffix hints when the suffix lies on
every path to `Match`, so lookarounds and disjunctions cannot skip into
a shared tail and produce false negatives.

This commit lands the Rust crate, the C++ wrapper, the build
integration, and the initial LibJS-side plumbing needed to exercise
the new engine under real RegExp callers before removing the legacy
backend.
2026-03-27 17:32:19 +01:00
Tim Ledbetter
657060ccc2 LibWeb: Implement FontFaceSet.check()
This returns true if the given text can be rendered with the fonts in
the set that are fully loaded.
2026-03-27 15:28:59 +00:00
Callum Law
c7b402eff5 LibWeb: Parse @function rules 2026-03-27 11:19:28 +00:00
Callum Law
7d158c47d1 LibWeb: Implement CSSFunctionDeclarations
We also define it as a valid `NestedDeclarationsRule` for the relevant
functions
2026-03-27 11:19:28 +00:00
Callum Law
7f72b01ed3 LibWeb: Implement CSSFunctionDescriptors 2026-03-27 11:19:28 +00:00
Callum Law
19c8eb4146 LibWeb: Implement CSSFunctionRule
Parsing/using this rule will come in later commits
2026-03-27 11:19:28 +00:00
Callum Law
fc3dc8ac8c Tests: Import some @function parsing tests 2026-03-27 11:19:28 +00:00
Jelle Raaijmakers
b38b7d0ae3 LibWeb: Draw text decoration lines with the right offset
For some text decorations (e.g. underline) we were using the line's top
edge as the Y-coordinate to draw the line at, which combined with the
line's thickness meant that it was positioned too high up.

Correct this by calculating the line's center Y position.
2026-03-26 12:15:36 +00:00
Jelle Raaijmakers
3d2571b46e LibWeb: Implement text-decoration-skip-ink painting
Use Skia's SkTextBlob::getIntercepts() to find where glyph outlines
cross the underline/overline band, then split the decoration line into
segments with gaps around those intersections.
2026-03-26 12:15:36 +00:00
Jelle Raaijmakers
18f01b2c4b LibWeb: Support parsing text-decoration-skip-ink property 2026-03-26 12:15:36 +00:00
Jelle Raaijmakers
6241cbb56d Tests: Import WPT tests for text-decoration-skip-ink parsing 2026-03-26 12:15:36 +00:00
Callum Law
b86377b9dc LibWeb: Clamp CSS <integer> value to i32 at parse time
This matches the behavior of other browsers. Previously we implemented
this at used-value time for z-index specifically.
2026-03-26 12:30:01 +01:00
Callum Law
0ab06e119e LibWeb: Use i32 max for clamping 'infinite' calculated integers
This required us to change our range values from `float`s to `double`s
since `float` can't exactly represent i32 max
2026-03-26 12:30:01 +01:00
Callum Law
0e8956ee30 LibWeb: Round up on half when rounding to nearest integer in CSS 2026-03-26 12:30:01 +01:00
Callum Law
cdc264a62e LibWeb: Validate nested contents when parsing declaration value
Previously we automatically assumed that contents inside functions and
blocks were valid, now we actually check them.
2026-03-26 01:11:39 +00:00
Callum Law
93bd066639 LibWeb: Ensure <declaration-value>? descriptors are valid
Currently this only applies to the `@property` `syntax` descriptor.

As with custom properties in the previous commit we assumed that any
consumed values were valid but that's not the case.
2026-03-26 01:11:39 +00:00
Callum Law
46bebf44c5 LibWeb: Ensure custom property definition is valid <declaration-value>?
Previously we assumed that consumed declarations were always valid but
that isn't the case
2026-03-26 01:11:39 +00:00
Callum Law
6afe2ff27b LibWeb: Limit <ident> to <custom-ident> in @property/syntax
The definition of syntax in the "css-properties-values-api" spec (which
is used for the `@property/syntax` descriptor) is slightly different
from the definition of `<syntax>` in the "css-values" spec (which we
implement) in that it limits literal idents to exclusively
`<custom-ident>`s (i.e. not CSS-wide keywords or "default").

`<custom-ident>`s are also case-sensitive so that behavior is
implemented for syntax matching here as well
2026-03-26 01:11:39 +00:00
Callum Law
283f8e46a4 LibWeb: Only match alternative syntax if entire stream consumed
Previously we would consider an alternative syntax child to be a match
as long as parsing produced a value, even if there were trailing tokens
(which would later invalidate it within `parse_with_a_syntax`). This
meant that we wouldn't consider later alternatives which may actually
produce a valid match.
2026-03-26 01:11:39 +00:00
Callum Law
614a5cf33e LibWeb: Set context for parsing against <foo-percentage> syntax
This means that we correctly parse dimension percentage mixes (i.e.
`calc(10px + 10%)` is a valid `<length-percentage>`)
2026-03-26 01:11:39 +00:00
Callum Law
ed2909674f LibWeb: Add computationally independent check for custom properties
Registered custom properties only accept "computationally independent"
values for their initial value
2026-03-26 01:11:39 +00: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
mikiubo
29ae949798 LibWeb: Use outputLength instead of length in KmacParams
The WebCrypto spec was updated to rename the KMAC algorithm
parameter from length to outputLength.
2026-03-25 22:07:53 +01:00
mikiubo
be9936263f LibWeb: Re-import KMAC WPT tests 2026-03-25 22:07:53 +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
Shannon Booth
633b684d76 Tests/LibWeb: Handle synchronous iframe processing in CloseWatcher test
If we conform with the HTML specification by processing the iframe
synchronously as part of the iframe post connection steps, this test
will time out as the load event is fired in the appendChild call.

Create the promise for the load event before performing the load event
to handle this situation, which also allows the test to pass in
chromium.
2026-03-25 14:49:36 +01:00
Shannon Booth
d330171be3 Tests/LibWeb: Import WPT test for iframe insertion/removing steps
The failing test is because we are not invoking 'process the iframe
attributes' synchronously in the <iframe> post connection /
insertion steps.
2026-03-25 14:49:36 +01:00
Luke Wilde
102c0232ac LibWeb: Add FACEs to disabled form control checks 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
9af3e34875 LibWeb: Return FACEs from HTML{FieldSet,Form}Element#elements 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
6a812cf919 Tests/LibWeb: Import form-associated custom elements WPT tests
These will be worked on in future commits.
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
Callum Law
500ca417ce LibWeb: Map logical aliases at compute rather than cascade time
This requires us to front load computation of writing-mode and direction
before we encounter any logical aliases or their physical counterparts
so that we can create a mapping context.

Doing this at compute rather than cascade time achieves a few things:
 1) Brings us into line with the spec
 2) Avoids the double cascade that was previously required to compute
    mapping contexts
 3) We now compute values of logical aliases, while
    `style_value_for_computed_property` maps logical aliases to their
    physical counterparts, this didn't account for all cases (i.e. if
    there was no layout node, Typed OM, etc).
 4) Removes a hurdle to moving other upstream processes (i.e. arbitrary
    substitution function resolution, custom property computation) to
    compute time as the spec requires.
2026-03-25 12:53:22 +00:00
Jelle Raaijmakers
16dffe39a0 LibWeb: Invalidate pseudo-elements on hover even when not yet created
The hover invalidation code only tried matching ::before/::after
selectors when has_pseudo_element() returned true, which requires an
existing layout node. A pseudo-element that doesn't exist yet (because
its content is only set by a hover rule) has no layout node, so the
match was skipped and hovering never triggered a style recompute.
Always try ::before/::after selectors during hover invalidation.
2026-03-24 10:23:35 -04:00
Callum Law
02db1b942b LibWeb: Improve handling of calculated values in <ratio>
We no longer try to resolve calculated values at parse time which means
we support relative lengths.

We now clamp negative values rather than rejecting them at parse time.

Parsing has been inlined into `parse_ratio_value` and `parse_ratio` has
been removed since `parse_ratio_value` was the only caller
2026-03-24 14:00:01 +00:00
aguiarcode
49d66867bd LibWeb: Invalidate inline paint caches when text selection state changes 2026-03-24 13:06:15 +00:00
Jelle Raaijmakers
fead8b92f9 LibWeb: Use correct scrollability check for autoscrolling
We only checked if the paintable box had scrollable overflow, but that
was too simple - we now use the same logic that checks whether a box can
be scrolled by a mousewheel event.

The autoscrolling test was updated as well to use rAF+rAF+timeout
instead of a fixed 1000ms timeout, which is prone to flakiness.
2026-03-24 13:55:37 +01:00
Rob Ryan
281c2ce545 LibWeb: Seed ancestor context for computing style with no layout node 2026-03-24 05:02:48 +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
fa1c046e68 Tests/LibWeb: Import some MessageEvent Origin API tests 2026-03-23 22:32:43 +01:00
Shannon Booth
ba79535d94 Tests/LibWeb: Support absolute paths for WPT files in HTTP test server
Imported WPT tests often load resources using canonical absolute paths,
for example:

/html/browsers/windows/resources/message-parent.html

Our usual strategy is to rewrite such URLs to relative paths during
import so they resolve from the importing test HTML file (which also
allows for loading this HTML as a file://).

That works for same-origin relative loading with the echo server, but it
breaks down when a test constructs a cross-origin URL from an absolute
path, for example:

get_host_info().REMOTE_ORIGIN + "/some/wpt/path.html"

In that case the resource still needs to be fetched at its canonical
absolute path, so rewriting it relative to the importing document is no
longer sufficient.

Update the HTTP test server so /static/ continues to serve from the
general test root, other non-echo requests are served from the imported
WPT tree, and dynamically registered echo responses live under /echo/
to avoid path conflicts.
2026-03-23 22:32:43 +01:00
Shannon Booth
8d6ce39a9b Tests/LibWeb: Support test-web echo server in get-host-info.sub.js
Make some local file edits to get-host-info.sub.js such that
get_host_info() refers to the echo server through localhost,
and the cross origin server through 127.0.0.1.

This allows many imported WPT tests using this function work
correctly (if loaded from the echo HTTP server).
2026-03-23 22:32:43 +01:00