Commit b7cce06
Streamline handling of null-terminated strings to improve clarity and safety
rdar://165305546
https://bugs.webkit.org/show_bug.cgi?id=303027
Reviewed by Sam Weinig.
Eliminated other members of the unsafeSpan function family, leaving only
unsafeSpan and unsafeSpanIncludingNullTerminator.
Eliminated some functions that take null-terminated strings, such as
String::createFromCString. Changed callers to safe interfaces that pass
lengths and sizes instead or to call unsafeSpan.
Redid the UTF-8 span literal operator so we can use it in constant expressions.
Syntax is now u8""_span instead of ""_spanChar8.
Simplified test code that was unnecessarily using null-terminated strings
to instead use ASCIILiteral or similar. Also used toNSData in test code
rather than toNSDataNoCopy; the "no copy" optimization is unnecessary for tests.
* Source/JavaScriptCore/API/JSStringRef.cpp:
(JSStringCreateWithUTF8CString): Use unsafeSpan. Use conversion from UTF-8
built into the String class. Take advantage of null handling built into the
function so we don't need a special case for the null pointer.
* Source/JavaScriptCore/API/JSValue.mm:
(createStructHandlerMap): Use unsafeSpan.
* Source/JavaScriptCore/runtime/Identifier.h: Removed overloads of
the == operator and the equal function that take null-terminated strings.
(JSC::Identifier::equal):
* Source/JavaScriptCore/runtime/Options.cpp:
(JSC::OptionsHelper::Option::dump const): Use unsafeSpan.
* Source/JavaScriptCore/wasm/WasmParser.h:
(JSC::Wasm::ParserBase::consumeUTF8String): Use byteCast.
* Source/WTF/wtf/FileSystem.cpp:
(WTF::FileSystemImpl::fromStdFileSystemPath): Use unsafeSpan.
* Source/WTF/wtf/text/ASCIILiteral.h: Added u8""_span. Removed ""_spanChar8.
* Source/WTF/wtf/text/StringCommon.h:
Deleted the unsafeSpan overload that takes const Latin1Character*.
(WTF::unsafeSpan8): Deleted.
(WTF::unsafeSpanChar8): Deleted.
(WTF::unsafeSpan8IncludingNullTerminator): Deleted.
* Source/WTF/wtf/text/StringConcatenate.h: Deleted the StringTypeAdapter
that takes const Latin1Character*.
* Source/WTF/wtf/text/StringImpl.h: Use unsafeSpan.
(WTF::StringImpl::createFromCString): Deleted.
* Source/WTF/wtf/text/StringView.h: Use unsafeSpan.
Replaced the equal function that takes const Latin1Character* with one
that takes span<const Latin1Character>.
* Source/WTF/wtf/text/WTFString.cpp:
(WTF::String::String): Use unsafeSpan.
* Source/WTF/wtf/text/WTFString.h: Use unsafeSpan.
Some updates to the fromUTF8 family of functions, clarifying deprecation.
* Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp:
(WebCore::GraphicsContextGLANGLE::initialize): Use unsafeSpan.
* Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
(WebCore::initializeEGLDisplay): Use unsafeSpan.
(WebCore::GraphicsContextGLCocoa::platformInitializeContext): Ditto.
* Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp:
(WebCore::FontPlatformData::familyName const): Use unsafeSpan.
* Source/WebCore/platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp:
(WebCore::TrackPrivateBaseGStreamer::TrackPrivateBaseGStreamer): Use unsafeSpan.
(WebCore::TrackPrivateBaseGStreamer::setPad): Ditto.
(WebCore::TrackPrivateBaseGStreamer::getLanguageCode): Ditto.
(WebCore::TrackPrivateBaseGStreamer::notifyTrackOfStreamChanged): Ditto.
(WebCore::TrackPrivateBaseGStreamer::updateTrackIDFromTags): Ditto.
* Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp:
(WebCore::AppendPipeline::recycleTrackForPad): Use unsafeSpan.
(WebCore::serializeLowercase): Moved this function up in the file, changed it
to return ASCIILiteral, and made it a non-member function so it can be internal
to the file rather than in the header.
(WebCore::AppendPipeline::Track::emplaceOptionalElementsForFormat): Use
serializeLowercase.
* Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.h:
Removed now-unused streamTypeToStringLower.
* Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp:
(webkit_web_view_load_plain_text): Use unsafeSpan.
* Source/WebKit/UIProcess/gtk/SystemSettingsManagerProxyGtk.cpp:
(WebKit::SystemSettingsManagerProxy::updateFontProperties): Use unsafeSpan.
* Source/WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp:
(WebKit::RemoteVideoCodecFactory::createEncoder): Use byteCast.
* Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.cpp:
(WebKit::GObjectEventListener::GObjectEventListener): Store event type as
m_eventType AtomString instead of m_domEventName CString, previously we converted
it to an AtomString any time it is used. Also, used the term event type from
the DOM rather than coining a different name for the same concept.
(WebKit::GObjectEventListener::gobjectDestroyed): Use m_eventType.
* Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.h:
(WebKit::GObjectEventListener::addEventListener): Use m_eventType instead of
converting to AtomString.
(WebKit::GObjectEventListener::removeEventListener): Ditto.
* Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::accessibilityFocusedUIElement): Use unsafeSpanIncludingNullTerminator.
* Tools/TestWebKitAPI/Tests/WTF/CString.cpp:
(TEST(WTF, CStringViewASCIICaseConversions)): Use u8""_span.
* Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp:
(TestWebKitAPI::TEST(StringBuilderTest, Append)): Use u8""_span.
* Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp:
(TestWebKitAPI::TEST(WTF_StringCommon, Equal)): Use u8""_span.
(TestWebKitAPI::TEST(WTF_StringCommon, EqualIgnoringASCIICase)): Ditto.
(TestWebKitAPI::TEST(WTF_StringCommon, StartsWith)): Ditto.
(TestWebKitAPI::TEST(WTF_StringCommon, EndsWith)): Ditto.
(TestWebKitAPI::TEST(WTF_StringCommon, Find)): Ditto.
(TestWebKitAPI::TEST(WTF_StringCommon, ReverseFind)): Ditto.
(TestWebKitAPI::TEST(WTF_StringCommon, Contains)): Ditto.
(TestWebKitAPI::TEST(WTF_StringCommon, StartsWithLettersIgnoringASCIICase)): Ditto.
(TestWebKitAPI::TEST(WTF_StringCommon, EndsWithLettersIgnoringASCIICase)): Ditto.
(TestWebKitAPI::TEST(WTF_StringCommon, FindIgnoringASCIICase)): Ditto.
(TestWebKitAPI::TEST(WTF_StringCommon, ContainsIgnoringASCIICase)): Ditto.
(TestWebKitAPI::TEST(WTF_StringCommon, CharactersAreAllASCII)): Ditto.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleEditingDelegatePlugIn.mm:
(-[BundleEditingDelegatePlugIn _webProcessPlugInBrowserContextController:pasteboardDataForRange:]):
Use [NSData dataUsingEncoding:].
* Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
(-[PSONScheme initWithBytes:]): Use ASCIILiteral.
(-[PSONScheme addMappingFromURLString:toData:]): Ditto.
(-[PSONScheme webView:startURLSchemeTask:]): Ditto.
((ProcessSwap, HistoryNavigationToFragmentURL)): Ditto.
((ProcessSwap, PolicyCancelAfterServerRedirect)): Ditto.
((ProcessSwap, SameOriginSystemPreview)): Ditto.
((ProcessSwap, SessionStorage)): Ditto.
((ProcessSwap, ReuseSuspendedProcessEvenIfPageCacheFails)): Ditto.
((ProcessSwap, HistoryItemIDConfusion)): Ditto.
((ProcessSwap, MainFramesOnly)): Ditto.
((ProcessSwap, MediaTypeAfterSwap)): Ditto.
((ProcessSwap, NavigateCrossSiteBeforePageLoadEnd)): Ditto.
((ProcessSwap, PageShowHide)): Ditto.
((ProcessSwap, LoadUnload)): Ditto.
((ProcessSwap, SameOriginBlobNavigation)): Ditto.
((ProcessSwap, NavigateToDataURLThenBack)): Ditto.
((ProcessSwap, SwapOnFormSubmission)): Ditto.
((ProcessSwap, OpenerLinkAfterAPIControlledProcessSwappingOfOpener)): Ditto.
((ProcessSwap, NavigateCrossOriginWithOpener)): Ditto.
((ProcessSwap, ContentBlockingAfterProcessSwap)): Ditto.
((ProcessSwap, ContentExtensionBlocksMainLoadThenReloadWithoutExtensions)): Ditto.
((ProcessSwap, GetUserMediaCaptureState)): Ditto.
((ProcessSwap, PassMinimumDeviceWidthOnNewWebView)): Ditto.
((ProcessSwap, ResizeWebViewDuringCrossSiteProvisionalNavigation)): Ditto.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
(-[ServiceWorkerSchemeHandler webView:startURLSchemeTask:]): Use unsafeSpan.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm:
(mainBytesData): Added.
(TEST(URLSchemeHandler, Basic)): Use ASCIILiteral.
(TEST(URLSchemeHandler, BasicWithHTTPS)): Ditto.
(TEST(URLSchemeHandler, BasicWithAsyncPolicyDelegate)): Ditto.
(TEST(URLSchemeHandler, NoMIMEType)): Ditto.
(-[SyncScheme webView:startURLSchemeTask:]): Ditto.
(-[SyncErrorScheme webView:startURLSchemeTask:]): Ditto.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
(-[DataMappingSchemeHandler addMappingFromURLString:toData:]): Use ASCIILiteral.
((WebpagePreferences, WebsitePoliciesCustomUserAgent)): Ditto.
* Tools/TestWebKitAPI/Tests/mac/WebViewIconLoading.mm:
(mainResourceData): Use ASCIILiteral.
(imageFromData): Ditto.
(TestWebKitAPI::TEST(WebKitLegacy, IconLoadingDelegateDefaultFirst)): Ditto.
(TestWebKitAPI::TEST(WebKitLegacy, IconLoadingDelegateCustomFirst)): Ditto.
Canonical link: https://commits.webkit.org/303520@main
Signed-off-by: Xabier Rodriguez Calvar <calvaris@igalia.com>1 parent 95e3e29 commit b7cce06
79 files changed
Lines changed: 368 additions & 400 deletions
File tree
- Source
- JavaScriptCore
- API
- glib
- bytecompiler
- runtime
- tools
- wasm
- WTF/wtf
- glib
- text
- WebCore
- Modules
- indexeddb/server
- mediastream/libwebrtc
- webdatabase
- bindings/js
- bridge
- dom
- editing
- loader
- page
- platform
- audio/gstreamer
- glib
- graphics
- cocoa
- freetype
- gstreamer
- eme
- mse
- texmap
- gstreamer
- mediastream
- gstreamer
- libwebrtc/gstreamer
- network
- soup
- sql
- xml
- WebKit
- NetworkProcess
- soup
- webrtc
- UIProcess
- API/glib
- Inspector/glib
- WebProcess
- GPU/media
- InjectedBundle/API/gtk/DOM
- Tools/TestWebKitAPI/Tests
- WTF
- WebKitCocoa
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1281 | 1281 | | |
1282 | 1282 | | |
1283 | 1283 | | |
1284 | | - | |
1285 | | - | |
| 1284 | + | |
| 1285 | + | |
1286 | 1286 | | |
1287 | 1287 | | |
1288 | 1288 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
| 231 | + | |
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
467 | 467 | | |
468 | 468 | | |
469 | 469 | | |
470 | | - | |
| 470 | + | |
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
| |||
587 | 587 | | |
588 | 588 | | |
589 | 589 | | |
590 | | - | |
| 590 | + | |
591 | 591 | | |
592 | 592 | | |
593 | 593 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
503 | 503 | | |
504 | 504 | | |
505 | 505 | | |
506 | | - | |
| 506 | + | |
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
| |||
905 | 905 | | |
906 | 906 | | |
907 | 907 | | |
908 | | - | |
| 908 | + | |
909 | 909 | | |
910 | 910 | | |
911 | 911 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
| 171 | + | |
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | | - | |
| 294 | + | |
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | | - | |
| 300 | + | |
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
148 | | - | |
149 | 147 | | |
150 | | - | |
151 | | - | |
152 | 148 | | |
153 | 149 | | |
154 | 150 | | |
| |||
175 | 171 | | |
176 | 172 | | |
177 | 173 | | |
178 | | - | |
179 | 174 | | |
180 | 175 | | |
181 | 176 | | |
| |||
228 | 223 | | |
229 | 224 | | |
230 | 225 | | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | 226 | | |
247 | 227 | | |
248 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
281 | | - | |
| 281 | + | |
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
299 | | - | |
| 299 | + | |
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
431 | | - | |
| 431 | + | |
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
| |||
1262 | 1262 | | |
1263 | 1263 | | |
1264 | 1264 | | |
1265 | | - | |
| 1265 | + | |
1266 | 1266 | | |
1267 | 1267 | | |
1268 | 1268 | | |
| |||
1439 | 1439 | | |
1440 | 1440 | | |
1441 | 1441 | | |
1442 | | - | |
| 1442 | + | |
1443 | 1443 | | |
1444 | 1444 | | |
1445 | | - | |
| 1445 | + | |
1446 | 1446 | | |
1447 | 1447 | | |
1448 | 1448 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
683 | 683 | | |
684 | 684 | | |
685 | 685 | | |
686 | | - | |
| 686 | + | |
687 | 687 | | |
688 | 688 | | |
689 | 689 | | |
0 commit comments