feat(libSceNKWebKit): implement OpaqueJSString::tryCreate #23826

Merged
Callimann8 merged 1 commit from upstream-pr/23826 into main 2026-11-20 19:24:12 +00:00
Callimann8 commented 2026-11-19 18:08:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Callimann8 on 2026-11-19T18:08:27Z.


What

Implements both OpaqueJSString::tryCreate overloads in libSceNKWebKit. Both were throwing stubs in Export.cpp:

  • OpaqueJSString::tryCreate(const WTF::String&) (_ZN14OpaqueJSString9tryCreateERKN3WTF6StringE, NID PVV6vSXtXwE)
  • OpaqueJSString::tryCreate(WTF::String&&) (_ZN14OpaqueJSString9tryCreateEON3WTF6StringE, NID mcOkVwJvgME)

They are in the new src/OpaqueJSString.cpp and follow the pinned WebKit OpaqueJSString.cpp:

  • A null WTF::String returns a null RefPtr<OpaqueJSString>.
  • Any other string, including an empty one, returns a new string with one reference. The HLE already uses GuestJSString as the OpaqueJSString behind JSStringRef (its reference count is at offset 0, and ~OpaqueJSString is exported for it). So the 8-bit or 16-bit characters are copied into a GuestJSString, and the result works with JSStringRetain, JSStringRelease and the other JSString* calls.
  • The String&& overload leaves the source string null, as the upstream move does.

RefPtr<OpaqueJSString> is not trivially copyable, so the guest gets it through a hidden return pointer. The new OpaqueJSStringPtr in src/JscApi.hpp has the same shape (one pointer, non-trivial destructor) to keep that ABI. include/JscExports.hpp declares both functions, and the two placeholders are dropped from InventoryExports.hpp. The debt fragment adds the entry and drops both names from the callable-exports table.

OpaqueJSString::string() is left alone because #23758 implements it.

Tested

Linux (Ubuntu 24.04, GCC 13), no title. New test nkwebkit_opaquejsstring_tests (picked up by the tests/*.cpp glob) checks null, empty, Latin-1 and UTF-16 (with a surrogate pair) strings, the reference count, retain and release, the moved-from source and a null argument. Built it and nkwebkit_jsc_tests in the full CMake build and ran both with ctest: they pass. Also built OpaqueJSString.cpp with the new test by itself under ASan and UBSan and ran it with no errors. python3 tools/debt_fold.py --check passes.

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:5400369283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23826). Originally posted by [Callimann8](https://github.com/Callimann8) on 2026-11-19T18:08:27Z. --- ### What Implements both `OpaqueJSString::tryCreate` overloads in libSceNKWebKit. Both were throwing stubs in `Export.cpp`: - `OpaqueJSString::tryCreate(const WTF::String&)` (`_ZN14OpaqueJSString9tryCreateERKN3WTF6StringE`, NID `PVV6vSXtXwE`) - `OpaqueJSString::tryCreate(WTF::String&&)` (`_ZN14OpaqueJSString9tryCreateEON3WTF6StringE`, NID `mcOkVwJvgME`) They are in the new `src/OpaqueJSString.cpp` and follow the pinned WebKit [OpaqueJSString.cpp](https://github.com/WebKit/WebKit/blob/e12a212a531aeddc11259e8515671cf5188e038d/Source/JavaScriptCore/API/OpaqueJSString.cpp#L35-L49): - A null `WTF::String` returns a null `RefPtr<OpaqueJSString>`. - Any other string, including an empty one, returns a new string with one reference. The HLE already uses `GuestJSString` as the `OpaqueJSString` behind `JSStringRef` (its reference count is at offset 0, and `~OpaqueJSString` is exported for it). So the 8-bit or 16-bit characters are copied into a `GuestJSString`, and the result works with `JSStringRetain`, `JSStringRelease` and the other `JSString*` calls. - The `String&&` overload leaves the source string null, as the upstream move does. `RefPtr<OpaqueJSString>` is not trivially copyable, so the guest gets it through a hidden return pointer. The new `OpaqueJSStringPtr` in `src/JscApi.hpp` has the same shape (one pointer, non-trivial destructor) to keep that ABI. `include/JscExports.hpp` declares both functions, and the two placeholders are dropped from `InventoryExports.hpp`. The debt fragment adds the entry and drops both names from the callable-exports table. `OpaqueJSString::string()` is left alone because #23758 implements it. ### Tested Linux (Ubuntu 24.04, GCC 13), no title. New test `nkwebkit_opaquejsstring_tests` (picked up by the `tests/*.cpp` glob) checks null, empty, Latin-1 and UTF-16 (with a surrogate pair) strings, the reference count, retain and release, the moved-from source and a null argument. Built it and `nkwebkit_jsc_tests` in the full CMake build and ran both with ctest: they pass. Also built `OpaqueJSString.cpp` with the new test by itself under ASan and UBSan and ran it with no errors. `python3 tools/debt_fold.py --check` passes. ### 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-19 18:26:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T18:26:48Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_opaquejsstring_tests built cleanly.
  • CTest (nkwebkit_opaquejsstring):
    1/1 Test #4697: nkwebkit_opaquejsstring ..........   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/include/JscExports.hpp, core/libs/prx/libSceNKWebKit/src/JscApi.hpp, core/libs/prx/libSceNKWebKit/src/OpaqueJSString.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Checked OpaqueJSString::tryCreate(const WTF::String*) and (WTF::String*) in core/libs/prx/libSceNKWebKit/src/OpaqueJSString.cpp for null pointer checks on argument and impl, correctly returning null RefPtr representation (nullptr) when string->impl is null as specified by WebKit upstream.
    • Checked character conversion for both 8-bit (Latin1) and 16-bit (UTF-16) strings against GuestJSString, including length validation via GuestJSStringValidLength and null termination.
    • Checked move semantics in OpaqueJSString::tryCreate(WTF::String*), confirming that the source WTF::String is cleared via move construction.
    • Verified OpaqueJSStringPtr ABI compatibility and lifetime semantics: non-trivially copyable wrapper ensuring hidden-return pointer calling convention matching RefPtr.
    • Verified technical debt fragments in docs/dev/debt/changes/feat-nkwebkit-opaque-jsstring-try-create.md and export registration in JscExports.hpp / InventoryExports.hpp.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5980900531 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23826#pullrequestreview-5980900531). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-19T18:26:48Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `a354e64577`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_opaquejsstring_tests` built cleanly. - **CTest** (`nkwebkit_opaquejsstring`): ``` 1/1 Test #4697: nkwebkit_opaquejsstring .......... 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/include/JscExports.hpp`, `core/libs/prx/libSceNKWebKit/src/JscApi.hpp`, `core/libs/prx/libSceNKWebKit/src/OpaqueJSString.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Checked OpaqueJSString::tryCreate(const WTF::String*) and (WTF::String*) in core/libs/prx/libSceNKWebKit/src/OpaqueJSString.cpp for null pointer checks on argument and impl, correctly returning null RefPtr representation (nullptr) when string->impl is null as specified by WebKit upstream. - Checked character conversion for both 8-bit (Latin1) and 16-bit (UTF-16) strings against GuestJSString, including length validation via GuestJSStringValidLength and null termination. - Checked move semantics in OpaqueJSString::tryCreate(WTF::String*), confirming that the source WTF::String is cleared via move construction. - Verified OpaqueJSStringPtr ABI compatibility and lifetime semantics: non-trivially copyable wrapper ensuring hidden-return pointer calling convention matching RefPtr<OpaqueJSString>. - Verified technical debt fragments in docs/dev/debt/changes/feat-nkwebkit-opaque-jsstring-try-create.md and export registration in JscExports.hpp / InventoryExports.hpp. 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!23826
No description provided.