feat(libSceJsc): implement WTF URL, time and StringBuilder read-only helpers #19104

Merged
KernelPanicNT merged 2 commits from upstream-pr/19104 into main 2026-11-13 01:08:26 +00:00
KernelPanicNT commented 2026-11-12 19:43:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KernelPanicNT on 2026-11-12T19:43:18Z.


What

Implements nine read-only WTF helpers in libSceJsc that threw through NotImplemented_nid_no_patch. They are ported from WebKit c55364d53f97, the revision that the module's WtfStringSearch.cpp and its debt entry already follow.

Export NID
URL::port() const AxbrDa89hBs
URL::query() const 0CB7Dz8pEuA
URL::isLocalFile() const 2awTIdIwODI
URL::protocolIsAbout() const YeskHF2qK4I
URL::stringWithoutQueryOrFragmentIdentifier() const Qlcy3AKepzU
WTF::defaultPortForProtocol(StringView) 8stlbyGspnE
TimeWithDynamicClockType::operator<(const TimeWithDynamicClockType&) const -tPqziuAbt0
Seconds::operator+(const TimeWithDynamicClockType&) const -oW-aAeCPs4
StringBuilder::isAllASCII() const R5rWHiU8BF4
  • New src/WtfUrlAbi.hpp adds layouts to the 24-byte StringImpl and 16-byte StringView that the module already uses. These are the same layouts libSceNKWebKit models in WtfStringAbi.hpp and WtfTextAbi.hpp, all pinned with static_assert:

    • the 40-byte release URL: string, bit field with valid bit 0, port length in bits 3-5 and scheme end from bit 6, then seven offsets;
    • the 40-byte release StringBuilder;
    • Seconds and TimeWithDynamicClockType.

    WtfStringAbi.hpp is not touched, so this does not collide with the String layout that #18430 and #18442 add there.

  • Optional<uint16_t> is returned indirectly, with the flag at byte 0 and the value at byte 2. WTF::Optional at this revision has a user-provided copy constructor, so the Itanium ABI returns it through a hidden pointer. The same reasoning backs ResponseOptionalTime in libSceNKWebKit.

  • port parses the substring after hostEnd with parseUInt16/toIntegralType<uint16_t>. It skips leading and trailing isSpaceOrNewline characters: Latin-1 ASCII spaces, and above U+00FF the Unicode bidi class WS set. It accepts an optional + and decimal digits only, and gives no value above 65535. StringView::substring clamping is kept, including empty() (a non-null zero-length view) when the start is past the end.

  • query returns a null view when queryEnd == pathEnd. stringWithoutQueryOrFragmentIdentifier returns the whole string for an invalid URL, and otherwise the string up to pathEnd.

  • isLocalFile and protocolIsAbout are protocolIs(const char*): false for an invalid URL, otherwise an ASCII-case-insensitive (| 0x20) match of the scheme against file or about.

  • defaultPortForProtocol is URLParser::defaultPortForProtocol. It is case-sensitive: ws/http give 80, wss/https give 443, ftp gives 21. One quirk of this revision is reproduced: a scheme starting with w whose length is not 2 or 3 returns false converted to an engaged port 0. The testing override map that WebKit checks first stays empty, because this module exports neither registerDefaultPortForProtocolForTesting nor clearDefaultPortForProtocolMapForTesting.

  • TimeWithDynamicClockType::operator< compares the raw seconds. Different clock types hit a RELEASE_ASSERT in WebKit, and here they throw std::invalid_argument. Seconds::operator+ returns other + *this with the time's clock.

  • StringBuilder::isAllASCII returns true for length 0. Otherwise it reads the characters of m_string, or m_buffer when the string is null, in the builder's width, and checks that no unit is above 0x7F. An overflowed builder (RELEASE_ASSERT in length()), a negative length, a nonzero length with no string or buffer, and null pointers throw.

Debt: two entries are added under Functional. The six InventoryExports.hpp rows leave the NID table. The inventory counts in the prose are left as they are; the generated progress report gives current totals.

Left out of this PR: pageMask(), SHA1::hexDigest and the random/UUID helpers, which need a device page size or CString allocation.

Source of the behaviour (WebKit c55364d53f97; no public reimplementation of these exports was found, so this is the only source)

Tested

Linux x86-64 (Ubuntu 24.04, GCC 14), on main 09ab49de9649. The new jsc_wtf_url test covers:

  • port and query on a parsed-style URL. A port of 65535, 65536, +80, -1, 8a, 8\t, empty and 00042; U+3000 around a digit; U+00A0 and a full-width digit.
  • The null and empty-view cases of query and stringWithoutQueryOrFragmentIdentifier, and a null URL string.
  • Case-insensitive file/about, a longer scheme, an invalid URL and a 16-bit URL.
  • Every defaultPortForProtocol branch, including w and webcal giving an engaged 0, a 16-bit scheme and a null view with a length.
  • operator< with NaN and with mismatched clocks; Seconds::operator+ keeping the clock.
  • isAllASCII for an empty builder, string before buffer, 8-bit and 16-bit buffers, an overflowed builder, no storage and a null this.

Results:

  • ctest -R '^jsc_wtf_(url|string_search)$' passed in 2 of 2 runs.
  • Negative control: with the nine bodies replaced by NotImplemented_nid_no_patch, jsc_wtf_url aborts.
  • tools/progress.py --compare: +9 implemented (libSceJsc 55/737 -> 64/737).
  • tools/check_conventions.py --base origin/main passes.

Not tested on a device 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
  • 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 (#18430, #18442 and #18951 touch libSceJsc Export.cpp, CMakeLists.txt and the debt file but implement none of these nine)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5284071205 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19104). Originally posted by [KernelPanicNT](https://github.com/KernelPanicNT) on 2026-11-12T19:43:18Z. --- ### What Implements nine read-only WTF helpers in `libSceJsc` that threw through `NotImplemented_nid_no_patch`. They are ported from WebKit `c55364d53f97`, the revision that the module's `WtfStringSearch.cpp` and its debt entry already follow. | Export | NID | |---|---| | `URL::port() const` | `AxbrDa89hBs` | | `URL::query() const` | `0CB7Dz8pEuA` | | `URL::isLocalFile() const` | `2awTIdIwODI` | | `URL::protocolIsAbout() const` | `YeskHF2qK4I` | | `URL::stringWithoutQueryOrFragmentIdentifier() const` | `Qlcy3AKepzU` | | `WTF::defaultPortForProtocol(StringView)` | `8stlbyGspnE` | | `TimeWithDynamicClockType::operator<(const TimeWithDynamicClockType&) const` | `-tPqziuAbt0` | | `Seconds::operator+(const TimeWithDynamicClockType&) const` | `-oW-aAeCPs4` | | `StringBuilder::isAllASCII() const` | `R5rWHiU8BF4` | - New `src/WtfUrlAbi.hpp` adds layouts to the 24-byte `StringImpl` and 16-byte `StringView` that the module already uses. These are the same layouts `libSceNKWebKit` models in `WtfStringAbi.hpp` and `WtfTextAbi.hpp`, all pinned with `static_assert`: - the 40-byte release `URL`: string, bit field with valid bit 0, port length in bits 3-5 and scheme end from bit 6, then seven offsets; - the 40-byte release `StringBuilder`; - `Seconds` and `TimeWithDynamicClockType`. `WtfStringAbi.hpp` is not touched, so this does not collide with the `String` layout that #18430 and #18442 add there. - `Optional<uint16_t>` is returned indirectly, with the flag at byte 0 and the value at byte 2. `WTF::Optional` at this revision has a user-provided copy constructor, so the Itanium ABI returns it through a hidden pointer. The same reasoning backs `ResponseOptionalTime` in `libSceNKWebKit`. - `port` parses the substring after `hostEnd` with `parseUInt16`/`toIntegralType<uint16_t>`. It skips leading and trailing `isSpaceOrNewline` characters: Latin-1 ASCII spaces, and above U+00FF the Unicode bidi class WS set. It accepts an optional `+` and decimal digits only, and gives no value above 65535. `StringView::substring` clamping is kept, including `empty()` (a non-null zero-length view) when the start is past the end. - `query` returns a null view when `queryEnd == pathEnd`. `stringWithoutQueryOrFragmentIdentifier` returns the whole string for an invalid URL, and otherwise the string up to `pathEnd`. - `isLocalFile` and `protocolIsAbout` are `protocolIs(const char*)`: false for an invalid URL, otherwise an ASCII-case-insensitive (`| 0x20`) match of the scheme against `file` or `about`. - `defaultPortForProtocol` is `URLParser::defaultPortForProtocol`. It is case-sensitive: `ws`/`http` give 80, `wss`/`https` give 443, `ftp` gives 21. One quirk of this revision is reproduced: a scheme starting with `w` whose length is not 2 or 3 returns `false` converted to an **engaged port 0**. The testing override map that WebKit checks first stays empty, because this module exports neither `registerDefaultPortForProtocolForTesting` nor `clearDefaultPortForProtocolMapForTesting`. - `TimeWithDynamicClockType::operator<` compares the raw seconds. Different clock types hit a `RELEASE_ASSERT` in WebKit, and here they throw `std::invalid_argument`. `Seconds::operator+` returns `other + *this` with the time's clock. - `StringBuilder::isAllASCII` returns true for length 0. Otherwise it reads the characters of `m_string`, or `m_buffer` when the string is null, in the builder's width, and checks that no unit is above 0x7F. An overflowed builder (`RELEASE_ASSERT` in `length()`), a negative length, a nonzero length with no string or buffer, and null pointers throw. Debt: two entries are added under *Functional*. The six `InventoryExports.hpp` rows leave the NID table. The inventory counts in the prose are left as they are; the generated progress report gives current totals. Left out of this PR: `pageMask()`, `SHA1::hexDigest` and the random/UUID helpers, which need a device page size or `CString` allocation. **Source of the behaviour** (WebKit `c55364d53f97`; no public reimplementation of these exports was found, so this is the only source) - URL: [URL.cpp#L113-L116](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/URL.cpp#L113-L116) `port`, [#L278-L288](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/URL.cpp#L278-L288) `defaultPortForProtocol`, [#L300-L317](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/URL.cpp#L300-L317) `protocolIs(const char*)`, [#L337-L343](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/URL.cpp#L337-L343) `query`, [#L650-L656](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/URL.cpp#L650-L656) `stringWithoutQueryOrFragmentIdentifier`, [#L795-L802](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/URL.cpp#L795-L802) `isLocalFile`, [#L843-L846](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/URL.cpp#L843-L846) `protocolIsAbout`; layout [URL.h#L204-L222](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/URL.h#L204-L222) - Ports: [URLParser.cpp#L571-L624](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/URLParser.cpp#L571-L624) (including `return false` at L595), [StringView.cpp#L316-L323](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringView.cpp#L316-L323), [StringToIntegerConversion.h#L48-L122](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringToIntegerConversion.h#L48-L122), [StringImpl.h#L770-L774](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringImpl.h#L770-L774) (`isSpaceOrNewline`) - Views: [StringView.h#L413-L416](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringView.h#L413-L416) (`empty()`), [#L480-L500](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringView.h#L480-L500) (`substring`); `Optional` copy constructor [Optional.h#L414-L424](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/Optional.h#L414-L424) - Time: [TimeWithDynamicClockType.cpp#L95-L99](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/TimeWithDynamicClockType.cpp#L95-L99), [TimeWithDynamicClockType.h#L82-L85](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/TimeWithDynamicClockType.h#L82-L85), [Seconds.cpp#L49-L52](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/Seconds.cpp#L49-L52) - Builder: [StringBuilder.cpp#L458-L466](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringBuilder.cpp#L458-L466), [StringBuilder.h#L275-L279](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringBuilder.h#L275-L279), [#L305-L325](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringBuilder.h#L305-L325), [#L365-L376](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringBuilder.h#L365-L376), [ASCIIFastPath.h#L79-L107](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/ASCIIFastPath.h#L79-L107) ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux x86-64 (Ubuntu 24.04, GCC 14), on `main` `09ab49de9649`. The new `jsc_wtf_url` test covers: - `port` and `query` on a parsed-style URL. A port of 65535, 65536, `+80`, `-1`, `8a`, ` 8\t`, empty and `00042`; U+3000 around a digit; U+00A0 and a full-width digit. - The null and empty-view cases of `query` and `stringWithoutQueryOrFragmentIdentifier`, and a null URL string. - Case-insensitive `file`/`about`, a longer scheme, an invalid URL and a 16-bit URL. - Every `defaultPortForProtocol` branch, including `w` and `webcal` giving an engaged 0, a 16-bit scheme and a null view with a length. - `operator<` with NaN and with mismatched clocks; `Seconds::operator+` keeping the clock. - `isAllASCII` for an empty builder, string before buffer, 8-bit and 16-bit buffers, an overflowed builder, no storage and a null `this`. Results: - `ctest -R '^jsc_wtf_(url|string_search)$'` passed in 2 of 2 runs. - Negative control: with the nine bodies replaced by `NotImplemented_nid_no_patch`, `jsc_wtf_url` aborts. - `tools/progress.py --compare`: +9 implemented (libSceJsc 55/737 -> 64/737). - `tools/check_conventions.py --base origin/main` passes. Not tested on a device 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) - [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 (#18430, #18442 and #18951 touch `libSceJsc` `Export.cpp`, `CMakeLists.txt` and the debt file but implement none of these nine) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-13 00:31:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T00:31:38Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: jsc_wtf_url_tests built cleanly.
  • CTest (jsc_wtf_url):
    1/1 Test #3327: jsc_wtf_url ......................   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceJsc/Export.cpp, core/libs/prx/libSceJsc/include/Api.hpp, core/libs/prx/libSceJsc/include/InventoryExports.hpp, core/libs/prx/libSceJsc/libSceJsc.hpp 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/libSceJsc/src/WtfUrl.cpp: Verified URL::port, URL::query, and URL::stringWithoutQueryOrFragmentIdentifier bounds checks, null URL string handling, and Substring clamping against slice underflow/overflow.
    • core/libs/prx/libSceJsc/src/WtfUrl.cpp: Verified ParseUInt16 integer parsing against WebKit StringToIntegerConversion.h, confirming whitespace handling, optional leading '+', and strict uint16 overflow boundary validation at 65535.
    • core/libs/prx/libSceJsc/src/WtfUrl.cpp: Verified ProtocolIs caseless ASCII comparison for URL::isLocalFile and URL::protocolIsAbout, ensuring early return on null terminator to prevent out-of-bounds reads when schemeEnd exceeds protocol literal length.
    • core/libs/prx/libSceJsc/src/WtfUrl.cpp: Verified defaultPortForProtocol case-sensitivity, bounds validation on StringView, and adherence to WebKit's pinned default port behavior.
    • core/libs/prx/libSceJsc/src/WtfUrl.cpp: Verified TimeWithDynamicClockType::operator< and Seconds::operator+ null guards, ClockType mismatch validation throwing std::invalid_argument, and IEEE 754 NaN comparison behavior.
    • core/libs/prx/libSceJsc/src/WtfUrl.cpp: Verified StringBuilder::isAllASCII null checks, overflow/negative length guards, string vs buffer fallback precedence, and bitwise ASCII validation across 8-bit and 16-bit character buffers.
    • core/libs/prx/libSceJsc/src/WtfUrlAbi.hpp: Verified struct layouts, member offsets, and size static_asserts for URL (40 bytes), StringBuilder (40 bytes), TimeWithDynamicClockType (16 bytes), and OptionalUInt16 (4 bytes with non-trivial copy constructor for sret return ABI).
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5884261363 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19104#pullrequestreview-5884261363). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-13T00:31:38Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `c754d9b33d`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `jsc_wtf_url_tests` built cleanly. - **CTest** (`jsc_wtf_url`): ``` 1/1 Test #3327: jsc_wtf_url ...................... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceJsc/Export.cpp`, `core/libs/prx/libSceJsc/include/Api.hpp`, `core/libs/prx/libSceJsc/include/InventoryExports.hpp`, `core/libs/prx/libSceJsc/libSceJsc.hpp` 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/libSceJsc/src/WtfUrl.cpp: Verified URL::port, URL::query, and URL::stringWithoutQueryOrFragmentIdentifier bounds checks, null URL string handling, and Substring clamping against slice underflow/overflow. - core/libs/prx/libSceJsc/src/WtfUrl.cpp: Verified ParseUInt16 integer parsing against WebKit StringToIntegerConversion.h, confirming whitespace handling, optional leading '+', and strict uint16 overflow boundary validation at 65535. - core/libs/prx/libSceJsc/src/WtfUrl.cpp: Verified ProtocolIs caseless ASCII comparison for URL::isLocalFile and URL::protocolIsAbout, ensuring early return on null terminator to prevent out-of-bounds reads when schemeEnd exceeds protocol literal length. - core/libs/prx/libSceJsc/src/WtfUrl.cpp: Verified defaultPortForProtocol case-sensitivity, bounds validation on StringView, and adherence to WebKit's pinned default port behavior. - core/libs/prx/libSceJsc/src/WtfUrl.cpp: Verified TimeWithDynamicClockType::operator< and Seconds::operator+ null guards, ClockType mismatch validation throwing std::invalid_argument, and IEEE 754 NaN comparison behavior. - core/libs/prx/libSceJsc/src/WtfUrl.cpp: Verified StringBuilder::isAllASCII null checks, overflow/negative length guards, string vs buffer fallback precedence, and bitwise ASCII validation across 8-bit and 16-bit character buffers. - core/libs/prx/libSceJsc/src/WtfUrlAbi.hpp: Verified struct layouts, member offsets, and size static_asserts for URL (40 bytes), StringBuilder (40 bytes), TimeWithDynamicClockType (16 bytes), and OptionalUInt16 (4 bytes with non-trivial copy constructor for sret return ABI). - Note: the AI-assisted checkbox can stay. 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!19104
No description provided.