feat(libSceNKWebKit): implement Inspector::ContentSearchUtilities::createRegularExpressionForSearchString and countRegularExpressionMatches #25170

Merged
XFlawless1 merged 1 commit from upstream-pr/25170 into main 2026-11-24 21:02:34 +00:00
XFlawless1 commented 2026-11-21 18:29:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XFlawless1 on 2026-11-21T18:29:12Z.


What

Implements two Inspector content-search exports that throw today, on top of the existing libregexp-backed JSC::Yarr::RegularExpression exports.

Export Pinned source link Output
Inspector::ContentSearchUtilities::createRegularExpressionForSearchString(WTF::String const&, bool, SearchStringType) ContentSearchUtilities.cpp#L46-L60, #L132-L147 a RegularExpression built in the caller's result slot: Regex uses the string as the pattern, ExactString is ^ + escaped + $, ContainsString is the escaped string, where escaping puts \ before each of [](){}+-*.,?\^$| (and U+0000, as upstream's strchr does); case-insensitive sets IgnoreCase; an unknown type throws
Inspector::ContentSearchUtilities::countRegularExpressionMatches(JSC::Yarr::RegularExpression const&, WTF::String const&) ContentSearchUtilities.cpp#L149-L166 the number of non-empty matches found by restarting match one past each match position (overlapping), 0 for null or empty content

Layouts: RegularExpression is the one-pointer RefPtr<Private> d from RegularExpression.h#L34-L52, modelled by the existing Jsc::YarrAbi::RegularExpression that libSceNKWebKit already uses for its destructor and operator=; its user-provided copy constructor and destructor make createRegularExpressionForSearchString return through the hidden result pointer. WTF::String const& points at one StringImpl*. SearchStringType is the plain enum class { Regex, ExactString, ContainsString } of ContentSearchUtilities.h#L42, passed as an int. All layouts are unverified against a console module. The escaped pattern is handed to libSceJsc as a temporary host string. libSceJsc exports its regex constructor and match only under their NIDs once the libraries are patched, so libSceNKWebKit calls two new libSceJsc helpers, JscRegularExpressionConstruct_nid_no_patch and JscRegularExpressionMatch_nid_no_patch, which forward to them, in the same way it already uses JscRegularExpressionRelease_nid_no_patch; regex semantics are those of the existing libregexp model, not Yarr. An unknown SearchStringType (upstream compiles a null pattern), null result, regex, search-string or content pointers, and a string with null data and a nonzero length throw std::invalid_argument.

Tested

Windows 11, MinGW GCC 15.2, Release.

  • nkwebkit_inspectorcontentsearchregex passes, using the real libSceJsc regex engine and a tracking application heap:
    • ContainsString/ExactString/Regex with a.b (escaped dot vs wildcard, anchors), case-sensitive and insensitive searches, each of the 17 special characters alone and all together, a 16-bit search string, an 8-bit Latin-1 one matched against 16-bit text, and null search strings (empty pattern, ^$);
    • counts: a in banana = 3, overlapping aa in aaa = 2 and in aaaa = 3, a* in baaa = 3 (empty matches not counted), $ in ab = 0, case-insensitive AN in banana = 2, escaped . in a.b.c = 2, a 16-bit pattern = 3, an invalid regex = 0, null and empty content = 0;
    • unknown types (-1, 3, 255) and null pointers throw without allocating; every created regex is freed.
  • Negative controls, each rebuilt and run, each makes the test fail: counting empty matches; dropping . from the special characters.
  • After a full build on current main, patched_libraries passes (the patched libSceNKWebKit.prx loads; calling the mangled libSceJsc exports directly failed it with error 127), all jsc_yarr_* and nkwebkit_* tests pass, as do the registration|conventions_pr_template|pr_overlap_exports|conventions_unknown_nids tests and every public_headers_compile_* batch (the new header compiles on its own).
  • python tools/check_conventions.py --base origin/main passes. python tools/debt_fold.py --check currently fails on main itself (fix-libkernel-clock-id-15.md and docs-libkernel-clock-gettime-1360-divergence.md change the same libkernel entry); with that pre-existing pair set aside, it passes and folds this fragment.

Not tested on a console.

Overlap (python tools/pr_overlap.py --names and --branch feat/nkwebkit-inspector-content-search-regex):

  • No open PR implements either export. #24322, #24910 and #24917, the refactors that split large libraries, move the stubs without implementing them.
  • No open PR touches the libSceJsc YarrRegularExpression files.
  • RegularExpression::matchedLength and RegularExpression(const RegularExpression&) are left alone: #23755, #23757 and others implement them. searchInTextByLines stays a stub (it needs the Inspector protocol JSON objects).
  • #24868 (ContentSearchUtilities::findStylesheetSourceMapURL, also mine) deletes a stub next to these in Export.cpp and InventoryExports.hpp, so whichever merges second gets a textual conflict there; the resolution keeps both deletions.
  • The tool could not compare 54 open PRs that already conflict with main and share Export.cpp, InventoryExports.hpp or libSceNKWebKit.hpp; the --names search covers every open PR's changes and finds these exports only in the refactors.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5431066507 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25170). Originally posted by [XFlawless1](https://github.com/XFlawless1) on 2026-11-21T18:29:12Z. --- ### What Implements two Inspector content-search exports that throw today, on top of the existing libregexp-backed `JSC::Yarr::RegularExpression` exports. | Export | Pinned source link | Output | | --- | --- | --- | | `Inspector::ContentSearchUtilities::createRegularExpressionForSearchString(WTF::String const&, bool, SearchStringType)` | [ContentSearchUtilities.cpp#L46-L60](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp#L46-L60), [#L132-L147](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp#L132-L147) | a `RegularExpression` built in the caller's result slot: `Regex` uses the string as the pattern, `ExactString` is `^` + escaped + `$`, `ContainsString` is the escaped string, where escaping puts `\` before each of `[](){}+-*.,?\^$\|` (and U+0000, as upstream's `strchr` does); case-insensitive sets `IgnoreCase`; an unknown type throws | | `Inspector::ContentSearchUtilities::countRegularExpressionMatches(JSC::Yarr::RegularExpression const&, WTF::String const&)` | [ContentSearchUtilities.cpp#L149-L166](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp#L149-L166) | the number of non-empty matches found by restarting `match` one past each match position (overlapping), 0 for null or empty content | Layouts: `RegularExpression` is the one-pointer `RefPtr<Private> d` from [RegularExpression.h#L34-L52](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/JavaScriptCore/yarr/RegularExpression.h#L34-L52), modelled by the existing `Jsc::YarrAbi::RegularExpression` that libSceNKWebKit already uses for its destructor and `operator=`; its user-provided copy constructor and destructor make `createRegularExpressionForSearchString` return through the hidden result pointer. `WTF::String const&` points at one `StringImpl*`. `SearchStringType` is the plain `enum class { Regex, ExactString, ContainsString }` of [ContentSearchUtilities.h#L42](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/JavaScriptCore/inspector/ContentSearchUtilities.h#L42), passed as an `int`. All layouts are unverified against a console module. The escaped pattern is handed to libSceJsc as a temporary host string. libSceJsc exports its regex constructor and `match` only under their NIDs once the libraries are patched, so libSceNKWebKit calls two new libSceJsc helpers, `JscRegularExpressionConstruct_nid_no_patch` and `JscRegularExpressionMatch_nid_no_patch`, which forward to them, in the same way it already uses `JscRegularExpressionRelease_nid_no_patch`; regex semantics are those of the existing libregexp model, not Yarr. An unknown `SearchStringType` (upstream compiles a null pattern), null result, regex, search-string or content pointers, and a string with null data and a nonzero length throw `std::invalid_argument`. ### Tested Windows 11, MinGW GCC 15.2, Release. - `nkwebkit_inspectorcontentsearchregex` passes, using the real libSceJsc regex engine and a tracking application heap: - `ContainsString`/`ExactString`/`Regex` with `a.b` (escaped dot vs wildcard, anchors), case-sensitive and insensitive searches, each of the 17 special characters alone and all together, a 16-bit search string, an 8-bit Latin-1 one matched against 16-bit text, and null search strings (empty pattern, `^$`); - counts: `a` in `banana` = 3, overlapping `aa` in `aaa` = 2 and in `aaaa` = 3, `a*` in `baaa` = 3 (empty matches not counted), `$` in `ab` = 0, case-insensitive `AN` in `banana` = 2, escaped `.` in `a.b.c` = 2, a 16-bit pattern = 3, an invalid regex = 0, null and empty content = 0; - unknown types (-1, 3, 255) and null pointers throw without allocating; every created regex is freed. - Negative controls, each rebuilt and run, each makes the test fail: counting empty matches; dropping `.` from the special characters. - After a full build on current `main`, `patched_libraries` passes (the patched `libSceNKWebKit.prx` loads; calling the mangled libSceJsc exports directly failed it with error 127), all `jsc_yarr_*` and `nkwebkit_*` tests pass, as do the `registration|conventions_pr_template|pr_overlap_exports|conventions_unknown_nids` tests and every `public_headers_compile_*` batch (the new header compiles on its own). - `python tools/check_conventions.py --base origin/main` passes. `python tools/debt_fold.py --check` currently fails on `main` itself (`fix-libkernel-clock-id-15.md` and `docs-libkernel-clock-gettime-1360-divergence.md` change the same libkernel entry); with that pre-existing pair set aside, it passes and folds this fragment. Not tested on a console. **Overlap** (`python tools/pr_overlap.py --names` and `--branch feat/nkwebkit-inspector-content-search-regex`): - No open PR implements either export. #24322, #24910 and #24917, the refactors that split large libraries, move the stubs without implementing them. - No open PR touches the libSceJsc `YarrRegularExpression` files. - `RegularExpression::matchedLength` and `RegularExpression(const RegularExpression&)` are left alone: #23755, #23757 and others implement them. `searchInTextByLines` stays a stub (it needs the Inspector protocol JSON objects). - #24868 (`ContentSearchUtilities::findStylesheetSourceMapURL`, also mine) deletes a stub next to these in `Export.cpp` and `InventoryExports.hpp`, so whichever merges second gets a textual conflict there; the resolution keeps both deletions. - The tool could not compare 54 open PRs that already conflict with `main` and share `Export.cpp`, `InventoryExports.hpp` or `libSceNKWebKit.hpp`; the `--names` search covers every open PR's changes and finds these exports only in the refactors. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PrivacyOnion commented 2026-11-21 18:35:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T18:35:41Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against cd9cc88b9e:

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_inspectorcontentsearchregex_tests built cleanly.
  • CTest (nkwebkit_inspectorcontentsearchregex):
    1/1 Test #4840: nkwebkit_inspectorcontentsearchregex ...   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp, core/libs/prx/libSceNKWebKit/src/InspectorContentSearchRegex.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified InspectorContentSearchRegex.cpp createRegularExpressionForSearchString handles null searchString->impl, 8-bit and 16-bit strings, escapes regex special characters matching upstream strchr behavior, and properly constructs RegularExpression into the result slot.
    • Verified countRegularExpressionMatches handles null regex, null content, null or empty impl (returns 0), loops with match() advancing start position by position + 1, avoids infinite loops on empty matches (matchLength > 0 check), and prevents overflow if start >= length.
    • Verified ABI and signature conventions: hidden return pointer for RegularExpression constructor/return value matches Itanium C++ ABI and InventoryExports.hpp was properly updated.
    • Checked AGENTS.md compliance: no unauthorized comments, debt fragment added under docs/dev/debt/changes/feat-nkwebkit-inspector-content-search-regex.md properly documenting divergences/unverified aspects, and tests cover error and normal execution paths without leaking memory.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6007299348 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25170#pullrequestreview-6007299348). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T18:35:41Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `cd9cc88b9e`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_inspectorcontentsearchregex_tests` built cleanly. - **CTest** (`nkwebkit_inspectorcontentsearchregex`): ``` 1/1 Test #4840: nkwebkit_inspectorcontentsearchregex ... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/Export.cpp`, `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp`, `core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp`, `core/libs/prx/libSceNKWebKit/src/InspectorContentSearchRegex.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified InspectorContentSearchRegex.cpp createRegularExpressionForSearchString handles null searchString->impl, 8-bit and 16-bit strings, escapes regex special characters matching upstream strchr behavior, and properly constructs RegularExpression into the result slot. - Verified countRegularExpressionMatches handles null regex, null content, null or empty impl (returns 0), loops with match() advancing start position by position + 1, avoids infinite loops on empty matches (matchLength > 0 check), and prevents overflow if start >= length. - Verified ABI and signature conventions: hidden return pointer for RegularExpression constructor/return value matches Itanium C++ ABI and InventoryExports.hpp was properly updated. - Checked AGENTS.md compliance: no unauthorized comments, debt fragment added under docs/dev/debt/changes/feat-nkwebkit-inspector-content-search-regex.md properly documenting divergences/unverified aspects, and tests cover error and normal execution paths without leaking memory. Looks Good To Me
MarcZX10 commented 2026-11-22 06:04:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T06:04:25Z.

Review: COMMENTED


Reviewed — no blocking findings

The inspected implementation has no verified blocking defect, but ABI compatibility remains unconfirmed and two changed files were excluded from full-text review.

What I ran

Reviewed head 08da9a0774aa2ecc313abdf3d6af1fc2135145fb. I did not run tests or build commands; the test results in the PR description are author-reported. I read the prepared description, commit summary, manifest, and diff, and inspected the implementation and related declarations with repo_read.py.

Results

Check Result Note
Patch inspection passed Changed hunks reviewed
Build and tests not run PR-reported results not independently verified
Console ABI not run Compatibility remains unconfirmed

Findings

Blocking

None verified in the inspected code.

Non-blocking

  • The new exports rely on assumed console ABI details, including the hidden result pointer and SearchStringType values. Host tests do not establish those details; confirm them against a console module before treating the exports as console-verified.

Not verified

  • Full text of core/libs/prx/libSceNKWebKit/Export.cpp and core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp was excluded as too large; their relevant deletion hunks were inspected in the diff.
  • Console behavior and ABI compatibility were not verified.
  • No tests or build checks were run during this review.

Files read from the prepared review bundle: description.md, commits.md, manifest.json, and diff.patch. Changed files whose added or relevant hunks were inspected: core/libs/prx/libSceJsc/include/YarrRegularExpressionExports.hpp, core/libs/prx/libSceJsc/src/YarrRegularExpression.cpp, core/libs/prx/libSceNKWebKit/Export.cpp (diff hunk only), core/libs/prx/libSceNKWebKit/include/InspectorContentSearchRegexExports.hpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp (diff hunk only), core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp, core/libs/prx/libSceNKWebKit/src/InspectorContentSearchRegex.cpp, core/libs/prx/libSceNKWebKit/tests/InspectorContentSearchRegex.cpp (diff), and docs/dev/debt/changes/feat-nkwebkit-inspector-content-search-regex.md (diff).

To get this to a good state

Nothing is required. Optional: confirm the ABI against a console module before claiming console compatibility.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6010650587 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25170#pullrequestreview-6010650587). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T06:04:25Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The inspected implementation has no verified blocking defect, but ABI compatibility remains unconfirmed and two changed files were excluded from full-text review. ## What I ran Reviewed head `08da9a0774aa2ecc313abdf3d6af1fc2135145fb`. I did not run tests or build commands; the test results in the PR description are author-reported. I read the prepared description, commit summary, manifest, and diff, and inspected the implementation and related declarations with `repo_read.py`. ## Results | Check | Result | Note | | --- | --- | --- | | Patch inspection | passed | Changed hunks reviewed | | Build and tests | not run | PR-reported results not independently verified | | Console ABI | not run | Compatibility remains unconfirmed | ## Findings ### Blocking None verified in the inspected code. ### Non-blocking - The new exports rely on assumed console ABI details, including the hidden result pointer and `SearchStringType` values. Host tests do not establish those details; confirm them against a console module before treating the exports as console-verified. ## Not verified - Full text of `core/libs/prx/libSceNKWebKit/Export.cpp` and `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp` was excluded as too large; their relevant deletion hunks were inspected in the diff. - Console behavior and ABI compatibility were not verified. - No tests or build checks were run during this review. Files read from the prepared review bundle: `description.md`, `commits.md`, `manifest.json`, and `diff.patch`. Changed files whose added or relevant hunks were inspected: `core/libs/prx/libSceJsc/include/YarrRegularExpressionExports.hpp`, `core/libs/prx/libSceJsc/src/YarrRegularExpression.cpp`, `core/libs/prx/libSceNKWebKit/Export.cpp` (diff hunk only), `core/libs/prx/libSceNKWebKit/include/InspectorContentSearchRegexExports.hpp`, `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp` (diff hunk only), `core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp`, `core/libs/prx/libSceNKWebKit/src/InspectorContentSearchRegex.cpp`, `core/libs/prx/libSceNKWebKit/tests/InspectorContentSearchRegex.cpp` (diff), and `docs/dev/debt/changes/feat-nkwebkit-inspector-content-search-regex.md` (diff). ## To get this to a good state Nothing is required. Optional: confirm the ABI against a console module before claiming console compatibility.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!25170
No description provided.