feat(libSceNKWebKit): implement six WebCore::StorageMap exports on a guest HashMap<String, String> #24883

Merged
ToRaNek merged 2 commits from upstream-pr/24883 into main 2026-11-22 12:36:53 +00:00
ToRaNek commented 2026-11-21 09:03:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ToRaNek on 2026-11-21T09:03:12Z.


What

Implements six WebCore::StorageMap exports that were stubs: key, getItem, setItem, setItemIgnoringQuota, removeItem and contains.

Which class. The six names are the same in the 3.20-era source and in the pinned 11.x one (return types are not mangled), but the classes differ: the old one is reference counted and returns a RefPtr from setItem; the pinned one is { Ref<Impl> m_impl; unsigned m_quotaSize; } with void returns (StorageMap.h L36-L80). These six are in the 11.x inventory, so they follow the pinned class. One independent check: #23757 translates StorageMap::length from the module, and it reads *this, then +8, then the key count before the table, which is m_impl->map.size() of this layout.

The functions follow StorageMap.cpp L74-L163 line by line:

  • sizes are String::sizeInBytes() (one byte per 8-bit character, two per 16-bit one), added in a checked 32-bit sum and refused when the sum is above the quota, not when it is equal;
  • setItem and removeItem copy the Impl first when it is shared, and report the old value;
  • every change resets the stored iterator, and key(index) walks it forward from the start or from where it is;
  • setItemIgnoringQuota lifts the quota for the call and puts it back.

The table. The map is the guest's WTF::HashMap<String, String>, which guest code also reads inline, so the table has to be the real one. It is in its own file (WtfHashMapString.cpp) so that other users of this map type can share it, and it follows the pinned HashTable.h:

Rule Lines
one pointer; size, mask, key count and deleted count in the four unsigned before the buckets L584-L607
triangular probing, i = (i + ++probeCount) & mask; an empty bucket ends the search L692-L722
empty key is null, deleted key is -1; on insert the last deleted bucket of the probe sequence is reused HashTraits.h, add loop
grow at 3/4 full up to 1024 buckets, then at 1/2; rehash in place when keyCount * 6 < size * 2 L318-L336, L546-L547
shrink by half when keyCount * 6 < size and size > 8 L548
a copy is sized by computeBestTableSize and refilled in bucket order L1196-L1228

Hashes come from the existing StringImpl::hashSlowCase export, which also fills the cache in the string; the table is allocated with fastZeroedMalloc.

Where the source crashes, this throws instead: a null key on a non-empty table, a size that overflows 32 bits with no quota, an underflow in removeItem.

Left as stubs: create, copy and importItems. They are 3.20 exports of the older class (and importItems of the pinned class has another mangled name, since HashMap gained a template parameter). Implementing them would create objects of the other layout. No export of the inventory constructs the 11.x object, so the test builds it by hand.

Tested

Windows 11, MinGW GCC 15.2.

  • The test is new (nkwebkit_storagemap); on main the six functions are untyped stubs that throw.
  • It passes on the branch. After every change a checker reads the raw table: it redoes the probing on its own, and checks the counters, the load and the reference counts. The test covers the best-size table; Add not overwriting and Set overwriting; the empty map; set, get and remove with 8-bit and 16-bit keys that compare equal; the exact sequence of table sizes while growing and shrinking; the reuse of deleted buckets with four keys of the same home bucket; the quota to the byte, a quota of 0, setItemIgnoringQuota; overflow and underflow; copy on write, including no copy when the quota refuses or the key is absent; the old value released from the output parameter; and 900 pseudo-random operations against a std::map model.
  • Fifteen negative controls, each rebuilt and run, each makes the test fail: linear probing in the search; two bytes for every character; a quota that refuses the exact size; no copy on write in setItem; the iterator kept after removeItem; the quota not put back; Set not releasing the old value; another shrink threshold; another growth threshold; the value kept in a deleted bucket; no eager growth in the best size; removeItem writing into a shared map; and, for deleted buckets, not reused, first one kept instead of the last, counter not decremented. The first version of the test missed the deleted-bucket reuse; I added that case and it now fails for the three variants.
  • I also rebuilt and ran the whole library: all 177 nkwebkit_* tests and patched_libraries pass on the branch.
  • python tools/check_conventions.py --base origin/main and python tools/debt_fold.py --check pass.

Not tested on a console; the layouts are read from the source.

Overlap (python tools/pr_overlap.py --branch feat/nkwebkit-storage-map):

  • No open PR implements these six functions. #24322, a refactor that splits the large libraries into smaller ones, moves the stubs without changing them.
  • #23757 implements StorageMap::length, the stub next to getItem in Export.cpp and InventoryExports.hpp: whichever merges second resolves an adjacent-line conflict by keeping both removals. Its length reads the layout used here.
  • The tool could not compare 34 PRs that conflict with main and share Export.cpp, InventoryExports.hpp or libSceNKWebKit.hpp, the files every implementation edits. I searched each of their diffs: none changes any of the six symbols.

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:5426241862 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24883). Originally posted by [ToRaNek](https://github.com/ToRaNek) on 2026-11-21T09:03:12Z. --- ### What Implements six `WebCore::StorageMap` exports that were stubs: `key`, `getItem`, `setItem`, `setItemIgnoringQuota`, `removeItem` and `contains`. **Which class.** The six names are the same in the 3.20-era source and in the pinned 11.x one (return types are not mangled), but the classes differ: the old one is reference counted and returns a `RefPtr` from `setItem`; the pinned one is `{ Ref<Impl> m_impl; unsigned m_quotaSize; }` with `void` returns ([StorageMap.h L36-L80](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/storage/StorageMap.h#L36-L80)). These six are in the 11.x inventory, so they follow the pinned class. One independent check: #23757 translates `StorageMap::length` from the module, and it reads `*this`, then `+8`, then the key count before the table, which is `m_impl->map.size()` of this layout. **The functions** follow [StorageMap.cpp L74-L163](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/storage/StorageMap.cpp#L74-L163) line by line: - sizes are `String::sizeInBytes()` (one byte per 8-bit character, two per 16-bit one), added in a checked 32-bit sum and refused when the sum is above the quota, not when it is equal; - `setItem` and `removeItem` copy the `Impl` first when it is shared, and report the old value; - every change resets the stored iterator, and `key(index)` walks it forward from the start or from where it is; - `setItemIgnoringQuota` lifts the quota for the call and puts it back. **The table.** The map is the guest's `WTF::HashMap<String, String>`, which guest code also reads inline, so the table has to be the real one. It is in its own file (`WtfHashMapString.cpp`) so that other users of this map type can share it, and it follows the pinned [HashTable.h](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/HashTable.h): | Rule | Lines | |---|---| | one pointer; size, mask, key count and deleted count in the four `unsigned` before the buckets | L584-L607 | | triangular probing, `i = (i + ++probeCount) & mask`; an empty bucket ends the search | L692-L722 | | empty key is null, deleted key is `-1`; on insert the last deleted bucket of the probe sequence is reused | `HashTraits.h`, add loop | | grow at 3/4 full up to 1024 buckets, then at 1/2; rehash in place when `keyCount * 6 < size * 2` | L318-L336, L546-L547 | | shrink by half when `keyCount * 6 < size` and `size > 8` | L548 | | a copy is sized by `computeBestTableSize` and refilled in bucket order | L1196-L1228 | Hashes come from the existing `StringImpl::hashSlowCase` export, which also fills the cache in the string; the table is allocated with `fastZeroedMalloc`. Where the source crashes, this throws instead: a null key on a non-empty table, a size that overflows 32 bits with no quota, an underflow in `removeItem`. **Left as stubs:** `create`, `copy` and `importItems`. They are 3.20 exports of the older class (and `importItems` of the pinned class has another mangled name, since `HashMap` gained a template parameter). Implementing them would create objects of the other layout. No export of the inventory constructs the 11.x object, so the test builds it by hand. ### Tested Windows 11, MinGW GCC 15.2. - The test is new (`nkwebkit_storagemap`); on `main` the six functions are untyped stubs that throw. - It passes on the branch. After every change a checker reads the raw table: it redoes the probing on its own, and checks the counters, the load and the reference counts. The test covers the best-size table; `Add` not overwriting and `Set` overwriting; the empty map; set, get and remove with 8-bit and 16-bit keys that compare equal; the exact sequence of table sizes while growing and shrinking; the reuse of deleted buckets with four keys of the same home bucket; the quota to the byte, a quota of 0, `setItemIgnoringQuota`; overflow and underflow; copy on write, including no copy when the quota refuses or the key is absent; the old value released from the output parameter; and 900 pseudo-random operations against a `std::map` model. - Fifteen negative controls, each rebuilt and run, each makes the test fail: linear probing in the search; two bytes for every character; a quota that refuses the exact size; no copy on write in `setItem`; the iterator kept after `removeItem`; the quota not put back; `Set` not releasing the old value; another shrink threshold; another growth threshold; the value kept in a deleted bucket; no eager growth in the best size; `removeItem` writing into a shared map; and, for deleted buckets, not reused, first one kept instead of the last, counter not decremented. The first version of the test missed the deleted-bucket reuse; I added that case and it now fails for the three variants. - I also rebuilt and ran the whole library: all 177 `nkwebkit_*` tests and `patched_libraries` pass on the branch. - `python tools/check_conventions.py --base origin/main` and `python tools/debt_fold.py --check` pass. Not tested on a console; the layouts are read from the source. **Overlap** (`python tools/pr_overlap.py --branch feat/nkwebkit-storage-map`): - No open PR implements these six functions. #24322, a refactor that splits the large libraries into smaller ones, moves the stubs without changing them. - #23757 implements `StorageMap::length`, the stub next to `getItem` in `Export.cpp` and `InventoryExports.hpp`: whichever merges second resolves an adjacent-line conflict by keeping both removals. Its `length` reads the layout used here. - The tool could not compare 34 PRs that conflict with `main` and share `Export.cpp`, `InventoryExports.hpp` or `libSceNKWebKit.hpp`, the files every implementation edits. I searched each of their diffs: none changes any of the six symbols. ### 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
PrivacyOnion commented 2026-11-21 09:05:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T09:05:14Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_storagemap_tests built cleanly.
  • CTest (nkwebkit_storagemap):
    1/1 Test #4851: nkwebkit_storagemap ..............   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/StorageMap.cpp, core/libs/prx/libSceNKWebKit/src/WtfHashMapString.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • StorageMapExports.hpp and StorageMap.cpp: Verified all six WebCore::StorageMap exports match the WebKit 11.x layout and function signatures, including null pointer checks for self, key, value, and out-params.
    • StorageMap.cpp: Checked quota arithmetic (CheckedSize) and size calculation (SizeInBytes) handling 8-bit vs 16-bit characters, overflow checks against quotaSize, and iterator invalidation on setItem and removeItem.
    • WtfHashMapString.cpp: Audited open-addressing quadratic probe lookup, Robin-Hood/deleted marker handling (DeletedKey), string refcounting (+2U / Release), table reallocation (bestTableSize), and copy-on-write semantics in ReplaceWithCopy.
    • InventoryExports.hpp and Export.cpp: Verified removal of stub declarations/exports and alignment with AGENTS.md, including technical debt tracking fragment in docs/dev/debt/changes/feat-nkwebkit-storage-map.md.
    • Tests in tests/StorageMap.cpp: Verified comprehensive coverage across copy-on-write, quota limits, integer overflow, alias reuse, key enumeration ordering, and randomized operations.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6004299946 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24883#pullrequestreview-6004299946). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T09:05:14Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `c07fb2350e`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_storagemap_tests` built cleanly. - **CTest** (`nkwebkit_storagemap`): ``` 1/1 Test #4851: nkwebkit_storagemap .............. 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/StorageMap.cpp`, `core/libs/prx/libSceNKWebKit/src/WtfHashMapString.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - StorageMapExports.hpp and StorageMap.cpp: Verified all six WebCore::StorageMap exports match the WebKit 11.x layout and function signatures, including null pointer checks for self, key, value, and out-params. - StorageMap.cpp: Checked quota arithmetic (CheckedSize) and size calculation (SizeInBytes) handling 8-bit vs 16-bit characters, overflow checks against quotaSize, and iterator invalidation on setItem and removeItem. - WtfHashMapString.cpp: Audited open-addressing quadratic probe lookup, Robin-Hood/deleted marker handling (DeletedKey), string refcounting (+2U / Release), table reallocation (bestTableSize), and copy-on-write semantics in ReplaceWithCopy. - InventoryExports.hpp and Export.cpp: Verified removal of stub declarations/exports and alignment with AGENTS.md, including technical debt tracking fragment in docs/dev/debt/changes/feat-nkwebkit-storage-map.md. - Tests in tests/StorageMap.cpp: Verified comprehensive coverage across copy-on-write, quota limits, integer overflow, alias reuse, key enumeration ordering, and randomized operations. Looks Good To Me
MarcZX10 commented 2026-11-21 09:25:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T09:25:29Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and its focused tests are consistent with the stated goal.

What I ran

Reviewed head c07fb2350e2d87e208e3dce00c9df5739ded84ac. I did not run commands or tests; the test and build results in the description are author-reported.

Results

Check Result Note
Diff and changed code passed Reviewed all changed files
Tests and build not run Results are author-reported
Console behavior not run No physical-console verification

Findings

Blocking

None.

Non-blocking

None.

Not verified

No test or build was run in this review. I read all files listed as reviewed in manifest.json: Export.cpp, InventoryExports.hpp, StorageMapExports.hpp, libSceNKWebKit.hpp, StorageMap.cpp, StorageMapAbi.hpp, WtfHashMapString.cpp, WtfHashMapStringAbi.hpp, tests/StorageMap.cpp, and docs/dev/debt/changes/feat-nkwebkit-storage-map.md. The excluded-files list has no entries; Export.cpp and InventoryExports.hpp were read through repo_read.py because their full text was not included in the review folder. No other changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6004372491 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24883#pullrequestreview-6004372491). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T09:25:29Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and its focused tests are consistent with the stated goal. ## What I ran Reviewed head `c07fb2350e2d87e208e3dce00c9df5739ded84ac`. I did not run commands or tests; the test and build results in the description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Reviewed all changed files | | Tests and build | not run | Results are author-reported | | Console behavior | not run | No physical-console verification | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No test or build was run in this review. I read all files listed as reviewed in `manifest.json`: `Export.cpp`, `InventoryExports.hpp`, `StorageMapExports.hpp`, `libSceNKWebKit.hpp`, `StorageMap.cpp`, `StorageMapAbi.hpp`, `WtfHashMapString.cpp`, `WtfHashMapStringAbi.hpp`, `tests/StorageMap.cpp`, and `docs/dev/debt/changes/feat-nkwebkit-storage-map.md`. The excluded-files list has no entries; `Export.cpp` and `InventoryExports.hpp` were read through `repo_read.py` because their full text was not included in the review folder. No other changed files were excluded. ## To get this to a good state Nothing is required.
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!24883
No description provided.