feat(libSceNKWebKit): implement WKBundleNodeHandle document and frame getters #18094

Merged
adriaespii merged 1 commit from upstream-pr/18094 into main 2026-11-12 14:32:49 +00:00
adriaespii commented 2026-11-10 11:35:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriaespii on 2026-11-10T11:35:54Z.


What

Implement WKBundleNodeHandleCopyDocument, WKBundleNodeHandleCopyDocumentFrame and WKBundleNodeHandleCopyHTMLIFrameElementContentFrame in libSceNKWebKit.

Tested

Unit tests in core/libs/prx/libSceNKWebKit/tests/Base.cpp.

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
  • 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:5240582083 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18094). Originally posted by [adriaespii](https://github.com/adriaespii) on 2026-11-10T11:35:54Z. --- ### What Implement WKBundleNodeHandleCopyDocument, WKBundleNodeHandleCopyDocumentFrame and WKBundleNodeHandleCopyHTMLIFrameElementContentFrame in libSceNKWebKit. ### Tested Unit tests in core/libs/prx/libSceNKWebKit/tests/Base.cpp. ### 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) - [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
slopgobblercobbler commented 2026-11-10 13:04:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-11-10T13:04:21Z.

Review: DISMISSED


Windows CI check of head 612b4e6249 (run 42811120332, job 129812561229) failed because nkwebkit_base_tests does not compile:

D:/a/AnyPS5/AnyPS5/core/libs/prx/libSceNKWebKit/tests/Base.cpp:1144:15: error: 'Release' is not a member of 'NKWebKit'; did you mean 'NKWebKit::WtfAbi::Release'?
 1144 |     NKWebKit::Release(copiedDoc);
      |               ^~~~~~~
D:/a/AnyPS5/AnyPS5/core/libs/prx/libSceNKWebKit/tests/Base.cpp:1148:15: error: 'Release' is not a member of 'NKWebKit'; did you mean 'NKWebKit::WtfAbi::Release'?
 1148 |     NKWebKit::Release(copiedDocFrame);
      |               ^~~~~~~
D:/a/AnyPS5/AnyPS5/core/libs/prx/libSceNKWebKit/tests/Base.cpp:1152:15: error: 'Release' is not a member of 'NKWebKit'; did you mean 'NKWebKit::WtfAbi::Release'?
 1152 |     NKWebKit::Release(copiedIframe);
      |               ^~~~~~~
D:/a/AnyPS5/AnyPS5/core/libs/prx/libSceNKWebKit/tests/Base.cpp:1154:15: error: 'Release' is not a member of 'NKWebKit'; did you mean 'NKWebKit::WtfAbi::Release'?
 1154 |     NKWebKit::Release(ref);
      |               ^~~~~~~
D:/a/AnyPS5/AnyPS5/core/libs/prx/libSceNKWebKit/tests/Base.cpp:1156:5: error: 'RequireThrows' was not declared in this scope
 1156 |     RequireThrows<std::runtime_error>([] {
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Analysis

  1. NKWebKit::Release does not exist. C-style WebKit objects returned by copy getters must be released using WKRelease(copiedDoc).
  2. RequireThrows is not defined in tests/Base.cpp. The standard pattern in Base.cpp is:
    bool threw = false;
    try {
        WKBundleNodeHandleCopyDocument(nullptr);
    } catch (const std::invalid_argument&) {
        threw = true;
    }
    Require(threw);
    
    Note that NKWebKit::Cast throws std::invalid_argument, so catch (const std::runtime_error&) would not catch it.
  3. In TestBundleNodeHandle(), calling NKWebKit::ToRef(...) inside comparisons (Require(copiedDoc == NKWebKit::ToRef(doc));) leaks retained references. Compare pointers directly using .Get():
    Require(copiedDoc == doc.Get());
    
    Similarly, the test handle reference can be obtained via const void* ref = handle.Get(); without needing a manual release on ref.

Suggested Fix

Replacing TestBundleNodeHandle() in core/libs/prx/libSceNKWebKit/tests/Base.cpp with the following resolves the build failure and prevents reference leaks:

static void TestBundleNodeHandle() {
    Require(WKBundleNodeHandleGetTypeID() == 121);
    auto handle = NKWebKit::Make<NKWebKit::BundleNodeHandle>();
    const void* ref = handle.Get();
    Require(WKBundleNodeHandleCopyDocument(ref) == nullptr);
    Require(WKBundleNodeHandleCopyDocumentFrame(ref) == nullptr);
    Require(WKBundleNodeHandleCopyHTMLIFrameElementContentFrame(ref) == nullptr);

    auto doc = NKWebKit::Make<NKWebKit::BundleNodeHandle>();
    auto docFrame = NKWebKit::Make<NKWebKit::BundleFrame>();
    auto iframeContent = NKWebKit::Make<NKWebKit::BundleFrame>();

    handle->document = doc;
    handle->documentFrame = docFrame;
    handle->htmlIFrameElementContentFrame = iframeContent;

    auto* copiedDoc = WKBundleNodeHandleCopyDocument(ref);
    Require(copiedDoc == doc.Get());
    WKRelease(copiedDoc);

    auto* copiedDocFrame = WKBundleNodeHandleCopyDocumentFrame(ref);
    Require(copiedDocFrame == docFrame.Get());
    WKRelease(copiedDocFrame);

    auto* copiedIframe = WKBundleNodeHandleCopyHTMLIFrameElementContentFrame(ref);
    Require(copiedIframe == iframeContent.Get());
    WKRelease(copiedIframe);

    bool threw = false;
    try {
        WKBundleNodeHandleCopyDocument(nullptr);
    } catch (const std::invalid_argument&) {
        threw = true;
    }
    Require(threw);
}
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5842269117 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18094#pullrequestreview-5842269117). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-10T13:04:21Z. **Review:** DISMISSED --- Windows CI check of head `612b4e6249` (run 42811120332, job 129812561229) failed because `nkwebkit_base_tests` does not compile: ```text D:/a/AnyPS5/AnyPS5/core/libs/prx/libSceNKWebKit/tests/Base.cpp:1144:15: error: 'Release' is not a member of 'NKWebKit'; did you mean 'NKWebKit::WtfAbi::Release'? 1144 | NKWebKit::Release(copiedDoc); | ^~~~~~~ D:/a/AnyPS5/AnyPS5/core/libs/prx/libSceNKWebKit/tests/Base.cpp:1148:15: error: 'Release' is not a member of 'NKWebKit'; did you mean 'NKWebKit::WtfAbi::Release'? 1148 | NKWebKit::Release(copiedDocFrame); | ^~~~~~~ D:/a/AnyPS5/AnyPS5/core/libs/prx/libSceNKWebKit/tests/Base.cpp:1152:15: error: 'Release' is not a member of 'NKWebKit'; did you mean 'NKWebKit::WtfAbi::Release'? 1152 | NKWebKit::Release(copiedIframe); | ^~~~~~~ D:/a/AnyPS5/AnyPS5/core/libs/prx/libSceNKWebKit/tests/Base.cpp:1154:15: error: 'Release' is not a member of 'NKWebKit'; did you mean 'NKWebKit::WtfAbi::Release'? 1154 | NKWebKit::Release(ref); | ^~~~~~~ D:/a/AnyPS5/AnyPS5/core/libs/prx/libSceNKWebKit/tests/Base.cpp:1156:5: error: 'RequireThrows' was not declared in this scope 1156 | RequireThrows<std::runtime_error>([] { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` ### Analysis 1. `NKWebKit::Release` does not exist. C-style WebKit objects returned by copy getters must be released using `WKRelease(copiedDoc)`. 2. `RequireThrows` is not defined in `tests/Base.cpp`. The standard pattern in `Base.cpp` is: ```cpp bool threw = false; try { WKBundleNodeHandleCopyDocument(nullptr); } catch (const std::invalid_argument&) { threw = true; } Require(threw); ``` Note that `NKWebKit::Cast` throws `std::invalid_argument`, so `catch (const std::runtime_error&)` would not catch it. 3. In `TestBundleNodeHandle()`, calling `NKWebKit::ToRef(...)` inside comparisons (`Require(copiedDoc == NKWebKit::ToRef(doc));`) leaks retained references. Compare pointers directly using `.Get()`: ```cpp Require(copiedDoc == doc.Get()); ``` Similarly, the test handle reference can be obtained via `const void* ref = handle.Get();` without needing a manual release on `ref`. ### Suggested Fix Replacing `TestBundleNodeHandle()` in `core/libs/prx/libSceNKWebKit/tests/Base.cpp` with the following resolves the build failure and prevents reference leaks: ```cpp static void TestBundleNodeHandle() { Require(WKBundleNodeHandleGetTypeID() == 121); auto handle = NKWebKit::Make<NKWebKit::BundleNodeHandle>(); const void* ref = handle.Get(); Require(WKBundleNodeHandleCopyDocument(ref) == nullptr); Require(WKBundleNodeHandleCopyDocumentFrame(ref) == nullptr); Require(WKBundleNodeHandleCopyHTMLIFrameElementContentFrame(ref) == nullptr); auto doc = NKWebKit::Make<NKWebKit::BundleNodeHandle>(); auto docFrame = NKWebKit::Make<NKWebKit::BundleFrame>(); auto iframeContent = NKWebKit::Make<NKWebKit::BundleFrame>(); handle->document = doc; handle->documentFrame = docFrame; handle->htmlIFrameElementContentFrame = iframeContent; auto* copiedDoc = WKBundleNodeHandleCopyDocument(ref); Require(copiedDoc == doc.Get()); WKRelease(copiedDoc); auto* copiedDocFrame = WKBundleNodeHandleCopyDocumentFrame(ref); Require(copiedDocFrame == docFrame.Get()); WKRelease(copiedDocFrame); auto* copiedIframe = WKBundleNodeHandleCopyHTMLIFrameElementContentFrame(ref); Require(copiedIframe == iframeContent.Get()); WKRelease(copiedIframe); bool threw = false; try { WKBundleNodeHandleCopyDocument(nullptr); } catch (const std::invalid_argument&) { threw = true; } Require(threw); } ```
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!18094
No description provided.