feat(libSceNKWebKit): implement six ContainerNode and Node element navigation exports #24319

Open
RiverWhy wants to merge 3 commits from upstream-pr/24319 into main
RiverWhy commented 2026-11-20 14:04:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by RiverWhy on 2026-11-20T14:04:07Z.


What

Implements 6 libSceNKWebKit exports that walk the child and sibling links of a DOM node. All six throw NotImplemented on main today.

  • ContainerNode::firstElementChild() const and lastElementChild() const: the first or last child whose node flags carry the element bit, or null.
  • ContainerNode::childElementCount() const: the number of children with the element bit.
  • ContainerNode::traverseToChildAt(unsigned) const: the child at the given index (the first child for 0), or null when the index is past the end.
  • Node::nextElementSibling() const and previousElementSibling() const: the next or previous sibling with the element bit, or null.

Source: the libSceNKWebKit.sprx with SHA-256 3af992253665387feeb5df90ff27dff683e3aa270cc4d92a0535b46ab18fa20d. The logic follows the pinned WebKit ContainerNode.cpp (ElementTraversal::firstChild/lastChild, childrenOfType<Element>, traverseToChildAt) and Node.cpp (ElementTraversal::nextSibling/previousSibling). The offsets come from the module's own code and match the pinned Node.h and ContainerNode.h: flags at 0x1c (element bit 0x8), previous sibling 0x30, next sibling 0x38, first child 0x50, last child 0x58. All except the element bit were already in src/NodeAbi.hpp. Like the merged NodeTraversal exports, a null or unreadable node throws instead of faulting.

Only the fields the six functions read were checked against the module; the other Node members are laid out from the pinned header.

Debt: the fragment docs/dev/debt/changes/feat-nkwebkit-element-navigation.md adds the Functional entry and removes the six inventory rows.
Overlap: no open PR matches these names (all 166 open PRs touching libSceNKWebKit were diffed against main), and on current origin/main all six are still only the NotImplemented stubs.

How it was checked

Offline, against the module's own code (none of it is in the repository): the six function bodies were disassembled and their bytes run against this implementation in a harness.

  • 3,000,000 random trees (0 to 13 children, random bytes in every field, the element bit random, all clear or all set), every function called on the parent or on each node, 0 mismatches, comparing the returned pointer (the count as 32 bits).
  • Seven mutants (wrong element bit, first child instead of last, wrong link direction, counting every child, off-by-one index, a sibling walk that includes the node itself, previous walking forward) give between 39,515 and 1,872,973 mismatches per 200,000 runs, so the harness does tell the behaviours apart.

In the repository, the new nkwebkit_elementnavigation test builds node trees of element, container and text nodes and checks all six exports, including no elements, a single element, an index past the end, and null or unreadable nodes.

Tested

Linux Mint 22.3, GCC 13.3, Release:

  • nkwebkit_elementnavigation passes (100% of the 1 test selected).
  • tools/check_conventions.py passes.
  • core/libs/tests/test_public_headers.py --audit-only passes.
  • git merge-tree against current origin/main is clean.
  • Not run on Windows.

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:5414633874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24319). Originally posted by [RiverWhy](https://github.com/RiverWhy) on 2026-11-20T14:04:07Z. --- ### What Implements 6 `libSceNKWebKit` exports that walk the child and sibling links of a DOM node. All six throw `NotImplemented` on `main` today. - `ContainerNode::firstElementChild() const` and `lastElementChild() const`: the first or last child whose node flags carry the element bit, or null. - `ContainerNode::childElementCount() const`: the number of children with the element bit. - `ContainerNode::traverseToChildAt(unsigned) const`: the child at the given index (the first child for 0), or null when the index is past the end. - `Node::nextElementSibling() const` and `previousElementSibling() const`: the next or previous sibling with the element bit, or null. Source: the `libSceNKWebKit.sprx` with SHA-256 `3af992253665387feeb5df90ff27dff683e3aa270cc4d92a0535b46ab18fa20d`. The logic follows the pinned WebKit `ContainerNode.cpp` (`ElementTraversal::firstChild/lastChild`, `childrenOfType<Element>`, `traverseToChildAt`) and `Node.cpp` (`ElementTraversal::nextSibling/previousSibling`). The offsets come from the module's own code and match the pinned `Node.h` and `ContainerNode.h`: flags at `0x1c` (element bit `0x8`), previous sibling `0x30`, next sibling `0x38`, first child `0x50`, last child `0x58`. All except the element bit were already in `src/NodeAbi.hpp`. Like the merged NodeTraversal exports, a null or unreadable node throws instead of faulting. Only the fields the six functions read were checked against the module; the other `Node` members are laid out from the pinned header. Debt: the fragment `docs/dev/debt/changes/feat-nkwebkit-element-navigation.md` adds the Functional entry and removes the six inventory rows. Overlap: no open PR matches these names (all 166 open PRs touching `libSceNKWebKit` were diffed against `main`), and on current `origin/main` all six are still only the `NotImplemented` stubs. ### How it was checked Offline, against the module's own code (none of it is in the repository): the six function bodies were disassembled and their bytes run against this implementation in a harness. - 3,000,000 random trees (0 to 13 children, random bytes in every field, the element bit random, all clear or all set), every function called on the parent or on each node, 0 mismatches, comparing the returned pointer (the count as 32 bits). - Seven mutants (wrong element bit, first child instead of last, wrong link direction, counting every child, off-by-one index, a sibling walk that includes the node itself, previous walking forward) give between 39,515 and 1,872,973 mismatches per 200,000 runs, so the harness does tell the behaviours apart. In the repository, the new `nkwebkit_elementnavigation` test builds node trees of element, container and text nodes and checks all six exports, including no elements, a single element, an index past the end, and null or unreadable nodes. ### Tested Linux Mint 22.3, GCC 13.3, Release: - `nkwebkit_elementnavigation` passes (100% of the 1 test selected). - `tools/check_conventions.py` passes. - `core/libs/tests/test_public_headers.py --audit-only` passes. - `git merge-tree` against current `origin/main` is clean. - Not run on Windows. ### Checklist - [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
MarcZX10 commented 2026-11-20 14:19:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T14:19:21Z.

Review: COMMENTED


Reviewed — no blocking findings

The implementation and changed lines are reviewable at the supplied head, but I did not run the reported checks, so a formal approval is not justified.

What I ran

  • Reviewed head 4bf9b3d3a20a435fd377f0cac928fc79ba071c76 against base main using the prepared diff and pinned reader.
  • No tests or build commands were run.

Results

Check Result Note
Changed implementation passed Navigation logic and ABI declarations inspected
Reported tests and checks not run Results are author reported
Windows behavior not run Not tested by author

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • The author-reported Linux test, convention check, public-header audit, and merge-tree check were not run in this review.
  • Windows behavior was not verified.
  • Full text of core/libs/prx/libSceNKWebKit/Export.cpp and core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp was excluded from the review folder; their removals were inspected in the diff.
  • Read changed lines from ElementNavigationExports.hpp, libSceNKWebKit.hpp, ElementNavigation.cpp, NodeAbi.hpp, tests/ElementNavigation.cpp, and docs/dev/debt/changes/feat-nkwebkit-element-navigation.md; also read the relevant diff hunks for Export.cpp and InventoryExports.hpp.

To get this to a good state

Nothing is required. Optional: run the reported checks on this head and verify on Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5994101887 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24319#pullrequestreview-5994101887). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T14:19:21Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The implementation and changed lines are reviewable at the supplied head, but I did not run the reported checks, so a formal approval is not justified. ## What I ran - Reviewed head `4bf9b3d3a20a435fd377f0cac928fc79ba071c76` against base `main` using the prepared diff and pinned reader. - No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Changed implementation | passed | Navigation logic and ABI declarations inspected | | Reported tests and checks | not run | Results are author reported | | Windows behavior | not run | Not tested by author | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - The author-reported Linux test, convention check, public-header audit, and merge-tree check were not run in this review. - Windows behavior was not verified. - Full text of `core/libs/prx/libSceNKWebKit/Export.cpp` and `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp` was excluded from the review folder; their removals were inspected in the diff. - Read changed lines from `ElementNavigationExports.hpp`, `libSceNKWebKit.hpp`, `ElementNavigation.cpp`, `NodeAbi.hpp`, `tests/ElementNavigation.cpp`, and `docs/dev/debt/changes/feat-nkwebkit-element-navigation.md`; also read the relevant diff hunks for `Export.cpp` and `InventoryExports.hpp`. ## To get this to a good state Nothing is required. Optional: run the reported checks on this head and verify on Windows.
PrivacyOnion commented 2026-11-20 14:20:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T14:20:46Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_elementnavigation_tests built cleanly.
  • CTest (nkwebkit_elementnavigation):
    1/1 Test #4717: nkwebkit_elementnavigation .......   Passed    0.08 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/NodeAbi.hpp, core/libs/prx/libSceNKWebKit/src/ElementNavigation.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified GuestCopyIn_nid_no_patch memory validation and errno preservation in ReadGuest within core/libs/prx/libSceNKWebKit/src/ElementNavigation.cpp
    • Verified bitmask check (node.nodeFlags & NodeFlagIsElementNode) matching WebCore NodeFlagIsElementNode (1u << 3) and NodeAbi.hpp definitions
    • Verified tree navigation logic in _ZNK7WebCore13ContainerNode17firstElementChildEv, lastElementChild, childElementCount, traverseToChildAt, nextElementSibling, and previousElementSibling matching WebKit ElementTraversal semantics
    • Verified traverseToChildAt 0-based indexing and boundary conditions when index extends past the child list
    • Verified AGENTS.md conventions: no prohibited comments, debt fragment added under docs/dev/debt/changes/feat-nkwebkit-element-navigation.md, unexported functions cleaned up from InventoryExports.hpp and Export.cpp

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5994120009 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24319#pullrequestreview-5994120009). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T14:20:46Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `4bf9b3d3a2`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_elementnavigation_tests` built cleanly. - **CTest** (`nkwebkit_elementnavigation`): ``` 1/1 Test #4717: nkwebkit_elementnavigation ....... Passed 0.08 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/NodeAbi.hpp`, `core/libs/prx/libSceNKWebKit/src/ElementNavigation.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified GuestCopyIn_nid_no_patch memory validation and errno preservation in ReadGuest within core/libs/prx/libSceNKWebKit/src/ElementNavigation.cpp - Verified bitmask check (node.nodeFlags & NodeFlagIsElementNode) matching WebCore NodeFlagIsElementNode (1u << 3) and NodeAbi.hpp definitions - Verified tree navigation logic in _ZNK7WebCore13ContainerNode17firstElementChildEv, lastElementChild, childElementCount, traverseToChildAt, nextElementSibling, and previousElementSibling matching WebKit ElementTraversal semantics - Verified traverseToChildAt 0-based indexing and boundary conditions when index extends past the child list - Verified AGENTS.md conventions: no prohibited comments, debt fragment added under docs/dev/debt/changes/feat-nkwebkit-element-navigation.md, unexported functions cleaned up from InventoryExports.hpp and Export.cpp Looks Good To Me
MarcZX10 commented 2026-11-21 03:05:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T03:05:05Z.

Review: COMMENTED


Reviewed — comments

The implementation follows the described child and sibling walks, but its error handling needs a targeted follow-up before the review can be fully resolved.

What I ran

Inspected head 6351124a0102f93f8d34d47fc480d9f51998c883. No commands or tests were run; the reported Linux test and checks are author-reported. The base merge check is also author-reported as clean. Read the prepared description, commits, manifest, diff, and the full text of ElementNavigation.cpp, ElementNavigationExports.hpp, NodeAbi.hpp, ElementNavigation.cpp tests, libSceNKWebKit.hpp, and CMakeLists.txt. The full text of Export.cpp and InventoryExports.hpp was excluded from the review folder and not read; their changed hunks were inspected in the diff. Also inspected the debt entry hunk.

Results

Check Result Note
Source review passed Six walks and their edge cases inspected
Automated checks not run Reported checks are author-reported
Windows and console behavior not run No local runs reported by reviewer

Findings

Blocking

None.

Non-blocking

  • ElementNavigation.cpp:20 and ElementNavigation.cpp:21 — errno is restored only after GuestCopyIn_nid_no_patch returns normally. If that helper throws, the intended errno preservation is bypassed. Consider using a small RAII guard so restoration also occurs during exception unwinding. This is low priority unless GuestCopyIn_nid_no_patch can throw in this runtime.

Not verified

  • Full contents of Export.cpp and InventoryExports.hpp were excluded by the review-folder size rule; only the changed hunks in the prepared diff were inspected.
  • Module disassembly, randomized harness, test execution, conventions check, public-header audit, merge-tree check, Windows build, and physical-console behavior were not independently run or confirmed.
  • ElementNavigation.cpp was read in full; only the relevant diff hunk of the tests and debt entry were inspected.

To get this to a good state

Nothing is required. Optional: use an errno guard if the guest-copy helper can throw.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002449952 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24319#pullrequestreview-6002449952). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T03:05:05Z. **Review:** COMMENTED --- # Reviewed — comments The implementation follows the described child and sibling walks, but its error handling needs a targeted follow-up before the review can be fully resolved. ## What I ran Inspected head `6351124a0102f93f8d34d47fc480d9f51998c883`. No commands or tests were run; the reported Linux test and checks are author-reported. The base merge check is also author-reported as clean. Read the prepared description, commits, manifest, diff, and the full text of `ElementNavigation.cpp`, `ElementNavigationExports.hpp`, `NodeAbi.hpp`, `ElementNavigation.cpp` tests, `libSceNKWebKit.hpp`, and `CMakeLists.txt`. The full text of `Export.cpp` and `InventoryExports.hpp` was excluded from the review folder and not read; their changed hunks were inspected in the diff. Also inspected the debt entry hunk. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Six walks and their edge cases inspected | | Automated checks | not run | Reported checks are author-reported | | Windows and console behavior | not run | No local runs reported by reviewer | ## Findings ### Blocking None. ### Non-blocking - `ElementNavigation.cpp:20` and `ElementNavigation.cpp:21` — `errno` is restored only after `GuestCopyIn_nid_no_patch` returns normally. If that helper throws, the intended errno preservation is bypassed. Consider using a small RAII guard so restoration also occurs during exception unwinding. This is low priority unless `GuestCopyIn_nid_no_patch` can throw in this runtime. ## Not verified - Full contents of `Export.cpp` and `InventoryExports.hpp` were excluded by the review-folder size rule; only the changed hunks in the prepared diff were inspected. - Module disassembly, randomized harness, test execution, conventions check, public-header audit, merge-tree check, Windows build, and physical-console behavior were not independently run or confirmed. - `ElementNavigation.cpp` was read in full; only the relevant diff hunk of the tests and debt entry were inspected. ## To get this to a good state Nothing is required. Optional: use an errno guard if the guest-copy helper can throw.
MarcZX10 commented 2026-11-25 18:16:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T18:16:43Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation matches the described child and sibling traversal behavior, and the reviewed source supports merging.

What I ran

Reviewed head 23c6f168b5f6eca8901d5762c375d02a186f8076 using the prepared diff and pinned repo_read.py reader. No commands or tests were run by me; the reported Linux test and checks are author supplied.

Results

Check Result Note
Diff and changed code passed Reviewed the implementation and registered declarations
Automated checks not run Results in the description are author reported
Windows and console behavior not run Not verified here

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read the full text of ElementNavigationExports.hpp, ElementNavigation.cpp, NodeAbi.hpp, ElementNavigation.cpp tests, and the debt entry; I read the relevant portions of libSceNKWebKit.hpp, InventoryExports.hpp, and Export.cpp. The latter three were included in the review folder, though only relevant ranges were read. Export.cpp was excluded from the prepared folder and accessed through the pinned reader. I did not read the remaining contents of the large InventoryExports.hpp or libSceNKWebKit.hpp files, and did not run builds, tests, or checks.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6062737512 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24319#pullrequestreview-6062737512). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T18:16:43Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation matches the described child and sibling traversal behavior, and the reviewed source supports merging. ## What I ran Reviewed head `23c6f168b5f6eca8901d5762c375d02a186f8076` using the prepared diff and pinned `repo_read.py` reader. No commands or tests were run by me; the reported Linux test and checks are author supplied. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Reviewed the implementation and registered declarations | | Automated checks | not run | Results in the description are author reported | | Windows and console behavior | not run | Not verified here | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read the full text of `ElementNavigationExports.hpp`, `ElementNavigation.cpp`, `NodeAbi.hpp`, `ElementNavigation.cpp` tests, and the debt entry; I read the relevant portions of `libSceNKWebKit.hpp`, `InventoryExports.hpp`, and `Export.cpp`. The latter three were included in the review folder, though only relevant ranges were read. `Export.cpp` was excluded from the prepared folder and accessed through the pinned reader. I did not read the remaining contents of the large `InventoryExports.hpp` or `libSceNKWebKit.hpp` files, and did not run builds, tests, or checks. ## To get this to a good state Nothing is required.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/24319:upstream-pr/24319'
git switch 'upstream-pr/24319'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/24319'
git switch 'upstream-pr/24319'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/24319'
git switch 'upstream-pr/24319'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/24319'
git switch 'main'
git merge --squash 'upstream-pr/24319'
git switch 'main'
git merge --ff-only 'upstream-pr/24319'
git switch 'main'
git merge 'upstream-pr/24319'
git push origin 'main'
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!24319
No description provided.