feat(libSceNKWebKit): implement the WTF::StringBuilder and WTF::TextStream exports #14172
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14172"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by winstrex on 2026-10-31T22:00:07Z.
Source of the behaviour
Ported from public WebKit at commit
c55364d53f97(September 2020), the revision #13564 and #13565 use. The module's revision is a strong inference from the exported names, not a proof: the 27 names exist together frombddada44652f(January 2020, which addsoperator<<(TextStream&, Seconds)) untile12a212a531a(May 2021, which removesappendNumber(float)). Across that range both layouts are the same (theTextStreamflags become one byte after1d10fce7651a, with the bit the exports read unchanged), and the ported files change only by a guard this port already has (5a14e48f02dd).PS5-WebKit-11.xhas none of these exports and a differentStringBuilderlayout, so it was not used. No console module was checked. The layouts below come from the source and the Itanium and System V rules, and the debt entry says they are not checked against the binary.StringBuildermembers:String m_string,RefPtr<StringImpl> m_buffer, the 8/16-bit buffer pointer union,Checked<int32_t, ConditionalCrashOnOverflow> m_length(twobools then theint32_t),bool m_is8Bit;m_isReifiedonly withASSERT_ENABLED, which is 0 underNDEBUGTextStreammembers: theStringBuilder,unsigned m_formattingFlags,int m_indent,bool m_multiLineMode;NumberRespectingIntegersis1 << 1append(const String&)adopts the string into an empty builder without a buffer,append(LChar)writes in place while there is room and no reified string,append(const char*),toString,clearmax(required, 16, 2 × capacity),reifyString(the buffer itself when full, else a substring sharing it), allocation, reallocation and up-conversion,reserveCapacity, the append paths,shrinkToFitbelow 80 % use,appendNumber(float)Checked<int32_t> + unsignedis computed asunsignedwith a fresh handler that crashes, then narrowed toCheckedInt32, which records; assignment clears the flagappendQuotedJSONString: capacityroundUpToPowerOfTwo(length + 2 + 6n), the escape table, lowercase\u00XX, unpaired surrogates escapedTextStreamoperators,release, groups, lines and indent; floating point asfixedWidth(value, 2), or as an integer whenNumberRespectingIntegersis set and the value has no fraction above 0.0001operator<<(TextStream&, Seconds)writes the value thens;operator<<(TextStream&, const URL&)writesurl.string()ToShortestSingleandToFixedof the ECMAScript converter (Infinity,NaN, unique zero,e+exponents, decimal between 1e-6 and 1e21, nothing forToFixedat 1e21 or above or past 100 digits, ties rounded up)ABI from the mangled names under the Itanium and System V rules: every member takes
thisfirst;release()returnsWTF::String, which has a non-trivial destructor, through a hidden result pointer; theTextStreamoperators returnTextStream&inrax;Secondsis a class with onedoubleand is passed inxmm0;longandunsigned longare 64-bit;appendNumber(float)andoperator<<(float)take thefloatinxmm0.AnyPS5 lines replaced:
WtfExports.hpp.appendNumber(float)was one of the 131 in the previous section, now 130.What
Implements the 27
WTF::StringBuilderandWTF::TextStreamexports oflibSceNKWebKitthat still threw, ported from the files above:StringBuilder:appendCharacters(Latin-1 and UTF-16),reserveCapacity,shrinkToFit,reifyString,appendNumber(float)andappendQuotedJSONString.TextStream: the 13operator<<members (bool,char, the six integer types,float,double,const char*,const void*,const String&),release,startGroup,endGroup,nextLine,writeIndent, and the freeoperator<<forSecondsandURL.New files:
src/StringBuilder.cpp,src/StringBuilderJSON.cpp(kept apart because the original is MPL 2.0),src/TextStream.cppandsrc/WtfNumberFormat.cpp, each with the original licence notice and a "Derived from" line;src/WtfTextAbi.hppholds both layouts withstatic_asserton every offset and the size.WtfStringAbi.hppgains a copy assignment forString, andWtfString.cppexposes its empty string, uninitialised allocation and shared substring to the new files. The uninitialised allocation usesTryAllocate, as WebKit'stryCreateUninitializedusestryMalloc, so a failed allocation returns null and the builder records an overflow (or throws, for a builder that crashes on overflow) instead of aborting.StringBuilder(append(UChar),append(const String&),length()), so it works on the same fields: the buffer is aStringImplwhose length is the capacity, and the growth, reification and shrink rules are WebKit's, including the odd ones, such as a zero-lengthfixedWidthappend still allocating a 16-character buffer.std::to_charsgives the shortest float digits and the exact decimal expansion, and the ECMAScript formatting and round-half-up ofToFixedare applied to them.UINT32_MAX(which crashes in WebKit even for a recording builder),toStringafter an overflow, null characters with a nonzero length. A recording builder records the overflow and ignores later appends, as in WebKit. Two debug assertions that guard memory WebKit would corrupt also throw:reserveCapacityon an empty 16-bit builder without a buffer, andappendQuotedJSONStringof a 16-bit string into an 8-bit builder that holds an adopted string and no buffer, which WebKit up-converts from a null pointer.operator<<(const void*)formats like the tree's libc%p(FormatPointer), since WebKit calls the console'ssnprintf.Functionalentries list the throwing cases, the allocation limit and the reallocation, and the%pformat.No open PR implements these exports or adds these files.
tools/pr_overlap.pyreports line conflicts only: #13930 edits the stub next toappendNumber(float)inExport.cpp, and #13930, #13936, #13947 and #13992 change the two count lines of the debt file. It could not compare #13515, #13744, #13766, #13770 and #13772, which conflict withmain; their diffs touch none of the 27 names and none of the new files. Whichever merges later rebases. #13992 declares a 24-byteJsonAbi::StringBuilder(the later layout) as the parameter type of thewriteJSONslot it leaves throwing, without reading its fields; once both land, that slot should takeWtfAbi::StringBuilder.Tested
ctest -R nkwebkitpasses (10 suites), including the newnkwebkit_wtftext(all 27 exports: growth, up-conversion, reification and shrinking with their reference counts, overflow on recording and crashing builders, JSON escaping and capacity, float text,TextStreamvalues, flags, strings, groups and indent) andnkwebkit_wtftext_allocation, which builds the builder and string sources with a test allocator that fails on demand and checks every free against its allocation and guard bytes: a failed initial allocation, growth of an owned and of a shared 8-bit and 16-bit buffer,reserveCapacityand up-conversion each record an overflow on a recording builder and throw on a crashing one, leaving the character pointer null, and the 16-bit length limit records an overflow without allocating. Full suite on9ef85aeeb2(before the allocation change), on the same PC with its GPU (RTX 5070 Ti, Overwolf's Vulkan layers disabled): 3198 of 3201 pass, 12 skipped; the 3 failures (guest_wide_formatting,log_macros,log_macros_timestamps) fail the same way onmain613f9b8edfon this machine.mainhas (typed, so the test still builds), the test aborts with_ZN3WTF13StringBuilder16appendCharactersEPKhj not implemented. 28 single-line mutations, each rebuilt and run: 27 make the test fail (minimum capacity, shrink threshold, string adoption, reallocation copy, up-conversion, crash and record on overflow, theUINT32_MAXcrash, the zero-length append, the Latin-1 shortcut, JSON capacity, escapes and hex case, fixed ties, 1e21 and negative zero, the shortest exponent bounds and sign,NumberRespectingIntegers, its tolerance and theINT_MINtruncation, group and line indent in both modes, theSecondsunit, the pointer format,releaseclearing,booltext). The one that passes, sharing a substring when the buffer is full, is equivalent:SubstringSharingImplof the whole string returns the buffer itself. Without theTryAllocatechange the allocation test aborts in the fatal allocator; 11 mutations of the failure paths (fatal allocator, empty string or a stale character pointer on failure, no length limit, 16-bit storage sized for 8 bits, each of the three builder null checks, the reallocation leaking the old buffer, the flag not set): 10 make it fail. The one that passes, a zero length allocating, is unreachable: every caller asks for 16 or more, and a reallocation to zero takes another path.double-conversionfrom the pinned commit (DoubleToStringConverter::EcmaScriptConverter, built on the host with stubconfig.h,Assertions.handASCIICType.h) againstWtfNumberFormat.cpp.ToShortestSingle: 70.4 million floats (every 61st bit pattern, plus the neighbours of every power of two, both signs) gave identical text.ToFixed: 22.9 million doubles (random bit patterns, decimals with three digits, multiples of 1/8, values just off the half-cent ties, scaled mantissas) with 2 digits and a random 0 to 7, plus the ties, 1e21, the subnormals and 100 and 101 digits, gave identical text.python tools/check_conventions.py --base upstream/mainpasses.tools/progress.py --compare: +27 implemented functions in libSceNKWebKit.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T22:13:12Z.
Review: COMMENTED
Reviewed — approval withheld pending ABI evidence
I reviewed head
9ef85aeeb26f7c798037140083b358ba630d8b63; I could not verify that the guestStringBuilderandTextStreamlayouts match the target module ABI.What I ran
The PR head is
9ef85aeeb26f7c798037140083b358ba630d8b63; the currentmainbase isf776fddcffd1cfece220ecdd894371988b164f6a. The merge preview was clean; the common ancestor wasb9bf246ea2efb00b58218c4709b8c4dd9e13a826. Checks ran on Linux x86_64, Debian 12, Python 3.11.2, with GCC 12.2.0 available. I did not build or compile.Results
git diff --checknkwebkitCTest suites passing on Windows 11/GCC 15.2, plus differential float-format checks and mutation tests. I did not run these.Unedited local check output
git diff --checkproduced no output and exited 0.Findings
Blocking
No reproducible code-level defect was established in the inspected implementation. The ABI uncertainty below prevents me from treating the review as complete.
Non-blocking
No separate source-level defect was established.
Sources
StringBuilderandTextStreamlayouts at this PR headNot verified
To get this to a good state
Please add evidence for the target object layouts or leave these exports throwing until the ABI is verified. I can repeat the same no-build checks and inspect the evidence on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T23:38:19Z.
Review: COMMENTED
Re-checked — new head, allocation fix verified; ABI evidence still pending
Head
83413ef46807f8ae6fa37b4f93d54ac6691db910adds a non-fatal allocation path and a failure-injection test that the Windows workflow built and passed.What I ran
Reviewed the exact head
83413ef46807f8ae6fa37b4f93d54ac6691db910against PR basef776fddcffd1cfece220ecdd894371988b164f6a; the clean merge preview used currentmainatb08c539c505c48341146c705bc72d9b603cdb3a7. Environment: Linux 6.1.0-54-amd64, Python 3.11.2. I did not build locally.Results
d211e617007b3c7d1faf212d64a1e2ca6ad96ac5nkwebkit_wtftext_allocation, test 2309, in 0.02 sghmetadata read fails withInvalid \uXXXX escapeUnedited relevant outputs
git diff --checkproduced no output and exited 0.Findings
The maintainer's allocation-failure finding is addressed:
TryCreateUninitializednow usesNKWebKit::TryAllocate, and the new test injects failures for initial allocation, growth, reserve, and 8-to-16-bit conversion. The new head still does not resolve the ABI uncertainty from my prior review. The updated PR description itself says no console module was checked, and its debt entry still says theStringBuilderandTextStreamlayouts are not checked against a console binary. I am not approving until the target ABI is supported by evidence.Sources
Not verified
No Linux, macOS, console, or local build was run. The Windows workflow's exact test result is hosted CI, not a local run.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:49:29Z.
Review: COMMENTED
Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (
Unblocks: noneis allowed), and it contained no code review.