feat(libSceNKWebKit): implement the WebCore::NodeTraversal deepLastChild, last and nextAncestorSibling exports #23888

Merged
RiverWhy merged 1 commit from upstream-pr/23888 into main 2026-11-19 23:12:09 +00:00
RiverWhy commented 2026-11-19 20:49:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by RiverWhy on 2026-11-19T20:49:12Z.


What

Implements 4 libSceNKWebKit exports of WebCore::NodeTraversal. All four throw NotImplemented on main today.

  • deepLastChild(Node&): descends through last children until a node has none, returns that node.
  • last(const ContainerNode&): the deepest last descendant, or null when the container is empty.
  • nextAncestorSibling(const Node&): the next sibling of the closest ancestor that has one, or null.
  • nextAncestorSibling(const Node&, const Node*): the same, but returns null on reaching stayWithin.

Source: the libSceNKWebKit.sprx with SHA-256 3af992253665387feeb5df90ff27dff683e3aa270cc4d92a0535b46ab18fa20d. The algorithm follows the pinned WebKit NodeTraversal.cpp. The object offsets come from the module's own code, and they match the pinned Node.h and ContainerNode.h: node flags at 0x1c (bit 0x4 is IsContainerNode), parent at 0x20, next sibling at 0x38, ContainerNode last child at 0x58. They live in the new src/NodeAbi.hpp.

The mangled name of last ends in 4lastERKNS_13ContainerNodeE (ContainerNode is 13 characters).

Only the fields the four functions read are described. The other Node fields are not compared with a console module.

Debt: the fragment docs/dev/debt/changes/feat-nkwebkit-node-traversal.md adds the Functional entry and removes the 4 inventory rows.
Overlap: no open PR matches NodeTraversal (searched the open PRs for the name and for each of the three mangled-name fragments), and on current origin/main the four 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 four function bodies were disassembled and their byte blobs run against this implementation in a harness.

  • 20000 random trees (random shapes, random flag bits, random stayWithin choices), 2,462,494 comparisons of the four functions, 0 mismatches.
  • Dropping the stayWithin check from the two-argument overload gives 9574 mismatches, so the harness does tell the behaviours apart.

In the repository, the new nkwebkit_nodetraversal test builds node trees in memory and checks all four exports on nested, empty and lone containers and on leaves, plus the field offsets (firstChild at 0x50, lastChild at 0x58) and a node whose container flag is cleared but still has a child, which must be treated as a leaf.

Tested

Linux Mint 22.3, GCC 13.3, Release:

  • nkwebkit_nodetraversal 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:5402726008 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23888). Originally posted by [RiverWhy](https://github.com/RiverWhy) on 2026-11-19T20:49:12Z. --- ### What Implements 4 `libSceNKWebKit` exports of `WebCore::NodeTraversal`. All four throw `NotImplemented` on `main` today. - `deepLastChild(Node&)`: descends through last children until a node has none, returns that node. - `last(const ContainerNode&)`: the deepest last descendant, or null when the container is empty. - `nextAncestorSibling(const Node&)`: the next sibling of the closest ancestor that has one, or null. - `nextAncestorSibling(const Node&, const Node*)`: the same, but returns null on reaching `stayWithin`. Source: the `libSceNKWebKit.sprx` with SHA-256 `3af992253665387feeb5df90ff27dff683e3aa270cc4d92a0535b46ab18fa20d`. The algorithm follows the pinned WebKit `NodeTraversal.cpp`. The object offsets come from the module's own code, and they match the pinned `Node.h` and `ContainerNode.h`: node flags at `0x1c` (bit `0x4` is `IsContainerNode`), parent at `0x20`, next sibling at `0x38`, `ContainerNode` last child at `0x58`. They live in the new `src/NodeAbi.hpp`. The mangled name of `last` ends in `4lastERKNS_13ContainerNodeE` (`ContainerNode` is 13 characters). Only the fields the four functions read are described. The other `Node` fields are not compared with a console module. Debt: the fragment `docs/dev/debt/changes/feat-nkwebkit-node-traversal.md` adds the Functional entry and removes the 4 inventory rows. Overlap: no open PR matches `NodeTraversal` (searched the open PRs for the name and for each of the three mangled-name fragments), and on current `origin/main` the four 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 four function bodies were disassembled and their byte blobs run against this implementation in a harness. - 20000 random trees (random shapes, random flag bits, random `stayWithin` choices), 2,462,494 comparisons of the four functions, 0 mismatches. - Dropping the `stayWithin` check from the two-argument overload gives 9574 mismatches, so the harness does tell the behaviours apart. In the repository, the new `nkwebkit_nodetraversal` test builds node trees in memory and checks all four exports on nested, empty and lone containers and on leaves, plus the field offsets (`firstChild` at `0x50`, `lastChild` at `0x58`) and a node whose container flag is cleared but still has a child, which must be treated as a leaf. ### Tested Linux Mint 22.3, GCC 13.3, Release: - `nkwebkit_nodetraversal` 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-19 21:09:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T21:09:14Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the reviewed code and integration support merging.

What I ran

Reviewed head 78c1616dad2758ed72065238373d9bcc20774f8c. I read the prepared description, commits, manifest and diff, the included changed files, and the relevant ranges in the two excluded files through repo_read.py. No tests or build commands were run.

Results

Check Result Note
Traversal logic and ABI passed Internally consistent
Build and test registration passed Configure-dependent source and test globs
Programmatic checks not run No command runner available

Findings

Blocking

None.

Non-blocking

None.

Not verified

The changed files read were include/NodeTraversalExports.hpp, libSceNKWebKit.hpp, src/NodeAbi.hpp, src/NodeTraversal.cpp, tests/NodeTraversal.cpp, and docs/dev/debt/changes/feat-nkwebkit-node-traversal.md. The full texts of Export.cpp and include/InventoryExports.hpp were excluded from the review bundle; I read the relevant ranges at the pinned head. The PR description’s reported Linux test, conventions check, header audit, merge-tree result, and external module harness were not independently run. Windows and console behavior were not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5983440931 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23888#pullrequestreview-5983440931). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-19T21:09:14Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the reviewed code and integration support merging. ## What I ran Reviewed head `78c1616dad2758ed72065238373d9bcc20774f8c`. I read the prepared description, commits, manifest and diff, the included changed files, and the relevant ranges in the two excluded files through `repo_read.py`. No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Traversal logic and ABI | passed | Internally consistent | | Build and test registration | passed | Configure-dependent source and test globs | | Programmatic checks | not run | No command runner available | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The changed files read were `include/NodeTraversalExports.hpp`, `libSceNKWebKit.hpp`, `src/NodeAbi.hpp`, `src/NodeTraversal.cpp`, `tests/NodeTraversal.cpp`, and `docs/dev/debt/changes/feat-nkwebkit-node-traversal.md`. The full texts of `Export.cpp` and `include/InventoryExports.hpp` were excluded from the review bundle; I read the relevant ranges at the pinned head. The PR description’s reported Linux test, conventions check, header audit, merge-tree result, and external module harness were not independently run. Windows and console behavior were not verified. ## To get this to a good state Nothing is required.
PrivacyOnion commented 2026-11-19 21:14:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T21:14:28Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_nodetraversal_tests built cleanly.
  • CTest (nkwebkit_nodetraversal):
    1/1 Test #4705: nkwebkit_nodetraversal ...........   Passed    0.02 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/NodeTraversal.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceNKWebKit/src/NodeAbi.hpp: verified struct Node and ContainerNode layout, member offsets (flags 0x1c, parentNode 0x20, previous 0x30, next 0x38, lastChild 0x58), sizeof(Node) == 0x50, sizeof(ContainerNode) == 0x60, and NodeFlagIsContainerNode bit (1 << 2 == 0x4) against static_asserts and WebKit ABI.
    • core/libs/prx/libSceNKWebKit/src/NodeTraversal.cpp: verified _ZN7WebCore13NodeTraversal13deepLastChildERNS_4NodeE iteratively traverses lastChild using LastChild() helper, terminating on null or non-container leaves.
    • core/libs/prx/libSceNKWebKit/src/NodeTraversal.cpp: verified _ZN7WebCore13NodeTraversal19nextAncestorSiblingERKNS_4NodeE and stayWithin overload correctly traverse parentNode chain, returning ancestor->next or nullptr when reaching stayWithin / root.
    • core/libs/prx/libSceNKWebKit/src/NodeTraversal.cpp: verified _ZN7WebCore13NodeTraversal4lastERKNS_13ContainerNodeE checks current->lastChild, returns nullptr if empty, and otherwise descends to deep last descendant.
    • core/libs/prx/libSceNKWebKit/tests/NodeTraversal.cpp: verified test suite thoroughly exercises non-container leaves, deep trees, empty containers, stale container flags, and stayWithin boundaries.
    • docs/dev/debt/changes/feat-nkwebkit-node-traversal.md and AGENTS.md: verified debt change fragment cleanly registers functional entry, removes stubs from inventory, and complies with no-comment / convention rules.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5983509140 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23888#pullrequestreview-5983509140). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-19T21:14:28Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `78c1616dad`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_nodetraversal_tests` built cleanly. - **CTest** (`nkwebkit_nodetraversal`): ``` 1/1 Test #4705: nkwebkit_nodetraversal ........... Passed 0.02 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/NodeTraversal.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceNKWebKit/src/NodeAbi.hpp: verified struct Node and ContainerNode layout, member offsets (flags 0x1c, parentNode 0x20, previous 0x30, next 0x38, lastChild 0x58), sizeof(Node) == 0x50, sizeof(ContainerNode) == 0x60, and NodeFlagIsContainerNode bit (1 << 2 == 0x4) against static_asserts and WebKit ABI. - core/libs/prx/libSceNKWebKit/src/NodeTraversal.cpp: verified _ZN7WebCore13NodeTraversal13deepLastChildERNS_4NodeE iteratively traverses lastChild using LastChild() helper, terminating on null or non-container leaves. - core/libs/prx/libSceNKWebKit/src/NodeTraversal.cpp: verified _ZN7WebCore13NodeTraversal19nextAncestorSiblingERKNS_4NodeE and stayWithin overload correctly traverse parentNode chain, returning ancestor->next or nullptr when reaching stayWithin / root. - core/libs/prx/libSceNKWebKit/src/NodeTraversal.cpp: verified _ZN7WebCore13NodeTraversal4lastERKNS_13ContainerNodeE checks current->lastChild, returns nullptr if empty, and otherwise descends to deep last descendant. - core/libs/prx/libSceNKWebKit/tests/NodeTraversal.cpp: verified test suite thoroughly exercises non-container leaves, deep trees, empty containers, stale container flags, and stayWithin boundaries. - docs/dev/debt/changes/feat-nkwebkit-node-traversal.md and AGENTS.md: verified debt change fragment cleanly registers functional entry, removes stubs from inventory, and complies with no-comment / convention rules. Looks Good To Me
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!23888
No description provided.