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.
This commit is contained in:
Andreas Kling
2026-03-25 10:52:20 +01:00
committed by Ali Mohammad Pur
parent 66fb0a8394
commit 34d954e2d7
Notes: github-actions[bot] 2026-03-27 16:35:21 +00:00
21 changed files with 394 additions and 104 deletions

View File

@@ -6,9 +6,11 @@
#pragma once
#include <AK/HashMap.h>
#include <AK/Optional.h>
#include <AK/OwnPtr.h>
#include <AK/String.h>
#include <LibRegex/Regex.h>
#include <LibRegex/ECMAScriptRegex.h>
#include <LibURL/Pattern/PatternParser.h>
namespace URL::Pattern {
@@ -23,7 +25,14 @@ struct Component {
OrderedHashMap<String, Variant<String, Empty>> groups;
};
Result create_match_result(String const& input, regex::RegexResult const& exec_result) const;
struct ExecutionResult {
bool success { false };
Vector<Optional<String>> captures;
};
Result create_match_result(String const& input, ExecutionResult const& exec_result) const;
ExecutionResult execute(String const& input) const;
bool matches(StringView input) const;
// https://urlpattern.spec.whatwg.org/#component-pattern-string
// pattern string, a well formed pattern string
@@ -31,7 +40,7 @@ struct Component {
// https://urlpattern.spec.whatwg.org/#component-regular-expression
// regular expression, a RegExp
OwnPtr<Regex<ECMA262>> regular_expression;
OwnPtr<regex::ECMAScriptRegex> regular_expression;
// https://urlpattern.spec.whatwg.org/#component-group-name-list
// group name list, a list of strings