Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: f5b6bcdb33c73c2e96577017d6ce3fc854aab795
https://github.com/WebKit/WebKit/commit/f5b6bcdb33c73c2e96577017d6ce3fc854aab795
Author: Darin Adler <[email protected]>
Date: 2024-04-28 (Sun, 28 Apr 2024)
Changed paths:
M
LayoutTests/fast/dom/Window/alert-with-unmatched-utf16-surrogate-should-not-crash-expected.txt
A
LayoutTests/platform/mac-wk1/fast/dom/Window/alert-with-unmatched-utf16-surrogate-should-not-crash-expected.txt
M Source/JavaScriptCore/API/JSStringRef.cpp
M Source/JavaScriptCore/API/OpaqueJSString.h
M Source/JavaScriptCore/jsc.cpp
M Source/JavaScriptCore/wasm/WasmParser.h
M Source/WTF/wtf/text/AtomString.cpp
M Source/WTF/wtf/text/AtomStringImpl.cpp
M Source/WTF/wtf/text/AtomStringImpl.h
M Source/WTF/wtf/text/StringConcatenate.h
M Source/WTF/wtf/text/StringImpl.cpp
M Source/WTF/wtf/text/StringImpl.h
M Source/WTF/wtf/text/UTF8ConversionError.h
M Source/WTF/wtf/text/WTFString.cpp
M Source/WTF/wtf/unicode/UTF8Conversion.cpp
M Source/WTF/wtf/unicode/UTF8Conversion.h
M Source/WebCore/platform/SharedBuffer.cpp
M Source/WebCore/xml/XSLTProcessorLibxslt.cpp
M Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
M Source/WebKit/Shared/API/c/WKString.cpp
M Tools/TestWebKitAPI/CMakeLists.txt
M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
A Tools/TestWebKitAPI/Tests/WTF/UTF8Conversion.cpp
Log Message:
-----------
Use std::span and char8_t more for UTF-8 handling
https://bugs.webkit.org/show_bug.cgi?id=272644
rdar://126441747
Reviewed by Chris Dumez.
*
LayoutTests/fast/dom/Window/alert-with-unmatched-utf16-surrogate-should-not-crash-expected.txt:
Updated because the test accidentally depended on a peculiar form of
strictness that only applied to an unpaired lead surrogate at the
end of the string; that's gone now.
*
LayoutTests/platform/mac-wk1/fast/dom/Window/alert-with-unmatched-utf16-surrogate-should-not-crash-expected.txt:
Added.
On Cocoa platforms, legacy WebKit uses -[NSString UTF8String] to
serialize, which is strict, causing this test to have a different result.
This difference was hidden before by accidental strictness in the one
specific case here, in WTF UTF-8 conversion. The best way to handle this
is an exception for the legacy WebKit test result.
* Source/JavaScriptCore/API/JSStringRef.cpp:
(JSStringCreateWithUTF8CString): Use new span-based functions.
(JSStringGetUTF8CString): Ditto.
* Source/JavaScriptCore/jsc.cpp:
(toCString): Simplified code, and removed unneeded distinct handling
for source exhausted vs. invalid, which is a distinction that is not
valuable in this context, and in fact not needed in any context!
* Source/JavaScriptCore/wasm/WasmParser.h: Changed large Parser class
template to be a tiny one, since the only thing dependent on the
template argument was a single type, Parser::Result. Moved all the
rest of the code into a ParserBase non-template class.
(JSC::Wasm::ParserBase::consumeUTF8String): Use new checkUTF8 function,
which is a more efficient way to check the string than converting into
a UTF-16 buffer and then discarding the buffer, what the code did before.
* Source/WTF/wtf/text/AtomString.cpp:
(WTF::AtomString::fromUTF8Internal): Use add instead of addUTF8, since
the char8_t type now expresses the fact that it's UTF-8.
* Source/WTF/wtf/text/AtomStringImpl.cpp:
(WTF::HashedUTF8CharactersTranslator::hash): Use UTF16LengthWithHash.
(WTF::HashedUTF8CharactersTranslator::equal): Ditto. Use equal functions
from UTF8Conversion.h and StringCommon.h instead of writing out alternate
implementations here.
(WTF::HashedUTF8CharactersTranslator::translate): Ditto.
(WTF::AtomStringImpl::add): Renamed from addUTF8 and changed argument
type to use char8_t.
* Source/WTF/wtf/text/AtomStringImpl.h: Renamed addUTF8 to add and changed
argument type to use char8_t.
* Source/WTF/wtf/text/StringConcatenate.h: Removed UTF8Adapter, use
CheckedUTF8 from UTF8Conversion.h instead.
* Source/WTF/wtf/text/StringImpl.cpp:
(WTF::putUTF8Triple): Deleted.
(WTF::StringImpl::utf8ForCharactersIntoBuffer): Use convert and
convertReplacingInvalidSequences instead of writing out more complex code
here. The old code was more complex to work around limitations in
UTF8Conversion.h that were easier to deal with at that level. Also, there
are two identical modes here that were implemented differently.
* Source/WTF/wtf/text/StringImpl.h:
(WTF::StringImpl::tryGetUTF8ForCharacters): Use new span-based functions.
* Source/WTF/wtf/text/UTF8ConversionError.h: Removed the distinct
"source exhausted" error, since there is no need to make that distinction.
Use the word "invalid" instead of "illegal" for invalid UTF-8 sequences.
* Source/WTF/wtf/text/WTFString.cpp:
(WTF::fromUTF8Impl): Use new span-based functions.
* Source/WTF/wtf/unicode/UTF8Conversion.cpp:
(WTF::Unicode::next): Added helpers so the convertInternal function can
handle various combinations without a lot of if statements.
(WTF::Unicode::append): Ditto.
(WTF::Unicode::convertInternal): Added. This is the main implementation
shared by the various convert functions below.
(WTF::Unicode::convert): Use convertInternal. Renamed from various names,
using types and overloading to make clear what's being converted, and
eliminating both out arguments and boolean "strict" arguments.
(WTF::Unicode::convertReplacingInvalidSequences): Ditto.
(WTF::Unicode::checkUTF8): Renamed from computeUTFLengths and changed
return type.
(WTF::Unicode::computeUTF16LengthWithHash): Renamed from
calculateStringHashAndLengthFromUTF8MaskingTop8Bits and use char8_t and
return value instead of out arguments.
(WTF::Unicode::equal): Use spans for arguments, remove no-longer-accurate
comments about being safe only because callers must check lengths.
* Source/WTF/wtf/unicode/UTF8Conversion.h: Use span, char8_t, and return values
* Source/WebCore/platform/SharedBuffer.cpp:
(WebCore::utf8Buffer): Use new functions.
* Source/WebCore/xml/XSLTProcessorLibxslt.cpp:
(WebCore::writeToStringBuilder): Ditto.
* Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::convertUTF16EntityToUTF8): Ditto.
* Source/WebKit/Shared/API/c/WKString.cpp:
(WKStringGetUTF8CStringImpl): Ditto.
* Tools/TestWebKitAPI/CMakeLists.txt: Added UTF8Conversion.cpp.
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Ditto.
* Tools/TestWebKitAPI/Tests/WTF/UTF8Conversion.cpp: Added.
Some basic tests for all the functions in UTF8Conversion.h.
Canonical link: https://commits.webkit.org/278094@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes