Skip to content

feat(libSceNKWebKit): implement the Inspector backend dispatcher core - #22666

Open
RiverWhy wants to merge 11 commits into
boykopovar:mainfrom
RiverWhy:feat/nkwebkit-inspector-backend-dispatcher
Open

RiverWhy wants to merge 11 commits into
boykopovar:mainfrom
RiverWhy:feat/nkwebkit-inspector-backend-dispatcher

Conversation

@RiverWhy

@RiverWhy RiverWhy commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements the Inspector backend dispatcher core in libSceNKWebKit. These are 19 exports that all throw on main today, plus the JSON support they need.

  • BackendDispatcher (7): dispatch, reportProtocolError, sendPendingErrors, registerDispatcherForDomain, isActive, hasProtocolErrors and D2.
  • BackendDispatcher::CallbackBase (5): sendFailure, disable, isActive, D1 and D2.
  • SupplementalBackendDispatcher (4): C2, D0, D1 and D2.
  • JSON (3): Value::writeJSON, ArrayBase::writeJSON and Value::toJSONString.
  • The 45 ForwardExports.cpp destructors of BackendDispatcher and of the 22 domain dispatchers jump to these, so they now run real code. Their RequireStub lines in tests/Forwarding.cpp are dropped.

Depends on #17864 (@alvaroelpob): this branch contains its head. It uses that PR's Value and ArrayBase writeJSON slots and its NumberToString(double), which already follow the same 2020 revision. This PR only routes the two writeJSON exports to those slots and adds the object slot, toJSONString and parsing. @alvaroelpob, if you'd rather the two exports live in #17864, say so and I'll drop them here.

Source: InspectorBackendDispatcher.cpp and JSONValues.cpp at c55364d53f97 (September 2020). The module's JSON exports use that revision's out-parameter API (asInteger(int&)), and libSceJsc's agents use its ErrorString& handlers, so the dispatcher is that revision's, not the pinned 11.x one.

  • dispatch:
    • It parses the message with that revision's JSON parser, ported in WtfJsonParse.cpp. The parser works on UTF-16 code units, limits nesting to depth 1000, and accepts \\x and \\v escapes.
    • Whitespace is isSpaceOrNewline: ASCII spaces, plus the non-Latin-1 Unicode WS characters (U+1680, U+2000 to U+200A, U+2028, U+205F, U+3000).
    • It then checks id and method with the same JSON-RPC errors and messages, splits Domain.method on exactly one dot, and calls the registered dispatcher's dispatch vtable slot.
    • Both SetForScope request-id scopes are kept, so nested and re-entrant dispatches restore the outer id.
    • The request id is an int cut from the JSON double, as in the pinned 11.x dispatcher. That is the only behavioural difference between its dispatch and the 2020 one. Ids outside int become -2147483648, which is x86 cvttsd2si.
  • sendPendingErrors builds the JSON-RPC 2.0 error object: the last error's code and message, all errors under data, and "id":null when no request id is set. It sends it through the existing FrontendRouter::sendResponse, then clears the errors and the id.
  • JSON objects: SetValue follows WTF HashMap::set and keeps the insertion order, on the table layout WtfJsonObject.cpp already uses. ObjectBase's writeJSON slot writes members in that order.

Layouts:

  • BackendDispatcher (56 bytes): reference count, router at 8, domain map at 16, the error Vector<std::tuple<CommonErrorCode, String>> at 24 (libc++ tuple order, 16-byte elements), and the optional current id (value at 40, flag at 48, as a decrypted PS4 libSceNKWebKit of the same generation reads it).
  • SupplementalBackendDispatcher (24 bytes): vtable [D1, D0, dispatch], count at 8, dispatcher at 16.
  • CallbackBase: 32 bytes.
  • BackendDispatcher::create is not exported, so a library-internal CreateBackendDispatcher builds one. It allocates with the guest operator new, and the last deref frees it with operator delete.

An unknown error code, a null domain or a null argument throws.

Debt: a fragment, docs/dev/debt/changes/feat-nkwebkit-inspector-backend-dispatcher.md, adds the entry and removes the 19 inventory rows.

Overlap: apart from #17864, which this depends on, pr_overlap.py finds no open PR with these exports. It could not compare the NKWebKit PRs that conflict with main (#13515, #14138, #14164, #14259, #14860, #16510, #17550, #17569, #17695, #17771, #17793, #17805, #17922, #17927, #17933, #18395, #18797, #20319, #20327, #20771, #21957, #22557). Their changes are in Export.cpp, the export headers and the shared include line, and none of them touch the dispatcher or JSON serialization.

Tested

Linux Mint 22.3.

  • Oracle: the September 2020 JSONValues.cpp and InspectorBackendDispatcher.cpp, compiled against WTF with the 2020 JSON namespace renamed, with a capturing FrontendRouter. Its request id is read as int, which is the one line where the 11.x dispatch differs.
  • Shared driver: feeds random messages to both sides and hashes every frontend message and every call to the registered dispatchers.
    • Messages: valid and broken JSON; ids that are missing, strings, negative, fractional, larger than int, 1e400 or 1e-400; every method shape; duplicate keys; escapes, surrogates and raw non-ASCII; Unicode whitespace; nesting at 997 to 1002 levels; 8-bit and 16-bit strings.
    • Behavior: frontends connecting and disconnecting.
    • Scripted domain dispatchers report each error code, send pending errors, fail callbacks twice and re-enter dispatch.
  • New nkwebkit_inspectorbackenddispatcher test: 16 sequences of 400 messages match. As a one-off, 200 sequences of 3,000 also matched.
  • Hand checks:
    • writer escapes and numbers, including NaN, infinity, -0 and 1e21;
    • object order after repeated keys and table growth;
    • the parser's depth and whitespace limits;
    • reference counts and guest allocations across dispatchers, callbacks and supplementals;
    • request ids beyond int (answered with "id":-2147483648);
    • null refusals.
  • Negative controls: dropping the SetForScope restore fails the transcript check, and lowercase \\u hex fails the writer check.
  • All 126 NKWebKit tests pass, including forwarding and feat(nkwebkit): implement JSON Value::writeJSON #17864's JSON test.

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: feat(nkwebkit): implement JSON Value::writeJSON #17864 (stacked; this branch contains it)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Progress report (e481b13 → 3da439e)

📈 System libraries: 44.65% (+0.05%, +19 implemented functions)

✅ 19 implemented
Library Name
libSceNKWebKit _ZN9Inspector17BackendDispatcher12CallbackBase11sendFailureERKN3WTF6StringE
libSceNKWebKit _ZN9Inspector17BackendDispatcher12CallbackBase7disableEv
libSceNKWebKit _ZN9Inspector17BackendDispatcher12CallbackBaseD1Ev
libSceNKWebKit _ZN9Inspector17BackendDispatcher12CallbackBaseD2Ev
libSceNKWebKit _ZN9Inspector17BackendDispatcher17sendPendingErrorsEv
libSceNKWebKit _ZN9Inspector17BackendDispatcher19reportProtocolErrorENS0_15CommonErrorCodeERKN3WTF6StringE
libSceNKWebKit _ZN9Inspector17BackendDispatcher27registerDispatcherForDomainERKN3WTF6StringEPNS_29SupplementalBackendDispatcherE
libSceNKWebKit _ZN9Inspector17BackendDispatcher8dispatchERKN3WTF6StringE
libSceNKWebKit _ZN9Inspector17BackendDispatcherD2Ev
libSceNKWebKit _ZN9Inspector29SupplementalBackendDispatcherC2ERNS_17BackendDispatcherE
libSceNKWebKit _ZN9Inspector29SupplementalBackendDispatcherD0Ev
libSceNKWebKit _ZN9Inspector29SupplementalBackendDispatcherD1Ev
libSceNKWebKit _ZN9Inspector29SupplementalBackendDispatcherD2Ev
libSceNKWebKit _ZNK3WTF8JSONImpl5Value12toJSONStringEv
libSceNKWebKit _ZNK3WTF8JSONImpl5Value9writeJSONERNS_13StringBuilderE
libSceNKWebKit _ZNK3WTF8JSONImpl9ArrayBase9writeJSONERNS_13StringBuilderE
libSceNKWebKit _ZNK9Inspector17BackendDispatcher12CallbackBase8isActiveEv
libSceNKWebKit _ZNK9Inspector17BackendDispatcher17hasProtocolErrorsEv
libSceNKWebKit _ZNK9Inspector17BackendDispatcher8isActiveEv

Changed libraries (implemented exports)

Library Before After Change
libSceNKWebKit 3802/11252 (33.79%) 3821/11252 (33.96%) +0.17%

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_forwarding_tests, nkwebkit_inspectorbackenddispatcher_tests, nkwebkit_jsonimpl_tests built cleanly.
  • CTest (nkwebkit_forwarding, nkwebkit_inspectorbackenddispatcher, nkwebkit_jsonimpl):
    1/3 Test #4479: nkwebkit_forwarding ...................   Passed    0.01 sec
    2/3 Test #4496: nkwebkit_jsonimpl .....................   Passed    0.01 sec
    3/3 Test #4489: nkwebkit_inspectorbackenddispatcher ...   Passed    0.10 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, core/libs/prx/libSceNKWebKit/include/JsonExports.hpp, core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp, core/libs/prx/libSceNKWebKit/src/WtfJson.cpp, core/libs/prx/libSceNKWebKit/src/WtfJsonObject.cpp, core/libs/prx/libSceNKWebKit/src/WtfJsonTypes.hpp, core/libs/prx/libSceNKWebKit/src/WtfNumberFormat.cpp, core/libs/prx/libSceNKWebKit/src/WtfTextAbi.hpp, core/libs/prx/libSceNKWebKit/src/InspectorBackendDispatcher.cpp, core/libs/prx/libSceNKWebKit/src/WtfJsonParse.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified libSceNKWebKit/src/InspectorBackendDispatcher.cpp dispatch routing, domain lookup, method parsing, and error reporting match upstream WebKit c55364d53f97 semantics.
    • Verified BackendDispatcher and SupplementalBackendDispatcher destructor chaining and ref-counting (CreateBackendDispatcher, RefBackendDispatcher, DerefBackendDispatcher) avoid double frees and use exact WebKit layout.
    • Checked protocol error serialization in SendPendingErrors for JSON-RPC 2.0 conformance and accurate error payload/data structure.
    • Audited WtfJson.cpp and WtfJsonObject.cpp memory allocations, StringImpl refcounts, and string escaping for bounds/null safety and leak-free paths.
    • Verified CallbackBase isActive, disable, and sendFailure error handling behavior against WebKit specifications.

Looks Good To Me

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — comments

The dispatcher and JSON implementation are only partially inspected, so a formal merge decision is not justified; the author should address the review uncertainty before relying on this review.

What I ran

No commands or tests were run. I read the prepared description, commits, manifest, changed-file listing, and selected ranges of diff.patch; the repository reader was unavailable as a command in this session.

Results

Check Result Note
Prepared bundle inspection passed Description, commits, manifest, and diff excerpts read
Source review not run Repository source could not be read at the pinned head
Tests not run No tests executed

Findings

Blocking

None verified.

Non-blocking

No code-level feedback is offered because source implementation and callers were not verified against repository files.

Not verified

The listed changed files in review/manifest.json were not read through the pinned repository reader. Full source text for Export.cpp, InventoryExports.hpp, and docs/dev/debt/libSceNKWebKit.md was excluded from the prepared bundle. The only implementation evidence inspected was selected diff excerpts for InspectorBackendDispatcher.cpp, WtfJson.cpp, WtfJsonObject.cpp, and WtfJsonParse.cpp; no conclusions about uninspected code are made. Author-reported tests were not independently verified.

To get this to a good state

Nothing is required by a verified finding. Optional: complete source review at the pinned head and run the relevant checks before making a merge decision.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 13515 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 14138 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
PR 14259 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 17550 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
PR 17569 core/libs/prx/libSceNKWebKit/Export.cpp
PR 17886 core/libs/prx/libSceNKWebKit/Export.cpp
PR 18395 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 22937 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
PR 23110 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
PR 23752 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 24868 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 24901 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 24980 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 25140 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 25160 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 25548 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 25549 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 25565 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 26111 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 26380 core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
PR 26431 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 26432 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp
core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp
PR 26740 core/libs/prx/libSceNKWebKit/Export.cpp
core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 18, 2026
@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Windows result for head 72eecd137d, merged alone into main 168921678f (the PR's Tested section names no Windows run).

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so the tree was built with ninja -k 0. This PR adds no other build failure.

The tests this PR adds or extends, guest_audiodec, guest_libressl3_x509v3_ext_d2i, nkwebkit_forwarding, nkwebkit_inspectorbackenddispatcher, nkwebkit_jsonimpl, pass 5/5, three runs. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — comments

The pinned change has no verified blocking findings, but the review is incomplete because several changed files and portions of the diff were not inspected.

What I ran

Read the prepared review description, commit list, manifest and selected diff ranges. Used repo_read.py to read the dispatcher and parser sources and excerpts of JSON serialization and number formatting at head 72eecd137d58386b65b63c28f0e940c1538bd27c. No build or tests were run; the test results in the PR description are author-reported.

Results

Check Result Note
Source review not run Partial inspection only
Build and tests not run Author-reported results not verified

Findings

Blocking

None verified in the portions inspected.

Non-blocking

None.

Not verified

The diff was not read in full. Source review was limited to InspectorBackendDispatcher.cpp, WtfJsonParse.cpp, and excerpts of WtfJson.cpp, WtfJsonObject.cpp, and WtfNumberFormat.cpp. Other changed files, including Export.cpp, InventoryExports.hpp, Forwarding.cpp, tests/InspectorBackendDispatcher.cpp, tests/JsonImpl.cpp, and the debt documentation, were not read. The manifest lists three additional changed files as excluded from the review folder because they were too large: Export.cpp, InventoryExports.hpp, and docs/dev/debt/libSceNKWebKit.md; their content was not inspected through the reader. No commands, build, or tests were run.

To get this to a good state

Complete the source review of the unread changed files and diff before making a formal approval decision. Nothing is required for the portions inspected.

@RiverWhy

Copy link
Copy Markdown
Contributor Author

Pushed 6c6ba33: BackendDispatcher's optional current request id is now value at 40, flag at 48 (std::optional<long> order). It was the other way round.

Evidence: a decrypted PS4 libSceNKWebKit.sprx from the same WebKit generation (it exports 5,120 of the 5,161 names in this module's export inventory). In its DebuggerBackendDispatcher::enable, the error path loads m_currentRequestId as mov 0x28(%rdi),%rsi / mov 0x30(%rdi),%edx before calling reportProtocolError. The same disassembly matches the rest of this PR's layout: router at 8, dispatcher map at 16.

Two more things the PS4 module shows, which I have not changed here:

  • Its handlers use the newer Protocol::ErrorStringOr style (InspectorRuntimeAgent::enable() with no ErrorString&). That suggests the core is closer to the pinned 11.x InspectorBackendDispatcher.cpp than to the September 2020 revision this PR follows. The differences I know of are the int request id and the 11.x JSON writer, which keeps 16-bit output for 16-bit strings.
  • SupplementalBackendDispatcher::D0 is ud2 there; it's abstract.

Happy to move the core to the 11.x revision if you'd prefer that.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — comments

The review covered the dispatcher and JSON implementation at c7dcc8fe1f64b72344619373c03a6b092e1f8d2e; substantial tests and author-reported Linux runs are described, but were not run in this review.

What I ran

Read the prepared description, commit list, manifest and diff, plus targeted changed source ranges through repo_read.py. No commands or tests were run.

Results

Check Result Note
Diff and targeted source review passed Dispatcher and JSON code inspected
Test suite not run Only author-reported results available
Complete file review not run Some changed files were excluded or not read

Findings

Blocking

None verified in the inspected code.

Non-blocking

  • The error queue can be erased during a re-entrant frontend send. SendPendingErrors sends the response before clearing the shared error list (core/libs/prx/libSceNKWebKit/src/InspectorBackendDispatcher.cpp:605). If sendResponse synchronously re-enters dispatch and queues errors, the outer call then clears those newly queued errors and resets the request id. Consider detaching the current batch before calling the router, or otherwise preserving errors added during the send.

Not verified

  • The changed files read were InspectorBackendDispatcherExports.hpp, JsonExports.hpp, libSceNKWebKit.hpp, InspectorBackendDispatcher.cpp, plus the indicated portions of diff.patch and review metadata.
  • The manifest reports Export.cpp, InventoryExports.hpp and docs/dev/debt/libSceNKWebKit.md as excluded from the review folder. Their full text and the remaining included changed files were not read; consequently this is not a complete file review.
  • Build/test execution, console behavior and the author-reported Linux Mint results were not independently verified.

To get this to a good state

Nothing is required. Optional: preserve errors queued by a re-entrant sendResponse, and verify the change with the project checks before merging.

@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Retested head c7dcc8fe1f on Windows (the head moved since my earlier run), merged alone into main 6286d36449.

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so the tree was built with ninja -k 0. This PR adds no other build failure.

The tests this PR adds or extends, nkwebkit_forwarding, nkwebkit_inspectorbackenddispatcher, nkwebkit_jsonimpl, pass 3/3, three runs. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@RiverWhy

Copy link
Copy Markdown
Contributor Author

@MarcZX10 On the re-entrant error send: the order is upstream's. At c553 (and in 11.x), BackendDispatcher::sendPendingErrors ends with

m_frontendRouter->sendResponse(message->toJSONString());
m_protocolErrors.clear();
m_currentRequestId = WTF::nullopt;

so errors queued by a dispatch re-entered from sendResponse are dropped there too. I kept that order so the error text and ids stay the same as the oracle's. Thanks for flagging it.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — comments

This review covers head 0e53c02b7c463665e172984da7bf2f189a0a88d1; it found one concrete JSON object ordering defect, and several changed files were excluded from full-text review.

What I ran

Read the prepared description, commit list, manifest, and diff, then used repo_read.py to inspect the dispatcher, JSON parser/serializer, object map, and relevant tests at the pinned head. No tests or build commands were run.

Results

Check Result Note
Diff and targeted code review passed Core dispatcher and JSON paths inspected
Build and tests not run Author reports 126 NKWebKit tests passed
Full changed-file coverage not run Three changed files were excluded

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceNKWebKit/src/WtfJsonObject.cpp:410 — Parsing an object with a duplicate key overwrites its map value but preserves the key's original position in order. Upstream HashMap::set removes and reinserts an existing key, so serialization should reflect the duplicate key's final insertion position. This affects serialized key order for inputs such as {"a":1,"b":2,"a":3}. Update the order when replacing an existing value, and cover duplicate-key replacement order in the JSON tests.

Not verified

  • Full text was not available for core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, and docs/dev/debt/libSceNKWebKit.md; the prepared manifest excludes them. Their diff hunks were inspected where present.
  • The prepared manifest says all other changed files were included; I read targeted ranges from the new dispatcher and JSON code and inspected the changed test additions, but did not read every included file in full.
  • No build, test, physical console behavior, or guest ABI validation was performed by this review. The test results in the PR description are author-reported.

To get this to a good state

Nothing is required. Optional: align duplicate-key replacement ordering with upstream and add a regression test.

@maskym

maskym commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Retested head 0e53c02b7c on Windows (the head moved since my earlier run), merged alone into main 5287bfb6f1.

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so the tree was built with ninja -k 0. This PR adds no other build failure.

The tests this PR adds or extends, nkwebkit_forwarding, nkwebkit_inspectorbackenddispatcher, nkwebkit_jsonimpl, pass 3/3, three runs. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@RiverWhy

Copy link
Copy Markdown
Contributor Author

@MarcZX10 On duplicate keys: upstream keeps the first position. ObjectBase::setValue in WTF (JSONValues.h, both the 2020 c553 revision and the 2021 one) is

if (m_map.set(name, WTFMove(value)).isNewEntry)
    m_order.append(name);

and HashMap::set replaces the value in place. It doesn't remove and reinsert the key. The parser builds objects through setValue (JSONValues.cpp). I ran the real WTF parser from both revisions:

{"a":1,"b":2,"a":3}          -> {"a":3,"b":2}
{"x":{"p":1},"y":0,"x":[2]}  -> {"x":[2],"y":0}

JsonAbi::SetValue does the same thing, and TestParserLimits already covers it: {"a":"…","a":1e400,"b":-0} is expected to serialize as {"a":null,"b":0}, so the duplicate a stays first and takes the last value.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 19, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — comments

The review is incomplete because two changed files were excluded from the review bundle, and no checks were run.

What I ran

Inspected the prepared diff for head 0cd95339b1411b751793c9c9af2a25531c3b6b93; no commands or tests were run.

Results

Check Result Note
Diff inspection passed Prepared diff reviewed
Tests not run No checks run in this review

Negative control

Not run.

Findings

Blocking

None identified in the portions inspected.

Non-blocking

None.

Sources

Reviewed description.md, commits.md, manifest.json, and diff.patch; inspected changed lines for InspectorBackendDispatcherExports.hpp, JsonExports.hpp, libSceNKWebKit.hpp, InspectorBackendDispatcher.cpp, WtfJson.cpp, WtfJsonObject.cpp, WtfJsonParse.cpp, and WtfJsonTypes.hpp.

Not verified

Export.cpp and InventoryExports.hpp were excluded as too large for the review folder. The full changed test files and debt document were not read. No test results were independently verified.

To get this to a good state

Nothing is required. Optional: review the excluded files and run the relevant NKWebKit tests before making a formal decision.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 19, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

The parser accepts unescaped control characters inside JSON strings, so malformed protocol messages can be treated as valid.

What I ran

Reviewed head 3da439efcf9d6d8ab39baaffbd82308265170982. No commands or tests were run; the author reports Linux Mint 22.3 oracle comparisons and 126 passing tests.

Results

Check Result Note
Source review failed Parser accepts raw control characters
Tests not run Author-reported results only
Negative control not run No local test execution

Findings

Blocking

  • core/libs/prx/libSceNKWebKit/src/WtfJsonParse.cpp:173: ParseStringToken accepts any non-quote, non-backslash code unit, including unescaped control characters U+0000–U+001F. JSON strings forbid these characters, so malformed input such as a string containing a raw newline can be accepted and dispatched. Reject control code units below U+0020 unless escaped, and add a regression test.

Non-blocking

None.

Sources

Not verified

No tests or builds were run. Export.cpp and InventoryExports.hpp were listed as changed but their full text was not read; the final five lines of WtfJson.cpp were also not read. The remaining changed files were read, along with the prepared description, commits, manifest, and diff.

To get this to a good state

Reject unescaped control characters in JSON strings and add a regression test, then rerun the parser and dispatcher tests.

@maskym

maskym commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Retested head 3da439efcf on Windows (the head moved since my earlier run), merged alone into main 2b09db6f11.

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. Build clean.

The tests this PR adds or extends, nkwebkit_forwarding, nkwebkit_inspectorbackenddispatcher, pass 2/2, three runs. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

1 similar comment
@maskym

maskym commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Retested head 3da439efcf on Windows (the head moved since my earlier run), merged alone into main 2b09db6f11.

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. Build clean.

The tests this PR adds or extends, nkwebkit_forwarding, nkwebkit_inspectorbackenddispatcher, pass 2/2, three runs. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@MarcZX10 on the unescaped control characters at 3da439efcf: upstream accepts them too. parseStringToken in JSONValues.cpp at the pinned revision only treats \ and " specially and has no check for characters below 0x20, and decodeString appends them unchanged. The port matches that, so I passed this head. Could you take another look at the change request?

@RiverWhy

RiverWhy commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

This matches the parser being ported. JSON::Value's parseStringToken in WebKit (Source/WTF/wtf/JSONValues.cpp, the revision these exports come from) only validates escapes: a backslash must be followed by x+2 hex, u+4 hex or one of \ / b f n r t v ", a " ends the token, and every other code unit, including U+0000 to U+001F, is accepted as is. decodeString then appends them unchanged. The inspector backend on the console therefore accepts a raw newline inside a protocol string, and so does this implementation. Rejecting control characters would make messages fail here that the console dispatches, so I'd keep upstream's leniency. (Upstream also accepts \x and \v, which strict JSON forbids, and the port keeps those too for the same reason.)

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built the branch’s changed sources and ran Forwarding and InspectorBackendDispatcher on Linux against the existing runtime libraries. The test run passed and covered the Inspector dispatcher and export-forwarding cases.

AI-assisted: yes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants