feat(libSceNKWebKit): implement Inspector::ContentSearchUtilities::textPositionFromOffset #24214

Merged
Callimann8 merged 1 commit from upstream-pr/24214 into main 2026-11-21 09:13:13 +00:00
Callimann8 commented 2026-11-20 10:33:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Callimann8 on 2026-11-20T10:33:07Z.


What

Implements Inspector::ContentSearchUtilities::textPositionFromOffset(size_t, const Vector<size_t>&) in libSceNKWebKit (NID jnonZqJRfQE), which was a throwing stub in Export.cpp.

It lives in the new src/InspectorContentSearchUtilities.cpp and follows ContentSearchUtilities.cpp at the pinned e12a212a531a revision. The PlayStation 11.x source has the same body:

  • The search is WTF's approximateBinarySearch (binarySearchImpl in ReturnAdjacentElementIfKeyIsNotPresent mode, StdLibExtras.h), copied step for step, so the element it lands on matches WebKit's.
  • The line index moves one forward when the offset is at or past that element. The column is the offset minus the previous entry, or minus 0 on the first line.
  • WTF::TextPosition is two OrdinalNumbers (one int each, zero-based), 8 bytes, returned in one register. The vector is read through the existing NKWebKit::WtfAbi::Vector layout (buffer, capacity, size).
  • An empty vector throws std::out_of_range. WebKit would crash in Vector::at(0) there. The debt fragment records this under Functional and removes the name from the callable-exports table. The declaration is removed from include/InventoryExports.hpp.

It needs no JSC cell, VM or string allocation.

Tested

New nkwebkit_inspectorcontentsearchutilities test: offsets before, on and after each entry of a four-entry vector and a one-entry vector, plus every offset for vectors of 1 to 40 entries checked against std::upper_bound, and the empty-vector throw. It passes on Linux (Ubuntu 24.04, GCC 13.3, Release) and also built standalone with -fsanitize=address,undefined. tools/check_conventions.py and tools/debt_fold.py --check pass. Not tested on a console or with a title.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5411834706 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24214). Originally posted by [Callimann8](https://github.com/Callimann8) on 2026-11-20T10:33:07Z. --- ### What Implements `Inspector::ContentSearchUtilities::textPositionFromOffset(size_t, const Vector<size_t>&)` in libSceNKWebKit (NID `jnonZqJRfQE`), which was a throwing stub in `Export.cpp`. It lives in the new `src/InspectorContentSearchUtilities.cpp` and follows [ContentSearchUtilities.cpp](https://github.com/WebKit/WebKit/blob/e12a212a531a/Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp#L67-L76) at the pinned e12a212a531a revision. The [PlayStation 11.x source](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp#L67-L76) has the same body: - The search is WTF's `approximateBinarySearch` (`binarySearchImpl` in `ReturnAdjacentElementIfKeyIsNotPresent` mode, [StdLibExtras.h](https://github.com/WebKit/WebKit/blob/e12a212a531a/Source/WTF/wtf/StdLibExtras.h#L203-L240)), copied step for step, so the element it lands on matches WebKit's. - The line index moves one forward when the offset is at or past that element. The column is the offset minus the previous entry, or minus 0 on the first line. - `WTF::TextPosition` is two `OrdinalNumber`s (one `int` each, zero-based), 8 bytes, returned in one register. The vector is read through the existing `NKWebKit::WtfAbi::Vector` layout (buffer, capacity, size). - An empty vector throws `std::out_of_range`. WebKit would crash in `Vector::at(0)` there. The debt fragment records this under Functional and removes the name from the callable-exports table. The declaration is removed from `include/InventoryExports.hpp`. It needs no JSC cell, VM or string allocation. ### Tested New `nkwebkit_inspectorcontentsearchutilities` test: offsets before, on and after each entry of a four-entry vector and a one-entry vector, plus every offset for vectors of 1 to 40 entries checked against `std::upper_bound`, and the empty-vector throw. It passes on Linux (Ubuntu 24.04, GCC 13.3, Release) and also built standalone with `-fsanitize=address,undefined`. `tools/check_conventions.py` and `tools/debt_fold.py --check` pass. Not tested on a console or with a title. ### 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
PrivacyOnion commented 2026-11-20 10:35:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T10:35:16Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_inspectorcontentsearchutilities_tests built cleanly.
  • CTest (nkwebkit_inspectorcontentsearchutilities):
    1/1 Test #4734: nkwebkit_inspectorcontentsearchutilities ...   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/InspectorContentSearchUtilities.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified Inspector::ContentSearchUtilities::textPositionFromOffset ABI signature, name mangling (_ZN9Inspector22ContentSearchUtilities22textPositionFromOffsetEmRKN3WTF6VectorImLm0ENS1_15CrashOnOverflowELm16ENS1_10FastMallocEEE), and TextPosition return layout (8 bytes, int line + int column) against WebKit e12a212a531a and PS5 WebKit 11.x upstream definitions.
    • Verified approximateBinarySearch / binarySearchImpl logic step-by-step against WTF StdLibExtras.h in ReturnAdjacentElementIfKeyIsNotPresent mode, including start/size/pos calculation and line index increment condition (offset >= lineEndings[lineIndex]).
    • Verified edge cases including empty vector handling (explicitly checked and throws std::out_of_range as documented in debt fragment), single-element vector, offsets before/at/after line endings, and multiline index calculation.
    • Verified AGENTS.md rule compliance: no unauthorized comments, debt fragment added under docs/dev/debt/changes/feat-nkwebkit-text-position-from-offset.md, export removed from InventoryExports.hpp and Export.cpp, and static_assert on sizeof(TextPosition) == 8.
    • Verified test coverage in tests/InspectorContentSearchUtilities.cpp, ensuring exhaustive testing of arbitrary line count combinations (1 to 40 lines), boundary offsets, exact line/column positions, and empty vector exception handling.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5991263233 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24214#pullrequestreview-5991263233). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T10:35:16Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `2c9dc24618`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_inspectorcontentsearchutilities_tests` built cleanly. - **CTest** (`nkwebkit_inspectorcontentsearchutilities`): ``` 1/1 Test #4734: nkwebkit_inspectorcontentsearchutilities ... 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/InspectorContentSearchUtilities.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified Inspector::ContentSearchUtilities::textPositionFromOffset ABI signature, name mangling (_ZN9Inspector22ContentSearchUtilities22textPositionFromOffsetEmRKN3WTF6VectorImLm0ENS1_15CrashOnOverflowELm16ENS1_10FastMallocEEE), and TextPosition return layout (8 bytes, int line + int column) against WebKit e12a212a531a and PS5 WebKit 11.x upstream definitions. - Verified approximateBinarySearch / binarySearchImpl logic step-by-step against WTF StdLibExtras.h in ReturnAdjacentElementIfKeyIsNotPresent mode, including start/size/pos calculation and line index increment condition (offset >= lineEndings[lineIndex]). - Verified edge cases including empty vector handling (explicitly checked and throws std::out_of_range as documented in debt fragment), single-element vector, offsets before/at/after line endings, and multiline index calculation. - Verified AGENTS.md rule compliance: no unauthorized comments, debt fragment added under docs/dev/debt/changes/feat-nkwebkit-text-position-from-offset.md, export removed from InventoryExports.hpp and Export.cpp, and static_assert on sizeof(TextPosition) == 8. - Verified test coverage in tests/InspectorContentSearchUtilities.cpp, ensuring exhaustive testing of arbitrary line count combinations (1 to 40 lines), boundary offsets, exact line/column positions, and empty vector exception handling. Looks Good To Me
MarcZX10 commented 2026-11-20 10:45:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T10:45:13Z.

Review: COMMENTED


Reviewed — no blocking findings

The implementation and its added unit test were reviewed at head 2c9dc2461890c07dda403344007000465e33c647; no blocking defect was verified, and checks were not run in this review.

What I ran

No commands or tests were run. I inspected the prepared diff and targeted source at the stated head.

Results

Check Result Note
Diff and targeted source review passed Algorithm, ABI declaration, and tests inspected
Unit tests and build not run Linux and sanitizer runs are author-reported
Console behavior not run No console comparison was performed

Findings

Blocking

None.

Non-blocking

None.

Not verified

Full file text was available and read for include/ContentSearchUtilitiesExports.hpp, libSceNKWebKit.hpp, src/InspectorContentSearchUtilities.cpp, tests/InspectorContentSearchUtilities.cpp, and docs/dev/debt/changes/feat-nkwebkit-text-position-from-offset.md. The diff was read for all changed files. Full text was not available for Export.cpp and include/InventoryExports.hpp; their shown changes remove the old stub and declaration. The prepared bundle lists no excluded-by-rule file separately. Build and test outcomes in the description were not independently verified; console behavior and comparison against a console module were not verified.

To get this to a good state

Nothing is required. Optional: verify the implementation against a console module, as the debt note specifies.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5991375959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24214#pullrequestreview-5991375959). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T10:45:13Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The implementation and its added unit test were reviewed at head `2c9dc2461890c07dda403344007000465e33c647`; no blocking defect was verified, and checks were not run in this review. ## What I ran No commands or tests were run. I inspected the prepared diff and targeted source at the stated head. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Algorithm, ABI declaration, and tests inspected | | Unit tests and build | not run | Linux and sanitizer runs are author-reported | | Console behavior | not run | No console comparison was performed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Full file text was available and read for `include/ContentSearchUtilitiesExports.hpp`, `libSceNKWebKit.hpp`, `src/InspectorContentSearchUtilities.cpp`, `tests/InspectorContentSearchUtilities.cpp`, and `docs/dev/debt/changes/feat-nkwebkit-text-position-from-offset.md`. The diff was read for all changed files. Full text was not available for `Export.cpp` and `include/InventoryExports.hpp`; their shown changes remove the old stub and declaration. The prepared bundle lists no excluded-by-rule file separately. Build and test outcomes in the description were not independently verified; console behavior and comparison against a console module were not verified. ## To get this to a good state Nothing is required. Optional: verify the implementation against a console module, as the debt note specifies.
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!24214
No description provided.