feat(libSceNKWebKit): parse legacy dates as WTF DateMath does #13565

Merged
KernelPanicNT merged 2 commits from upstream-pr/13565 into main 2026-10-31 02:47:57 +00:00
KernelPanicNT commented 2026-10-30 18:28:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KernelPanicNT on 2026-10-30T18:28:48Z.


What

Implements the legacy libSceNKWebKit WTF date parser from public WebKit source:

  • WTF::parseDateFromNullTerminatedCharacters(char const*, bool&)

What changes in the tree:

  • It lives in a new core/libs/prx/libSceNKWebKit/DateParsing.cpp.
  • Its parameterless stub comes out of Export.cpp. Its declaration in InventoryExports.hpp now carries the real signature: double (const char*, bool*), because a bool& is passed as a pointer. Its row comes out of the debt table.
  • The library gets a CMakeLists.txt that builds Export.cpp and DateParsing.cpp and the guest_nkwebkit_dates test.
  • The exported name does not change, so the NID still resolves.

Behaviour follows WebKit's DateMath.cpp statement by statement:

  • The weekday is ignored, and month names are matched on three letters.
  • Parenthesised comments are skipped, at any nesting depth.
  • Three date layouts are accepted: MM/DD/YYYY, YYYY/MM/DD, and day-month-year with - or space separators.
  • The year can come before the time, after it, or after the time zone.
  • am/pm are applied, GMT/UTC are recognised, and +hhmm, +hh and GMT+hh:mm offsets are read, along with the ten RFC 2822 zone names. With no zone the result is local time.
  • Two-digit years map below 50 to 20xx and from 50 up to 19xx. A date with no year gets the year 2000.
  • The ±100,000,000-day clamp is applied before the zone offset, as in WebKit.
  • Integers are parsed through this libc's guest strtol, because WebKit calls the platform C library.
  • Where WebKit faults, the export throws std::invalid_argument, as libc models a fault for feholdexcept. That covers a null string and a null bool&.
  • Where WebKit's source overflows a signed integer, which is undefined behaviour, the export throws std::overflow_error, as the LibreSSL ASN1 functions already throw where LibreSSL is undefined. This happens in three places:
    • the YYYY/MM/DD day count when the day is near LONG_MAX
    • the GMT+hh:mm minute total when the minutes are near INT_MAX
    • comment nesting past INT_MAX
  • Still throwing, recorded under ### Functional in docs/dev/debt/libSceNKWebKit.md, together with the overflow and null-pointer throws:
    • parseDateFromNullTerminatedCharacters(char const*). It subtracts calculateLocalTimeOffset, which depends on two things WebKit's source does not fix:
      • which code path is compiled. HAVE_LOCALTIME_R, HAVE_TIMEGM and HAVE_TM_GMTOFF are decided by configure checks against the port's sysroot.
      • the device time zone.

Relation to other open PRs:

  • WTF::parseES5DateFromNullTerminatedCharacters(char const*, bool&) is left to #13500, which implements it. This PR keeps its stub, declaration and debt row exactly as on main, and implements no export that #13500 implements.
  • This PR and #13500 both add core/libs/prx/libSceNKWebKit/CMakeLists.txt. Whichever merges later rebases and keeps both sets of sources and tests in that file.
  • #13500 and #13515 also add sections to docs/dev/debt/libSceNKWebKit.md. Whichever merges later rebases and keeps every entry under its ### section.

Source of the behaviour

Pinned WebKit commit: c55364d53f97. The export inventory matches this era:

  • It still has WTF::DumbPtrTraits (DumbPtrTraits.h), WTF::Optional (Optional.h) and WTF::JSONImpl (JSONValues.h).
  • Its date parsers have exactly the three exported overloads, with double returns: DateMath.h L92-L94.
  • The inventory has Inspector::NetworkBackendDispatcher::interceptRequestWithResponse, added in 514c944fc201, and still has WTF::DumbPtrTraits, renamed in 5c5f0584738c. DateMath.cpp has no change between 49e9ee2745cd, before that window, and ca19599f2160, after it, which moved the parsers to millisecond arithmetic. So the parser in the inventory is the one at the pin.

Behaviour:

Port configuration:

AnyPS5 lines replaced (at 6a3afa4deb18, unchanged on the current main):

Guest libc reused:

Tested

On Linux x86_64 (Release, GCC, BUILD_TESTING=ON), the new guest_nkwebkit_dates test passes. It checks the result bits and the isLocalTime flag for:

  • RFC 2822, MM/DD/YYYY, YYYY/MM/DD and JavaScript-style strings
  • comments, two-digit years, am/pm, zone names and numeric offsets
  • the time range clamp, and an offset applied after the clamp
  • invalid strings, the overflow throws and the null-pointer throws

Negative control: Export.cpp and InventoryExports.hpp were restored from main and DateParsing.cpp was emptied, leaving only the old stub. The test then fails.

The parser was also compared locally against WebKit's own DateMath.cpp parsing code from the pinned commit, built with a minimal WTF shim, on 12 million random date-like strings. Results and isLocalTime matched bit for bit, with about 76,000 of the strings parsing to a valid date.

python3 tools/check_conventions.py --base origin/main passes. tools/progress.py reports +1 implemented function. tools/pr_overlap.py finds no shared exports with open pull requests; the shared files are listed under What.

The "8703 declarations" count in the existing Additional callable exports entry is left as is, to avoid conflicts with sibling branches that remove other rows of the same table.

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:5089211328 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13565). Originally posted by [KernelPanicNT](https://github.com/KernelPanicNT) on 2026-10-30T18:28:48Z. --- ### What Implements the legacy `libSceNKWebKit` WTF date parser from public WebKit source: - `WTF::parseDateFromNullTerminatedCharacters(char const*, bool&)` What changes in the tree: - It lives in a new `core/libs/prx/libSceNKWebKit/DateParsing.cpp`. - Its parameterless stub comes out of `Export.cpp`. Its declaration in `InventoryExports.hpp` now carries the real signature: `double (const char*, bool*)`, because a `bool&` is passed as a pointer. Its row comes out of the debt table. - The library gets a `CMakeLists.txt` that builds `Export.cpp` and `DateParsing.cpp` and the `guest_nkwebkit_dates` test. - The exported name does not change, so the NID still resolves. Behaviour follows WebKit's `DateMath.cpp` statement by statement: - The weekday is ignored, and month names are matched on three letters. - Parenthesised comments are skipped, at any nesting depth. - Three date layouts are accepted: `MM/DD/YYYY`, `YYYY/MM/DD`, and day-month-year with `-` or space separators. - The year can come before the time, after it, or after the time zone. - `am`/`pm` are applied, `GMT`/`UTC` are recognised, and `+hhmm`, `+hh` and `GMT+hh:mm` offsets are read, along with the ten RFC 2822 zone names. With no zone the result is local time. - Two-digit years map below 50 to 20xx and from 50 up to 19xx. A date with no year gets the year 2000. - The ±100,000,000-day clamp is applied before the zone offset, as in WebKit. - Integers are parsed through this libc's guest `strtol`, because WebKit calls the platform C library. - Where WebKit faults, the export throws `std::invalid_argument`, as libc models a fault for `feholdexcept`. That covers a null string and a null `bool&`. - Where WebKit's source overflows a signed integer, which is undefined behaviour, the export throws `std::overflow_error`, as the LibreSSL ASN1 functions already throw where LibreSSL is undefined. This happens in three places: - the `YYYY/MM/DD` day count when the day is near `LONG_MAX` - the `GMT+hh:mm` minute total when the minutes are near `INT_MAX` - comment nesting past `INT_MAX` - Still throwing, recorded under `### Functional` in `docs/dev/debt/libSceNKWebKit.md`, together with the overflow and null-pointer throws: - `parseDateFromNullTerminatedCharacters(char const*)`. It subtracts `calculateLocalTimeOffset`, which depends on two things WebKit's source does not fix: - which code path is compiled. `HAVE_LOCALTIME_R`, `HAVE_TIMEGM` and `HAVE_TM_GMTOFF` are decided by configure checks against the port's sysroot. - the device time zone. Relation to other open PRs: - `WTF::parseES5DateFromNullTerminatedCharacters(char const*, bool&)` is left to #13500, which implements it. This PR keeps its stub, declaration and debt row exactly as on `main`, and implements no export that #13500 implements. - This PR and #13500 both add `core/libs/prx/libSceNKWebKit/CMakeLists.txt`. Whichever merges later rebases and keeps both sets of sources and tests in that file. - #13500 and #13515 also add sections to `docs/dev/debt/libSceNKWebKit.md`. Whichever merges later rebases and keeps every entry under its `###` section. ### Source of the behaviour Pinned WebKit commit: [`c55364d53f97`](https://github.com/WebKit/WebKit/tree/c55364d53f97). The export inventory matches this era: - It still has `WTF::DumbPtrTraits` ([DumbPtrTraits.h](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DumbPtrTraits.h)), `WTF::Optional` ([Optional.h](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/Optional.h)) and `WTF::JSONImpl` ([JSONValues.h](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/JSONValues.h#L45)). - Its date parsers have exactly the three exported overloads, with `double` returns: [DateMath.h L92-L94](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.h#L92-L94). - The inventory has `Inspector::NetworkBackendDispatcher::interceptRequestWithResponse`, added in [514c944fc201](https://github.com/WebKit/WebKit/commit/514c944fc201), and still has `WTF::DumbPtrTraits`, renamed in [5c5f0584738c](https://github.com/WebKit/WebKit/commit/5c5f0584738c). `DateMath.cpp` has no change between [49e9ee2745cd](https://github.com/WebKit/WebKit/commit/49e9ee2745cd), before that window, and [ca19599f2160](https://github.com/WebKit/WebKit/commit/ca19599f2160), after it, which moved the parsers to millisecond arithmetic. So the parser in the inventory is the one at the pin. Behaviour: - DateMath.cpp: - [ymdhmsToSeconds and the time range clamp](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.cpp#L374-L387) - [known zones](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.cpp#L389-L408) - [skipSpacesAndComments and findMonth](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.cpp#L410-L446) - [parseInt and parseLong over strtol](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.cpp#L448-L465) - [parseDateFromNullTerminatedCharacters(const char*, bool&)](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.cpp#L684-L988) - [the one-argument overload](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.cpp#L990-L999), which calls [calculateLocalTimeOffset](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.cpp#L318-L361) - [startsWithLettersIgnoringASCIICase](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.cpp#L89-L93) and [firstDayOfMonth](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.cpp#L101-L106) - DateMath.h: - [the time constants](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.h#L109-L118) - [daysFrom1970ToYear](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.h#L159-L176) - [isLeapYear](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/DateMath.h#L193-L202) - ASCIICType.h: - [toASCIILowerUnchecked](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/ASCIICType.h#L85-L93) - [isASCIIDigit](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/ASCIICType.h#L100-L103) - [isASCIISpace, isASCIIUpper and toASCIILower](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/ASCIICType.h#L146-L159) - [isASCIIAlphaCaselessEqual](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/ASCIICType.h#L211-L226) - [equalLettersIgnoringASCIICase(const CharacterType*, const char*, unsigned)](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringCommon.h#L597-L604) in StringCommon.h Port configuration: - [OptionsPlayStation.cmake](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/cmake/OptionsPlayStation.cmake#L110) links the platform C library, which supplies `strtol`. - [OptionsCommon.cmake](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/cmake/OptionsCommon.cmake#L131-L148) decides `HAVE_LOCALTIME_R`, `HAVE_TIMEGM` and `HAVE_TM_GMTOFF` by probing the sysroot. [PlatformHave.h](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/PlatformHave.h#L105-L147) sets them only for Darwin. That is why the one-argument overload stays open. AnyPS5 lines replaced (at `6a3afa4deb18`, unchanged on the current `main`): - [`Export.cpp` stub](https://github.com/boykopovar/AnyPS5/blob/6a3afa4deb18/core/libs/prx/libSceNKWebKit/Export.cpp#L11751-L11753) - [`InventoryExports.hpp` declaration](https://github.com/boykopovar/AnyPS5/blob/6a3afa4deb18/core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp#L2791) - [Debt table row](https://github.com/boykopovar/AnyPS5/blob/6a3afa4deb18/docs/dev/debt/libSceNKWebKit.md#L2799) Guest libc reused: - [strtol](https://github.com/boykopovar/AnyPS5/blob/6a3afa4deb18/core/libs/prx/libc/src/Strings.cpp#L470-L473) ### 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. --> On Linux x86_64 (Release, GCC, `BUILD_TESTING=ON`), the new `guest_nkwebkit_dates` test passes. It checks the result bits and the `isLocalTime` flag for: - RFC 2822, `MM/DD/YYYY`, `YYYY/MM/DD` and JavaScript-style strings - comments, two-digit years, `am`/`pm`, zone names and numeric offsets - the time range clamp, and an offset applied after the clamp - invalid strings, the overflow throws and the null-pointer throws Negative control: `Export.cpp` and `InventoryExports.hpp` were restored from `main` and `DateParsing.cpp` was emptied, leaving only the old stub. The test then fails. The parser was also compared locally against WebKit's own `DateMath.cpp` parsing code from the pinned commit, built with a minimal WTF shim, on 12 million random date-like strings. Results and `isLocalTime` matched bit for bit, with about 76,000 of the strings parsing to a valid date. `python3 tools/check_conventions.py --base origin/main` passes. `tools/progress.py` reports +1 implemented function. `tools/pr_overlap.py` finds no shared exports with open pull requests; the shared files are listed under What. The "8703 declarations" count in the existing `Additional callable exports` entry is left as is, to avoid conflicts with sibling branches that remove other rows of the same table. ### 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
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!13565
No description provided.