From 9c69f13ecdd059cd1a6391861557afa00ec4f259 Mon Sep 17 00:00:00 2001 From: Xabier Rodriguez-Calvar Date: Mon, 17 Mar 2025 04:23:25 -0700 Subject: [PATCH 01/22] [GStreamer] Make webkitGstGhostPadFromStaticTemplate use ASCIILiteral https://bugs.webkit.org/show_bug.cgi?id=289788 Reviewed by Philippe Normand. Other than the description, as a fly-by, made GstPadTemplate use a smart ptr. * Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp: (_WebKitWebAudioSrcPrivate::_WebKitWebAudioSrcPrivate): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::webkitGstGhostPadFromStaticTemplate): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h: * Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp: (webKitAudioSinkConfigure): * Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp: (videoEncoderConstructed): * Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp: (webkitMediaStreamSrcAddTrack): Canonical link: https://commits.webkit.org/292260@main Signed-off-by: Xabier Rodriguez Calvar --- .../audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp | 2 +- .../platform/graphics/gstreamer/GStreamerCommon.cpp | 10 ++++------ .../platform/graphics/gstreamer/GStreamerCommon.h | 2 +- .../graphics/gstreamer/WebKitAudioSinkGStreamer.cpp | 2 +- .../gstreamer/VideoEncoderPrivateGStreamer.cpp | 4 ++-- .../gstreamer/GStreamerMediaStreamSource.cpp | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp index eda12afc7da0b..49cb81f269bed 100644 --- a/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp @@ -90,7 +90,7 @@ struct _WebKitWebAudioSrcPrivate { _WebKitWebAudioSrcPrivate() { - sourcePad = webkitGstGhostPadFromStaticTemplate(&srcTemplate, "src", nullptr); + sourcePad = webkitGstGhostPadFromStaticTemplate(&srcTemplate, "src"_s, nullptr); g_rec_mutex_init(&mutex); } diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp index 1157a1e720430..8a732464b5ef7 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp @@ -111,17 +111,15 @@ namespace WebCore { static GstClockTime s_webkitGstInitTime; -GstPad* webkitGstGhostPadFromStaticTemplate(GstStaticPadTemplate* staticPadTemplate, const gchar* name, GstPad* target) +WARN_UNUSED_RETURN GstPad* webkitGstGhostPadFromStaticTemplate(GstStaticPadTemplate* staticPadTemplate, ASCIILiteral name, GstPad* target) { GstPad* pad; - GstPadTemplate* padTemplate = gst_static_pad_template_get(staticPadTemplate); + GRefPtr padTemplate = gst_static_pad_template_get(staticPadTemplate); if (target) - pad = gst_ghost_pad_new_from_template(name, target, padTemplate); + pad = gst_ghost_pad_new_from_template(name.characters(), target, padTemplate.get()); else - pad = gst_ghost_pad_new_no_target_from_template(name, padTemplate); - - gst_object_unref(padTemplate); + pad = gst_ghost_pad_new_no_target_from_template(name.characters(), padTemplate.get()); return pad; } diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h index 6818212332643..01d00608250a4 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h @@ -66,7 +66,7 @@ inline bool webkitGstCheckVersion(guint major, guint minor, guint micro) #define GST_AUDIO_CAPS_TYPE_PREFIX "audio/" #define GST_TEXT_CAPS_TYPE_PREFIX "text/" -GstPad* webkitGstGhostPadFromStaticTemplate(GstStaticPadTemplate*, const gchar* name, GstPad* target); +WARN_UNUSED_RETURN GstPad* webkitGstGhostPadFromStaticTemplate(GstStaticPadTemplate*, ASCIILiteral name, GstPad* target); #if ENABLE(VIDEO) bool getVideoSizeAndFormatFromCaps(const GstCaps*, WebCore::IntSize&, GstVideoFormat&, int& pixelAspectRatioNumerator, int& pixelAspectRatioDenominator, int& stride); std::optional getVideoResolutionFromCaps(const GstCaps*); diff --git a/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp index 4e5dbfbe5474e..a0b7225f548d5 100644 --- a/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp @@ -65,7 +65,7 @@ static bool webKitAudioSinkConfigure(WebKitAudioSink* sink) gst_bin_add(GST_BIN_CAST(sink), sink->priv->interAudioSink.get()); auto targetPad = adoptGRef(gst_element_get_static_pad(sink->priv->interAudioSink.get(), "sink")); - gst_element_add_pad(GST_ELEMENT_CAST(sink), webkitGstGhostPadFromStaticTemplate(&sinkTemplate, "sink", targetPad.get())); + gst_element_add_pad(GST_ELEMENT_CAST(sink), webkitGstGhostPadFromStaticTemplate(&sinkTemplate, "sink"_s, targetPad.get())); return true; } return false; diff --git a/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp b/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp index 6883dda235674..a785d1eec9379 100644 --- a/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp +++ b/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp @@ -581,7 +581,7 @@ static void videoEncoderConstructed(GObject* encoder) self->priv->bitrateMode = CONSTANT_BITRATE_MODE; self->priv->latencyMode = REALTIME_LATENCY_MODE; - auto* sinkPad = webkitGstGhostPadFromStaticTemplate(&sinkTemplate, "sink", nullptr); + auto* sinkPad = webkitGstGhostPadFromStaticTemplate(&sinkTemplate, "sink"_s, nullptr); GST_OBJECT_FLAG_SET(sinkPad, GST_PAD_FLAG_NEED_PARENT); gst_pad_set_event_function(sinkPad, reinterpret_cast(+[](GstPad* pad, GstObject* parent, GstEvent* event) -> gboolean { if (GST_EVENT_TYPE(event) == GST_EVENT_CUSTOM_DOWNSTREAM_OOB) { @@ -597,7 +597,7 @@ static void videoEncoderConstructed(GObject* encoder) })); gst_element_add_pad(GST_ELEMENT_CAST(self), sinkPad); - gst_element_add_pad(GST_ELEMENT_CAST(self), webkitGstGhostPadFromStaticTemplate(&srcTemplate, "src", nullptr)); + gst_element_add_pad(GST_ELEMENT_CAST(self), webkitGstGhostPadFromStaticTemplate(&srcTemplate, "src"_s, nullptr)); } static void setupVaEncoder(WebKitVideoEncoder* self) diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp index a804a88cbbef2..9d2f4ca212c54 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp @@ -1157,7 +1157,7 @@ void webkitMediaStreamSrcAddTrack(WebKitMediaStreamSrc* self, MediaStreamTrackPr GST_DEBUG_OBJECT(self, "%s Ghosting %" GST_PTR_FORMAT, objectPath.get(), pad.get()); #endif - auto ghostPad = webkitGstGhostPadFromStaticTemplate(padTemplate, padName.ascii().data(), pad.get()); + auto* ghostPad = webkitGstGhostPadFromStaticTemplate(padTemplate, ASCIILiteral::fromLiteralUnsafe(padName.ascii().data()), pad.get()); gst_pad_store_sticky_event(ghostPad, stickyStreamStartEvent.get()); gst_pad_set_active(ghostPad, TRUE); gst_element_add_pad(GST_ELEMENT_CAST(self), ghostPad); From a6e4e278e344c443fbda3dfe7466415e61737b2f Mon Sep 17 00:00:00 2001 From: Xabier Rodriguez-Calvar Date: Tue, 18 Mar 2025 00:05:39 -0700 Subject: [PATCH 02/22] [GStreamer] Switch doCapsHaveType to ASCIILiteral https://bugs.webkit.org/show_bug.cgi?id=289896 Reviewed by Philippe Normand. * Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::AudioFileReader::plugDeinterleave): * Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp: (WebCore::AudioSourceProviderGStreamer::AudioSourceProviderGStreamer): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::doCapsHaveType): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h: * Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.cpp: (WebCore::ImageDecoderGStreamer::ImageDecoderGStreamer): * Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp: (WebCore::GStreamerIncomingTrackProcessor::configure): * Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp: Canonical link: https://commits.webkit.org/292297@main Signed-off-by: Xabier Rodriguez Calvar --- .../platform/audio/gstreamer/AudioFileReaderGStreamer.cpp | 2 +- .../audio/gstreamer/AudioSourceProviderGStreamer.cpp | 2 +- .../platform/graphics/gstreamer/GStreamerCommon.cpp | 4 ++-- .../WebCore/platform/graphics/gstreamer/GStreamerCommon.h | 8 ++++---- .../platform/graphics/gstreamer/ImageDecoderGStreamer.cpp | 2 +- .../gstreamer/GStreamerIncomingTrackProcessor.cpp | 2 +- .../mediastream/gstreamer/GStreamerMediaStreamSource.cpp | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp index cbee6c5281fa0..e0407314d3bc2 100644 --- a/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp @@ -346,7 +346,7 @@ void AudioFileReader::plugDeinterleave(GstPad* pad) return; auto padCaps = adoptGRef(gst_pad_query_caps(pad, nullptr)); - if (!doCapsHaveType(padCaps.get(), "audio/x-raw")) + if (!doCapsHaveType(padCaps.get(), "audio/x-raw"_s)) return; // A decodebin pad was added, plug in a deinterleave element to diff --git a/Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp index 51547b0226c00..33616a00c9b33 100644 --- a/Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp @@ -123,7 +123,7 @@ AudioSourceProviderGStreamer::AudioSourceProviderGStreamer(MediaStreamTrackPriva g_signal_connect_swapped(decodebin, "pad-added", G_CALLBACK(+[](AudioSourceProviderGStreamer* provider, GstPad* pad) { auto padCaps = adoptGRef(gst_pad_query_caps(pad, nullptr)); - bool isAudio = doCapsHaveType(padCaps.get(), "audio"); + bool isAudio = doCapsHaveType(padCaps.get(), "audio"_s); RELEASE_ASSERT(isAudio); auto sinkPad = adoptGRef(gst_element_get_static_pad(provider->m_audioSinkBin.get(), "sink")); diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp index 8a732464b5ef7..a5e1e3003c229 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp @@ -297,14 +297,14 @@ StringView capsMediaType(const GstCaps* caps) return gstStructureGetName(structure); } -bool doCapsHaveType(const GstCaps* caps, const char* type) +bool doCapsHaveType(const GstCaps* caps, ASCIILiteral type) { auto mediaType = capsMediaType(caps); if (!mediaType) { GST_WARNING("Failed to get MediaType"); return false; } - return mediaType.startsWith(span(type)); + return mediaType.startsWith(type); } bool areEncryptedCaps(const GstCaps* caps) diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h index 01d00608250a4..859e792e15e58 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h @@ -62,9 +62,9 @@ inline bool webkitGstCheckVersion(guint major, guint minor, guint micro) return true; } -#define GST_VIDEO_CAPS_TYPE_PREFIX "video/" -#define GST_AUDIO_CAPS_TYPE_PREFIX "audio/" -#define GST_TEXT_CAPS_TYPE_PREFIX "text/" +#define GST_VIDEO_CAPS_TYPE_PREFIX "video/"_s +#define GST_AUDIO_CAPS_TYPE_PREFIX "audio/"_s +#define GST_TEXT_CAPS_TYPE_PREFIX "text/"_s WARN_UNUSED_RETURN GstPad* webkitGstGhostPadFromStaticTemplate(GstStaticPadTemplate*, ASCIILiteral name, GstPad* target); #if ENABLE(VIDEO) @@ -76,7 +76,7 @@ StringView capsMediaType(const GstCaps*); std::optional getStreamIdFromPad(const GRefPtr&); std::optional getStreamIdFromStream(const GRefPtr&); std::optional parseStreamId(StringView stringId); -bool doCapsHaveType(const GstCaps*, const char*); +bool doCapsHaveType(const GstCaps*, ASCIILiteral); bool areEncryptedCaps(const GstCaps*); Vector extractGStreamerOptionsFromCommandLine(); void setGStreamerOptionsFromUIProcess(Vector&&); diff --git a/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.cpp index 5ae702a055a44..77057b3b54702 100644 --- a/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.cpp @@ -124,7 +124,7 @@ ImageDecoderGStreamer::ImageDecoderGStreamer(FragmentedSharedBuffer& data, const auto caps = adoptGRef(gst_pad_query_caps(pad.get(), nullptr)); auto identityHarness = GStreamerElementHarness::create(GRefPtr(gst_element_factory_make("identity", nullptr)), [](auto&, const auto&) { }); GST_DEBUG_OBJECT(pad.get(), "Caps on parser source pad: %" GST_PTR_FORMAT, caps.get()); - if (!caps || !doCapsHaveType(caps.get(), "video")) { + if (!caps || !doCapsHaveType(caps.get(), "video"_s)) { GST_WARNING_OBJECT(m_decoderHarness->element(), "Ignoring non-video track"); return identityHarness; } diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp index 4f6fe0b36b919..4e9dbfd93094d 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp @@ -49,7 +49,7 @@ void GStreamerIncomingTrackProcessor::configure(ThreadSafeWeakPtr Date: Tue, 18 Mar 2025 02:23:49 -0700 Subject: [PATCH 03/22] [GStreamer] Change isGStreamerPluginAvailable to ASCIILiteral https://bugs.webkit.org/show_bug.cgi?id=289942 Reviewed by Philippe Normand. * Source/WebCore/Modules/mediastream/gstreamer/GStreamerPeerConnectionBackend.cpp: (WebCore::createGStreamerPeerConnectionBackend): * Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp: (webKitGLVideoSinkProbePlatform): * Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp: (WebCore::GStreamerAudioMixer::isAvailable): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::isGStreamerPluginAvailable): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h: * Source/WebCore/platform/graphics/gstreamer/TextCombinerGStreamer.cpp: (webKitTextCombinerHandleCaps): (webkitTextCombinerNew): * Source/WebCore/platform/mediarecorder/MediaRecorderPrivateGStreamer.cpp: (WebCore::MediaRecorderPrivateBackend::containerProfile): Canonical link: https://commits.webkit.org/292299@main Signed-off-by: Xabier Rodriguez Calvar --- .../gstreamer/GStreamerPeerConnectionBackend.cpp | 2 +- .../graphics/gstreamer/DMABufVideoSinkGStreamer.cpp | 2 +- .../platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp | 2 +- .../platform/graphics/gstreamer/GStreamerAudioMixer.cpp | 2 +- .../WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp | 6 +++--- .../WebCore/platform/graphics/gstreamer/GStreamerCommon.h | 2 +- .../platform/graphics/gstreamer/TextCombinerGStreamer.cpp | 4 ++-- .../mediarecorder/MediaRecorderPrivateGStreamer.cpp | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerPeerConnectionBackend.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerPeerConnectionBackend.cpp index 34e4a80e2b91a..c0910212cad77 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerPeerConnectionBackend.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerPeerConnectionBackend.cpp @@ -76,7 +76,7 @@ static std::unique_ptr createGStreamerPeerConnectionBacke std::call_once(debugRegisteredFlag, [] { GST_DEBUG_CATEGORY_INIT(webkit_webrtc_pc_backend_debug, "webkitwebrtcpeerconnection", 0, "WebKit WebRTC PeerConnection"); }); - if (!isGStreamerPluginAvailable("webrtc")) { + if (!isGStreamerPluginAvailable("webrtc"_s)) { WTFLogAlways("GstWebRTC plugin not found. Make sure to install gst-plugins-bad >= 1.20 with the webrtc plugin enabled."); return nullptr; } diff --git a/Source/WebCore/platform/graphics/gstreamer/DMABufVideoSinkGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/DMABufVideoSinkGStreamer.cpp index 5d8d75bbdf6d1..353205535581e 100644 --- a/Source/WebCore/platform/graphics/gstreamer/DMABufVideoSinkGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/DMABufVideoSinkGStreamer.cpp @@ -195,7 +195,7 @@ bool webKitDMABufVideoSinkIsEnabled() bool webKitDMABufVideoSinkProbePlatform() { - return webkitGstCheckVersion(1, 20, 0) && isGStreamerPluginAvailable("app"); + return webkitGstCheckVersion(1, 20, 0) && isGStreamerPluginAvailable("app"_s); } void webKitDMABufVideoSinkSetMediaPlayerPrivate(WebKitDMABufVideoSink* sink, MediaPlayerPrivateGStreamer* player) diff --git a/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp index 4f9b81163aa3c..8ddc8c8dcd0f6 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp @@ -195,7 +195,7 @@ bool webKitGLVideoSinkProbePlatform() return false; } - return isGStreamerPluginAvailable("app") && isGStreamerPluginAvailable("opengl"); + return isGStreamerPluginAvailable("app"_s) && isGStreamerPluginAvailable("opengl"_s); } #undef GST_CAT_DEFAULT diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp index 8b30e0f14b6a3..a61828231aa26 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp @@ -32,7 +32,7 @@ GST_DEBUG_CATEGORY_STATIC(webkit_media_gst_audio_mixer_debug); bool GStreamerAudioMixer::isAvailable() { - return isGStreamerPluginAvailable("inter") && isGStreamerPluginAvailable("audiomixer"); + return isGStreamerPluginAvailable("inter"_s) && isGStreamerPluginAvailable("audiomixer"_s); } GStreamerAudioMixer& GStreamerAudioMixer::singleton() diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp index a5e1e3003c229..b0d2d706a96a0 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp @@ -935,11 +935,11 @@ Vector GstMappedBuffer::createVector() const return std::span { data(), size() }; } -bool isGStreamerPluginAvailable(const char* name) +bool isGStreamerPluginAvailable(ASCIILiteral name) { - GRefPtr plugin = adoptGRef(gst_registry_find_plugin(gst_registry_get(), name)); + GRefPtr plugin = adoptGRef(gst_registry_find_plugin(gst_registry_get(), name.characters())); if (!plugin) - GST_WARNING("Plugin %s not found. Please check your GStreamer installation", name); + GST_WARNING("Plugin %s not found. Please check your GStreamer installation", name.characters()); return plugin; } diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h index 859e792e15e58..59ddc677c663a 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h @@ -269,7 +269,7 @@ void disconnectSimpleBusMessageCallback(GstElement*); enum class GstVideoDecoderPlatform { ImxVPU, Video4Linux, OpenMAX }; -bool isGStreamerPluginAvailable(const char* name); +bool isGStreamerPluginAvailable(ASCIILiteral name); bool gstElementFactoryEquals(GstElement*, ASCIILiteral name); GstElement* createAutoAudioSink(const String& role); diff --git a/Source/WebCore/platform/graphics/gstreamer/TextCombinerGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/TextCombinerGStreamer.cpp index 232939e9526f3..2f31b5b590ee7 100644 --- a/Source/WebCore/platform/graphics/gstreamer/TextCombinerGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/TextCombinerGStreamer.cpp @@ -87,7 +87,7 @@ void webKitTextCombinerHandleCaps(WebKitTextCombiner* combiner, GstPad* pad, con gst_pad_link(srcPad.get(), internalPad.get()); } // Else: pipeline is already correct. } else if (gst_caps_can_intersect(cea608Caps.get(), caps)) { - if (!isGStreamerPluginAvailable("rsclosedcaption") || !isGStreamerPluginAvailable("closedcaption")) { + if (!isGStreamerPluginAvailable("rsclosedcaption"_s) || !isGStreamerPluginAvailable("closedcaption"_s)) { WTFLogAlways("GStreamer closedcaption plugins are missing. Please install gst-plugins-bad and gst-plugins-rs"); return; } @@ -218,7 +218,7 @@ static void webkit_text_combiner_class_init(WebKitTextCombinerClass* klass) GstElement* webkitTextCombinerNew() { // The combiner relies on webvttenc, fail early if it's not there. - if (!isGStreamerPluginAvailable("subenc")) { + if (!isGStreamerPluginAvailable("subenc"_s)) { WTFLogAlways("WebKit wasn't able to find a WebVTT encoder. Subtitles handling will be degraded unless gst-plugins-bad is installed."); return nullptr; } diff --git a/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateGStreamer.cpp b/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateGStreamer.cpp index b6c848cb127a4..646c6bb4c8bd8 100644 --- a/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateGStreamer.cpp +++ b/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateGStreamer.cpp @@ -271,7 +271,7 @@ GRefPtr MediaRecorderPrivateBackend::containerProfi if (scanner.isContentTypeSupported(GStreamerRegistryScanner::Configuration::Encoding, contentType, { }) == MediaPlayerEnums::SupportsType::IsNotSupported) return nullptr; - auto mp4Variant = isGStreamerPluginAvailable("fmp4") ? "iso-fragmented"_s : "iso"_s; + auto mp4Variant = isGStreamerPluginAvailable("fmp4"_s) ? "iso-fragmented"_s : "iso"_s; StringBuilder containerCapsDescriptionBuilder; auto containerType = contentType.containerType(); if (containerType.endsWith("mp4"_s)) From b71cbf674610fbc762fae1616879947ee57ff378 Mon Sep 17 00:00:00 2001 From: Xabier Rodriguez-Calvar Date: Wed, 19 Mar 2025 00:03:08 -0700 Subject: [PATCH 04/22] [GStreamer] Switch makeGStreamerElement to have proper string management https://bugs.webkit.org/show_bug.cgi?id=289949 Reviewed by Philippe Normand. For the same price I removed the makeGStreamerBin function, that is supposed to be dead code. * Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp: (WebCore::GStreamerMediaEndpoint::maybeInsertNetSimForElement): (WebCore::GStreamerMediaEndpoint::initializePipeline): * Source/WebCore/platform/audio/gstreamer/AudioDecoderGStreamer.cpp: (WebCore::GStreamerInternalAudioDecoder::GStreamerInternalAudioDecoder): * Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp: (WebCore::AudioDestinationGStreamer::AudioDestinationGStreamer): * Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::AudioFileReader::handleNewDeinterleavePad): (WebCore::AudioFileReader::plugDeinterleave): (WebCore::AudioFileReader::decodeAudioForBusCreation): * Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp: (WebCore::AudioSourceProviderGStreamer::AudioSourceProviderGStreamer): (WebCore::AudioSourceProviderGStreamer::configureAudioBin): (WebCore::AudioSourceProviderGStreamer::setClient): (WebCore::AudioSourceProviderGStreamer::handleNewDeinterleavePad): * Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp: (webKitWebAudioSrcConstructed): * Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp: (webKitGLVideoSinkConstructed): * Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp: (WebCore::GStreamerAudioMixer::GStreamerAudioMixer): (WebCore::GStreamerAudioMixer::registerProducer): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::createAutoAudioSink): (WebCore::makeGStreamerElement): (WebCore::makeGStreamerBin): Deleted. * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h: * Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp: (WebCore::GStreamerVideoFrameConverter::Pipeline::Pipeline): * Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): (WebCore::MediaPlayerPrivateGStreamer::createVideoSinkGL): (WebCore::MediaPlayerPrivateGStreamer::createVideoSink): * Source/WebCore/platform/graphics/gstreamer/TextCombinerGStreamer.cpp: (webKitTextCombinerHandleCaps): * Source/WebCore/platform/graphics/gstreamer/TextSinkGStreamer.cpp: (webkitTextSinkConstructed): * Source/WebCore/platform/graphics/gstreamer/VideoDecoderGStreamer.cpp: (WebCore::GStreamerInternalVideoDecoder::GStreamerInternalVideoDecoder): * Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp: (webKitAudioSinkConfigure): * Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp: (WebCore::AppendPipeline::AppendPipeline): (WebCore::createOptionalParserForFormat): (WebCore::createOptionalEncoderForFormat): (WebCore::AppendPipeline::Track::initializeElements): * Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkFake.h: * Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkRialto.cpp: (WebCore::GStreamerHolePunchQuirkRialto::createHolePunchVideoSink): * Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkWesteros.cpp: (WebCore::GStreamerHolePunchQuirkWesteros::createHolePunchVideoSink): * Source/WebCore/platform/gstreamer/GStreamerQuirkAmLogic.cpp: (WebCore::GStreamerQuirkAmLogic::createWebAudioSink): * Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.cpp: (WebCore::GStreamerQuirkRealtek::createWebAudioSink): * Source/WebCore/platform/gstreamer/GStreamerQuirkRialto.cpp: (WebCore::GStreamerQuirkRialto::createAudioSink): (WebCore::GStreamerQuirkRialto::createWebAudioSink): * Source/WebCore/platform/gstreamer/PlatformSpeechSynthesizerGStreamer.cpp: (WebCore::GstSpeechSynthesisWrapper::GstSpeechSynthesisWrapper): * Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp: (videoEncoderSetEncoder): * Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCapturer.cpp: (WebCore::GStreamerAudioCapturer::createConverter): * Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp: (WebCore::GStreamerAudioRTPPacketizer::create): (WebCore::GStreamerAudioRTPPacketizer::GStreamerAudioRTPPacketizer): * Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp: (WebCore::GStreamerCapturer::GStreamerCapturer): (WebCore::GStreamerCapturer::setupPipeline): (WebCore::GStreamerCapturer::makeElement): * Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.h: * Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp: (WebCore::GStreamerIncomingTrackProcessor::incomingTrackProcessor): (WebCore::GStreamerIncomingTrackProcessor::createParser): * Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp: * Source/WebCore/platform/mediastream/gstreamer/GStreamerMockDevice.cpp: (webkitMockDeviceCreateElement): * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp: (WebCore::GStreamerVideoCaptureSource::GStreamerVideoCaptureSource): * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.h: * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp: (WebCore::GStreamerVideoCapturer::GStreamerVideoCapturer): (WebCore::GStreamerVideoCapturer::createConverter): * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.h: * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp: (WebCore::GStreamerVideoRTPPacketizer::GStreamerVideoRTPPacketizer): * Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingVideoSourceGStreamer.cpp: (WebCore::RealtimeOutgoingVideoSourceGStreamer::initializePreProcessor): * Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp: (WebCore::GStreamerWebRTCVideoDecoder::makeElement): (WebCore::GStreamerWebRTCVideoDecoder::CreateFilter): * Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoderFactory.cpp: (WebCore::LibWebRTCGStreamerVideoEncoder::makeElement): Canonical link: https://commits.webkit.org/292349@main Signed-off-by: Xabier Rodriguez Calvar --- .../gstreamer/GStreamerMediaEndpoint.cpp | 4 +- .../audio/gstreamer/AudioDecoderGStreamer.cpp | 20 +++++----- .../gstreamer/AudioDestinationGStreamer.cpp | 6 +-- .../gstreamer/AudioFileReaderGStreamer.cpp | 12 +++--- .../AudioSourceProviderGStreamer.cpp | 20 +++++----- .../WebKitWebAudioSourceGStreamer.cpp | 2 +- .../gstreamer/DMABufVideoSinkGStreamer.cpp | 2 +- .../gstreamer/GLVideoSinkGStreamer.cpp | 6 +-- .../gstreamer/GStreamerAudioMixer.cpp | 8 ++-- .../graphics/gstreamer/GStreamerCommon.cpp | 25 +++--------- .../graphics/gstreamer/GStreamerCommon.h | 3 +- .../GStreamerVideoFrameConverter.cpp | 10 ++--- .../gstreamer/MediaPlayerPrivateGStreamer.cpp | 16 ++++---- .../gstreamer/TextCombinerGStreamer.cpp | 6 +-- .../graphics/gstreamer/TextSinkGStreamer.cpp | 2 +- .../gstreamer/VideoDecoderGStreamer.cpp | 16 ++++---- .../gstreamer/WebKitAudioSinkGStreamer.cpp | 2 +- .../graphics/gstreamer/mse/AppendPipeline.cpp | 38 +++++++++---------- .../gstreamer/GStreamerHolePunchQuirkFake.h | 2 +- .../GStreamerHolePunchQuirkRialto.cpp | 2 +- .../GStreamerHolePunchQuirkWesteros.cpp | 2 +- .../gstreamer/GStreamerQuirkAmLogic.cpp | 2 +- .../gstreamer/GStreamerQuirkRealtek.cpp | 2 +- .../gstreamer/GStreamerQuirkRialto.cpp | 4 +- .../PlatformSpeechSynthesizerGStreamer.cpp | 8 ++-- .../VideoEncoderPrivateGStreamer.cpp | 8 ++-- .../gstreamer/GStreamerAudioCapturer.cpp | 12 +++--- .../gstreamer/GStreamerAudioRTPPacketizer.cpp | 12 +++--- .../gstreamer/GStreamerCapturer.cpp | 14 +++---- .../mediastream/gstreamer/GStreamerCapturer.h | 6 +-- .../GStreamerIncomingTrackProcessor.cpp | 4 +- .../gstreamer/GStreamerMediaStreamSource.cpp | 2 +- .../gstreamer/GStreamerMockDevice.cpp | 2 +- .../gstreamer/GStreamerVideoCaptureSource.cpp | 4 +- .../gstreamer/GStreamerVideoCaptureSource.h | 2 +- .../gstreamer/GStreamerVideoCapturer.cpp | 10 ++--- .../gstreamer/GStreamerVideoCapturer.h | 2 +- .../gstreamer/GStreamerVideoRTPPacketizer.cpp | 4 +- .../RealtimeOutgoingVideoSourceGStreamer.cpp | 6 +-- .../GStreamerVideoDecoderFactory.cpp | 18 ++++----- .../GStreamerVideoEncoderFactory.cpp | 18 ++++----- 41 files changed, 165 insertions(+), 179 deletions(-) diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp index a1a8c15423e70..9cb85a7205e27 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp @@ -124,7 +124,7 @@ void GStreamerMediaEndpoint::maybeInsertNetSimForElement(GstBin* bin, GstElement gst_pad_unlink(pad.get(), peer.get()); - auto netsim = makeGStreamerElement("netsim", nullptr); + auto netsim = makeGStreamerElement("netsim"_s); gst_bin_add(GST_BIN_CAST(bin), netsim); GST_DEBUG_OBJECT(m_pipeline.get(), "Configuring %" GST_PTR_FORMAT " for transport element %" GST_PTR_FORMAT, netsim, element); @@ -160,7 +160,7 @@ bool GStreamerMediaEndpoint::initializePipeline() }); auto binName = makeString("webkit-webrtcbin-"_s, nPipeline++); - m_webrtcBin = makeGStreamerElement("webrtcbin", binName.ascii().data()); + m_webrtcBin = makeGStreamerElement("webrtcbin"_s, binName); if (!m_webrtcBin) return false; diff --git a/Source/WebCore/platform/audio/gstreamer/AudioDecoderGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/AudioDecoderGStreamer.cpp index 7640bf894795e..598cb3494a3ac 100644 --- a/Source/WebCore/platform/audio/gstreamer/AudioDecoderGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/AudioDecoderGStreamer.cpp @@ -166,7 +166,7 @@ GStreamerInternalAudioDecoder::GStreamerInternalAudioDecoder(const String& codec { GST_DEBUG_OBJECT(element.get(), "Configuring decoder for codec %s", codecName.ascii().data()); - const char* parser = nullptr; + ASCIILiteral parser; if (codecName.startsWith("mp4a"_s)) { m_inputCaps = adoptGRef(gst_caps_new_simple("audio/mpeg", "mpegversion", G_TYPE_INT, 4, "channels", G_TYPE_INT, config.numberOfChannels, nullptr)); auto codecData = wrapSpanData(config.description); @@ -181,7 +181,7 @@ GStreamerInternalAudioDecoder::GStreamerInternalAudioDecoder(const String& codec m_inputCaps = adoptGRef(gst_caps_new_simple("audio/x-opus", "channel-mapping-family", G_TYPE_INT, channelMappingFamily, nullptr)); m_header = wrapSpanData(config.description); if (m_header) - parser = "opusparse"; + parser = "opusparse"_s; } else if (codecName == "alaw"_s) m_inputCaps = adoptGRef(gst_caps_new_simple("audio/x-alaw", "rate", G_TYPE_INT, config.sampleRate, "channels", G_TYPE_INT, config.numberOfChannels, nullptr)); else if (codecName == "ulaw"_s) @@ -192,7 +192,7 @@ GStreamerInternalAudioDecoder::GStreamerInternalAudioDecoder(const String& codec GST_WARNING("Decoder config description for flac codec is mandatory"); return; } - parser = "flacparse"; + parser = "flacparse"_s; m_inputCaps = adoptGRef(gst_caps_new_empty_simple("audio/x-flac")); } else if (codecName == "vorbis"_s) { m_header = wrapSpanData(config.description); @@ -200,7 +200,7 @@ GStreamerInternalAudioDecoder::GStreamerInternalAudioDecoder(const String& codec GST_WARNING("Decoder config description for vorbis codec is mandatory"); return; } - parser = "oggparse"; + parser = "oggparse"_s; m_inputCaps = adoptGRef(gst_caps_new_empty_simple("application/ogg")); } else if (codecName.startsWith("pcm-"_s)) { auto components = codecName.split('-'); @@ -223,7 +223,7 @@ GStreamerInternalAudioDecoder::GStreamerInternalAudioDecoder(const String& codec m_inputCaps = adoptGRef(gst_caps_new_simple("audio/x-raw", "format", G_TYPE_STRING, gst_audio_format_to_string(gstPcmFormat), "rate", G_TYPE_INT, config.sampleRate, "channels", G_TYPE_INT, config.numberOfChannels, "layout", G_TYPE_STRING, "interleaved", nullptr)); - parser = "rawaudioparse"; + parser = "rawaudioparse"_s; } else return; @@ -235,18 +235,18 @@ GStreamerInternalAudioDecoder::GStreamerInternalAudioDecoder(const String& codec auto* factory = gst_element_get_factory(element.get()); isParserRequired = !gst_element_factory_can_sink_all_caps(factory, m_inputCaps.get()); } - if (!g_strcmp0(parser, "rawaudioparse")) { - harnessedElement = makeGStreamerElement(parser, nullptr); + if (parser == "rawaudioparse"_s) { + harnessedElement = makeGStreamerElement(parser); if (!harnessedElement) { - GST_WARNING_OBJECT(element.get(), "Required parser %s not found", parser); + GST_WARNING_OBJECT(element.get(), "Required parser %s not found", parser.characters()); m_inputCaps.clear(); return; } } else if (parser && isParserRequired) { // The decoder won't accept the input caps, so put a parser in front. - auto* parserElement = makeGStreamerElement(parser, nullptr); + auto* parserElement = makeGStreamerElement(parser); if (!parserElement) { - GST_WARNING_OBJECT(element.get(), "Required parser %s not found, decoding will fail", parser); + GST_WARNING_OBJECT(element.get(), "Required parser %s not found, decoding will fail", parser.characters()); m_inputCaps.clear(); return; } diff --git a/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp index 6f68ec4207603..073505856671a 100644 --- a/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp @@ -149,8 +149,8 @@ AudioDestinationGStreamer::AudioDestinationGStreamer(AudioIOCallback& callback, } } - GstElement* audioConvert = makeGStreamerElement("audioconvert", nullptr); - GstElement* audioResample = makeGStreamerElement("audioresample", nullptr); + GstElement* audioConvert = makeGStreamerElement("audioconvert"_s); + GstElement* audioResample = makeGStreamerElement("audioresample"_s); auto queue = gst_element_factory_make("queue", nullptr); g_object_set(queue, "max-size-buffers", 2, "max-size-bytes", 0, "max-size-time", static_cast(0), nullptr); @@ -166,7 +166,7 @@ AudioDestinationGStreamer::AudioDestinationGStreamer(AudioIOCallback& callback, // 1) Some platform sinks don't support non-interleaved audio without special caps (rialtowebaudiosink). // 2) Interaudio sink/src doesn't fully support non-interleaved audio (webkit audio sink) // 3) audiomixer doesn't support non-interleaved audio in output pipeline (webkit audio sink) - GstElement* capsFilter = makeGStreamerElement("capsfilter", nullptr); + GstElement* capsFilter = makeGStreamerElement("capsfilter"_s); GRefPtr caps = adoptGRef(gst_caps_new_simple("audio/x-raw", "layout", G_TYPE_STRING, "interleaved", nullptr)); g_object_set(capsFilter, "caps", caps.get(), nullptr); gst_bin_add(GST_BIN_CAST(m_pipeline.get()), capsFilter); diff --git a/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp index e0407314d3bc2..16877a5cd3104 100644 --- a/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp @@ -293,7 +293,7 @@ void AudioFileReader::handleNewDeinterleavePad(GstPad* pad) // in an appsink so we can pull the data from each // channel. Pipeline looks like: // ... deinterleave ! appsink. - GstElement* sink = makeGStreamerElement("appsink", nullptr); + GstElement* sink = makeGStreamerElement("appsink"_s); if (!m_firstChannelType) { auto caps = adoptGRef(gst_pad_query_caps(pad, nullptr)); @@ -352,10 +352,10 @@ void AudioFileReader::plugDeinterleave(GstPad* pad) // A decodebin pad was added, plug in a deinterleave element to // separate each planar channel. Sub pipeline looks like // ... decodebin2 ! audioconvert ! audioresample ! capsfilter ! deinterleave. - GstElement* audioConvert = makeGStreamerElement("audioconvert", nullptr); - GstElement* audioResample = makeGStreamerElement("audioresample", nullptr); + GstElement* audioConvert = makeGStreamerElement("audioconvert"_s); + GstElement* audioResample = makeGStreamerElement("audioresample"_s); GstElement* capsFilter = gst_element_factory_make("capsfilter", nullptr); - m_deInterleave = makeGStreamerElement("deinterleave", "deinterleave"); + m_deInterleave = makeGStreamerElement("deinterleave"_s, "deinterleave"_s); g_object_set(m_deInterleave.get(), "keep-positions", TRUE, nullptr); g_signal_connect_swapped(m_deInterleave.get(), "pad-added", G_CALLBACK(deinterleavePadAddedCallback), this); @@ -409,11 +409,11 @@ void AudioFileReader::decodeAudioForBusCreation() }, this, nullptr); ASSERT(!m_data.empty()); - auto* source = makeGStreamerElement("giostreamsrc", nullptr); + auto* source = makeGStreamerElement("giostreamsrc"_s); auto memoryStream = adoptGRef(g_memory_input_stream_new_from_data(m_data.data(), m_data.size(), nullptr)); g_object_set(source, "stream", memoryStream.get(), nullptr); - m_decodebin = makeGStreamerElement("decodebin", "decodebin"); + m_decodebin = makeGStreamerElement("decodebin"_s, "decodebin"_s); g_signal_connect(m_decodebin.get(), "autoplug-select", G_CALLBACK(decodebinAutoplugSelectCallback), nullptr); g_signal_connect_swapped(m_decodebin.get(), "pad-added", G_CALLBACK(decodebinPadAddedCallback), this); diff --git a/Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp index 33616a00c9b33..80496cfbe6ff4 100644 --- a/Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/AudioSourceProviderGStreamer.cpp @@ -111,7 +111,7 @@ AudioSourceProviderGStreamer::AudioSourceProviderGStreamer(MediaStreamTrackPriva m_audioSinkBin = gst_parse_bin_from_description("tee name=audioTee", true, nullptr); - auto* decodebin = makeGStreamerElement("uridecodebin3", nullptr); + auto* decodebin = makeGStreamerElement("uridecodebin3"_s); g_signal_connect_swapped(decodebin, "source-setup", G_CALLBACK(+[](AudioSourceProviderGStreamer* provider, GstElement* sourceElement) { if (!WEBKIT_IS_MEDIA_STREAM_SRC(sourceElement)) { @@ -205,11 +205,11 @@ void AudioSourceProviderGStreamer::configureAudioBin(GstElement* audioBin, GstEl GstElement* audioTee = gst_element_factory_make("tee", "audioTee"); GstElement* audioQueue = gst_element_factory_make("queue", nullptr); - GstElement* audioConvert = makeGStreamerElement("audioconvert", nullptr); - GstElement* audioConvert2 = makeGStreamerElement("audioconvert", nullptr); - GstElement* audioResample = makeGStreamerElement("audioresample", nullptr); - GstElement* audioResample2 = makeGStreamerElement("audioresample", nullptr); - GstElement* volumeElement = makeGStreamerElement("volume", "volume"); + GstElement* audioConvert = makeGStreamerElement("audioconvert"_s); + GstElement* audioConvert2 = makeGStreamerElement("audioconvert"_s); + GstElement* audioResample = makeGStreamerElement("audioresample"_s); + GstElement* audioResample2 = makeGStreamerElement("audioresample"_s); + GstElement* volumeElement = makeGStreamerElement("volume"_s, "volume"_s); gst_bin_add_many(GST_BIN_CAST(m_audioSinkBin.get()), audioTee, audioQueue, audioConvert, audioResample, volumeElement, audioConvert2, audioResample2, audioSink, nullptr); @@ -324,10 +324,10 @@ void AudioSourceProviderGStreamer::setClient(WeakPtr& // ensure deinterleave and the sinks downstream receive buffers in // the format specified by the capsfilter. auto* audioQueue = gst_element_factory_make("queue", "queue"); - auto* audioConvert = makeGStreamerElement("audioconvert", "audioconvert"); - auto* audioResample = makeGStreamerElement("audioresample", "audioresample"); + auto* audioConvert = makeGStreamerElement("audioconvert"_s, "audioconvert"_s); + auto* audioResample = makeGStreamerElement("audioresample"_s, "audioresample"_s); auto* capsFilter = gst_element_factory_make("capsfilter", "capsfilter"); - auto* deInterleave = makeGStreamerElement("deinterleave", "deinterleave"); + auto* deInterleave = makeGStreamerElement("deinterleave"_s, "deinterleave"_s); GST_DEBUG("Setting up audio deinterleave chain"); g_object_set(deInterleave, "keep-positions", TRUE, nullptr); @@ -377,7 +377,7 @@ void AudioSourceProviderGStreamer::handleNewDeinterleavePad(GstPad* pad) // channel. Pipeline looks like: // ... deinterleave ! queue ! appsink. auto* queue = gst_element_factory_make("queue", nullptr); - auto* sink = makeGStreamerElement("appsink", nullptr); + auto* sink = makeGStreamerElement("appsink"_s); static GstAppSinkCallbacks callbacks = { nullptr, diff --git a/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp index 49cb81f269bed..7f7221bb5e47e 100644 --- a/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp @@ -214,7 +214,7 @@ static void webKitWebAudioSrcConstructed(GObject* object) priv->task = adoptGRef(gst_task_new(reinterpret_cast(webKitWebAudioSrcRenderIteration), src, nullptr)); gst_task_set_lock(priv->task.get(), &priv->mutex); - priv->source = makeGStreamerElement("appsrc", "webaudioSrc"); + priv->source = makeGStreamerElement("appsrc"_s, "webaudioSrc"_s); // Configure the appsrc for minimal latency. g_object_set(priv->source.get(), "block", TRUE, "blocksize", priv->bufferSize, "format", GST_FORMAT_TIME, "is-live", TRUE, nullptr); diff --git a/Source/WebCore/platform/graphics/gstreamer/DMABufVideoSinkGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/DMABufVideoSinkGStreamer.cpp index 353205535581e..410bd82869c61 100644 --- a/Source/WebCore/platform/graphics/gstreamer/DMABufVideoSinkGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/DMABufVideoSinkGStreamer.cpp @@ -90,7 +90,7 @@ static void webKitDMABufVideoSinkConstructed(GObject* object) WebKitDMABufVideoSink* sink = WEBKIT_DMABUF_VIDEO_SINK(object); - sink->priv->appSink = makeGStreamerElement("appsink", "webkit-dmabuf-video-appsink"); + sink->priv->appSink = makeGStreamerElement("appsink"_s, "webkit-dmabuf-video-appsink"_s); ASSERT(sink->priv->appSink); g_object_set(sink->priv->appSink.get(), "enable-last-sample", FALSE, "emit-signals", TRUE, "max-buffers", 1, nullptr); diff --git a/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp index 8ddc8c8dcd0f6..7fae6da120386 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp @@ -66,7 +66,7 @@ static void webKitGLVideoSinkConstructed(GObject* object) GST_OBJECT_FLAG_SET(GST_OBJECT_CAST(sink), GST_ELEMENT_FLAG_SINK); gst_bin_set_suppressed_flags(GST_BIN_CAST(sink), static_cast(GST_ELEMENT_FLAG_SOURCE | GST_ELEMENT_FLAG_SINK)); - sink->priv->appSink = makeGStreamerElement("appsink", "webkit-gl-video-appsink"); + sink->priv->appSink = makeGStreamerElement("appsink"_s, "webkit-gl-video-appsink"_s); ASSERT(sink->priv->appSink); g_object_set(sink->priv->appSink.get(), "enable-last-sample", FALSE, "emit-signals", TRUE, "max-buffers", 1, nullptr); @@ -81,8 +81,8 @@ static void webKitGLVideoSinkConstructed(GObject* object) if (imxVideoConvertG2D) gst_bin_add(GST_BIN_CAST(sink), imxVideoConvertG2D); - GstElement* upload = makeGStreamerElement("glupload", nullptr); - GstElement* colorconvert = makeGStreamerElement("glcolorconvert", nullptr); + GstElement* upload = makeGStreamerElement("glupload"_s); + GstElement* colorconvert = makeGStreamerElement("glcolorconvert"_s); ASSERT(upload); ASSERT(colorconvert); diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp index a61828231aa26..20feda0c81e5c 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp @@ -48,7 +48,7 @@ GStreamerAudioMixer::GStreamerAudioMixer() registerActivePipeline(m_pipeline); connectSimpleBusMessageCallback(m_pipeline.get()); - m_mixer = makeGStreamerElement("audiomixer", nullptr); + m_mixer = makeGStreamerElement("audiomixer"_s); auto* audioSink = createAutoAudioSink({ }); gst_bin_add_many(GST_BIN_CAST(m_pipeline.get()), m_mixer.get(), audioSink, nullptr); @@ -88,13 +88,13 @@ void GStreamerAudioMixer::ensureState(GstStateChange stateChange) GRefPtr GStreamerAudioMixer::registerProducer(GstElement* interaudioSink) { - GstElement* src = makeGStreamerElement("interaudiosrc", nullptr); + GstElement* src = makeGStreamerElement("interaudiosrc"_s); g_object_set(src, "channel", GST_ELEMENT_NAME(interaudioSink), nullptr); g_object_set(interaudioSink, "channel", GST_ELEMENT_NAME(interaudioSink), nullptr); auto bin = gst_bin_new(nullptr); - auto audioResample = makeGStreamerElement("audioresample", nullptr); - auto audioConvert = makeGStreamerElement("audioconvert", nullptr); + auto audioResample = makeGStreamerElement("audioresample"_s); + auto audioConvert = makeGStreamerElement("audioconvert"_s); gst_bin_add_many(GST_BIN_CAST(bin), audioResample, audioConvert, nullptr); gst_element_link(audioConvert, audioResample); diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp index b0d2d706a96a0..6ddd6c10dda5e 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp @@ -950,7 +950,7 @@ bool gstElementFactoryEquals(GstElement* element, ASCIILiteral name) GstElement* createAutoAudioSink(const String& role) { - auto* audioSink = makeGStreamerElement("autoaudiosink", nullptr); + auto* audioSink = makeGStreamerElement("autoaudiosink"_s); g_signal_connect_data(audioSink, "child-added", G_CALLBACK(+[](GstChildProxy*, GObject* object, gchar*, gpointer userData) { auto* role = reinterpret_cast(userData); auto* objectClass = G_OBJECT_GET_CLASS(object); @@ -1036,33 +1036,20 @@ GstBuffer* gstBufferNewWrappedFast(void* data, size_t length) return gst_buffer_new_wrapped_full(static_cast(0), data, length, 0, length, data, fastFree); } -GstElement* makeGStreamerElement(const char* factoryName, const char* name) +GstElement* makeGStreamerElement(ASCIILiteral factoryName, const String& name) { static Lock lock; - static Vector cache WTF_GUARDED_BY_LOCK(lock); - auto* element = gst_element_factory_make(factoryName, name); + static Vector cache WTF_GUARDED_BY_LOCK(lock); + auto* element = gst_element_factory_make(factoryName.characters(), name.isEmpty() ? nullptr : name.ascii().data()); Locker locker { lock }; if (!element && !cache.contains(factoryName)) { cache.append(factoryName); - WTFLogAlways("GStreamer element %s not found. Please install it", factoryName); + WTFLogAlways("GStreamer element %s not found. Please install it", factoryName.characters()); + ASSERT_NOT_REACHED_WITH_MESSAGE("GStreamer element %s not found. Please install it", factoryName.characters()); } return element; } -GstElement* makeGStreamerBin(const char* description, bool ghostUnlinkedPads) -{ - static Lock lock; - static Vector cache WTF_GUARDED_BY_LOCK(lock); - GUniqueOutPtr error; - auto* bin = gst_parse_bin_from_description(description, ghostUnlinkedPads, &error.outPtr()); - Locker locker { lock }; - if (!bin && !cache.contains(description)) { - cache.append(description); - WTFLogAlways("Unable to create bin for description: \"%s\". Error: %s", description, error->message); - } - return bin; -} - #if USE(GSTREAMER_WEBRTC) static ASCIILiteral webrtcStatsTypeName(int value) { diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h index 59ddc677c663a..5976962833c0d 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h @@ -282,8 +282,7 @@ bool webkitGstSetElementStateSynchronously(GstElement*, GstState, Function std::optional gstStructureGet(const GstStructure*, ASCIILiteral key); diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp index 0161efa74d6d2..3823f92a65bf2 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp @@ -47,11 +47,11 @@ GStreamerVideoFrameConverter::GStreamerVideoFrameConverter() ensureGStreamerInitialized(); GST_DEBUG_CATEGORY_INIT(webkit_gst_video_frame_converter_debug, "webkitvideoframeconverter", 0, "WebKit GStreamer Video Frame Converter"); m_pipeline = gst_element_factory_make("pipeline", "video-frame-converter"); - m_src = makeGStreamerElement("appsrc", nullptr); - auto gldownload = makeGStreamerElement("gldownload", nullptr); - auto videoconvert = makeGStreamerElement("videoconvert", nullptr); - auto videoscale = makeGStreamerElement("videoscale", nullptr); - m_sink = makeGStreamerElement("appsink", nullptr); + m_src = makeGStreamerElement("appsrc"_s); + auto gldownload = makeGStreamerElement("gldownload"_s); + auto videoconvert = makeGStreamerElement("videoconvert"_s); + auto videoscale = makeGStreamerElement("videoscale"_s); + m_sink = makeGStreamerElement("appsink"_s); g_object_set(m_sink.get(), "enable-last-sample", FALSE, "max-buffers", 1, nullptr); gst_bin_add_many(GST_BIN_CAST(m_pipeline.get()), m_src.get(), gldownload, videoconvert, videoscale, m_sink.get(), nullptr); diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp index b5dd44ab736df..ea2b2cc5ac8bc 100644 --- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp @@ -3314,14 +3314,14 @@ void MediaPlayerPrivateGStreamer::createGSTPlayBin(const URL& url) return; GST_INFO("Creating pipeline for %s player", player->isVideoPlayer() ? "video" : "audio"); - const char* playbinName = "playbin"; + ASCIILiteral playbinName = "playbin"_s; // MSE and Mediastream require playbin3. Regular playback can use playbin3 on-demand with the // WEBKIT_GST_USE_PLAYBIN3 environment variable. const char* usePlaybin3 = g_getenv("WEBKIT_GST_USE_PLAYBIN3"); bool isMediaStream = url.protocolIs("mediastream"_s); if (isMediaSource() || isMediaStream || (usePlaybin3 && !strcmp(usePlaybin3, "1"))) - playbinName = "playbin3"; + playbinName = "playbin3"_s; ASSERT(!m_pipeline); @@ -3331,13 +3331,13 @@ void MediaPlayerPrivateGStreamer::createGSTPlayBin(const URL& url) auto type = isMediaSource() ? "MSE-"_s : isMediaStream ? "mediastream-"_s : ""_s; - m_isLegacyPlaybin = !g_strcmp0(playbinName, "playbin"); + m_isLegacyPlaybin = playbinName == "playbin"_s; static Atomic pipelineId; - m_pipeline = makeGStreamerElement(playbinName, makeString(type, elementId, '-', pipelineId.exchangeAdd(1)).ascii().data()); + m_pipeline = makeGStreamerElement(playbinName, makeString(type, elementId, '-', pipelineId.exchangeAdd(1))); if (!m_pipeline) { - GST_WARNING("%s not found, make sure to install gst-plugins-base", playbinName); + GST_WARNING("%s not found, make sure to install gst-plugins-base", playbinName.characters()); loadingFailed(MediaPlayer::NetworkState::FormatError, MediaPlayer::ReadyState::HaveNothing, true); return; } @@ -3425,7 +3425,7 @@ void MediaPlayerPrivateGStreamer::createGSTPlayBin(const URL& url) g_object_set(m_pipeline.get(), "audio-sink", m_audioSink.get(), "video-sink", createVideoSink(), nullptr); if (m_shouldPreservePitch && !isMediaStream && !GStreamerQuirksManager::singleton().needsCustomInstantRateChange()) { - if (auto* scale = makeGStreamerElement("scaletempo", nullptr)) + if (auto* scale = makeGStreamerElement("scaletempo"_s)) g_object_set(m_pipeline.get(), "audio-filter", scale, nullptr); } @@ -4443,7 +4443,7 @@ GstElement* MediaPlayerPrivateGStreamer::createVideoSinkGL() const char* desiredVideoSink = g_getenv("WEBKIT_GST_CUSTOM_VIDEO_SINK"); if (desiredVideoSink) - return makeGStreamerElement(desiredVideoSink, nullptr); + return makeGStreamerElement(ASCIILiteral::fromLiteralUnsafe(desiredVideoSink)); if (!webKitGLVideoSinkProbePlatform()) { g_warning("WebKit wasn't able to find the GL video sink dependencies. Hardware-accelerated zero-copy video rendering can't be enabled without this plugin."); @@ -4559,7 +4559,7 @@ GstElement* MediaPlayerPrivateGStreamer::createVideoSink() RefPtr player = m_player.get(); if (player && !player->isVideoPlayer()) { - m_videoSink = makeGStreamerElement("fakevideosink", nullptr); + m_videoSink = makeGStreamerElement("fakevideosink"_s); if (!m_videoSink) { GST_DEBUG_OBJECT(m_pipeline.get(), "Falling back to fakesink for video rendering"); m_videoSink = gst_element_factory_make("fakesink", nullptr); diff --git a/Source/WebCore/platform/graphics/gstreamer/TextCombinerGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/TextCombinerGStreamer.cpp index 2f31b5b590ee7..7063cb52b60c7 100644 --- a/Source/WebCore/platform/graphics/gstreamer/TextCombinerGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/TextCombinerGStreamer.cpp @@ -68,7 +68,7 @@ void webKitTextCombinerHandleCaps(WebKitTextCombiner* combiner, GstPad* pad, con // Caps are plain text, we want a WebVTT encoder between the ghostpad and the combinerElement. if (!target || gstElementFactoryEquals(targetParent.get(), "webvttenc"_s)) { GST_DEBUG_OBJECT(combiner, "Setting up a WebVTT encoder"); - auto* encoder = makeGStreamerElement("webvttenc", nullptr); + auto* encoder = makeGStreamerElement("webvttenc"_s); ASSERT(encoder); gst_bin_add(GST_BIN_CAST(combiner), encoder); @@ -95,9 +95,9 @@ void webKitTextCombinerHandleCaps(WebKitTextCombiner* combiner, GstPad* pad, con GST_DEBUG_OBJECT(combiner, "Converting CEA-608 closed captions to WebVTT."); auto* encoder = gst_bin_new(nullptr); auto* queue = gst_element_factory_make("queue", nullptr); - auto* converter = makeGStreamerElement("ccconverter", nullptr); + auto* converter = makeGStreamerElement("ccconverter"_s); auto* rawCapsFilter = gst_element_factory_make("capsfilter", nullptr); - auto* webvttEncoder = makeGStreamerElement("cea608tott", nullptr); + auto* webvttEncoder = makeGStreamerElement("cea608tott"_s); auto* vttCapsFilter = gst_element_factory_make("capsfilter", nullptr); auto rawCaps = adoptGRef(gst_caps_new_simple("closedcaption/x-cea-608", "format", G_TYPE_STRING, "raw", nullptr)); diff --git a/Source/WebCore/platform/graphics/gstreamer/TextSinkGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/TextSinkGStreamer.cpp index fa584c2b11c0b..f08e759f16635 100644 --- a/Source/WebCore/platform/graphics/gstreamer/TextSinkGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/TextSinkGStreamer.cpp @@ -80,7 +80,7 @@ static void webkitTextSinkConstructed(GObject* object) auto* sink = WEBKIT_TEXT_SINK(object); auto* priv = sink->priv; - priv->appSink = makeGStreamerElement("appsink", nullptr); + priv->appSink = makeGStreamerElement("appsink"_s); gst_bin_add(GST_BIN_CAST(sink), priv->appSink.get()); auto pad = adoptGRef(gst_element_get_static_pad(priv->appSink.get(), "sink")); diff --git a/Source/WebCore/platform/graphics/gstreamer/VideoDecoderGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/VideoDecoderGStreamer.cpp index f075daad0f272..840a5a2c02d40 100644 --- a/Source/WebCore/platform/graphics/gstreamer/VideoDecoderGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/VideoDecoderGStreamer.cpp @@ -163,32 +163,32 @@ GStreamerInternalVideoDecoder::GStreamerInternalVideoDecoder(const String& codec configureVideoDecoderForHarnessing(element); auto* factory = gst_element_get_factory(element.get()); - const char* parser = nullptr; + ASCIILiteral parser; if (codecName.startsWith("avc1"_s)) { m_inputCaps = adoptGRef(gst_caps_new_simple("video/x-h264", "stream-format", G_TYPE_STRING, "avc", "alignment", G_TYPE_STRING, "au", nullptr)); if (auto codecData = wrapSpanData(config.description)) gst_caps_set_simple(m_inputCaps.get(), "codec_data", GST_TYPE_BUFFER, codecData.get(), nullptr); if (!gst_element_factory_can_sink_all_caps(factory, m_inputCaps.get())) - parser = "h264parse"; + parser = "h264parse"_s; } else if (codecName.startsWith("av01"_s)) m_inputCaps = adoptGRef(gst_caps_new_simple("video/x-av1", "stream-format", G_TYPE_STRING, "obu-stream", "alignment", G_TYPE_STRING, "frame", nullptr)); else if (codecName.startsWith("vp8"_s)) m_inputCaps = adoptGRef(gst_caps_new_empty_simple("video/x-vp8")); else if (codecName.startsWith("vp09"_s)) { m_inputCaps = adoptGRef(gst_caps_new_empty_simple("video/x-vp9")); - parser = "vp9parse"; + parser = "vp9parse"_s; } else if (codecName.startsWith("hvc1"_s)) { m_inputCaps = adoptGRef(gst_caps_new_simple("video/x-h265", "stream-format", G_TYPE_STRING, "hvc1", "alignment", G_TYPE_STRING, "au", nullptr)); if (auto codecData = wrapSpanData(config.description)) gst_caps_set_simple(m_inputCaps.get(), "codec_data", GST_TYPE_BUFFER, codecData.get(), nullptr); if (!gst_element_factory_can_sink_all_caps(factory, m_inputCaps.get())) - parser = "h265parse"; + parser = "h265parse"_s; } else if (codecName.startsWith("hev1"_s)) { m_inputCaps = adoptGRef(gst_caps_new_simple("video/x-h265", "stream-format", G_TYPE_STRING, "hev1", "alignment", G_TYPE_STRING, "au", nullptr)); if (auto codecData = wrapSpanData(config.description)) gst_caps_set_simple(m_inputCaps.get(), "codec_data", GST_TYPE_BUFFER, codecData.get(), nullptr); if (!gst_element_factory_can_sink_all_caps(factory, m_inputCaps.get())) - parser = "h265parse"; + parser = "h265parse"_s; } else { WTFLogAlways("Codec %s not wired in yet", codecName.ascii().data()); return; @@ -198,11 +198,11 @@ GStreamerInternalVideoDecoder::GStreamerInternalVideoDecoder(const String& codec gst_caps_set_simple(m_inputCaps.get(), "width", G_TYPE_INT, config.width, "height", G_TYPE_INT, config.height, nullptr); GRefPtr harnessedElement; - if (parser) { + if (!parser.isEmpty()) { // The decoder won't accept the input caps, so put a parser in front. - auto* parserElement = makeGStreamerElement(parser, nullptr); + auto* parserElement = makeGStreamerElement(parser); if (!parserElement) { - GST_WARNING_OBJECT(element.get(), "Required parser %s not found, decoding will fail", parser); + GST_WARNING_OBJECT(element.get(), "Required parser %s not found, decoding will fail", parser.characters()); m_inputCaps.clear(); return; } diff --git a/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp index a0b7225f548d5..5dba7107b6572 100644 --- a/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp @@ -60,7 +60,7 @@ static bool webKitAudioSinkConfigure(WebKitAudioSink* sink) return false; } - sink->priv->interAudioSink = makeGStreamerElement("interaudiosink", nullptr); + sink->priv->interAudioSink = makeGStreamerElement("interaudiosink"_s); RELEASE_ASSERT(sink->priv->interAudioSink); gst_bin_add(GST_BIN_CAST(sink), sink->priv->interAudioSink.get()); diff --git a/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp b/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp index cdbd76814e424..9d18463536dd6 100644 --- a/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp @@ -185,7 +185,7 @@ AppendPipeline::AppendPipeline(SourceBufferPrivateGStreamer& sourceBufferPrivate // We assign the created instances here instead of adoptRef() because gst_bin_add_many() // below will already take the initial reference and we need an additional one for us. - m_appsrc = makeGStreamerElement("appsrc", nullptr); + m_appsrc = makeGStreamerElement("appsrc"_s); GRefPtr appsrcPad = adoptGRef(gst_element_get_static_pad(m_appsrc.get(), "src")); gst_pad_add_probe(appsrcPad.get(), GST_PAD_PROBE_TYPE_BUFFER, [](GstPad*, GstPadProbeInfo* padProbeInfo, void* userData) { @@ -196,17 +196,17 @@ AppendPipeline::AppendPipeline(SourceBufferPrivateGStreamer& sourceBufferPrivate GST_DEBUG_OBJECT(pipeline(), "SourceBuffer containerType: %s", type.utf8().data()); if (type.endsWith("mp4"_s) || type.endsWith("aac"_s)) { - m_demux = makeGStreamerElement("qtdemux", nullptr); - m_typefind = makeGStreamerElement("identity", nullptr); + m_demux = makeGStreamerElement("qtdemux"_s); + m_typefind = makeGStreamerElement("identity"_s); GRefPtr caps = adoptGRef(gst_caps_new_simple("video/quicktime", "variant", G_TYPE_STRING, "mse-bytestream", NULL)); gst_app_src_set_caps(GST_APP_SRC(m_appsrc.get()), caps.get()); } else if (type.endsWith("webm"_s)) { - m_demux = makeGStreamerElement("matroskademux", nullptr); - m_typefind = makeGStreamerElement("identity", nullptr); + m_demux = makeGStreamerElement("matroskademux"_s); + m_typefind = makeGStreamerElement("identity"_s); } else if (type == "audio/mpeg"_s) { // Will be instantiated later based on typefind results. m_demux = nullptr; - m_typefind = makeGStreamerElement("typefind", nullptr); + m_typefind = makeGStreamerElement("typefind"_s); g_signal_connect(m_typefind.get(), "have-type", G_CALLBACK(+[]( GstElement* typefind, guint, GstCaps* caps, AppendPipeline* appendPipeline) { @@ -232,7 +232,7 @@ AppendPipeline::AppendPipeline(SourceBufferPrivateGStreamer& sourceBufferPrivate GST_DEBUG_OBJECT(appendPipeline->pipeline(), "Creating %s demuxer for caps: %s", demuxerElementName.characters(), gstStructureGetName(capsStructure).toStringWithoutCopying().utf8().data()); - appendPipeline->m_demux = makeGStreamerElement(demuxerElementName.characters(), nullptr); + appendPipeline->m_demux = makeGStreamerElement(demuxerElementName); ASSERT(appendPipeline->m_demux); appendPipeline->configureOptionalDemuxerFromAnyThread(); @@ -846,7 +846,7 @@ GRefPtr createOptionalParserForFormat([[maybe_unused]] GstBin* bin, // Since parsers are not needed in every case, we can use an identity element as pass-through // parser for cases where a parser is not needed, making the management of elements and pads // more orthogonal. - const char* elementClass = "identity"; + ASCIILiteral elementClass = "identity"_s; if (mediaType == "audio/x-opus"_s) { // Necessary for: metadata filling. @@ -855,7 +855,7 @@ GRefPtr createOptionalParserForFormat([[maybe_unused]] GstBin* bin, // during quality changes. // An example of an Opus audio file lacking durations is car_opus_low.webm // https://storage.googleapis.com/ytlr-cert.appspot.com/test/materials/media/car_opus_low.webm - elementClass = "opusparse"; + elementClass = "opusparse"_s; } else if (mediaType == "video/x-h264"_s) { // Necessary for: metadata filling. // Some dubiously muxed content lacks the bit specifying what frames are key frames or not. @@ -863,7 +863,7 @@ GRefPtr createOptionalParserForFormat([[maybe_unused]] GstBin* bin, // as the browser will be unaware of any dependencies of those frames and they won't be fed // to the decoder. // An example of such a stream: http://orange-opensource.github.io/hasplayer.js/1.2.0/player.html?url=http://playready.directtaps.net/smoothstreaming/SSWSS720H264/SuperSpeedway_720.ism/Manifest - elementClass = "h264parse"; + elementClass = "h264parse"_s; } else if (mediaType == "audio/mpeg"_s) { // Necessary for: framing. // The Media Source Extensions Byte Stream Format Registry includes MPEG Audio Byte Stream Format @@ -876,7 +876,7 @@ GRefPtr createOptionalParserForFormat([[maybe_unused]] GstBin* bin, // MPEG-1 Part 3 Audio (ISO 11172-3) Layer I -- MP1, archaic // MPEG-1 Part 3 Audio (ISO 11172-3) Layer II -- MP2, common in audio broadcasting, e.g. DVB // MPEG-1 Part 3 Audio (ISO 11172-3) Layer III -- MP3, the only one of the three most people actually know - elementClass = "mpegaudioparse"; + elementClass = "mpegaudioparse"_s; break; case 2: // MPEG-2 Part 7 Advanced Audio Coding (ISO 13818-7) -- MPEG-2 AAC, the original AAC format, widely used, @@ -886,7 +886,7 @@ GRefPtr createOptionalParserForFormat([[maybe_unused]] GstBin* bin, // defines several extensions to the original AAC, also widely used. // Not to be confused with the MP4 file format, which is a container format, not an audio stream format, // and can incidentally contain MPEG-4 audio. - elementClass = "aacparse"; + elementClass = "aacparse"_s; break; default: GST_WARNING_OBJECT(bin, "Unsupported audio mpeg caps: %" GST_PTR_FORMAT, caps); @@ -894,15 +894,15 @@ GRefPtr createOptionalParserForFormat([[maybe_unused]] GstBin* bin, } else if (mediaType == "video/x-vp9"_s) { // Necessary for: metadata filling. // Without this parser the codec string set on the corresponding video track will be incomplete. - elementClass = "vp9parse"; + elementClass = "vp9parse"_s; } - GST_DEBUG_OBJECT(bin, "Creating %s parser for stream with caps %" GST_PTR_FORMAT, elementClass, caps); - GRefPtr result(makeGStreamerElement(elementClass, parserName.ascii().data())); - if (!result && g_strcmp0(elementClass, "identity")) { + GST_DEBUG_OBJECT(bin, "Creating %s parser for stream with caps %" GST_PTR_FORMAT, elementClass.characters(), caps); + GRefPtr result(makeGStreamerElement(elementClass, parserName)); + if (!result && elementClass != "identity"_s) { GST_WARNING_OBJECT(bin, "Couldn't create %s, there might be problems processing some MSE streams. " - "Continue at your own risk and consider adding %s to your build.", elementClass, elementClass); - result = makeGStreamerElement("identity", parserName.ascii().data()); + "Continue at your own risk and consider adding %s to your build.", elementClass.characters(), elementClass.characters()); + result = makeGStreamerElement("identity"_s, parserName); } return result; } @@ -1095,7 +1095,7 @@ void AppendPipeline::Track::emplaceOptionalParserForFormat(GstBin* bin, const GR void AppendPipeline::Track::initializeElements(AppendPipeline* appendPipeline, GstBin* bin) { - appsink = makeGStreamerElement("appsink", nullptr); + appsink = makeGStreamerElement("appsink"_s); gst_app_sink_set_emit_signals(GST_APP_SINK(appsink.get()), TRUE); gst_base_sink_set_sync(GST_BASE_SINK(appsink.get()), FALSE); gst_base_sink_set_async_enabled(GST_BASE_SINK(appsink.get()), FALSE); // No prerolls, no async state changes. diff --git a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkFake.h b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkFake.h index bae3da0a8b094..ee44d52a806be 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkFake.h +++ b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkFake.h @@ -30,7 +30,7 @@ namespace WebCore { class GStreamerHolePunchQuirkFake final : public GStreamerHolePunchQuirk { public: const ASCIILiteral identifier() const final { return "FakeHolePunch"_s; } - GstElement* createHolePunchVideoSink(bool, const MediaPlayer*) final { return makeGStreamerElement("fakevideosink", nullptr); } + GstElement* createHolePunchVideoSink(bool, const MediaPlayer*) final { return makeGStreamerElement("fakevideosink"_s); } bool setHolePunchVideoRectangle(GstElement*, const IntRect&) final { return true; } }; diff --git a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkRialto.cpp b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkRialto.cpp index 903f5bf85acf3..0799b64be8ca5 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkRialto.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkRialto.cpp @@ -42,7 +42,7 @@ GstElement* GStreamerHolePunchQuirkRialto::createHolePunchVideoSink(bool isLegac return nullptr; // Rialto using holepunch. - GstElement* videoSink = makeGStreamerElement("rialtomsevideosink", nullptr); + GstElement* videoSink = makeGStreamerElement("rialtomsevideosink"_s); if (isPIPRequested) g_object_set(G_OBJECT(videoSink), "maxVideoWidth", 640, "maxVideoHeight", 480, "has-drm", FALSE, nullptr); return videoSink; diff --git a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkWesteros.cpp b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkWesteros.cpp index 4d7a6f4a95d05..4250a2600231b 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkWesteros.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkWesteros.cpp @@ -37,7 +37,7 @@ GstElement* GStreamerHolePunchQuirkWesteros::createHolePunchVideoSink(bool isLeg return nullptr; // Westeros using holepunch. - GstElement* videoSink = makeGStreamerElement("westerossink", "WesterosVideoSink"); + GstElement* videoSink = makeGStreamerElement("westerossink"_s, "WesterosVideoSink"_s); g_object_set(videoSink, "zorder", 0.0f, nullptr); if (isPIPRequested) { g_object_set(videoSink, "res-usage", 0u, nullptr); diff --git a/Source/WebCore/platform/gstreamer/GStreamerQuirkAmLogic.cpp b/Source/WebCore/platform/gstreamer/GStreamerQuirkAmLogic.cpp index 9f9d25e18a6a1..4bc22c8ad199b 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerQuirkAmLogic.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerQuirkAmLogic.cpp @@ -48,7 +48,7 @@ GstElement* GStreamerQuirkAmLogic::createWebAudioSink() // that causes resource acquisition in some cases interrupting any playback already running. // On Amlogic we need to set direct-mode=false prop before changing state to READY // but this is not possible with autoaudiosink. - auto sink = makeGStreamerElement("amlhalasink", nullptr); + auto sink = makeGStreamerElement("amlhalasink"_s); RELEASE_ASSERT_WITH_MESSAGE(sink, "amlhalasink should be available in the system but it is not"); g_object_set(sink, "direct-mode", FALSE, nullptr); return sink; diff --git a/Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.cpp b/Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.cpp index 4f0d34a59a845..07a44c381b0d2 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.cpp @@ -55,7 +55,7 @@ bool GStreamerQuirkRealtek::isPlatformSupported() const GstElement* GStreamerQuirkRealtek::createWebAudioSink() { - auto sink = makeGStreamerElement("rtkaudiosink", nullptr); + auto sink = makeGStreamerElement("rtkaudiosink"_s); RELEASE_ASSERT_WITH_MESSAGE(sink, "rtkaudiosink should be available in the system but it is not"); g_object_set(sink, "media-tunnel", FALSE, "audio-service", TRUE, nullptr); return sink; diff --git a/Source/WebCore/platform/gstreamer/GStreamerQuirkRialto.cpp b/Source/WebCore/platform/gstreamer/GStreamerQuirkRialto.cpp index 9dea4ed41f27b..853a054b88061 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerQuirkRialto.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerQuirkRialto.cpp @@ -96,7 +96,7 @@ void GStreamerQuirkRialto::configureElement(GstElement* element, const OptionSet GstElement* GStreamerQuirkRialto::createAudioSink() { - auto sink = makeGStreamerElement("rialtomseaudiosink", nullptr); + auto sink = makeGStreamerElement("rialtomseaudiosink"_s); RELEASE_ASSERT_WITH_MESSAGE(sink, "rialtomseaudiosink should be available in the system but it is not"); return sink; } @@ -106,7 +106,7 @@ GstElement* GStreamerQuirkRialto::createWebAudioSink() if (GstElement* sink = webkitAudioSinkNew()) return sink; - auto sink = makeGStreamerElement("rialtowebaudiosink", nullptr); + auto sink = makeGStreamerElement("rialtowebaudiosink"_s); RELEASE_ASSERT_WITH_MESSAGE(sink, "rialtowebaudiosink should be available in the system but it is not"); return sink; } diff --git a/Source/WebCore/platform/gstreamer/PlatformSpeechSynthesizerGStreamer.cpp b/Source/WebCore/platform/gstreamer/PlatformSpeechSynthesizerGStreamer.cpp index 871cb7ee8684d..42ab137b0efeb 100644 --- a/Source/WebCore/platform/gstreamer/PlatformSpeechSynthesizerGStreamer.cpp +++ b/Source/WebCore/platform/gstreamer/PlatformSpeechSynthesizerGStreamer.cpp @@ -99,13 +99,13 @@ GstSpeechSynthesisWrapper::GstSpeechSynthesisWrapper(const PlatformSpeechSynthes } } - m_volumeElement = makeGStreamerElement("volume", nullptr); - m_pitchElement = makeGStreamerElement("pitch", nullptr); + m_volumeElement = makeGStreamerElement("volume"_s); + m_pitchElement = makeGStreamerElement("pitch"_s); if (!m_pitchElement) WTFLogAlways("The pitch GStreamer plugin is unavailable. The pitch property of Speech Synthesis is ignored."); - GRefPtr audioConvert = makeGStreamerElement("audioconvert", nullptr); - GRefPtr audioResample = makeGStreamerElement("audioresample", nullptr); + GRefPtr audioConvert = makeGStreamerElement("audioconvert"_s); + GRefPtr audioResample = makeGStreamerElement("audioresample"_s); if (m_pitchElement) gst_bin_add_many(GST_BIN_CAST(m_pipeline.get()), m_src.get(), m_volumeElement.get(), audioConvert.get(), audioResample.get(), m_pitchElement.get(), audioSink.get(), nullptr); else diff --git a/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp b/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp index a785d1eec9379..6fdb7402b7809 100644 --- a/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp +++ b/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp @@ -351,7 +351,7 @@ static bool videoEncoderSetEncoder(WebKitVideoEncoder* self, EncoderId encoderId if (useVideoConvertScale) { if (!priv->videoConvert) { - priv->videoConvert = makeGStreamerElement("videoconvertscale", nullptr); + priv->videoConvert = makeGStreamerElement("videoconvertscale"_s); gst_bin_add(GST_BIN_CAST(self), priv->videoConvert.get()); auto sinkPadTarget = adoptGRef(gst_element_get_static_pad(priv->videoConvert.get(), "sink")); @@ -364,12 +364,12 @@ static bool videoEncoderSetEncoder(WebKitVideoEncoder* self, EncoderId encoderId } } else { if (!priv->videoScale) { - priv->videoScale = makeGStreamerElement("videoscale", nullptr); + priv->videoScale = makeGStreamerElement("videoscale"_s); gst_bin_add(GST_BIN_CAST(self), priv->videoScale.get()); } if (!priv->videoConvert) { - priv->videoConvert = makeGStreamerElement("videoconvert", nullptr); + priv->videoConvert = makeGStreamerElement("videoconvert"_s); gst_bin_add(GST_BIN_CAST(self), priv->videoConvert.get()); auto sinkPadTarget = adoptGRef(gst_element_get_static_pad(priv->videoConvert.get(), "sink")); @@ -383,7 +383,7 @@ static bool videoEncoderSetEncoder(WebKitVideoEncoder* self, EncoderId encoderId } if (encoderDefinition->parserName) { - priv->parser = makeGStreamerElement(encoderDefinition->parserName, nullptr); + priv->parser = makeGStreamerElement(encoderDefinition->parserName); if (!priv->outputCapsFilter) { priv->outputCapsFilter = gst_element_factory_make("capsfilter", nullptr); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCapturer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCapturer.cpp index 7e94080f40384..e4be65f150ef2 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCapturer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioCapturer.cpp @@ -47,7 +47,7 @@ GStreamerAudioCapturer::GStreamerAudioCapturer(GStreamerCaptureDevice&& device) } GStreamerAudioCapturer::GStreamerAudioCapturer() - : GStreamerCapturer("appsrc", adoptGRef(gst_caps_new_empty_simple("audio/x-raw")), CaptureDevice::DeviceType::Microphone) + : GStreamerCapturer("appsrc"_s, adoptGRef(gst_caps_new_empty_simple("audio/x-raw")), CaptureDevice::DeviceType::Microphone) { initializeAudioCapturerDebugCategory(); } @@ -69,15 +69,15 @@ void GStreamerAudioCapturer::setSinkAudioCallback(SinkAudioDataCallback&& callba GstElement* GStreamerAudioCapturer::createConverter() { auto* bin = gst_bin_new(nullptr); - auto* audioconvert = makeGStreamerElement("audioconvert", nullptr); - auto* audioresample = makeGStreamerElement("audioresample", nullptr); + auto* audioconvert = makeGStreamerElement("audioconvert"_s); + auto* audioresample = makeGStreamerElement("audioresample"_s); gst_bin_add_many(GST_BIN_CAST(bin), audioconvert, audioresample, nullptr); gst_element_link(audioconvert, audioresample); #if USE(GSTREAMER_WEBRTC) - if (auto audioFilter = makeGStreamerElement("audiornnoise", nullptr)) { - auto audioconvert2 = makeGStreamerElement("audioconvert", nullptr); - auto audioresample2 = makeGStreamerElement("audioresample", nullptr); + if (auto audioFilter = makeGStreamerElement("audiornnoise"_s)) { + auto audioconvert2 = makeGStreamerElement("audioconvert"_s); + auto audioresample2 = makeGStreamerElement("audioresample"_s); gst_bin_add_many(GST_BIN_CAST(bin), audioconvert2, audioresample2, audioFilter, nullptr); gst_element_link_many(audioconvert2, audioresample2, audioFilter, audioconvert, nullptr); } diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp index 8e22e5bb38047..8150486cc837f 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp @@ -67,7 +67,7 @@ RefPtr GStreamerAudioRTPPacketizer::create(RefPtr encoder; if (encoding == "opus"_s) { - encoder = makeGStreamerElement("opusenc", nullptr); + encoder = makeGStreamerElement("opusenc"_s); if (!encoder) return nullptr; @@ -96,11 +96,11 @@ RefPtr GStreamerAudioRTPPacketizer::create(RefPtr&& inpu g_object_set(m_capsFilter.get(), "caps", rtpCaps.get(), nullptr); GST_DEBUG_OBJECT(m_bin.get(), "RTP caps: %" GST_PTR_FORMAT, rtpCaps.get()); - m_audioconvert = makeGStreamerElement("audioconvert", nullptr); - m_audioresample = makeGStreamerElement("audioresample", nullptr); + m_audioconvert = makeGStreamerElement("audioconvert"_s); + m_audioresample = makeGStreamerElement("audioresample"_s); m_inputCapsFilter = gst_element_factory_make("capsfilter", nullptr); g_object_set(m_inputCapsFilter.get(), "caps", inputCaps.get(), nullptr); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp index 5bd77a1278f61..6329827cbe45e 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp @@ -59,7 +59,7 @@ GStreamerCapturer::GStreamerCapturer(GStreamerCaptureDevice&& device, GRefPtr&& caps, CaptureDevice::DeviceType deviceType) +GStreamerCapturer::GStreamerCapturer(ASCIILiteral sourceFactory, GRefPtr&& caps, CaptureDevice::DeviceType deviceType) : m_caps(WTFMove(caps)) , m_sourceFactory(sourceFactory) , m_deviceType(deviceType) @@ -195,7 +195,7 @@ void GStreamerCapturer::setupPipeline() disconnectSimpleBusMessageCallback(pipeline()); } - m_pipeline = makeElement("pipeline"); + m_pipeline = makeElement("pipeline"_s); auto clock = adoptGRef(gst_system_clock_obtain()); gst_pipeline_use_clock(GST_PIPELINE(m_pipeline.get()), clock.get()); gst_element_set_base_time(m_pipeline.get(), 0); @@ -207,10 +207,10 @@ void GStreamerCapturer::setupPipeline() GRefPtr source = createSource(); GRefPtr converter = createConverter(); - m_valve = makeElement("valve"); - m_capsfilter = makeElement("capsfilter"); + m_valve = makeElement("valve"_s); + m_capsfilter = makeElement("capsfilter"_s); auto queue = gst_element_factory_make("queue", nullptr); - m_sink = makeElement("appsink"); + m_sink = makeElement("appsink"_s); gst_util_set_object_arg(G_OBJECT(m_capsfilter.get()), "caps-change-mode", "delayed"); @@ -228,9 +228,9 @@ void GStreamerCapturer::setupPipeline() gst_element_link_many(tail, m_capsfilter.get(), m_valve.get(), queue, m_sink.get(), nullptr); } -GstElement* GStreamerCapturer::makeElement(const char* factoryName) +GstElement* GStreamerCapturer::makeElement(ASCIILiteral factoryName) { - auto* element = makeGStreamerElement(factoryName, nullptr); + auto* element = makeGStreamerElement(factoryName); auto elementName = makeString(span(name()), "_capturer_"_s, span(GST_OBJECT_NAME(element)), '_', hex(reinterpret_cast(this))); gst_object_set_name(GST_OBJECT(element), elementName.ascii().data()); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.h b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.h index 241d3bf1d2ba0..b28e5717bc882 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.h +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.h @@ -52,7 +52,7 @@ class GStreamerCapturerObserver : public CanMakeWeakPtr { public: GStreamerCapturer(GStreamerCaptureDevice&&, GRefPtr&&); - GStreamerCapturer(const char* sourceFactory, GRefPtr&&, CaptureDevice::DeviceType); + GStreamerCapturer(ASCIILiteral sourceFactory, GRefPtr&&, CaptureDevice::DeviceType); virtual ~GStreamerCapturer(); virtual void tearDown(bool disconnectSignals); @@ -69,7 +69,7 @@ class GStreamerCapturer : public ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr std::pair queryLatency(); - GstElement* makeElement(const char* factoryName); + GstElement* makeElement(ASCIILiteral factoryName); virtual GstElement* createSource(); GstElement* source() { return m_src.get(); } virtual const char* name() = 0; @@ -95,7 +95,7 @@ class GStreamerCapturer : public ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr std::optional m_device { }; GRefPtr m_caps; GRefPtr m_pipeline; - const char* m_sourceFactory; + ASCIILiteral m_sourceFactory; private: CaptureDevice::DeviceType m_deviceType; diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp index 4e9dbfd93094d..f01eeeaad2d59 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp @@ -199,7 +199,7 @@ GRefPtr GStreamerIncomingTrackProcessor::incomingTrackProcessor() } GST_DEBUG_OBJECT(m_bin.get(), "Preparing video decoder for depayloaded RTP packets"); - GRefPtr decodebin = makeGStreamerElement("decodebin3", nullptr); + GRefPtr decodebin = makeGStreamerElement("decodebin3"_s); m_isDecoding = true; g_signal_connect(decodebin.get(), "deep-element-added", G_CALLBACK(+[](GstBin*, GstBin*, GstElement* element, gpointer userData) { @@ -250,7 +250,7 @@ GRefPtr GStreamerIncomingTrackProcessor::incomingTrackProcessor() GRefPtr GStreamerIncomingTrackProcessor::createParser() { - GRefPtr parsebin = makeGStreamerElement("parsebin", nullptr); + GRefPtr parsebin = makeGStreamerElement("parsebin"_s); g_signal_connect(parsebin.get(), "element-added", G_CALLBACK(+[](GstBin*, GstElement* element, gpointer userData) { String elementClass = WTF::span(gst_element_get_metadata(element, GST_ELEMENT_METADATA_KLASS)); auto classifiers = elementClass.split('/'); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp index f31f53464c5e2..7957a4580d0e0 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp @@ -162,7 +162,7 @@ class InternalSource final : public MediaStreamTrackPrivateObserver, } bool isCaptureTrack = track.isCaptureTrack(); - m_src = makeGStreamerElement("appsrc", elementName.ascii().data()); + m_src = makeGStreamerElement("appsrc"_s, elementName); g_object_set(m_src.get(), "is-live", TRUE, "format", GST_FORMAT_TIME, "emit-signals", TRUE, "min-percent", 100, "do-timestamp", isCaptureTrack, "handle-segment-change", TRUE, nullptr); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerMockDevice.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerMockDevice.cpp index 7d84047d125d8..e8e024e68c5f9 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerMockDevice.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerMockDevice.cpp @@ -41,7 +41,7 @@ WEBKIT_DEFINE_TYPE_WITH_CODE(GStreamerMockDevice, webkit_mock_device, GST_TYPE_D static GstElement* webkitMockDeviceCreateElement([[maybe_unused]] GstDevice* device, const char* name) { GST_INFO_OBJECT(device, "Creating source element for device %s", name); - auto* element = makeGStreamerElement("appsrc", name); + auto* element = makeGStreamerElement("appsrc"_s, String::fromLatin1(name)); g_object_set(element, "format", GST_FORMAT_TIME, "is-live", TRUE, "do-timestamp", TRUE, nullptr); return element; } diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp index d6e42711bef70..4e935ef5c01ae 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp @@ -85,7 +85,7 @@ CaptureSourceOrError GStreamerVideoCaptureSource::create(String&& deviceID, Medi CaptureSourceOrError GStreamerVideoCaptureSource::createPipewireSource(String&& deviceID, const NodeAndFD& nodeAndFd, MediaDeviceHashSalts&& hashSalts, const MediaConstraints* constraints, CaptureDevice::DeviceType deviceType) { - auto source = adoptRef(*new GStreamerVideoCaptureSource(WTFMove(deviceID), { }, WTFMove(hashSalts), "pipewiresrc", deviceType, nodeAndFd)); + auto source = adoptRef(*new GStreamerVideoCaptureSource(WTFMove(deviceID), { }, WTFMove(hashSalts), "pipewiresrc"_s, deviceType, nodeAndFd)); if (constraints) { if (auto result = source->applyConstraints(*constraints)) return CaptureSourceOrError(CaptureSourceError { result->invalidConstraint }); @@ -105,7 +105,7 @@ DisplayCaptureFactory& GStreamerVideoCaptureSource::displayFactory() return factory.get(); } -GStreamerVideoCaptureSource::GStreamerVideoCaptureSource(String&& deviceID, AtomString&& name, MediaDeviceHashSalts&& hashSalts, const gchar* sourceFactory, CaptureDevice::DeviceType deviceType, const NodeAndFD& nodeAndFd) +GStreamerVideoCaptureSource::GStreamerVideoCaptureSource(String&& deviceID, AtomString&& name, MediaDeviceHashSalts&& hashSalts, ASCIILiteral sourceFactory, CaptureDevice::DeviceType deviceType, const NodeAndFD& nodeAndFd) : RealtimeVideoCaptureSource(CaptureDevice { WTFMove(deviceID), CaptureDevice::DeviceType::Camera, WTFMove(name) }, WTFMove(hashSalts), { }) , m_capturer(adoptRef(*new GStreamerVideoCapturer(sourceFactory, deviceType))) , m_deviceType(deviceType) diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.h b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.h index 35e5bec76d465..ddbb1cc806645 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.h +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCaptureSource.h @@ -53,7 +53,7 @@ class GStreamerVideoCaptureSource : public RealtimeVideoCaptureSource, GStreamer std::pair queryCaptureLatency() const final; protected: - GStreamerVideoCaptureSource(String&& deviceID, AtomString&& name, MediaDeviceHashSalts&&, const gchar* source_factory, CaptureDevice::DeviceType, const NodeAndFD&); + GStreamerVideoCaptureSource(String&& deviceID, AtomString&& name, MediaDeviceHashSalts&&, ASCIILiteral sourceFactory, CaptureDevice::DeviceType, const NodeAndFD&); GStreamerVideoCaptureSource(GStreamerCaptureDevice&&, MediaDeviceHashSalts&&); virtual ~GStreamerVideoCaptureSource(); void startProducingData() override; diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp index fb4e7d5685e0b..bcac3c260edfb 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp @@ -49,7 +49,7 @@ GStreamerVideoCapturer::GStreamerVideoCapturer(GStreamerCaptureDevice&& device) initializeVideoCapturerDebugCategory(); } -GStreamerVideoCapturer::GStreamerVideoCapturer(const char* sourceFactory, CaptureDevice::DeviceType deviceType) +GStreamerVideoCapturer::GStreamerVideoCapturer(ASCIILiteral sourceFactory, CaptureDevice::DeviceType deviceType) : GStreamerCapturer(sourceFactory, adoptGRef(gst_caps_new_empty_simple("video/x-raw")), deviceType) { initializeVideoCapturerDebugCategory(); @@ -107,9 +107,9 @@ GstElement* GStreamerVideoCapturer::createConverter() } auto* bin = gst_bin_new(nullptr); - auto* videoscale = makeGStreamerElement("videoscale", "videoscale"); - auto* videoconvert = makeGStreamerElement("videoconvert", nullptr); - auto* videorate = makeGStreamerElement("videorate", "videorate"); + auto* videoscale = makeGStreamerElement("videoscale"_s, "videoscale"_s); + auto* videoconvert = makeGStreamerElement("videoconvert"_s); + auto* videorate = makeGStreamerElement("videorate"_s, "videorate"_s); // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/97#note_56575 g_object_set(videorate, "drop-only", TRUE, "average-period", UINT64_C(1), nullptr); @@ -121,7 +121,7 @@ GstElement* GStreamerVideoCapturer::createConverter() auto caps = adoptGRef(gst_caps_new_empty_simple("video/x-raw")); g_object_set(m_videoSrcMIMETypeFilter.get(), "caps", caps.get(), nullptr); - auto* decodebin = makeGStreamerElement("decodebin3", nullptr); + auto* decodebin = makeGStreamerElement("decodebin3"_s); gst_bin_add_many(GST_BIN_CAST(bin), m_videoSrcMIMETypeFilter.get(), decodebin, nullptr); gst_element_link(m_videoSrcMIMETypeFilter.get(), decodebin); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.h b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.h index 8f3f50d962d2c..23cf2868890d3 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.h +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.h @@ -35,7 +35,7 @@ class GStreamerVideoCapturer final : public GStreamerCapturer { friend class MockRealtimeVideoSourceGStreamer; public: GStreamerVideoCapturer(GStreamerCaptureDevice&&); - GStreamerVideoCapturer(const char* sourceFactory, CaptureDevice::DeviceType); + GStreamerVideoCapturer(ASCIILiteral sourceFactory, CaptureDevice::DeviceType); ~GStreamerVideoCapturer() = default; diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp index 896988d99bf4a..7cab1b9193e8a 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp @@ -151,10 +151,10 @@ GStreamerVideoRTPPacketizer::GStreamerVideoRTPPacketizer(GRefPtr&& e GST_DEBUG_OBJECT(m_bin.get(), "RTP encoding parameters: %" GST_PTR_FORMAT, m_encodingParameters.get()); - m_videoRate = makeGStreamerElement("videorate", nullptr); + m_videoRate = makeGStreamerElement("videorate"_s); // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/97#note_56575 g_object_set(m_videoRate.get(), "skip-to-first", TRUE, "drop-only", TRUE, "average-period", UINT64_C(1), nullptr); - m_frameRateCapsFilter = makeGStreamerElement("capsfilter", nullptr); + m_frameRateCapsFilter = makeGStreamerElement("capsfilter"_s); gst_bin_add_many(GST_BIN_CAST(m_bin.get()), m_videoRate.get(), m_frameRateCapsFilter.get(), nullptr); auto lastIdentifier = findLastExtensionId(rtpCaps.get()); diff --git a/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingVideoSourceGStreamer.cpp b/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingVideoSourceGStreamer.cpp index 22ab836698b1d..dcc24e2d1418e 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingVideoSourceGStreamer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingVideoSourceGStreamer.cpp @@ -66,12 +66,12 @@ void RealtimeOutgoingVideoSourceGStreamer::initializePreProcessor() m_preProcessor = gst_bin_new(nullptr); - auto videoConvert = makeGStreamerElement("videoconvert", nullptr); + auto videoConvert = makeGStreamerElement("videoconvert"_s); - auto videoFlip = makeGStreamerElement("autovideoflip", nullptr); + auto videoFlip = makeGStreamerElement("autovideoflip"_s); if (!videoFlip) { GST_DEBUG("autovideoflip element not available, falling back to videoflip"); - videoFlip = makeGStreamerElement("videoflip", nullptr); + videoFlip = makeGStreamerElement("videoflip"_s); } gst_util_set_object_arg(G_OBJECT(videoFlip), "video-direction", "auto"); diff --git a/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp b/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp index 3c0f76a17efd5..0a667c7a51068 100644 --- a/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp +++ b/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp @@ -68,11 +68,11 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder { return m_pipeline.get(); } - GstElement* makeElement(const gchar* factoryName) + GstElement* makeElement(ASCIILiteral factoryName) { - GUniquePtr name(g_strdup_printf("%s_dec_%s_%p", Name(), factoryName, this)); - - return makeGStreamerElement(factoryName, name.get()); + static Atomic elementId; + auto name = makeString(span(Name()), "-dec-"_s, factoryName, "-"_s, elementId.exchangeAdd(1)); + return makeGStreamerElement(factoryName, name); } void handleError(GError* error) @@ -85,16 +85,16 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder { bool Configure(const webrtc::VideoDecoder::Settings& codecSettings) override { - m_src = makeElement("appsrc"); + m_src = makeElement("appsrc"_s); g_object_set(m_src, "is-live", TRUE, "do-timestamp", TRUE, "max-buffers", 2, "max-bytes", 0, nullptr); GRefPtr caps = nullptr; auto capsfilter = CreateFilter(); - auto decoder = makeElement("decodebin"); + auto decoder = makeElement("decodebin"_s); updateCapsFromImageSize(codecSettings.max_render_resolution().Width(), codecSettings.max_render_resolution().Height()); - m_pipeline = makeElement("pipeline"); + m_pipeline = makeElement("pipeline"_s); connectSimpleBusMessageCallback(m_pipeline.get()); auto sinkpad = adoptGRef(gst_element_get_static_pad(capsfilter, "sink")); @@ -140,7 +140,7 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder { } g_object_set(decoder, "caps", caps.get(), nullptr); - m_sink = makeElement("appsink"); + m_sink = makeElement("appsink"_s); gst_app_sink_set_emit_signals(GST_APP_SINK(m_sink), true); // This is a decoder, everything should happen as fast as possible and not be synced on the clock. g_object_set(m_sink, "sync", false, nullptr); @@ -173,7 +173,7 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder { virtual GstElement* CreateFilter() { - return makeElement("identity"); + return makeElement("identity"_s); } int32_t Release() final diff --git a/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoderFactory.cpp b/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoderFactory.cpp index 74fd63f864fe8..bc8336705e180 100644 --- a/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoderFactory.cpp +++ b/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoderFactory.cpp @@ -115,11 +115,11 @@ class LibWebRTCGStreamerVideoEncoder : public webrtc::VideoEncoder { return m_pipeline.get(); } - GstElement* makeElement(const gchar* factoryName) + GstElement* makeElement(ASCIILiteral factoryName) { static Atomic elementId; - auto name = makeString(Name(), "-enc-"_s, span(factoryName), "-"_s, elementId.exchangeAdd(1)); - auto* elem = makeGStreamerElement(factoryName, name.utf8().data()); + auto name = makeString(Name(), "-enc-"_s, factoryName, "-"_s, elementId.exchangeAdd(1)); + auto* elem = makeGStreamerElement(factoryName, name); return elem; } @@ -133,7 +133,7 @@ class LibWebRTCGStreamerVideoEncoder : public webrtc::VideoEncoder { return WEBRTC_VIDEO_CODEC_ERR_SIMULCAST_PARAMETERS_NOT_SUPPORTED; } - m_pipeline = makeElement("pipeline"); + m_pipeline = makeElement("pipeline"_s); connectSimpleBusMessageCallback(m_pipeline.get()); m_encoder = createEncoder(); @@ -141,15 +141,15 @@ class LibWebRTCGStreamerVideoEncoder : public webrtc::VideoEncoder { g_object_set(m_encoder.get(), "keyframe-interval", KeyframeInterval(codecSettings), nullptr); - m_src = makeElement("appsrc"); + m_src = makeElement("appsrc"_s); g_object_set(m_src.get(), "is-live", true, "format", GST_FORMAT_TIME, nullptr); - auto* videoconvert = makeElement("videoconvert"); - auto* videoscale = makeElement("videoscale"); - m_sink = makeElement("appsink"); + auto* videoconvert = makeElement("videoconvert"_s); + auto* videoscale = makeElement("videoscale"_s); + m_sink = makeElement("appsink"_s); g_object_set(m_sink.get(), "sync", FALSE, nullptr); - m_capsFilter = makeElement("capsfilter"); + m_capsFilter = makeElement("capsfilter"_s); if (m_restrictionCaps) g_object_set(m_capsFilter.get(), "caps", m_restrictionCaps.get(), nullptr); From 025676c55b11381841b1731440e17b5a8e26f497 Mon Sep 17 00:00:00 2001 From: Xabier Rodriguez Calvar Date: Fri, 12 Dec 2025 12:05:58 +0100 Subject: [PATCH 05/22] [GStreamer] Solved some compiler warnings --- .../Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp | 2 ++ .../graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp | 5 ++++- .../platform/graphics/gstreamer/VideoEncoderGStreamer.cpp | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp b/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp index 75cc35a9a72ae..9865cc0a1407d 100644 --- a/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp +++ b/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp @@ -848,6 +848,8 @@ void LibWebRTCMediaEndpoint::OnStatsDelivered(const rtc::scoped_refptr GValueArray* { + G_CALLBACK(+[](GstElement*, GstPad*, GstCaps* caps, MediaPlayerPrivateGStreamer*) -> GValueArray* { ALLOW_DEPRECATED_DECLARATIONS_BEGIN; // GValueArray is deprecated GValueArray* result; // First, build a list of all decodable factories that can handle the caps, diff --git a/Source/WebCore/platform/graphics/gstreamer/VideoEncoderGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/VideoEncoderGStreamer.cpp index 1b1c41ad36606..45a8c89271ea9 100644 --- a/Source/WebCore/platform/graphics/gstreamer/VideoEncoderGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/VideoEncoderGStreamer.cpp @@ -195,6 +195,8 @@ static std::optional retrieveTemporalIndex(const GRefPtr& s auto name = gstStructureGetName(structure); GST_TRACE("Retrieval of temporal index from encoded format %s is not yet supported.", reinterpret_cast(name.rawCharacters())); #endif +#else + UNUSED_PARAM(sample); #endif return { }; } From 8dc284b20e0310e4644a88c31cb234cc1c8bd437 Mon Sep 17 00:00:00 2001 From: Xabier Rodriguez-Calvar Date: Wed, 19 Mar 2025 07:36:16 -0700 Subject: [PATCH 06/22] [GStreamer] Make gstObjectHasProperty use ASCIILiteral https://bugs.webkit.org/show_bug.cgi?id=290035 Reviewed by Philippe Normand. * Source/WebCore/Modules/mediastream/gstreamer/GStreamerIceTransportBackend.cpp: (WebCore::GStreamerIceTransportBackend::iceTransportChanged): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp: (WebCore::GStreamerMediaEndpoint::initializePipeline): (WebCore::GStreamerMediaEndpoint::requestPad): * Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp: (WebCore::GStreamerInternalAudioEncoder::initialize): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::configureAudioDecoderForHarnessing): (WebCore::configureVideoDecoderForHarnessing): (WebCore::configureMediaStreamVideoDecoder): (WebCore::configureVideoRTPDepayloader): (WebCore::gstObjectHasProperty): (WebCore::gstElementMatchesFactoryAndHasProperty): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h: * Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::configureVideoDecoder): (WebCore::MediaPlayerPrivateGStreamer::createVideoSink): * Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkBcmNexus.cpp: (WebCore::GStreamerHolePunchQuirkBcmNexus::setHolePunchVideoRectangle): * Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkRialto.cpp: (WebCore::GStreamerHolePunchQuirkRialto::setHolePunchVideoRectangle): * Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkWesteros.cpp: (WebCore::GStreamerHolePunchQuirkWesteros::setHolePunchVideoRectangle): * Source/WebCore/platform/gstreamer/GStreamerQuirkAmLogic.cpp: (WebCore::GStreamerQuirkAmLogic::configureElement): * Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcom.cpp: (WebCore::GStreamerQuirkBroadcom::configureElement): * Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcomBase.cpp: (WebCore::GStreamerQuirkBroadcomBase::setupBufferingPercentageCorrection const): * Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.cpp: (WebCore::GStreamerQuirkRealtek::configureElement): * Source/WebCore/platform/gstreamer/GStreamerQuirkWesteros.cpp: (WebCore::GStreamerQuirkWesteros::configureElement): * Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp: (webkit_video_encoder_class_init): * Source/WebCore/platform/mediarecorder/MediaRecorderPrivateGStreamer.cpp: (WebCore::MediaRecorderPrivateBackend::configureAudioEncoder): * Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp: (WebCore::GStreamerAudioRTPPacketizer::create): * Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp: (WebCore::GStreamerIncomingTrackProcessor::mediaStreamIdFromPad): * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp: (WebCore::GStreamerVideoRTPPacketizer::create): * Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp: (WebCore::RealtimeOutgoingMediaSourceGStreamer::initialize): Canonical link: https://commits.webkit.org/292351@main Signed-off-by: Xabier Rodriguez Calvar --- .../gstreamer/GStreamerMediaEndpoint.cpp | 4 +-- .../audio/gstreamer/AudioEncoderGStreamer.cpp | 2 +- .../graphics/gstreamer/GStreamerCommon.cpp | 34 +++++++++---------- .../graphics/gstreamer/GStreamerCommon.h | 4 +-- .../gstreamer/MediaPlayerPrivateGStreamer.cpp | 6 ++-- .../mse/MediaPlayerPrivateGStreamerMSE.cpp | 2 +- .../GStreamerHolePunchQuirkBcmNexus.cpp | 2 +- .../GStreamerHolePunchQuirkRialto.cpp | 2 +- .../GStreamerHolePunchQuirkWesteros.cpp | 2 +- .../gstreamer/GStreamerQuirkAmLogic.cpp | 4 +-- .../gstreamer/GStreamerQuirkBroadcom.cpp | 2 +- .../gstreamer/GStreamerQuirkBroadcomBase.cpp | 2 +- .../gstreamer/GStreamerQuirkRealtek.cpp | 4 +-- .../gstreamer/GStreamerQuirkWesteros.cpp | 2 +- .../VideoEncoderPrivateGStreamer.cpp | 2 +- .../MediaRecorderPrivateGStreamer.cpp | 2 +- .../gstreamer/GStreamerAudioRTPPacketizer.cpp | 2 +- .../GStreamerIncomingTrackProcessor.cpp | 2 +- .../gstreamer/GStreamerVideoRTPPacketizer.cpp | 4 +-- .../RealtimeOutgoingMediaSourceGStreamer.cpp | 2 +- 20 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp index 9cb85a7205e27..e34740d62fad7 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp @@ -187,7 +187,7 @@ bool GStreamerMediaEndpoint::initializePipeline() return false; } - if (gstObjectHasProperty(rtpBin.get(), "add-reference-timestamp-meta")) + if (gstObjectHasProperty(rtpBin.get(), "add-reference-timestamp-meta"_s)) g_object_set(rtpBin.get(), "add-reference-timestamp-meta", TRUE, nullptr); g_signal_connect(rtpBin.get(), "new-jitterbuffer", G_CALLBACK(+[](GstElement*, GstElement* element, unsigned, unsigned ssrc, GStreamerMediaEndpoint* endPoint) { @@ -1106,7 +1106,7 @@ GRefPtr GStreamerMediaEndpoint::requestPad(const GRefPtr& allow if (!mediaStreamID.isEmpty()) { GST_DEBUG_OBJECT(m_pipeline.get(), "Setting msid to %s on sink pad %" GST_PTR_FORMAT, mediaStreamID.ascii().data(), sinkPad.get()); - if (gstObjectHasProperty(sinkPad.get(), "msid")) + if (gstObjectHasProperty(sinkPad.get(), "msid"_s)) g_object_set(sinkPad.get(), "msid", mediaStreamID.ascii().data(), nullptr); } diff --git a/Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp index ae62dce82ca23..06d52cd70e7da 100644 --- a/Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp @@ -291,7 +291,7 @@ String GStreamerInternalAudioEncoder::initialize(const String& codecName, const if (codecName.startsWith("mp4a"_s)) { const char* streamFormat = config.isAacADTS.value_or(false) ? "adts" : "raw"; m_outputCaps = adoptGRef(gst_caps_new_simple("audio/mpeg", "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, streamFormat, nullptr)); - if (gstObjectHasProperty(m_encoder.get(), "bitrate") && config.bitRate && config.bitRate < std::numeric_limits::max()) + if (gstObjectHasProperty(m_encoder.get(), "bitrate"_s) && config.bitRate && config.bitRate < std::numeric_limits::max()) g_object_set(m_encoder.get(), "bitrate", static_cast(config.bitRate), nullptr); } else if (codecName == "mp3"_s) m_outputCaps = adoptGRef(gst_caps_new_simple("audio/mpeg", "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, nullptr)); diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp index 6ddd6c10dda5e..444dcb539f968 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp @@ -1588,69 +1588,69 @@ void fillVideoInfoColorimetryFromColorSpace(GstVideoInfo* info, const PlatformVi void configureAudioDecoderForHarnessing(const GRefPtr& element) { - if (gstObjectHasProperty(element.get(), "max-errors")) + if (gstObjectHasProperty(element.get(), "max-errors"_s)) g_object_set(element.get(), "max-errors", 0, nullptr); // rawaudioparse-specific: - if (gstObjectHasProperty(element.get(), "use-sink-caps")) + if (gstObjectHasProperty(element.get(), "use-sink-caps"_s)) g_object_set(element.get(), "use-sink-caps", TRUE, nullptr); } void configureVideoDecoderForHarnessing(const GRefPtr& element) { - if (gstObjectHasProperty(element.get(), "max-threads")) + if (gstObjectHasProperty(element.get(), "max-threads"_s)) g_object_set(element.get(), "max-threads", 1, nullptr); - if (gstObjectHasProperty(element.get(), "max-errors")) + if (gstObjectHasProperty(element.get(), "max-errors"_s)) g_object_set(element.get(), "max-errors", 0, nullptr); // avdec-specific: - if (gstObjectHasProperty(element.get(), "std-compliance")) + if (gstObjectHasProperty(element.get(), "std-compliance"_s)) gst_util_set_object_arg(G_OBJECT(element.get()), "std-compliance", "strict"); - if (gstObjectHasProperty(element.get(), "output-corrupt")) + if (gstObjectHasProperty(element.get(), "output-corrupt"_s)) g_object_set(element.get(), "output-corrupt", FALSE, nullptr); // dav1ddec-specific: - if (gstObjectHasProperty(element.get(), "n-threads")) + if (gstObjectHasProperty(element.get(), "n-threads"_s)) g_object_set(element.get(), "n-threads", 1, nullptr); } void configureMediaStreamVideoDecoder(GstElement* element) { - if (gstObjectHasProperty(element, "automatic-request-sync-points")) + if (gstObjectHasProperty(element, "automatic-request-sync-points"_s)) g_object_set(element, "automatic-request-sync-points", TRUE, nullptr); - if (gstObjectHasProperty(element, "discard-corrupted-frames")) + if (gstObjectHasProperty(element, "discard-corrupted-frames"_s)) g_object_set(element, "discard-corrupted-frames", TRUE, nullptr); - if (gstObjectHasProperty(element, "output-corrupt")) + if (gstObjectHasProperty(element, "output-corrupt"_s)) g_object_set(element, "output-corrupt", FALSE, nullptr); - if (gstObjectHasProperty(element, "max-errors")) + if (gstObjectHasProperty(element, "max-errors"_s)) g_object_set(element, "max-errors", -1, nullptr); } void configureVideoRTPDepayloader(GstElement* element) { - if (gstObjectHasProperty(element, "request-keyframe")) + if (gstObjectHasProperty(element, "request-keyframe"_s)) g_object_set(element, "request-keyframe", TRUE, nullptr); - if (gstObjectHasProperty(element, "wait-for-keyframe")) + if (gstObjectHasProperty(element, "wait-for-keyframe"_s)) g_object_set(element, "wait-for-keyframe", TRUE, nullptr); } -static bool gstObjectHasProperty(GstObject* gstObject, const char* name) +static bool gstObjectHasProperty(GstObject* gstObject, ASCIILiteral name) { - return g_object_class_find_property(G_OBJECT_GET_CLASS(gstObject), name); + return g_object_class_find_property(G_OBJECT_GET_CLASS(gstObject), name.characters()); } -bool gstObjectHasProperty(GstElement* element, const char* name) +bool gstObjectHasProperty(GstElement* element, ASCIILiteral name) { return gstObjectHasProperty(GST_OBJECT_CAST(element), name); } -bool gstObjectHasProperty(GstPad* pad, const char* name) +bool gstObjectHasProperty(GstPad* pad, ASCIILiteral name) { return gstObjectHasProperty(GST_OBJECT_CAST(pad), name); } diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h index 5976962833c0d..658aa83f26b41 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h @@ -311,8 +311,8 @@ void configureVideoDecoderForHarnessing(const GRefPtr&); void configureMediaStreamVideoDecoder(GstElement*); void configureVideoRTPDepayloader(GstElement*); -bool gstObjectHasProperty(GstElement*, const char* name); -bool gstObjectHasProperty(GstPad*, const char* name); +bool gstObjectHasProperty(GstElement*, ASCIILiteral name); +bool gstObjectHasProperty(GstPad*, ASCIILiteral name); GRefPtr wrapSpanData(const std::span&); diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp index ab9376a335403..8a19a5f77e318 100644 --- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp @@ -3502,11 +3502,11 @@ void MediaPlayerPrivateGStreamer::configureVideoDecoder(GstElement* decoder) // Set the decoder maximum number of threads to a low, fixed value, not depending on the // platform. This also helps with processing metrics gathering. When using the default value // the decoder introduces artificial processing latency reflecting the maximum number of threads. - if (gstObjectHasProperty(decoder, "max-threads")) + if (gstObjectHasProperty(decoder, "max-threads"_s)) g_object_set(decoder, "max-threads", 2, nullptr); } - if (gstObjectHasProperty(decoder, "max-errors")) + if (gstObjectHasProperty(decoder, "max-errors"_s)) g_object_set(decoder, "max-errors", 0, nullptr); #if USE(TEXTURE_MAPPER) @@ -4550,7 +4550,7 @@ GstElement* MediaPlayerPrivateGStreamer::createVideoSink() g_value_unset(&value); } - if (gstObjectHasProperty(sink, "max-lateness")) { + if (gstObjectHasProperty(sink, "max-lateness"_s)) { uint64_t maxLateness = 100 * GST_MSECOND; g_object_set(sink, "max-lateness", maxLateness, nullptr); } else { diff --git a/Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp b/Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp index 18a99580198e6..041a714abd17d 100644 --- a/Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp @@ -315,7 +315,7 @@ bool MediaPlayerPrivateGStreamerMSE::doSeek(const SeekTarget& target, float rate sink = GST_ELEMENT(g_value_get_object(&value)); g_value_unset(&value); } - if (gstObjectHasProperty(sink.get(), "async")) + if (gstObjectHasProperty(sink.get(), "async"_s)) g_object_get(sink.get(), "async", &audioSinkPerformsAsyncStateChanges, nullptr); if (!audioSinkPerformsAsyncStateChanges) { // If audio-only pipeline's sink is not performing async state changes diff --git a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkBcmNexus.cpp b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkBcmNexus.cpp index aef32a25d07ef..cd57630362620 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkBcmNexus.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkBcmNexus.cpp @@ -30,7 +30,7 @@ namespace WebCore { bool GStreamerHolePunchQuirkBcmNexus::setHolePunchVideoRectangle(GstElement* videoSink, const IntRect& rect) { - if (UNLIKELY(!gstObjectHasProperty(videoSink, "rectangle"))) + if (UNLIKELY(!gstObjectHasProperty(videoSink, "rectangle"_s))) return false; auto rectString = makeString(rect.x(), ',', rect.y(), ',', rect.width(), ',', rect.height()); diff --git a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkRialto.cpp b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkRialto.cpp index 0799b64be8ca5..1765efb5b4e95 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkRialto.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkRialto.cpp @@ -50,7 +50,7 @@ GstElement* GStreamerHolePunchQuirkRialto::createHolePunchVideoSink(bool isLegac bool GStreamerHolePunchQuirkRialto::setHolePunchVideoRectangle(GstElement* videoSink, const IntRect& rect) { - if (UNLIKELY(!gstObjectHasProperty(videoSink, "rectangle"))) + if (UNLIKELY(!gstObjectHasProperty(videoSink, "rectangle"_s))) return false; auto rectString = makeString(rect.x(), ',', rect.y(), ',', rect.width(), ',', rect.height()); diff --git a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkWesteros.cpp b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkWesteros.cpp index 4250a2600231b..2999d37015ed3 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkWesteros.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerHolePunchQuirkWesteros.cpp @@ -53,7 +53,7 @@ GstElement* GStreamerHolePunchQuirkWesteros::createHolePunchVideoSink(bool isLeg bool GStreamerHolePunchQuirkWesteros::setHolePunchVideoRectangle(GstElement* videoSink, const IntRect& rect) { - if (UNLIKELY(!gstObjectHasProperty(videoSink, "rectangle"))) + if (UNLIKELY(!gstObjectHasProperty(videoSink, "rectangle"_s))) return false; auto rectString = makeString(rect.x(), ',', rect.y(), ',', rect.width(), ',', rect.height()); diff --git a/Source/WebCore/platform/gstreamer/GStreamerQuirkAmLogic.cpp b/Source/WebCore/platform/gstreamer/GStreamerQuirkAmLogic.cpp index 4bc22c8ad199b..d18cd1b1c892e 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerQuirkAmLogic.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerQuirkAmLogic.cpp @@ -56,12 +56,12 @@ GstElement* GStreamerQuirkAmLogic::createWebAudioSink() void GStreamerQuirkAmLogic::configureElement(GstElement* element, const OptionSet& characteristics) { - if (gstObjectHasProperty(element, "disable-xrun")) { + if (gstObjectHasProperty(element, "disable-xrun"_s)) { GST_INFO("Set property disable-xrun to TRUE"); g_object_set(element, "disable-xrun", TRUE, nullptr); } - if (characteristics.contains(ElementRuntimeCharacteristics::HasVideo) && gstObjectHasProperty(element, "wait-video")) { + if (characteristics.contains(ElementRuntimeCharacteristics::HasVideo) && gstObjectHasProperty(element, "wait-video"_s)) { GST_INFO("Set property wait-video to TRUE"); g_object_set(element, "wait-video", TRUE, nullptr); } diff --git a/Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcom.cpp b/Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcom.cpp index ea50c767f5a3c..5d321563d1675 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcom.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcom.cpp @@ -56,7 +56,7 @@ void GStreamerQuirkBroadcom::configureElement(GstElement* element, const OptionS if (!characteristics.contains(ElementRuntimeCharacteristics::IsMediaStream)) return; - if (!g_strcmp0(G_OBJECT_TYPE_NAME(G_OBJECT(element)), "GstBrcmPCMSink") && gstObjectHasProperty(element, "low_latency")) { + if (!g_strcmp0(G_OBJECT_TYPE_NAME(G_OBJECT(element)), "GstBrcmPCMSink") && gstObjectHasProperty(element, "low_latency"_s)) { GST_DEBUG("Set 'low_latency' in brcmpcmsink"); g_object_set(element, "low_latency", TRUE, "low_latency_max_queued_ms", 60, nullptr); } diff --git a/Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcomBase.cpp b/Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcomBase.cpp index c02275e9e717c..1bb55df815d43 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcomBase.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcomBase.cpp @@ -157,7 +157,7 @@ void GStreamerQuirkBroadcomBase::setupBufferingPercentageCorrection(MediaPlayerP // The multiqueue reference is useless if we can't access its stats (on older GStreamer versions). if (peerElement && !g_strcmp0(G_OBJECT_TYPE_NAME(element.get()), "GstMultiQueue") - && gstObjectHasProperty(peerElement.get(), "stats")) + && gstObjectHasProperty(peerElement.get(), "stats"_s)) state.m_multiqueue = peerElement; break; } diff --git a/Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.cpp b/Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.cpp index 07a44c381b0d2..36bc169f335ba 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.cpp @@ -66,12 +66,12 @@ void GStreamerQuirkRealtek::configureElement(GstElement* element, const OptionSe if (!characteristics.contains(ElementRuntimeCharacteristics::IsMediaStream)) return; - if (gstObjectHasProperty(element, "media-tunnel")) { + if (gstObjectHasProperty(element, "media-tunnel"_s)) { GST_INFO("Enable 'immediate-output' in rtkaudiosink"); g_object_set(element, "media-tunnel", FALSE, "audio-service", TRUE, "lowdelay-sync-mode", TRUE, nullptr); } - if (gstObjectHasProperty(element, "lowdelay-mode")) { + if (gstObjectHasProperty(element, "lowdelay-mode"_s)) { GST_INFO("Enable 'lowdelay-mode' in rtk omx decoder"); g_object_set(element, "lowdelay-mode", TRUE, nullptr); } diff --git a/Source/WebCore/platform/gstreamer/GStreamerQuirkWesteros.cpp b/Source/WebCore/platform/gstreamer/GStreamerQuirkWesteros.cpp index c7f62b7e33b82..feba7a365cd56 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerQuirkWesteros.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerQuirkWesteros.cpp @@ -85,7 +85,7 @@ void GStreamerQuirkWesteros::configureElement(GstElement* element, const OptionS if (!characteristics.contains(ElementRuntimeCharacteristics::IsMediaStream)) return; - if (!g_strcmp0(G_OBJECT_TYPE_NAME(G_OBJECT(element)), "GstWesterosSink") && gstObjectHasProperty(element, "immediate-output")) { + if (!g_strcmp0(G_OBJECT_TYPE_NAME(G_OBJECT(element)), "GstWesterosSink") && gstObjectHasProperty(element, "immediate-output"_s)) { GST_INFO("Enable 'immediate-output' in WesterosSink"); g_object_set(element, "immediate-output", TRUE, nullptr); } diff --git a/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp b/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp index 6fdb7402b7809..3a5f138a08663 100644 --- a/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp +++ b/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp @@ -923,7 +923,7 @@ static void webkit_video_encoder_class_init(WebKitVideoEncoderClass* klass) break; } }, [](GstElement* encoder, LatencyMode mode) { - if (!gstObjectHasProperty(encoder, "usage-profile")) + if (!gstObjectHasProperty(encoder, "usage-profile"_s)) return; switch (mode) { case REALTIME_LATENCY_MODE: diff --git a/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateGStreamer.cpp b/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateGStreamer.cpp index 646c6bb4c8bd8..dc549c4888201 100644 --- a/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateGStreamer.cpp +++ b/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateGStreamer.cpp @@ -405,7 +405,7 @@ void MediaRecorderPrivateBackend::setSink(GstElement* element) void MediaRecorderPrivateBackend::configureAudioEncoder(GstElement* element) { - if (!gstObjectHasProperty(element, "bitrate")) { + if (!gstObjectHasProperty(element, "bitrate"_s)) { GST_WARNING_OBJECT(m_pipeline.get(), "Audio encoder %" GST_PTR_FORMAT " has no bitrate property, skipping configuration", element); return; } diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp index 8150486cc837f..95efb4f8a6c65 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp @@ -116,7 +116,7 @@ RefPtr GStreamerAudioRTPPacketizer::create(RefPtr(minPTime)) { - if (gstObjectHasProperty(payloader.get(), "min-ptime")) + if (gstObjectHasProperty(payloader.get(), "min-ptime"_s)) g_object_set(payloader.get(), "min-ptime", *value * GST_MSECOND, nullptr); else GST_WARNING_OBJECT(payloader.get(), "min-ptime property not supported"); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp index f01eeeaad2d59..699d4c2f5893d 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp @@ -122,7 +122,7 @@ String GStreamerIncomingTrackProcessor::mediaStreamIdFromPad() { // Look-up the mediastream ID, using the msid attribute, fall back to pad name if there is no msid. String mediaStreamId; - if (gstObjectHasProperty(m_pad.get(), "msid")) { + if (gstObjectHasProperty(m_pad.get(), "msid"_s)) { GUniqueOutPtr msid; g_object_get(m_pad.get(), "msid", &msid.outPtr(), nullptr); if (msid) { diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp index 7cab1b9193e8a..3cb88c882e04f 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp @@ -64,12 +64,12 @@ RefPtr GStreamerVideoRTPPacketizer::create(RefPtr Date: Wed, 19 Mar 2025 12:43:40 -0700 Subject: [PATCH 07/22] [GStreamer] Switch setGstElementGLContext to ASCIILiteral https://bugs.webkit.org/show_bug.cgi?id=290049 Reviewed by Philippe Normand. * Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp: (webKitGLVideoSinkChangeState): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::setGstElementGLContext): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h: * Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp: (WebCore::GStreamerVideoFrameConverter::Pipeline::run): Canonical link: https://commits.webkit.org/292373@main Signed-off-by: Xabier Rodriguez Calvar --- .../platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp | 5 +++-- .../WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp | 6 +++--- .../WebCore/platform/graphics/gstreamer/GStreamerCommon.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp index 7fae6da120386..d389b481a1c90 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp @@ -131,9 +131,10 @@ static GstStateChangeReturn webKitGLVideoSinkChangeState(GstElement* element, Gs case GST_STATE_CHANGE_NULL_TO_READY: case GST_STATE_CHANGE_READY_TO_READY: case GST_STATE_CHANGE_READY_TO_PAUSED: { - if (!setGstElementGLContext(element, GST_GL_DISPLAY_CONTEXT_TYPE)) + static ASCIILiteral gstGlDisplayContextyType = ASCIILiteral::fromLiteralUnsafe(GST_GL_DISPLAY_CONTEXT_TYPE); + if (!setGstElementGLContext(element, gstGlDisplayContextyType)) return GST_STATE_CHANGE_FAILURE; - if (!setGstElementGLContext(element, "gst.gl.app_context")) + if (!setGstElementGLContext(element, "gst.gl.app_context"_s)) return GST_STATE_CHANGE_FAILURE; break; } diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp index 444dcb539f968..a3976fb1c5e56 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp @@ -1866,11 +1866,11 @@ static std::optional> requestGLContext(const char* contextTy return std::nullopt; } -bool setGstElementGLContext(GstElement* element, const char* contextType) +bool setGstElementGLContext(GstElement* element, ASCIILiteral contextType) { - GRefPtr oldContext = adoptGRef(gst_element_get_context(element, contextType)); + GRefPtr oldContext = adoptGRef(gst_element_get_context(element, contextType.characters())); if (!oldContext) { - auto newContext = requestGLContext(contextType); + auto newContext = requestGLContext(contextType.characters()); if (!newContext) return false; gst_element_set_context(element, newContext->get()); diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h index 658aa83f26b41..40164732c67c5 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h @@ -356,7 +356,7 @@ WARN_UNUSED_RETURN GRefPtr buildDMABufCaps(); #endif #if USE(GSTREAMER_GL) -bool setGstElementGLContext(GstElement*, const char* contextType); +bool setGstElementGLContext(GstElement*, ASCIILiteral contextType); #endif } // namespace WebCore From 56027fe52604cdd8a10c625ad8e4582a98c696c6 Mon Sep 17 00:00:00 2001 From: Xabier Rodriguez-Calvar Date: Mon, 22 Sep 2025 05:58:05 -0700 Subject: [PATCH 08/22] [GStreamer] Change gstStructureGetString and Name to properly handle null terminated strings https://bugs.webkit.org/show_bug.cgi?id=290306 Reviewed by Geoffrey Garen. Created a new CStringView type to wrap a C String and be able to recover, without copies, the original string while taking advantage of some other string niceties likes comparisons and the like. This class handles UTF8 strings only, so if you need to compare or interface with any other WebKit strings, you have to convert to String. I used that on gstStructureGetString and Name and updated the rest of the code accordingly. Tests: Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp * Source/WTF/WTF.xcodeproj/project.pbxproj: * Source/WTF/wtf/CMakeLists.txt: * Source/WTF/wtf/text/CStringView.cpp: Added. (WTF::CStringView::toString const): (WTF::CStringView::dump const): * Source/WTF/wtf/text/CStringView.h: Added. (WTF::operator==): (WTF::safePrintfType): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp: (WebCore::GStreamerMediaEndpoint::requestPad): (WebCore::GStreamerMediaEndpoint::connectIncomingTrack): (WebCore::GStreamerMediaEndpoint::preprocessStats): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpReceiverBackend.cpp: (WebCore::GStreamerRtpReceiverBackend::getParameters): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerStatsCollector.cpp: (WebCore::iceCandidateType): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp: (WebCore::toRTCEncodingParameters): (WebCore::toRTCRtpSendParameters): (WebCore::payloadTypeForEncodingName): (WebCore::capsFromRtpCapabilities): (WebCore::capsFromSDPMedia): (WebCore::extractMidAndRidFromRTPBuffer): * Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.h: * Source/WebCore/inspector/agents/page/PageHeapAgent.cpp: (WebCore::PageHeapAgent::heapSnapshotBuilderOverrideClassName): * Source/WebCore/loader/FrameLoader.cpp: (WebCore::FrameLoader::userAgent const): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::webkitGstGhostPadFromStaticTemplate): (WebCore::capsMediaType): (WebCore::doCapsHaveType): (WebCore::gstStructureGet): (WebCore::gstStructureGetString): (WebCore::gstStructureGetName): (WebCore::gstStructureGetArray): (WebCore::gstStructureGetList): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h: * Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp: (WebCore::GStreamerRegistryScanner::isContentTypeSupported const): * Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp: (WebCore::GStreamerVideoFrameConverter::convert): * Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::handleMessage): (WebCore::MediaPlayerPrivateGStreamer::loadNextLocation): * Source/WebCore/platform/graphics/gstreamer/VideoEncoderGStreamer.cpp: (WebCore::retrieveTemporalIndex): * Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp: (webKitAudioSinkConfigure): * Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp: (transformCaps): (transformInPlace): * Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp: (WebCore::AppendPipeline::AppendPipeline): (WebCore::AppendPipeline::appsinkCapsChanged): * Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp: (WebCore::GStreamerMediaDescription::extractCodecName const): * Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp: (WebCore::MermaidBuilder::describeCaps): * Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp: (webkit_video_encoder_class_init): * Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp: (WebCore::GStreamerAudioRTPPacketizer::create): * Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp: (WebCore::GStreamerCaptureDeviceManager::captureDeviceFromGstDevice): * Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp: (WebCore::GStreamerIncomingTrackProcessor::configure): (WebCore::GStreamerIncomingTrackProcessor::incomingTrackProcessor): * Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp: (webkitMediaStreamSrcAddTrack): * Source/WebCore/platform/mediastream/gstreamer/GStreamerMockDeviceProvider.cpp: (webkitGstMockDeviceProviderSwitchDefaultDevice): * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp: (WebCore::GStreamerVideoCapturer::reconfigure): * Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp: (WebCore::GStreamerVideoRTPPacketizer::create): * Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingAudioSourceGStreamer.cpp: (WebCore::RealtimeOutgoingAudioSourceGStreamer::setInitialParameters): * Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp: (WebCore::RealtimeOutgoingMediaSourceGStreamer::setParameters): (WebCore::RealtimeOutgoingMediaSourceGStreamer::getPacketizerForRid): * Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.h: * Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp: (WebCore::GStreamerWebRTCVideoDecoder::makeElement): * Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm: (WebKit::operator<<): * Tools/TestWebKitAPI/CMakeLists.txt: * Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp: Added. (TestWebKitAPI::TEST(WTF, CStringViewNullAndEmpty)): (TestWebKitAPI::TEST(WTF, CStringViewLength)): (TestWebKitAPI::TEST(WTF, CStringViewFrom)): (TestWebKitAPI::TEST(WTF, CStringViewEquality)): Canonical link: https://commits.webkit.org/300318@main Signed-off-by: Xabier Rodriguez Calvar --- Source/WTF/WTF.xcodeproj/project.pbxproj | 8 ++ Source/WTF/wtf/CMakeLists.txt | 2 + Source/WTF/wtf/text/CStringView.cpp | 48 +++++++ Source/WTF/wtf/text/CStringView.h | 121 ++++++++++++++++++ .../gstreamer/GStreamerMediaEndpoint.cpp | 8 +- .../gstreamer/GStreamerRtpReceiverBackend.cpp | 4 +- .../gstreamer/GStreamerStatsCollector.cpp | 2 +- .../gstreamer/GStreamerWebRTCUtils.cpp | 15 +-- .../gstreamer/GStreamerWebRTCUtils.h | 2 +- .../graphics/gstreamer/GStreamerCommon.cpp | 76 ++++------- .../graphics/gstreamer/GStreamerCommon.h | 16 +-- .../gstreamer/GStreamerRegistryScanner.cpp | 2 +- .../GStreamerVideoFrameConverter.cpp | 6 +- .../gstreamer/MediaPlayerPrivateGStreamer.cpp | 12 +- .../gstreamer/VideoEncoderGStreamer.cpp | 2 +- ...bKitCommonEncryptionDecryptorGStreamer.cpp | 6 +- .../graphics/gstreamer/mse/AppendPipeline.cpp | 10 +- .../mse/GStreamerMediaDescription.cpp | 2 +- .../gstreamer/GStreamerElementHarness.cpp | 2 +- .../VideoEncoderPrivateGStreamer.cpp | 2 +- .../gstreamer/GStreamerAudioRTPPacketizer.cpp | 9 +- .../GStreamerCaptureDeviceManager.cpp | 2 +- .../GStreamerIncomingTrackProcessor.cpp | 13 +- .../gstreamer/GStreamerMediaStreamSource.cpp | 2 +- .../gstreamer/GStreamerVideoCapturer.cpp | 4 +- .../gstreamer/GStreamerVideoRTPPacketizer.cpp | 7 +- .../RealtimeOutgoingMediaSourceGStreamer.cpp | 4 +- .../RealtimeOutgoingMediaSourceGStreamer.h | 2 +- .../PlatformCAAnimationRemote.mm | 4 +- Tools/TestWebKitAPI/CMakeLists.txt | 1 + .../TestWebKitAPI.xcodeproj/project.pbxproj | 4 + Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp | 106 +++++++++++++++ 32 files changed, 386 insertions(+), 118 deletions(-) create mode 100644 Source/WTF/wtf/text/CStringView.cpp create mode 100644 Source/WTF/wtf/text/CStringView.h create mode 100644 Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp diff --git a/Source/WTF/WTF.xcodeproj/project.pbxproj b/Source/WTF/WTF.xcodeproj/project.pbxproj index 74f1cc055d2be..4e17c4e75fe5d 100644 --- a/Source/WTF/WTF.xcodeproj/project.pbxproj +++ b/Source/WTF/WTF.xcodeproj/project.pbxproj @@ -209,6 +209,8 @@ C2BCFC551F621F3F00C9222C /* LineEnding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C2BCFC531F621F3F00C9222C /* LineEnding.cpp */; }; C805EF39E5F14481A96D39FC /* ASCIILiteral.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6F050790D9C432A99085E75 /* ASCIILiteral.cpp */; }; CD5497AC15857D0300B5BC30 /* MediaTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD5497AA15857D0300B5BC30 /* MediaTime.cpp */; }; + CDD4AC792D9C309A00D11414 /* CStringView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDD4AC772D9C309A00D11414 /* CStringView.cpp */; }; + CDD4AC7A2D9C309A00D11414 /* CStringView.h in Headers */ = {isa = PBXBuildFile; fileRef = CDD4AC782D9C309A00D11414 /* CStringView.h */; settings = {ATTRIBUTES = (Private, ); }; }; CEA072AA236FFBF70018839C /* CrashReporter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CEA072A9236FFBF70018839C /* CrashReporter.cpp */; }; DCEE22011CEA7551000C2396 /* BlockObjCExceptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = DCEE21FD1CEA7551000C2396 /* BlockObjCExceptions.mm */; }; DD03059327B5DA0D00344002 /* SignedPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 862A8D32278DE74A0014120C /* SignedPtr.h */; settings = {ATTRIBUTES = (Private, ); }; }; @@ -1532,6 +1534,8 @@ CD5497AB15857D0300B5BC30 /* MediaTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaTime.h; sourceTree = ""; }; CD6D9FCD1EEF3AD4008B0671 /* Algorithms.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Algorithms.h; sourceTree = ""; }; CDCC9BC422382FCE00FFB51C /* AggregateLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AggregateLogger.h; path = wtf/AggregateLogger.h; sourceTree = SOURCE_ROOT; }; + CDD4AC772D9C309A00D11414 /* CStringView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CStringView.cpp; sourceTree = ""; }; + CDD4AC782D9C309A00D11414 /* CStringView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CStringView.h; sourceTree = ""; }; CE1132832370634900A8C83B /* AnsiColors.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AnsiColors.h; sourceTree = ""; }; CEA072A8236FFBF70018839C /* CrashReporter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CrashReporter.h; sourceTree = ""; }; CEA072A9236FFBF70018839C /* CrashReporter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CrashReporter.cpp; sourceTree = ""; }; @@ -2611,6 +2615,8 @@ 0F8F2B9B172F2594007DBDA5 /* ConversionMode.h */, A8A47321151A825B004123FF /* CString.cpp */, A8A47322151A825B004123FF /* CString.h */, + CDD4AC772D9C309A00D11414 /* CStringView.cpp */, + CDD4AC782D9C309A00D11414 /* CStringView.h */, 93853DD228755A6600FF4E2B /* EscapedFormsForJSON.h */, 50DE35F3215BB01500B979C7 /* ExternalStringImpl.cpp */, 50DE35F4215BB01500B979C7 /* ExternalStringImpl.h */, @@ -3221,6 +3227,7 @@ DD3DC8FC27A4BF8E007E5B61 /* CryptographicallyRandomNumber.h in Headers */, DD3DC8B727A4BF8E007E5B61 /* CryptographicUtilities.h in Headers */, DDF307E127C086DF006A526F /* CString.h in Headers */, + CDD4AC7A2D9C309A00D11414 /* CStringView.h in Headers */, DD3DC8E327A4BF8E007E5B61 /* DataLog.h in Headers */, DD4901E927B4748A00D7E50D /* DataMutex.h in Headers */, DD3DC94227A4BF8E007E5B61 /* DataRef.h in Headers */, @@ -4029,6 +4036,7 @@ A8A4739A151A825B004123FF /* CryptographicallyRandomNumber.cpp in Sources */, E15556F518A0CC18006F48FB /* CryptographicUtilities.cpp in Sources */, A8A47439151A825B004123FF /* CString.cpp in Sources */, + CDD4AC792D9C309A00D11414 /* CStringView.cpp in Sources */, A8A4739C151A825B004123FF /* CurrentTime.cpp in Sources */, A8A4739E151A825B004123FF /* DataLog.cpp in Sources */, A8A473A0151A825B004123FF /* DateMath.cpp in Sources */, diff --git a/Source/WTF/wtf/CMakeLists.txt b/Source/WTF/wtf/CMakeLists.txt index a1c4469d73844..291e2b6bf301f 100644 --- a/Source/WTF/wtf/CMakeLists.txt +++ b/Source/WTF/wtf/CMakeLists.txt @@ -438,6 +438,7 @@ set(WTF_PUBLIC_HEADERS text/AtomStringTable.h text/Base64.h text/CString.h + text/CStringView.h text/CharacterProperties.h text/CodePointIterator.h text/ConversionMode.h @@ -622,6 +623,7 @@ set(WTF_SOURCES text/AtomStringTable.cpp text/Base64.cpp text/CString.cpp + text/CStringView.cpp text/ExternalStringImpl.cpp text/LineEnding.cpp text/StringBuffer.cpp diff --git a/Source/WTF/wtf/text/CStringView.cpp b/Source/WTF/wtf/text/CStringView.cpp new file mode 100644 index 0000000000000..97eef8fa45278 --- /dev/null +++ b/Source/WTF/wtf/text/CStringView.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2018 Yusuke Suzuki + * Copyright (C) 2024 Apple Inc. All Rights Reserved. + * Copyright (C) 2025 Comcast Inc. + * Copyright (C) 2025 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include + +#include +#include +#include + +namespace WTF { + +String CStringView::toString() const +{ + return String::fromUTF8(span8()); +} + +void CStringView::dump(PrintStream& out) const +{ + out.print(span8()); +} + +} // namespace WTF diff --git a/Source/WTF/wtf/text/CStringView.h b/Source/WTF/wtf/text/CStringView.h new file mode 100644 index 0000000000000..d50f72a5dfbf4 --- /dev/null +++ b/Source/WTF/wtf/text/CStringView.h @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2018 Yusuke Suzuki + * Copyright (C) 2024 Apple Inc. All Rights Reserved. + * Copyright (C) 2025 Comcast Inc. + * Copyright (C) 2025 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace WTF { + +class PrintStream; +class String; + +// This is a class designed to contain a UTF8 string, untouched. Interactions with other string classes in WebKit should +// be handled with care or perform a string conversion through the String class, with the exception of ASCIILiteral +// because ASCII characters are also UTF8. +class CStringView final { + WTF_FORBID_HEAP_ALLOCATION; +public: + static CStringView unsafeFromUTF8(const char* string) + { + if (!string) + return CStringView(); + return CStringView(unsafeMakeSpan(byteCast(string), std::char_traits::length(string) + 1)); + } + + WTF_EXPORT_PRIVATE void dump(PrintStream& out) const; + + CStringView() = default; + constexpr CStringView(std::nullptr_t) + : CStringView() + { } + CStringView(ASCIILiteral literal LIFETIME_BOUND) + { + if (!literal.length()) + return; + m_spanWithNullTerminator = byteCast(literal.spanIncludingNullTerminator()); + } + + unsigned hash() const; + bool isNull() const { return m_spanWithNullTerminator.empty(); } + + // This method is designed to interface with external C functions handling UTF8 strings. Interactions with other + // strings should be done through String with the exception of ASCIILiteral because ASCII is also UTF8. + const char* utf8() const LIFETIME_BOUND { return reinterpret_cast(m_spanWithNullTerminator.data()); } + size_t length() const { return m_spanWithNullTerminator.size() > 0 ? m_spanWithNullTerminator.size() - 1 : 0; } + std::span span8() const LIFETIME_BOUND { return m_spanWithNullTerminator.first(length()); } + std::span spanIncludingNullTerminator() const LIFETIME_BOUND { return m_spanWithNullTerminator; } + size_t isEmpty() const { return m_spanWithNullTerminator.size() <= 1; } + WTF_EXPORT_PRIVATE String toString() const; + + explicit operator bool() const { return !isEmpty(); } + bool operator!() const { return isEmpty(); } + +private: + explicit CStringView(std::span spanWithNullTerminator LIFETIME_BOUND) + : m_spanWithNullTerminator(spanWithNullTerminator) + { + } + + std::span m_spanWithNullTerminator; +}; + +inline bool operator==(CStringView a, CStringView b) +{ + if (!a || !b) + return a.utf8() == b.utf8(); + return equalSpans(a.span8(), b.span8()); +} + +inline bool operator==(CStringView a, ASCIILiteral b) +{ + if (a.isEmpty() || b.isEmpty()) + return a.utf8() == b.characters(); + return equalSpans(a.span8(), byteCast(b.span8())); +} + +inline bool operator==(ASCIILiteral a, CStringView b) +{ + return b == a; +} + +// CStringView is null terminated +inline const char* safePrintfType(const CStringView& string) { return string.utf8(); } + +} // namespace WTF + +using WTF::CStringView; diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp index e34740d62fad7..5f936b1f26f7c 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp @@ -1053,7 +1053,7 @@ GRefPtr GStreamerMediaEndpoint::requestPad(const GRefPtr& allow } std::optional payloadType; if (auto encodingName = gstStructureGetString(structure, "encoding-name"_s)) - payloadType = payloadTypeForEncodingName(encodingName); + payloadType = payloadTypeForEncodingName(encodingName.toString()); if (!payloadType) { if (availablePayloadType < 128) @@ -2201,7 +2201,7 @@ GUniquePtr GStreamerMediaEndpoint::preprocessStats(const GRefPtr GStreamerMediaEndpoint::preprocessStats(const GRefPtr(structure, "clock-rate"_s)) codec.clockRate = *clockRate; diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerStatsCollector.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerStatsCollector.cpp index c12aa3374cd7c..c66f90096d37c 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerStatsCollector.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerStatsCollector.cpp @@ -199,7 +199,7 @@ RTCStatsReport::TransportStats::TransportStats(const GstStructure* structure) // stats.srtpCipher = } -static inline RTCIceCandidateType iceCandidateType(StringView type) +static inline RTCIceCandidateType iceCandidateType(CStringView type) { if (type == "host"_s) return RTCIceCandidateType::Host; diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp index 198762cf6261d..19a180ce57765 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp @@ -164,7 +164,7 @@ static inline RTCRtpEncodingParameters toRTCEncodingParameters(const GstStructur parameters.maxFramerate = *maxFramerate; if (auto rid = gstStructureGetString(rtcParameters, "rid"_s)) - parameters.rid = makeString(rid); + parameters.rid = rid.toString(); if (auto scaleResolutionDownBy = gstStructureGet(rtcParameters, "scale-resolution-down-by"_s)) parameters.scaleResolutionDownBy = *scaleResolutionDownBy; @@ -207,7 +207,7 @@ RTCRtpSendParameters toRTCRtpSendParameters(const GstStructure* rtcParameters) RTCRtpSendParameters parameters; if (auto transactionId = gstStructureGetString(rtcParameters, "transaction-id"_s)) - parameters.transactionId = makeString(transactionId); + parameters.transactionId = transactionId.toString(); if (auto encodings = gst_structure_get_value(rtcParameters, "encodings")) { unsigned size = gst_value_list_get_size(encodings); @@ -555,7 +555,7 @@ uint32_t UniqueSSRCGenerator::generateSSRC() return std::numeric_limits::max(); } -std::optional payloadTypeForEncodingName(StringView encodingName) +std::optional payloadTypeForEncodingName(const String& encodingName) { static HashMap staticPayloadTypes = { { "PCMU"_s, 0 }, @@ -563,9 +563,8 @@ std::optional payloadTypeForEncodingName(StringView encodingName) { "G722"_s, 9 }, }; - const auto key = encodingName.toStringWithoutCopying(); - if (staticPayloadTypes.contains(key)) - return staticPayloadTypes.get(key); + if (staticPayloadTypes.contains(encodingName)) + return staticPayloadTypes.get(encodingName); return { }; } @@ -588,7 +587,7 @@ GRefPtr capsFromRtpCapabilities(const RTCRtpCapabilities& capabilities, gst_structure_set(codecStructure, "encoding-params", G_TYPE_STRING, makeString(*codec.channels).ascii().data(), nullptr); if (auto encodingName = gstStructureGetString(codecStructure, "encoding-name"_s)) { - if (auto payloadType = payloadTypeForEncodingName(encodingName)) + if (auto payloadType = payloadTypeForEncodingName(encodingName.toString())) gst_structure_set(codecStructure, "payload", G_TYPE_INT, *payloadType, nullptr); } @@ -661,7 +660,7 @@ GRefPtr capsFromSDPMedia(const GstSDPMedia* media) "a-sendonly", "a-recvonly", "a-end-of-candidates", nullptr); if (auto name = gstStructureGetString(structure, "encoding-name"_s)) { - auto encodingName = name.convertToASCIIUppercase(); + auto encodingName = name.toString().convertToASCIIUppercase(); gst_structure_set(structure, "encoding-name", G_TYPE_STRING, encodingName.ascii().data(), nullptr); } diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.h b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.h index e6f38a89d7136..a21a99aac017f 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.h +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.h @@ -283,7 +283,7 @@ class UniqueSSRCGenerator : public ThreadSafeRefCounted { Vector m_knownIds WTF_GUARDED_BY_LOCK(m_lock); }; -std::optional payloadTypeForEncodingName(StringView encodingName); +std::optional payloadTypeForEncodingName(const String& encodingName); WARN_UNUSED_RETURN GRefPtr capsFromRtpCapabilities(const RTCRtpCapabilities&, Function supplementCapsCallback); diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp index a3976fb1c5e56..7a4fbb5c29292 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp @@ -111,15 +111,15 @@ namespace WebCore { static GstClockTime s_webkitGstInitTime; -WARN_UNUSED_RETURN GstPad* webkitGstGhostPadFromStaticTemplate(GstStaticPadTemplate* staticPadTemplate, ASCIILiteral name, GstPad* target) +WARN_UNUSED_RETURN GstPad* webkitGstGhostPadFromStaticTemplate(GstStaticPadTemplate* staticPadTemplate, CStringView name, GstPad* target) { GstPad* pad; GRefPtr padTemplate = gst_static_pad_template_get(staticPadTemplate); if (target) - pad = gst_ghost_pad_new_from_template(name.characters(), target, padTemplate.get()); + pad = gst_ghost_pad_new_from_template(name.utf8(), target, padTemplate.get()); else - pad = gst_ghost_pad_new_no_target_from_template(name.characters(), padTemplate.get()); + pad = gst_ghost_pad_new_no_target_from_template(name.utf8(), padTemplate.get()); return pad; } @@ -279,7 +279,7 @@ std::optional parseStreamId(StringView stringId) return parseIntegerAllowingTrailingJunk(stringId.substring(position + 1)); } -StringView capsMediaType(const GstCaps* caps) +CStringView capsMediaType(const GstCaps* caps) { ASSERT(caps); GstStructure* structure = gst_caps_get_structure(caps, 0); @@ -304,7 +304,7 @@ bool doCapsHaveType(const GstCaps* caps, ASCIILiteral type) GST_WARNING("Failed to get MediaType"); return false; } - return mediaType.startsWith(type); + return mediaType.toString().startsWith(type); } bool areEncryptedCaps(const GstCaps* caps) @@ -1089,13 +1089,7 @@ static ASCIILiteral webrtcStatsTypeName(int value) #endif template -std::optional gstStructureGet(const GstStructure* structure, ASCIILiteral key) -{ - return gstStructureGet(structure, StringView { key }); -} - -template -std::optional gstStructureGet(const GstStructure* structure, StringView key) +std::optional gstStructureGet(const GstStructure* structure, CStringView key) { if (!structure) { ASSERT_NOT_REACHED_WITH_MESSAGE("tried to access a field of a null GstStructure"); @@ -1103,25 +1097,24 @@ std::optional gstStructureGet(const GstStructure* structure, StringView key) } T value; - auto strKey = key.toStringWithoutCopying(); if constexpr(std::is_same_v) { - if (gst_structure_get_int(structure, strKey.ascii().data(), &value)) + if (gst_structure_get_int(structure, key.utf8(), &value)) return value; } else if constexpr(std::is_same_v) { - if (gst_structure_get_int64(structure, strKey.ascii().data(), &value)) + if (gst_structure_get_int64(structure, key.utf8(), &value)) return value; } else if constexpr(std::is_same_v) { - if (gst_structure_get_uint(structure, strKey.ascii().data(), &value)) + if (gst_structure_get_uint(structure, key.utf8(), &value)) return value; } else if constexpr(std::is_same_v) { - if (gst_structure_get_uint64(structure, strKey.ascii().data(), &value)) + if (gst_structure_get_uint64(structure, key.utf8(), &value)) return value; } else if constexpr(std::is_same_v) { - if (gst_structure_get_double(structure, strKey.ascii().data(), &value)) + if (gst_structure_get_double(structure, key.utf8(), &value)) return value; } else if constexpr(std::is_same_v) { gboolean gstValue; - if (gst_structure_get_boolean(structure, strKey.ascii().data(), &gstValue)) { + if (gst_structure_get_boolean(structure, key.utf8(), &gstValue)) { value = gstValue; return value; } @@ -1130,60 +1123,45 @@ std::optional gstStructureGet(const GstStructure* structure, StringView key) return std::nullopt; } -template std::optional gstStructureGet(const GstStructure*, ASCIILiteral key); -template std::optional gstStructureGet(const GstStructure*, ASCIILiteral key); -template std::optional gstStructureGet(const GstStructure*, ASCIILiteral key); -template std::optional gstStructureGet(const GstStructure*, ASCIILiteral key); -template std::optional gstStructureGet(const GstStructure*, ASCIILiteral key); -template std::optional gstStructureGet(const GstStructure*, ASCIILiteral key); - -template std::optional gstStructureGet(const GstStructure*, StringView key); -template std::optional gstStructureGet(const GstStructure*, StringView key); -template std::optional gstStructureGet(const GstStructure*, StringView key); -template std::optional gstStructureGet(const GstStructure*, StringView key); -template std::optional gstStructureGet(const GstStructure*, StringView key); -template std::optional gstStructureGet(const GstStructure*, StringView key); +template std::optional gstStructureGet(const GstStructure*, CStringView key); +template std::optional gstStructureGet(const GstStructure*, CStringView key); +template std::optional gstStructureGet(const GstStructure*, CStringView key); +template std::optional gstStructureGet(const GstStructure*, CStringView key); +template std::optional gstStructureGet(const GstStructure*, CStringView key); +template std::optional gstStructureGet(const GstStructure*, CStringView key); -StringView gstStructureGetString(const GstStructure* structure, ASCIILiteral key) +CStringView gstStructureGetString(const GstStructure* structure, CStringView key) { if (!structure) { ASSERT_NOT_REACHED_WITH_MESSAGE("tried to access a field of a null GstStructure"); return { }; } - return gstStructureGetString(structure, StringView { key }); -} - -StringView gstStructureGetString(const GstStructure* structure, StringView key) -{ - if (!structure) { - ASSERT_NOT_REACHED_WITH_MESSAGE("tried to access a field of a null GstStructure"); + const GValue* value = gst_structure_get_value(structure, key.utf8()); + if (!value || !G_VALUE_HOLDS_STRING(value)) return { }; - } - - auto utf8String = key.utf8(); - return StringView::fromLatin1(gst_structure_get_string(structure, utf8String.data())); + return CStringView::unsafeFromUTF8(g_value_get_string(value)); } -StringView gstStructureGetName(const GstStructure* structure) +CStringView gstStructureGetName(const GstStructure* structure) { if (!structure) { ASSERT_NOT_REACHED_WITH_MESSAGE("tried to access a field of a null GstStructure"); return { }; } - return StringView::fromLatin1(gst_structure_get_name(structure)); + return CStringView::unsafeFromUTF8(gst_structure_get_name(structure)); } template -Vector gstStructureGetArray(const GstStructure* structure, ASCIILiteral key) +Vector gstStructureGetArray(const GstStructure* structure, CStringView key) { static_assert(std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v); Vector result; if (!structure) return result; - const GValue* array = gst_structure_get_value(structure, key.characters()); + const GValue* array = gst_structure_get_value(structure, key.utf8()); if (!GST_VALUE_HOLDS_ARRAY (array)) return result; unsigned size = gst_value_array_get_size(array); @@ -1205,7 +1183,7 @@ Vector gstStructureGetArray(const GstStructure* structure, ASCIILiteral key) return result; } -template Vector gstStructureGetArray(const GstStructure*, ASCIILiteral key); +template Vector gstStructureGetArray(const GstStructure*, CStringView key); static RefPtr gstStructureToJSON(const GstStructure*); diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h index 40164732c67c5..a8007025f4d5d 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace WebCore { @@ -66,13 +67,13 @@ inline bool webkitGstCheckVersion(guint major, guint minor, guint micro) #define GST_AUDIO_CAPS_TYPE_PREFIX "audio/"_s #define GST_TEXT_CAPS_TYPE_PREFIX "text/"_s -WARN_UNUSED_RETURN GstPad* webkitGstGhostPadFromStaticTemplate(GstStaticPadTemplate*, ASCIILiteral name, GstPad* target); +WARN_UNUSED_RETURN GstPad* webkitGstGhostPadFromStaticTemplate(GstStaticPadTemplate*, CStringView name, GstPad* target); #if ENABLE(VIDEO) bool getVideoSizeAndFormatFromCaps(const GstCaps*, WebCore::IntSize&, GstVideoFormat&, int& pixelAspectRatioNumerator, int& pixelAspectRatioDenominator, int& stride); std::optional getVideoResolutionFromCaps(const GstCaps*); bool getSampleVideoInfo(GstSample*, GstVideoInfo&); #endif -StringView capsMediaType(const GstCaps*); +CStringView capsMediaType(const GstCaps*); std::optional getStreamIdFromPad(const GRefPtr&); std::optional getStreamIdFromStream(const GRefPtr&); std::optional parseStreamId(StringView stringId); @@ -285,17 +286,14 @@ GstBuffer* gstBufferNewWrappedFast(void* data, size_t length); GstElement* makeGStreamerElement(ASCIILiteral factoryName, const String& name = emptyString()); template -std::optional gstStructureGet(const GstStructure*, ASCIILiteral key); -template -std::optional gstStructureGet(const GstStructure*, StringView key); +std::optional gstStructureGet(const GstStructure*, CStringView key); -StringView gstStructureGetString(const GstStructure*, ASCIILiteral key); -StringView gstStructureGetString(const GstStructure*, StringView key); +CStringView gstStructureGetString(const GstStructure*, CStringView key); -StringView gstStructureGetName(const GstStructure*); +CStringView gstStructureGetName(const GstStructure*); template -Vector gstStructureGetArray(const GstStructure*, ASCIILiteral key); +Vector gstStructureGetArray(const GstStructure*, CStringView key); String gstStructureToJSONString(const GstStructure*); diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp index 5fec3d807d1d8..949b9ffa4c5e5 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp @@ -880,7 +880,7 @@ MediaPlayerEnums::SupportsType GStreamerRegistryScanner::isContentTypeSupported( } auto structure = gst_caps_get_structure(codecCaps.get(), 0); auto name = gstStructureGetName(structure); - auto caps = adoptGRef(gst_caps_new_simple("application/x-webm-enc", "original-media-type", G_TYPE_STRING, reinterpret_cast(name.rawCharacters()), nullptr)); + auto caps = adoptGRef(gst_caps_new_simple("application/x-webm-enc", "original-media-type", G_TYPE_STRING, name.utf8(), nullptr)); if (!factories.hasElementForCaps(ElementFactories::Type::Decryptor, caps)) return SupportsType::IsNotSupported; } diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp index 3823f92a65bf2..f14557ffe69c8 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameConverter.cpp @@ -118,9 +118,9 @@ GRefPtr GStreamerVideoFrameConverter::convert(const GRefPtr(structure, "width"_s); auto height = gstStructureGet(structure, "height"_s); - auto formatStringView = gstStructureGetString(structure, "format"_s); - if (width && height && !formatStringView.isEmpty()) { - auto format = gst_video_format_from_string(formatStringView.toStringWithoutCopying().ascii().data()); + auto formatString = gstStructureGetString(structure, "format"_s); + if (width && height && !formatString.isEmpty()) { + auto format = gst_video_format_from_string(formatString.utf8()); gst_buffer_add_video_meta(writableBuffer.get(), GST_VIDEO_FRAME_FLAG_NONE, format, *width, *height); } gst_sample_set_buffer(convertedSample.get(), writableBuffer.get()); diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp index 8a19a5f77e318..c600f224acace 100644 --- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp @@ -2223,7 +2223,7 @@ void MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message) if (gst_structure_has_name(structure, "http-headers")) { GST_DEBUG_OBJECT(pipeline(), "Processing HTTP headers: %" GST_PTR_FORMAT, structure); if (auto uri = gstStructureGetString(structure, "uri"_s)) { - URL url { makeString(uri) }; + URL url { uri.toString() }; if (url != m_url) { GST_DEBUG_OBJECT(pipeline(), "Ignoring HTTP response headers for non-main URI."); @@ -2248,7 +2248,7 @@ void MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message) // handle it here, until we remove the webkit+ protocol // prefix from webkitwebsrc. if (auto contentLengthValue = gstStructureGetString(responseHeaders.get(), contentLengthHeaderName)) { - if (auto parsedContentLength = parseInteger(contentLengthValue)) + if (auto parsedContentLength = parseInteger(contentLengthValue.toString())) contentLength = *parsedContentLength; } } else @@ -3021,7 +3021,7 @@ bool MediaPlayerPrivateGStreamer::loadNextLocation() return false; const GValue* locations = gst_structure_get_value(m_mediaLocations.get(), "locations"); - StringView newLocation; + CStringView newLocation; if (!locations) { // Fallback on new-location string. @@ -3030,7 +3030,7 @@ bool MediaPlayerPrivateGStreamer::loadNextLocation() return false; } - if (!newLocation) { + if (newLocation.isEmpty()) { if (m_mediaLocationCurrentIndex < 0) { m_mediaLocations.reset(); return false; @@ -3047,11 +3047,11 @@ bool MediaPlayerPrivateGStreamer::loadNextLocation() newLocation = gstStructureGetString(structure, "new-location"_s); } - if (newLocation) { + if (!newLocation.isEmpty()) { // Found a candidate. new-location is not always an absolute url // though. We need to take the base of the current url and // append the value of new-location to it. - auto locationString = makeString(newLocation); + auto locationString = newLocation.toString(); URL baseURL = gst_uri_is_valid(locationString.utf8().data()) ? URL() : m_url; URL newURL = URL(baseURL, WTFMove(locationString)); diff --git a/Source/WebCore/platform/graphics/gstreamer/VideoEncoderGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/VideoEncoderGStreamer.cpp index 45a8c89271ea9..4ace137b3cf2e 100644 --- a/Source/WebCore/platform/graphics/gstreamer/VideoEncoderGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/VideoEncoderGStreamer.cpp @@ -193,7 +193,7 @@ static std::optional retrieveTemporalIndex(const GRefPtr& s } #ifndef GST_DISABLE_GST_DEBUG auto name = gstStructureGetName(structure); - GST_TRACE("Retrieval of temporal index from encoded format %s is not yet supported.", reinterpret_cast(name.rawCharacters())); + GST_TRACE("Retrieval of temporal index from encoded format %s is not yet supported.", name.utf8()); #endif #else UNUSED_PARAM(sample); diff --git a/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp index 69c0a1c7caa9d..7c40dfdc375d4 100644 --- a/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp @@ -156,7 +156,7 @@ static GstCaps* transformCaps(GstBaseTransform* base, GstPadDirection direction, if (!canDoPassthrough) { auto originalMediaType = WebCore::gstStructureGetString(outgoingStructure.get(), "original-media-type"_s); RELEASE_ASSERT(originalMediaType); - gst_structure_set_name(outgoingStructure.get(), static_cast(originalMediaType.rawCharacters())); + gst_structure_set_name(outgoingStructure.get(), originalMediaType.utf8()); } // Filter out the DRM related fields from the down-stream caps. @@ -171,7 +171,7 @@ static GstCaps* transformCaps(GstBaseTransform* base, GstPadDirection direction, auto name = WebCore::gstStructureGetName(incomingStructure); gst_structure_set(outgoingStructure.get(), "protection-system", G_TYPE_STRING, klass->protectionSystemId(self), - "original-media-type", G_TYPE_STRING, reinterpret_cast(name.rawCharacters()) , nullptr); + "original-media-type", G_TYPE_STRING, name.utf8() , nullptr); // GST_PROTECTION_UNSPECIFIED_SYSTEM_ID was added in the GStreamer // developement git master which will ship as version 1.16.0. @@ -269,7 +269,7 @@ static GstFlowReturn transformInPlace(GstBaseTransform* base, GstBuffer* buffer) bool isCbcs = false; if (auto cipherMode = WebCore::gstStructureGetString(protectionMeta->info, "cipher-mode"_s)) - isCbcs = WTF::equalIgnoringASCIICase(cipherMode, "cbcs"_s); + isCbcs = WTF::equalIgnoringASCIICase(cipherMode.toString(), "cbcs"_s); auto ivSizeFromMeta = WebCore::gstStructureGet(protectionMeta->info, "iv_size"_s); if (!ivSizeFromMeta) { diff --git a/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp b/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp index 9d18463536dd6..7b884b640d69b 100644 --- a/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp @@ -226,12 +226,12 @@ AppendPipeline::AppendPipeline(SourceBufferPrivateGStreamer& sourceBufferPrivate if (demuxerElementName.isNull()) { GST_ELEMENT_ERROR(appendPipeline->pipeline(), STREAM, WRONG_TYPE, ("Unsupported caps for audio/mpeg mimetype: %s", - gstStructureGetName(capsStructure).toStringWithoutCopying().utf8().data()), (nullptr)); + gstStructureGetName(capsStructure).utf8()), (nullptr)); return; } GST_DEBUG_OBJECT(appendPipeline->pipeline(), "Creating %s demuxer for caps: %s", - demuxerElementName.characters(), gstStructureGetName(capsStructure).toStringWithoutCopying().utf8().data()); + demuxerElementName.characters(), gstStructureGetName(capsStructure).utf8()); appendPipeline->m_demux = makeGStreamerElement(demuxerElementName); ASSERT(appendPipeline->m_demux); @@ -428,11 +428,11 @@ std::tuple, AppendPipeline::StreamType, FloatSize> AppendPipeli auto originalMediaType = capsMediaType(demuxerSrcPadCaps); auto& gstRegistryScanner = GStreamerRegistryScannerMSE::singleton(); auto shouldIgnore = std::find_if(s_ignoreMediaTypes.begin(), s_ignoreMediaTypes.end(), [&originalMediaType](const ASCIILiteral& type) { - return originalMediaType.startsWithIgnoringASCIICase(type); + return originalMediaType.toString().startsWithIgnoringASCIICase(type); }) != s_ignoreMediaTypes.end(); if (shouldIgnore) { streamType = StreamType::Ignore; - } else if (!gstRegistryScanner.isCodecSupported(GStreamerRegistryScanner::Configuration::Decoding, originalMediaType.toStringWithoutCopying())) { + } else if (!gstRegistryScanner.isCodecSupported(GStreamerRegistryScanner::Configuration::Decoding, originalMediaType.toString())) { streamType = StreamType::Invalid; } else if (doCapsHaveType(demuxerSrcPadCaps, GST_VIDEO_CAPS_TYPE_PREFIX)) { presentationSize = getVideoResolutionFromCaps(demuxerSrcPadCaps).value_or(FloatSize()); @@ -466,7 +466,7 @@ void AppendPipeline::appsinkCapsChanged(Track& track) auto currentMediaType = capsMediaType(caps.get()); auto trackMediaType = capsMediaType(track.caps.get()); if (track.caps && currentMediaType != trackMediaType) { - GST_WARNING_OBJECT(pipeline(), "Track received incompatible caps, received '%s' for a track previously handling '%s'. Erroring out.", reinterpret_cast(currentMediaType.rawCharacters()), reinterpret_cast(trackMediaType.rawCharacters())); + GST_WARNING_OBJECT(pipeline(), "Track received incompatible caps, received '%s' for a track previously handling '%s'. Erroring out.", currentMediaType.utf8(), trackMediaType.utf8()); m_sourceBufferPrivate.appendParsingFailed(); return; } diff --git a/Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp b/Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp index e570425b3482b..4cbb39fc813e7 100644 --- a/Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp @@ -58,7 +58,7 @@ String GStreamerMediaDescription::extractCodecName(const GRefPtr& caps) auto originalMediaType = WebCore::gstStructureGetString(structure, "original-media-type"_s); RELEASE_ASSERT(originalMediaType); - gst_structure_set_name(structure, originalMediaType.toStringWithoutCopying().ascii().data()); + gst_structure_set_name(structure, originalMediaType.utf8()); // Remove the DRM related fields from the caps. for (int j = 0; j < gst_structure_n_fields(structure); ++j) { diff --git a/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp b/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp index 064eb9fdc5ea7..93deb612372a1 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp @@ -646,7 +646,7 @@ String MermaidBuilder::describeCaps(const GRefPtr& caps) for (unsigned i = 0; i < capsSize; i++) { auto* features = gst_caps_get_features(caps.get(), i); const auto* structure = gst_caps_get_structure(caps.get(), i); - builder.append(gstStructureGetName(structure), "
"_s); + builder.append(gstStructureGetName(structure).toString(), "
"_s); if (features && (gst_caps_features_is_any(features) || !gst_caps_features_is_equal(features, GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) { GUniquePtr serializedFeature(gst_caps_features_to_string(features)); builder.append('(', WTF::span(serializedFeature.get()), ')'); diff --git a/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp b/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp index 3a5f138a08663..4a177cde4f76a 100644 --- a/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp +++ b/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp @@ -665,7 +665,7 @@ static void webkit_video_encoder_class_init(WebKitVideoEncoderClass* klass) const auto& encodedCaps = self->priv->encodedCaps; if (LIKELY(!gst_caps_is_any(encodedCaps.get()) && !gst_caps_is_empty(encodedCaps.get()))) { auto structure = gst_caps_get_structure(encodedCaps.get(), 0); - auto profile = gstStructureGetString(structure, "profile"_s); + auto profile = gstStructureGetString(structure, "profile"_s).toString(); if (profile.findIgnoringASCIICase("high"_s) != notFound) gst_preset_load_preset(GST_PRESET(self->priv->encoder.get()), "Profile High"); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp index 95efb4f8a6c65..52d410ef4a1a6 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp @@ -42,8 +42,9 @@ RefPtr GStreamerAudioRTPPacketizer::create(RefPtr GStreamerAudioRTPPacketizer::create(RefPtr(encodingParameters)) + if (auto channels = parseIntegerAllowingTrailingJunk(encodingParameters.toString())) inputCaps = adoptGRef(gst_caps_new_simple("audio/x-raw", "channels", G_TYPE_INT, *channels, nullptr)); } } @@ -115,7 +116,7 @@ RefPtr GStreamerAudioRTPPacketizer::create(RefPtr(minPTime)) { + if (auto value = parseIntegerAllowingTrailingJunk(minPTime.toString())) { if (gstObjectHasProperty(payloader.get(), "min-ptime"_s)) g_object_set(payloader.get(), "min-ptime", *value * GST_MSECOND, nullptr); else diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp index 247f1d9a24a9d..59a1c93113124 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp @@ -209,7 +209,7 @@ void GStreamerCaptureDeviceManager::addDevice(GRefPtr&& device) auto identifier = label; bool isMock = false; if (auto persistentId = gstStructureGetString(properties.get(), "persistent-id"_s)) { - identifier = makeString(persistentId); + identifier = persistentId.toString(); isMock = true; } diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp index 699d4c2f5893d..f1ee99955e7fd 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp @@ -68,17 +68,18 @@ void GStreamerIncomingTrackProcessor::configure(ThreadSafeWeakPtr(structure, "ssrc"_s)) { m_data.ssrc = *ssrc; auto msIdAttributeName = makeString("ssrc-"_s, *ssrc, "-msid"_s); - if (auto msIdAttribute = gstStructureGetString(structure, msIdAttributeName)) { - auto components = msIdAttribute.toStringWithoutCopying().split(' '); + if (auto msIdAttribute = gstStructureGetString(structure, CStringView::unsafeFromUTF8(msIdAttributeName.utf8().data()))) { + auto components = msIdAttribute.toString().split(' '); if (components.size() == 2) m_sdpMsIdAndTrackId = { components[0], components[1] }; } } - if (auto msIdAttribute = gstStructureGetString(structure, "a-msid"_s)) { + auto msIdAttribute = gstStructureGetString(structure, "a-msid"_s).toString(); + if (!msIdAttribute.isEmpty()) { if (msIdAttribute.startsWith(' ')) - m_sdpMsIdAndTrackId = { emptyString(), msIdAttribute.substring(1).toString() }; + m_sdpMsIdAndTrackId = { emptyString(), msIdAttribute.substring(1) }; else { - auto components = msIdAttribute.toStringWithoutCopying().split(' '); + auto components = msIdAttribute.split(' '); if (components.size() == 2) m_sdpMsIdAndTrackId = { components[0], components[1] }; } @@ -187,7 +188,7 @@ GRefPtr GStreamerIncomingTrackProcessor::incomingTrackProcessor() if (!forceEarlyVideoDecoding) { auto structure = gst_caps_get_structure(m_data.caps.get(), 0); ASSERT(gst_structure_has_name(structure, "application/x-rtp")); - auto encodingName = gstStructureGetString(structure, "encoding-name"_s); + auto encodingName = gstStructureGetString(structure, "encoding-name"_s).toString(); auto mediaType = makeString("video/x-"_s, encodingName.convertToASCIILowercase()); auto codecCaps = adoptGRef(gst_caps_new_empty_simple(mediaType.ascii().data())); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp index 7957a4580d0e0..593a6d8f03fda 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp @@ -1157,7 +1157,7 @@ void webkitMediaStreamSrcAddTrack(WebKitMediaStreamSrc* self, MediaStreamTrackPr GST_DEBUG_OBJECT(self, "%s Ghosting %" GST_PTR_FORMAT, objectPath.get(), pad.get()); #endif - auto* ghostPad = webkitGstGhostPadFromStaticTemplate(padTemplate, ASCIILiteral::fromLiteralUnsafe(padName.ascii().data()), pad.get()); + auto* ghostPad = webkitGstGhostPadFromStaticTemplate(padTemplate, CStringView::unsafeFromUTF8(padName.utf8().data()), pad.get()); gst_pad_store_sticky_event(ghostPad, stickyStreamStartEvent.get()); gst_pad_set_active(ghostPad, TRUE); gst_element_add_pad(GST_ELEMENT_CAST(self), ghostPad); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp index bcac3c260edfb..93ec4d88a756f 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp @@ -349,7 +349,7 @@ void GStreamerVideoCapturer::reconfigure() selector->mimeType = gstStructureGetName(structure).toString(); if (gst_structure_has_name(structure, "video/x-raw")) { if (gst_structure_has_field(structure, "format")) - selector->format = makeString(gstStructureGetString(structure, "format"_s)); + selector->format = gstStructureGetString(structure, "format"_s).toString(); else return TRUE; } @@ -363,7 +363,7 @@ void GStreamerVideoCapturer::reconfigure() selector->mimeType = gstStructureGetName(structure).toString(); if (gst_structure_has_name(structure, "video/x-raw")) { if (gst_structure_has_field(structure, "format")) - selector->format = makeString(gstStructureGetString(structure, "format"_s)); + selector->format = gstStructureGetString(structure, "format"_s).toString(); else return TRUE; } diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp index 3cb88c882e04f..a2a187c4e8ff1 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp @@ -46,8 +46,9 @@ RefPtr GStreamerVideoRTPPacketizer::create(RefPtr GStreamerVideoRTPPacketizer::create(RefPtr(vp9Profile)) + if (auto profile = parseInteger(vp9Profile.toString())) record.profile = *profile; } codec = createVPCodecParametersString(record); diff --git a/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp b/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp index 0c1682d11b495..332f5cda224b8 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp @@ -378,7 +378,7 @@ void RealtimeOutgoingMediaSourceGStreamer::setParameters(GUniquePtr RealtimeOutgoingMediaSourceGStreamer::getPacketizerForRid(StringView rid) +RefPtr RealtimeOutgoingMediaSourceGStreamer::getPacketizerForRid(const String& rid) { for (auto& packetizer : m_packetizers) { if (packetizer->rtpStreamId() == rid) diff --git a/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.h b/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.h index f6c2be9abfd12..d84052da0069e 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.h +++ b/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.h @@ -143,7 +143,7 @@ class RealtimeOutgoingMediaSourceGStreamer : public ThreadSafeRefCountedAndCanMa void startUpdatingStats(); void stopUpdatingStats(); - RefPtr getPacketizerForRid(StringView); + RefPtr getPacketizerForRid(const String&); }; } // namespace WebCore diff --git a/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm b/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm index d00680b1f33a9..8573edb877997 100644 --- a/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm +++ b/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm @@ -664,7 +664,7 @@ static void addAnimationToLayer(CALayer *layer, RemoteLayerTreeHost* layerTreeHo ts.dumpProperty("fillMode", animation.fillMode); ts.dumpProperty("valueFunction", animation.valueFunction); if (animation.timingFunction) - ts.dumpProperty("timing function", *animation.timingFunction); + ts.dumpProperty("timing function"_s, *animation.timingFunction); if (animation.autoReverses) ts.dumpProperty("autoReverses", animation.autoReverses); @@ -698,7 +698,7 @@ static void addAnimationToLayer(CALayer *layer, RemoteLayerTreeHost* layerTreeHo ts.dumpProperty("time", animation.keyTimes[i]); if (i < animation.timingFunctions.size()) - ts.dumpProperty("timing function", animation.timingFunctions[i]); + ts.dumpProperty("timing function"_s, animation.timingFunctions[i]); if (i < animation.keyValues.size()) { ts.startGroup(); diff --git a/Tools/TestWebKitAPI/CMakeLists.txt b/Tools/TestWebKitAPI/CMakeLists.txt index 5519a570affe7..b47433728fac4 100644 --- a/Tools/TestWebKitAPI/CMakeLists.txt +++ b/Tools/TestWebKitAPI/CMakeLists.txt @@ -32,6 +32,7 @@ set(TestWTF_SOURCES Tests/WTF/BoxPtr.cpp Tests/WTF/BumpPointerAllocator.cpp Tests/WTF/CString.cpp + Tests/WTF/CStringView.cpp Tests/WTF/CharacterProperties.cpp Tests/WTF/CheckedArithmeticOperations.cpp Tests/WTF/CompactPtr.cpp diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj index 4707fdcf2c8c9..37033022b61a5 100644 --- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj +++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj @@ -1045,6 +1045,7 @@ CD8394DF232AF7C000149495 /* media-loading.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD8394DE232AF15E00149495 /* media-loading.html */; }; CD9E292E1C90C33F000BB800 /* audio-only.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD9E292D1C90C1BA000BB800 /* audio-only.html */; }; CDA29B2B20FD358400F15CED /* ExitFullscreenOnEnterPiP.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */; }; + CD930D7E2D9EAC9F00507B6B /* CStringView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD930D7D2D9EAC9F00507B6B /* CStringView.cpp */; }; CDA315981ED53651009F60D3 /* MediaPlaybackSleepAssertion.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDA315961ED53651009F60D3 /* MediaPlaybackSleepAssertion.mm */; }; CDA3159A1ED548F1009F60D3 /* MediaPlaybackSleepAssertion.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDA315991ED540A5009F60D3 /* MediaPlaybackSleepAssertion.html */; }; CDA3159D1ED5643F009F60D3 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA3159C1ED5643F009F60D3 /* IOKit.framework */; }; @@ -3396,6 +3397,7 @@ CD7F89DB22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewSuspendAllMediaPlayback.mm; sourceTree = ""; }; CD8394DE232AF15E00149495 /* media-loading.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "media-loading.html"; sourceTree = ""; }; CD89D0381C4EDB2A00040A04 /* WebCoreNSURLSession.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSURLSession.mm; sourceTree = ""; }; + CD930D7D2D9EAC9F00507B6B /* CStringView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CStringView.cpp; sourceTree = ""; }; CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RequiresUserActionForPlayback.mm; sourceTree = ""; }; CD9E292D1C90C1BA000BB800 /* audio-only.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "audio-only.html"; sourceTree = ""; }; CDA29B2820FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ExitFullscreenOnEnterPiP.mm; sourceTree = ""; }; @@ -5426,6 +5428,7 @@ 278DE64B22B8D611004E0E7A /* CrossThreadCopierTests.cpp */, 51714EB91D087416004723C4 /* CrossThreadTask.cpp */, 26A2C72E15E2E73C005B1A14 /* CString.cpp */, + CD930D7D2D9EAC9F00507B6B /* CStringView.cpp */, 7AA021BA1AB09EA70052953F /* DateMath.cpp */, 1A3524A91D627BD40031729B /* DeletedAddressOfOperator.h */, E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */, @@ -6425,6 +6428,7 @@ 7C83DEA61D0A590C00FEBCF3 /* Counters.cpp in Sources */, 5C2C01A82734883600F89D37 /* CrossThreadCopierTests.cpp in Sources */, 7C83DEA91D0A590C00FEBCF3 /* CString.cpp in Sources */, + CD930D7E2D9EAC9F00507B6B /* CStringView.cpp in Sources */, 7C83DEAD1D0A590C00FEBCF3 /* Deque.cpp in Sources */, FFD3FF372AF9BD8F0057C508 /* DragonBoxTest.cpp in Sources */, E36B87A3276221870059D2F9 /* EmbeddedFixedVector.cpp in Sources */, diff --git a/Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp b/Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp new file mode 100644 index 0000000000000..9423a3511da26 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2025 Comcast Inc. + * Copyright (C) 2025 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include + +#include +#include + +namespace TestWebKitAPI { + +TEST(WTF, CStringViewNullAndEmpty) +{ + CStringView string; + EXPECT_TRUE(string.isNull()); + EXPECT_TRUE(string.isEmpty()); + EXPECT_EQ(string.utf8(), nullptr); + EXPECT_TRUE(!string); + EXPECT_FALSE(string); + + string = CStringView(nullptr); + EXPECT_TRUE(string.isNull()); + EXPECT_TRUE(string.isEmpty()); + EXPECT_EQ(string.utf8(), nullptr); + EXPECT_TRUE(!string); + EXPECT_FALSE(string); + + string = CStringView(""_s); + EXPECT_TRUE(string.isNull()); + EXPECT_TRUE(string.isEmpty()); + EXPECT_EQ(string.utf8(), nullptr); + EXPECT_TRUE(!string); + EXPECT_FALSE(string); + + string = CStringView("test"_s); + EXPECT_FALSE(string.isNull()); + EXPECT_FALSE(string.isEmpty()); + EXPECT_TRUE(string.utf8()); + EXPECT_FALSE(!string); + EXPECT_TRUE(string); +} + +TEST(WTF, CStringViewLength) +{ + CStringView string; + EXPECT_EQ(string.length(), static_cast(0)); + EXPECT_EQ(string.span8().size(), static_cast(0)); + + string = CStringView("test"_s); + EXPECT_EQ(string.length(), static_cast(4)); + EXPECT_EQ(string.span8().size(), static_cast(4)); +} + +TEST(WTF, CStringViewFrom) +{ + const char* stringPtr = "test"; + CStringView string = CStringView::unsafeFromUTF8(stringPtr); + EXPECT_EQ(string.length(), static_cast(4)); + EXPECT_TRUE(string); + EXPECT_EQ(string.utf8(), stringPtr); + + stringPtr = ""; + string = CStringView::unsafeFromUTF8(stringPtr); + EXPECT_EQ(string.length(), static_cast(0)); + EXPECT_FALSE(string); + EXPECT_EQ(string.utf8(), stringPtr); +} + +TEST(WTF, CStringViewEquality) +{ + CStringView string("Test"_s); + CStringView sameString("Test"_s); + CStringView anotherString("another test"_s); + CStringView emptyString; + CStringView nullString(nullptr); + EXPECT_TRUE(string != emptyString); + EXPECT_EQ(string, string); + EXPECT_EQ(string, sameString); + EXPECT_TRUE(string != anotherString); + EXPECT_EQ(emptyString, nullString); +} + +} // namespace TestWebKitAPI From a3ca13714766441c78ce24c0ce0f6aaa1a425952 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Tue, 1 Jul 2025 08:58:35 -0700 Subject: [PATCH 09/22] JSC: Replace UChar with char16_t https://bugs.webkit.org/show_bug.cgi?id=294724 rdar://153818709 Reviewed by Alex Christensen. WebKit wishes to move from UChar to the C++ standard char16_t; they are currently typedef'ed to be the same. This PR makes the textual substitutions across JavaScriptCore. This is a simple search and replace for \bUChar\b with no other changes, and it should have no functional effect. This is one of a series of PRs for different parts of WebKit. * Source/JavaScriptCore/API/JSStringRef.cpp: (JSStringCreateWithCharacters): (JSStringCreateWithUTF8CString): (JSStringCreateWithCharactersNoCopy): * Source/JavaScriptCore/API/JSStringRefCF.cpp: (JSStringCreateWithCFString): * Source/JavaScriptCore/API/JSValueRef.cpp: (JSValueMakeFromJSONString): * Source/JavaScriptCore/API/OpaqueJSString.cpp: (OpaqueJSString::~OpaqueJSString): (OpaqueJSString::characters): * Source/JavaScriptCore/API/OpaqueJSString.h: (OpaqueJSString::create): (OpaqueJSString::OpaqueJSString): * Source/JavaScriptCore/API/glib/JSCValue.cpp: (jsc_value_new_from_json): * Source/JavaScriptCore/API/tests/JSONParseTest.cpp: (testJSONParse): * Source/JavaScriptCore/KeywordLookupGenerator.py: (Trie.printAsC): * Source/JavaScriptCore/builtins/BuiltinNames.cpp: (JSC::BuiltinNames::lookUpPrivateName const): (JSC::BuiltinNames::lookUpWellKnownSymbol const): * Source/JavaScriptCore/builtins/BuiltinNames.h: * Source/JavaScriptCore/bytecode/CodeBlockHash.cpp: (JSC::CodeBlockHash::CodeBlockHash): * Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter::executeEffects): * Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp: (JSC::DFG::equalToSingleCharacter): * Source/JavaScriptCore/dfg/DFGLazyJSValue.h: (JSC::DFG::LazyJSValue::singleCharacterString): (JSC::DFG::LazyJSValue::character const): * Source/JavaScriptCore/dfg/DFGOperations.cpp: (JSC::DFG::JSC_DEFINE_JIT_OPERATION): * Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp: * Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.h: * Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileStringIndexOf): * Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp: (Inspector::ContentSearchUtilities::escapeStringForRegularExpressionSource): * Source/JavaScriptCore/interpreter/Interpreter.cpp: (JSC::eval): (JSC::Interpreter::executeProgram): * Source/JavaScriptCore/jsc.cpp: (pathSeparator): * Source/JavaScriptCore/parser/Lexer.cpp: (JSC::isSingleCharacterIdentStart): (JSC::cannotBeIdentStart): (JSC::isSingleCharacterIdentPart): (JSC::cannotBeIdentPartOrEscapeStart): (JSC::Lexer::currentCodePoint const): (JSC::Lexer::append16): (JSC::Lexer::record16): (JSC::Lexer::recordUnicodeCodePoint): (JSC::Lexer::parseIdentifier): (JSC::characterRequiresParseStringSlowCase): (JSC::Lexer::parseCommentDirectiveValue): (JSC::orCharacter): (JSC::orCharacter): (JSC::Lexer::scanRegExp): (JSC::Lexer::clear): (JSC::Lexer::currentCodePoint const): Deleted. (JSC::Lexer::parseIdentifier): Deleted. (JSC::orCharacter): Deleted. * Source/JavaScriptCore/parser/Lexer.h: (JSC::Lexer::append16): (JSC::Lexer::isWhiteSpace): (JSC::Lexer::isLineTerminator): (JSC::Lexer::convertUnicode): (JSC::Lexer::makeRightSizedIdentifier): (JSC::Lexer::makeRightSizedIdentifier): (JSC::Lexer::setCodeStart): (JSC::Lexer::makeIdentifierLCharFromUChar): (JSC::Lexer::makeLCharIdentifier): (JSC::Lexer::isWhiteSpace): Deleted. (JSC::Lexer::isLineTerminator): Deleted. (JSC::Lexer::makeRightSizedIdentifier): Deleted. (JSC::Lexer::setCodeStart): Deleted. * Source/JavaScriptCore/parser/Parser.cpp: * Source/JavaScriptCore/parser/Parser.h: (JSC::parse): (JSC::parseRootNode): (JSC::parseFunctionForFunctionConstructor): * Source/JavaScriptCore/parser/ParserArena.h: (JSC::IdentifierArena::makeIdentifierLCharFromUChar): * Source/JavaScriptCore/runtime/ArrayPrototype.cpp: (JSC::sortBucketSort): * Source/JavaScriptCore/runtime/CachedTypes.cpp: (JSC::CachedUniquedStringImplBase::span16 const): * Source/JavaScriptCore/runtime/ExceptionHelpers.cpp: (JSC::functionCallBase): * Source/JavaScriptCore/runtime/ISO8601.cpp: (JSC::ISO8601::canBeTimeZone): (JSC::ISO8601::parseTimeZoneAnnotation): (JSC::ISO8601::parseTimeZone): * Source/JavaScriptCore/runtime/Identifier.cpp: (JSC::Identifier::add8): * Source/JavaScriptCore/runtime/Identifier.h: (JSC::Identifier::createLCharFromUChar): (JSC::Identifier::canUseSingleCharacterString): (JSC::Identifier::equal): * Source/JavaScriptCore/runtime/IdentifierInlines.h: (JSC::Identifier::Identifier): (JSC::Identifier::fromString): * Source/JavaScriptCore/runtime/IntlCache.cpp: (JSC::IntlCache::getBestDateTimePattern): (JSC::IntlCache::getFieldDisplayName): * Source/JavaScriptCore/runtime/IntlCache.h: * Source/JavaScriptCore/runtime/IntlCollator.cpp: (JSC::IntlCollator::checkICULocaleInvariants): * Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp: (JSC::canonicalizeTimeZoneName): (JSC::IntlDateTimeFormat::hourCycleFromSymbol): (JSC::IntlDateTimeFormat::hourCycleFromPattern): (JSC::IntlDateTimeFormat::replaceHourCycleInSkeleton): (JSC::IntlDateTimeFormat::replaceHourCycleInPattern): (JSC::IntlDateTimeFormat::buildSkeleton): (JSC::IntlDateTimeFormat::initializeDateTimeFormat): (JSC::IntlDateTimeFormat::format const): (JSC::IntlDateTimeFormat::formatToParts const): (JSC::IntlDateTimeFormat::createDateIntervalFormatIfNecessary): (JSC::IntlDateTimeFormat::formatRange): (JSC::IntlDateTimeFormat::formatRangeToParts): * Source/JavaScriptCore/runtime/IntlDateTimeFormat.h: * Source/JavaScriptCore/runtime/IntlDisplayNames.cpp: (JSC::IntlDisplayNames::of const): * Source/JavaScriptCore/runtime/IntlDurationFormat.cpp: (JSC::retrieveSeparator): (JSC::collectElements): (JSC::IntlDurationFormat::format const): (JSC::IntlDurationFormat::formatToParts const): * Source/JavaScriptCore/runtime/IntlListFormat.cpp: (JSC::IntlListFormat::format const): (JSC::IntlListFormat::formatToParts const): * Source/JavaScriptCore/runtime/IntlLocale.cpp: (JSC::IntlLocale::hourCycles): * Source/JavaScriptCore/runtime/IntlNumberFormat.cpp: (JSC::IntlNumberFormat::format const): (JSC::IntlNumberFormat::formatRange const): (JSC::IntlNumberFormat::formatRangeToPartsInternal): (JSC::IntlNumberFormat::formatToParts const): * Source/JavaScriptCore/runtime/IntlObject.cpp: (JSC::convertToUnicodeSingletonIndex): (JSC::LanguageTagParser::parseExtensionsAndPUExtensions): * Source/JavaScriptCore/runtime/IntlObjectInlines.h: (JSC::canUseASCIIUCADUCETComparison): (JSC::followedByNonLatinCharacter): (JSC::ListFormatInput::stringPointers const): * Source/JavaScriptCore/runtime/IntlPluralRules.cpp: (JSC::IntlPluralRules::select const): (JSC::IntlPluralRules::selectRange const): * Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.cpp: (JSC::IntlRelativeTimeFormat::formatInternal const): (JSC::IntlRelativeTimeFormat::formatToParts const): * Source/JavaScriptCore/runtime/IntlSegmentIterator.cpp: (JSC::IntlSegmentIterator::create): (JSC::IntlSegmentIterator::IntlSegmentIterator): * Source/JavaScriptCore/runtime/IntlSegmentIterator.h: * Source/JavaScriptCore/runtime/IntlSegmenter.cpp: (JSC::IntlSegmenter::segment const): * Source/JavaScriptCore/runtime/IntlSegments.cpp: (JSC::IntlSegments::create): (JSC::IntlSegments::IntlSegments): * Source/JavaScriptCore/runtime/IntlSegments.h: * Source/JavaScriptCore/runtime/JSDateMath.cpp: (JSC::DateCache::timeZoneDisplayName): (JSC::retrieveTimeZoneInformation): * Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.cpp: (JSC::decodeHex): * Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.h: * Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp: (JSC::decode): (JSC::parseFloat): (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/JSImmutableButterfly.cpp: (JSC::JSImmutableButterfly::createFromString): * Source/JavaScriptCore/runtime/JSONAtomStringCache.h: (JSC::JSONAtomStringCache::cacheSlot): * Source/JavaScriptCore/runtime/JSONAtomStringCacheInlines.h: (JSC::JSONAtomStringCache::makeIdentifier): * Source/JavaScriptCore/runtime/JSONObject.cpp: (JSC::stringCopyUpconvert): (JSC::stringify): (JSC::jsonParseSlow): (JSC::JSC_DEFINE_HOST_FUNCTION): (JSC::JSONParse): (JSC::JSONParseWithException): * Source/JavaScriptCore/runtime/JSString.cpp: (JSC:: const): (JSC::JSRopeString::resolveRopeWithFunction const): * Source/JavaScriptCore/runtime/JSString.h: (JSC::jsSingleCharacterString): * Source/JavaScriptCore/runtime/JSStringInlines.h: (JSC::JSString::tryReplaceOneCharImpl): (JSC::JSString::tryReplaceOneChar): (JSC::jsAtomString): (JSC::jsSubstringOfResolved): * Source/JavaScriptCore/runtime/JSStringJoiner.cpp: (JSC::appendStringToDataWithOneCharacterSeparatorRepeatedly): (JSC::JSStringJoiner::joinImpl): (JSC::JSOnlyStringsAndInt32sJoiner::joinImpl): * Source/JavaScriptCore/runtime/LiteralParser.cpp: (JSC::cannotBeIdentPartOrEscapeStart): (JSC::setParserTokenString): (JSC::isSafeStringCharacter): (JSC::isSafeStringCharacterForIdentifier): (JSC::setParserTokenString): Deleted. * Source/JavaScriptCore/runtime/LiteralParser.h: (JSC::LiteralParserToken::string16 const): * Source/JavaScriptCore/runtime/ParseInt.h: (JSC::parseIntOverflow): (JSC::isStrWhiteSpace): * Source/JavaScriptCore/runtime/RegExp.cpp: (JSC::RegExpFunctionalTestCollector::outputEscapedString): (JSC::appendLineTerminatorEscape): (JSC::appendLineTerminatorEscape): Deleted. * Source/JavaScriptCore/runtime/RegExpObjectInlines.h: (JSC::advanceStringUnicode): * Source/JavaScriptCore/runtime/StringConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): (JSC::stringFromCharCode): * Source/JavaScriptCore/runtime/StringPrototype.cpp: (JSC::substituteBackreferencesSlow): (JSC::JSC_DEFINE_HOST_FUNCTION): (JSC::splitStringByOneCharacterImpl): (JSC::isASCIIIdentifierStart): (JSC::toLocaleCase): (JSC::normalize): (JSC::illFormedIndex): * Source/JavaScriptCore/runtime/StringPrototypeInlines.h: (JSC::jsSpliceSubstringsWithSeparators): (JSC::jsSpliceSubstringsWithSeparator): (JSC::jsSpliceSubstrings): (JSC::replaceAllWithCacheUsingRegExpSearchThreeArguments): (JSC::replaceAllWithCacheUsingRegExpSearch): * Source/JavaScriptCore/testRegExp.cpp: (scanString): * Source/JavaScriptCore/tools/CharacterPropertyDataGenerator.cpp: (JSC::LineBreakData::fill): (JSC::LineBreakData::dump): (JSC::LineBreakData::setPairValue): * Source/JavaScriptCore/yarr/YarrInterpreter.cpp: (JSC::Yarr::interpret): * Source/JavaScriptCore/yarr/YarrJIT.cpp: (JSC::Yarr::SubjectSampler::frequency const): (JSC::Yarr::SubjectSampler::add): * Source/JavaScriptCore/yarr/YarrJIT.h: * Source/JavaScriptCore/yarr/YarrParser.h: (JSC::Yarr::requires): (JSC::Yarr::Parser::tryConsume): (JSC::Yarr::parse): * Source/JavaScriptCore/yarr/YarrPattern.cpp: (JSC::Yarr::CharacterClassConstructor::putRange): (JSC::Yarr::YarrPatternConstructor::extractSpecificPattern): * Source/JavaScriptCore/yarr/YarrSyntaxChecker.cpp: (JSC::Yarr::SyntaxChecker::atomCharacterClassAtom): (JSC::Yarr::SyntaxChecker::atomCharacterClassRange): Canonical link: https://commits.webkit.org/296865@main Signed-off-by: Xabier Rodriguez Calvar --- Source/JavaScriptCore/API/JSStringRef.cpp | 6 +- Source/JavaScriptCore/API/JSStringRefCF.cpp | 4 +- Source/JavaScriptCore/API/JSValueRef.cpp | 2 +- Source/JavaScriptCore/API/OpaqueJSString.cpp | 8 +-- Source/JavaScriptCore/API/OpaqueJSString.h | 18 +++--- Source/JavaScriptCore/API/glib/JSCValue.cpp | 2 +- .../API/tests/JSONParseTest.cpp | 2 +- .../JavaScriptCore/KeywordLookupGenerator.py | 6 +- .../JavaScriptCore/builtins/BuiltinNames.cpp | 6 +- Source/JavaScriptCore/builtins/BuiltinNames.h | 4 +- .../JavaScriptCore/bytecode/CodeBlockHash.cpp | 2 +- .../dfg/DFGAbstractInterpreterInlines.h | 2 +- Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp | 2 +- Source/JavaScriptCore/dfg/DFGLazyJSValue.h | 6 +- Source/JavaScriptCore/dfg/DFGOperations.cpp | 10 ++-- .../JavaScriptCore/dfg/DFGSpeculativeJIT.cpp | 2 +- .../ftl/FTLAbstractHeapRepository.h | 2 +- Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp | 2 +- .../inspector/ContentSearchUtilities.cpp | 2 +- .../interpreter/Interpreter.cpp | 4 +- Source/JavaScriptCore/jsc.cpp | 2 +- Source/JavaScriptCore/parser/Lexer.cpp | 58 +++++++++---------- Source/JavaScriptCore/parser/Lexer.h | 32 +++++----- Source/JavaScriptCore/parser/Parser.cpp | 2 +- Source/JavaScriptCore/parser/Parser.h | 6 +- Source/JavaScriptCore/parser/ParserArena.h | 4 +- .../JavaScriptCore/runtime/ArrayPrototype.cpp | 4 +- Source/JavaScriptCore/runtime/CachedTypes.cpp | 2 +- .../runtime/ExceptionHelpers.cpp | 2 +- Source/JavaScriptCore/runtime/ISO8601.cpp | 6 +- Source/JavaScriptCore/runtime/Identifier.cpp | 4 +- Source/JavaScriptCore/runtime/Identifier.h | 14 ++--- .../runtime/IdentifierInlines.h | 2 +- Source/JavaScriptCore/runtime/IntlCache.cpp | 8 +-- Source/JavaScriptCore/runtime/IntlCache.h | 4 +- .../JavaScriptCore/runtime/IntlCollator.cpp | 6 +- .../runtime/IntlDateTimeFormat.cpp | 40 ++++++------- .../runtime/IntlDateTimeFormat.h | 8 +-- .../runtime/IntlDisplayNames.cpp | 8 +-- .../runtime/IntlDurationFormat.cpp | 8 +-- .../JavaScriptCore/runtime/IntlListFormat.cpp | 4 +- Source/JavaScriptCore/runtime/IntlLocale.cpp | 4 +- .../runtime/IntlNumberFormat.cpp | 14 ++--- Source/JavaScriptCore/runtime/IntlObject.cpp | 4 +- .../runtime/IntlObjectInlines.h | 8 +-- .../runtime/IntlPluralRules.cpp | 4 +- .../runtime/IntlRelativeTimeFormat.cpp | 4 +- .../runtime/IntlSegmentIterator.cpp | 4 +- .../runtime/IntlSegmentIterator.h | 6 +- .../JavaScriptCore/runtime/IntlSegmenter.cpp | 2 +- .../JavaScriptCore/runtime/IntlSegments.cpp | 4 +- Source/JavaScriptCore/runtime/IntlSegments.h | 6 +- Source/JavaScriptCore/runtime/JSDateMath.cpp | 12 ++-- .../JSGenericTypedArrayViewConstructor.cpp | 2 +- .../JSGenericTypedArrayViewConstructor.h | 2 +- .../runtime/JSGlobalObjectFunctions.cpp | 18 +++--- .../runtime/JSImmutableButterfly.cpp | 8 +-- .../runtime/JSONAtomStringCache.h | 6 +- Source/JavaScriptCore/runtime/JSONObject.cpp | 22 +++---- Source/JavaScriptCore/runtime/JSString.cpp | 8 +-- Source/JavaScriptCore/runtime/JSString.h | 10 ++-- .../JavaScriptCore/runtime/JSStringInlines.h | 24 ++++---- .../JavaScriptCore/runtime/JSStringJoiner.cpp | 6 +- .../JavaScriptCore/runtime/LiteralParser.cpp | 12 ++-- Source/JavaScriptCore/runtime/LiteralParser.h | 4 +- Source/JavaScriptCore/runtime/ParseInt.h | 6 +- Source/JavaScriptCore/runtime/RegExp.cpp | 4 +- .../runtime/RegExpObjectInlines.h | 4 +- .../runtime/StringConstructor.cpp | 12 ++-- .../runtime/StringPrototype.cpp | 26 ++++----- .../runtime/StringPrototypeInlines.h | 2 +- Source/JavaScriptCore/testRegExp.cpp | 4 +- .../tools/CharacterPropertyDataGenerator.cpp | 20 +++---- .../JavaScriptCore/yarr/YarrInterpreter.cpp | 10 ++-- Source/JavaScriptCore/yarr/YarrJIT.cpp | 6 +- Source/JavaScriptCore/yarr/YarrJIT.h | 8 +-- Source/JavaScriptCore/yarr/YarrParser.h | 4 +- Source/JavaScriptCore/yarr/YarrPattern.cpp | 4 +- .../JavaScriptCore/yarr/YarrSyntaxChecker.cpp | 4 +- 79 files changed, 312 insertions(+), 312 deletions(-) diff --git a/Source/JavaScriptCore/API/JSStringRef.cpp b/Source/JavaScriptCore/API/JSStringRef.cpp index 7cbe58ff2157c..26efd304ee504 100644 --- a/Source/JavaScriptCore/API/JSStringRef.cpp +++ b/Source/JavaScriptCore/API/JSStringRef.cpp @@ -38,7 +38,7 @@ WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars) { JSC::initialize(); - return &OpaqueJSString::create({ reinterpret_cast(chars), numChars }).leakRef(); + return &OpaqueJSString::create({ reinterpret_cast(chars), numChars }).leakRef(); } JSStringRef JSStringCreateWithUTF8CString(const char* string) @@ -46,7 +46,7 @@ JSStringRef JSStringCreateWithUTF8CString(const char* string) JSC::initialize(); if (string) { auto stringSpan = span8(string); - Vector buffer(stringSpan.size()); + Vector buffer(stringSpan.size()); auto result = WTF::Unicode::convert(spanReinterpretCast(stringSpan), buffer.mutableSpan()); if (result.code == WTF::Unicode::ConversionResultCode::Success) { if (result.isAllASCII) @@ -61,7 +61,7 @@ JSStringRef JSStringCreateWithUTF8CString(const char* string) JSStringRef JSStringCreateWithCharactersNoCopy(const JSChar* chars, size_t numChars) { JSC::initialize(); - return OpaqueJSString::tryCreate(StringImpl::createWithoutCopying({ reinterpret_cast(chars), numChars })).leakRef(); + return OpaqueJSString::tryCreate(StringImpl::createWithoutCopying({ reinterpret_cast(chars), numChars })).leakRef(); } JSStringRef JSStringRetain(JSStringRef string) diff --git a/Source/JavaScriptCore/API/JSStringRefCF.cpp b/Source/JavaScriptCore/API/JSStringRefCF.cpp index 58481e0eae917..b29072484864d 100644 --- a/Source/JavaScriptCore/API/JSStringRefCF.cpp +++ b/Source/JavaScriptCore/API/JSStringRefCF.cpp @@ -53,8 +53,8 @@ JSStringRef JSStringCreateWithCFString(CFStringRef string) Vector buffer(length); CFStringGetCharacters(string, CFRangeMake(0, length), buffer.data()); - static_assert(sizeof(UniChar) == sizeof(UChar), "UniChar and UChar must be same size"); - return &OpaqueJSString::create({ reinterpret_cast(buffer.data()), length }).leakRef(); + static_assert(sizeof(UniChar) == sizeof(char16_t), "UniChar and char16_t must be same size"); + return &OpaqueJSString::create({ reinterpret_cast(buffer.data()), length }).leakRef(); } CFStringRef JSStringCopyCFString(CFAllocatorRef allocator, JSStringRef string) diff --git a/Source/JavaScriptCore/API/JSValueRef.cpp b/Source/JavaScriptCore/API/JSValueRef.cpp index b68dfcfc02c8d..ed96912742b03 100644 --- a/Source/JavaScriptCore/API/JSValueRef.cpp +++ b/Source/JavaScriptCore/API/JSValueRef.cpp @@ -700,7 +700,7 @@ JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string) LiteralParser parser(globalObject, str.span8(), StrictJSON); return toRef(globalObject, parser.tryLiteralParse()); } - LiteralParser parser(globalObject, str.span16(), StrictJSON); + LiteralParser parser(globalObject, str.span16(), StrictJSON); return toRef(globalObject, parser.tryLiteralParse()); } diff --git a/Source/JavaScriptCore/API/OpaqueJSString.cpp b/Source/JavaScriptCore/API/OpaqueJSString.cpp index 4e724eb6e729b..1d99da4ed35bd 100644 --- a/Source/JavaScriptCore/API/OpaqueJSString.cpp +++ b/Source/JavaScriptCore/API/OpaqueJSString.cpp @@ -52,7 +52,7 @@ RefPtr OpaqueJSString::tryCreate(String&& string) OpaqueJSString::~OpaqueJSString() { // m_characters is put in a local here to avoid an extra atomic load. - UChar* characters = m_characters; + char16_t* characters = m_characters; if (!characters) return; @@ -79,17 +79,17 @@ Identifier OpaqueJSString::identifier(VM* vm) const return Identifier::fromString(*vm, m_string.span16()); } -const UChar* OpaqueJSString::characters() +const char16_t* OpaqueJSString::characters() { // m_characters is put in a local here to avoid an extra atomic load. - UChar* characters = m_characters; + char16_t* characters = m_characters; if (characters) return characters; if (m_string.isNull()) return nullptr; - auto newCharacters = MallocSpan::malloc(m_string.length() * sizeof(UChar)); + auto newCharacters = MallocSpan::malloc(m_string.length() * sizeof(char16_t)); StringView { m_string }.getCharacters(newCharacters.mutableSpan()); if (!m_characters.compare_exchange_strong(characters, newCharacters.mutableSpan().data())) diff --git a/Source/JavaScriptCore/API/OpaqueJSString.h b/Source/JavaScriptCore/API/OpaqueJSString.h index d0c1e8334469a..56df6fa82dbaf 100644 --- a/Source/JavaScriptCore/API/OpaqueJSString.h +++ b/Source/JavaScriptCore/API/OpaqueJSString.h @@ -45,7 +45,7 @@ struct OpaqueJSString : public ThreadSafeRefCounted { return adoptRef(*new OpaqueJSString(characters)); } - static Ref create(std::span characters) + static Ref create(std::span characters) { return adoptRef(*new OpaqueJSString(characters)); } @@ -56,11 +56,11 @@ struct OpaqueJSString : public ThreadSafeRefCounted { JS_EXPORT_PRIVATE ~OpaqueJSString(); bool is8Bit() { return m_string.is8Bit(); } - std::span span8() { return m_string.span8(); } - std::span span16() { return m_string.span16(); } + std::span span8() LIFETIME_BOUND { return m_string.span8(); } + std::span span16() LIFETIME_BOUND { return m_string.span16(); } unsigned length() { return m_string.length(); } - const UChar* characters(); + const char16_t* characters() LIFETIME_BOUND; JS_EXPORT_PRIVATE String string() const; JSC::Identifier identifier(JSC::VM*) const; @@ -77,13 +77,13 @@ struct OpaqueJSString : public ThreadSafeRefCounted { OpaqueJSString(const String& string) : m_string(string.isolatedCopy()) - , m_characters(m_string.impl() && m_string.is8Bit() ? nullptr : const_cast(m_string.span16().data())) + , m_characters(m_string.impl() && m_string.is8Bit() ? nullptr : const_cast(m_string.span16().data())) { } explicit OpaqueJSString(String&& string) : m_string(WTFMove(string)) - , m_characters(m_string.impl() && m_string.is8Bit() ? nullptr : const_cast(m_string.span16().data())) + , m_characters(m_string.impl() && m_string.is8Bit() ? nullptr : const_cast(m_string.span16().data())) { } @@ -93,14 +93,14 @@ struct OpaqueJSString : public ThreadSafeRefCounted { { } - OpaqueJSString(std::span characters) + OpaqueJSString(std::span characters) : m_string(characters) - , m_characters(m_string.impl() && m_string.is8Bit() ? nullptr : const_cast(m_string.span16().data())) + , m_characters(m_string.impl() && m_string.is8Bit() ? nullptr : const_cast(m_string.span16().data())) { } String m_string; // This will be initialized on demand when characters() is called if the string needs up-conversion. - std::atomic m_characters; + std::atomic m_characters; }; diff --git a/Source/JavaScriptCore/API/glib/JSCValue.cpp b/Source/JavaScriptCore/API/glib/JSCValue.cpp index 48e5ad211e623..aba485286c154 100644 --- a/Source/JavaScriptCore/API/glib/JSCValue.cpp +++ b/Source/JavaScriptCore/API/glib/JSCValue.cpp @@ -2098,7 +2098,7 @@ JSCValue* jsc_value_new_from_json(JSCContext* context, const char* json) if (!jsValue) exception = toRef(JSC::createSyntaxError(globalObject, jsonParser.getErrorMessage())); } else { - JSC::LiteralParser jsonParser(globalObject, jsonString.span16(), JSC::StrictJSON); + JSC::LiteralParser jsonParser(globalObject, jsonString.span16(), JSC::StrictJSON); jsValue = jsonParser.tryLiteralParse(); if (!jsValue) exception = toRef(JSC::createSyntaxError(globalObject, jsonParser.getErrorMessage())); diff --git a/Source/JavaScriptCore/API/tests/JSONParseTest.cpp b/Source/JavaScriptCore/API/tests/JSONParseTest.cpp index 447c259ec0b4d..ddcd54ef021eb 100644 --- a/Source/JavaScriptCore/API/tests/JSONParseTest.cpp +++ b/Source/JavaScriptCore/API/tests/JSONParseTest.cpp @@ -48,7 +48,7 @@ int testJSONParse() JSValue v0 = JSONParse(globalObject, ""_s); JSValue v1 = JSONParse(globalObject, "#$%^"_s); JSValue v2 = JSONParse(globalObject, String()); - UChar emptyUCharArray[1] = { '\0' }; + char16_t emptyUCharArray[1] = { '\0' }; unsigned zeroLength = 0; JSValue v3 = JSONParse(globalObject, String({ emptyUCharArray, zeroLength })); JSValue v4; diff --git a/Source/JavaScriptCore/KeywordLookupGenerator.py b/Source/JavaScriptCore/KeywordLookupGenerator.py index b572954692058..37d5a5a6eea97 100644 --- a/Source/JavaScriptCore/KeywordLookupGenerator.py +++ b/Source/JavaScriptCore/KeywordLookupGenerator.py @@ -186,16 +186,16 @@ def printAsC(self): print("namespace JSC {") print("") print("static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(LChar);") - print("static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(UChar);") + print("static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(char16_t);") # max length + 1 so we don't need to do any bounds checking at all print("static constexpr int maxTokenLength = %d;" % (self.maxLength() + 1)) print("") print("template <>") - print("template ALWAYS_INLINE JSTokenType Lexer::parseKeyword(JSTokenData* data)") + print("template ALWAYS_INLINE JSTokenType Lexer::parseKeyword(JSTokenData* data)") print("{") print(" ASSERT(m_codeEnd - m_code >= maxTokenLength);") print("") - print(" const UChar* code = m_code;") + print(" const char16_t* code = m_code;") self.printSubTreeAsC("UCHAR", 4) print(" return IDENT;") print("}") diff --git a/Source/JavaScriptCore/builtins/BuiltinNames.cpp b/Source/JavaScriptCore/builtins/BuiltinNames.cpp index 34376bf5018e0..701a2accb17b4 100644 --- a/Source/JavaScriptCore/builtins/BuiltinNames.cpp +++ b/Source/JavaScriptCore/builtins/BuiltinNames.cpp @@ -94,7 +94,7 @@ BuiltinNames::BuiltinNames(VM& vm, CommonIdentifiers* commonIdentifiers) using LCharBuffer = WTF::HashTranslatorCharBuffer; -using UCharBuffer = WTF::HashTranslatorCharBuffer; +using UCharBuffer = WTF::HashTranslatorCharBuffer; template struct CharBufferSeacher { @@ -138,7 +138,7 @@ PrivateSymbolImpl* BuiltinNames::lookUpPrivateName(std::span charac return lookUpPrivateNameImpl(m_privateNameSet, buffer); } -PrivateSymbolImpl* BuiltinNames::lookUpPrivateName(std::span characters) const +PrivateSymbolImpl* BuiltinNames::lookUpPrivateName(std::span characters) const { UCharBuffer buffer { characters }; return lookUpPrivateNameImpl(m_privateNameSet, buffer); @@ -160,7 +160,7 @@ SymbolImpl* BuiltinNames::lookUpWellKnownSymbol(std::span character return lookUpWellKnownSymbolImpl(m_wellKnownSymbolsMap, buffer); } -SymbolImpl* BuiltinNames::lookUpWellKnownSymbol(std::span characters) const +SymbolImpl* BuiltinNames::lookUpWellKnownSymbol(std::span characters) const { UCharBuffer buffer { characters }; return lookUpWellKnownSymbolImpl(m_wellKnownSymbolsMap, buffer); diff --git a/Source/JavaScriptCore/builtins/BuiltinNames.h b/Source/JavaScriptCore/builtins/BuiltinNames.h index 07aae9248fa57..71edb79a95403 100644 --- a/Source/JavaScriptCore/builtins/BuiltinNames.h +++ b/Source/JavaScriptCore/builtins/BuiltinNames.h @@ -247,12 +247,12 @@ class BuiltinNames { PrivateSymbolImpl* lookUpPrivateName(const Identifier&) const; PrivateSymbolImpl* lookUpPrivateName(const String&) const; PrivateSymbolImpl* lookUpPrivateName(std::span) const; - PrivateSymbolImpl* lookUpPrivateName(std::span) const; + PrivateSymbolImpl* lookUpPrivateName(std::span) const; SymbolImpl* lookUpWellKnownSymbol(const Identifier&) const; SymbolImpl* lookUpWellKnownSymbol(const String&) const; SymbolImpl* lookUpWellKnownSymbol(std::span) const; - SymbolImpl* lookUpWellKnownSymbol(std::span) const; + SymbolImpl* lookUpWellKnownSymbol(std::span) const; void appendExternalName(const Identifier& publicName, const Identifier& privateName); diff --git a/Source/JavaScriptCore/bytecode/CodeBlockHash.cpp b/Source/JavaScriptCore/bytecode/CodeBlockHash.cpp index c3e97874fd767..7ade2833a4ddb 100644 --- a/Source/JavaScriptCore/bytecode/CodeBlockHash.cpp +++ b/Source/JavaScriptCore/bytecode/CodeBlockHash.cpp @@ -66,7 +66,7 @@ CodeBlockHash::CodeBlockHash(const SourceCode& sourceCode, CodeSpecializationKin sha1.addBytes(std::span { std::bit_cast(&length), sizeof(length) }); do { - UChar character = str[index]; + char16_t character = str[index]; sha1.addBytes(std::span { std::bit_cast(&character), sizeof(character) }); oldIndex = index; index += step; diff --git a/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h b/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h index c1246c61294f8..ac6ed9618c498 100644 --- a/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h +++ b/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h @@ -1632,7 +1632,7 @@ bool AbstractInterpreter::executeEffects(unsigned clobberLimi if (const StringImpl* a = asString(string)->tryGetValueImpl()) { bool lower = true; for (unsigned index = 0; index < a->length(); ++index) { - UChar character = a->at(index); + char16_t character = a->at(index); if (!isASCII(character) || isASCIIUpper(character)) { lower = false; break; diff --git a/Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp b/Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp index 34516b078991d..77ac0e3ea1fb7 100644 --- a/Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp +++ b/Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp @@ -59,7 +59,7 @@ JSValue LazyJSValue::getValue(VM& vm) const return JSValue(); } -static TriState equalToSingleCharacter(JSValue value, UChar character) +static TriState equalToSingleCharacter(JSValue value, char16_t character) { if (!value.isString()) return TriState::False; diff --git a/Source/JavaScriptCore/dfg/DFGLazyJSValue.h b/Source/JavaScriptCore/dfg/DFGLazyJSValue.h index 65b96daf578ac..b490328429c6d 100644 --- a/Source/JavaScriptCore/dfg/DFGLazyJSValue.h +++ b/Source/JavaScriptCore/dfg/DFGLazyJSValue.h @@ -59,7 +59,7 @@ class LazyJSValue { u.value = value; } - static LazyJSValue singleCharacterString(UChar character) + static LazyJSValue singleCharacterString(char16_t character) { LazyJSValue result; result.m_kind = SingleCharacterString; @@ -95,7 +95,7 @@ class LazyJSValue { return u.value; } - UChar character() const + char16_t character() const { ASSERT(m_kind == SingleCharacterString); return u.character; @@ -123,7 +123,7 @@ class LazyJSValue { union { FrozenValue* value; - UChar character; + char16_t character; StringImpl* stringImpl; } u; LazinessKind m_kind; diff --git a/Source/JavaScriptCore/dfg/DFGOperations.cpp b/Source/JavaScriptCore/dfg/DFGOperations.cpp index f971f0e32df51..2ad3574b0d8ff 100644 --- a/Source/JavaScriptCore/dfg/DFGOperations.cpp +++ b/Source/JavaScriptCore/dfg/DFGOperations.cpp @@ -1901,7 +1901,7 @@ JSC_DEFINE_JIT_OPERATION(operationToNumberString, EncodedJSValue, (JSGlobalObjec unsigned size = view->length(); if (size == 1) { - UChar c = view[0]; + char16_t c = view[0]; if (isASCIIDigit(c)) OPERATION_RETURN(scope, JSValue::encode(jsNumber(static_cast(c - '0')))); if (isStrWhiteSpace(c)) @@ -1910,7 +1910,7 @@ JSC_DEFINE_JIT_OPERATION(operationToNumberString, EncodedJSValue, (JSGlobalObjec } if (size == 2 && view[0] == '-') { - UChar c = view[1]; + char16_t c = view[1]; if (c == '0') OPERATION_RETURN(scope, JSValue::encode(jsNumber(-0.0))); if (isASCIIDigit(c)) @@ -3091,7 +3091,7 @@ JSC_DEFINE_JIT_OPERATION(operationStringIndexOfWithOneChar, UCPUStrictInt32, (JS auto thisView = base->view(globalObject); OPERATION_RETURN_IF_EXCEPTION(scope, 0); - size_t result = thisView->find(static_cast(character)); + size_t result = thisView->find(static_cast(character)); if (result == notFound) OPERATION_RETURN(scope, toUCPUStrictInt32(-1)); OPERATION_RETURN(scope, toUCPUStrictInt32(result)); @@ -3144,7 +3144,7 @@ JSC_DEFINE_JIT_OPERATION(operationStringIndexOfWithIndexWithOneChar, UCPUStrictI if (static_cast(length) < 1 + pos) OPERATION_RETURN(scope, toUCPUStrictInt32(-1)); - size_t result = thisView->find(static_cast(character), pos); + size_t result = thisView->find(static_cast(character), pos); if (result == notFound) OPERATION_RETURN(scope, toUCPUStrictInt32(-1)); OPERATION_RETURN(scope, toUCPUStrictInt32(result)); @@ -3321,7 +3321,7 @@ JSC_DEFINE_JIT_OPERATION(operationSingleCharacterString, JSString*, (VM* vmPoint JITOperationPrologueCallFrameTracer tracer(vm, callFrame); auto scope = DECLARE_THROW_SCOPE(vm); - OPERATION_RETURN(scope, jsSingleCharacterString(vm, static_cast(character))); + OPERATION_RETURN(scope, jsSingleCharacterString(vm, static_cast(character))); } JSC_DEFINE_JIT_OPERATION(operationNewSymbol, Symbol*, (VM* vmPointer)) diff --git a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp index 37af71aa90127..22cb7847d1573 100644 --- a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp +++ b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp @@ -16218,7 +16218,7 @@ void SpeculativeJIT::compileStringLocaleCompare(Node* node) void SpeculativeJIT::compileStringIndexOf(Node* node) { - std::optional character; + std::optional character; String searchString = node->child2()->tryGetString(m_graph); if (!!searchString) { if (searchString.length() == 1) diff --git a/Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.h b/Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.h index 3f2e27342f9ce..b6a99aea06c2a 100644 --- a/Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.h +++ b/Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.h @@ -195,7 +195,7 @@ namespace JSC { namespace FTL { macro(ScopedArguments_Storage_storage, 0, sizeof(EncodedJSValue)) \ macro(WriteBarrierBuffer_bufferContents, 0, sizeof(JSCell*)) \ macro(characters8, 0, sizeof(LChar)) \ - macro(characters16, 0, sizeof(UChar)) \ + macro(characters16, 0, sizeof(char16_t)) \ macro(indexedInt32Properties, 0, sizeof(EncodedJSValue)) \ macro(indexedDoubleProperties, 0, sizeof(double)) \ macro(indexedContiguousProperties, 0, sizeof(EncodedJSValue)) \ diff --git a/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp b/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp index 51d6c733e7d7c..61635981c9cc9 100644 --- a/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp +++ b/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp @@ -10401,7 +10401,7 @@ IGNORE_CLANG_WARNINGS_END void compileStringIndexOf() { - std::optional character; + std::optional character; String searchString = m_node->child2()->tryGetString(m_graph); if (!!searchString) { if (searchString.length() == 1) diff --git a/Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp b/Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp index ed6dfb592cab1..c727b9eb83daa 100644 --- a/Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp +++ b/Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp @@ -51,7 +51,7 @@ static String escapeStringForRegularExpressionSource(const String& text) StringBuilder result; for (unsigned i = 0; i < text.length(); i++) { - UChar character = text[i]; + char16_t character = text[i]; WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN if (isASCII(character) && strchr(regexSpecialCharacters, character)) result.append('\\'); diff --git a/Source/JavaScriptCore/interpreter/Interpreter.cpp b/Source/JavaScriptCore/interpreter/Interpreter.cpp index 91f75c2a4e066..a6a631cb736be 100644 --- a/Source/JavaScriptCore/interpreter/Interpreter.cpp +++ b/Source/JavaScriptCore/interpreter/Interpreter.cpp @@ -191,7 +191,7 @@ JSValue eval(CallFrame* callFrame, JSValue thisValue, JSScope* callerScopeChain, RELEASE_AND_RETURN(scope, parsedObject); } else { - LiteralParser preparser(globalObject, programSource.span16(), SloppyJSON, callerBaselineCodeBlock); + LiteralParser preparser(globalObject, programSource.span16(), SloppyJSON, callerBaselineCodeBlock); if (JSValue parsedObject = preparser.tryLiteralParse()) RELEASE_AND_RETURN(scope, parsedObject); @@ -1021,7 +1021,7 @@ JSValue Interpreter::executeProgram(const SourceCode& source, JSGlobalObject*, J LiteralParser literalParser(globalObject, programSource.span8(), JSONP); parseResult = literalParser.tryJSONPParse(JSONPData, globalObject->globalObjectMethodTable()->supportsRichSourceInfo(globalObject)); } else { - LiteralParser literalParser(globalObject, programSource.span16(), JSONP); + LiteralParser literalParser(globalObject, programSource.span16(), JSONP); parseResult = literalParser.tryJSONPParse(JSONPData, globalObject->globalObjectMethodTable()->supportsRichSourceInfo(globalObject)); } diff --git a/Source/JavaScriptCore/jsc.cpp b/Source/JavaScriptCore/jsc.cpp index 1dfd6103d0089..7b676c5e5c8db 100644 --- a/Source/JavaScriptCore/jsc.cpp +++ b/Source/JavaScriptCore/jsc.cpp @@ -985,7 +985,7 @@ JSC_DEFINE_CUSTOM_SETTER(testCustomValueSetter, (JSGlobalObject* lexicalGlobalOb return GlobalObject::testCustomSetterImpl(lexicalGlobalObject, thisObject, encodedValue, "_testCustomValueSetter"_s); } -static UChar pathSeparator() +static char16_t pathSeparator() { #if OS(WINDOWS) return '\\'; diff --git a/Source/JavaScriptCore/parser/Lexer.cpp b/Source/JavaScriptCore/parser/Lexer.cpp index c18addf89e3ee..f3352dca8f80b 100644 --- a/Source/JavaScriptCore/parser/Lexer.cpp +++ b/Source/JavaScriptCore/parser/Lexer.cpp @@ -739,13 +739,13 @@ static bool isNonLatin1IdentStart(char32_t c) template static ALWAYS_INLINE bool isIdentStart(CharacterType c) { - static_assert(std::is_same_v || std::is_same_v, "Call isSingleCharacterIdentStart for UChars that don't need to check for surrogate pairs"); + static_assert(std::is_same_v || std::is_same_v, "Call isSingleCharacterIdentStart for char16_ts that don't need to check for surrogate pairs"); if (!isLatin1(c)) return isNonLatin1IdentStart(c); return typesOfLatin1Characters[static_cast(c)] == CharacterIdentifierStart; } -static ALWAYS_INLINE UNUSED_FUNCTION bool isSingleCharacterIdentStart(UChar c) +static ALWAYS_INLINE UNUSED_FUNCTION bool isSingleCharacterIdentStart(char16_t c) { if (LIKELY(isLatin1(c))) return isIdentStart(static_cast(c)); @@ -757,11 +757,11 @@ static ALWAYS_INLINE bool cannotBeIdentStart(LChar c) return !isIdentStart(c) && c != '\\'; } -static ALWAYS_INLINE bool cannotBeIdentStart(UChar c) +static ALWAYS_INLINE bool cannotBeIdentStart(char16_t c) { if (LIKELY(isLatin1(c))) return cannotBeIdentStart(static_cast(c)); - return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); + return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); } static NEVER_INLINE bool isNonLatin1IdentPart(char32_t c) @@ -772,7 +772,7 @@ static NEVER_INLINE bool isNonLatin1IdentPart(char32_t c) template static ALWAYS_INLINE bool isIdentPart(CharacterType c) { - static_assert(std::is_same_v || std::is_same_v, "Call isSingleCharacterIdentPart for UChars that don't need to check for surrogate pairs"); + static_assert(std::is_same_v || std::is_same_v, "Call isSingleCharacterIdentPart for char16_ts that don't need to check for surrogate pairs"); if (!isLatin1(c)) return isNonLatin1IdentPart(c); @@ -782,7 +782,7 @@ static ALWAYS_INLINE bool isIdentPart(CharacterType c) return typesOfLatin1Characters[static_cast(c)] <= CharacterOtherIdentifierPart; } -static ALWAYS_INLINE bool isSingleCharacterIdentPart(UChar c) +static ALWAYS_INLINE bool isSingleCharacterIdentPart(char16_t c) { if (LIKELY(isLatin1(c))) return isIdentPart(static_cast(c)); @@ -796,11 +796,11 @@ static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(LChar c) // NOTE: This may give give false negatives (for non-ascii) but won't give false posititves. // This means it can be used to detect the end of a keyword (all keywords are ascii) -static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(UChar c) +static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(char16_t c) { if (LIKELY(isLatin1(c))) return cannotBeIdentPartOrEscapeStart(static_cast(c)); - return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); + return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); } @@ -811,13 +811,13 @@ ALWAYS_INLINE char32_t Lexer::currentCodePoint() const } template<> -ALWAYS_INLINE char32_t Lexer::currentCodePoint() const +ALWAYS_INLINE char32_t Lexer::currentCodePoint() const { ASSERT_WITH_MESSAGE(!isIdentStart(errorCodePoint), "error values shouldn't appear as a valid identifier start code point"); if (!U16_IS_SURROGATE(m_current)) return m_current; - UChar trail = peek(1); + char16_t trail = peek(1); if (UNLIKELY(!U16_IS_LEAD(m_current) || !U16_IS_SURROGATE_TRAIL(trail))) return errorCodePoint; @@ -883,7 +883,7 @@ inline void Lexer::append16(std::span span) { size_t currentSize = m_buffer16.size(); m_buffer16.grow(currentSize + span.size()); - UChar* rawBuffer = m_buffer16.data() + currentSize; + char16_t* rawBuffer = m_buffer16.data() + currentSize; for (size_t i = 0; i < span.size(); i++) rawBuffer[i] = span[i]; @@ -900,16 +900,16 @@ inline void Lexer::record16(int c) { ASSERT(c >= 0); ASSERT(c <= static_cast(USHRT_MAX)); - m_buffer16.append(static_cast(c)); + m_buffer16.append(static_cast(c)); } template inline void Lexer::recordUnicodeCodePoint(char32_t codePoint) { ASSERT(codePoint <= UCHAR_MAX_VALUE); if (U_IS_BMP(codePoint)) - record16(static_cast(codePoint)); + record16(static_cast(codePoint)); else { - UChar codeUnits[2] = { U16_LEAD(codePoint), U16_TRAIL(codePoint) }; + char16_t codeUnits[2] = { U16_LEAD(codePoint), U16_TRAIL(codePoint) }; append16(codeUnits); } } @@ -1016,7 +1016,7 @@ template ALWAYS_INLINE JSTokenType Lexer::p } template <> -template ALWAYS_INLINE JSTokenType Lexer::parseIdentifier(JSTokenData* tokenData, OptionSet lexerFlags, bool strictMode) +template ALWAYS_INLINE JSTokenType Lexer::parseIdentifier(JSTokenData* tokenData, OptionSet lexerFlags, bool strictMode) { ASSERT(!m_parsingBuiltinFunction); tokenData->escaped = false; @@ -1030,12 +1030,12 @@ template ALWAYS_INLINE JSTokenType Lexer::p } bool isPrivateName = m_current == '#'; - const UChar* identifierStart = currentSourcePtr(); + const char16_t* identifierStart = currentSourcePtr(); if (isPrivateName) shift(); - UChar orAllChars = 0; + char16_t orAllChars = 0; ASSERT(isSingleCharacterIdentStart(m_current) || U16_IS_SURROGATE(m_current) || m_current == '\\'); while (isSingleCharacterIdentPart(m_current)) { orAllChars |= m_current; @@ -1177,7 +1177,7 @@ static ALWAYS_INLINE bool characterRequiresParseStringSlowCase(LChar character) return character < 0xE; } -static ALWAYS_INLINE bool characterRequiresParseStringSlowCase(UChar character) +static ALWAYS_INLINE bool characterRequiresParseStringSlowCase(char16_t character) { return character < 0xE || !isLatin1(character); } @@ -1842,10 +1842,10 @@ IGNORE_WARNINGS_BEGIN("unused-but-set-variable") template ALWAYS_INLINE String Lexer::parseCommentDirectiveValue() { skipWhitespace(); - UChar mergedCharacterBits = 0; + char16_t mergedCharacterBits = 0; auto stringStart = currentSourcePtr(); while (!isWhiteSpace(m_current) && !isLineTerminator(m_current) && m_current != '"' && m_current != '\'' && !atEnd()) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) mergedCharacterBits |= m_current; shift(); } @@ -1855,7 +1855,7 @@ template ALWAYS_INLINE String Lexer::pars if (!isLineTerminator(m_current) && !atEnd()) return String(); - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { if (isLatin1(mergedCharacterBits)) return String::make8Bit(commentDirective); } @@ -2605,26 +2605,26 @@ JSTokenType Lexer::lexWithoutClearingLineTerminator(JSToken* tokenRecord, Opt } template -static inline void orCharacter(UChar&, UChar); +static inline void orCharacter(char16_t&, char16_t); template <> -inline void orCharacter(UChar&, UChar) { } +inline void orCharacter(char16_t&, char16_t) { } template <> -inline void orCharacter(UChar& orAccumulator, UChar character) +inline void orCharacter(char16_t& orAccumulator, char16_t character) { orAccumulator |= character; } template -JSTokenType Lexer::scanRegExp(JSToken* tokenRecord, UChar patternPrefix) +JSTokenType Lexer::scanRegExp(JSToken* tokenRecord, char16_t patternPrefix) { JSTokenData* tokenData = &tokenRecord->m_data; ASSERT(m_buffer16.isEmpty()); bool lastWasEscape = false; bool inBrackets = false; - UChar charactersOredTogether = 0; + char16_t charactersOredTogether = 0; if (patternPrefix) { ASSERT(!isLineTerminator(patternPrefix)); @@ -2738,10 +2738,10 @@ void Lexer::clear() Vector newBuffer8; m_buffer8.swap(newBuffer8); - Vector newBuffer16; + Vector newBuffer16; m_buffer16.swap(newBuffer16); - Vector newBufferForRawTemplateString16; + Vector newBufferForRawTemplateString16; m_bufferForRawTemplateString16.swap(newBufferForRawTemplateString16); m_isReparsingFunction = false; @@ -2749,7 +2749,7 @@ void Lexer::clear() // Instantiate the two flavors of Lexer we need instead of putting most of this file in Lexer.h template class Lexer; -template class Lexer; +template class Lexer; } // namespace JSC diff --git a/Source/JavaScriptCore/parser/Lexer.h b/Source/JavaScriptCore/parser/Lexer.h index bb401c341bfd1..754d40c2e2496 100644 --- a/Source/JavaScriptCore/parser/Lexer.h +++ b/Source/JavaScriptCore/parser/Lexer.h @@ -58,7 +58,7 @@ class Lexer { static bool isWhiteSpace(T character); static bool isLineTerminator(T character); static unsigned char convertHex(int c1, int c2); - static UChar convertUnicode(int c1, int c2, int c3, int c4); + static char16_t convertUnicode(int c1, int c2, int c3, int c4); // Functions to set up parsing. void setCode(const SourceCode&, ParserArena*); @@ -80,7 +80,7 @@ class Lexer { void setLastLineNumber(int lastLineNumber) { m_lastLineNumber = lastLineNumber; } int lastLineNumber() const { return m_lastLineNumber; } bool hasLineTerminatorBeforeToken() const { return m_hasLineTerminatorBeforeToken; } - JSTokenType scanRegExp(JSToken*, UChar patternPrefix = 0); + JSTokenType scanRegExp(JSToken*, char16_t patternPrefix = 0); enum class RawStringsBuildMode { BuildRawStrings, DontBuildRawStrings }; JSTokenType scanTemplateString(JSToken*, RawStringsBuildMode); @@ -136,7 +136,7 @@ class Lexer { void record16(T); void recordUnicodeCodePoint(char32_t); void append16(std::span); - void append16(std::span characters) { m_buffer16.append(characters); } + void append16(std::span characters) { m_buffer16.append(characters); } static constexpr char32_t errorCodePoint = 0xFFFFFFFFu; char32_t currentCodePoint() const; @@ -159,9 +159,9 @@ class Lexer { ALWAYS_INLINE const Identifier* makeIdentifier(std::span); ALWAYS_INLINE const Identifier* makeLCharIdentifier(std::span); - ALWAYS_INLINE const Identifier* makeLCharIdentifier(std::span); - ALWAYS_INLINE const Identifier* makeRightSizedIdentifier(std::span, UChar orAllChars); - ALWAYS_INLINE const Identifier* makeIdentifierLCharFromUChar(std::span); + ALWAYS_INLINE const Identifier* makeLCharIdentifier(std::span); + ALWAYS_INLINE const Identifier* makeRightSizedIdentifier(std::span, char16_t orAllChars); + ALWAYS_INLINE const Identifier* makeIdentifierLCharFromUChar(std::span); ALWAYS_INLINE const Identifier* makeEmptyIdentifier(); ALWAYS_INLINE bool lastTokenWasRestrKeyword() const; @@ -207,8 +207,8 @@ class Lexer { int m_lastLineNumber; Vector m_buffer8; - Vector m_buffer16; - Vector m_bufferForRawTemplateString16; + Vector m_buffer16; + Vector m_bufferForRawTemplateString16; bool m_hasLineTerminatorBeforeToken; int m_lastToken; @@ -247,7 +247,7 @@ ALWAYS_INLINE bool Lexer::isWhiteSpace(LChar ch) } template <> -ALWAYS_INLINE bool Lexer::isWhiteSpace(UChar ch) +ALWAYS_INLINE bool Lexer::isWhiteSpace(char16_t ch) { return isLatin1(ch) ? Lexer::isWhiteSpace(static_cast(ch)) : (u_charType(ch) == U_SPACE_SEPARATOR || ch == byteOrderMark); } @@ -259,7 +259,7 @@ ALWAYS_INLINE bool Lexer::isLineTerminator(LChar ch) } template <> -ALWAYS_INLINE bool Lexer::isLineTerminator(UChar ch) +ALWAYS_INLINE bool Lexer::isLineTerminator(char16_t ch) { return ch == '\r' || ch == '\n' || (ch & ~1) == 0x2028; } @@ -271,7 +271,7 @@ inline unsigned char Lexer::convertHex(int c1, int c2) } template -inline UChar Lexer::convertUnicode(int c1, int c2, int c3, int c4) +inline char16_t Lexer::convertUnicode(int c1, int c2, int c3, int c4) { return (convertHex(c1, c2) << 8) | convertHex(c3, c4); } @@ -284,13 +284,13 @@ ALWAYS_INLINE const Identifier* Lexer::makeIdentifier(std::span -ALWAYS_INLINE const Identifier* Lexer::makeRightSizedIdentifier(std::span characters, UChar) +ALWAYS_INLINE const Identifier* Lexer::makeRightSizedIdentifier(std::span characters, char16_t) { return &m_arena->makeIdentifierLCharFromUChar(m_vm, characters); } template <> -ALWAYS_INLINE const Identifier* Lexer::makeRightSizedIdentifier(std::span characters, UChar orAllChars) +ALWAYS_INLINE const Identifier* Lexer::makeRightSizedIdentifier(std::span characters, char16_t orAllChars) { if (!(orAllChars & ~0xff)) return &m_arena->makeIdentifierLCharFromUChar(m_vm, characters); @@ -312,14 +312,14 @@ ALWAYS_INLINE void Lexer::setCodeStart(StringView sourceString) } template <> -ALWAYS_INLINE void Lexer::setCodeStart(StringView sourceString) +ALWAYS_INLINE void Lexer::setCodeStart(StringView sourceString) { ASSERT(!sourceString.is8Bit()); m_codeStart = sourceString.span16().data(); } template -ALWAYS_INLINE const Identifier* Lexer::makeIdentifierLCharFromUChar(std::span characters) +ALWAYS_INLINE const Identifier* Lexer::makeIdentifierLCharFromUChar(std::span characters) { return &m_arena->makeIdentifierLCharFromUChar(m_vm, characters); } @@ -331,7 +331,7 @@ ALWAYS_INLINE const Identifier* Lexer::makeLCharIdentifier(std::span -ALWAYS_INLINE const Identifier* Lexer::makeLCharIdentifier(std::span characters) +ALWAYS_INLINE const Identifier* Lexer::makeLCharIdentifier(std::span characters) { return &m_arena->makeIdentifierLCharFromUChar(m_vm, characters); } diff --git a/Source/JavaScriptCore/parser/Parser.cpp b/Source/JavaScriptCore/parser/Parser.cpp index 11016067e29cf..073521882a070 100644 --- a/Source/JavaScriptCore/parser/Parser.cpp +++ b/Source/JavaScriptCore/parser/Parser.cpp @@ -5756,6 +5756,6 @@ template void Parser::printUnexpectedTokenText(W // Instantiate the two flavors of Parser we need instead of putting most of this file in Parser.h template class Parser>; -template class Parser>; +template class Parser>; } // namespace JSC diff --git a/Source/JavaScriptCore/parser/Parser.h b/Source/JavaScriptCore/parser/Parser.h index f33c3b2867231..443cb78a1a024 100644 --- a/Source/JavaScriptCore/parser/Parser.h +++ b/Source/JavaScriptCore/parser/Parser.h @@ -2294,7 +2294,7 @@ std::unique_ptr parse( } } } else { - Parser> parser(vm, source, implementationVisibility, builtinMode, lexicallyScopedFeatures, scriptMode, parseMode, functionMode, superBinding, constructorKind, derivedContextType, isEvalNode(), evalContextType, nullptr, isInsideOrdinaryFunction); + Parser> parser(vm, source, implementationVisibility, builtinMode, lexicallyScopedFeatures, scriptMode, parseMode, functionMode, superBinding, constructorKind, derivedContextType, isEvalNode(), evalContextType, nullptr, isInsideOrdinaryFunction); result = parser.parse(error, name, ParsingContext::Normal, std::nullopt, parentScopePrivateNames, classElementDefinitions); } @@ -2340,7 +2340,7 @@ std::unique_ptr parseRootNode( } else { ASSERT_WITH_MESSAGE(!positionBeforeLastNewline, "BuiltinExecutables should always use a 8-bit string"); ASSERT_WITH_MESSAGE(constructorKindForTopLevelFunctionExpressions == ConstructorKind::None, "BuiltinExecutables' special constructors should always use a 8-bit string"); - Parser> parser(vm, source, implementationVisibility, builtinMode, lexicallyScopedFeatures, scriptMode, parseMode, FunctionMode::None, SuperBinding::NotNeeded, ConstructorKind::None, DerivedContextType::None, isEvalNode, EvalContextType::None, debuggerParseData, isInsideOrdinaryFunction); + Parser> parser(vm, source, implementationVisibility, builtinMode, lexicallyScopedFeatures, scriptMode, parseMode, FunctionMode::None, SuperBinding::NotNeeded, ConstructorKind::None, DerivedContextType::None, isEvalNode, EvalContextType::None, debuggerParseData, isInsideOrdinaryFunction); result = parser.parse(error, name, ParsingContext::Normal); } @@ -2373,7 +2373,7 @@ inline std::unique_ptr parseFunctionForFunctionConstructor(VM& vm, if (positionBeforeLastNewline) *positionBeforeLastNewline = parser.positionBeforeLastNewline(); } else { - Parser> parser(vm, source, ImplementationVisibility::Public, JSParserBuiltinMode::NotBuiltin, lexicallyScopedFeatures, JSParserScriptMode::Classic, SourceParseMode::ProgramMode, FunctionMode::None, SuperBinding::NotNeeded, ConstructorKind::None, DerivedContextType::None, isEvalNode, EvalContextType::None, nullptr); + Parser> parser(vm, source, ImplementationVisibility::Public, JSParserBuiltinMode::NotBuiltin, lexicallyScopedFeatures, JSParserScriptMode::Classic, SourceParseMode::ProgramMode, FunctionMode::None, SuperBinding::NotNeeded, ConstructorKind::None, DerivedContextType::None, isEvalNode, EvalContextType::None, nullptr); result = parser.parse(error, name, ParsingContext::FunctionConstructor, functionConstructorParametersEndPosition); if (positionBeforeLastNewline) *positionBeforeLastNewline = parser.positionBeforeLastNewline(); diff --git a/Source/JavaScriptCore/parser/ParserArena.h b/Source/JavaScriptCore/parser/ParserArena.h index 7ad52673c2a95..df9994a470330 100644 --- a/Source/JavaScriptCore/parser/ParserArena.h +++ b/Source/JavaScriptCore/parser/ParserArena.h @@ -50,7 +50,7 @@ namespace JSC { template ALWAYS_INLINE const Identifier& makeIdentifier(VM&, std::span characters); ALWAYS_INLINE const Identifier& makeEmptyIdentifier(VM&); - ALWAYS_INLINE const Identifier& makeIdentifierLCharFromUChar(VM&, std::span characters); + ALWAYS_INLINE const Identifier& makeIdentifierLCharFromUChar(VM&, std::span characters); ALWAYS_INLINE const Identifier& makeIdentifier(VM&, SymbolImpl*); const Identifier* makeBigIntDecimalIdentifier(VM&, const Identifier&, uint8_t radix); @@ -111,7 +111,7 @@ namespace JSC { return vm.propertyNames->emptyIdentifier; } - ALWAYS_INLINE const Identifier& IdentifierArena::makeIdentifierLCharFromUChar(VM& vm, std::span characters) + ALWAYS_INLINE const Identifier& IdentifierArena::makeIdentifierLCharFromUChar(VM& vm, std::span characters) { if (characters.empty()) return vm.propertyNames->emptyIdentifier; diff --git a/Source/JavaScriptCore/runtime/ArrayPrototype.cpp b/Source/JavaScriptCore/runtime/ArrayPrototype.cpp index b6b5404c8949d..ea3af3d8eba75 100644 --- a/Source/JavaScriptCore/runtime/ArrayPrototype.cpp +++ b/Source/JavaScriptCore/runtime/ArrayPrototype.cpp @@ -1057,14 +1057,14 @@ static unsigned sortBucketSort(std::span sorted, unsigned dst, S return dst; } - StdMap buckets; + StdMap buckets; for (const auto& entry : bucket) { if (std::get<1>(entry).length() == depth) { sorted[dst++] = JSValue::encode(std::get<0>(entry)); continue; } - UChar character = std::get<1>(entry).characterAt(depth); + char16_t character = std::get<1>(entry).characterAt(depth); buckets.insert(std::pair { character, SortEntryVector { } }).first->second.append(entry); } diff --git a/Source/JavaScriptCore/runtime/CachedTypes.cpp b/Source/JavaScriptCore/runtime/CachedTypes.cpp index 57e0226fa35dd..11ad05bd7bfc1 100644 --- a/Source/JavaScriptCore/runtime/CachedTypes.cpp +++ b/Source/JavaScriptCore/runtime/CachedTypes.cpp @@ -782,7 +782,7 @@ class CachedUniquedStringImplBase : public VariableLengthObject { } std::span span8() const { return { this->template buffer(), m_length }; } - std::span span16() const { return { this->template buffer(), m_length }; } + std::span span16() const { return { this->template buffer(), m_length }; } private: bool m_is8Bit : 1; diff --git a/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp b/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp index 2c757fdb44ae8..dd8d0e6dbc8b9 100644 --- a/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp +++ b/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp @@ -125,7 +125,7 @@ static StringView functionCallBase(StringView sourceText) // Note that we're scanning text right to left instead of the more common left to right, // so syntax detection is backwards. while (parenStack && idx) { - UChar curChar = sourceText[idx]; + char16_t curChar = sourceText[idx]; if (isInMultiLineComment) { if (curChar == '*' && sourceText[idx - 1] == '/') { isInMultiLineComment = false; diff --git a/Source/JavaScriptCore/runtime/ISO8601.cpp b/Source/JavaScriptCore/runtime/ISO8601.cpp index 7057653a9e11a..4724463fe0b8a 100644 --- a/Source/JavaScriptCore/runtime/ISO8601.cpp +++ b/Source/JavaScriptCore/runtime/ISO8601.cpp @@ -539,7 +539,7 @@ static bool canBeCalendar(const StringParsingBuffer& buffer) template static bool canBeTimeZone(const StringParsingBuffer& buffer, CharacterType character) { - switch (static_cast(character)) { + switch (static_cast(character)) { // UTCDesignator // https://tc39.es/proposal-temporal/#prod-UTCDesignator case 'z': @@ -585,7 +585,7 @@ static std::optional, int64_t>> parseTimeZoneAnnotati if (*buffer == '!') buffer.advance(); - switch (static_cast(*buffer)) { + switch (static_cast(*buffer)) { case '+': case '-': { auto offset = parseUTCOffset(buffer, false); @@ -717,7 +717,7 @@ static std::optional parseTimeZone(StringParsingBuffer(*buffer)) { + switch (static_cast(*buffer)) { // UTCDesignator // https://tc39.es/proposal-temporal/#prod-UTCDesignator case 'z': diff --git a/Source/JavaScriptCore/runtime/Identifier.cpp b/Source/JavaScriptCore/runtime/Identifier.cpp index 5700e3dc3e8ba..bbd568bd8ca62 100644 --- a/Source/JavaScriptCore/runtime/Identifier.cpp +++ b/Source/JavaScriptCore/runtime/Identifier.cpp @@ -27,10 +27,10 @@ namespace JSC { -Ref Identifier::add8(VM& vm, std::span s) +Ref Identifier::add8(VM& vm, std::span s) { if (s.size() == 1) { - UChar c = s.front(); + char16_t c = s.front(); ASSERT(isLatin1(c)); if (canUseSingleCharacterString(c)) return vm.smallStrings.singleCharacterStringRep(c); diff --git a/Source/JavaScriptCore/runtime/Identifier.h b/Source/JavaScriptCore/runtime/Identifier.h index 568931a639ef3..f746c0cb5a644 100644 --- a/Source/JavaScriptCore/runtime/Identifier.h +++ b/Source/JavaScriptCore/runtime/Identifier.h @@ -113,7 +113,7 @@ class Identifier { static Identifier fromString(VM&, ASCIILiteral); static Identifier fromString(VM&, std::span); - static Identifier fromString(VM&, std::span); + static Identifier fromString(VM&, std::span); static Identifier fromString(VM&, const String&); static Identifier fromString(VM&, AtomStringImpl*); static Identifier fromString(VM&, Ref&&); @@ -125,7 +125,7 @@ class Identifier { static Identifier fromUid(const PrivateName&); static Identifier fromUid(SymbolImpl&); - static Identifier createLCharFromUChar(VM& vm, std::span string) { return Identifier(vm, add8(vm, string)); } + static Identifier createLCharFromUChar(VM& vm, std::span string) { return Identifier(vm, add8(vm, string)); } JS_EXPORT_PRIVATE static Identifier from(VM&, unsigned y); JS_EXPORT_PRIVATE static Identifier from(VM&, int y); @@ -150,7 +150,7 @@ class Identifier { static bool equal(const StringImpl*, const LChar*); static inline bool equal(const StringImpl* a, const char* b) { return Identifier::equal(a, byteCast(b)); }; static bool equal(const StringImpl*, std::span); - static bool equal(const StringImpl*, std::span); + static bool equal(const StringImpl*, std::span); static bool equal(const StringImpl* a, const StringImpl* b) { return ::equal(a, b); } void dump(PrintStream&) const; @@ -159,7 +159,7 @@ class Identifier { AtomString m_string; Identifier(VM& vm, std::span string) : m_string(add(vm, string)) { ASSERT(m_string.impl()->isAtom()); } - Identifier(VM& vm, std::span string) : m_string(add(vm, string)) { ASSERT(m_string.impl()->isAtom()); } + Identifier(VM& vm, std::span string) : m_string(add(vm, string)) { ASSERT(m_string.impl()->isAtom()); } ALWAYS_INLINE Identifier(VM& vm, ASCIILiteral literal) : m_string(add(vm, literal)) { ASSERT(m_string.impl()->isAtom()); } Identifier(VM&, AtomStringImpl*); Identifier(VM&, const AtomString&); @@ -178,7 +178,7 @@ class Identifier { static bool equal(const Identifier& a, const LChar* b) { return equal(a.m_string.impl(), b); } template static Ref add(VM&, std::span); - static Ref add8(VM&, std::span); + static Ref add8(VM&, std::span); template ALWAYS_INLINE static constexpr bool canUseSingleCharacterString(T); static Ref add(VM&, StringImpl*); @@ -197,7 +197,7 @@ template <> ALWAYS_INLINE constexpr bool Identifier::canUseSingleCharacterString return true; } -template <> ALWAYS_INLINE constexpr bool Identifier::canUseSingleCharacterString(UChar c) +template <> ALWAYS_INLINE constexpr bool Identifier::canUseSingleCharacterString(char16_t c) { return (c <= maxSingleCharacterString); } @@ -248,7 +248,7 @@ inline bool Identifier::equal(const StringImpl* r, std::span s) return WTF::equal(r, s); } -inline bool Identifier::equal(const StringImpl* r, std::span s) +inline bool Identifier::equal(const StringImpl* r, std::span s) { return WTF::equal(r, s); } diff --git a/Source/JavaScriptCore/runtime/IdentifierInlines.h b/Source/JavaScriptCore/runtime/IdentifierInlines.h index 05dc8f0231f30..e9e9dcbf2e0de 100644 --- a/Source/JavaScriptCore/runtime/IdentifierInlines.h +++ b/Source/JavaScriptCore/runtime/IdentifierInlines.h @@ -90,7 +90,7 @@ inline Identifier Identifier::fromString(VM& vm, std::span s) return Identifier(vm, s); } -inline Identifier Identifier::fromString(VM& vm, std::span s) +inline Identifier Identifier::fromString(VM& vm, std::span s) { return Identifier(vm, s); } diff --git a/Source/JavaScriptCore/runtime/IntlCache.cpp b/Source/JavaScriptCore/runtime/IntlCache.cpp index 0941a7278e2a0..d099acc9f2f4b 100644 --- a/Source/JavaScriptCore/runtime/IntlCache.cpp +++ b/Source/JavaScriptCore/runtime/IntlCache.cpp @@ -43,25 +43,25 @@ UDateTimePatternGenerator* IntlCache::cacheSharedPatternGenerator(const CString& return m_cachedDateTimePatternGenerator.get(); } -Vector IntlCache::getBestDateTimePattern(const CString& locale, std::span skeleton, UErrorCode& status) +Vector IntlCache::getBestDateTimePattern(const CString& locale, std::span skeleton, UErrorCode& status) { // Always use ICU date format generator, rather than our own pattern list and matcher. auto sharedGenerator = getSharedPatternGenerator(locale, status); if (U_FAILURE(status)) return { }; - Vector patternBuffer; + Vector patternBuffer; status = callBufferProducingFunction(udatpg_getBestPatternWithOptions, sharedGenerator, skeleton.data(), skeleton.size(), UDATPG_MATCH_HOUR_FIELD_LENGTH, patternBuffer); if (U_FAILURE(status)) return { }; return patternBuffer; } -Vector IntlCache::getFieldDisplayName(const CString& locale, UDateTimePatternField field, UDateTimePGDisplayWidth width, UErrorCode& status) +Vector IntlCache::getFieldDisplayName(const CString& locale, UDateTimePatternField field, UDateTimePGDisplayWidth width, UErrorCode& status) { auto sharedGenerator = getSharedPatternGenerator(locale, status); if (U_FAILURE(status)) return { }; - Vector buffer; + Vector buffer; status = callBufferProducingFunction(udatpg_getFieldDisplayName, sharedGenerator, field, width, buffer); if (U_FAILURE(status)) return { }; diff --git a/Source/JavaScriptCore/runtime/IntlCache.h b/Source/JavaScriptCore/runtime/IntlCache.h index 4c818fd59424f..2b31dc1bdd9c6 100644 --- a/Source/JavaScriptCore/runtime/IntlCache.h +++ b/Source/JavaScriptCore/runtime/IntlCache.h @@ -39,8 +39,8 @@ class IntlCache { public: IntlCache() = default; - Vector getBestDateTimePattern(const CString& locale, std::span skeleton, UErrorCode&); - Vector getFieldDisplayName(const CString& locale, UDateTimePatternField, UDateTimePGDisplayWidth, UErrorCode&); + Vector getBestDateTimePattern(const CString& locale, std::span skeleton, UErrorCode&); + Vector getFieldDisplayName(const CString& locale, UDateTimePatternField, UDateTimePGDisplayWidth, UErrorCode&); private: UDateTimePatternGenerator* getSharedPatternGenerator(const CString& locale, UErrorCode& status) diff --git a/Source/JavaScriptCore/runtime/IntlCollator.cpp b/Source/JavaScriptCore/runtime/IntlCollator.cpp index d9073a65bdcd2..b2a2fc000d06d 100644 --- a/Source/JavaScriptCore/runtime/IntlCollator.cpp +++ b/Source/JavaScriptCore/runtime/IntlCollator.cpp @@ -446,8 +446,8 @@ void IntlCollator::checkICULocaleInvariants(const LocaleSet& locales) for (unsigned y = 0; y < 128; ++y) { if (canUseASCIIUCADUCETComparison(static_cast(x)) && canUseASCIIUCADUCETComparison(static_cast(y))) { UErrorCode status = U_ZERO_ERROR; - UChar xstring[] = { static_cast(x), 0 }; - UChar ystring[] = { static_cast(y), 0 }; + char16_t xstring[] = { static_cast(x), 0 }; + char16_t ystring[] = { static_cast(y), 0 }; auto resultICU = ucol_strcoll(&collator, xstring, 1, ystring, 1); ASSERT(U_SUCCESS(status)); auto resultJSC = compareASCIIWithUCADUCET(span(*xstring), span(*ystring)); @@ -489,7 +489,7 @@ void IntlCollator::checkICULocaleInvariants(const LocaleSet& locales) // Contractions and Expansions are defined as a rule. If there is no tailoring rule, then they should be UCA DUCET's default. auto ensureNotIncludingASCII = [&](USet& set) { - Vector buffer; + Vector buffer; for (int32_t index = 0, count = uset_getItemCount(&set); index < count; ++index) { // start and end are inclusive. UChar32 start = 0; diff --git a/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp b/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp index 2f23716496678..2963594bc77bc 100644 --- a/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp +++ b/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp @@ -118,8 +118,8 @@ static String canonicalizeTimeZoneName(const String& timeZoneName) do { status = U_ZERO_ERROR; int32_t ianaTimeZoneLength; - // Time zone names are represented as UChar[] in all related ICU APIs. - const UChar* ianaTimeZone = uenum_unext(timeZones, &ianaTimeZoneLength, &status); + // Time zone names are represented as char16_t[] in all related ICU APIs. + const char16_t* ianaTimeZone = uenum_unext(timeZones, &ianaTimeZoneLength, &status); ASSERT(U_SUCCESS(status)); // End of enumeration. @@ -135,7 +135,7 @@ static String canonicalizeTimeZoneName(const String& timeZoneName) // 1. Let ianaTimeZone be the Zone or Link name of the IANA Time Zone Database such that timeZone, converted to upper case as described in 6.1, is equal to ianaTimeZone, converted to upper case as described in 6.1. // 2. If ianaTimeZone is a Link name, then let ianaTimeZone be the corresponding Zone name as specified in the “backward” file of the IANA Time Zone Database. - Vector buffer; + Vector buffer; auto status = callBufferProducingFunction(ucal_getCanonicalTimeZoneID, ianaTimeZone, ianaTimeZoneLength, buffer, nullptr); ASSERT_UNUSED(status, U_SUCCESS(status)); canonical = String(buffer); @@ -371,7 +371,7 @@ IntlDateTimeFormat::HourCycle IntlDateTimeFormat::parseHourCycle(const String& h return HourCycle::None; } -inline IntlDateTimeFormat::HourCycle IntlDateTimeFormat::hourCycleFromSymbol(UChar symbol) +inline IntlDateTimeFormat::HourCycle IntlDateTimeFormat::hourCycleFromSymbol(char16_t symbol) { switch (symbol) { case 'K': @@ -386,7 +386,7 @@ inline IntlDateTimeFormat::HourCycle IntlDateTimeFormat::hourCycleFromSymbol(UCh return HourCycle::None; } -IntlDateTimeFormat::HourCycle IntlDateTimeFormat::hourCycleFromPattern(const Vector& pattern) +IntlDateTimeFormat::HourCycle IntlDateTimeFormat::hourCycleFromPattern(const Vector& pattern) { for (unsigned i = 0, length = pattern.size(); i < length; ++i) { auto character = pattern[i]; @@ -407,9 +407,9 @@ IntlDateTimeFormat::HourCycle IntlDateTimeFormat::hourCycleFromPattern(const Vec return HourCycle::None; } -inline void IntlDateTimeFormat::replaceHourCycleInSkeleton(Vector& skeleton, bool isHour12) +inline void IntlDateTimeFormat::replaceHourCycleInSkeleton(Vector& skeleton, bool isHour12) { - UChar skeletonCharacter = 'H'; + char16_t skeletonCharacter = 'H'; if (isHour12) skeletonCharacter = 'h'; for (unsigned i = 0, length = skeleton.size(); i < length; ++i) { @@ -432,9 +432,9 @@ inline void IntlDateTimeFormat::replaceHourCycleInSkeleton(Vector& sk } } -inline void IntlDateTimeFormat::replaceHourCycleInPattern(Vector& pattern, HourCycle hourCycle) +inline void IntlDateTimeFormat::replaceHourCycleInPattern(Vector& pattern, HourCycle hourCycle) { - UChar hourFromHourCycle = 'H'; + char16_t hourFromHourCycle = 'H'; switch (hourCycle) { case HourCycle::H11: hourFromHourCycle = 'K'; @@ -558,7 +558,7 @@ String IntlDateTimeFormat::buildSkeleton(Weekday weekday, Era era, Year year, Mo // > hourCycle = h23: "H", plus modifying the resolved pattern to use the hour symbol "H". // > hourCycle = h24: "H", plus modifying the resolved pattern to use the hour symbol "k". // - UChar skeletonCharacter = 'j'; + char16_t skeletonCharacter = 'j'; if (hour12 == TriState::Indeterminate) { switch (hourCycle) { case HourCycle::None: @@ -810,7 +810,7 @@ void IntlDateTimeFormat::initializeDateTimeFormat(JSGlobalObject* globalObject, m_timeStyle = intlOption(globalObject, options, vm.propertyNames->timeStyle, { { "full"_s, DateTimeStyle::Full }, { "long"_s, DateTimeStyle::Long }, { "medium"_s, DateTimeStyle::Medium }, { "short"_s, DateTimeStyle::Short } }, "timeStyle must be \"full\", \"long\", \"medium\", or \"short\""_s, DateTimeStyle::None); RETURN_IF_EXCEPTION(scope, void()); - Vector patternBuffer; + Vector patternBuffer; if (m_dateStyle != DateTimeStyle::None || m_timeStyle != DateTimeStyle::None) { // 30. For each row in Table 1, except the header row, do // i. Let prop be the name given in the Property column of the row. @@ -887,7 +887,7 @@ void IntlDateTimeFormat::initializeDateTimeFormat(JSGlobalObject* globalObject, specifiedHour12 = isHour12(hourCycle); HourCycle extractedHourCycle = hourCycleFromPattern(patternBuffer); if (extractedHourCycle != HourCycle::None && isHour12(extractedHourCycle) != specifiedHour12) { - Vector skeleton; + Vector skeleton; auto status = callBufferProducingFunction(udatpg_getSkeleton, nullptr, patternBuffer.data(), patternBuffer.size(), skeleton); if (U_FAILURE(status)) { throwTypeError(globalObject, scope, "failed to initialize DateTimeFormat"_s); @@ -1264,7 +1264,7 @@ JSValue IntlDateTimeFormat::format(JSGlobalObject* globalObject, double value) c if (!std::isfinite(value)) return throwRangeError(globalObject, scope, "date value is not finite in DateTimeFormat format()"_s); - Vector result; + Vector result; auto status = callBufferProducingFunction(udat_format, m_dateFormat.get(), value, result, nullptr); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to format date value"_s); @@ -1352,7 +1352,7 @@ JSValue IntlDateTimeFormat::formatToParts(JSGlobalObject* globalObject, double v if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to open field position iterator"_s); - Vector result; + Vector result; status = callBufferProducingFunction(udat_formatForFields, m_dateFormat.get(), value, result, fields.get()); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to format date value"_s); @@ -1412,7 +1412,7 @@ UDateIntervalFormat* IntlDateTimeFormat::createDateIntervalFormatIfNecessary(JSG if (m_dateIntervalFormat) return m_dateIntervalFormat.get(); - Vector pattern; + Vector pattern; { auto status = callBufferProducingFunction(udat_toPattern, m_dateFormat.get(), false, pattern); if (U_FAILURE(status)) { @@ -1421,7 +1421,7 @@ UDateIntervalFormat* IntlDateTimeFormat::createDateIntervalFormatIfNecessary(JSG } } - Vector skeleton; + Vector skeleton; { auto status = callBufferProducingFunction(udatpg_getSkeleton, nullptr, pattern.data(), pattern.size(), skeleton); if (U_FAILURE(status)) { @@ -1579,12 +1579,12 @@ JSValue IntlDateTimeFormat::formatRange(JSGlobalObject* globalObject, double sta RELEASE_AND_RETURN(scope, format(globalObject, startDate)); int32_t formattedStringLength = 0; - const UChar* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status); + const char16_t* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status); if (U_FAILURE(status)) { throwTypeError(globalObject, scope, "Failed to format date interval"_s); return { }; } - Vector buffer(std::span { formattedStringPointer, static_cast(formattedStringLength) }); + Vector buffer(std::span { formattedStringPointer, static_cast(formattedStringLength) }); replaceNarrowNoBreakSpaceOrThinSpaceWithNormalSpace(buffer); return jsString(vm, String(WTFMove(buffer))); @@ -1695,12 +1695,12 @@ JSValue IntlDateTimeFormat::formatRangeToParts(JSGlobalObject* globalObject, dou } int32_t formattedStringLength = 0; - const UChar* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status); + const char16_t* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status); if (U_FAILURE(status)) { throwTypeError(globalObject, scope, "Failed to format date interval"_s); return { }; } - Vector buffer(std::span { formattedStringPointer, static_cast(formattedStringLength) }); + Vector buffer(std::span { formattedStringPointer, static_cast(formattedStringLength) }); replaceNarrowNoBreakSpaceOrThinSpaceWithNormalSpace(buffer); StringView resultStringView(buffer.span()); diff --git a/Source/JavaScriptCore/runtime/IntlDateTimeFormat.h b/Source/JavaScriptCore/runtime/IntlDateTimeFormat.h index b5f4f5d505b52..ba574586b67c1 100644 --- a/Source/JavaScriptCore/runtime/IntlDateTimeFormat.h +++ b/Source/JavaScriptCore/runtime/IntlDateTimeFormat.h @@ -85,7 +85,7 @@ class IntlDateTimeFormat final : public JSNonFinalObject { static IntlDateTimeFormat* unwrapForOldFunctions(JSGlobalObject*, JSValue); enum class HourCycle : uint8_t { None, H11, H12, H23, H24 }; - static HourCycle hourCycleFromPattern(const Vector&); + static HourCycle hourCycleFromPattern(const Vector&); private: IntlDateTimeFormat(VM&, Structure*); @@ -124,10 +124,10 @@ class IntlDateTimeFormat final : public JSNonFinalObject { static ASCIILiteral timeZoneNameString(TimeZoneName); static ASCIILiteral formatStyleString(DateTimeStyle); - static HourCycle hourCycleFromSymbol(UChar); + static HourCycle hourCycleFromSymbol(char16_t); static HourCycle parseHourCycle(const String&); - static void replaceHourCycleInSkeleton(Vector&, bool hour12); - static void replaceHourCycleInPattern(Vector&, HourCycle); + static void replaceHourCycleInSkeleton(Vector&, bool hour12); + static void replaceHourCycleInPattern(Vector&, HourCycle); static String buildSkeleton(Weekday, Era, Year, Month, Day, TriState, HourCycle, Hour, DayPeriod, Minute, Second, unsigned, TimeZoneName); using UDateFormatDeleter = ICUDeleter; diff --git a/Source/JavaScriptCore/runtime/IntlDisplayNames.cpp b/Source/JavaScriptCore/runtime/IntlDisplayNames.cpp index 8fd61d6cfbc8d..f95cd47f0c3e9 100644 --- a/Source/JavaScriptCore/runtime/IntlDisplayNames.cpp +++ b/Source/JavaScriptCore/runtime/IntlDisplayNames.cpp @@ -189,7 +189,7 @@ JSValue IntlDisplayNames::of(JSGlobalObject* globalObject, JSValue codeValue) co return { }; }; - Vector buffer; + Vector buffer; UErrorCode status = U_ZERO_ERROR; CString canonicalCode; switch (m_type) { @@ -249,7 +249,7 @@ JSValue IntlDisplayNames::of(JSGlobalObject* globalObject, JSValue codeValue) co } // 6. Let code be the result of mapping code to upper case as described in 6.1. - const UChar currency[4] = { + const char16_t currency[4] = { toASCIIUpper(code[0]), toASCIIUpper(code[1]), toASCIIUpper(code[2]), @@ -258,14 +258,14 @@ JSValue IntlDisplayNames::of(JSGlobalObject* globalObject, JSValue codeValue) co // The result of ucurr_getName is static string so that we do not need to free the result. int32_t length = 0; UBool isChoiceFormat = false; // We need to pass this, otherwise, we will see crash in ICU 64. - const UChar* result = ucurr_getName(currency, m_localeCString.data(), style, &isChoiceFormat, &length, &status); + const char16_t* result = ucurr_getName(currency, m_localeCString.data(), style, &isChoiceFormat, &length, &status); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "Failed to query a display name."_s); // ucurr_getName returns U_USING_DEFAULT_WARNING if the display-name is not found. But U_USING_DEFAULT_WARNING is returned even if // narrow and short results are the same: narrow "USD" is "$" with U_USING_DEFAULT_WARNING since short "USD" is also "$". We need to check // result == currency to check whether ICU actually failed to find the corresponding display-name. This pointer comparison is ensured by // ICU API document. - // > Returns pointer to display string of 'len' UChars. If the resource data contains no entry for 'currency', then 'currency' itself is returned. + // > Returns pointer to display string of 'len' char16_ts. If the resource data contains no entry for 'currency', then 'currency' itself is returned. if (status == U_USING_DEFAULT_WARNING && result == currency) return (m_fallback == Fallback::None) ? jsUndefined() : jsString(vm, StringView({ currency, 3 })); return jsString(vm, String({ result, static_cast(length) })); diff --git a/Source/JavaScriptCore/runtime/IntlDurationFormat.cpp b/Source/JavaScriptCore/runtime/IntlDurationFormat.cpp index 78e9106ee0a4a..c066e80ab130f 100644 --- a/Source/JavaScriptCore/runtime/IntlDurationFormat.cpp +++ b/Source/JavaScriptCore/runtime/IntlDurationFormat.cpp @@ -305,7 +305,7 @@ static String retrieveSeparator(const CString& locale, const String& numberingSy return fallbackTimeSeparator; int32_t length = 0; - const UChar* data = ures_getStringByKey(symbolsBundle.get(), "timeSeparator", &length, &status); + const char16_t* data = ures_getStringByKey(symbolsBundle.get(), "timeSeparator", &length, &status); if (U_FAILURE(status)) return fallbackTimeSeparator; @@ -489,7 +489,7 @@ static Vector collectElements(JSGlobalObject* globalObject, const IntlD auto scope = DECLARE_THROW_SCOPE(vm); UErrorCode status = U_ZERO_ERROR; - Vector buffer; + Vector buffer; status = callBufferProducingFunction(unumf_resultToString, formattedNumber, buffer); if (U_FAILURE(status)) { throwTypeError(globalObject, scope, "Failed to format a number."_s); @@ -688,7 +688,7 @@ JSValue IntlDurationFormat::format(JSGlobalObject* globalObject, ISO8601::Durati ListFormatInput input(WTFMove(stringList)); - Vector result; + Vector result; auto status = callBufferProducingFunction(ulistfmt_format, m_listFormat.get(), input.stringPointers(), input.stringLengths(), input.size(), result); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to format list of strings"_s); @@ -766,7 +766,7 @@ JSValue IntlDurationFormat::formatToParts(JSGlobalObject* globalObject, ISO8601: return throwOutOfMemoryError(globalObject, scope); int32_t formattedStringLength = 0; - const UChar* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status); + const char16_t* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to format list of strings"_s); StringView resultStringView(std::span(formattedStringPointer, formattedStringLength)); diff --git a/Source/JavaScriptCore/runtime/IntlListFormat.cpp b/Source/JavaScriptCore/runtime/IntlListFormat.cpp index c25cc5f9e90fa..c24073ce31711 100644 --- a/Source/JavaScriptCore/runtime/IntlListFormat.cpp +++ b/Source/JavaScriptCore/runtime/IntlListFormat.cpp @@ -185,7 +185,7 @@ JSValue IntlListFormat::format(JSGlobalObject* globalObject, JSValue list) const ListFormatInput input(WTFMove(stringList)); - Vector result; + Vector result; auto status = callBufferProducingFunction(ulistfmt_format, m_listFormat.get(), input.stringPointers(), input.stringLengths(), input.size(), result); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to format list of strings"_s); @@ -229,7 +229,7 @@ JSValue IntlListFormat::formatToParts(JSGlobalObject* globalObject, JSValue list return throwOutOfMemoryError(globalObject, scope); int32_t formattedStringLength = 0; - const UChar* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status); + const char16_t* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to format list of strings"_s); StringView resultStringView(std::span(formattedStringPointer, formattedStringLength)); diff --git a/Source/JavaScriptCore/runtime/IntlLocale.cpp b/Source/JavaScriptCore/runtime/IntlLocale.cpp index 60b7402ef1801..025cf5ae098d7 100644 --- a/Source/JavaScriptCore/runtime/IntlLocale.cpp +++ b/Source/JavaScriptCore/runtime/IntlLocale.cpp @@ -676,8 +676,8 @@ JSArray* IntlLocale::hourCycles(JSGlobalObject* globalObject) } // Use "j" skeleton and parse pattern to retrieve the configured hour-cycle information. - constexpr const UChar skeleton[] = { 'j', 0 }; - Vector pattern; + constexpr const char16_t skeleton[] = { 'j', 0 }; + Vector pattern; status = callBufferProducingFunction(udatpg_getBestPatternWithOptions, generator.get(), skeleton, 1, UDATPG_MATCH_HOUR_FIELD_LENGTH, pattern); if (!U_SUCCESS(status)) { throwTypeError(globalObject, scope, "invalid locale"_s); diff --git a/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp b/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp index 1f0aa041c2018..efdcfcf626aed 100644 --- a/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp +++ b/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp @@ -694,7 +694,7 @@ JSValue IntlNumberFormat::format(JSGlobalObject* globalObject, double value) con value = purifyNaN(value); - Vector buffer; + Vector buffer; #if HAVE(ICU_U_NUMBER_FORMATTER) ASSERT(m_numberFormatter); UErrorCode status = U_ZERO_ERROR; @@ -725,7 +725,7 @@ JSValue IntlNumberFormat::format(JSGlobalObject* globalObject, IntlMathematicalV value.ensureNonDouble(); const auto& string = value.getString(); - Vector buffer; + Vector buffer; #if HAVE(ICU_U_NUMBER_FORMATTER) ASSERT(m_numberFormatter); UErrorCode status = U_ZERO_ERROR; @@ -772,7 +772,7 @@ JSValue IntlNumberFormat::formatRange(JSGlobalObject* globalObject, double start return throwTypeError(globalObject, scope, "failed to format a range"_s); int32_t length = 0; - const UChar* string = ufmtval_getString(formattedValue, &length, &status); + const char16_t* string = ufmtval_getString(formattedValue, &length, &status); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to format a range"_s); @@ -809,7 +809,7 @@ JSValue IntlNumberFormat::formatRange(JSGlobalObject* globalObject, IntlMathemat return throwTypeError(globalObject, scope, "failed to format a range"_s); int32_t length = 0; - const UChar* string = ufmtval_getString(formattedValue, &length, &status); + const char16_t* string = ufmtval_getString(formattedValue, &length, &status); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to format a range"_s); @@ -955,7 +955,7 @@ void IntlNumberFormat::formatRangeToPartsInternal(JSGlobalObject* globalObject, UErrorCode status = U_ZERO_ERROR; int32_t formattedStringLength = 0; - const UChar* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status); + const char16_t* formattedStringPointer = ufmtval_getString(formattedValue, &formattedStringLength, &status); if (U_FAILURE(status)) { throwTypeError(globalObject, scope, "Failed to format number range"_s); return; @@ -1467,7 +1467,7 @@ JSValue IntlNumberFormat::formatToParts(JSGlobalObject* globalObject, double val if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to open field position iterator"_s); - Vector result; + Vector result; #if HAVE(ICU_U_NUMBER_FORMATTER) ASSERT(m_numberFormatter); auto formattedNumber = std::unique_ptr>(unumf_openResult(&status)); @@ -1517,7 +1517,7 @@ JSValue IntlNumberFormat::formatToParts(JSGlobalObject* globalObject, IntlMathem if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to open field position iterator"_s); - Vector result; + Vector result; ASSERT(m_numberFormatter); auto formattedNumber = std::unique_ptr>(unumf_openResult(&status)); if (U_FAILURE(status)) diff --git a/Source/JavaScriptCore/runtime/IntlObject.cpp b/Source/JavaScriptCore/runtime/IntlObject.cpp index 51dbe4447db38..755357e168f98 100644 --- a/Source/JavaScriptCore/runtime/IntlObject.cpp +++ b/Source/JavaScriptCore/runtime/IntlObject.cpp @@ -1158,7 +1158,7 @@ static VariantCode parseVariantCode(StringView string) return result; } -static unsigned convertToUnicodeSingletonIndex(UChar singleton) +static unsigned convertToUnicodeSingletonIndex(char16_t singleton) { ASSERT(isASCIIAlphanumeric(singleton)); singleton = toASCIILower(singleton); @@ -1445,7 +1445,7 @@ bool LanguageTagParser::parseExtensionsAndPUExtensions() while (true) { if (m_current.length() != 1) return true; - UChar prefixCode = m_current[0]; + char16_t prefixCode = m_current[0]; if (!isASCIIAlphanumeric(prefixCode)) return true; diff --git a/Source/JavaScriptCore/runtime/IntlObjectInlines.h b/Source/JavaScriptCore/runtime/IntlObjectInlines.h index 90e3ffae62c0b..e731949bd0a45 100644 --- a/Source/JavaScriptCore/runtime/IntlObjectInlines.h +++ b/Source/JavaScriptCore/runtime/IntlObjectInlines.h @@ -198,7 +198,7 @@ ResultType intlStringOrBooleanOption(JSGlobalObject* globalObject, JSObject* opt return { }; } -ALWAYS_INLINE bool canUseASCIIUCADUCETComparison(UChar character) +ALWAYS_INLINE bool canUseASCIIUCADUCETComparison(char16_t character) { return isASCII(character) && ducetLevel1Weights[character]; } @@ -208,7 +208,7 @@ ALWAYS_INLINE bool canUseASCIIUCADUCETComparison(LChar character) return ducetLevel1Weights[character]; } -ALWAYS_INLINE bool followedByNonLatinCharacter(std::span characters, size_t index) +ALWAYS_INLINE bool followedByNonLatinCharacter(std::span characters, size_t index) { size_t nextIndex = index + 1; if (characters.size() > nextIndex) @@ -363,12 +363,12 @@ class ListFormatInput { } int32_t size() const { return m_stringPointers.size(); } - const UChar* const* stringPointers() const { return m_stringPointers.data(); } + const char16_t* const* stringPointers() const { return m_stringPointers.data(); } const int32_t* stringLengths() const { return m_stringLengths.data(); } private: Vector m_strings; - Vector m_stringPointers; + Vector m_stringPointers; Vector m_stringLengths; }; diff --git a/Source/JavaScriptCore/runtime/IntlPluralRules.cpp b/Source/JavaScriptCore/runtime/IntlPluralRules.cpp index af58373c78e81..801b7fcada51e 100644 --- a/Source/JavaScriptCore/runtime/IntlPluralRules.cpp +++ b/Source/JavaScriptCore/runtime/IntlPluralRules.cpp @@ -267,7 +267,7 @@ JSValue IntlPluralRules::select(JSGlobalObject* globalObject, double value) cons unumf_formatDouble(m_numberFormatter.get(), value, formattedNumber.get(), &status); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to select plural value"_s); - Vector buffer; + Vector buffer; status = callBufferProducingFunction(uplrules_selectFormatted, m_pluralRules.get(), formattedNumber.get(), buffer); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to select plural value"_s); @@ -302,7 +302,7 @@ JSValue IntlPluralRules::selectRange(JSGlobalObject* globalObject, double start, if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to select range of plural value"_s); - Vector buffer; + Vector buffer; status = callBufferProducingFunction(uplrules_selectForRange, m_pluralRules.get(), range.get(), buffer); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to select plural value"_s); diff --git a/Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.cpp b/Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.cpp index d1ee95fc6a6c5..fd547b47e71ae 100644 --- a/Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.cpp +++ b/Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.cpp @@ -246,7 +246,7 @@ String IntlRelativeTimeFormat::formatInternal(JSGlobalObject* globalObject, doub auto formatRelativeTime = m_numeric ? ureldatefmt_formatNumeric : ureldatefmt_format; - Vector result; + Vector result; auto status = callBufferProducingFunction(formatRelativeTime, m_relativeDateTimeFormatter.get(), value, unitType.value(), result); if (UNLIKELY(U_FAILURE(status))) { throwTypeError(globalObject, scope, "failed to format relative time"_s); @@ -283,7 +283,7 @@ JSValue IntlRelativeTimeFormat::formatToParts(JSGlobalObject* globalObject, doub double absValue = std::abs(value); - Vector buffer; + Vector buffer; status = callBufferProducingFunction(unum_formatDoubleForFields, m_numberFormat.get(), absValue, buffer, iterator.get()); if (U_FAILURE(status)) return throwTypeError(globalObject, scope, "failed to format relative time"_s); diff --git a/Source/JavaScriptCore/runtime/IntlSegmentIterator.cpp b/Source/JavaScriptCore/runtime/IntlSegmentIterator.cpp index a0363f8e7fc8e..f854f52b0338f 100644 --- a/Source/JavaScriptCore/runtime/IntlSegmentIterator.cpp +++ b/Source/JavaScriptCore/runtime/IntlSegmentIterator.cpp @@ -37,7 +37,7 @@ namespace JSC { const ClassInfo IntlSegmentIterator::s_info = { "Object"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(IntlSegmentIterator) }; -IntlSegmentIterator* IntlSegmentIterator::create(VM& vm, Structure* structure, std::unique_ptr&& segmenter, Box> buffer, JSString* string, IntlSegmenter::Granularity granularity) +IntlSegmentIterator* IntlSegmentIterator::create(VM& vm, Structure* structure, std::unique_ptr&& segmenter, Box> buffer, JSString* string, IntlSegmenter::Granularity granularity) { auto* object = new (NotNull, allocateCell(vm)) IntlSegmentIterator(vm, structure, WTFMove(segmenter), WTFMove(buffer), granularity, string); object->finishCreation(vm); @@ -49,7 +49,7 @@ Structure* IntlSegmentIterator::createStructure(VM& vm, JSGlobalObject* globalOb return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info()); } -IntlSegmentIterator::IntlSegmentIterator(VM& vm, Structure* structure, std::unique_ptr&& segmenter, Box>&& buffer, IntlSegmenter::Granularity granularity, JSString* string) +IntlSegmentIterator::IntlSegmentIterator(VM& vm, Structure* structure, std::unique_ptr&& segmenter, Box>&& buffer, IntlSegmenter::Granularity granularity, JSString* string) : Base(vm, structure) , m_segmenter(WTFMove(segmenter)) , m_buffer(WTFMove(buffer)) diff --git a/Source/JavaScriptCore/runtime/IntlSegmentIterator.h b/Source/JavaScriptCore/runtime/IntlSegmentIterator.h index a491ea48bedde..86638dfaf7384 100644 --- a/Source/JavaScriptCore/runtime/IntlSegmentIterator.h +++ b/Source/JavaScriptCore/runtime/IntlSegmentIterator.h @@ -47,7 +47,7 @@ class IntlSegmentIterator final : public JSNonFinalObject { return vm.intlSegmentIteratorSpace(); } - static IntlSegmentIterator* create(VM&, Structure*, std::unique_ptr&&, Box>, JSString*, IntlSegmenter::Granularity); + static IntlSegmentIterator* create(VM&, Structure*, std::unique_ptr&&, Box>, JSString*, IntlSegmenter::Granularity); static Structure* createStructure(VM&, JSGlobalObject*, JSValue); DECLARE_INFO; @@ -57,12 +57,12 @@ class IntlSegmentIterator final : public JSNonFinalObject { DECLARE_VISIT_CHILDREN; private: - IntlSegmentIterator(VM&, Structure*, std::unique_ptr&&, Box>&&, IntlSegmenter::Granularity, JSString*); + IntlSegmentIterator(VM&, Structure*, std::unique_ptr&&, Box>&&, IntlSegmenter::Granularity, JSString*); DECLARE_DEFAULT_FINISH_CREATION; std::unique_ptr m_segmenter; - Box> m_buffer; + Box> m_buffer; WriteBarrier m_string; IntlSegmenter::Granularity m_granularity; }; diff --git a/Source/JavaScriptCore/runtime/IntlSegmenter.cpp b/Source/JavaScriptCore/runtime/IntlSegmenter.cpp index ac04023761b90..fe9be8bfe37cc 100644 --- a/Source/JavaScriptCore/runtime/IntlSegmenter.cpp +++ b/Source/JavaScriptCore/runtime/IntlSegmenter.cpp @@ -123,7 +123,7 @@ JSValue IntlSegmenter::segment(JSGlobalObject* globalObject, JSValue stringValue return { }; } - auto upconvertedCharacters = Box>::create(expectedCharacters.value()); + auto upconvertedCharacters = Box>::create(expectedCharacters.value()); UErrorCode status = U_ZERO_ERROR; auto segmenter = std::unique_ptr(cloneUBreakIterator(m_segmenter.get(), &status)); diff --git a/Source/JavaScriptCore/runtime/IntlSegments.cpp b/Source/JavaScriptCore/runtime/IntlSegments.cpp index cac69283bc6e4..4244ff4096204 100644 --- a/Source/JavaScriptCore/runtime/IntlSegments.cpp +++ b/Source/JavaScriptCore/runtime/IntlSegments.cpp @@ -39,7 +39,7 @@ namespace JSC { const ClassInfo IntlSegments::s_info = { "Object"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(IntlSegments) }; -IntlSegments* IntlSegments::create(VM& vm, Structure* structure, std::unique_ptr&& segmenter, Box>&& buffer, JSString* string, IntlSegmenter::Granularity granularity) +IntlSegments* IntlSegments::create(VM& vm, Structure* structure, std::unique_ptr&& segmenter, Box>&& buffer, JSString* string, IntlSegmenter::Granularity granularity) { auto* object = new (NotNull, allocateCell(vm)) IntlSegments(vm, structure, WTFMove(segmenter), WTFMove(buffer), granularity, string); object->finishCreation(vm); @@ -51,7 +51,7 @@ Structure* IntlSegments::createStructure(VM& vm, JSGlobalObject* globalObject, J return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info()); } -IntlSegments::IntlSegments(VM& vm, Structure* structure, std::unique_ptr&& segmenter, Box>&& buffer, IntlSegmenter::Granularity granularity, JSString* string) +IntlSegments::IntlSegments(VM& vm, Structure* structure, std::unique_ptr&& segmenter, Box>&& buffer, IntlSegmenter::Granularity granularity, JSString* string) : Base(vm, structure) , m_segmenter(WTFMove(segmenter)) , m_buffer(WTFMove(buffer)) diff --git a/Source/JavaScriptCore/runtime/IntlSegments.h b/Source/JavaScriptCore/runtime/IntlSegments.h index 750da050409c1..f062546867b23 100644 --- a/Source/JavaScriptCore/runtime/IntlSegments.h +++ b/Source/JavaScriptCore/runtime/IntlSegments.h @@ -46,7 +46,7 @@ class IntlSegments final : public JSNonFinalObject { return vm.intlSegmentsSpace(); } - static IntlSegments* create(VM&, Structure*, std::unique_ptr&&, Box>&&, JSString*, IntlSegmenter::Granularity); + static IntlSegments* create(VM&, Structure*, std::unique_ptr&&, Box>&&, JSString*, IntlSegmenter::Granularity); static Structure* createStructure(VM&, JSGlobalObject*, JSValue); DECLARE_INFO; @@ -57,12 +57,12 @@ class IntlSegments final : public JSNonFinalObject { DECLARE_VISIT_CHILDREN; private: - IntlSegments(VM&, Structure*, std::unique_ptr&&, Box>&&, IntlSegmenter::Granularity, JSString*); + IntlSegments(VM&, Structure*, std::unique_ptr&&, Box>&&, IntlSegmenter::Granularity, JSString*); DECLARE_DEFAULT_FINISH_CREATION; std::unique_ptr m_segmenter; - Box> m_buffer; + Box> m_buffer; WriteBarrier m_string; IntlSegmenter::Granularity m_granularity; }; diff --git a/Source/JavaScriptCore/runtime/JSDateMath.cpp b/Source/JavaScriptCore/runtime/JSDateMath.cpp index 1eb8995b135cb..ce82f6138ae8c 100644 --- a/Source/JavaScriptCore/runtime/JSDateMath.cpp +++ b/Source/JavaScriptCore/runtime/JSDateMath.cpp @@ -501,13 +501,13 @@ String DateCache::timeZoneDisplayName(bool isDST) auto& timeZoneCache = *this->timeZoneCache(); CString language = defaultLanguage().utf8(); { - Vector standardDisplayNameBuffer; + Vector standardDisplayNameBuffer; auto status = callBufferProducingFunction(ucal_getTimeZoneDisplayName, timeZoneCache.m_calendar.get(), UCAL_STANDARD, language.data(), standardDisplayNameBuffer); if (U_SUCCESS(status)) m_timeZoneStandardDisplayNameCache = String::adopt(WTFMove(standardDisplayNameBuffer)); } { - Vector dstDisplayNameBuffer; + Vector dstDisplayNameBuffer; auto status = callBufferProducingFunction(ucal_getTimeZoneDisplayName, timeZoneCache.m_calendar.get(), UCAL_DST, language.data(), dstDisplayNameBuffer); if (U_SUCCESS(status)) m_timeZoneDSTDisplayNameCache = String::adopt(WTFMove(dstDisplayNameBuffer)); @@ -555,10 +555,10 @@ DateCache::DateCache() #endif } -static std::tuple> retrieveTimeZoneInformation() +static std::tuple> retrieveTimeZoneInformation() { Locker locker { timeZoneCacheLock }; - static NeverDestroyed, uint64_t>> globalCache; + static NeverDestroyed, uint64_t>> globalCache; bool isCacheStale = true; uint64_t currentID = 0; @@ -567,7 +567,7 @@ static std::tuple> retrieveTimeZoneInformation() isCacheStale = std::get<2>(globalCache.get()) != currentID; #endif if (isCacheStale) { - Vector timeZoneID; + Vector timeZoneID; getTimeZoneOverride(timeZoneID); String canonical; UErrorCode status = U_ZERO_ERROR; @@ -576,7 +576,7 @@ static std::tuple> retrieveTimeZoneInformation() ASSERT_UNUSED(status, U_SUCCESS(status)); } if (U_SUCCESS(status)) { - Vector canonicalBuffer; + Vector canonicalBuffer; auto status = callBufferProducingFunction(ucal_getCanonicalTimeZoneID, timeZoneID.data(), timeZoneID.size(), canonicalBuffer, nullptr); if (U_SUCCESS(status)) canonical = String(canonicalBuffer); diff --git a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.cpp b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.cpp index 4ecd99085db8e..ec9576fc57e34 100644 --- a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.cpp +++ b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.cpp @@ -204,7 +204,7 @@ WARN_UNUSED_RETURN size_t decodeHex(std::span span, std::span span, std::span result) +WARN_UNUSED_RETURN size_t decodeHex(std::span span, std::span result) { return decodeHexImpl(span, result); } diff --git a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.h b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.h index 363ab192da243..b1ee6c4c0be4b 100644 --- a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.h +++ b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.h @@ -151,6 +151,6 @@ JSC_DECLARE_HOST_FUNCTION(uint8ArrayConstructorFromBase64); JSC_DECLARE_HOST_FUNCTION(uint8ArrayConstructorFromHex); WARN_UNUSED_RETURN size_t decodeHex(std::span, std::span result); -WARN_UNUSED_RETURN size_t decodeHex(std::span, std::span result); +WARN_UNUSED_RETURN size_t decodeHex(std::span, std::span result); } // namespace JSC diff --git a/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp b/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp index eeb703b22585f..ded357f472781 100644 --- a/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp +++ b/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp @@ -166,7 +166,7 @@ static JSValue decode(JSGlobalObject* globalObject, std::span ch StringBuilder builder(OverflowPolicy::RecordOverflow); size_t k = 0; - UChar u = 0; + char16_t u = 0; while (k < characters.size()) { const CharType* p = characters.data() + k; CharType c = *p; @@ -201,7 +201,7 @@ static JSValue decode(JSGlobalObject* globalObject, std::span ch u = U16_TRAIL(character); } else { ASSERT(!U_IS_SURROGATE(character)); - u = static_cast(character); + u = static_cast(character); } } } @@ -215,7 +215,7 @@ static JSValue decode(JSGlobalObject* globalObject, std::span ch && isASCIIHexDigit(p[2]) && isASCIIHexDigit(p[3]) && isASCIIHexDigit(p[4]) && isASCIIHexDigit(p[5])) { charLen = 6; - u = Lexer::convertUnicode(p[2], p[3], p[4], p[5]); + u = Lexer::convertUnicode(p[2], p[3], p[4], p[5]); } } if (charLen && (u >= 128 || !doNotUnescape.get(static_cast(u)))) { @@ -428,7 +428,7 @@ double jsToNumber(StringView s) static double parseFloat(StringView s) { if (s.length() == 1) { - UChar c = s[0]; + char16_t c = s[0]; if (isASCIIDigit(c)) return c - '0'; return PNaN; @@ -509,7 +509,7 @@ JSC_DEFINE_HOST_FUNCTION(globalFuncEval, (JSGlobalObject* globalObject, CallFram LiteralParser preparser(globalObject, programSource.span8(), SloppyJSON, nullptr); parsedObject = preparser.tryLiteralParse(); } else { - LiteralParser preparser(globalObject, programSource.span16(), SloppyJSON, nullptr); + LiteralParser preparser(globalObject, programSource.span16(), SloppyJSON, nullptr); parsedObject = preparser.tryLiteralParse(); } RETURN_IF_EXCEPTION(scope, encodedJSValue()); @@ -666,7 +666,7 @@ JSC_DEFINE_HOST_FUNCTION(globalFuncUnescape, (JSGlobalObject* globalObject, Call auto c = characters.subspan(k); if (c[0] == '%' && k <= length - 6 && c[1] == 'u') { if (isASCIIHexDigit(c[2]) && isASCIIHexDigit(c[3]) && isASCIIHexDigit(c[4]) && isASCIIHexDigit(c[5])) { - builder.append(Lexer::convertUnicode(c[2], c[3], c[4], c[5])); + builder.append(Lexer::convertUnicode(c[2], c[3], c[4], c[5])); k += 6; continue; } @@ -683,15 +683,15 @@ JSC_DEFINE_HOST_FUNCTION(globalFuncUnescape, (JSGlobalObject* globalObject, Call while (k < length) { auto c = characters.subspan(k); - UChar convertedUChar; + char16_t convertedUChar; if (c[0] == '%' && k <= length - 6 && c[1] == 'u') { if (isASCIIHexDigit(c[2]) && isASCIIHexDigit(c[3]) && isASCIIHexDigit(c[4]) && isASCIIHexDigit(c[5])) { - convertedUChar = Lexer::convertUnicode(c[2], c[3], c[4], c[5]); + convertedUChar = Lexer::convertUnicode(c[2], c[3], c[4], c[5]); c = span(convertedUChar); k += 5; } } else if (c[0] == '%' && k <= length - 3 && isASCIIHexDigit(c[1]) && isASCIIHexDigit(c[2])) { - convertedUChar = UChar(Lexer::convertHex(c[1], c[2])); + convertedUChar = char16_t(Lexer::convertHex(c[1], c[2])); c = span(convertedUChar); k += 2; } diff --git a/Source/JavaScriptCore/runtime/JSImmutableButterfly.cpp b/Source/JavaScriptCore/runtime/JSImmutableButterfly.cpp index 0456efb2297b8..974a711db864a 100644 --- a/Source/JavaScriptCore/runtime/JSImmutableButterfly.cpp +++ b/Source/JavaScriptCore/runtime/JSImmutableButterfly.cpp @@ -182,15 +182,15 @@ JSImmutableButterfly* JSImmutableButterfly::createFromString(JSGlobalObject* glo return result; } - auto forEachCodePointViaStringIteratorProtocol = [](std::span characters, auto func) { + auto forEachCodePointViaStringIteratorProtocol = [](std::span characters, auto func) { for (size_t i = 0; i < characters.size(); ++i) { - UChar character = characters[i]; + char16_t character = characters[i]; if (!U16_IS_LEAD(character) || (i + 1) == characters.size()) { if (func(i, 1) == IterationStatus::Done) return; continue; } - UChar second = characters[i + 1]; + char16_t second = characters[i + 1]; if (!U16_IS_TRAIL(second)) { if (func(i, 1) == IterationStatus::Done) return; @@ -224,7 +224,7 @@ JSImmutableButterfly* JSImmutableButterfly::createFromString(JSGlobalObject* glo value = jsSingleCharacterString(vm, characters[index]); else { ASSERT(size == 2); - const UChar string[2] = { + const char16_t string[2] = { characters[index], characters[index + 1], }; diff --git a/Source/JavaScriptCore/runtime/JSONAtomStringCache.h b/Source/JavaScriptCore/runtime/JSONAtomStringCache.h index f6f0c5e5f5552..6f5b72c915772 100644 --- a/Source/JavaScriptCore/runtime/JSONAtomStringCache.h +++ b/Source/JavaScriptCore/runtime/JSONAtomStringCache.h @@ -37,8 +37,8 @@ class JSONAtomStringCache { static constexpr auto capacity = 256; struct Slot { - UChar m_buffer[maxStringLengthForCache] { }; - UChar m_length { 0 }; + char16_t m_buffer[maxStringLengthForCache] { }; + char16_t m_length { 0 }; RefPtr m_impl; }; static_assert(sizeof(Slot) <= 64); @@ -62,7 +62,7 @@ class JSONAtomStringCache { template Ref make(std::span); - ALWAYS_INLINE Slot& cacheSlot(UChar firstCharacter, UChar lastCharacter, UChar length) + ALWAYS_INLINE Slot& cacheSlot(char16_t firstCharacter, char16_t lastCharacter, char16_t length) { unsigned hash = (firstCharacter << 6) ^ ((lastCharacter << 14) ^ firstCharacter); hash += (hash >> 14) + (length << 14); diff --git a/Source/JavaScriptCore/runtime/JSONObject.cpp b/Source/JavaScriptCore/runtime/JSONObject.cpp index cf9d46506a1db..c1b2f8fb28ef1 100644 --- a/Source/JavaScriptCore/runtime/JSONObject.cpp +++ b/Source/JavaScriptCore/runtime/JSONObject.cpp @@ -1128,7 +1128,7 @@ static ALWAYS_INLINE bool stringCopySameType(std::span span, Cha return false; } -static ALWAYS_INLINE bool stringCopyUpconvert(std::span span, UChar* cursor) +static ALWAYS_INLINE bool stringCopyUpconvert(std::span span, char16_t* cursor) { #if (CPU(ARM64) || CPU(X86_64)) && COMPILER(CLANG) constexpr size_t stride = SIMD::stride; @@ -1494,12 +1494,12 @@ static NEVER_INLINE String stringify(JSGlobalObject& globalObject, JSValue value return result; if (failureReason == FailureReason::Found16BitEarly) { failureReason = std::nullopt; - if (String result = FastStringifier::stringify(globalObject, value, replacer, space, failureReason); !result.isNull()) + if (String result = FastStringifier::stringify(globalObject, value, replacer, space, failureReason); !result.isNull()) return result; if (failureReason == FailureReason::BufferFull) { failureReason = std::nullopt; - if (String result = FastStringifier::stringify(globalObject, value, replacer, space, failureReason); !result.isNull()) + if (String result = FastStringifier::stringify(globalObject, value, replacer, space, failureReason); !result.isNull()) return result; } } else if (failureReason == FailureReason::BufferFull) { @@ -1821,7 +1821,7 @@ static NEVER_INLINE JSValue jsonParseSlow(JSGlobalObject* globalObject, JSString return { }; } } else { - LiteralParser jsonParser(globalObject, view.span16(), StrictJSON); + LiteralParser jsonParser(globalObject, view.span16(), StrictJSON); unfiltered = jsonParser.tryLiteralParse(Options::useJSONSourceTextAccess() ? &ranges : nullptr); EXCEPTION_ASSERT(!scope.exception() || !unfiltered); if (!unfiltered) { @@ -1864,7 +1864,7 @@ JSC_DEFINE_HOST_FUNCTION(jsonProtoFuncParse, (JSGlobalObject* globalObject, Call return JSValue::encode(unfiltered); } - LiteralParser jsonParser(globalObject, view->span16(), StrictJSON); + LiteralParser jsonParser(globalObject, view->span16(), StrictJSON); JSValue unfiltered = jsonParser.tryLiteralParse(); EXCEPTION_ASSERT(!scope.exception() || !unfiltered); if (!unfiltered) { @@ -1891,7 +1891,7 @@ JSValue JSONParse(JSGlobalObject* globalObject, StringView json) return jsonParser.tryLiteralParse(); } - LiteralParser jsonParser(globalObject, json.span16(), StrictJSON); + LiteralParser jsonParser(globalObject, json.span16(), StrictJSON); return jsonParser.tryLiteralParse(); } @@ -1912,7 +1912,7 @@ JSValue JSONParseWithException(JSGlobalObject* globalObject, StringView json) return result; } - LiteralParser jsonParser(globalObject, json.span16(), StrictJSON); + LiteralParser jsonParser(globalObject, json.span16(), StrictJSON); JSValue result = jsonParser.tryLiteralParse(); RETURN_IF_EXCEPTION(scope, { }); if (!result) @@ -1946,7 +1946,7 @@ JSC_DEFINE_HOST_FUNCTION(jsonProtoFuncRawJSON, (JSGlobalObject* globalObject, Ca JSString* jsString = callFrame->argument(0).toString(globalObject); RETURN_IF_EXCEPTION(scope, { }); - auto isJSONWhitespace = [](UChar character) { + auto isJSONWhitespace = [](char16_t character) { return character == 0x0009 || character == 0x000A || character == 0x000D || character == 0x0020; }; @@ -1957,13 +1957,13 @@ JSC_DEFINE_HOST_FUNCTION(jsonProtoFuncRawJSON, (JSGlobalObject* globalObject, Ca return { }; } - UChar firstCharacter = string[0]; + char16_t firstCharacter = string[0]; if (UNLIKELY(isJSONWhitespace(firstCharacter))) { throwSyntaxError(globalObject, scope, makeString("JSON.rawJSON cannot accept string starting with '"_s, firstCharacter, "'"_s)); return { }; } - UChar lastCharacter = string[string.length() - 1]; + char16_t lastCharacter = string[string.length() - 1]; if (UNLIKELY(isJSONWhitespace(lastCharacter))) { throwSyntaxError(globalObject, scope, makeString("JSON.rawJSON cannot accept string ending with '"_s, lastCharacter, "'"_s)); return { }; @@ -1980,7 +1980,7 @@ JSC_DEFINE_HOST_FUNCTION(jsonProtoFuncRawJSON, (JSGlobalObject* globalObject, Ca return { }; } } else { - LiteralParser jsonParser(globalObject, string.span16(), StrictJSON); + LiteralParser jsonParser(globalObject, string.span16(), StrictJSON); result = jsonParser.tryLiteralParsePrimitiveValue(); RETURN_IF_EXCEPTION(scope, { }); if (UNLIKELY(!result)) { diff --git a/Source/JavaScriptCore/runtime/JSString.cpp b/Source/JavaScriptCore/runtime/JSString.cpp index e76be7f41078b..243e99a29f61b 100644 --- a/Source/JavaScriptCore/runtime/JSString.cpp +++ b/Source/JavaScriptCore/runtime/JSString.cpp @@ -173,9 +173,9 @@ AtomString JSRopeString::resolveRopeToAtomString(JSGlobalObject* globalObject) c resolveRopeInternalNoSubstring(std::span { buffer }.first(length()), stackLimit); atomString = std::span { buffer }.first(length()); } else { - std::array buffer; + std::array buffer; resolveRopeInternalNoSubstring(std::span { buffer }.first(length()), stackLimit); - atomString = std::span { buffer }.first(length()); + atomString = std::span { buffer }.first(length()); } } else atomString = StringView { substringBase()->valueInternal() }.substring(substringOffset(), length()).toAtomString(); @@ -213,7 +213,7 @@ RefPtr JSRopeString::resolveRopeToExistingAtomString(JSGlobalObj resolveRopeInternalNoSubstring(std::span { buffer }.first(length()), stackLimit); existingAtomString = AtomStringImpl::lookUp(std::span { buffer }.first(length())); } else { - std::array buffer; + std::array buffer; resolveRopeInternalNoSubstring(std::span { buffer }.first(length()), stackLimit); existingAtomString = AtomStringImpl::lookUp(std::span { buffer }.first(length())); } @@ -255,7 +255,7 @@ const String& JSRopeString::resolveRopeWithFunction(JSGlobalObject* nullOrGlobal return valueInternal(); } - std::span buffer; + std::span buffer; auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer); if (!newImpl) { outOfMemory(nullOrGlobalObjectForOOM); diff --git a/Source/JavaScriptCore/runtime/JSString.h b/Source/JavaScriptCore/runtime/JSString.h index 3e6da6a20a60b..aef28273720d3 100644 --- a/Source/JavaScriptCore/runtime/JSString.h +++ b/Source/JavaScriptCore/runtime/JSString.h @@ -60,7 +60,7 @@ JSString* jsString(VM&, RefPtr&&); JSString* jsString(VM&, Ref&&); JSString* jsString(VM&, Ref&&); -JSString* jsSingleCharacterString(VM&, UChar); +JSString* jsSingleCharacterString(VM&, char16_t); JSString* jsSingleCharacterString(VM&, LChar); JSString* jsSubstring(VM&, const String&, unsigned offset, unsigned length); @@ -272,7 +272,7 @@ class JSString : public JSCell { bool is8Bit() const; - ALWAYS_INLINE JSString* tryReplaceOneChar(JSGlobalObject*, UChar, JSString* replacement); + ALWAYS_INLINE JSString* tryReplaceOneChar(JSGlobalObject*, char16_t, JSString* replacement); bool isSubstring() const; protected: @@ -281,7 +281,7 @@ class JSString : public JSCell { JS_EXPORT_PRIVATE bool equalSlowCase(JSGlobalObject*, JSString* other) const; - inline JSString* tryReplaceOneCharImpl(JSGlobalObject*, UChar search, JSString* replacement, uint8_t* stackLimit, bool& found); + inline JSString* tryReplaceOneCharImpl(JSGlobalObject*, char16_t search, JSString* replacement, uint8_t* stackLimit, bool& found); uintptr_t fiberConcurrently() const { return m_fiber; } @@ -302,7 +302,7 @@ class JSString : public JSCell { friend JSString* jsString(JSGlobalObject*, JSString*, JSString*, JSString*); friend JSString* jsString(JSGlobalObject*, const String&, const String&, const String&); friend JS_EXPORT_PRIVATE JSString* jsStringWithCacheSlowCase(VM&, StringImpl&); - friend JSString* jsSingleCharacterString(VM&, UChar); + friend JSString* jsSingleCharacterString(VM&, char16_t); friend JSString* jsSingleCharacterString(VM&, LChar); friend JSString* jsNontrivialString(VM&, const String&); friend JSString* jsNontrivialString(VM&, String&&); @@ -791,7 +791,7 @@ inline JSString* jsEmptyString(VM& vm) return vm.smallStrings.emptyString(); } -ALWAYS_INLINE JSString* jsSingleCharacterString(VM& vm, UChar c) +ALWAYS_INLINE JSString* jsSingleCharacterString(VM& vm, char16_t c) { if constexpr (validateDFGDoesGC) vm.verifyCanGC(); diff --git a/Source/JavaScriptCore/runtime/JSStringInlines.h b/Source/JavaScriptCore/runtime/JSStringInlines.h index 4f67502e72474..a13750c3f7cf3 100644 --- a/Source/JavaScriptCore/runtime/JSStringInlines.h +++ b/Source/JavaScriptCore/runtime/JSStringInlines.h @@ -73,7 +73,7 @@ ALWAYS_INLINE bool JSString::equalInline(JSGlobalObject* globalObject, JSString* return WTF::equal(str1, str2, length); } -JSString* JSString::tryReplaceOneCharImpl(JSGlobalObject* globalObject, UChar search, JSString* replacement, uint8_t* stackLimit, bool& found) +JSString* JSString::tryReplaceOneCharImpl(JSGlobalObject* globalObject, char16_t search, JSString* replacement, uint8_t* stackLimit, bool& found) { VM& vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); @@ -150,7 +150,7 @@ JSString* JSString::tryReplaceOneCharImpl(JSGlobalObject* globalObject, UChar se RELEASE_AND_RETURN(scope, jsString(globalObject, left, replacement, right)); } -JSString* JSString::tryReplaceOneChar(JSGlobalObject* globalObject, UChar search, JSString* replacement) +JSString* JSString::tryReplaceOneChar(JSGlobalObject* globalObject, char16_t search, JSString* replacement) { uint8_t* stackLimit = std::bit_cast(globalObject->vm().softStackLimit()); bool found = false; @@ -413,7 +413,7 @@ inline JSString* jsAtomString(JSGlobalObject* globalObject, VM& vm, JSString* st return vm.keyAtomStringCache.make(vm, buffer, createFromNonRope); } - WTF::HashTranslatorCharBuffer buffer { string->valueInternal().span16(), string->valueInternal().hash() }; + WTF::HashTranslatorCharBuffer buffer { string->valueInternal().span16(), string->valueInternal().hash() }; return vm.keyAtomStringCache.make(vm, buffer, createFromNonRope); } @@ -439,9 +439,9 @@ inline JSString* jsAtomString(JSGlobalObject* globalObject, VM& vm, JSString* st WTF::HashTranslatorCharBuffer buffer { std::span { characters }.first(length) }; return vm.keyAtomStringCache.make(vm, buffer, createFromRope); } - std::array characters; + std::array characters; JSRopeString::resolveToBuffer(fiber0, fiber1, fiber2, std::span { characters }.first(length), stackLimit); - WTF::HashTranslatorCharBuffer buffer { std::span { characters }.first(length) }; + WTF::HashTranslatorCharBuffer buffer { std::span { characters }.first(length) }; return vm.keyAtomStringCache.make(vm, buffer, createFromRope); } @@ -450,7 +450,7 @@ inline JSString* jsAtomString(JSGlobalObject* globalObject, VM& vm, JSString* st WTF::HashTranslatorCharBuffer buffer { view.span8() }; return vm.keyAtomStringCache.make(vm, buffer, createFromRope); } - WTF::HashTranslatorCharBuffer buffer { view.span16() }; + WTF::HashTranslatorCharBuffer buffer { view.span16() }; return vm.keyAtomStringCache.make(vm, buffer, createFromRope); } @@ -528,9 +528,9 @@ inline JSString* jsAtomString(JSGlobalObject* globalObject, VM& vm, JSString* s1 WTF::HashTranslatorCharBuffer buffer { std::span(characters).first(length) }; return vm.keyAtomStringCache.make(vm, buffer, createFromFibers); } - UChar characters[KeyAtomStringCache::maxStringLengthForCache]; + char16_t characters[KeyAtomStringCache::maxStringLengthForCache]; resolveWith2Fibers(s1, s2, std::span(characters).first(length)); - WTF::HashTranslatorCharBuffer buffer { std::span(characters).first(length) }; + WTF::HashTranslatorCharBuffer buffer { std::span(characters).first(length) }; return vm.keyAtomStringCache.make(vm, buffer, createFromFibers); } @@ -587,9 +587,9 @@ inline JSString* jsAtomString(JSGlobalObject* globalObject, VM& vm, JSString* s1 WTF::HashTranslatorCharBuffer buffer { std::span { characters }.first(length) }; return vm.keyAtomStringCache.make(vm, buffer, createFromFibers); } - UChar characters[KeyAtomStringCache::maxStringLengthForCache]; + char16_t characters[KeyAtomStringCache::maxStringLengthForCache]; resolveWith3Fibers(s1, s2, s3, std::span { characters }.first(length)); - WTF::HashTranslatorCharBuffer buffer { std::span { characters }.first(length) }; + WTF::HashTranslatorCharBuffer buffer { std::span { characters }.first(length) }; return vm.keyAtomStringCache.make(vm, buffer, createFromFibers); } @@ -618,8 +618,8 @@ inline JSString* jsSubstringOfResolved(VM& vm, GCDeferralContext* deferralContex if (auto c = base.characterAt(offset); c <= maxSingleCharacterString) return vm.smallStrings.singleCharacterString(c); } else if (length == 2) { - UChar first = base.characterAt(offset); - UChar second = base.characterAt(offset + 1); + char16_t first = base.characterAt(offset); + char16_t second = base.characterAt(offset + 1); if ((first | second) < 0x80) { auto createFromSubstring = [&](VM& vm, auto& buffer) { auto impl = AtomStringImpl::add(buffer); diff --git a/Source/JavaScriptCore/runtime/JSStringJoiner.cpp b/Source/JavaScriptCore/runtime/JSStringJoiner.cpp index a0a84fe3ef8be..d64f12d3fa2b9 100644 --- a/Source/JavaScriptCore/runtime/JSStringJoiner.cpp +++ b/Source/JavaScriptCore/runtime/JSStringJoiner.cpp @@ -54,7 +54,7 @@ static inline void appendStringToData(std::span& data, std: } template -static inline void appendStringToDataWithOneCharacterSeparatorRepeatedly(std::span& data, UChar separatorCharacter, StringView string, unsigned count) +static inline void appendStringToDataWithOneCharacterSeparatorRepeatedly(std::span& data, char16_t separatorCharacter, StringView string, unsigned count) { #if OS(DARWIN) if constexpr (std::is_same_v) { @@ -205,9 +205,9 @@ JSValue JSStringJoiner::joinSlow(JSGlobalObject* globalObject) result = joinStrings(m_strings, m_separator.span8(), length); else { if (m_separator.is8Bit()) - result = joinStrings(m_strings, m_separator.span8(), length); + result = joinStrings(m_strings, m_separator.span8(), length); else - result = joinStrings(m_strings, m_separator.span16(), length); + result = joinStrings(m_strings, m_separator.span16(), length); } if (UNLIKELY(result.isNull())) { diff --git a/Source/JavaScriptCore/runtime/LiteralParser.cpp b/Source/JavaScriptCore/runtime/LiteralParser.cpp index 23b0388f8b9eb..71f6a38de25d6 100644 --- a/Source/JavaScriptCore/runtime/LiteralParser.cpp +++ b/Source/JavaScriptCore/runtime/LiteralParser.cpp @@ -175,7 +175,7 @@ ALWAYS_INLINE JSString* LiteralParser::makeJSString(VM& v RELEASE_ASSERT_NOT_REACHED(); } -[[maybe_unused]] static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(UChar) +[[maybe_unused]] static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(char16_t) { RELEASE_ASSERT_NOT_REACHED(); } @@ -864,7 +864,7 @@ ALWAYS_INLINE void setParserTokenString(LiteralParserToken& token, } template <> -ALWAYS_INLINE void setParserTokenString(LiteralParserToken& token, const UChar* string) +ALWAYS_INLINE void setParserTokenString(LiteralParserToken& token, const char16_t* string) { token.stringIs8Bit = 0; token.stringStart16 = string; @@ -882,7 +882,7 @@ static ALWAYS_INLINE bool isSafeStringCharacter(LChar c, LChar terminator) } template -static ALWAYS_INLINE bool isSafeStringCharacter(UChar c, UChar terminator) +static ALWAYS_INLINE bool isSafeStringCharacter(char16_t c, char16_t terminator) { if constexpr (set == SafeStringCharacterSet::Strict) { if (!isLatin1(c)) @@ -893,7 +893,7 @@ static ALWAYS_INLINE bool isSafeStringCharacter(UChar c, UChar terminator) } template -static ALWAYS_INLINE bool isSafeStringCharacterForIdentifier(UChar c, UChar terminator) +static ALWAYS_INLINE bool isSafeStringCharacterForIdentifier(char16_t c, char16_t terminator) { if constexpr (set == SafeStringCharacterSet::Strict) return isSafeStringCharacter(static_cast(c), static_cast(terminator)) || !isLatin1(c); @@ -1781,9 +1781,9 @@ JSValue LiteralParser::parse(VM& vm, ParserState initialS // Instantiate the two flavors of LiteralParser we need instead of putting most of this file in LiteralParser.h template class LiteralParser; -template class LiteralParser; +template class LiteralParser; template class LiteralParser; -template class LiteralParser; +template class LiteralParser; } diff --git a/Source/JavaScriptCore/runtime/LiteralParser.h b/Source/JavaScriptCore/runtime/LiteralParser.h index 0e0fbde75379e..aebaa8b74a803 100644 --- a/Source/JavaScriptCore/runtime/LiteralParser.h +++ b/Source/JavaScriptCore/runtime/LiteralParser.h @@ -118,12 +118,12 @@ template struct LiteralParserToken { double numberToken; // Only used for TokNumber. const CharacterType* identifierStart; const LChar* stringStart8; - const UChar* stringStart16; + const char16_t* stringStart16; }; std::span identifier() const { return { identifierStart, stringOrIdentifierLength }; } std::span string8() const { return { stringStart8, stringOrIdentifierLength }; } - std::span string16() const { return { stringStart16, stringOrIdentifierLength }; } + std::span string16() const { return { stringStart16, stringOrIdentifierLength }; } }; template diff --git a/Source/JavaScriptCore/runtime/ParseInt.h b/Source/JavaScriptCore/runtime/ParseInt.h index d72d7fcd2ce9b..ba6e3171706a2 100644 --- a/Source/JavaScriptCore/runtime/ParseInt.h +++ b/Source/JavaScriptCore/runtime/ParseInt.h @@ -73,12 +73,12 @@ static double parseIntOverflow(std::span s, int radix) return number; } -static double parseIntOverflow(std::span s, int radix) +static double parseIntOverflow(std::span s, int radix) { double number = 0.0; double radixMultiplier = 1.0; - for (const UChar* p = s.data() + s.size() - 1; p >= s.data(); p--) { + for (const char16_t* p = s.data() + s.size() - 1; p >= s.data(); p--) { if (radixMultiplier == std::numeric_limits::infinity()) { if (*p != '0') { number = std::numeric_limits::infinity(); @@ -101,7 +101,7 @@ ALWAYS_INLINE static bool isStrWhiteSpace(CharacterType c) // https://tc39.github.io/ecma262/#sec-tonumber-applied-to-the-string-type if constexpr (sizeof(c) == 1) return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); - return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); + return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); } inline static std::optional parseIntDouble(double n) diff --git a/Source/JavaScriptCore/runtime/RegExp.cpp b/Source/JavaScriptCore/runtime/RegExp.cpp index d2c60d97cc84b..978c9de69b458 100644 --- a/Source/JavaScriptCore/runtime/RegExp.cpp +++ b/Source/JavaScriptCore/runtime/RegExp.cpp @@ -94,7 +94,7 @@ void RegExpFunctionalTestCollector::outputEscapedString(StringView s, bool escap int len = s.length(); for (int i = 0; i < len; ++i) { - UChar c = s[i]; + char16_t c = s[i]; switch (c) { case '\0': @@ -583,7 +583,7 @@ inline void appendLineTerminatorEscape(StringBuilder& builder, LChar line } template <> -inline void appendLineTerminatorEscape(StringBuilder& builder, UChar lineTerminator) +inline void appendLineTerminatorEscape(StringBuilder& builder, char16_t lineTerminator) { if (lineTerminator == '\n') builder.append('n'); diff --git a/Source/JavaScriptCore/runtime/RegExpObjectInlines.h b/Source/JavaScriptCore/runtime/RegExpObjectInlines.h index 7139971a4ebd5..f7b77b0e7394d 100644 --- a/Source/JavaScriptCore/runtime/RegExpObjectInlines.h +++ b/Source/JavaScriptCore/runtime/RegExpObjectInlines.h @@ -131,11 +131,11 @@ inline unsigned advanceStringUnicode(StringView s, unsigned length, unsigned cur if (currentIndex + 1 >= length) return currentIndex + 1; - UChar first = s[currentIndex]; + char16_t first = s[currentIndex]; if (!U16_IS_LEAD(first)) return currentIndex + 1; - UChar second = s[currentIndex + 1]; + char16_t second = s[currentIndex + 1]; if (!U16_IS_TRAIL(second)) return currentIndex + 1; diff --git a/Source/JavaScriptCore/runtime/StringConstructor.cpp b/Source/JavaScriptCore/runtime/StringConstructor.cpp index 8889e548b9bec..4d13d056c13c8 100644 --- a/Source/JavaScriptCore/runtime/StringConstructor.cpp +++ b/Source/JavaScriptCore/runtime/StringConstructor.cpp @@ -84,7 +84,7 @@ JSC_DEFINE_HOST_FUNCTION(stringFromCharCode, (JSGlobalObject* globalObject, Call unsigned length = callFrame->argumentCount(); if (LIKELY(length == 1)) { scope.release(); - UChar code = callFrame->uncheckedArgument(0).toUInt32(globalObject); + char16_t code = callFrame->uncheckedArgument(0).toUInt32(globalObject); // Not checking for an exception here is ok because jsSingleCharacterString will just fetch an unused string if there's an exception. return JSValue::encode(jsSingleCharacterString(vm, code)); } @@ -92,16 +92,16 @@ JSC_DEFINE_HOST_FUNCTION(stringFromCharCode, (JSGlobalObject* globalObject, Call std::span buf8Bit; auto impl8Bit = StringImpl::createUninitialized(length, buf8Bit); for (unsigned i = 0; i < length; ++i) { - UChar character = static_cast(callFrame->uncheckedArgument(i).toUInt32(globalObject)); + char16_t character = static_cast(callFrame->uncheckedArgument(i).toUInt32(globalObject)); RETURN_IF_EXCEPTION(scope, encodedJSValue()); if (UNLIKELY(!isLatin1(character))) { - std::span buf16Bit; + std::span buf16Bit; auto impl16Bit = StringImpl::createUninitialized(length, buf16Bit); StringImpl::copyCharacters(buf16Bit.data(), buf8Bit.first(i)); buf16Bit[i] = character; ++i; for (; i < length; ++i) { - buf16Bit[i] = static_cast(callFrame->uncheckedArgument(i).toUInt32(globalObject)); + buf16Bit[i] = static_cast(callFrame->uncheckedArgument(i).toUInt32(globalObject)); RETURN_IF_EXCEPTION(scope, encodedJSValue()); } RELEASE_AND_RETURN(scope, JSValue::encode(jsString(vm, WTFMove(impl16Bit)))); @@ -113,7 +113,7 @@ JSC_DEFINE_HOST_FUNCTION(stringFromCharCode, (JSGlobalObject* globalObject, Call JSString* stringFromCharCode(JSGlobalObject* globalObject, int32_t arg) { - return jsSingleCharacterString(globalObject->vm(), static_cast(arg)); + return jsSingleCharacterString(globalObject->vm(), static_cast(arg)); } JSC_DEFINE_HOST_FUNCTION(stringFromCodePoint, (JSGlobalObject* globalObject, CallFrame* callFrame)) @@ -135,7 +135,7 @@ JSC_DEFINE_HOST_FUNCTION(stringFromCodePoint, (JSGlobalObject* globalObject, Cal return throwVMError(globalObject, scope, createRangeError(globalObject, "Arguments contain a value that is out of range of code points"_s)); if (U_IS_BMP(codePoint)) - builder.append(static_cast(codePoint)); + builder.append(static_cast(codePoint)); else { builder.append(U16_LEAD(codePoint)); builder.append(U16_TRAIL(codePoint)); diff --git a/Source/JavaScriptCore/runtime/StringPrototype.cpp b/Source/JavaScriptCore/runtime/StringPrototype.cpp index 61490fc3a9b56..6f66ec9381255 100644 --- a/Source/JavaScriptCore/runtime/StringPrototype.cpp +++ b/Source/JavaScriptCore/runtime/StringPrototype.cpp @@ -193,7 +193,7 @@ NEVER_INLINE void substituteBackreferencesSlow(StringBuilder& result, StringView if (i + 1 == replacement.length()) break; - UChar ref = replacement[i + 1]; + char16_t ref = replacement[i + 1]; if (ref == '$') { // "$$" -> "$" ++i; @@ -940,7 +940,7 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncRepeatCharacter, (JSGlobalObject* global auto view = string->view(globalObject); ASSERT(view->length() == 1); scope.assertNoException(); - UChar character = view[0]; + char16_t character = view[0]; scope.release(); if (isLatin1(character)) return JSValue::encode(repeatCharacter(globalObject, static_cast(character), repeatCount)); @@ -1300,7 +1300,7 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncSlice, (JSGlobalObject* globalObject, Ca // Return true in case of early return (resultLength got to limitLength). template -static ALWAYS_INLINE bool splitStringByOneCharacterImpl(Indice& result, StringImpl* string, UChar separatorCharacter, unsigned limitLength) +static ALWAYS_INLINE bool splitStringByOneCharacterImpl(Indice& result, StringImpl* string, char16_t separatorCharacter, unsigned limitLength) { // 12. Let q = p. size_t matchPosition; @@ -1459,12 +1459,12 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncSplitFast, (JSGlobalObject* globalObject StringImpl* separatorImpl = separator.impl(); if (separatorLength == 1) { - UChar separatorCharacter = separatorImpl->at(0); + char16_t separatorCharacter = separatorImpl->at(0); if (stringImpl->is8Bit()) { if (splitStringByOneCharacterImpl(result, stringImpl, separatorCharacter, limit)) RELEASE_AND_RETURN(scope, JSValue::encode(cacheAndCreateArray())); } else { - if (splitStringByOneCharacterImpl(result, stringImpl, separatorCharacter, limit)) + if (splitStringByOneCharacterImpl(result, stringImpl, separatorCharacter, limit)) RELEASE_AND_RETURN(scope, JSValue::encode(cacheAndCreateArray())); } } else { @@ -1775,7 +1775,7 @@ static EncodedJSValue toLocaleCase(JSGlobalObject* globalObject, CallFrame* call // 17. Let L be a String whose elements are, in order, the elements of cuList. // Most strings lower/upper case will be the same size as original, so try that first. - Vector buffer; + Vector buffer; buffer.reserveInitialCapacity(s->length()); auto convertCase = mode == CaseConversionMode::Lower ? u_strToLower : u_strToUpper; auto status = callBufferProducingFunction(convertCase, buffer, StringView { s }.upconvertedCharacters().get(), s->length(), locale.utf8().data()); @@ -2059,7 +2059,7 @@ static JSValue normalize(JSGlobalObject* globalObject, JSString* string, Normali int32_t normalizedStringLength = unorm2_normalize(normalizer, characters, view->length(), nullptr, 0, &status); ASSERT(needsToGrowToProduceBuffer(status)); - std::span buffer; + std::span buffer; auto result = StringImpl::tryCreateUninitialized(normalizedStringLength, buffer); if (!result) return throwOutOfMemoryError(globalObject, scope); @@ -2103,10 +2103,10 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncNormalize, (JSGlobalObject* globalObject RELEASE_AND_RETURN(scope, JSValue::encode(normalize(globalObject, string, form))); } -static inline std::optional illFormedIndex(std::span characters) +static inline std::optional illFormedIndex(std::span characters) { for (unsigned index = 0; index < characters.size(); ++index) { - UChar character = characters[index]; + char16_t character = characters[index]; if (!U16_IS_SURROGATE(character)) continue; @@ -2116,7 +2116,7 @@ static inline std::optional illFormedIndex(std::span char ASSERT(U16_IS_SURROGATE_LEAD(character)); if ((index + 1) == characters.size()) return index; - UChar nextCharacter = characters[index + 1]; + char16_t nextCharacter = characters[index + 1]; if (!U16_IS_SURROGATE(nextCharacter)) return index; @@ -2180,11 +2180,11 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncToWellFormed, (JSGlobalObject* globalObj if (!firstIllFormedIndex) return JSValue::encode(stringValue); - Vector buffer; + Vector buffer; buffer.reserveInitialCapacity(characters.size()); buffer.append(characters.first(*firstIllFormedIndex)); for (unsigned index = firstIllFormedIndex.value(); index < characters.size(); ++index) { - UChar character = characters[index]; + char16_t character = characters[index]; if (!U16_IS_SURROGATE(character)) { buffer.append(character); @@ -2201,7 +2201,7 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncToWellFormed, (JSGlobalObject* globalObj buffer.append(replacementCharacter); continue; } - UChar nextCharacter = characters[index + 1]; + char16_t nextCharacter = characters[index + 1]; if (!U16_IS_SURROGATE(nextCharacter)) { buffer.append(replacementCharacter); diff --git a/Source/JavaScriptCore/runtime/StringPrototypeInlines.h b/Source/JavaScriptCore/runtime/StringPrototypeInlines.h index 6d4d556141939..2ba58ded04581 100644 --- a/Source/JavaScriptCore/runtime/StringPrototypeInlines.h +++ b/Source/JavaScriptCore/runtime/StringPrototypeInlines.h @@ -170,7 +170,7 @@ ALWAYS_INLINE JSString* jsSpliceSubstringsWithSeparators(JSGlobalObject* globalO RELEASE_AND_RETURN(scope, jsString(vm, impl.releaseNonNull())); } - std::span buffer; + std::span buffer; auto impl = StringImpl::tryCreateUninitialized(totalLength, buffer); if (!impl) { throwOutOfMemoryError(globalObject, scope); diff --git a/Source/JavaScriptCore/testRegExp.cpp b/Source/JavaScriptCore/testRegExp.cpp index 34ed21e9d66c8..706a30da75ac4 100644 --- a/Source/JavaScriptCore/testRegExp.cpp +++ b/Source/JavaScriptCore/testRegExp.cpp @@ -227,7 +227,7 @@ static int scanString(char* buffer, int bufferLength, StringBuilder& builder, ch bool escape = false; for (int i = 0; i < bufferLength; ++i) { - UChar c = buffer[i]; + char16_t c = buffer[i]; if (escape) { switch (c) { @@ -267,7 +267,7 @@ static int scanString(char* buffer, int bufferLength, StringBuilder& builder, ch unsigned int charValue; if (sscanf(buffer+i+1, "%04x", &charValue) != 1) return -1; - c = static_cast(charValue); + c = static_cast(charValue); i += 4; break; } diff --git a/Source/JavaScriptCore/tools/CharacterPropertyDataGenerator.cpp b/Source/JavaScriptCore/tools/CharacterPropertyDataGenerator.cpp index d2e04626df394..5e4b744a918de 100644 --- a/Source/JavaScriptCore/tools/CharacterPropertyDataGenerator.cpp +++ b/Source/JavaScriptCore/tools/CharacterPropertyDataGenerator.cpp @@ -43,8 +43,8 @@ namespace JSC { // class LineBreakData { public: - static constexpr UChar minChar = '!'; - static constexpr UChar maxChar = 0xFF; + static constexpr char16_t minChar = '!'; + static constexpr char16_t maxChar = 0xFF; static constexpr unsigned numChars = maxChar - minChar + 1; static constexpr unsigned numCharsRoundUp8 = (numChars + 7) / 8 * 8; @@ -61,8 +61,8 @@ class LineBreakData { private: void fill() { - for (UChar ch = minChar; ch <= maxChar; ++ch) { - for (UChar chNext = minChar; chNext <= maxChar; ++chNext) { + for (char16_t ch = minChar; ch <= maxChar; ++ch) { + for (char16_t chNext = minChar; chNext <= maxChar; ++chNext) { auto string = makeString(ch, chNext); CachedTextBreakIterator iterator(string, { }, WTF::TextBreakIterator::LineMode { WTF::TextBreakIterator::LineMode::Behavior::Default }, AtomString("en"_str)); setPairValue(ch, chNext, iterator.isBoundary(1)); @@ -176,7 +176,7 @@ class LineBreakData { // Print the column comment. dataLog(" /*"); - for (UChar ch = minChar; ch <= maxChar; ++ch) { + for (char16_t ch = minChar; ch <= maxChar; ++ch) { if (ch != minChar && (ch - minChar) % 8 == 0) dataLog(" "); dataLogF(ch < 0x7F ? " %c" : "%02X", ch); @@ -185,7 +185,7 @@ class LineBreakData { // Print the data array. for (unsigned y = 0; y < numChars; ++y) { - const UChar ch = y + minChar; + const char16_t ch = y + minChar; dataLogF("/* %02X %c */ {B(", ch, ch < 0x7F ? ch : ' '); const char* prefix = ""; for (unsigned x = 0; x < numCharsRoundUp8; ++x) { @@ -201,16 +201,16 @@ class LineBreakData { dataLogLn("} // namespace WebCore"); } - void setPairValue(UChar ch1Min, UChar ch1Max, UChar ch2Min, UChar ch2Max, bool value) + void setPairValue(char16_t ch1Min, char16_t ch1Max, char16_t ch2Min, char16_t ch2Max, bool value) { - for (UChar ch1 = ch1Min; ch1 <= ch1Max; ++ch1) { - for (UChar ch2 = ch2Min; ch2 <= ch2Max; ++ch2) + for (char16_t ch1 = ch1Min; ch1 <= ch1Max; ++ch1) { + for (char16_t ch2 = ch2Min; ch2 <= ch2Max; ++ch2) setPairValue(ch1, ch2, value); } } // Set the breakability between `ch1` and `ch2`. - void setPairValue(UChar ch1, UChar ch2, bool value) + void setPairValue(char16_t ch1, char16_t ch2, bool value) { RELEASE_ASSERT(ch1 >= minChar); RELEASE_ASSERT(ch1 <= maxChar); diff --git a/Source/JavaScriptCore/yarr/YarrInterpreter.cpp b/Source/JavaScriptCore/yarr/YarrInterpreter.cpp index 0ed882f454f89..aaf27442eb26a 100644 --- a/Source/JavaScriptCore/yarr/YarrInterpreter.cpp +++ b/Source/JavaScriptCore/yarr/YarrInterpreter.cpp @@ -3175,7 +3175,7 @@ unsigned interpret(BytecodePattern* bytecode, StringView input, unsigned start, SuperSamplerScope superSamplerScope(false); if (input.is8Bit()) return Interpreter(bytecode, output, input.span8(), start).interpret(); - return Interpreter(bytecode, output, input.span16(), start).interpret(); + return Interpreter(bytecode, output, input.span16(), start).interpret(); } unsigned interpret(BytecodePattern* bytecode, std::span input, unsigned start, unsigned* output) @@ -3184,20 +3184,20 @@ unsigned interpret(BytecodePattern* bytecode, std::span input, unsi return Interpreter(bytecode, output, input, start).interpret(); } -unsigned interpret(BytecodePattern* bytecode, std::span input, unsigned start, unsigned* output) +unsigned interpret(BytecodePattern* bytecode, std::span input, unsigned start, unsigned* output) { SuperSamplerScope superSamplerScope(false); - return Interpreter(bytecode, output, input, start).interpret(); + return Interpreter(bytecode, output, input, start).interpret(); } -// These should be the same for both UChar & LChar. +// These should be the same for both char16_t & LChar. static_assert(sizeof(BackTrackInfoPatternCharacter) == (YarrStackSpaceForBackTrackInfoPatternCharacter * sizeof(uintptr_t))); static_assert(sizeof(BackTrackInfoCharacterClass) == (YarrStackSpaceForBackTrackInfoCharacterClass * sizeof(uintptr_t))); static_assert(sizeof(BackTrackInfoBackReference) == (YarrStackSpaceForBackTrackInfoBackReference * sizeof(uintptr_t))); static_assert(sizeof(BackTrackInfoAlternative) == (YarrStackSpaceForBackTrackInfoAlternative * sizeof(uintptr_t))); static_assert(sizeof(BackTrackInfoParentheticalAssertion) == (YarrStackSpaceForBackTrackInfoParentheticalAssertion * sizeof(uintptr_t))); static_assert(sizeof(BackTrackInfoParenthesesOnce) == (YarrStackSpaceForBackTrackInfoParenthesesOnce * sizeof(uintptr_t))); -static_assert(sizeof(Interpreter::BackTrackInfoParentheses) <= (YarrStackSpaceForBackTrackInfoParentheses * sizeof(uintptr_t))); +static_assert(sizeof(Interpreter::BackTrackInfoParentheses) <= (YarrStackSpaceForBackTrackInfoParentheses * sizeof(uintptr_t))); } } diff --git a/Source/JavaScriptCore/yarr/YarrJIT.cpp b/Source/JavaScriptCore/yarr/YarrJIT.cpp index c36d744bf6e86..33e38e3ac67d0 100644 --- a/Source/JavaScriptCore/yarr/YarrJIT.cpp +++ b/Source/JavaScriptCore/yarr/YarrJIT.cpp @@ -111,7 +111,7 @@ class SubjectSampler { { } - int32_t frequency(UChar character) const + int32_t frequency(char16_t character) const { if (!m_size) return 1; @@ -143,7 +143,7 @@ class SubjectSampler { bool is8Bit() const { return m_is8Bit; } private: - inline void add(UChar character) + inline void add(char16_t character) { ++m_size; ++m_samples[character & BoyerMooreBitmap::mapMask]; @@ -971,7 +971,7 @@ class YarrGenerator final : public YarrJITInfo { if (m_charSize == CharSize::Char8) return MacroAssembler::BaseIndex(m_regs.input, indexReg, MacroAssembler::TimesOne, characterOffset * static_cast(sizeof(char))); - return MacroAssembler::BaseIndex(m_regs.input, indexReg, MacroAssembler::TimesTwo, characterOffset * static_cast(sizeof(UChar))); + return MacroAssembler::BaseIndex(m_regs.input, indexReg, MacroAssembler::TimesTwo, characterOffset * static_cast(sizeof(char16_t))); } #if ENABLE(YARR_JIT_UNICODE_EXPRESSIONS) diff --git a/Source/JavaScriptCore/yarr/YarrJIT.h b/Source/JavaScriptCore/yarr/YarrJIT.h index 7e1eae4f3bfd2..7f170160955c0 100644 --- a/Source/JavaScriptCore/yarr/YarrJIT.h +++ b/Source/JavaScriptCore/yarr/YarrJIT.h @@ -277,9 +277,9 @@ class YarrCodeBlock final : public YarrBoyerMooreData { public: using YarrJITCode8 = UGPRPair SYSV_ABI (*)(const LChar* input, UCPURegister start, UCPURegister length, int* output, MatchingContextHolder*) YARR_CALL; - using YarrJITCode16 = UGPRPair SYSV_ABI (*)(const UChar* input, UCPURegister start, UCPURegister length, int* output, MatchingContextHolder*) YARR_CALL; + using YarrJITCode16 = UGPRPair SYSV_ABI (*)(const char16_t* input, UCPURegister start, UCPURegister length, int* output, MatchingContextHolder*) YARR_CALL; using YarrJITCodeMatchOnly8 = UGPRPair SYSV_ABI (*)(const LChar* input, UCPURegister start, UCPURegister length, void*, MatchingContextHolder*) YARR_CALL; - using YarrJITCodeMatchOnly16 = UGPRPair SYSV_ABI (*)(const UChar* input, UCPURegister start, UCPURegister length, void*, MatchingContextHolder*) YARR_CALL; + using YarrJITCodeMatchOnly16 = UGPRPair SYSV_ABI (*)(const char16_t* input, UCPURegister start, UCPURegister length, void*, MatchingContextHolder*) YARR_CALL; YarrCodeBlock(RegExp* regExp) : m_regExp(regExp) @@ -342,7 +342,7 @@ class YarrCodeBlock final : public YarrBoyerMooreData { return MatchResult(untagCFunctionPtr(m_ref8.code().taggedPtr())(input.data(), start, input.size(), output, matchingContext)); } - MatchResult execute(std::span input, unsigned start, int* output, MatchingContextHolder* matchingContext) + MatchResult execute(std::span input, unsigned start, int* output, MatchingContextHolder* matchingContext) { ASSERT(has16BitCode()); #if CPU(ARM64E) @@ -362,7 +362,7 @@ class YarrCodeBlock final : public YarrBoyerMooreData { return MatchResult(untagCFunctionPtr(m_matchOnly8.code().taggedPtr())(input.data(), start, input.size(), nullptr, matchingContext)); } - MatchResult execute(std::span input, unsigned start, MatchingContextHolder* matchingContext) + MatchResult execute(std::span input, unsigned start, MatchingContextHolder* matchingContext) { ASSERT(has16BitCodeMatchOnly()); #if CPU(ARM64E) diff --git a/Source/JavaScriptCore/yarr/YarrParser.h b/Source/JavaScriptCore/yarr/YarrParser.h index 4cf4273e36979..f6f9624131c73 100644 --- a/Source/JavaScriptCore/yarr/YarrParser.h +++ b/Source/JavaScriptCore/yarr/YarrParser.h @@ -1973,7 +1973,7 @@ class Parser { return octal; } - bool tryConsume(UChar ch) + bool tryConsume(char16_t ch) { if (atEndOfPattern() || (m_data[m_index] != ch)) return false; @@ -2189,7 +2189,7 @@ ErrorCode parse(Delegate& delegate, const StringView pattern, CompileMode compil { if (pattern.is8Bit()) return Parser(delegate, pattern, compileMode, backReferenceLimit, isNamedForwardReferenceAllowed).parse(); - return Parser(delegate, pattern, compileMode, backReferenceLimit, isNamedForwardReferenceAllowed).parse(); + return Parser(delegate, pattern, compileMode, backReferenceLimit, isNamedForwardReferenceAllowed).parse(); } } } // namespace JSC::Yarr diff --git a/Source/JavaScriptCore/yarr/YarrPattern.cpp b/Source/JavaScriptCore/yarr/YarrPattern.cpp index b4f4383ebf42c..07e7c0bc78f04 100644 --- a/Source/JavaScriptCore/yarr/YarrPattern.cpp +++ b/Source/JavaScriptCore/yarr/YarrPattern.cpp @@ -286,7 +286,7 @@ class CharacterClassConstructor { // Nothing to do - no canonical equivalents. break; case CanonicalizeSet: { - UChar ch; + char16_t ch; for (auto* set = canonicalCharacterSetInfo(info->value, m_canonicalMode); (ch = *set); ++set) addSorted(ch); break; @@ -2041,7 +2041,7 @@ class YarrPatternConstructor { return { }; if (term.m_matchDirection != MatchDirection::Forward) return { }; - builder.append(static_cast(term.patternCharacter)); + builder.append(static_cast(term.patternCharacter)); } String atom = builder.toString(); if (atom.length() > 0) diff --git a/Source/JavaScriptCore/yarr/YarrSyntaxChecker.cpp b/Source/JavaScriptCore/yarr/YarrSyntaxChecker.cpp index cb95e7c032a21..a300cec90803c 100644 --- a/Source/JavaScriptCore/yarr/YarrSyntaxChecker.cpp +++ b/Source/JavaScriptCore/yarr/YarrSyntaxChecker.cpp @@ -39,8 +39,8 @@ class SyntaxChecker { void atomPatternCharacter(char32_t) { } void atomBuiltInCharacterClass(BuiltInCharacterClassID, bool) { } void atomCharacterClassBegin(bool = false) { } - void atomCharacterClassAtom(UChar) { } - void atomCharacterClassRange(UChar, UChar) { } + void atomCharacterClassAtom(char16_t) { } + void atomCharacterClassRange(char16_t, char16_t) { } void atomCharacterClassBuiltIn(BuiltInCharacterClassID, bool) { } void atomClassStringDisjunction(Vector>&) { } void atomCharacterClassSetOp(CharacterClassSetOp) { } From c47a2316c2e1ca623be6daccd00bae2c705340ca Mon Sep 17 00:00:00 2001 From: Darin Adler Date: Sat, 27 Sep 2025 10:32:53 -0700 Subject: [PATCH 10/22] Rename LChar to Latin1Character rdar://161048219 https://bugs.webkit.org/show_bug.cgi?id=299254 Reviewed by Sam Weinig. * Source/WTF/wtf/text/Latin1Character.h: Renamed from Source/WTF/wtf/text/LChar.h. * Tools/Scripts/do-webcore-rename: Updated the script so it only skips our copy of icu, not our icu directories. And updated the "things to rename" to rename LChar. * : Let the do-webcore-rename script do its thing! Canonical link: https://commits.webkit.org/300639@main Signed-off-by: Xabier Rodriguez Calvar --- Source/JavaScriptCore/API/JSStringRefCF.cpp | 2 +- Source/JavaScriptCore/API/JSValueRef.cpp | 2 +- Source/JavaScriptCore/API/OpaqueJSString.h | 6 +- Source/JavaScriptCore/API/glib/JSCValue.cpp | 2 +- .../JavaScriptCore/KeywordLookupGenerator.py | 6 +- .../builtins/BuiltinExecutables.cpp | 2 +- .../JavaScriptCore/builtins/BuiltinNames.cpp | 6 +- Source/JavaScriptCore/builtins/BuiltinNames.h | 4 +- .../JavaScriptCore/dfg/DFGSpeculativeJIT.cpp | 2 +- .../ftl/FTLAbstractHeapRepository.h | 2 +- Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp | 6 +- .../interpreter/Interpreter.cpp | 4 +- Source/JavaScriptCore/parser/Lexer.cpp | 62 +- Source/JavaScriptCore/parser/Lexer.h | 18 +- Source/JavaScriptCore/parser/Parser.cpp | 2 +- Source/JavaScriptCore/parser/Parser.h | 6 +- .../JavaScriptCore/runtime/ArrayPrototype.cpp | 6 +- Source/JavaScriptCore/runtime/CachedTypes.cpp | 2 +- .../runtime/FuzzerPredictions.cpp | 2 +- Source/JavaScriptCore/runtime/ISO8601.cpp | 16 +- Source/JavaScriptCore/runtime/ISO8601.h | 6 +- Source/JavaScriptCore/runtime/Identifier.h | 24 +- .../runtime/IdentifierInlines.h | 2 +- .../JavaScriptCore/runtime/IntlCollator.cpp | 2 +- .../runtime/IntlDurationFormat.cpp | 2 +- Source/JavaScriptCore/runtime/IntlLocale.cpp | 2 +- .../runtime/IntlNumberFormatInlines.h | 2 +- Source/JavaScriptCore/runtime/IntlObject.cpp | 4 +- .../runtime/IntlObjectInlines.h | 4 +- Source/JavaScriptCore/runtime/JSBigInt.cpp | 4 +- .../JSGenericTypedArrayViewConstructor.cpp | 2 +- .../JSGenericTypedArrayViewConstructor.h | 2 +- .../JSGenericTypedArrayViewPrototype.cpp | 4 +- .../runtime/JSGlobalObjectFunctions.cpp | 14 +- Source/JavaScriptCore/runtime/JSONObject.cpp | 22 +- Source/JavaScriptCore/runtime/JSString.cpp | 8 +- Source/JavaScriptCore/runtime/JSString.h | 6 +- .../JavaScriptCore/runtime/JSStringInlines.h | 20 +- .../JavaScriptCore/runtime/JSStringJoiner.cpp | 12 +- .../JavaScriptCore/runtime/LiteralParser.cpp | 14 +- Source/JavaScriptCore/runtime/LiteralParser.h | 4 +- .../runtime/NumberPrototype.cpp | 6 +- Source/JavaScriptCore/runtime/Operations.h | 8 +- Source/JavaScriptCore/runtime/ParseInt.h | 6 +- Source/JavaScriptCore/runtime/PropertyName.h | 2 +- Source/JavaScriptCore/runtime/RegExp.cpp | 2 +- .../JavaScriptCore/runtime/SmallStrings.cpp | 4 +- .../runtime/StringConstructor.cpp | 4 +- .../runtime/StringPrototype.cpp | 8 +- .../runtime/StringPrototypeInlines.h | 2 +- .../yarr/YarrCanonicalizeUCS2.js | 4 +- .../JavaScriptCore/yarr/YarrInterpreter.cpp | 8 +- Source/JavaScriptCore/yarr/YarrInterpreter.h | 4 +- Source/JavaScriptCore/yarr/YarrJIT.h | 8 +- Source/JavaScriptCore/yarr/YarrParser.h | 2 +- Source/JavaScriptCore/yarr/hasher.py | 2 +- Source/WTF/WTF.xcodeproj/project.pbxproj | 8 +- Source/WTF/wtf/ASCIICType.h | 4 +- Source/WTF/wtf/CMakeLists.txt | 2 +- Source/WTF/wtf/DateMath.cpp | 22 +- Source/WTF/wtf/DateMath.h | 6 +- Source/WTF/wtf/FastFloat.cpp | 2 +- Source/WTF/wtf/FastFloat.h | 4 +- Source/WTF/wtf/HexNumber.cpp | 2 +- Source/WTF/wtf/HexNumber.h | 14 +- Source/WTF/wtf/Int128.cpp | 4 +- Source/WTF/wtf/JSONValues.cpp | 2 +- Source/WTF/wtf/SIMDHelpers.h | 2 +- Source/WTF/wtf/URL.cpp | 4 +- Source/WTF/wtf/URLParser.cpp | 34 +- Source/WTF/wtf/URLParser.h | 12 +- Source/WTF/wtf/cf/CFURLExtras.cpp | 2 +- .../WTF/wtf/persistence/PersistentCoders.cpp | 4 +- Source/WTF/wtf/text/ASCIIFastPath.h | 6 +- Source/WTF/wtf/text/ASCIILiteral.h | 6 +- Source/WTF/wtf/text/AdaptiveStringSearcher.h | 4 +- Source/WTF/wtf/text/AtomString.cpp | 4 +- Source/WTF/wtf/text/AtomString.h | 14 +- Source/WTF/wtf/text/AtomStringImpl.cpp | 18 +- Source/WTF/wtf/text/AtomStringImpl.h | 16 +- Source/WTF/wtf/text/Base64.cpp | 6 +- Source/WTF/wtf/text/Base64.h | 4 +- Source/WTF/wtf/text/CString.h | 4 +- Source/WTF/wtf/text/CodePointIterator.h | 6 +- Source/WTF/wtf/text/ExternalStringImpl.cpp | 4 +- Source/WTF/wtf/text/ExternalStringImpl.h | 8 +- .../WTF/wtf/text/IntegerToStringConversion.h | 24 +- .../wtf/text/{LChar.h => Latin1Character.h} | 2 +- Source/WTF/wtf/text/MakeString.h | 12 +- Source/WTF/wtf/text/ParsingUtilities.h | 50 +- Source/WTF/wtf/text/StringBuilder.cpp | 36 +- Source/WTF/wtf/text/StringBuilder.h | 42 +- Source/WTF/wtf/text/StringBuilderJSON.cpp | 2 +- Source/WTF/wtf/text/StringCommon.cpp | 4 +- Source/WTF/wtf/text/StringCommon.h | 175 +- Source/WTF/wtf/text/StringConcatenate.h | 30 +- .../WTF/wtf/text/StringConcatenateNumbers.h | 10 +- Source/WTF/wtf/text/StringHasher.h | 2 +- Source/WTF/wtf/text/StringImpl.cpp | 166 +- Source/WTF/wtf/text/StringImpl.h | 286 +- Source/WTF/wtf/text/StringView.cpp | 32 +- Source/WTF/wtf/text/StringView.h | 162 +- Source/WTF/wtf/text/SuperFastHash.h | 2 +- Source/WTF/wtf/text/SymbolImpl.h | 10 +- Source/WTF/wtf/text/UniquedStringImpl.h | 6 +- Source/WTF/wtf/text/WTFString.cpp | 20 +- Source/WTF/wtf/text/WTFString.h | 42 +- Source/WTF/wtf/text/WYHash.h | 4 +- Source/WTF/wtf/text/cf/StringCF.cpp | 2 +- Source/WTF/wtf/text/cf/StringConcatenateCF.h | 2 +- .../WTF/wtf/text/cocoa/ASCIILiteralCocoa.mm | 2 +- Source/WTF/wtf/text/cocoa/StringViewCocoa.mm | 4 +- .../WTF/wtf/text/icu/UTextProviderLatin1.cpp | 36 +- Source/WTF/wtf/text/icu/UTextProviderLatin1.h | 6 +- Source/WTF/wtf/unicode/UTF8Conversion.cpp | 6 +- Source/WTF/wtf/unicode/UTF8Conversion.h | 6 +- Source/WTF/wtf/unicode/icu/CollatorICU.cpp | 8 +- Source/WebCore/PAL/pal/Gunzip.h | 4 +- Source/WebCore/PAL/pal/cocoa/Gunzip.cpp | 4 +- .../PAL/pal/text/TextCodecASCIIFastPath.h | 6 +- .../WebCore/PAL/pal/text/TextCodecLatin1.cpp | 20 +- Source/WebCore/PAL/pal/text/TextCodecUTF8.cpp | 24 +- Source/WebCore/PAL/pal/text/TextCodecUTF8.h | 6 +- .../DFABytecodeInterpreter.cpp | 6 +- .../DFABytecodeInterpreter.h | 2 +- Source/WebCore/css/CSSVariableData.cpp | 2 +- Source/WebCore/css/parser/CSSParserToken.h | 2 +- .../WebCore/css/parser/CSSPropertyParser.cpp | 2 +- .../css/parser/CSSTokenizerInputStream.h | 2 +- Source/WebCore/css/process-css-properties.py | 4 +- .../css/process-css-pseudo-selectors.py | 12 +- .../CSSPropertyNames.gperf | 935 +++++++ Source/WebCore/dom/DatasetDOMStringMap.cpp | 4 +- Source/WebCore/dom/Document.cpp | 6 +- Source/WebCore/dom/SpaceSplitString.cpp | 4 +- Source/WebCore/dom/make_names.pl | 6 +- Source/WebCore/editing/Editing.cpp | 2 +- Source/WebCore/editing/MarkupAccumulator.cpp | 2 +- .../editing/cocoa/NodeHTMLConverter.mm | 2325 +++++++++++++++++ .../WebCore/html/MediaFragmentURIParser.cpp | 8 +- Source/WebCore/html/MediaFragmentURIParser.h | 4 +- .../parser/HTMLDocumentParserFastPath.cpp | 4 +- .../WebCore/html/parser/HTMLEntityParser.cpp | 4 +- Source/WebCore/html/parser/HTMLEntityParser.h | 6 +- Source/WebCore/html/parser/HTMLNameCache.h | 4 +- Source/WebCore/html/parser/HTMLParserIdioms.h | 4 +- .../WebCore/html/parser/HTMLSrcsetParser.cpp | 2 +- Source/WebCore/html/parser/HTMLToken.h | 22 +- Source/WebCore/html/parser/HTMLTokenizer.cpp | 4 +- Source/WebCore/html/parser/HTMLTokenizer.h | 4 +- .../WebCore/html/parser/HTMLTreeBuilder.cpp | 2 +- Source/WebCore/html/track/VTTScanner.cpp | 2 +- Source/WebCore/html/track/VTTScanner.h | 58 +- .../WebCore/inspector/InspectorStyleSheet.cpp | 4 +- .../inline/text/TextUtil.cpp | 4 +- .../loader/ResourceCryptographicDigest.cpp | 4 +- .../loader/ResourceCryptographicDigest.h | 9 +- .../platform/graphics/AV1Utilities.cpp | 12 +- .../WebCore/platform/graphics/FontCascade.cpp | 4 +- .../WebCore/platform/graphics/FontCascade.h | 14 +- .../platform/graphics/Latin1TextIterator.h | 12 +- Source/WebCore/platform/graphics/TextRun.h | 10 +- .../platform/graphics/iso/ISOVTTCue.cpp | 2 +- .../platform/network/curl/CookieUtil.cpp | 2 +- .../WebCore/platform/text/SegmentedString.h | 10 +- Source/WebCore/rendering/BreakLines.h | 4 +- Source/WebCore/rendering/RenderBlock.cpp | 2 +- Source/WebCore/rendering/RenderBlock.h | 2 +- Source/WebCore/svg/SVGFitToViewBox.cpp | 2 +- Source/WebCore/svg/SVGFitToViewBox.h | 4 +- Source/WebCore/svg/SVGParserUtilities.cpp | 6 +- Source/WebCore/svg/SVGParserUtilities.h | 12 +- Source/WebCore/svg/SVGPathStringViewSource.h | 4 +- .../svg/SVGPreserveAspectRatioValue.cpp | 2 +- .../WebCore/svg/SVGPreserveAspectRatioValue.h | 4 +- Source/WebCore/svg/SVGTransformList.cpp | 2 +- Source/WebCore/svg/SVGTransformList.h | 4 +- Source/WebCore/svg/SVGTransformable.cpp | 8 +- Source/WebCore/svg/SVGTransformable.h | 8 +- Source/WebCore/svg/SVGZoomAndPan.cpp | 2 +- Source/WebCore/svg/SVGZoomAndPan.h | 4 +- .../xml/parser/XMLDocumentParserLibxml2.cpp | 2 +- Source/WebGPU/WGSL/Lexer.cpp | 8 +- Source/WebGPU/WGSL/Lexer.h | 4 +- Source/WebGPU/WGSL/Parser.cpp | 4 +- Source/WebKit/Platform/IPC/ArgumentCoders.cpp | 4 +- Source/WebKit/Platform/IPC/DaemonCoders.h | 4 +- .../WebKit/WebProcess/glib/WebProcessGLib.cpp | 2 +- Tools/Scripts/do-webcore-rename | 17 +- .../Tests/WGSL/ConstLiteralTests.cpp | 2 +- Tools/TestWebKitAPI/Tests/WGSL/LexerTests.cpp | 4 +- Tools/TestWebKitAPI/Tests/WTF/HexNumber.cpp | 2 +- .../TestWebKitAPI/Tests/WTF/StringBuilder.cpp | 14 +- .../TestWebKitAPI/Tests/WTF/StringCommon.cpp | 78 +- .../TestWebKitAPI/Tests/WTF/StringHasher.cpp | 16 +- Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp | 4 +- .../Tests/WTF/StringParsingBuffer.cpp | 2 +- Tools/TestWebKitAPI/Tests/WTF/StringView.cpp | 14 +- .../TestWebKitAPI/Tests/WTF/SuperFastHash.cpp | 18 +- .../Tests/WTF/UTF8Conversion.cpp | 2 +- Tools/TestWebKitAPI/Tests/WTF/Vector.cpp | 4 +- Tools/TestWebKitAPI/Tests/WTF/WYHash.cpp | 6 +- .../Tests/WTF/cocoa/URLExtras.mm | 2 +- .../Tests/WebCore/SharedBuffer.cpp | 2 +- .../Tests/WebKitCocoa/Download.mm | 4 +- .../WKWebExtensionAPIWebNavigation.mm | 4 +- .../InjectedBundle/InjectedBundlePage.cpp | 4 +- Tools/gdb/webkit.py | 6 +- 208 files changed, 4434 insertions(+), 1271 deletions(-) rename Source/WTF/wtf/text/{LChar.h => Latin1Character.h} (97%) create mode 100644 Source/WebCore/css/scripts/test/TestCSSPropertiesResults/CSSPropertyNames.gperf create mode 100644 Source/WebCore/editing/cocoa/NodeHTMLConverter.mm diff --git a/Source/JavaScriptCore/API/JSStringRefCF.cpp b/Source/JavaScriptCore/API/JSStringRefCF.cpp index b29072484864d..156202a0d6a9a 100644 --- a/Source/JavaScriptCore/API/JSStringRefCF.cpp +++ b/Source/JavaScriptCore/API/JSStringRefCF.cpp @@ -45,7 +45,7 @@ JSStringRef JSStringCreateWithCFString(CFStringRef string) if (!length) return &OpaqueJSString::create(""_span8).leakRef(); - Vector lcharBuffer(length); + Vector lcharBuffer(length); CFIndex usedBufferLength; CFIndex convertedSize = CFStringGetBytes(string, CFRangeMake(0, length), kCFStringEncodingISOLatin1, 0, false, lcharBuffer.data(), length, &usedBufferLength); if (static_cast(convertedSize) == length && static_cast(usedBufferLength) == length) diff --git a/Source/JavaScriptCore/API/JSValueRef.cpp b/Source/JavaScriptCore/API/JSValueRef.cpp index ed96912742b03..fae8e64d71e88 100644 --- a/Source/JavaScriptCore/API/JSValueRef.cpp +++ b/Source/JavaScriptCore/API/JSValueRef.cpp @@ -697,7 +697,7 @@ JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string) JSLockHolder locker(globalObject); String str = string->string(); if (str.is8Bit()) { - LiteralParser parser(globalObject, str.span8(), StrictJSON); + LiteralParser parser(globalObject, str.span8(), StrictJSON); return toRef(globalObject, parser.tryLiteralParse()); } LiteralParser parser(globalObject, str.span16(), StrictJSON); diff --git a/Source/JavaScriptCore/API/OpaqueJSString.h b/Source/JavaScriptCore/API/OpaqueJSString.h index 56df6fa82dbaf..b6c43f359340e 100644 --- a/Source/JavaScriptCore/API/OpaqueJSString.h +++ b/Source/JavaScriptCore/API/OpaqueJSString.h @@ -40,7 +40,7 @@ struct OpaqueJSString : public ThreadSafeRefCounted { return adoptRef(*new OpaqueJSString); } - static Ref create(std::span characters) + static Ref create(std::span characters) { return adoptRef(*new OpaqueJSString(characters)); } @@ -56,7 +56,7 @@ struct OpaqueJSString : public ThreadSafeRefCounted { JS_EXPORT_PRIVATE ~OpaqueJSString(); bool is8Bit() { return m_string.is8Bit(); } - std::span span8() LIFETIME_BOUND { return m_string.span8(); } + std::span span8() LIFETIME_BOUND { return m_string.span8(); } std::span span16() LIFETIME_BOUND { return m_string.span16(); } unsigned length() { return m_string.length(); } @@ -87,7 +87,7 @@ struct OpaqueJSString : public ThreadSafeRefCounted { { } - OpaqueJSString(std::span characters) + OpaqueJSString(std::span characters) : m_string(characters) , m_characters(nullptr) { diff --git a/Source/JavaScriptCore/API/glib/JSCValue.cpp b/Source/JavaScriptCore/API/glib/JSCValue.cpp index aba485286c154..7a26478a8471d 100644 --- a/Source/JavaScriptCore/API/glib/JSCValue.cpp +++ b/Source/JavaScriptCore/API/glib/JSCValue.cpp @@ -2093,7 +2093,7 @@ JSCValue* jsc_value_new_from_json(JSCContext* context, const char* json) JSC::JSValue jsValue; String jsonString = String::fromUTF8(json); if (jsonString.is8Bit()) { - JSC::LiteralParser jsonParser(globalObject, jsonString.span8(), JSC::StrictJSON); + JSC::LiteralParser jsonParser(globalObject, jsonString.span8(), JSC::StrictJSON); jsValue = jsonParser.tryLiteralParse(); if (!jsValue) exception = toRef(JSC::createSyntaxError(globalObject, jsonParser.getErrorMessage())); diff --git a/Source/JavaScriptCore/KeywordLookupGenerator.py b/Source/JavaScriptCore/KeywordLookupGenerator.py index 37d5a5a6eea97..af7d34070c361 100644 --- a/Source/JavaScriptCore/KeywordLookupGenerator.py +++ b/Source/JavaScriptCore/KeywordLookupGenerator.py @@ -185,7 +185,7 @@ def printAsC(self): print("") print("namespace JSC {") print("") - print("static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(LChar);") + print("static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(Latin1Character);") print("static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(char16_t);") # max length + 1 so we don't need to do any bounds checking at all print("static constexpr int maxTokenLength = %d;" % (self.maxLength() + 1)) @@ -201,11 +201,11 @@ def printAsC(self): print("}") print("") print("template <>") - print("template ALWAYS_INLINE JSTokenType Lexer::parseKeyword(JSTokenData* data)") + print("template ALWAYS_INLINE JSTokenType Lexer::parseKeyword(JSTokenData* data)") print("{") print(" ASSERT(m_codeEnd - m_code >= maxTokenLength);") print("") - print(" const LChar* code = m_code;") + print(" const Latin1Character* code = m_code;") self.printSubTreeAsC("CHAR", 4) print(" return IDENT;") print("}") diff --git a/Source/JavaScriptCore/builtins/BuiltinExecutables.cpp b/Source/JavaScriptCore/builtins/BuiltinExecutables.cpp index 15676a8e82ede..45e245cba264e 100644 --- a/Source/JavaScriptCore/builtins/BuiltinExecutables.cpp +++ b/Source/JavaScriptCore/builtins/BuiltinExecutables.cpp @@ -128,7 +128,7 @@ UnlinkedFunctionExecutable* BuiltinExecutables::createExecutable(VM& vm, const S continue; } else if (characters[i] == ',') ++commas; - else if (!Lexer::isWhiteSpace(characters[i])) + else if (!Lexer::isWhiteSpace(characters[i])) sawOneParam = true; if (i + 2 < view.length() && characters[i] == '.' && characters[i + 1] == '.' && characters[i + 2] == '.') { diff --git a/Source/JavaScriptCore/builtins/BuiltinNames.cpp b/Source/JavaScriptCore/builtins/BuiltinNames.cpp index 701a2accb17b4..45d1de8b9d843 100644 --- a/Source/JavaScriptCore/builtins/BuiltinNames.cpp +++ b/Source/JavaScriptCore/builtins/BuiltinNames.cpp @@ -93,7 +93,7 @@ BuiltinNames::BuiltinNames(VM& vm, CommonIdentifiers* commonIdentifiers) #undef INITIALIZE_WELL_KNOWN_SYMBOL_PUBLIC_TO_PRIVATE_ENTRY -using LCharBuffer = WTF::HashTranslatorCharBuffer; +using LCharBuffer = WTF::HashTranslatorCharBuffer; using UCharBuffer = WTF::HashTranslatorCharBuffer; template @@ -132,7 +132,7 @@ static SymbolImpl* lookUpWellKnownSymbolImpl(const BuiltinNames::WellKnownSymbol return iterator->value; } -PrivateSymbolImpl* BuiltinNames::lookUpPrivateName(std::span characters) const +PrivateSymbolImpl* BuiltinNames::lookUpPrivateName(std::span characters) const { LCharBuffer buffer { characters }; return lookUpPrivateNameImpl(m_privateNameSet, buffer); @@ -154,7 +154,7 @@ PrivateSymbolImpl* BuiltinNames::lookUpPrivateName(const String& string) const return lookUpPrivateNameImpl(m_privateNameSet, buffer); } -SymbolImpl* BuiltinNames::lookUpWellKnownSymbol(std::span characters) const +SymbolImpl* BuiltinNames::lookUpWellKnownSymbol(std::span characters) const { LCharBuffer buffer { characters }; return lookUpWellKnownSymbolImpl(m_wellKnownSymbolsMap, buffer); diff --git a/Source/JavaScriptCore/builtins/BuiltinNames.h b/Source/JavaScriptCore/builtins/BuiltinNames.h index 71edb79a95403..880eb993aeb2c 100644 --- a/Source/JavaScriptCore/builtins/BuiltinNames.h +++ b/Source/JavaScriptCore/builtins/BuiltinNames.h @@ -246,12 +246,12 @@ class BuiltinNames { PrivateSymbolImpl* lookUpPrivateName(const Identifier&) const; PrivateSymbolImpl* lookUpPrivateName(const String&) const; - PrivateSymbolImpl* lookUpPrivateName(std::span) const; + PrivateSymbolImpl* lookUpPrivateName(std::span) const; PrivateSymbolImpl* lookUpPrivateName(std::span) const; SymbolImpl* lookUpWellKnownSymbol(const Identifier&) const; SymbolImpl* lookUpWellKnownSymbol(const String&) const; - SymbolImpl* lookUpWellKnownSymbol(std::span) const; + SymbolImpl* lookUpWellKnownSymbol(std::span) const; SymbolImpl* lookUpWellKnownSymbol(std::span) const; void appendExternalName(const Identifier& publicName, const Identifier& privateName); diff --git a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp index 22cb7847d1573..b42f48a0d656d 100644 --- a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp +++ b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp @@ -12198,7 +12198,7 @@ struct CharacterCase { return character < other.character; } - LChar character; + Latin1Character character; unsigned begin; unsigned end; }; diff --git a/Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.h b/Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.h index b6a99aea06c2a..8f3e44391d862 100644 --- a/Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.h +++ b/Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.h @@ -194,7 +194,7 @@ namespace JSC { namespace FTL { macro(JSInternalFieldObjectImpl_internalFields, JSInternalFieldObjectImpl<>::offsetOfInternalFields(), sizeof(WriteBarrier)) \ macro(ScopedArguments_Storage_storage, 0, sizeof(EncodedJSValue)) \ macro(WriteBarrierBuffer_bufferContents, 0, sizeof(JSCell*)) \ - macro(characters8, 0, sizeof(LChar)) \ + macro(characters8, 0, sizeof(Latin1Character)) \ macro(characters16, 0, sizeof(char16_t)) \ macro(indexedInt32Properties, 0, sizeof(EncodedJSValue)) \ macro(indexedDoubleProperties, 0, sizeof(double)) \ diff --git a/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp b/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp index 61635981c9cc9..cbef7dcc11548 100644 --- a/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp +++ b/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp @@ -20178,7 +20178,7 @@ IGNORE_CLANG_WARNINGS_END { } - CharacterCase(LChar character, unsigned begin, unsigned end) + CharacterCase(Latin1Character character, unsigned begin, unsigned end) : character(character) , begin(begin) , end(end) @@ -20190,7 +20190,7 @@ IGNORE_CLANG_WARNINGS_END return character < other.character; } - LChar character; + Latin1Character character; unsigned begin; unsigned end; }; @@ -20282,7 +20282,7 @@ IGNORE_CLANG_WARNINGS_END Vector characterCases; CharacterCase currentCase(cases[begin].string->at(commonChars), begin, begin + 1); for (unsigned i = begin + 1; i < end; ++i) { - LChar currentChar = cases[i].string->at(commonChars); + Latin1Character currentChar = cases[i].string->at(commonChars); if (currentChar != currentCase.character) { currentCase.end = i; characterCases.append(currentCase); diff --git a/Source/JavaScriptCore/interpreter/Interpreter.cpp b/Source/JavaScriptCore/interpreter/Interpreter.cpp index a6a631cb736be..71fb363f95dfd 100644 --- a/Source/JavaScriptCore/interpreter/Interpreter.cpp +++ b/Source/JavaScriptCore/interpreter/Interpreter.cpp @@ -186,7 +186,7 @@ JSValue eval(CallFrame* callFrame, JSValue thisValue, JSScope* callerScopeChain, if (!eval) { if (!(lexicallyScopedFeatures & StrictModeLexicallyScopedFeature)) { if (programSource.is8Bit()) { - LiteralParser preparser(globalObject, programSource.span8(), SloppyJSON, callerBaselineCodeBlock); + LiteralParser preparser(globalObject, programSource.span8(), SloppyJSON, callerBaselineCodeBlock); if (JSValue parsedObject = preparser.tryLiteralParse()) RELEASE_AND_RETURN(scope, parsedObject); @@ -1018,7 +1018,7 @@ JSValue Interpreter::executeProgram(const SourceCode& source, JSGlobalObject*, J if (programSource.isNull()) return jsUndefined(); if (programSource.is8Bit()) { - LiteralParser literalParser(globalObject, programSource.span8(), JSONP); + LiteralParser literalParser(globalObject, programSource.span8(), JSONP); parseResult = literalParser.tryJSONPParse(JSONPData, globalObject->globalObjectMethodTable()->supportsRichSourceInfo(globalObject)); } else { LiteralParser literalParser(globalObject, programSource.span16(), JSONP); diff --git a/Source/JavaScriptCore/parser/Lexer.cpp b/Source/JavaScriptCore/parser/Lexer.cpp index f3352dca8f80b..1eaf993aae1e7 100644 --- a/Source/JavaScriptCore/parser/Lexer.cpp +++ b/Source/JavaScriptCore/parser/Lexer.cpp @@ -359,7 +359,7 @@ static constexpr const CharacterType typesOfLatin1Characters[256] = { // This table provides the character that results from \X where X is the index in the table beginning // with SPACE. A table value of 0 means that more processing needs to be done. -static constexpr const LChar singleCharacterEscapeValuesForASCII[128] = { +static constexpr const Latin1Character singleCharacterEscapeValuesForASCII[128] = { /* 0 - Null */ 0, /* 1 - Start of Heading */ 0, /* 2 - Start of Text */ 0, @@ -739,20 +739,20 @@ static bool isNonLatin1IdentStart(char32_t c) template static ALWAYS_INLINE bool isIdentStart(CharacterType c) { - static_assert(std::is_same_v || std::is_same_v, "Call isSingleCharacterIdentStart for char16_ts that don't need to check for surrogate pairs"); + static_assert(std::is_same_v || std::is_same_v, "Call isSingleCharacterIdentStart for char16_ts that don't need to check for surrogate pairs"); if (!isLatin1(c)) return isNonLatin1IdentStart(c); - return typesOfLatin1Characters[static_cast(c)] == CharacterIdentifierStart; + return typesOfLatin1Characters[static_cast(c)] == CharacterIdentifierStart; } static ALWAYS_INLINE UNUSED_FUNCTION bool isSingleCharacterIdentStart(char16_t c) { if (LIKELY(isLatin1(c))) - return isIdentStart(static_cast(c)); + return isIdentStart(static_cast(c)); return !U16_IS_SURROGATE(c) && isIdentStart(static_cast(c)); } -static ALWAYS_INLINE bool cannotBeIdentStart(LChar c) +static ALWAYS_INLINE bool cannotBeIdentStart(Latin1Character c) { return !isIdentStart(c) && c != '\\'; } @@ -760,7 +760,7 @@ static ALWAYS_INLINE bool cannotBeIdentStart(LChar c) static ALWAYS_INLINE bool cannotBeIdentStart(char16_t c) { if (LIKELY(isLatin1(c))) - return cannotBeIdentStart(static_cast(c)); + return cannotBeIdentStart(static_cast(c)); return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); } @@ -772,24 +772,24 @@ static NEVER_INLINE bool isNonLatin1IdentPart(char32_t c) template static ALWAYS_INLINE bool isIdentPart(CharacterType c) { - static_assert(std::is_same_v || std::is_same_v, "Call isSingleCharacterIdentPart for char16_ts that don't need to check for surrogate pairs"); + static_assert(std::is_same_v || std::is_same_v, "Call isSingleCharacterIdentPart for char16_ts that don't need to check for surrogate pairs"); if (!isLatin1(c)) return isNonLatin1IdentPart(c); // Character types are divided into two groups depending on whether they can be part of an // identifier or not. Those whose type value is less or equal than CharacterOtherIdentifierPart can be // part of an identifier. (See the CharacterType definition for more details.) - return typesOfLatin1Characters[static_cast(c)] <= CharacterOtherIdentifierPart; + return typesOfLatin1Characters[static_cast(c)] <= CharacterOtherIdentifierPart; } static ALWAYS_INLINE bool isSingleCharacterIdentPart(char16_t c) { if (LIKELY(isLatin1(c))) - return isIdentPart(static_cast(c)); + return isIdentPart(static_cast(c)); return !U16_IS_SURROGATE(c) && isIdentPart(static_cast(c)); } -static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(LChar c) +static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(Latin1Character c) { return !isIdentPart(c) && c != '\\'; } @@ -799,13 +799,13 @@ static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(LChar c) static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(char16_t c) { if (LIKELY(isLatin1(c))) - return cannotBeIdentPartOrEscapeStart(static_cast(c)); + return cannotBeIdentPartOrEscapeStart(static_cast(c)); return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); } template<> -ALWAYS_INLINE char32_t Lexer::currentCodePoint() const +ALWAYS_INLINE char32_t Lexer::currentCodePoint() const { return m_current; } @@ -848,7 +848,7 @@ static inline bool isASCIIOctalDigitOrSeparator(CharacterType character) return isASCIIOctalDigit(character) || character == '_'; } -static inline LChar singleEscape(int c) +static inline Latin1Character singleEscape(int c) { if (c < 128) { ASSERT(static_cast(c) < std::size(singleCharacterEscapeValuesForASCII)); @@ -861,7 +861,7 @@ template inline void Lexer::record8(int c) { ASSERT(isLatin1(c)); - m_buffer8.append(static_cast(c)); + m_buffer8.append(static_cast(c)); } template @@ -869,7 +869,7 @@ inline void Lexer::append8(std::span span) { size_t currentSize = m_buffer8.size(); m_buffer8.grow(currentSize + span.size()); - LChar* rawBuffer = m_buffer8.data() + currentSize; + Latin1Character* rawBuffer = m_buffer8.data() + currentSize; for (size_t i = 0; i < span.size(); i++) { T c = span[i]; @@ -879,7 +879,7 @@ inline void Lexer::append8(std::span span) } template -inline void Lexer::append16(std::span span) +inline void Lexer::append16(std::span span) { size_t currentSize = m_buffer16.size(); m_buffer16.grow(currentSize + span.size()); @@ -936,7 +936,7 @@ bool isSafeBuiltinIdentifier(VM& vm, const Identifier* ident) #endif // ASSERT_ENABLED template <> -template ALWAYS_INLINE JSTokenType Lexer::parseIdentifier(JSTokenData* tokenData, OptionSet lexerFlags, bool strictMode) +template ALWAYS_INLINE JSTokenType Lexer::parseIdentifier(JSTokenData* tokenData, OptionSet lexerFlags, bool strictMode) { tokenData->escaped = false; const ptrdiff_t remaining = m_codeEnd - m_code; @@ -960,7 +960,7 @@ template ALWAYS_INLINE JSTokenType Lexer::p } } - const LChar* identifierStart = currentSourcePtr(); + const Latin1Character* identifierStart = currentSourcePtr(); if (isPrivateName) shift(); @@ -1172,7 +1172,7 @@ JSTokenType Lexer::parseIdentifierSlowCase(JSTokenData* tokenData return identType; } -static ALWAYS_INLINE bool characterRequiresParseStringSlowCase(LChar character) +static ALWAYS_INLINE bool characterRequiresParseStringSlowCase(Latin1Character character) { return character < 0xE; } @@ -1199,7 +1199,7 @@ template ALWAYS_INLINE typename Lexer::StringParseR append8({ stringStart, currentSourcePtr() }); shift(); - LChar escape = singleEscape(m_current); + Latin1Character escape = singleEscape(m_current); // Most common escape sequences first. if (escape) { @@ -1363,7 +1363,7 @@ template auto Lexer::parseStringSlowCase(JSTokenDat append16({ stringStart, currentSourcePtr() }); shift(); - LChar escape = singleEscape(m_current); + Latin1Character escape = singleEscape(m_current); // Most common escape sequences first if (escape) { @@ -1419,7 +1419,7 @@ typename Lexer::StringParseResult Lexer::parseTemplateLiteral(JSTokenData* append16({ stringStart, currentSourcePtr() }); shift(); - LChar escape = singleEscape(m_current); + Latin1Character escape = singleEscape(m_current); // Most common escape sequences first. if (escape) { @@ -1592,7 +1592,7 @@ ALWAYS_INLINE auto Lexer::parseBinary() -> std::optional int digit = maximumDigits - 1; // Temporary buffer for the digits. Makes easier // to reconstruct the input characters when needed. - LChar digits[maximumDigits]; + Latin1Character digits[maximumDigits]; do { if (m_current == '_') { @@ -1648,7 +1648,7 @@ ALWAYS_INLINE auto Lexer::parseOctal() -> std::optional int digit = maximumDigits - 1; // Temporary buffer for the digits. Makes easier // to reconstruct the input characters when needed. - LChar digits[maximumDigits]; + Latin1Character digits[maximumDigits]; do { if (m_current == '_') { @@ -1707,7 +1707,7 @@ ALWAYS_INLINE auto Lexer::parseDecimal() -> std::optional int digit = maximumDigits - 1; // Temporary buffer for the digits. Makes easier // to reconstruct the input characters when needed. - LChar digits[maximumDigits]; + Latin1Character digits[maximumDigits]; do { if (m_current == '_') { @@ -2522,7 +2522,7 @@ JSTokenType Lexer::lexWithoutClearingLineTerminator(JSToken* tokenRecord, Opt bool isValidPrivateName; if (LIKELY(isLatin1(next))) - isValidPrivateName = typesOfLatin1Characters[static_cast(next)] == CharacterIdentifierStart || next == '\\'; + isValidPrivateName = typesOfLatin1Characters[static_cast(next)] == CharacterIdentifierStart || next == '\\'; else { ASSERT(m_code + 1 < m_codeEnd); char32_t codePoint; @@ -2608,7 +2608,7 @@ template static inline void orCharacter(char16_t&, char16_t); template <> -inline void orCharacter(char16_t&, char16_t) { } +inline void orCharacter(char16_t&, char16_t) { } template <> inline void orCharacter(char16_t& orAccumulator, char16_t character) @@ -2675,8 +2675,8 @@ JSTokenType Lexer::scanRegExp(JSToken* tokenRecord, char16_t patternPrefix) m_buffer16.shrink(0); ASSERT(m_buffer8.isEmpty()); - while (LIKELY(isLatin1(m_current)) && isIdentPart(static_cast(m_current))) { - record8(static_cast(m_current)); + while (LIKELY(isLatin1(m_current)) && isIdentPart(static_cast(m_current))) { + record8(static_cast(m_current)); shift(); } @@ -2735,7 +2735,7 @@ void Lexer::clear() { m_arena = nullptr; - Vector newBuffer8; + Vector newBuffer8; m_buffer8.swap(newBuffer8); Vector newBuffer16; @@ -2748,7 +2748,7 @@ void Lexer::clear() } // Instantiate the two flavors of Lexer we need instead of putting most of this file in Lexer.h -template class Lexer; +template class Lexer; template class Lexer; } // namespace JSC diff --git a/Source/JavaScriptCore/parser/Lexer.h b/Source/JavaScriptCore/parser/Lexer.h index 754d40c2e2496..bc328e32f856b 100644 --- a/Source/JavaScriptCore/parser/Lexer.h +++ b/Source/JavaScriptCore/parser/Lexer.h @@ -135,7 +135,7 @@ class Lexer { void record16(int); void record16(T); void recordUnicodeCodePoint(char32_t); - void append16(std::span); + void append16(std::span); void append16(std::span characters) { m_buffer16.append(characters); } static constexpr char32_t errorCodePoint = 0xFFFFFFFFu; @@ -158,7 +158,7 @@ class Lexer { template ALWAYS_INLINE const Identifier* makeIdentifier(std::span); - ALWAYS_INLINE const Identifier* makeLCharIdentifier(std::span); + ALWAYS_INLINE const Identifier* makeLCharIdentifier(std::span); ALWAYS_INLINE const Identifier* makeLCharIdentifier(std::span); ALWAYS_INLINE const Identifier* makeRightSizedIdentifier(std::span, char16_t orAllChars); ALWAYS_INLINE const Identifier* makeIdentifierLCharFromUChar(std::span); @@ -206,7 +206,7 @@ class Lexer { int m_lineNumber; int m_lastLineNumber; - Vector m_buffer8; + Vector m_buffer8; Vector m_buffer16; Vector m_bufferForRawTemplateString16; bool m_hasLineTerminatorBeforeToken; @@ -241,7 +241,7 @@ class Lexer { WTF_MAKE_TZONE_ALLOCATED_TEMPLATE_IMPL(template, Lexer); template <> -ALWAYS_INLINE bool Lexer::isWhiteSpace(LChar ch) +ALWAYS_INLINE bool Lexer::isWhiteSpace(Latin1Character ch) { return ch == ' ' || ch == '\t' || ch == 0xB || ch == 0xC || ch == 0xA0; } @@ -249,11 +249,11 @@ ALWAYS_INLINE bool Lexer::isWhiteSpace(LChar ch) template <> ALWAYS_INLINE bool Lexer::isWhiteSpace(char16_t ch) { - return isLatin1(ch) ? Lexer::isWhiteSpace(static_cast(ch)) : (u_charType(ch) == U_SPACE_SEPARATOR || ch == byteOrderMark); + return isLatin1(ch) ? Lexer::isWhiteSpace(static_cast(ch)) : (u_charType(ch) == U_SPACE_SEPARATOR || ch == byteOrderMark); } template <> -ALWAYS_INLINE bool Lexer::isLineTerminator(LChar ch) +ALWAYS_INLINE bool Lexer::isLineTerminator(Latin1Character ch) { return ch == '\r' || ch == '\n'; } @@ -284,7 +284,7 @@ ALWAYS_INLINE const Identifier* Lexer::makeIdentifier(std::span -ALWAYS_INLINE const Identifier* Lexer::makeRightSizedIdentifier(std::span characters, char16_t) +ALWAYS_INLINE const Identifier* Lexer::makeRightSizedIdentifier(std::span characters, char16_t) { return &m_arena->makeIdentifierLCharFromUChar(m_vm, characters); } @@ -305,7 +305,7 @@ ALWAYS_INLINE const Identifier* Lexer::makeEmptyIdentifier() } template <> -ALWAYS_INLINE void Lexer::setCodeStart(StringView sourceString) +ALWAYS_INLINE void Lexer::setCodeStart(StringView sourceString) { ASSERT(sourceString.is8Bit()); m_codeStart = sourceString.span8().data(); @@ -325,7 +325,7 @@ ALWAYS_INLINE const Identifier* Lexer::makeIdentifierLCharFromUChar(std::span } template -ALWAYS_INLINE const Identifier* Lexer::makeLCharIdentifier(std::span characters) +ALWAYS_INLINE const Identifier* Lexer::makeLCharIdentifier(std::span characters) { return &m_arena->makeIdentifier(m_vm, characters); } diff --git a/Source/JavaScriptCore/parser/Parser.cpp b/Source/JavaScriptCore/parser/Parser.cpp index 073521882a070..4d65b83f1f7e9 100644 --- a/Source/JavaScriptCore/parser/Parser.cpp +++ b/Source/JavaScriptCore/parser/Parser.cpp @@ -5755,7 +5755,7 @@ template void Parser::printUnexpectedTokenText(W } // Instantiate the two flavors of Parser we need instead of putting most of this file in Parser.h -template class Parser>; +template class Parser>; template class Parser>; } // namespace JSC diff --git a/Source/JavaScriptCore/parser/Parser.h b/Source/JavaScriptCore/parser/Parser.h index 443cb78a1a024..c525d8cac325b 100644 --- a/Source/JavaScriptCore/parser/Parser.h +++ b/Source/JavaScriptCore/parser/Parser.h @@ -2284,7 +2284,7 @@ std::unique_ptr parse( std::unique_ptr result; if (source.provider()->source().is8Bit()) { - Parser> parser(vm, source, implementationVisibility, builtinMode, lexicallyScopedFeatures, scriptMode, parseMode, functionMode, superBinding, constructorKind, derivedContextType, isEvalNode(), evalContextType, nullptr, isInsideOrdinaryFunction); + Parser> parser(vm, source, implementationVisibility, builtinMode, lexicallyScopedFeatures, scriptMode, parseMode, functionMode, superBinding, constructorKind, derivedContextType, isEvalNode(), evalContextType, nullptr, isInsideOrdinaryFunction); result = parser.parse(error, name, ParsingContext::Normal, std::nullopt, parentScopePrivateNames, classElementDefinitions); if (builtinMode == JSParserBuiltinMode::Builtin) { if (!result) { @@ -2332,7 +2332,7 @@ std::unique_ptr parseRootNode( bool isInsideOrdinaryFunction = false; std::unique_ptr result; if (source.provider()->source().is8Bit()) { - Parser> parser(vm, source, implementationVisibility, builtinMode, lexicallyScopedFeatures, scriptMode, parseMode, FunctionMode::None, SuperBinding::NotNeeded, ConstructorKind::None, DerivedContextType::None, isEvalNode, EvalContextType::None, debuggerParseData, isInsideOrdinaryFunction); + Parser> parser(vm, source, implementationVisibility, builtinMode, lexicallyScopedFeatures, scriptMode, parseMode, FunctionMode::None, SuperBinding::NotNeeded, ConstructorKind::None, DerivedContextType::None, isEvalNode, EvalContextType::None, debuggerParseData, isInsideOrdinaryFunction); parser.overrideConstructorKindForTopLevelFunctionExpressions(constructorKindForTopLevelFunctionExpressions); result = parser.parse(error, name, ParsingContext::Normal); if (positionBeforeLastNewline) @@ -2368,7 +2368,7 @@ inline std::unique_ptr parseFunctionForFunctionConstructor(VM& vm, bool isEvalNode = false; std::unique_ptr result; if (source.provider()->source().is8Bit()) { - Parser> parser(vm, source, ImplementationVisibility::Public, JSParserBuiltinMode::NotBuiltin, lexicallyScopedFeatures, JSParserScriptMode::Classic, SourceParseMode::ProgramMode, FunctionMode::None, SuperBinding::NotNeeded, ConstructorKind::None, DerivedContextType::None, isEvalNode, EvalContextType::None, nullptr); + Parser> parser(vm, source, ImplementationVisibility::Public, JSParserBuiltinMode::NotBuiltin, lexicallyScopedFeatures, JSParserScriptMode::Classic, SourceParseMode::ProgramMode, FunctionMode::None, SuperBinding::NotNeeded, ConstructorKind::None, DerivedContextType::None, isEvalNode, EvalContextType::None, nullptr); result = parser.parse(error, name, ParsingContext::FunctionConstructor, functionConstructorParametersEndPosition); if (positionBeforeLastNewline) *positionBeforeLastNewline = parser.positionBeforeLastNewline(); diff --git a/Source/JavaScriptCore/runtime/ArrayPrototype.cpp b/Source/JavaScriptCore/runtime/ArrayPrototype.cpp index ea3af3d8eba75..079d65cf62792 100644 --- a/Source/JavaScriptCore/runtime/ArrayPrototype.cpp +++ b/Source/JavaScriptCore/runtime/ArrayPrototype.cpp @@ -418,7 +418,7 @@ JSC_DEFINE_HOST_FUNCTION(arrayProtoFuncToString, (JSGlobalObject* globalObject, return JSValue::encode(earlyReturnValue); if (LIKELY(canUseFastJoin(thisArray))) { - const LChar comma = ','; + const Latin1Character comma = ','; bool isCoW = isCopyOnWrite(thisArray->indexingMode()); JSImmutableButterfly* immutableButterfly = nullptr; @@ -506,7 +506,7 @@ JSC_DEFINE_HOST_FUNCTION(arrayProtoFuncToLocaleString, (JSGlobalObject* globalOb // 3. Let separator be the String value for the list-separator String appropriate for // the host environment's current locale (this is derived in an implementation-defined way). - const LChar comma = ','; + const Latin1Character comma = ','; JSString* separator = jsSingleCharacterString(vm, comma); // 4. Let R be the empty String. @@ -628,7 +628,7 @@ JSC_DEFINE_HOST_FUNCTION(arrayProtoFuncJoin, (JSGlobalObject* globalObject, Call // 3. If separator is undefined, let separator be the single-element String ",". JSValue separatorValue = callFrame->argument(0); if (separatorValue.isUndefined()) { - const LChar comma = ','; + const Latin1Character comma = ','; if (UNLIKELY(length > std::numeric_limits::max() || !canUseFastJoin(thisObject))) { JSString* jsSeparator = jsSingleCharacterString(vm, comma); diff --git a/Source/JavaScriptCore/runtime/CachedTypes.cpp b/Source/JavaScriptCore/runtime/CachedTypes.cpp index 11ad05bd7bfc1..11b491d120a9b 100644 --- a/Source/JavaScriptCore/runtime/CachedTypes.cpp +++ b/Source/JavaScriptCore/runtime/CachedTypes.cpp @@ -781,7 +781,7 @@ class CachedUniquedStringImplBase : public VariableLengthObject { return m_is8Bit ? create(span8()) : create(span16()); } - std::span span8() const { return { this->template buffer(), m_length }; } + std::span span8() const { return { this->template buffer(), m_length }; } std::span span16() const { return { this->template buffer(), m_length }; } private: diff --git a/Source/JavaScriptCore/runtime/FuzzerPredictions.cpp b/Source/JavaScriptCore/runtime/FuzzerPredictions.cpp index 9e80d7df7c939..f2f5dce33c01a 100644 --- a/Source/JavaScriptCore/runtime/FuzzerPredictions.cpp +++ b/Source/JavaScriptCore/runtime/FuzzerPredictions.cpp @@ -39,7 +39,7 @@ static String readFileIntoString(const char* fileName) RELEASE_ASSERT(bufferCapacity != -1); RELEASE_ASSERT(fseek(file, 0, SEEK_SET) != -1); - std::span buffer; + std::span buffer; auto bufferData = buffer.data(); String string = String::createUninitialized(bufferCapacity, bufferData); WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN diff --git a/Source/JavaScriptCore/runtime/ISO8601.cpp b/Source/JavaScriptCore/runtime/ISO8601.cpp index 4724463fe0b8a..cf06caa0f2e71 100644 --- a/Source/JavaScriptCore/runtime/ISO8601.cpp +++ b/Source/JavaScriptCore/runtime/ISO8601.cpp @@ -80,7 +80,7 @@ static void handleFraction(Duration& duration, int factor, StringView fractionSt ASSERT(fractionLength && fractionLength <= 9 && fractionString.containsOnlyASCII()); ASSERT(fractionType == TemporalUnit::Hour || fractionType == TemporalUnit::Minute || fractionType == TemporalUnit::Second); - Vector padded(9, '0'); + Vector padded(9, '0'); for (unsigned i = 0; i < fractionLength; i++) padded[i] = fractionString[i]; @@ -363,7 +363,7 @@ static std::optional parseTimeSpec(StringParsingBuffer if (!digits) return std::nullopt; - Vector padded(9, '0'); + Vector padded(9, '0'); for (size_t i = 0; i < digits; ++i) padded[i] = buffer[i]; buffer.advanceBy(digits); @@ -566,7 +566,7 @@ static bool canBeTimeZone(const StringParsingBuffer& buffer, Char } template -static std::optional, int64_t>> parseTimeZoneAnnotation(StringParsingBuffer& buffer) +static std::optional, int64_t>> parseTimeZoneAnnotation(StringParsingBuffer& buffer) { // https://tc39.es/proposal-temporal/#prod-TimeZoneAnnotation // TimeZoneAnnotation : @@ -700,7 +700,7 @@ static std::optional, int64_t>> parseTimeZoneAnnotati if (!isValidComponent(currentNameComponentStartIndex, nameLength)) return std::nullopt; - Vector result(buffer.consume(nameLength)); + Vector result(buffer.consume(nameLength)); if (buffer.atEnd()) return std::nullopt; @@ -836,7 +836,7 @@ static std::optional parseCalendar(StringParsingBuffer result(buffer.consume(nameLength)); + Vector result(buffer.consume(nameLength)); if (buffer.atEnd()) return std::nullopt; @@ -1297,7 +1297,7 @@ String formatTimeZoneOffsetString(int64_t offset) if (nanoseconds) { // Since nsPerSecond is 1000000000, stringified nanoseconds takes at most 9 characters (999999999). - auto fraction = numberToStringUnsigned>(nanoseconds); + auto fraction = numberToStringUnsigned>(nanoseconds); unsigned paddingLength = 9 - fraction.size(); unsigned index = fraction.size(); std::optional validLength; @@ -1332,7 +1332,7 @@ String temporalTimeToString(PlainTime plainTime, std::tuple if (precisionType == Precision::Auto) { if (!fractionNanoseconds) return makeString(pad('0', 2, plainTime.hour()), ':', pad('0', 2, plainTime.minute()), ':', pad('0', 2, plainTime.second())); - auto fraction = numberToStringUnsigned>(fractionNanoseconds); + auto fraction = numberToStringUnsigned>(fractionNanoseconds); unsigned paddingLength = 9 - fraction.size(); unsigned index = fraction.size(); std::optional validLength; @@ -1350,7 +1350,7 @@ String temporalTimeToString(PlainTime plainTime, std::tuple } if (!precisionValue) return makeString(pad('0', 2, plainTime.hour()), ':', pad('0', 2, plainTime.minute()), ':', pad('0', 2, plainTime.second())); - auto fraction = numberToStringUnsigned>(fractionNanoseconds); + auto fraction = numberToStringUnsigned>(fractionNanoseconds); unsigned paddingLength = 9 - fraction.size(); paddingLength = std::min(paddingLength, precisionValue); precisionValue -= paddingLength; diff --git a/Source/JavaScriptCore/runtime/ISO8601.h b/Source/JavaScriptCore/runtime/ISO8601.h index 4e542d227a524..92fc6fb0974c8 100644 --- a/Source/JavaScriptCore/runtime/ISO8601.h +++ b/Source/JavaScriptCore/runtime/ISO8601.h @@ -178,7 +178,7 @@ class ExactTime { { if (value > 9) asStringImpl(builder, value / 10); - builder.append(static_cast(static_cast(value % 10) + '0')); + builder.append(static_cast(static_cast(value % 10) + '0')); } static Int128 round(Int128 quantity, unsigned increment, TemporalUnit, RoundingMode); @@ -261,13 +261,13 @@ using TimeZone = std::variant; struct TimeZoneRecord { bool m_z { false }; std::optional m_offset; - std::variant, int64_t> m_nameOrOffset; + std::variant, int64_t> m_nameOrOffset; }; static constexpr unsigned minCalendarLength = 3; static constexpr unsigned maxCalendarLength = 8; struct CalendarRecord { - Vector m_name; + Vector m_name; }; // https://tc39.es/proposal-temporal/#sup-isvalidtimezonename diff --git a/Source/JavaScriptCore/runtime/Identifier.h b/Source/JavaScriptCore/runtime/Identifier.h index f746c0cb5a644..2d77d8bad54ff 100644 --- a/Source/JavaScriptCore/runtime/Identifier.h +++ b/Source/JavaScriptCore/runtime/Identifier.h @@ -112,7 +112,7 @@ class Identifier { // Use fromUid when constructing Identifier from StringImpl* which may represent symbols. static Identifier fromString(VM&, ASCIILiteral); - static Identifier fromString(VM&, std::span); + static Identifier fromString(VM&, std::span); static Identifier fromString(VM&, std::span); static Identifier fromString(VM&, const String&); static Identifier fromString(VM&, AtomStringImpl*); @@ -144,12 +144,12 @@ class Identifier { bool isPrivateName() const { return isSymbol() && static_cast(impl())->isPrivate(); } friend bool operator==(const Identifier&, const Identifier&); - friend bool operator==(const Identifier&, const LChar*); + friend bool operator==(const Identifier&, const Latin1Character*); friend bool operator==(const Identifier&, const char*); - static bool equal(const StringImpl*, const LChar*); - static inline bool equal(const StringImpl* a, const char* b) { return Identifier::equal(a, byteCast(b)); }; - static bool equal(const StringImpl*, std::span); + static bool equal(const StringImpl*, const Latin1Character*); + static inline bool equal(const StringImpl* a, const char* b) { return Identifier::equal(a, byteCast(b)); }; + static bool equal(const StringImpl*, std::span); static bool equal(const StringImpl*, std::span); static bool equal(const StringImpl* a, const StringImpl* b) { return ::equal(a, b); } @@ -158,7 +158,7 @@ class Identifier { private: AtomString m_string; - Identifier(VM& vm, std::span string) : m_string(add(vm, string)) { ASSERT(m_string.impl()->isAtom()); } + Identifier(VM& vm, std::span string) : m_string(add(vm, string)) { ASSERT(m_string.impl()->isAtom()); } Identifier(VM& vm, std::span string) : m_string(add(vm, string)) { ASSERT(m_string.impl()->isAtom()); } ALWAYS_INLINE Identifier(VM& vm, ASCIILiteral literal) : m_string(add(vm, literal)) { ASSERT(m_string.impl()->isAtom()); } Identifier(VM&, AtomStringImpl*); @@ -175,7 +175,7 @@ class Identifier { { } static bool equal(const Identifier& a, const Identifier& b) { return a.m_string.impl() == b.m_string.impl(); } - static bool equal(const Identifier& a, const LChar* b) { return equal(a.m_string.impl(), b); } + static bool equal(const Identifier& a, const Latin1Character* b) { return equal(a.m_string.impl(), b); } template static Ref add(VM&, std::span); static Ref add8(VM&, std::span); @@ -191,7 +191,7 @@ class Identifier { #endif }; -template <> ALWAYS_INLINE constexpr bool Identifier::canUseSingleCharacterString(LChar) +template <> ALWAYS_INLINE constexpr bool Identifier::canUseSingleCharacterString(Latin1Character) { static_assert(maxSingleCharacterString == 0xff); return true; @@ -228,22 +228,22 @@ inline bool operator==(const Identifier& a, const Identifier& b) return Identifier::equal(a, b); } -inline bool operator==(const Identifier& a, const LChar* b) +inline bool operator==(const Identifier& a, const Latin1Character* b) { return Identifier::equal(a, b); } inline bool operator==(const Identifier& a, const char* b) { - return Identifier::equal(a, byteCast(b)); + return Identifier::equal(a, byteCast(b)); } -inline bool Identifier::equal(const StringImpl* r, const LChar* s) +inline bool Identifier::equal(const StringImpl* r, const Latin1Character* s) { return WTF::equal(r, s); } -inline bool Identifier::equal(const StringImpl* r, std::span s) +inline bool Identifier::equal(const StringImpl* r, std::span s) { return WTF::equal(r, s); } diff --git a/Source/JavaScriptCore/runtime/IdentifierInlines.h b/Source/JavaScriptCore/runtime/IdentifierInlines.h index e9e9dcbf2e0de..69e876ef06e34 100644 --- a/Source/JavaScriptCore/runtime/IdentifierInlines.h +++ b/Source/JavaScriptCore/runtime/IdentifierInlines.h @@ -85,7 +85,7 @@ ALWAYS_INLINE Identifier Identifier::fromString(VM& vm, ASCIILiteral s) return Identifier(vm, s); } -inline Identifier Identifier::fromString(VM& vm, std::span s) +inline Identifier Identifier::fromString(VM& vm, std::span s) { return Identifier(vm, s); } diff --git a/Source/JavaScriptCore/runtime/IntlCollator.cpp b/Source/JavaScriptCore/runtime/IntlCollator.cpp index b2a2fc000d06d..6cbeb03aed285 100644 --- a/Source/JavaScriptCore/runtime/IntlCollator.cpp +++ b/Source/JavaScriptCore/runtime/IntlCollator.cpp @@ -444,7 +444,7 @@ void IntlCollator::checkICULocaleInvariants(const LocaleSet& locales) bool allAreGood = true; for (unsigned x = 0; x < 128; ++x) { for (unsigned y = 0; y < 128; ++y) { - if (canUseASCIIUCADUCETComparison(static_cast(x)) && canUseASCIIUCADUCETComparison(static_cast(y))) { + if (canUseASCIIUCADUCETComparison(static_cast(x)) && canUseASCIIUCADUCETComparison(static_cast(y))) { UErrorCode status = U_ZERO_ERROR; char16_t xstring[] = { static_cast(x), 0 }; char16_t ystring[] = { static_cast(y), 0 }; diff --git a/Source/JavaScriptCore/runtime/IntlDurationFormat.cpp b/Source/JavaScriptCore/runtime/IntlDurationFormat.cpp index c066e80ab130f..f7d35b8e39015 100644 --- a/Source/JavaScriptCore/runtime/IntlDurationFormat.cpp +++ b/Source/JavaScriptCore/runtime/IntlDurationFormat.cpp @@ -345,7 +345,7 @@ static DurationSignType getDurationSign(ISO8601::Duration duration) static String int128ToString(Int128 value) { - Vector resultString; + Vector resultString; bool isNegative = value < 0; if (isNegative) value = -value; diff --git a/Source/JavaScriptCore/runtime/IntlLocale.cpp b/Source/JavaScriptCore/runtime/IntlLocale.cpp index 025cf5ae098d7..b65a7a9533bb5 100644 --- a/Source/JavaScriptCore/runtime/IntlLocale.cpp +++ b/Source/JavaScriptCore/runtime/IntlLocale.cpp @@ -180,7 +180,7 @@ bool LocaleIDBuilder::setKeywordValue(ASCIILiteral key, StringView value) ASSERT(value.containsOnlyASCII()); Vector rawValue(value.length() + 1); - value.getCharacters(byteCast(rawValue.mutableSpan())); + value.getCharacters(byteCast(rawValue.mutableSpan())); rawValue[value.length()] = '\0'; UErrorCode status = U_ZERO_ERROR; diff --git a/Source/JavaScriptCore/runtime/IntlNumberFormatInlines.h b/Source/JavaScriptCore/runtime/IntlNumberFormatInlines.h index 980da4e3c74ab..cb0f52aa00ec7 100644 --- a/Source/JavaScriptCore/runtime/IntlNumberFormatInlines.h +++ b/Source/JavaScriptCore/runtime/IntlNumberFormatInlines.h @@ -235,7 +235,7 @@ void appendNumberFormatDigitOptionsToSkeleton(IntlType* intlInstance, StringBuil if (intlInstance->m_roundingIncrement != 1) { skeletonBuilder.append(" precision-increment/"_s); - auto string = numberToStringUnsigned>(intlInstance->m_roundingIncrement); + auto string = numberToStringUnsigned>(intlInstance->m_roundingIncrement); if (intlInstance->m_maximumFractionDigits >= string.size()) { skeletonBuilder.append("0."_s); for (unsigned i = 0; i < (intlInstance->m_maximumFractionDigits - string.size()); ++i) diff --git a/Source/JavaScriptCore/runtime/IntlObject.cpp b/Source/JavaScriptCore/runtime/IntlObject.cpp index 755357e168f98..4bc596c168e50 100644 --- a/Source/JavaScriptCore/runtime/IntlObject.cpp +++ b/Source/JavaScriptCore/runtime/IntlObject.cpp @@ -1145,9 +1145,9 @@ static VariantCode parseVariantCode(StringView string) ASSERT(string.length() <= 8); ASSERT(string.length() >= 1); struct Code { - LChar characters[8] { }; + Latin1Character characters[8] { }; }; - static_assert(std::is_unsigned_v); + static_assert(std::is_unsigned_v); static_assert(sizeof(VariantCode) == sizeof(Code)); Code code { }; for (unsigned index = 0; index < string.length(); ++index) diff --git a/Source/JavaScriptCore/runtime/IntlObjectInlines.h b/Source/JavaScriptCore/runtime/IntlObjectInlines.h index e731949bd0a45..775a26f8379d1 100644 --- a/Source/JavaScriptCore/runtime/IntlObjectInlines.h +++ b/Source/JavaScriptCore/runtime/IntlObjectInlines.h @@ -203,7 +203,7 @@ ALWAYS_INLINE bool canUseASCIIUCADUCETComparison(char16_t character) return isASCII(character) && ducetLevel1Weights[character]; } -ALWAYS_INLINE bool canUseASCIIUCADUCETComparison(LChar character) +ALWAYS_INLINE bool canUseASCIIUCADUCETComparison(Latin1Character character) { return ducetLevel1Weights[character]; } @@ -216,7 +216,7 @@ ALWAYS_INLINE bool followedByNonLatinCharacter(std::span charact return false; } -ALWAYS_INLINE bool followedByNonLatinCharacter(std::span, size_t) +ALWAYS_INLINE bool followedByNonLatinCharacter(std::span, size_t) { return false; } diff --git a/Source/JavaScriptCore/runtime/JSBigInt.cpp b/Source/JavaScriptCore/runtime/JSBigInt.cpp index ac791318eff86..4e88511314ba9 100644 --- a/Source/JavaScriptCore/runtime/JSBigInt.cpp +++ b/Source/JavaScriptCore/runtime/JSBigInt.cpp @@ -2273,7 +2273,7 @@ String JSBigInt::toStringBasePowerOfTwo(VM& vm, JSGlobalObject* nullOrGlobalObje return String(); } - Vector resultString(charsRequired); + Vector resultString(charsRequired); Digit digit = 0; // Keeps track of how many unprocessed bits there are in {digit}. unsigned availableBits = 0; @@ -2312,7 +2312,7 @@ String JSBigInt::toStringGeneric(VM& vm, JSGlobalObject* nullOrGlobalObjectForOO { // FIXME: [JSC] Revisit usage of Vector into JSBigInt::toString // https://bugs.webkit.org/show_bug.cgi?id=180671 - Vector resultString; + Vector resultString; ASSERT(radix >= 2 && radix <= 36); ASSERT(!x->isZero()); diff --git a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.cpp b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.cpp index ec9576fc57e34..2e3a8857df684 100644 --- a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.cpp +++ b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.cpp @@ -199,7 +199,7 @@ inline static WARN_UNUSED_RETURN size_t decodeHexImpl(std::span s return WTF::notFound; } -WARN_UNUSED_RETURN size_t decodeHex(std::span span, std::span result) +WARN_UNUSED_RETURN size_t decodeHex(std::span span, std::span result) { return decodeHexImpl(span, result); } diff --git a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.h b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.h index b1ee6c4c0be4b..4d04dc54471f1 100644 --- a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.h +++ b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructor.h @@ -150,7 +150,7 @@ class JSGenericTypedArrayViewConstructor final : public InternalFunction { JSC_DECLARE_HOST_FUNCTION(uint8ArrayConstructorFromBase64); JSC_DECLARE_HOST_FUNCTION(uint8ArrayConstructorFromHex); -WARN_UNUSED_RETURN size_t decodeHex(std::span, std::span result); +WARN_UNUSED_RETURN size_t decodeHex(std::span, std::span result); WARN_UNUSED_RETURN size_t decodeHex(std::span, std::span result); } // namespace JSC diff --git a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototype.cpp b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototype.cpp index 8f0f14c3a4f2d..b6f526ac03183 100644 --- a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototype.cpp +++ b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototype.cpp @@ -231,9 +231,9 @@ JSC_DEFINE_HOST_FUNCTION(uint8ArrayPrototypeToHex, (JSGlobalObject* globalObject return { }; } - std::span buffer; + std::span buffer; auto result = StringImpl::createUninitialized(length * 2, buffer); - LChar* bufferEnd = std::to_address(buffer.end()); + Latin1Character* bufferEnd = std::to_address(buffer.end()); constexpr size_t stride = 8; // Because loading uint8x8_t. if (length >= stride) { auto encodeVector = [&](auto input) { diff --git a/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp b/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp index ded357f472781..162cf03e9cbef 100644 --- a/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp +++ b/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp @@ -91,7 +91,7 @@ static JSValue encode(JSGlobalObject* globalObject, const WTF::BitSet<256>& doNo if (character < doNotEscape.size() && doNotEscape.get(character)) { // 4-c-i. Let S be a String containing only the code unit C. // 4-c-ii. Let R be a new String value computed by concatenating the previous value of R and S. - builder.append(static_cast(character)); + builder.append(static_cast(character)); continue; } @@ -125,7 +125,7 @@ static JSValue encode(JSGlobalObject* globalObject, const WTF::BitSet<256>& doNo } // 4-d-iv. Let Octets be the array of octets resulting by applying the UTF-8 transformation to V, and let L be the array size. - LChar utf8OctetsBuffer[U8_MAX_LENGTH]; + Latin1Character utf8OctetsBuffer[U8_MAX_LENGTH]; unsigned utf8Length = 0; // We can use U8_APPEND_UNSAFE here since codePoint is either // 1. non surrogate one, correct code point. @@ -218,7 +218,7 @@ static JSValue decode(JSGlobalObject* globalObject, std::span ch u = Lexer::convertUnicode(p[2], p[3], p[4], p[5]); } } - if (charLen && (u >= 128 || !doNotUnescape.get(static_cast(u)))) { + if (charLen && (u >= 128 || !doNotUnescape.get(static_cast(u)))) { builder.append(u); k += charLen; continue; @@ -506,7 +506,7 @@ JSC_DEFINE_HOST_FUNCTION(globalFuncEval, (JSGlobalObject* globalObject, CallFram JSValue parsedObject; if (programSource.is8Bit()) { - LiteralParser preparser(globalObject, programSource.span8(), SloppyJSON, nullptr); + LiteralParser preparser(globalObject, programSource.span8(), SloppyJSON, nullptr); parsedObject = preparser.tryLiteralParse(); } else { LiteralParser preparser(globalObject, programSource.span16(), SloppyJSON, nullptr); @@ -630,7 +630,7 @@ JSC_DEFINE_HOST_FUNCTION(globalFuncEscape, (JSGlobalObject* globalObject, CallFr for (auto character : view.span16()) { if (character >= doNotEscape.size()) builder.append("%u"_s, hex(static_cast(character >> 8), 2), hex(static_cast(character), 2)); - else if (doNotEscape.get(static_cast(character))) + else if (doNotEscape.get(static_cast(character))) builder.append(character); else builder.append('%', hex(character, 2)); @@ -661,7 +661,7 @@ JSC_DEFINE_HOST_FUNCTION(globalFuncUnescape, (JSGlobalObject* globalObject, Call if (view.is8Bit()) { auto characters = view.span8(); - LChar convertedLChar; + Latin1Character convertedLChar; while (k < length) { auto c = characters.subspan(k); if (c[0] == '%' && k <= length - 6 && c[1] == 'u') { @@ -671,7 +671,7 @@ JSC_DEFINE_HOST_FUNCTION(globalFuncUnescape, (JSGlobalObject* globalObject, Call continue; } } else if (c[0] == '%' && k <= length - 3 && isASCIIHexDigit(c[1]) && isASCIIHexDigit(c[2])) { - convertedLChar = LChar(Lexer::convertHex(c[1], c[2])); + convertedLChar = Latin1Character(Lexer::convertHex(c[1], c[2])); c = span(convertedLChar); k += 2; } diff --git a/Source/JavaScriptCore/runtime/JSONObject.cpp b/Source/JavaScriptCore/runtime/JSONObject.cpp index c1b2f8fb28ef1..798e0957fb17b 100644 --- a/Source/JavaScriptCore/runtime/JSONObject.cpp +++ b/Source/JavaScriptCore/runtime/JSONObject.cpp @@ -829,7 +829,7 @@ inline unsigned FastStringifier::usableBufferSize(unsigned // to limit recursion. Hence, we need to compute an appropriate m_capacity value. // // To do this, we empirically measured the worst case stack usage incurred by 1 recursion - // of any of the append methods. Assuming each call to append() only consumes 1 LChar in + // of any of the append methods. Assuming each call to append() only consumes 1 Latin1Character in // m_buffer, the amount of buffer size that FastStringifier is allowed to run with can be // estimated as: // @@ -1128,12 +1128,12 @@ static ALWAYS_INLINE bool stringCopySameType(std::span span, Cha return false; } -static ALWAYS_INLINE bool stringCopyUpconvert(std::span span, char16_t* cursor) +static ALWAYS_INLINE bool stringCopyUpconvert(std::span span, char16_t* cursor) { #if (CPU(ARM64) || CPU(X86_64)) && COMPILER(CLANG) - constexpr size_t stride = SIMD::stride; + constexpr size_t stride = SIMD::stride; if (span.size() >= stride) { - using UnsignedType = std::make_unsigned_t; + using UnsignedType = std::make_unsigned_t; using BulkType = decltype(SIMD::load(static_cast(nullptr))); constexpr auto quoteMask = SIMD::splat('"'); constexpr auto escapeMask = SIMD::splat('\\'); @@ -1490,7 +1490,7 @@ static NEVER_INLINE String stringify(JSGlobalObject& globalObject, JSValue value if (LIKELY(std::bit_cast(currentStackPointer()) >= stackLimit)) { std::optional failureReason; failureReason = std::nullopt; - if (String result = FastStringifier::stringify(globalObject, value, replacer, space, failureReason); !result.isNull()) + if (String result = FastStringifier::stringify(globalObject, value, replacer, space, failureReason); !result.isNull()) return result; if (failureReason == FailureReason::Found16BitEarly) { failureReason = std::nullopt; @@ -1504,7 +1504,7 @@ static NEVER_INLINE String stringify(JSGlobalObject& globalObject, JSValue value } } else if (failureReason == FailureReason::BufferFull) { failureReason = std::nullopt; - if (String result = FastStringifier::stringify(globalObject, value, replacer, space, failureReason); !result.isNull()) + if (String result = FastStringifier::stringify(globalObject, value, replacer, space, failureReason); !result.isNull()) return result; } } @@ -1812,7 +1812,7 @@ static NEVER_INLINE JSValue jsonParseSlow(JSGlobalObject* globalObject, JSString JSONRanges ranges; JSValue unfiltered; if (view.is8Bit()) { - LiteralParser jsonParser(globalObject, view.span8(), StrictJSON); + LiteralParser jsonParser(globalObject, view.span8(), StrictJSON); unfiltered = jsonParser.tryLiteralParse(Options::useJSONSourceTextAccess() ? &ranges : nullptr); EXCEPTION_ASSERT(!scope.exception() || !unfiltered); if (!unfiltered) { @@ -1854,7 +1854,7 @@ JSC_DEFINE_HOST_FUNCTION(jsonProtoFuncParse, (JSGlobalObject* globalObject, Call } if (view->is8Bit()) { - LiteralParser jsonParser(globalObject, view->span8(), StrictJSON); + LiteralParser jsonParser(globalObject, view->span8(), StrictJSON); JSValue unfiltered = jsonParser.tryLiteralParse(); EXCEPTION_ASSERT(!scope.exception() || !unfiltered); if (!unfiltered) { @@ -1887,7 +1887,7 @@ JSValue JSONParse(JSGlobalObject* globalObject, StringView json) return JSValue(); if (json.is8Bit()) { - LiteralParser jsonParser(globalObject, json.span8(), StrictJSON); + LiteralParser jsonParser(globalObject, json.span8(), StrictJSON); return jsonParser.tryLiteralParse(); } @@ -1904,7 +1904,7 @@ JSValue JSONParseWithException(JSGlobalObject* globalObject, StringView json) return JSValue(); if (json.is8Bit()) { - LiteralParser jsonParser(globalObject, json.span8(), StrictJSON); + LiteralParser jsonParser(globalObject, json.span8(), StrictJSON); JSValue result = jsonParser.tryLiteralParse(); RETURN_IF_EXCEPTION(scope, { }); if (!result) @@ -1972,7 +1972,7 @@ JSC_DEFINE_HOST_FUNCTION(jsonProtoFuncRawJSON, (JSGlobalObject* globalObject, Ca { JSValue result; if (string.is8Bit()) { - LiteralParser jsonParser(globalObject, string.span8(), StrictJSON); + LiteralParser jsonParser(globalObject, string.span8(), StrictJSON); result = jsonParser.tryLiteralParsePrimitiveValue(); RETURN_IF_EXCEPTION(scope, { }); if (UNLIKELY(!result)) { diff --git a/Source/JavaScriptCore/runtime/JSString.cpp b/Source/JavaScriptCore/runtime/JSString.cpp index 243e99a29f61b..85c7f08bb6a52 100644 --- a/Source/JavaScriptCore/runtime/JSString.cpp +++ b/Source/JavaScriptCore/runtime/JSString.cpp @@ -169,9 +169,9 @@ AtomString JSRopeString::resolveRopeToAtomString(JSGlobalObject* globalObject) c uint8_t* stackLimit = std::bit_cast(vm.softStackLimit()); if (!isSubstring()) { if (is8Bit()) { - std::array buffer; + std::array buffer; resolveRopeInternalNoSubstring(std::span { buffer }.first(length()), stackLimit); - atomString = std::span { buffer }.first(length()); + atomString = std::span { buffer }.first(length()); } else { std::array buffer; resolveRopeInternalNoSubstring(std::span { buffer }.first(length()), stackLimit); @@ -209,7 +209,7 @@ RefPtr JSRopeString::resolveRopeToExistingAtomString(JSGlobalObj if (!isSubstring()) { uint8_t* stackLimit = std::bit_cast(vm.softStackLimit()); if (is8Bit()) { - std::array buffer; + std::array buffer; resolveRopeInternalNoSubstring(std::span { buffer }.first(length()), stackLimit); existingAtomString = AtomStringImpl::lookUp(std::span { buffer }.first(length())); } else { @@ -239,7 +239,7 @@ const String& JSRopeString::resolveRopeWithFunction(JSGlobalObject* nullOrGlobal } if (is8Bit()) { - std::span buffer; + std::span buffer; auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer); if (!newImpl) { outOfMemory(nullOrGlobalObjectForOOM); diff --git a/Source/JavaScriptCore/runtime/JSString.h b/Source/JavaScriptCore/runtime/JSString.h index aef28273720d3..b11eba876594d 100644 --- a/Source/JavaScriptCore/runtime/JSString.h +++ b/Source/JavaScriptCore/runtime/JSString.h @@ -61,7 +61,7 @@ JSString* jsString(VM&, Ref&&); JSString* jsString(VM&, Ref&&); JSString* jsSingleCharacterString(VM&, char16_t); -JSString* jsSingleCharacterString(VM&, LChar); +JSString* jsSingleCharacterString(VM&, Latin1Character); JSString* jsSubstring(VM&, const String&, unsigned offset, unsigned length); // Non-trivial strings are two or more characters long. @@ -303,7 +303,7 @@ class JSString : public JSCell { friend JSString* jsString(JSGlobalObject*, const String&, const String&, const String&); friend JS_EXPORT_PRIVATE JSString* jsStringWithCacheSlowCase(VM&, StringImpl&); friend JSString* jsSingleCharacterString(VM&, char16_t); - friend JSString* jsSingleCharacterString(VM&, LChar); + friend JSString* jsSingleCharacterString(VM&, Latin1Character); friend JSString* jsNontrivialString(VM&, const String&); friend JSString* jsNontrivialString(VM&, String&&); friend JSString* jsSubstring(VM&, const String&, unsigned, unsigned); @@ -800,7 +800,7 @@ ALWAYS_INLINE JSString* jsSingleCharacterString(VM& vm, char16_t c) return JSString::create(vm, StringImpl::create(std::span { &c, 1 })); } -ALWAYS_INLINE JSString* jsSingleCharacterString(VM& vm, LChar c) +ALWAYS_INLINE JSString* jsSingleCharacterString(VM& vm, Latin1Character c) { if constexpr (validateDFGDoesGC) vm.verifyCanGC(); diff --git a/Source/JavaScriptCore/runtime/JSStringInlines.h b/Source/JavaScriptCore/runtime/JSStringInlines.h index a13750c3f7cf3..5a9824745a03c 100644 --- a/Source/JavaScriptCore/runtime/JSStringInlines.h +++ b/Source/JavaScriptCore/runtime/JSStringInlines.h @@ -409,7 +409,7 @@ inline JSString* jsAtomString(JSGlobalObject* globalObject, VM& vm, JSString* st }; if (string->valueInternal().is8Bit()) { - WTF::HashTranslatorCharBuffer buffer { string->valueInternal().span8(), string->valueInternal().hash() }; + WTF::HashTranslatorCharBuffer buffer { string->valueInternal().span8(), string->valueInternal().hash() }; return vm.keyAtomStringCache.make(vm, buffer, createFromNonRope); } @@ -434,9 +434,9 @@ inline JSString* jsAtomString(JSGlobalObject* globalObject, VM& vm, JSString* st JSString* fiber1 = ropeString->fiber1(); JSString* fiber2 = ropeString->fiber2(); if (ropeString->is8Bit()) { - std::array characters; + std::array characters; JSRopeString::resolveToBuffer(fiber0, fiber1, fiber2, std::span { characters }.first(length), stackLimit); - WTF::HashTranslatorCharBuffer buffer { std::span { characters }.first(length) }; + WTF::HashTranslatorCharBuffer buffer { std::span { characters }.first(length) }; return vm.keyAtomStringCache.make(vm, buffer, createFromRope); } std::array characters; @@ -447,7 +447,7 @@ inline JSString* jsAtomString(JSGlobalObject* globalObject, VM& vm, JSString* st auto view = StringView { ropeString->substringBase()->valueInternal() }.substring(ropeString->substringOffset(), length); if (view.is8Bit()) { - WTF::HashTranslatorCharBuffer buffer { view.span8() }; + WTF::HashTranslatorCharBuffer buffer { view.span8() }; return vm.keyAtomStringCache.make(vm, buffer, createFromRope); } WTF::HashTranslatorCharBuffer buffer { view.span16() }; @@ -523,9 +523,9 @@ inline JSString* jsAtomString(JSGlobalObject* globalObject, VM& vm, JSString* s1 }; if (s1->is8Bit() && s2->is8Bit()) { - LChar characters[KeyAtomStringCache::maxStringLengthForCache]; + Latin1Character characters[KeyAtomStringCache::maxStringLengthForCache]; resolveWith2Fibers(s1, s2, std::span { characters }.first(length)); - WTF::HashTranslatorCharBuffer buffer { std::span(characters).first(length) }; + WTF::HashTranslatorCharBuffer buffer { std::span(characters).first(length) }; return vm.keyAtomStringCache.make(vm, buffer, createFromFibers); } char16_t characters[KeyAtomStringCache::maxStringLengthForCache]; @@ -582,9 +582,9 @@ inline JSString* jsAtomString(JSGlobalObject* globalObject, VM& vm, JSString* s1 }; if (s1->is8Bit() && s2->is8Bit() && s3->is8Bit()) { - LChar characters[KeyAtomStringCache::maxStringLengthForCache]; + Latin1Character characters[KeyAtomStringCache::maxStringLengthForCache]; resolveWith3Fibers(s1, s2, s3, std::span { characters }.first(length)); - WTF::HashTranslatorCharBuffer buffer { std::span { characters }.first(length) }; + WTF::HashTranslatorCharBuffer buffer { std::span { characters }.first(length) }; return vm.keyAtomStringCache.make(vm, buffer, createFromFibers); } char16_t characters[KeyAtomStringCache::maxStringLengthForCache]; @@ -625,8 +625,8 @@ inline JSString* jsSubstringOfResolved(VM& vm, GCDeferralContext* deferralContex auto impl = AtomStringImpl::add(buffer); return JSString::create(vm, deferralContext, impl.releaseNonNull()); }; - LChar buf[] = { static_cast(first), static_cast(second) }; - WTF::HashTranslatorCharBuffer buffer { std::span { buf, length } }; + Latin1Character buf[] = { static_cast(first), static_cast(second) }; + WTF::HashTranslatorCharBuffer buffer { std::span { buf, length } }; return vm.keyAtomStringCache.make(vm, buffer, createFromSubstring); } } diff --git a/Source/JavaScriptCore/runtime/JSStringJoiner.cpp b/Source/JavaScriptCore/runtime/JSStringJoiner.cpp index d64f12d3fa2b9..a3b373a308c03 100644 --- a/Source/JavaScriptCore/runtime/JSStringJoiner.cpp +++ b/Source/JavaScriptCore/runtime/JSStringJoiner.cpp @@ -38,7 +38,7 @@ JSStringJoiner::~JSStringJoiner() = default; template static inline void appendStringToData(std::span& data, StringView string) { - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { ASSERT(string.is8Bit()); string.getCharacters8(data); } else @@ -57,12 +57,12 @@ template static inline void appendStringToDataWithOneCharacterSeparatorRepeatedly(std::span& data, char16_t separatorCharacter, StringView string, unsigned count) { #if OS(DARWIN) - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { ASSERT(string.is8Bit()); if (count > 4) { switch (string.length() + 1) { case 16: { - alignas(16) LChar pattern[16]; + alignas(16) Latin1Character pattern[16]; pattern[0] = separatorCharacter; string.getCharacters8(std::span { pattern }.subspan(1)); size_t fillLength = count * 16; @@ -71,7 +71,7 @@ static inline void appendStringToDataWithOneCharacterSeparatorRepeatedly(std::sp return; } case 8: { - alignas(8) LChar pattern[8]; + alignas(8) Latin1Character pattern[8]; pattern[0] = separatorCharacter; string.getCharacters8(std::span { pattern }.subspan(1)); size_t fillLength = count * 8; @@ -80,7 +80,7 @@ static inline void appendStringToDataWithOneCharacterSeparatorRepeatedly(std::sp return; } case 4: { - alignas(4) LChar pattern[4]; + alignas(4) Latin1Character pattern[4]; pattern[0] = separatorCharacter; string.getCharacters8(std::span { pattern }.subspan(1)); size_t fillLength = count * 4; @@ -202,7 +202,7 @@ JSValue JSStringJoiner::joinSlow(JSGlobalObject* globalObject) String result; if (m_isAll8Bit) - result = joinStrings(m_strings, m_separator.span8(), length); + result = joinStrings(m_strings, m_separator.span8(), length); else { if (m_separator.is8Bit()) result = joinStrings(m_strings, m_separator.span8(), length); diff --git a/Source/JavaScriptCore/runtime/LiteralParser.cpp b/Source/JavaScriptCore/runtime/LiteralParser.cpp index 71f6a38de25d6..15298a51b0568 100644 --- a/Source/JavaScriptCore/runtime/LiteralParser.cpp +++ b/Source/JavaScriptCore/runtime/LiteralParser.cpp @@ -170,7 +170,7 @@ ALWAYS_INLINE JSString* LiteralParser::makeJSString(VM& v return jsString(vm, Identifier::fromString(vm, token->string16()).string()); } -[[maybe_unused]] static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(LChar) +[[maybe_unused]] static ALWAYS_INLINE bool cannotBeIdentPartOrEscapeStart(Latin1Character) { RELEASE_ASSERT_NOT_REACHED(); } @@ -857,7 +857,7 @@ ALWAYS_INLINE TokenType LiteralParser::Lexer::nextMaybeId } template <> -ALWAYS_INLINE void setParserTokenString(LiteralParserToken& token, const LChar* string) +ALWAYS_INLINE void setParserTokenString(LiteralParserToken& token, const Latin1Character* string) { token.stringIs8Bit = 1; token.stringStart8 = string; @@ -873,7 +873,7 @@ ALWAYS_INLINE void setParserTokenString(LiteralParserToken& enum class SafeStringCharacterSet { Strict, Sloppy }; template -static ALWAYS_INLINE bool isSafeStringCharacter(LChar c, LChar terminator) +static ALWAYS_INLINE bool isSafeStringCharacter(Latin1Character c, Latin1Character terminator) { if constexpr (set == SafeStringCharacterSet::Strict) return safeStringLatin1CharactersInStrictJSON[c]; @@ -887,7 +887,7 @@ static ALWAYS_INLINE bool isSafeStringCharacter(char16_t c, char16_t terminator) if constexpr (set == SafeStringCharacterSet::Strict) { if (!isLatin1(c)) return true; - return isSafeStringCharacter(static_cast(c), static_cast(terminator)); + return isSafeStringCharacter(static_cast(c), static_cast(terminator)); } else return (c >= ' ' && isLatin1(c) && c != '\\' && c != terminator) || (c == '\t'); } @@ -896,7 +896,7 @@ template static ALWAYS_INLINE bool isSafeStringCharacterForIdentifier(char16_t c, char16_t terminator) { if constexpr (set == SafeStringCharacterSet::Strict) - return isSafeStringCharacter(static_cast(c), static_cast(terminator)) || !isLatin1(c); + return isSafeStringCharacter(static_cast(c), static_cast(terminator)) || !isLatin1(c); else return (c >= ' ' && isLatin1(c) && c != '\\' && c != terminator) || (c == '\t'); } @@ -1780,9 +1780,9 @@ JSValue LiteralParser::parse(VM& vm, ParserState initialS } // Instantiate the two flavors of LiteralParser we need instead of putting most of this file in LiteralParser.h -template class LiteralParser; +template class LiteralParser; template class LiteralParser; -template class LiteralParser; +template class LiteralParser; template class LiteralParser; } diff --git a/Source/JavaScriptCore/runtime/LiteralParser.h b/Source/JavaScriptCore/runtime/LiteralParser.h index aebaa8b74a803..752c22bcde8cd 100644 --- a/Source/JavaScriptCore/runtime/LiteralParser.h +++ b/Source/JavaScriptCore/runtime/LiteralParser.h @@ -117,12 +117,12 @@ template struct LiteralParserToken { union { double numberToken; // Only used for TokNumber. const CharacterType* identifierStart; - const LChar* stringStart8; + const Latin1Character* stringStart8; const char16_t* stringStart16; }; std::span identifier() const { return { identifierStart, stringOrIdentifierLength }; } - std::span string8() const { return { stringStart8, stringOrIdentifierLength }; } + std::span string8() const { return { stringStart8, stringOrIdentifierLength }; } std::span string16() const { return { stringStart16, stringOrIdentifierLength }; } }; diff --git a/Source/JavaScriptCore/runtime/NumberPrototype.cpp b/Source/JavaScriptCore/runtime/NumberPrototype.cpp index 46505611bb9c0..2cfa53f5b31fc 100644 --- a/Source/JavaScriptCore/runtime/NumberPrototype.cpp +++ b/Source/JavaScriptCore/runtime/NumberPrototype.cpp @@ -342,9 +342,9 @@ static char* toStringWithRadixInternal(RadixBuffer& buffer, double originalNumbe static String toStringWithRadixInternal(int32_t number, unsigned radix) { - LChar buf[1 + 32]; // Worst case is radix == 2, which gives us 32 digits + sign. - LChar* end = std::end(buf); - LChar* p = end; + Latin1Character buf[1 + 32]; // Worst case is radix == 2, which gives us 32 digits + sign. + Latin1Character* end = std::end(buf); + Latin1Character* p = end; bool negative = false; uint32_t positiveNumber = number; diff --git a/Source/JavaScriptCore/runtime/Operations.h b/Source/JavaScriptCore/runtime/Operations.h index cb448cb9cc304..89f41e98821ea 100644 --- a/Source/JavaScriptCore/runtime/Operations.h +++ b/Source/JavaScriptCore/runtime/Operations.h @@ -100,7 +100,7 @@ ALWAYS_INLINE JSString* jsString(JSGlobalObject* globalObject, const String& u1, // We do not account u1 cost in (2) since u1 may be shared StringImpl, and it may not introduce additional cost. // We conservatively consider the cost of u1. Currently, we are not considering about is8Bit() case because 16-bit // strings are relatively rare. But we can do that if we need to consider it. - if (s2->isRope() || (StringImpl::headerSize() + length1 + length2) >= sizeof(JSRopeString)) + if (s2->isRope() || (StringImpl::headerSize() + length1 + length2) >= sizeof(JSRopeString)) return JSRopeString::create(vm, jsString(vm, u1), s2); ASSERT(!s2->isRope()); @@ -133,7 +133,7 @@ ALWAYS_INLINE JSString* jsString(JSGlobalObject* globalObject, JSString* s1, con // (1) Cost of making JSString : sizeof(JSString) (for new string) + sizeof(StringImpl header) + length1 + length2 // (2) Cost of making JSRopeString: sizeof(JSString) (for u2) + sizeof(JSRopeString) - if (s1->isRope() || (StringImpl::headerSize() + length1 + length2) >= sizeof(JSRopeString)) + if (s1->isRope() || (StringImpl::headerSize() + length1 + length2) >= sizeof(JSRopeString)) return JSRopeString::create(vm, s1, jsString(vm, u2)); ASSERT(!s1->isRope()); @@ -212,7 +212,7 @@ ALWAYS_INLINE JSString* jsString(JSGlobalObject* globalObject, const String& u1, // (1) Cost of making JSString : sizeof(JSString) (for new string) + sizeof(StringImpl header) + length1 + length2 // (2) Cost of making JSRopeString: sizeof(JSString) (for u1) + sizeof(JSString) (for u2) + sizeof(JSRopeString) - if ((StringImpl::headerSize() + length1 + length2) >= (sizeof(JSRopeString) + sizeof(JSString))) + if ((StringImpl::headerSize() + length1 + length2) >= (sizeof(JSRopeString) + sizeof(JSString))) return JSRopeString::create(vm, jsString(vm, u1), jsString(vm, u2)); String newString = tryMakeString(u1, u2); @@ -252,7 +252,7 @@ ALWAYS_INLINE JSString* jsString(JSGlobalObject* globalObject, const String& u1, // (1) Cost of making JSString : sizeof(JSString) (for new string) + sizeof(StringImpl header) + length1 + length2 + length3 // (2) Cost of making JSRopeString: sizeof(JSString) (for u1) + sizeof(JSString) (for u2) + sizeof(JSString) (for u3) + sizeof(JSRopeString) - if ((StringImpl::headerSize() + length1 + length2 + length3) >= (sizeof(JSRopeString) + sizeof(JSString) * 2)) + if ((StringImpl::headerSize() + length1 + length2 + length3) >= (sizeof(JSRopeString) + sizeof(JSString) * 2)) return JSRopeString::create(vm, jsString(vm, u1), jsString(vm, u2), jsString(vm, u3)); String newString = tryMakeString(u1, u2, u3); diff --git a/Source/JavaScriptCore/runtime/ParseInt.h b/Source/JavaScriptCore/runtime/ParseInt.h index ba6e3171706a2..10da42bec0f83 100644 --- a/Source/JavaScriptCore/runtime/ParseInt.h +++ b/Source/JavaScriptCore/runtime/ParseInt.h @@ -51,12 +51,12 @@ ALWAYS_INLINE static int parseDigit(unsigned short c, int radix) return digit; } -static double parseIntOverflow(std::span s, int radix) +static double parseIntOverflow(std::span s, int radix) { double number = 0.0; double radixMultiplier = 1.0; - for (const LChar* p = s.data() + s.size() - 1; p >= s.data(); p--) { + for (const Latin1Character* p = s.data() + s.size() - 1; p >= s.data(); p--) { if (radixMultiplier == std::numeric_limits::infinity()) { if (*p != '0') { number = std::numeric_limits::infinity(); @@ -100,7 +100,7 @@ ALWAYS_INLINE static bool isStrWhiteSpace(CharacterType c) { // https://tc39.github.io/ecma262/#sec-tonumber-applied-to-the-string-type if constexpr (sizeof(c) == 1) - return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); + return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); return Lexer::isWhiteSpace(c) || Lexer::isLineTerminator(c); } diff --git a/Source/JavaScriptCore/runtime/PropertyName.h b/Source/JavaScriptCore/runtime/PropertyName.h index 833ed99da283f..a40e2022de809 100644 --- a/Source/JavaScriptCore/runtime/PropertyName.h +++ b/Source/JavaScriptCore/runtime/PropertyName.h @@ -167,7 +167,7 @@ ALWAYS_INLINE bool isCanonicalNumericIndexString(UniquedStringImpl* propertyName double index = jsToNumber(propertyName); NumberToStringBuffer buffer; auto span = WTF::numberToStringAndSize(index, buffer); - return equal(propertyName, byteCast(span)); + return equal(propertyName, byteCast(span)); } } // namespace JSC diff --git a/Source/JavaScriptCore/runtime/RegExp.cpp b/Source/JavaScriptCore/runtime/RegExp.cpp index 978c9de69b458..b418e3fa804a5 100644 --- a/Source/JavaScriptCore/runtime/RegExp.cpp +++ b/Source/JavaScriptCore/runtime/RegExp.cpp @@ -574,7 +574,7 @@ template static inline void appendLineTerminatorEscape(StringBuilder&, CharacterType); template <> -inline void appendLineTerminatorEscape(StringBuilder& builder, LChar lineTerminator) +inline void appendLineTerminatorEscape(StringBuilder& builder, Latin1Character lineTerminator) { if (lineTerminator == '\n') builder.append('n'); diff --git a/Source/JavaScriptCore/runtime/SmallStrings.cpp b/Source/JavaScriptCore/runtime/SmallStrings.cpp index 7ec76a9741531..830260eca89ab 100644 --- a/Source/JavaScriptCore/runtime/SmallStrings.cpp +++ b/Source/JavaScriptCore/runtime/SmallStrings.cpp @@ -49,7 +49,7 @@ void SmallStrings::initializeCommonStrings(VM& vm) for (unsigned i = 0; i < singleCharacterStringCount; ++i) { ASSERT(!m_singleCharacterStrings[i]); - std::array string = { static_cast(i) }; + std::array string = { static_cast(i) }; m_singleCharacterStrings[i] = JSString::createHasOtherOwner(vm, AtomStringImpl::add(string).releaseNonNull()); ASSERT(m_needsToBeVisited); } @@ -118,7 +118,7 @@ Ref SmallStrings::singleCharacterStringRep(unsigned char charact { if (LIKELY(m_isInitialized)) return *static_cast(const_cast(m_singleCharacterStrings[character]->tryGetValueImpl())); - std::array string = { static_cast(character) }; + std::array string = { static_cast(character) }; return AtomStringImpl::add(string).releaseNonNull(); } diff --git a/Source/JavaScriptCore/runtime/StringConstructor.cpp b/Source/JavaScriptCore/runtime/StringConstructor.cpp index 4d13d056c13c8..ffc9537fec0d2 100644 --- a/Source/JavaScriptCore/runtime/StringConstructor.cpp +++ b/Source/JavaScriptCore/runtime/StringConstructor.cpp @@ -89,7 +89,7 @@ JSC_DEFINE_HOST_FUNCTION(stringFromCharCode, (JSGlobalObject* globalObject, Call return JSValue::encode(jsSingleCharacterString(vm, code)); } - std::span buf8Bit; + std::span buf8Bit; auto impl8Bit = StringImpl::createUninitialized(length, buf8Bit); for (unsigned i = 0; i < length; ++i) { char16_t character = static_cast(callFrame->uncheckedArgument(i).toUInt32(globalObject)); @@ -106,7 +106,7 @@ JSC_DEFINE_HOST_FUNCTION(stringFromCharCode, (JSGlobalObject* globalObject, Call } RELEASE_AND_RETURN(scope, JSValue::encode(jsString(vm, WTFMove(impl16Bit)))); } - buf8Bit[i] = static_cast(character); + buf8Bit[i] = static_cast(character); } RELEASE_AND_RETURN(scope, JSValue::encode(jsString(vm, WTFMove(impl8Bit)))); } diff --git a/Source/JavaScriptCore/runtime/StringPrototype.cpp b/Source/JavaScriptCore/runtime/StringPrototype.cpp index 6f66ec9381255..6e018cbdbce0a 100644 --- a/Source/JavaScriptCore/runtime/StringPrototype.cpp +++ b/Source/JavaScriptCore/runtime/StringPrototype.cpp @@ -310,7 +310,7 @@ static ALWAYS_INLINE JSString* jsSpliceSubstrings(JSGlobalObject* globalObject, return jsEmptyString(vm); if (source.is8Bit()) { - std::span buffer; + std::span buffer; auto sourceData = source.span8(); auto impl = StringImpl::tryCreateUninitialized(totalLength, buffer); if (!impl) { @@ -328,7 +328,7 @@ static ALWAYS_INLINE JSString* jsSpliceSubstrings(JSGlobalObject* globalObject, RELEASE_AND_RETURN(scope, jsString(vm, impl.releaseNonNull())); } - std::span buffer; + std::span buffer; auto sourceData = source.span16(); auto impl = StringImpl::tryCreateUninitialized(totalLength, buffer); @@ -943,7 +943,7 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncRepeatCharacter, (JSGlobalObject* global char16_t character = view[0]; scope.release(); if (isLatin1(character)) - return JSValue::encode(repeatCharacter(globalObject, static_cast(character), repeatCount)); + return JSValue::encode(repeatCharacter(globalObject, static_cast(character), repeatCount)); return JSValue::encode(repeatCharacter(globalObject, character, repeatCount)); } @@ -1461,7 +1461,7 @@ JSC_DEFINE_HOST_FUNCTION(stringProtoFuncSplitFast, (JSGlobalObject* globalObject if (separatorLength == 1) { char16_t separatorCharacter = separatorImpl->at(0); if (stringImpl->is8Bit()) { - if (splitStringByOneCharacterImpl(result, stringImpl, separatorCharacter, limit)) + if (splitStringByOneCharacterImpl(result, stringImpl, separatorCharacter, limit)) RELEASE_AND_RETURN(scope, JSValue::encode(cacheAndCreateArray())); } else { if (splitStringByOneCharacterImpl(result, stringImpl, separatorCharacter, limit)) diff --git a/Source/JavaScriptCore/runtime/StringPrototypeInlines.h b/Source/JavaScriptCore/runtime/StringPrototypeInlines.h index 2ba58ded04581..06dfca03ef5ab 100644 --- a/Source/JavaScriptCore/runtime/StringPrototypeInlines.h +++ b/Source/JavaScriptCore/runtime/StringPrototypeInlines.h @@ -145,7 +145,7 @@ ALWAYS_INLINE JSString* jsSpliceSubstringsWithSeparators(JSGlobalObject* globalO return jsEmptyString(vm); if (source.is8Bit() && allSeparators8Bit) { - std::span buffer; + std::span buffer; auto impl = StringImpl::tryCreateUninitialized(totalLength, buffer); if (!impl) { throwOutOfMemoryError(globalObject, scope); diff --git a/Source/JavaScriptCore/yarr/YarrCanonicalizeUCS2.js b/Source/JavaScriptCore/yarr/YarrCanonicalizeUCS2.js index 9eac46f58285e..3b365212dc813 100644 --- a/Source/JavaScriptCore/yarr/YarrCanonicalizeUCS2.js +++ b/Source/JavaScriptCore/yarr/YarrCanonicalizeUCS2.js @@ -183,8 +183,8 @@ function createTables(prefix, maxValue, canonicalGroups) } print("};"); print(); - // Create canonical table for LChar domain - let line = "const uint16_t canonicalTableLChar[256] = {"; + // Create canonical table for Latin1Character domain + let line = "const uint16_t canonicalTableLatin1Character[256] = {"; for (let i = 0; i < 256; i++) { if (!(i % 16)) { print(line); diff --git a/Source/JavaScriptCore/yarr/YarrInterpreter.cpp b/Source/JavaScriptCore/yarr/YarrInterpreter.cpp index aaf27442eb26a..8b935df6c2ff8 100644 --- a/Source/JavaScriptCore/yarr/YarrInterpreter.cpp +++ b/Source/JavaScriptCore/yarr/YarrInterpreter.cpp @@ -3174,14 +3174,14 @@ unsigned interpret(BytecodePattern* bytecode, StringView input, unsigned start, { SuperSamplerScope superSamplerScope(false); if (input.is8Bit()) - return Interpreter(bytecode, output, input.span8(), start).interpret(); + return Interpreter(bytecode, output, input.span8(), start).interpret(); return Interpreter(bytecode, output, input.span16(), start).interpret(); } -unsigned interpret(BytecodePattern* bytecode, std::span input, unsigned start, unsigned* output) +unsigned interpret(BytecodePattern* bytecode, std::span input, unsigned start, unsigned* output) { SuperSamplerScope superSamplerScope(false); - return Interpreter(bytecode, output, input, start).interpret(); + return Interpreter(bytecode, output, input, start).interpret(); } unsigned interpret(BytecodePattern* bytecode, std::span input, unsigned start, unsigned* output) @@ -3190,7 +3190,7 @@ unsigned interpret(BytecodePattern* bytecode, std::span input, u return Interpreter(bytecode, output, input, start).interpret(); } -// These should be the same for both char16_t & LChar. +// These should be the same for both char16_t & Latin1Character. static_assert(sizeof(BackTrackInfoPatternCharacter) == (YarrStackSpaceForBackTrackInfoPatternCharacter * sizeof(uintptr_t))); static_assert(sizeof(BackTrackInfoCharacterClass) == (YarrStackSpaceForBackTrackInfoCharacterClass * sizeof(uintptr_t))); static_assert(sizeof(BackTrackInfoBackReference) == (YarrStackSpaceForBackTrackInfoBackReference * sizeof(uintptr_t))); diff --git a/Source/JavaScriptCore/yarr/YarrInterpreter.h b/Source/JavaScriptCore/yarr/YarrInterpreter.h index 61a257c29415c..17737a3be2d75 100644 --- a/Source/JavaScriptCore/yarr/YarrInterpreter.h +++ b/Source/JavaScriptCore/yarr/YarrInterpreter.h @@ -536,7 +536,7 @@ struct BytecodePattern { JS_EXPORT_PRIVATE std::unique_ptr byteCompile(YarrPattern&, BumpPointerAllocator*, ErrorCode&, ConcurrentJSLock* = nullptr); JS_EXPORT_PRIVATE unsigned interpret(BytecodePattern*, StringView input, unsigned start, unsigned* output); -unsigned interpret(BytecodePattern*, std::span input, unsigned start, unsigned* output); -unsigned interpret(BytecodePattern*, std::span input, unsigned start, unsigned* output); +unsigned interpret(BytecodePattern*, std::span input, unsigned start, unsigned* output); +unsigned interpret(BytecodePattern*, std::span input, unsigned start, unsigned* output); } } // namespace JSC::Yarr diff --git a/Source/JavaScriptCore/yarr/YarrJIT.h b/Source/JavaScriptCore/yarr/YarrJIT.h index 7f170160955c0..8d07c4cada7f4 100644 --- a/Source/JavaScriptCore/yarr/YarrJIT.h +++ b/Source/JavaScriptCore/yarr/YarrJIT.h @@ -276,9 +276,9 @@ class YarrCodeBlock final : public YarrBoyerMooreData { WTF_MAKE_NONCOPYABLE(YarrCodeBlock); public: - using YarrJITCode8 = UGPRPair SYSV_ABI (*)(const LChar* input, UCPURegister start, UCPURegister length, int* output, MatchingContextHolder*) YARR_CALL; + using YarrJITCode8 = UGPRPair SYSV_ABI (*)(const Latin1Character* input, UCPURegister start, UCPURegister length, int* output, MatchingContextHolder*) YARR_CALL; using YarrJITCode16 = UGPRPair SYSV_ABI (*)(const char16_t* input, UCPURegister start, UCPURegister length, int* output, MatchingContextHolder*) YARR_CALL; - using YarrJITCodeMatchOnly8 = UGPRPair SYSV_ABI (*)(const LChar* input, UCPURegister start, UCPURegister length, void*, MatchingContextHolder*) YARR_CALL; + using YarrJITCodeMatchOnly8 = UGPRPair SYSV_ABI (*)(const Latin1Character* input, UCPURegister start, UCPURegister length, void*, MatchingContextHolder*) YARR_CALL; using YarrJITCodeMatchOnly16 = UGPRPair SYSV_ABI (*)(const char16_t* input, UCPURegister start, UCPURegister length, void*, MatchingContextHolder*) YARR_CALL; YarrCodeBlock(RegExp* regExp) @@ -332,7 +332,7 @@ class YarrCodeBlock final : public YarrBoyerMooreData { InlineStats& get8BitInlineStats() { return m_matchOnly8Stats; } InlineStats& get16BitInlineStats() { return m_matchOnly16Stats; } - MatchResult execute(std::span input, unsigned start, int* output, MatchingContextHolder* matchingContext) + MatchResult execute(std::span input, unsigned start, int* output, MatchingContextHolder* matchingContext) { ASSERT(has8BitCode()); #if CPU(ARM64E) @@ -352,7 +352,7 @@ class YarrCodeBlock final : public YarrBoyerMooreData { return MatchResult(untagCFunctionPtr(m_ref16.code().taggedPtr())(input.data(), start, input.size(), output, matchingContext)); } - MatchResult execute(std::span input, unsigned start, MatchingContextHolder* matchingContext) + MatchResult execute(std::span input, unsigned start, MatchingContextHolder* matchingContext) { ASSERT(has8BitCodeMatchOnly()); #if CPU(ARM64E) diff --git a/Source/JavaScriptCore/yarr/YarrParser.h b/Source/JavaScriptCore/yarr/YarrParser.h index f6f9624131c73..1cd4d47492ae8 100644 --- a/Source/JavaScriptCore/yarr/YarrParser.h +++ b/Source/JavaScriptCore/yarr/YarrParser.h @@ -2188,7 +2188,7 @@ template ErrorCode parse(Delegate& delegate, const StringView pattern, CompileMode compileMode, unsigned backReferenceLimit = quantifyInfinite, bool isNamedForwardReferenceAllowed = true) { if (pattern.is8Bit()) - return Parser(delegate, pattern, compileMode, backReferenceLimit, isNamedForwardReferenceAllowed).parse(); + return Parser(delegate, pattern, compileMode, backReferenceLimit, isNamedForwardReferenceAllowed).parse(); return Parser(delegate, pattern, compileMode, backReferenceLimit, isNamedForwardReferenceAllowed).parse(); } diff --git a/Source/JavaScriptCore/yarr/hasher.py b/Source/JavaScriptCore/yarr/hasher.py index dd86fbc88a5d3..5c07bd7579ca9 100644 --- a/Source/JavaScriptCore/yarr/hasher.py +++ b/Source/JavaScriptCore/yarr/hasher.py @@ -72,7 +72,7 @@ def maskTop8BitsAndAvoidZero(value): def superFastHash(str): # Implements Paul Hsieh's SuperFastHash - http://www.azillionmonkeys.com/qed/hash.html - # LChar data is interpreted as Latin-1-encoded (zero extended to 16 bits). + # Latin1Character data is interpreted as Latin-1-encoded (zero extended to 16 bits). stringHashingStartValue = 0x9E3779B9 hash = stringHashingStartValue diff --git a/Source/WTF/WTF.xcodeproj/project.pbxproj b/Source/WTF/WTF.xcodeproj/project.pbxproj index 4e17c4e75fe5d..2053e48e11756 100644 --- a/Source/WTF/WTF.xcodeproj/project.pbxproj +++ b/Source/WTF/WTF.xcodeproj/project.pbxproj @@ -598,7 +598,7 @@ DDF307D027C086DF006A526F /* TextBreakIteratorCF.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CCDB1491E566626006C73C0 /* TextBreakIteratorCF.h */; settings = {ATTRIBUTES = (Private, ); }; }; DDF307D127C086DF006A526F /* StringConcatenateNumbers.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD4C26F1E2C82B900929470 /* StringConcatenateNumbers.h */; settings = {ATTRIBUTES = (Private, ); }; }; DDF307D227C086DF006A526F /* UTextProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C181C8A1D307AB800F5FA16 /* UTextProvider.h */; settings = {ATTRIBUTES = (Private, ); }; }; - DDF307D327C086DF006A526F /* LChar.h in Headers */ = {isa = PBXBuildFile; fileRef = 93AC91A718942FC400244939 /* LChar.h */; settings = {ATTRIBUTES = (Private, ); }; }; + DDF307D327C086DF006A526F /* Latin1Character.h in Headers */ = {isa = PBXBuildFile; fileRef = 93AC91A718942FC400244939 /* Latin1Character.h */; settings = {ATTRIBUTES = (Private, ); }; }; DDF307D427C086DF006A526F /* TextBreakIteratorICU.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CCDB14D1E566898006C73C0 /* TextBreakIteratorICU.h */; settings = {ATTRIBUTES = (Private, ); }; }; DDF307D527C086DF006A526F /* LineEnding.h in Headers */ = {isa = PBXBuildFile; fileRef = C2BCFC541F621F3F00C9222C /* LineEnding.h */; settings = {ATTRIBUTES = (Private, ); }; }; DDF307D627C086DF006A526F /* NullTextBreakIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = DD4901ED27B474D900D7E50D /* NullTextBreakIterator.h */; settings = {ATTRIBUTES = (Private, ); }; }; @@ -1328,7 +1328,7 @@ 93853DD228755A6600FF4E2B /* EscapedFormsForJSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EscapedFormsForJSON.h; sourceTree = ""; }; 93934BD218A1E8C300D0D6A1 /* StringViewCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringViewCocoa.mm; sourceTree = ""; }; 93934BD418A1F16900D0D6A1 /* StringViewCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringViewCF.cpp; sourceTree = ""; }; - 93AC91A718942FC400244939 /* LChar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LChar.h; sourceTree = ""; }; + 93AC91A718942FC400244939 /* Latin1Character.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Latin1Character.h; sourceTree = ""; }; 93B07ED626B86BB500A09B34 /* SuspendableWorkQueue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SuspendableWorkQueue.h; sourceTree = ""; }; 93B07ED726B8715B00A09B34 /* SuspendableWorkQueue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SuspendableWorkQueue.cpp; sourceTree = ""; }; 93B5B44D2213D616004B7AA7 /* HexNumber.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HexNumber.cpp; sourceTree = ""; }; @@ -2622,7 +2622,7 @@ 50DE35F4215BB01500B979C7 /* ExternalStringImpl.h */, 461229712ACF6B3100BB1CCC /* FastCharacterComparison.h */, 26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */, - 93AC91A718942FC400244939 /* LChar.h */, + 93AC91A718942FC400244939 /* Latin1Character.h */, C2BCFC531F621F3F00C9222C /* LineEnding.cpp */, C2BCFC541F621F3F00C9222C /* LineEnding.h */, BC5267662C2726D600E422DD /* MakeString.h */, @@ -3331,9 +3331,9 @@ DD3DC86F27A4BF8E007E5B61 /* JSValueMalloc.h in Headers */, DD3DC99727A4BF8E007E5B61 /* KeyValuePair.h in Headers */, DD3DC8BF27A4BF8E007E5B61 /* Language.h in Headers */, + DDF307D327C086DF006A526F /* Latin1Character.h in Headers */, E32AB5012B5CE35D00B9FAAE /* LazyRef.h in Headers */, E32AB5022B5CE35D00B9FAAE /* LazyUniqueRef.h in Headers */, - DDF307D327C086DF006A526F /* LChar.h in Headers */, DD3DC88927A4BF8E007E5B61 /* LEBDecoder.h in Headers */, 6311592628989A55006A9A12 /* LibraryPathDiagnostics.h in Headers */, DD3DC8B427A4BF8E007E5B61 /* LikelyDenseUnsignedIntegerSet.h in Headers */, diff --git a/Source/WTF/wtf/ASCIICType.h b/Source/WTF/wtf/ASCIICType.h index cfbbe0758356d..9532646de460c 100644 --- a/Source/WTF/wtf/ASCIICType.h +++ b/Source/WTF/wtf/ASCIICType.h @@ -25,7 +25,7 @@ #pragma once #include -#include +#include // The behavior of many of the functions in the header is dependent // on the current locale. But in the WebKit project, all uses of those functions @@ -184,7 +184,7 @@ template<> inline char toASCIILower(char character) return static_cast(asciiCaseFoldTable[static_cast(character)]); } -template<> inline LChar toASCIILower(LChar character) +template<> inline Latin1Character toASCIILower(Latin1Character character) { return asciiCaseFoldTable[character]; } diff --git a/Source/WTF/wtf/CMakeLists.txt b/Source/WTF/wtf/CMakeLists.txt index 291e2b6bf301f..769690f87842d 100644 --- a/Source/WTF/wtf/CMakeLists.txt +++ b/Source/WTF/wtf/CMakeLists.txt @@ -446,7 +446,7 @@ set(WTF_PUBLIC_HEADERS text/ExternalStringImpl.h text/FastCharacterComparison.h text/IntegerToStringConversion.h - text/LChar.h + text/Latin1Character.h text/LineEnding.h text/MakeString.h text/NullTextBreakIterator.h diff --git a/Source/WTF/wtf/DateMath.cpp b/Source/WTF/wtf/DateMath.cpp index c116d66a23c31..7f4a9f4f72da4 100644 --- a/Source/WTF/wtf/DateMath.cpp +++ b/Source/WTF/wtf/DateMath.cpp @@ -131,8 +131,8 @@ static void appendTwoDigitNumber(StringBuilder& builder, int number) { ASSERT(number >= 0); ASSERT(number < 100); - builder.append(static_cast('0' + number / 10)); - builder.append(static_cast('0' + number % 10)); + builder.append(static_cast('0' + number / 10)); + builder.append(static_cast('0' + number % 10)); } static inline double msToMilliseconds(double ms) @@ -416,7 +416,7 @@ static const struct KnownZone { { "pdt", -420 } }; -inline static void skipSpacesAndComments(std::span& s) +inline static void skipSpacesAndComments(std::span& s) { int nesting = 0; while (!s.empty()) { @@ -434,7 +434,7 @@ inline static void skipSpacesAndComments(std::span& s) } // returns 0-11 (Jan-Dec); -1 on failure -static int findMonth(std::span monthStr) +static int findMonth(std::span monthStr) { if (monthStr.size() < 3) return -1; @@ -453,7 +453,7 @@ static int findMonth(std::span monthStr) return -1; } -static bool parseInt(std::span& string, int base, int* result) +static bool parseInt(std::span& string, int base, int* result) { char* stopPosition; long longResult = strtol(byteCast(string.data()), &stopPosition, base); @@ -465,7 +465,7 @@ static bool parseInt(std::span& string, int base, int* result) return true; } -static bool parseLong(std::span& string, int base, long* result) +static bool parseLong(std::span& string, int base, long* result) { char* stopPosition; *result = strtol(byteCast(string.data()), &stopPosition, base); @@ -479,7 +479,7 @@ static bool parseLong(std::span& string, int base, long* result) // Parses a date with the format YYYY[-MM[-DD]]. // Year parsing is lenient, allows any number of digits, and +/-. // Returns 0 if a parse error occurs, else returns the end of the parsed portion of the string. -static bool parseES5DatePortion(std::span& currentPosition, int& year, long& month, long& day) +static bool parseES5DatePortion(std::span& currentPosition, int& year, long& month, long& day) { // This is a bit more lenient on the year string than ES5 specifies: // instead of restricting to 4 digits (or 6 digits with mandatory +/-), @@ -523,7 +523,7 @@ static bool parseES5DatePortion(std::span& currentPosition, int& ye // Parses a time with the format HH:mm[:ss[.sss]][Z|(+|-)(00:00|0000|00)]. // Fractional seconds parsing is lenient, allows any number of digits. // Returns 0 if a parse error occurs, else returns the end of the parsed portion of the string. -static bool parseES5TimePortion(std::span& currentPosition, long& hours, long& minutes, long& seconds, double& milliseconds, bool& isLocalTime, long& timeZoneSeconds) +static bool parseES5TimePortion(std::span& currentPosition, long& hours, long& minutes, long& seconds, double& milliseconds, bool& isLocalTime, long& timeZoneSeconds) { isLocalTime = false; @@ -644,7 +644,7 @@ static bool parseES5TimePortion(std::span& currentPosition, long& h return true; } -double parseES5Date(std::span dateString, bool& isLocalTime) +double parseES5Date(std::span dateString, bool& isLocalTime) { isLocalTime = false; @@ -704,7 +704,7 @@ double parseES5Date(std::span dateString, bool& isLocalTime) } // Odd case where 'exec' is allowed to be 0, to accomodate a caller in WebCore. -double parseDate(std::span dateString, bool& isLocalTime) +double parseDate(std::span dateString, bool& isLocalTime) { isLocalTime = true; int offset = 0; @@ -1009,7 +1009,7 @@ double parseDate(std::span dateString, bool& isLocalTime) return ymdhmsToMilliseconds(year.value(), month + 1, day, hour, minute, second, 0) - offset * (secondsPerMinute * msPerSecond); } -double parseDate(std::span dateString) +double parseDate(std::span dateString) { bool isLocalTime; double value = parseDate(dateString, isLocalTime); diff --git a/Source/WTF/wtf/DateMath.h b/Source/WTF/wtf/DateMath.h index 594645c39e888..75a18b16bf87e 100644 --- a/Source/WTF/wtf/DateMath.h +++ b/Source/WTF/wtf/DateMath.h @@ -77,9 +77,9 @@ void initializeDates(); int equivalentYearForDST(int year); // Not really math related, but this is currently the only shared place to put these. -WTF_EXPORT_PRIVATE double parseES5Date(std::span dateString, bool& isLocalTime); -WTF_EXPORT_PRIVATE double parseDate(std::span dateString); -WTF_EXPORT_PRIVATE double parseDate(std::span dateString, bool& isLocalTime); +WTF_EXPORT_PRIVATE double parseES5Date(std::span dateString, bool& isLocalTime); +WTF_EXPORT_PRIVATE double parseDate(std::span dateString); +WTF_EXPORT_PRIVATE double parseDate(std::span dateString, bool& isLocalTime); // dayOfWeek: [0, 6] 0 being Monday, day: [1, 31], month: [0, 11], year: ex: 2011, hours: [0, 23], minutes: [0, 59], seconds: [0, 59], utcOffset: [-720,720]. WTF_EXPORT_PRIVATE String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, unsigned year, unsigned hours, unsigned minutes, unsigned seconds, int utcOffset); diff --git a/Source/WTF/wtf/FastFloat.cpp b/Source/WTF/wtf/FastFloat.cpp index c4a98d44e87e3..a8d16dff88eea 100644 --- a/Source/WTF/wtf/FastFloat.cpp +++ b/Source/WTF/wtf/FastFloat.cpp @@ -30,7 +30,7 @@ namespace WTF { -double parseDouble(std::span string, size_t& parsedLength) +double parseDouble(std::span string, size_t& parsedLength) { double doubleValue = 0; auto stringData = byteCast(string.data()); diff --git a/Source/WTF/wtf/FastFloat.h b/Source/WTF/wtf/FastFloat.h index 11d1ee3ef0365..87fd60b560964 100644 --- a/Source/WTF/wtf/FastFloat.h +++ b/Source/WTF/wtf/FastFloat.h @@ -31,7 +31,7 @@ namespace WTF { -WTF_EXPORT_PRIVATE double parseDouble(std::span string, size_t& parsedLength); -WTF_EXPORT_PRIVATE double parseDouble(std::span string, size_t& parsedLength); +WTF_EXPORT_PRIVATE double parseDouble(std::span string, size_t& parsedLength); +WTF_EXPORT_PRIVATE double parseDouble(std::span string, size_t& parsedLength); } // namespace WTF diff --git a/Source/WTF/wtf/HexNumber.cpp b/Source/WTF/wtf/HexNumber.cpp index d0a3c185e15ca..8daf9f8513c13 100644 --- a/Source/WTF/wtf/HexNumber.cpp +++ b/Source/WTF/wtf/HexNumber.cpp @@ -27,7 +27,7 @@ namespace WTF { namespace Internal { -std::pair appendHex(LChar* buffer, unsigned bufferSize, std::uintmax_t number, unsigned minimumDigits, HexConversionMode mode) +std::pair appendHex(Latin1Character* buffer, unsigned bufferSize, std::uintmax_t number, unsigned minimumDigits, HexConversionMode mode) { auto end = buffer + bufferSize; auto start = end; diff --git a/Source/WTF/wtf/HexNumber.h b/Source/WTF/wtf/HexNumber.h index 1f577ede13a78..f2cb9253c77d6 100644 --- a/Source/WTF/wtf/HexNumber.h +++ b/Source/WTF/wtf/HexNumber.h @@ -29,17 +29,17 @@ enum HexConversionMode { Lowercase, Uppercase }; namespace Internal { -inline const LChar* hexDigitsForMode(HexConversionMode mode) +inline const Latin1Character* hexDigitsForMode(HexConversionMode mode) { - static const LChar lowercaseHexDigits[17] = "0123456789abcdef"; - static const LChar uppercaseHexDigits[17] = "0123456789ABCDEF"; + static const Latin1Character lowercaseHexDigits[17] = "0123456789abcdef"; + static const Latin1Character uppercaseHexDigits[17] = "0123456789ABCDEF"; return mode == Lowercase ? lowercaseHexDigits : uppercaseHexDigits; } -WTF_EXPORT_PRIVATE std::pair appendHex(LChar* buffer, unsigned bufferSize, std::uintmax_t number, unsigned minimumDigits, HexConversionMode); +WTF_EXPORT_PRIVATE std::pair appendHex(Latin1Character* buffer, unsigned bufferSize, std::uintmax_t number, unsigned minimumDigits, HexConversionMode); template -inline std::pair appendHex(std::array& buffer, NumberType number, unsigned minimumDigits, HexConversionMode mode) +inline std::pair appendHex(std::array& buffer, NumberType number, unsigned minimumDigits, HexConversionMode mode) { return appendHex(&buffer.front(), buffer.size(), static_cast::type>(number), minimumDigits, mode); } @@ -49,10 +49,10 @@ inline std::pair appendHex(std::array& buffe struct HexNumberBuffer { WTF_MAKE_STRUCT_FAST_ALLOCATED; - std::array buffer; + std::array buffer; unsigned length; - std::span span() const LIFETIME_BOUND { return std::span { buffer }.last(length); } + std::span span() const LIFETIME_BOUND { return std::span { buffer }.last(length); } }; template HexNumberBuffer hex(NumberType number, unsigned minimumDigits = 0, HexConversionMode mode = Uppercase) diff --git a/Source/WTF/wtf/Int128.cpp b/Source/WTF/wtf/Int128.cpp index 8326873032bf8..bb2d03d9c70bb 100644 --- a/Source/WTF/wtf/Int128.cpp +++ b/Source/WTF/wtf/Int128.cpp @@ -302,7 +302,7 @@ std::ostream& operator<<(std::ostream& os, Int128Impl v) { void printInternal(PrintStream& out, UInt128 value) { - auto vector = numberToStringUnsigned>(value); + auto vector = numberToStringUnsigned>(value); vector.append('\0'); out.printf("%s", std::bit_cast(vector.data())); } @@ -318,7 +318,7 @@ void printInternal(PrintStream& out, Int128 value) positive = static_cast(0x8000'0000'0000'0000ULL) << 64; else positive = -value; - auto vector = numberToStringUnsigned>(positive); + auto vector = numberToStringUnsigned>(positive); vector.append('\0'); out.printf("-%s", std::bit_cast(vector.data())); } diff --git a/Source/WTF/wtf/JSONValues.cpp b/Source/WTF/wtf/JSONValues.cpp index a22c907801b54..5673a469276fd 100644 --- a/Source/WTF/wtf/JSONValues.cpp +++ b/Source/WTF/wtf/JSONValues.cpp @@ -545,7 +545,7 @@ RefPtr Value::parseJSON(StringView json) RefPtr result; if (json.is8Bit()) { auto data = json.span8(); - std::span tokenEnd; + std::span tokenEnd; result = buildValue(data, tokenEnd, 0); if (containsNonSpace(tokenEnd)) return nullptr; diff --git a/Source/WTF/wtf/SIMDHelpers.h b/Source/WTF/wtf/SIMDHelpers.h index 1344580fd21a7..bbb8431c0535f 100644 --- a/Source/WTF/wtf/SIMDHelpers.h +++ b/Source/WTF/wtf/SIMDHelpers.h @@ -466,7 +466,7 @@ ALWAYS_INLINE std::optional findFirstNonZeroIndex(simde_uint64x2_t valu #endif } -template +template ALWAYS_INLINE simde_uint8x16_t equal(simde_uint8x16_t input) { auto result = simde_vceqq_u8(input, simde_vmovq_n_u8(character)); diff --git a/Source/WTF/wtf/URL.cpp b/Source/WTF/wtf/URL.cpp index be52bd9f501b3..39e1c5ff11bc9 100644 --- a/Source/WTF/wtf/URL.cpp +++ b/Source/WTF/wtf/URL.cpp @@ -189,7 +189,7 @@ String URL::protocolHostAndPort() const ); } -static std::optional decodeEscapeSequence(StringView input, unsigned index, unsigned length) +static std::optional decodeEscapeSequence(StringView input, unsigned index, unsigned length) { if (index + 3 > length || input[index] != '%') return std::nullopt; @@ -209,7 +209,7 @@ static String decodeEscapeSequencesFromParsedURL(StringView input) return input.toString(); // FIXME: This 100 is arbitrary. Should make a histogram of how this function is actually used to choose a better value. - Vector percentDecoded; + Vector percentDecoded; percentDecoded.reserveInitialCapacity(length); for (unsigned i = 0; i < length; ) { if (auto decodedCharacter = decodeEscapeSequence(input, i, length)) { diff --git a/Source/WTF/wtf/URLParser.cpp b/Source/WTF/wtf/URLParser.cpp index bc3ca0a63e2e0..699e140c7213c 100644 --- a/Source/WTF/wtf/URLParser.cpp +++ b/Source/WTF/wtf/URLParser.cpp @@ -410,7 +410,7 @@ ALWAYS_INLINE void URLParser::appendToASCIIBuffer(char32_t codePoint) m_asciiBuffer.append(codePoint); } -ALWAYS_INLINE void URLParser::appendToASCIIBuffer(std::span characters) +ALWAYS_INLINE void URLParser::appendToASCIIBuffer(std::span characters) { if (UNLIKELY(m_didSeeSyntaxViolation)) m_asciiBuffer.append(characters); @@ -475,7 +475,7 @@ bool URLParser::shouldCopyFileURL(CodePointIterator iterator) return !isSlashQuestionOrHash(*iterator); } -static void percentEncodeByte(uint8_t byte, Vector& buffer) +static void percentEncodeByte(uint8_t byte, Vector& buffer) { buffer.append('%'); buffer.append(upperNibbleToASCIIHexDigit(byte)); @@ -971,7 +971,7 @@ bool URLParser::shouldPopPath(unsigned newPathAfterLastSlash) return true; ASSERT(m_url.m_pathAfterLastSlash <= m_asciiBuffer.size()); - CodePointIterator componentToPop({ &m_asciiBuffer[newPathAfterLastSlash], &m_asciiBuffer[0] + m_url.m_pathAfterLastSlash }); + CodePointIterator componentToPop({ &m_asciiBuffer[newPathAfterLastSlash], &m_asciiBuffer[0] + m_url.m_pathAfterLastSlash }); if (newPathAfterLastSlash == m_url.m_hostEnd + m_url.m_portLength + 1 && isWindowsDriveLetter(componentToPop)) return false; return true; @@ -1051,8 +1051,8 @@ bool URLParser::isAtLocalhost(CodePointIterator iterator) bool URLParser::isLocalhost(StringView view) { if (view.is8Bit()) - return isAtLocalhost(view.span8()); - return isAtLocalhost(view.span16()); + return isAtLocalhost(view.span8()); + return isAtLocalhost(view.span16()); } ALWAYS_INLINE StringView URLParser::parsedDataView(size_t start, size_t length) @@ -2078,9 +2078,9 @@ void URLParser::parseAuthority(CodePointIterator iterator) template void URLParser::appendNumberToASCIIBuffer(UnsignedIntegerType number) { - LChar buf[sizeof(UnsignedIntegerType) * 3 + 1]; - LChar* end = std::end(buf); - LChar* p = end; + Latin1Character buf[sizeof(UnsignedIntegerType) * 3 + 1]; + Latin1Character* end = std::end(buf); + Latin1Character* p = end; do { *--p = (number % 10) + '0'; number /= 10; @@ -2476,7 +2476,7 @@ std::optional URLParser::parseIPv6Host(CodePointIterator } template -URLParser::LCharBuffer URLParser::percentDecode(std::span input, const CodePointIterator& iteratorForSyntaxViolationPosition) +URLParser::LCharBuffer URLParser::percentDecode(std::span input, const CodePointIterator& iteratorForSyntaxViolationPosition) { LCharBuffer output; output.reserveInitialCapacity(input.size()); @@ -2498,7 +2498,7 @@ URLParser::LCharBuffer URLParser::percentDecode(std::span input, co return output; } -URLParser::LCharBuffer URLParser::percentDecode(std::span input) +URLParser::LCharBuffer URLParser::percentDecode(std::span input) { LCharBuffer output; output.reserveInitialCapacity(input.size()); @@ -2705,8 +2705,8 @@ bool URLParser::subdomainStartsWithXNDashDash(CodePointIterator i bool URLParser::subdomainStartsWithXNDashDash(StringImpl& host) { if (host.is8Bit()) - return subdomainStartsWithXNDashDash(host.span8()); - return subdomainStartsWithXNDashDash(host.span16()); + return subdomainStartsWithXNDashDash(host.span8()); + return subdomainStartsWithXNDashDash(host.span16()); } static bool dnsNameEndsInNumber(StringView name) @@ -2860,9 +2860,9 @@ auto URLParser::parseHostAndPort(CodePointIterator iterator) -> H if (!asciiDomain || hasForbiddenHostCodePoint(asciiDomain.value())) return HostParsingResult::InvalidHost; LCharBuffer& asciiDomainValue = asciiDomain.value(); - const LChar* asciiDomainCharacters = asciiDomainValue.data(); + const Latin1Character* asciiDomainCharacters = asciiDomainValue.data(); - auto address = parseIPv4Host(hostBegin, asciiDomainValue.span()); + auto address = parseIPv4Host(hostBegin, asciiDomainValue.span()); if (address) { serializeIPv4(address.value()); m_url.m_hostEnd = currentPosition(iterator); @@ -2892,7 +2892,7 @@ std::optional URLParser::formURLDecode(StringView input) auto utf8 = input.utf8(StrictConversion); if (utf8.isNull()) return std::nullopt; - auto percentDecoded = percentDecode(utf8.span()); + auto percentDecoded = percentDecode(byteCast(utf8.span())); return String::fromUTF8ReplacingInvalidSequences(percentDecoded.span()); } @@ -2923,7 +2923,7 @@ std::optional> URLParser::parseQueryNameAndValue(St return std::nullopt; } -static void serializeURLEncodedForm(const String& input, Vector& output) +static void serializeURLEncodedForm(const String& input, Vector& output) { auto utf8 = input.utf8(StrictConversion); for (char byte : utf8.span()) { @@ -2947,7 +2947,7 @@ String URLParser::serialize(const URLEncodedForm& tuples) if (tuples.isEmpty()) return { }; - Vector output; + Vector output; for (auto& tuple : tuples) { if (!output.isEmpty()) output.append('&'); diff --git a/Source/WTF/wtf/URLParser.h b/Source/WTF/wtf/URLParser.h index d371bf592564b..20b035fccb015 100644 --- a/Source/WTF/wtf/URLParser.h +++ b/Source/WTF/wtf/URLParser.h @@ -78,7 +78,7 @@ class URLParser { friend class URL; URL m_url; - Vector m_asciiBuffer; + Vector m_asciiBuffer; bool m_urlIsSpecial { false }; bool m_urlIsFile { false }; bool m_hostHasPercentOrNonASCII { false }; @@ -87,7 +87,7 @@ class URLParser { const void* m_inputBegin { nullptr }; static constexpr size_t defaultInlineBufferSize = 2048; - using LCharBuffer = Vector; + using LCharBuffer = Vector; template void parse(std::span, const URL&, const URLTextEncoding*); template void parseAuthority(CodePointIterator); @@ -119,13 +119,13 @@ class URLParser { template void utf8PercentEncode(const CodePointIterator&); template void utf8QueryEncode(const CodePointIterator&); template std::optional domainToASCII(StringImpl&, const CodePointIterator& iteratorForSyntaxViolationPosition); - template LCharBuffer percentDecode(std::span, const CodePointIterator& iteratorForSyntaxViolationPosition); - static LCharBuffer percentDecode(std::span); + template LCharBuffer percentDecode(std::span, const CodePointIterator& iteratorForSyntaxViolationPosition); + static LCharBuffer percentDecode(std::span); bool hasForbiddenHostCodePoint(const LCharBuffer&); void percentEncodeByte(uint8_t); void appendToASCIIBuffer(char32_t); - void appendToASCIIBuffer(std::span); - template void encodeNonUTF8Query(const Vector& source, const URLTextEncoding&, CodePointIterator); + void appendToASCIIBuffer(std::span); + template void encodeNonUTF8Query(const Vector& source, const URLTextEncoding&, CodePointIterator); void copyASCIIStringUntil(const String&, size_t length); bool copyBaseWindowsDriveLetter(const URL&); StringView parsedDataView(size_t start, size_t length) LIFETIME_BOUND; diff --git a/Source/WTF/wtf/cf/CFURLExtras.cpp b/Source/WTF/wtf/cf/CFURLExtras.cpp index b5f2c02944ba7..686c2dd031f94 100644 --- a/Source/WTF/wtf/cf/CFURLExtras.cpp +++ b/Source/WTF/wtf/cf/CFURLExtras.cpp @@ -54,7 +54,7 @@ String bytesAsString(CFURLRef url) auto bytesLength = CFURLGetBytes(url, nullptr, 0); RELEASE_ASSERT(bytesLength != -1); RELEASE_ASSERT(bytesLength <= static_cast(String::MaxLength)); - LChar* buffer; + Latin1Character* buffer; auto result = String::createUninitialized(bytesLength, buffer); CFURLGetBytes(url, buffer, bytesLength); return result; diff --git a/Source/WTF/wtf/persistence/PersistentCoders.cpp b/Source/WTF/wtf/persistence/PersistentCoders.cpp index d159ce8ec71a8..024b7c22b3abd 100644 --- a/Source/WTF/wtf/persistence/PersistentCoders.cpp +++ b/Source/WTF/wtf/persistence/PersistentCoders.cpp @@ -138,8 +138,8 @@ std::optional Coder::decodeForPersistence(Decoder& decoder) return std::nullopt; if (*is8Bit) - return decodeStringText(decoder, *length); - return decodeStringText(decoder, *length); + return decodeStringText(decoder, *length); + return decodeStringText(decoder, *length); } void Coder::encodeForPersistence(Encoder& encoder, const URL& url) diff --git a/Source/WTF/wtf/text/ASCIIFastPath.h b/Source/WTF/wtf/text/ASCIIFastPath.h index e45b6be285028..0cd07229d284b 100644 --- a/Source/WTF/wtf/text/ASCIIFastPath.h +++ b/Source/WTF/wtf/text/ASCIIFastPath.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #if CPU(X86_SSE2) #include @@ -57,7 +57,7 @@ template struct NonASCIIMask; template<> struct NonASCIIMask<4, UChar> { static inline uint32_t value() { return 0xFF80FF80U; } }; -template<> struct NonASCIIMask<4, LChar> { +template<> struct NonASCIIMask<4, Latin1Character> { static inline uint32_t value() { return 0x80808080U; } }; template<> struct NonASCIIMask<4, char8_t> { @@ -66,7 +66,7 @@ template<> struct NonASCIIMask<4, char8_t> { template<> struct NonASCIIMask<8, UChar> { static inline uint64_t value() { return 0xFF80FF80FF80FF80ULL; } }; -template<> struct NonASCIIMask<8, LChar> { +template<> struct NonASCIIMask<8, Latin1Character> { static inline uint64_t value() { return 0x8080808080808080ULL; } }; template<> struct NonASCIIMask<8, char8_t> { diff --git a/Source/WTF/wtf/text/ASCIILiteral.h b/Source/WTF/wtf/text/ASCIILiteral.h index c8f914a77c018..b3ee726680060 100644 --- a/Source/WTF/wtf/text/ASCIILiteral.h +++ b/Source/WTF/wtf/text/ASCIILiteral.h @@ -63,7 +63,7 @@ class ASCIILiteral final { constexpr const char* characters() const { return m_charactersWithNullTerminator.data(); } constexpr size_t length() const { return !m_charactersWithNullTerminator.empty() ? m_charactersWithNullTerminator.size() - 1 : 0; } - std::span span8() const { return { std::bit_cast(characters()), length() }; } + std::span span8() const { return { std::bit_cast(characters()), length() }; } std::span spanIncludingNullTerminator() const { return m_charactersWithNullTerminator; } size_t isEmpty() const { return m_charactersWithNullTerminator.size() <= 1; } @@ -139,13 +139,13 @@ constexpr ASCIILiteral operator"" _s(const char* characters, size_t) return result; } -constexpr std::span operator"" _span(const char* characters, size_t n) +constexpr std::span operator"" _span(const char* characters, size_t n) { #if ASSERT_ENABLED for (size_t i = 0; i < n; ++i) ASSERT_UNDER_CONSTEXPR_CONTEXT(isASCII(characters[i])); #endif - return std::span { std::bit_cast(characters), n }; + return std::span { std::bit_cast(characters), n }; } } // inline StringLiterals diff --git a/Source/WTF/wtf/text/AdaptiveStringSearcher.h b/Source/WTF/wtf/text/AdaptiveStringSearcher.h index 7ba63a8af08ec..eb0d483a8d4b2 100644 --- a/Source/WTF/wtf/text/AdaptiveStringSearcher.h +++ b/Source/WTF/wtf/text/AdaptiveStringSearcher.h @@ -62,8 +62,8 @@ class AdaptiveStringSearcherBase { // to compensate for the algorithmic overhead compared to simple brute force. static constexpr int bmMinPatternLength = 7; - static constexpr bool exceedsOneByte(LChar) { return false; } - static constexpr bool exceedsOneByte(UChar c) { return c > 0xff; } + static constexpr bool exceedsOneByte(Latin1Character) { return false; } + static constexpr bool exceedsOneByte(char16_t c) { return c > 0xff; } template static inline int findFirstCharacter(std::span pattern, std::span subject, int index) diff --git a/Source/WTF/wtf/text/AtomString.cpp b/Source/WTF/wtf/text/AtomString.cpp index ec9494c58378a..bb99948d6aec5 100644 --- a/Source/WTF/wtf/text/AtomString.cpp +++ b/Source/WTF/wtf/text/AtomString.cpp @@ -58,12 +58,12 @@ ALWAYS_INLINE AtomString AtomString::convertASCIICase() const } return *this; SlowPath: - LChar localBuffer[localBufferSize]; + Latin1Character localBuffer[localBufferSize]; for (unsigned i = 0; i < failingIndex; ++i) localBuffer[i] = characters[i]; for (unsigned i = failingIndex; i < length; ++i) localBuffer[i] = type == CaseConvertType::Lower ? toASCIILower(characters[i]) : toASCIIUpper(characters[i]); - return std::span { localBuffer, length }; + return std::span { localBuffer, length }; } Ref convertedString = type == CaseConvertType::Lower ? impl->convertToASCIILowercase() : impl->convertToASCIIUppercase(); diff --git a/Source/WTF/wtf/text/AtomString.h b/Source/WTF/wtf/text/AtomString.h index ae6e4d2f46066..f248991785ac3 100644 --- a/Source/WTF/wtf/text/AtomString.h +++ b/Source/WTF/wtf/text/AtomString.h @@ -30,10 +30,10 @@ class AtomString final { WTF_MAKE_FAST_ALLOCATED; public: AtomString(); - AtomString(std::span); - AtomString(std::span); + AtomString(std::span); + AtomString(std::span); - ALWAYS_INLINE static AtomString fromLatin1(const char* characters) { return AtomString(characters); } + ALWAYS_INLINE static AtomString fromLatin1(const char *characters) { return AtomString(characters); } AtomString(AtomStringImpl*); AtomString(RefPtr&&); @@ -66,8 +66,8 @@ class AtomString final { RefPtr releaseImpl() { return static_pointer_cast(m_string.releaseImpl()); } bool is8Bit() const { return m_string.is8Bit(); } - std::span span8() const { return m_string.span8(); } - std::span span16() const { return m_string.span16(); } + std::span span8() const LIFETIME_BOUND { return m_string.span8(); } + std::span span16() const LIFETIME_BOUND { return m_string.span16(); } unsigned length() const { return m_string.length(); } UChar operator[](unsigned int i) const { return m_string[i]; } @@ -174,7 +174,7 @@ inline AtomString::AtomString(const char* string) { } -inline AtomString::AtomString(std::span string) +inline AtomString::AtomString(std::span string) : m_string(AtomStringImpl::add(string)) { } @@ -341,7 +341,7 @@ ALWAYS_INLINE String WARN_UNUSED_RETURN makeStringByReplacingAll(const AtomStrin template<> struct IntegerToStringConversionTrait { using ReturnType = AtomString; using AdditionalArgumentType = void; - static AtomString flush(std::span characters, void*) { return characters; } + static AtomString flush(std::span characters, void*) { return characters; } }; } // namespace WTF diff --git a/Source/WTF/wtf/text/AtomStringImpl.cpp b/Source/WTF/wtf/text/AtomStringImpl.cpp index af90a6f6d8138..e215ca33b9c7d 100644 --- a/Source/WTF/wtf/text/AtomStringImpl.cpp +++ b/Source/WTF/wtf/text/AtomStringImpl.cpp @@ -133,7 +133,7 @@ struct HashedUTF8CharactersTranslator { return Unicode::equal(string->span16(), characters.characters); } - auto charactersLatin1 = spanReinterpretCast(characters.characters); + auto charactersLatin1 = spanReinterpretCast(characters.characters); if (string->is8Bit()) return WTF::equal(string->span8().data(), charactersLatin1); return WTF::equal(string->span16().data(), charactersLatin1); @@ -148,7 +148,7 @@ struct HashedUTF8CharactersTranslator { RELEASE_ASSERT(result.code == Unicode::ConversionResultCode::Success); if (result.isAllASCII) - newString = StringImpl::create(spanReinterpretCast(characters.characters)); + newString = StringImpl::create(spanReinterpretCast(characters.characters)); auto* pointer = &newString.leakRef(); pointer->setHash(hash); @@ -241,7 +241,7 @@ RefPtr AtomStringImpl::add(StringImpl* baseString, unsigned star return addToStringTable(buffer); } -using LCharBuffer = HashTranslatorCharBuffer; +using LCharBuffer = HashTranslatorCharBuffer; struct LCharBufferTranslator { static unsigned hash(const LCharBuffer& buf) { @@ -284,7 +284,7 @@ struct BufferFromStaticDataTranslator { } }; -RefPtr AtomStringImpl::add(HashTranslatorCharBuffer& buffer) +RefPtr AtomStringImpl::add(HashTranslatorCharBuffer& buffer) { if (!buffer.characters.data()) return nullptr; @@ -295,7 +295,7 @@ RefPtr AtomStringImpl::add(HashTranslatorCharBuffer& buff return addToStringTable(buffer); } -RefPtr AtomStringImpl::add(std::span characters) +RefPtr AtomStringImpl::add(std::span characters) { if (!characters.data()) return nullptr; @@ -307,13 +307,13 @@ RefPtr AtomStringImpl::add(std::span characters) return addToStringTable(buffer); } -Ref AtomStringImpl::addLiteral(std::span characters) +Ref AtomStringImpl::addLiteral(std::span characters) { ASSERT(characters.data()); ASSERT(!characters.empty()); LCharBuffer buffer { characters }; - return addToStringTable>(buffer); + return addToStringTable>(buffer); } static Ref addSymbol(AtomStringTableLocker& locker, StringTableImpl& atomStringTable, StringImpl& base) @@ -340,7 +340,7 @@ static Ref addStatic(AtomStringTableLocker& locker, StringTableI if (base.is8Bit()) { LCharBuffer buffer { base.span8(), base.hash() }; - return addToStringTable>(locker, atomStringTable, buffer); + return addToStringTable>(locker, atomStringTable, buffer); } UCharBuffer buffer { base.span16(), base.hash() }; return addToStringTable>(locker, atomStringTable, buffer); @@ -482,7 +482,7 @@ RefPtr AtomStringImpl::add(std::span characters) return addToStringTable(buffer); } -RefPtr AtomStringImpl::lookUp(std::span characters) +RefPtr AtomStringImpl::lookUp(std::span characters) { AtomStringTableLocker locker; auto& table = stringTable(); diff --git a/Source/WTF/wtf/text/AtomStringImpl.h b/Source/WTF/wtf/text/AtomStringImpl.h index db2b3f2ddbf66..5d12d7e9c8528 100644 --- a/Source/WTF/wtf/text/AtomStringImpl.h +++ b/Source/WTF/wtf/text/AtomStringImpl.h @@ -28,18 +28,18 @@ class AtomStringTable; class SUPPRESS_REFCOUNTED_WITHOUT_VIRTUAL_DESTRUCTOR AtomStringImpl final : public UniquedStringImpl { public: - WTF_EXPORT_PRIVATE static RefPtr lookUp(std::span); - WTF_EXPORT_PRIVATE static RefPtr lookUp(std::span); + WTF_EXPORT_PRIVATE static RefPtr lookUp(std::span); + WTF_EXPORT_PRIVATE static RefPtr lookUp(std::span); static RefPtr lookUp(StringImpl*); static void remove(AtomStringImpl*); - WTF_EXPORT_PRIVATE static RefPtr add(std::span); - WTF_EXPORT_PRIVATE static RefPtr add(std::span); + WTF_EXPORT_PRIVATE static RefPtr add(std::span); + WTF_EXPORT_PRIVATE static RefPtr add(std::span); ALWAYS_INLINE static RefPtr add(std::span characters); - WTF_EXPORT_PRIVATE static RefPtr add(HashTranslatorCharBuffer&); - WTF_EXPORT_PRIVATE static RefPtr add(HashTranslatorCharBuffer&); + WTF_EXPORT_PRIVATE static RefPtr add(HashTranslatorCharBuffer&); + WTF_EXPORT_PRIVATE static RefPtr add(HashTranslatorCharBuffer&); WTF_EXPORT_PRIVATE static RefPtr add(StringImpl*, unsigned offset, unsigned length); ALWAYS_INLINE static RefPtr add(StringImpl*); @@ -69,7 +69,7 @@ class SUPPRESS_REFCOUNTED_WITHOUT_VIRTUAL_DESTRUCTOR AtomStringImpl final : publ ALWAYS_INLINE static Ref add(StringImpl&); ALWAYS_INLINE static Ref add(Ref&&); - WTF_EXPORT_PRIVATE static Ref addLiteral(std::span); + WTF_EXPORT_PRIVATE static Ref addLiteral(std::span); ALWAYS_INLINE static Ref add(AtomStringTable&, StringImpl&); @@ -89,7 +89,7 @@ inline RefPtr AtomStringImpl::lookUp(StringImpl* string) ALWAYS_INLINE RefPtr AtomStringImpl::add(std::span characters) { - return add(byteCast(characters)); + return add(byteCast(characters)); } ALWAYS_INLINE RefPtr AtomStringImpl::add(StringImpl* string) diff --git a/Source/WTF/wtf/text/Base64.cpp b/Source/WTF/wtf/text/Base64.cpp index 33e84b99e983e..65095448983c8 100644 --- a/Source/WTF/wtf/text/Base64.cpp +++ b/Source/WTF/wtf/text/Base64.cpp @@ -175,7 +175,7 @@ void base64Encode(std::span input, std::span destination base64EncodeInternal(input, destination, options); } -void base64Encode(std::span input, std::span destination, OptionSet options) +void base64Encode(std::span input, std::span destination, OptionSet options) { if (!destination.size()) return; @@ -309,8 +309,8 @@ String base64DecodeToString(StringView input, OptionSet opti }; if (input.is8Bit()) - return toString(base64DecodeInternal(input.span8(), options)); - return toString(base64DecodeInternal(input.span16(), options)); + return toString(base64DecodeInternal(input.span8(), options)); + return toString(base64DecodeInternal(input.span16(), options)); } template diff --git a/Source/WTF/wtf/text/Base64.h b/Source/WTF/wtf/text/Base64.h index 71fc19071992d..7af1170a59ac6 100644 --- a/Source/WTF/wtf/text/Base64.h +++ b/Source/WTF/wtf/text/Base64.h @@ -57,8 +57,8 @@ WTF_EXPORT_PRIVATE unsigned calculateBase64EncodedSize(unsigned inputLength, Opt template bool isBase64OrBase64URLCharacter(CharacterType); -WTF_EXPORT_PRIVATE void base64Encode(std::span, std::span, OptionSet = { }); -WTF_EXPORT_PRIVATE void base64Encode(std::span, std::span, OptionSet = { }); +WTF_EXPORT_PRIVATE void base64Encode(std::span, std::span, OptionSet = { }); +WTF_EXPORT_PRIVATE void base64Encode(std::span, std::span, OptionSet = { }); WTF_EXPORT_PRIVATE Vector base64EncodeToVector(std::span, OptionSet = { }); Vector base64EncodeToVector(std::span, OptionSet = { }); diff --git a/Source/WTF/wtf/text/CString.h b/Source/WTF/wtf/text/CString.h index 8d127eab37e00..1da2ad5681d70 100644 --- a/Source/WTF/wtf/text/CString.h +++ b/Source/WTF/wtf/text/CString.h @@ -46,7 +46,7 @@ class CStringBuffer final : public RefCounted { size_t length() const { return m_length; } WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN - std::span span() const LIFETIME_BOUND { return unsafeMakeSpan(reinterpret_cast_ptr(this + 1), m_length); } + std::span span() const LIFETIME_BOUND { return unsafeMakeSpan(reinterpret_cast_ptr(this + 1), m_length); } std::span spanIncludingNullTerminator() const LIFETIME_BOUND { return unsafeMakeSpan(reinterpret_cast_ptr(this + 1), m_length + 1); } WTF_ALLOW_UNSAFE_BUFFER_USAGE_END @@ -126,7 +126,7 @@ template<> struct DefaultHash : CStringHash { }; template struct HashTraits; template<> struct HashTraits : SimpleClassHashTraits { }; -inline CString::CString(std::span bytes) +inline CString::CString(std::span bytes) : CString(byteCast(bytes)) { } diff --git a/Source/WTF/wtf/text/CodePointIterator.h b/Source/WTF/wtf/text/CodePointIterator.h index ad9254cf7f1ba..ac681f89ab71b 100644 --- a/Source/WTF/wtf/text/CodePointIterator.h +++ b/Source/WTF/wtf/text/CodePointIterator.h @@ -27,7 +27,7 @@ #include #include -#include +#include namespace WTF { @@ -76,14 +76,14 @@ class CodePointIterator { }; template<> -ALWAYS_INLINE char32_t CodePointIterator::operator*() const +ALWAYS_INLINE char32_t CodePointIterator::operator*() const { ASSERT(!atEnd()); return m_data.front(); } template<> -ALWAYS_INLINE auto CodePointIterator::operator++() -> CodePointIterator& +ALWAYS_INLINE auto CodePointIterator::operator++() -> CodePointIterator& { m_data = m_data.subspan(1); return *this; diff --git a/Source/WTF/wtf/text/ExternalStringImpl.cpp b/Source/WTF/wtf/text/ExternalStringImpl.cpp index 15aeaefb97d34..c5229b9be866a 100644 --- a/Source/WTF/wtf/text/ExternalStringImpl.cpp +++ b/Source/WTF/wtf/text/ExternalStringImpl.cpp @@ -28,7 +28,7 @@ namespace WTF { -WTF_EXPORT_PRIVATE Ref ExternalStringImpl::create(std::span characters, ExternalStringImplFreeFunction&& free) +WTF_EXPORT_PRIVATE Ref ExternalStringImpl::create(std::span characters, ExternalStringImplFreeFunction&& free) { return adoptRef(*new ExternalStringImpl(characters, WTFMove(free))); } @@ -38,7 +38,7 @@ WTF_EXPORT_PRIVATE Ref ExternalStringImpl::create(std::span< return adoptRef(*new ExternalStringImpl(characters, WTFMove(free))); } -ExternalStringImpl::ExternalStringImpl(std::span characters, ExternalStringImplFreeFunction&& free) +ExternalStringImpl::ExternalStringImpl(std::span characters, ExternalStringImplFreeFunction&& free) : StringImpl(characters, ConstructWithoutCopying) , m_free(WTFMove(free)) { diff --git a/Source/WTF/wtf/text/ExternalStringImpl.h b/Source/WTF/wtf/text/ExternalStringImpl.h index 990373d644824..7cd5100d8c828 100644 --- a/Source/WTF/wtf/text/ExternalStringImpl.h +++ b/Source/WTF/wtf/text/ExternalStringImpl.h @@ -36,14 +36,14 @@ using ExternalStringImplFreeFunction = Function create(std::span characters, ExternalStringImplFreeFunction&&); - WTF_EXPORT_PRIVATE static Ref create(std::span characters, ExternalStringImplFreeFunction&&); + WTF_EXPORT_PRIVATE static Ref create(std::span characters, ExternalStringImplFreeFunction&&); + WTF_EXPORT_PRIVATE static Ref create(std::span characters, ExternalStringImplFreeFunction&&); private: friend class StringImpl; - ExternalStringImpl(std::span characters, ExternalStringImplFreeFunction&&); - ExternalStringImpl(std::span characters, ExternalStringImplFreeFunction&&); + ExternalStringImpl(std::span characters, ExternalStringImplFreeFunction&&); + ExternalStringImpl(std::span characters, ExternalStringImplFreeFunction&&); inline void freeExternalBuffer(void* buffer, unsigned bufferSize); diff --git a/Source/WTF/wtf/text/IntegerToStringConversion.h b/Source/WTF/wtf/text/IntegerToStringConversion.h index 7da3f16e4ee0e..080acab327a96 100644 --- a/Source/WTF/wtf/text/IntegerToStringConversion.h +++ b/Source/WTF/wtf/text/IntegerToStringConversion.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include namespace WTF { @@ -37,12 +37,12 @@ template struct IntegerToStringConversionTrait; template static typename IntegerToStringConversionTrait::ReturnType numberToStringImpl(UnsignedIntegerType number, AdditionalArgumentType additionalArgument) { - LChar buf[sizeof(UnsignedIntegerType) * 3 + 1]; - LChar* end = std::end(buf); - LChar* p = end; + Latin1Character buf[sizeof(UnsignedIntegerType) * 3 + 1]; + Latin1Character* end = std::end(buf); + Latin1Character* p = end; do { - *--p = static_cast((number % 10) + '0'); + *--p = static_cast((number % 10) + '0'); number /= 10; } while (number); @@ -70,12 +70,12 @@ template>, "'bool' not supported"); - LChar buf[sizeof(UnsignedIntegerType) * 3 + 1]; - LChar* end = std::end(buf); - LChar* p = end; + Latin1Character buf[sizeof(UnsignedIntegerType) * 3 + 1]; + Latin1Character* end = std::end(buf); + Latin1Character* p = end; do { - *--p = static_cast((number % 10) + '0'); + *--p = static_cast((number % 10) + '0'); number /= 10; } while (number); @@ -133,10 +133,10 @@ constexpr unsigned lengthOfIntegerAsString(IntegerType integer) } template -struct IntegerToStringConversionTrait> { - using ReturnType = Vector; +struct IntegerToStringConversionTrait> { + using ReturnType = Vector; using AdditionalArgumentType = void; - static ReturnType flush(std::span characters, void*) { return characters; } + static ReturnType flush(std::span characters, void*) { return characters; } }; } // namespace WTF diff --git a/Source/WTF/wtf/text/LChar.h b/Source/WTF/wtf/text/Latin1Character.h similarity index 97% rename from Source/WTF/wtf/text/LChar.h rename to Source/WTF/wtf/text/Latin1Character.h index 465406b8d49af..592f27bb1cc2b 100644 --- a/Source/WTF/wtf/text/LChar.h +++ b/Source/WTF/wtf/text/Latin1Character.h @@ -29,4 +29,4 @@ // A type to hold a single Latin-1 character. // This type complements the UChar type that we get from the ICU library. // To parallel that type, we put this one in the global namespace. -typedef unsigned char LChar; +typedef unsigned char Latin1Character; diff --git a/Source/WTF/wtf/text/MakeString.h b/Source/WTF/wtf/text/MakeString.h index 3fc47702690b7..13f5d035b0b89 100644 --- a/Source/WTF/wtf/text/MakeString.h +++ b/Source/WTF/wtf/text/MakeString.h @@ -44,7 +44,7 @@ RefPtr tryMakeStringImplFromAdaptersInternal(unsigned length, bool a { ASSERT(length <= String::MaxLength); if (areAllAdapters8Bit) { - LChar* buffer; + Latin1Character* buffer; RefPtr result = StringImpl::tryCreateUninitialized(length, buffer); if (!result) return nullptr; @@ -55,7 +55,7 @@ RefPtr tryMakeStringImplFromAdaptersInternal(unsigned length, bool a return result; } - UChar* buffer; + char16_t* buffer; RefPtr result = StringImpl::tryCreateUninitialized(length, buffer); if (!result) return nullptr; @@ -121,13 +121,13 @@ AtomString tryMakeAtomStringFromAdapters(StringTypeAdapters ...adapters) constexpr size_t maxLengthToUseStackVariable = 64; if (length < maxLengthToUseStackVariable) { if (areAllAdapters8Bit) { - LChar buffer[maxLengthToUseStackVariable]; + Latin1Character buffer[maxLengthToUseStackVariable]; stringTypeAdapterAccumulator(buffer, adapters...); - return std::span { buffer, length }; + return std::span { buffer, length }; } - UChar buffer[maxLengthToUseStackVariable]; + char16_t buffer[maxLengthToUseStackVariable]; stringTypeAdapterAccumulator(buffer, adapters...); - return std::span { buffer, length }; + return std::span { buffer, length }; } return tryMakeStringImplFromAdaptersInternal(length, areAllAdapters8Bit, adapters...).get(); } diff --git a/Source/WTF/wtf/text/ParsingUtilities.h b/Source/WTF/wtf/text/ParsingUtilities.h index 9b2ad140640c8..3d3e4d2ea152a 100644 --- a/Source/WTF/wtf/text/ParsingUtilities.h +++ b/Source/WTF/wtf/text/ParsingUtilities.h @@ -94,7 +94,7 @@ template bool skipExactly(String return false; } -template bool skipExactly(StringParsingBuffer& buffer) +template bool skipExactly(StringParsingBuffer& buffer) { if (buffer.hasCharactersRemaining() && characterPredicate(*buffer)) { ++buffer; @@ -103,7 +103,7 @@ template bool skipExactly(StringParsingBuffer bool skipExactly(StringParsingBuffer& buffer) +template bool skipExactly(StringParsingBuffer& buffer) { if (buffer.hasCharactersRemaining() && characterPredicate(*buffer)) { ++buffer; @@ -112,7 +112,7 @@ template bool skipExactly(StringParsingBuffer bool skipExactly(std::span& buffer) +template bool skipExactly(std::span& buffer) requires(std::is_same_v, Latin1Character>) { if (!buffer.empty() && characterPredicate(buffer[0])) { skip(buffer, 1); @@ -121,7 +121,7 @@ template bool skipExactly(std::span return false; } -template bool skipExactly(std::span& buffer) +template bool skipExactly(std::span& buffer) { if (!buffer.empty() && characterPredicate(buffer[0])) { skip(buffer, 1); @@ -144,7 +144,7 @@ template void skipUntil(std::spa skip(buffer, index); } -template void skipUntil(std::span& data) +template void skipUntil(std::span& data) requires(std::is_same_v, Latin1Character>) { size_t index = 0; while (index < data.size() && !characterPredicate(data[index])) @@ -152,7 +152,7 @@ template void skipUntil(std::span& skip(data, index); } -template void skipUntil(std::span& data) +template void skipUntil(std::span& data) { size_t index = 0; while (index < data.size() && !characterPredicate(data[index])) @@ -160,13 +160,13 @@ template void skipUntil(std::span& skip(data, index); } -template void skipUntil(StringParsingBuffer& buffer) +template void skipUntil(StringParsingBuffer& buffer) { while (buffer.hasCharactersRemaining() && !characterPredicate(*buffer)) ++buffer; } -template void skipUntil(StringParsingBuffer& buffer) +template void skipUntil(StringParsingBuffer& buffer) { while (buffer.hasCharactersRemaining() && !characterPredicate(*buffer)) ++buffer; @@ -186,7 +186,7 @@ template void skipWhile(std::spa skip(buffer, index); } -template void skipWhile(std::span& data) +template void skipWhile(std::span& data) requires(std::is_same_v, Latin1Character>) { size_t index = 0; while (index < data.size() && characterPredicate(data[index])) @@ -194,7 +194,7 @@ template void skipWhile(std::span& skip(data, index); } -template void skipWhile(std::span& data) +template void skipWhile(std::span& data) { size_t index = 0; while (index < data.size() && characterPredicate(data[index])) @@ -202,13 +202,13 @@ template void skipWhile(std::span& skip(data, index); } -template void skipWhile(StringParsingBuffer& buffer) +template void skipWhile(StringParsingBuffer& buffer) { while (buffer.hasCharactersRemaining() && characterPredicate(*buffer)) ++buffer; } -template void skipWhile(StringParsingBuffer& buffer) +template void skipWhile(StringParsingBuffer& buffer) { while (buffer.hasCharactersRemaining() && characterPredicate(*buffer)) ++buffer; @@ -285,11 +285,11 @@ match_constness_t& consumeAndCastTo(std::span>(consumeSpan(data, sizeof(DestinationType)))[0]; } -// Adapt a UChar-predicate to an LChar-predicate. -template -static inline bool LCharPredicateAdapter(LChar c) { return characterPredicate(c); } +// Adapt a char16_t-predicate to an Latin1Character-predicate. +template +static inline bool Latin1CharacterPredicateAdapter(Latin1Character c) { return characterPredicate(c); } -template bool skipExactly(const LChar*& position, const LChar* end) +template bool skipExactly(const Latin1Character*& position, const Latin1Character* end) { if (position < end && characterPredicate(*position)) { ++position; @@ -298,7 +298,7 @@ template bool skipExactly(const LChar*& position return false; } -template bool skipExactly(const UChar*& position, const UChar* end) +template bool skipExactly(const char16_t*& position, const char16_t* end) { if (position < end && characterPredicate(*position)) { ++position; @@ -313,37 +313,37 @@ template void skipUntil(const Ch ++position; } -template void skipUntil(const LChar*& position, const LChar* end) +template void skipUntil(const Latin1Character*& position, const Latin1Character* end) { while (position < end && !characterPredicate(*position)) ++position; } -template void skipUntil(const UChar*& position, const UChar* end) +template void skipUntil(const char16_t*& position, const char16_t* end) { while (position < end && !characterPredicate(*position)) ++position; } -template void skipWhile(const LChar*& position, const LChar* end) +template void skipWhile(const Latin1Character*& position, const Latin1Character* end) { while (position < end && characterPredicate(*position)) ++position; } -template void skipWhile(const UChar*& position, const UChar* end) +template void skipWhile(const char16_t*& position, const char16_t* end) { while (position < end && characterPredicate(*position)) ++position; } -template void reverseSkipWhile(const LChar*& position, const LChar* start) +template void reverseSkipWhile(const Latin1Character*& position, const Latin1Character* start) { while (position >= start && characterPredicate(*position)) --position; } -template void reverseSkipWhile(const UChar*& position, const UChar* start) +template void reverseSkipWhile(const char16_t*& position, const char16_t* start) { while (position >= start && characterPredicate(*position)) --position; @@ -396,7 +396,7 @@ template constexpr bool skipCha } // namespace WTF -using WTF::LCharPredicateAdapter; +using WTF::Latin1CharacterPredicateAdapter; using WTF::clampedMoveCursorWithinSpan; using WTF::consume; using WTF::consumeAndCastTo; @@ -414,7 +414,7 @@ using WTF::skipWhile; using WTF::reverseSkipWhile; namespace WebCore { - using WTF::LCharPredicateAdapter; + using WTF::Latin1CharacterPredicateAdapter; using WTF::clampedMoveCursorWithinSpan; using WTF::consume; using WTF::consumeAndCastTo; diff --git a/Source/WTF/wtf/text/StringBuilder.cpp b/Source/WTF/wtf/text/StringBuilder.cpp index e8548813e0804..536d63f9fbc89 100644 --- a/Source/WTF/wtf/text/StringBuilder.cpp +++ b/Source/WTF/wtf/text/StringBuilder.cpp @@ -93,9 +93,9 @@ void StringBuilder::shrink(unsigned newLength) } // Allocate a fresh buffer, with a copy of the characters we are keeping. if (m_buffer->is8Bit()) - allocateBuffer(m_buffer->span8().data(), newLength); + allocateBuffer(m_buffer->span8().data(), newLength); else - allocateBuffer(m_buffer->span16().data(), newLength); + allocateBuffer(m_buffer->span16().data(), newLength); return; } @@ -106,9 +106,9 @@ void StringBuilder::shrink(unsigned newLength) void StringBuilder::reallocateBuffer(unsigned requiredCapacity) { if (is8Bit()) - reallocateBuffer(requiredCapacity); + reallocateBuffer(requiredCapacity); else - reallocateBuffer(requiredCapacity); + reallocateBuffer(requiredCapacity); } void StringBuilder::reserveCapacity(unsigned newCapacity) @@ -122,39 +122,39 @@ void StringBuilder::reserveCapacity(unsigned newCapacity) } else { if (newCapacity > m_length) { if (!m_length) - allocateBuffer(static_cast(nullptr), newCapacity); + allocateBuffer(static_cast(nullptr), newCapacity); else if (m_string.is8Bit()) - allocateBuffer(m_string.span8().data(), newCapacity); + allocateBuffer(m_string.span8().data(), newCapacity); else - allocateBuffer(m_string.span16().data(), newCapacity); + allocateBuffer(m_string.span16().data(), newCapacity); } } ASSERT(hasOverflowed() || !newCapacity || m_buffer->length() >= newCapacity); } // Alterative extendBufferForAppending that can be called from the header without inlining. -LChar* StringBuilder::extendBufferForAppendingLChar(unsigned requiredLength) +Latin1Character* StringBuilder::extendBufferForAppendingLatin1Character(unsigned requiredLength) { - return extendBufferForAppending(requiredLength); + return extendBufferForAppending(requiredLength); } -UChar* StringBuilder::extendBufferForAppendingWithUpconvert(unsigned requiredLength) +char16_t* StringBuilder::extendBufferForAppendingWithUpconvert(unsigned requiredLength) { if (is8Bit()) { - allocateBuffer(characters(), expandedCapacity(capacity(), requiredLength)); + allocateBuffer(characters(), expandedCapacity(capacity(), requiredLength)); if (UNLIKELY(hasOverflowed())) return nullptr; - return const_cast(m_buffer->span16().data()) + std::exchange(m_length, requiredLength); + return const_cast(m_buffer->span16().data()) + std::exchange(m_length, requiredLength); } - return extendBufferForAppending(requiredLength); + return extendBufferForAppending(requiredLength); } -void StringBuilder::append(std::span characters) +void StringBuilder::append(std::span characters) { if (characters.empty() || hasOverflowed()) return; if (characters.size() == 1 && isLatin1(characters[0]) && is8Bit()) { - append(static_cast(characters[0])); + append(static_cast(characters[0])); return; } RELEASE_ASSERT(characters.size() < std::numeric_limits::max()); @@ -162,16 +162,16 @@ void StringBuilder::append(std::span characters) StringImpl::copyCharacters(destination, characters); } -void StringBuilder::append(std::span characters) +void StringBuilder::append(std::span characters) { if (characters.empty() || hasOverflowed()) return; RELEASE_ASSERT(characters.size() < std::numeric_limits::max()); if (is8Bit()) { - if (auto destination = extendBufferForAppending(saturatedSum(m_length, static_cast(characters.size())))) + if (auto destination = extendBufferForAppending(saturatedSum(m_length, static_cast(characters.size())))) StringImpl::copyCharacters(destination, characters); } else { - if (auto destination = extendBufferForAppending(saturatedSum(m_length, static_cast(characters.size())))) + if (auto destination = extendBufferForAppending(saturatedSum(m_length, static_cast(characters.size())))) StringImpl::copyCharacters(destination, characters); } } diff --git a/Source/WTF/wtf/text/StringBuilder.h b/Source/WTF/wtf/text/StringBuilder.h index 2aeb3319d9e31..be2a2adee02f4 100644 --- a/Source/WTF/wtf/text/StringBuilder.h +++ b/Source/WTF/wtf/text/StringBuilder.h @@ -56,16 +56,16 @@ class StringBuilder { template void append(const StringTypes&...); // FIXME: We should keep these overloads only if optimizations make them more efficient than the single-argument form of the variadic append above. - WTF_EXPORT_PRIVATE void append(std::span); - WTF_EXPORT_PRIVATE void append(std::span); + WTF_EXPORT_PRIVATE void append(std::span); + WTF_EXPORT_PRIVATE void append(std::span); void append(const AtomString& string) { append(string.string()); } void append(const String&); void append(StringView); void append(ASCIILiteral); void append(const char*) = delete; // Pass ASCIILiteral or span instead. - void append(UChar); - void append(LChar); - void append(char character) { append(byteCast(character)); } + void append(char16_t); + void append(Latin1Character); + void append(char character) { append(byteCast(character)); } template void appendFromAdapters(const StringTypeAdapters&...); @@ -84,13 +84,13 @@ class StringBuilder { unsigned length() const; operator StringView() const; - UChar operator[](unsigned i) const; + char16_t operator[](unsigned i) const; bool is8Bit() const; - std::span span8() const { return { characters(), length() }; } - std::span span16() const { return { characters(), length() }; } - template std::span span() const { return std::span(characters(), length()); } - + std::span span8() const LIFETIME_BOUND { return span(); } + std::span span16() const LIFETIME_BOUND { return span(); } + template std::span span() const LIFETIME_BOUND { return std::span(characters(), length()); } + unsigned capacity() const; WTF_EXPORT_PRIVATE void reserveCapacity(unsigned newCapacity); @@ -110,8 +110,8 @@ class StringBuilder { template CharacterType* extendBufferForAppending(unsigned requiredLength); template CharacterType* extendBufferForAppendingSlowCase(unsigned requiredLength); - WTF_EXPORT_PRIVATE LChar* extendBufferForAppendingLChar(unsigned requiredLength); - WTF_EXPORT_PRIVATE UChar* extendBufferForAppendingWithUpconvert(unsigned requiredLength); + WTF_EXPORT_PRIVATE Latin1Character* extendBufferForAppendingLatin1Character(unsigned requiredLength); + WTF_EXPORT_PRIVATE char16_t* extendBufferForAppendingWithUpconvert(unsigned requiredLength); WTF_EXPORT_PRIVATE void reifyString() const; @@ -156,11 +156,11 @@ inline void StringBuilder::swap(StringBuilder& other) inline StringBuilder::operator StringView() const { if (is8Bit()) - return span(); - return span(); + return span(); + return span(); } -inline void StringBuilder::append(UChar character) +inline void StringBuilder::append(char16_t character) { if (m_buffer && m_length < m_buffer->length() && m_string.isNull()) { if (!m_buffer->is8Bit()) { @@ -168,14 +168,14 @@ inline void StringBuilder::append(UChar character) return; } if (isLatin1(character)) { - spanConstCast(m_buffer->span8())[m_length++] = static_cast(character); + spanConstCast(m_buffer->span8())[m_length++] = static_cast(character); return; } } append(WTF::span(character)); } -inline void StringBuilder::append(LChar character) +inline void StringBuilder::append(Latin1Character character) { if (m_buffer && m_length < m_buffer->length() && m_string.isNull()) { if (m_buffer->is8Bit()) @@ -276,10 +276,10 @@ inline unsigned StringBuilder::capacity() const return m_buffer ? m_buffer->length() : length(); } -inline UChar StringBuilder::operator[](unsigned i) const +inline char16_t StringBuilder::operator[](unsigned i) const { RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(i < length()); - return is8Bit() ? characters()[i] : characters()[i]; + return is8Bit() ? characters()[i] : characters()[i]; } inline bool StringBuilder::is8Bit() const @@ -308,7 +308,7 @@ template void StringBuilder::appendFromAdapters( } else { auto requiredLength = saturatedSum(m_length, adapters.length()...); if (is8Bit() && are8Bit(adapters...)) { - auto destination = extendBufferForAppendingLChar(requiredLength); + auto destination = extendBufferForAppendingLatin1Character(requiredLength); if (!destination) return; stringTypeAdapterAccumulator(destination, adapters...); @@ -349,7 +349,7 @@ template bool equal(const StringBuilder& builder, const template<> struct IntegerToStringConversionTrait { using ReturnType = void; using AdditionalArgumentType = StringBuilder; - static void flush(std::span characters, StringBuilder* builder) { builder->append(characters); } + static void flush(std::span characters, StringBuilder* builder) { builder->append(characters); } }; // Helper functor useful in generic contexts where both makeString() and StringBuilder are being used. diff --git a/Source/WTF/wtf/text/StringBuilderJSON.cpp b/Source/WTF/wtf/text/StringBuilderJSON.cpp index a1f37a447c8bf..3abf8a794c01e 100644 --- a/Source/WTF/wtf/text/StringBuilderJSON.cpp +++ b/Source/WTF/wtf/text/StringBuilderJSON.cpp @@ -36,7 +36,7 @@ void StringBuilder::appendQuotedJSONString(const String& string) auto stringLengthValue = stringLength.value(); if (is8Bit() && string.is8Bit()) { - if (auto* output = extendBufferForAppending(saturatedSum(m_length, stringLengthValue))) { + if (auto* output = extendBufferForAppending(saturatedSum(m_length, stringLengthValue))) { auto* end = output + stringLengthValue; *output++ = '"'; appendEscapedJSONStringContent(output, string.span8()); diff --git a/Source/WTF/wtf/text/StringCommon.cpp b/Source/WTF/wtf/text/StringCommon.cpp index 4a7309e260c65..6206606192f95 100644 --- a/Source/WTF/wtf/text/StringCommon.cpp +++ b/Source/WTF/wtf/text/StringCommon.cpp @@ -90,7 +90,7 @@ const double* findDoubleAlignedImpl(const double* pointer, double target, size_t } SUPPRESS_ASAN -const LChar* find8NonASCIIAlignedImpl(std::span data) +const Latin1Character* find8NonASCIIAlignedImpl(std::span data) { constexpr simde_uint8x16_t indexMask { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; @@ -110,7 +110,7 @@ const LChar* find8NonASCIIAlignedImpl(std::span data) if (simde_vmaxvq_u8(mask)) { simde_uint8x16_t ranked = simde_vornq_u8(indexMask, mask); uint8_t index = simde_vminvq_u8(ranked); - return std::bit_cast((index < length) ? cursor + index : nullptr); + return std::bit_cast((index < length) ? cursor + index : nullptr); } if (length <= stride) return nullptr; diff --git a/Source/WTF/wtf/text/StringCommon.h b/Source/WTF/wtf/text/StringCommon.h index daec2d3478de4..3b1d57f7d50a2 100644 --- a/Source/WTF/wtf/text/StringCommon.h +++ b/Source/WTF/wtf/text/StringCommon.h @@ -39,7 +39,7 @@ namespace WTF { -inline std::span span(const LChar& character) +inline std::span span(const Latin1Character& character) { return { &character, 1 }; } @@ -49,9 +49,9 @@ inline std::span span(const UChar& character) return { &character, 1 }; } -inline std::span span8(const char* string) +inline std::span span8(const char* string) { - return { byteCast(string), string ? strlen(string) : 0 }; + return { byteCast(string), string ? strlen(string) : 0 }; } inline std::span span(const char* string) @@ -72,7 +72,7 @@ template inline constexpr bool isLatin1(CharacterType ch return static_cast(character) <= static_cast(0xFF); } -template<> ALWAYS_INLINE constexpr bool isLatin1(LChar) +template<> ALWAYS_INLINE constexpr bool isLatin1(Latin1Character) { return true; } @@ -83,7 +83,7 @@ template bool equalIgnoringASC template bool equalIgnoringASCIICaseCommon(const StringClassA&, const StringClassB&); -template bool equalLettersIgnoringASCIICase(std::span, std::span lowercaseLetters); +template bool equalLettersIgnoringASCIICase(std::span, std::span lowercaseLetters); template bool equalLettersIgnoringASCIICase(std::span, ASCIILiteral); template bool equalLettersIgnoringASCIICaseCommon(const StringClass&, ASCIILiteral); @@ -92,7 +92,7 @@ bool equalIgnoringASCIICase(const char*, const char*); // Do comparisons 8 or 4 bytes-at-a-time on architectures where it's safe. #if (CPU(X86_64) || CPU(ARM64)) && !ASAN_ENABLED -ALWAYS_INLINE bool equal(const LChar* aLChar, std::span bLChar) +ALWAYS_INLINE bool equal(const Latin1Character* aLChar, std::span bLChar) { ASSERT(bLChar.size() <= std::numeric_limits::max()); unsigned length = bLChar.size(); @@ -193,7 +193,7 @@ ALWAYS_INLINE bool equal(const UChar* aUChar, std::span bUChar) } } #elif CPU(X86) && !ASAN_ENABLED -ALWAYS_INLINE bool equal(const LChar* aLChar, std::span bLChar) +ALWAYS_INLINE bool equal(const Latin1Character* aLChar, std::span bLChar) { ASSERT(bLChar.size() <= std::numeric_limits::max()); unsigned length = bLChar.size(); @@ -212,8 +212,8 @@ ALWAYS_INLINE bool equal(const LChar* aLChar, std::span bLChar) length &= 3; if (length) { - const LChar* aRemainder = byteCast(a); - const LChar* bRemainder = byteCast(b); + const Latin1Character* aRemainder = byteCast(a); + const Latin1Character* bRemainder = byteCast(b); for (unsigned i = 0; i < length; ++i) { if (aRemainder[i] != bRemainder[i]) @@ -245,125 +245,12 @@ ALWAYS_INLINE bool equal(const UChar* aUChar, std::span bUChar) return true; } -#elif OS(DARWIN) && WTF_ARM_ARCH_AT_LEAST(7) && !ASAN_ENABLED -ALWAYS_INLINE bool equal(const LChar* a, std::span bSpan) -{ - ASSERT(b.size() <= std::numeric_limits::max()); - auto* b = bSpan.data(); - unsigned length = bSpan.size(); - - bool isEqual = false; - uint32_t aValue; - uint32_t bValue; - asm("subs %[length], #4\n" - "blo 2f\n" - - "0:\n" // Label 0 = Start of loop over 32 bits. - "ldr %[aValue], [%[a]], #4\n" - "ldr %[bValue], [%[b]], #4\n" - "cmp %[aValue], %[bValue]\n" - "bne 66f\n" - "subs %[length], #4\n" - "bhs 0b\n" - - // At this point, length can be: - // -0: 00000000000000000000000000000000 (0 bytes left) - // -1: 11111111111111111111111111111111 (3 bytes left) - // -2: 11111111111111111111111111111110 (2 bytes left) - // -3: 11111111111111111111111111111101 (1 byte left) - // -4: 11111111111111111111111111111100 (length was 0) - // The pointers are at the correct position. - "2:\n" // Label 2 = End of loop over 32 bits, check for pair of characters. - "tst %[length], #2\n" - "beq 1f\n" - "ldrh %[aValue], [%[a]], #2\n" - "ldrh %[bValue], [%[b]], #2\n" - "cmp %[aValue], %[bValue]\n" - "bne 66f\n" - - "1:\n" // Label 1 = Check for a single character left. - "tst %[length], #1\n" - "beq 42f\n" - "ldrb %[aValue], [%[a]]\n" - "ldrb %[bValue], [%[b]]\n" - "cmp %[aValue], %[bValue]\n" - "bne 66f\n" - - "42:\n" // Label 42 = Success. - "mov %[isEqual], #1\n" - "66:\n" // Label 66 = End without changing isEqual to 1. - : [length]"+r"(length), [isEqual]"+r"(isEqual), [a]"+r"(a), [b]"+r"(b), [aValue]"+r"(aValue), [bValue]"+r"(bValue) - : - : - ); - return isEqual; -} - -ALWAYS_INLINE bool equal(const UChar* a, std::span bSpan) -{ - ASSERT(b.size() <= std::numeric_limits::max()); - auto* b = bSpan.data(); - unsigned length = bSpan.size(); - - bool isEqual = false; - uint32_t aValue; - uint32_t bValue; - asm("subs %[length], #2\n" - "blo 1f\n" - - "0:\n" // Label 0 = Start of loop over 32 bits. - "ldr %[aValue], [%[a]], #4\n" - "ldr %[bValue], [%[b]], #4\n" - "cmp %[aValue], %[bValue]\n" - "bne 66f\n" - "subs %[length], #2\n" - "bhs 0b\n" - - // At this point, length can be: - // -0: 00000000000000000000000000000000 (0 bytes left) - // -1: 11111111111111111111111111111111 (1 character left, 2 bytes) - // -2: 11111111111111111111111111111110 (length was zero) - // The pointers are at the correct position. - "1:\n" // Label 1 = Check for a single character left. - "tst %[length], #1\n" - "beq 42f\n" - "ldrh %[aValue], [%[a]]\n" - "ldrh %[bValue], [%[b]]\n" - "cmp %[aValue], %[bValue]\n" - "bne 66f\n" - - "42:\n" // Label 42 = Success. - "mov %[isEqual], #1\n" - "66:\n" // Label 66 = End without changing isEqual to 1. - : [length]"+r"(length), [isEqual]"+r"(isEqual), [a]"+r"(a), [b]"+r"(b), [aValue]"+r"(aValue), [bValue]"+r"(bValue) - : - : - ); - return isEqual; -} -#elif !ASAN_ENABLED -ALWAYS_INLINE bool equal(const LChar* a, std::span b) { return !memcmp(a, b.data(), b.size()); } -ALWAYS_INLINE bool equal(const UChar* a, std::span b) { return !memcmp(a, b.data(), b.size_bytes()); } #else -ALWAYS_INLINE bool equal(const LChar* a, std::span b) -{ - for (size_t i = 0; i < b.size(); ++i) { - if (a[i] != b[i]) - return false; - } - return true; -} -ALWAYS_INLINE bool equal(const UChar* a, std::span b) -{ - for (size_t i = 0; i < b.size(); ++i) { - if (a[i] != b[i]) - return false; - } - return true; -} +ALWAYS_INLINE bool equal(const Latin1Character* a, std::span b) { return !memcmp(a, b.data(), b.size()); } +ALWAYS_INLINE bool equal(const char16_t* a, std::span b) { return !memcmp(a, b.data(), b.size_bytes()); } #endif -ALWAYS_INLINE bool equal(const LChar* a, std::span b) +ALWAYS_INLINE bool equal(const Latin1Character* a, std::span b) { #if CPU(ARM64) ASSERT(b.size() <= std::numeric_limits::max()); @@ -383,7 +270,7 @@ ALWAYS_INLINE bool equal(const LChar* a, std::span b) return true; } if (length >= 4) { - auto read4 = [](const LChar* p) ALWAYS_INLINE_LAMBDA { + auto read4 = [](const Latin1Character* p) ALWAYS_INLINE_LAMBDA { // Copy 32 bits and expand to 64 bits. uint32_t v32 = unalignedLoad(p); uint64_t v64 = static_cast(v32); @@ -394,7 +281,7 @@ ALWAYS_INLINE bool equal(const LChar* a, std::span b) return static_cast(read4(a) == unalignedLoad(b.data())) & static_cast(read4(a + (length % 4)) == unalignedLoad(b.data() + (length % 4))); } if (length >= 2) { - auto read2 = [](const LChar* p) ALWAYS_INLINE_LAMBDA { + auto read2 = [](const Latin1Character* p) ALWAYS_INLINE_LAMBDA { // Copy 16 bits and expand to 32 bits. uint16_t v16 = unalignedLoad(p); uint32_t v32 = static_cast(v16); @@ -414,7 +301,7 @@ ALWAYS_INLINE bool equal(const LChar* a, std::span b) #endif } -ALWAYS_INLINE bool equal(const UChar* a, std::span b) +ALWAYS_INLINE bool equal(const char16_t* a, std::span b) { return equal(b.data(), { a, b.size() }); } @@ -700,20 +587,20 @@ ALWAYS_INLINE const double* findDouble(const double* pointer, double target, siz } #endif -WTF_EXPORT_PRIVATE const LChar* find8NonASCIIAlignedImpl(std::span); -WTF_EXPORT_PRIVATE const UChar* find16NonASCIIAlignedImpl(std::span); +WTF_EXPORT_PRIVATE const Latin1Character* find8NonASCIIAlignedImpl(std::span); +WTF_EXPORT_PRIVATE const char16_t* find16NonASCIIAlignedImpl(std::span); #if CPU(ARM64) -ALWAYS_INLINE const LChar* find8NonASCII(std::span data) +ALWAYS_INLINE const Latin1Character* find8NonASCII(std::span data) { constexpr size_t thresholdLength = 16; - static_assert(!(thresholdLength % (16 / sizeof(LChar))), "length threshold should be 16-byte aligned to make find8NonASCIIAlignedImpl simpler"); + static_assert(!(thresholdLength % (16 / sizeof(Latin1Character))), "length threshold should be 16-byte aligned to make find8NonASCIIAlignedImpl simpler"); auto* pointer = data.data(); auto length = data.size(); uintptr_t unaligned = reinterpret_cast(pointer) & 0xf; size_t index = 0; - size_t runway = std::min(thresholdLength - (unaligned / sizeof(LChar)), length); + size_t runway = std::min(thresholdLength - (unaligned / sizeof(Latin1Character)), length); for (; index < runway; ++index) { if (!isASCII(pointer[index])) return pointer + index; @@ -778,16 +665,16 @@ inline size_t find(std::span characters, CharacterType matc return notFound; } -ALWAYS_INLINE size_t find(std::span characters, LChar matchCharacter, size_t index = 0) +ALWAYS_INLINE size_t find(std::span characters, Latin1Character matchCharacter, size_t index = 0) { return find(characters, static_cast(matchCharacter), index); } -inline size_t find(std::span characters, UChar matchCharacter, size_t index = 0) +inline size_t find(std::span characters, char16_t matchCharacter, size_t index = 0) { if (!isLatin1(matchCharacter)) return notFound; - return find(characters, static_cast(matchCharacter), index); + return find(characters, static_cast(matchCharacter), index); } template @@ -817,7 +704,7 @@ ALWAYS_INLINE static size_t reverseFindInner(std::span inline bool equalLettersIgnoringASCIICaseWithLength(std::span characters, std::span lowercaseLetters, size_t length) +template inline bool equalLettersIgnoringASCIICaseWithLength(std::span characters, std::span lowercaseLetters, size_t length) { ASSERT(characters.size() >= length); ASSERT(lowercaseLetters.size() >= length); @@ -828,14 +715,14 @@ template inline bool equalLettersIgnoringASCIICaseWithLe return true; } -template inline bool equalLettersIgnoringASCIICase(std::span characters, std::span lowercaseLetters) +template inline bool equalLettersIgnoringASCIICase(std::span characters, std::span lowercaseLetters) { return characters.size() == lowercaseLetters.size() && equalLettersIgnoringASCIICaseWithLength(characters, lowercaseLetters, lowercaseLetters.size()); } template inline bool equalLettersIgnoringASCIICase(std::span characters, std::span lowercaseLetters) { - return equalLettersIgnoringASCIICase(characters, byteCast(lowercaseLetters)); + return equalLettersIgnoringASCIICase(characters, byteCast(lowercaseLetters)); } template inline bool equalLettersIgnoringASCIICase(std::span characters, ASCIILiteral lowercaseLetters) @@ -843,7 +730,7 @@ template inline bool equalLettersIgnoringASCIICase(std:: return equalLettersIgnoringASCIICase(characters, lowercaseLetters.span8()); } -template bool inline hasPrefixWithLettersIgnoringASCIICaseCommon(const StringClass& string, std::span lowercaseLetters) +template bool inline hasPrefixWithLettersIgnoringASCIICaseCommon(const StringClass& string, std::span lowercaseLetters) { #if ASSERT_ENABLED ASSERT(lowercaseLetters.front()); @@ -858,14 +745,14 @@ template bool inline hasPrefixWithLettersIgnoringASCIICase } // This is intentionally not marked inline because it's used often and is not speed-critical enough to want it inlined everywhere. -template bool equalLettersIgnoringASCIICaseCommon(const StringClass& string, std::span literal) +template bool equalLettersIgnoringASCIICaseCommon(const StringClass& string, std::span literal) { if (string.length() != literal.size()) return false; return hasPrefixWithLettersIgnoringASCIICaseCommon(string, literal); } -template bool startsWithLettersIgnoringASCIICaseCommon(const StringClass& string, std::span prefix) +template bool startsWithLettersIgnoringASCIICaseCommon(const StringClass& string, std::span prefix) { if (prefix.empty()) return true; @@ -1116,12 +1003,12 @@ inline void copyElements(uint8_t* __restrict destination, const uint64_t* __rest *destination++ = *source++; } -inline void copyElements(UChar* __restrict destination, const LChar* __restrict source, size_t length) +inline void copyElements(char16_t* __restrict destination, const Latin1Character* __restrict source, size_t length) { copyElements(std::bit_cast(destination), std::bit_cast(source), length); } -inline void copyElements(LChar* __restrict destination, const UChar* __restrict source, size_t length) +inline void copyElements(Latin1Character* __restrict destination, const char16_t* __restrict source, size_t length) { copyElements(std::bit_cast(destination), std::bit_cast(source), length); } diff --git a/Source/WTF/wtf/text/StringConcatenate.h b/Source/WTF/wtf/text/StringConcatenate.h index 6d4b575c606a6..183adb83a4dca 100644 --- a/Source/WTF/wtf/text/StringConcatenate.h +++ b/Source/WTF/wtf/text/StringConcatenate.h @@ -77,7 +77,7 @@ template<> class StringTypeAdapter { unsigned length() const { return 1; } bool is8Bit() const { return isLatin1(m_character); } - void writeTo(LChar* destination) const + void writeTo(Latin1Character* destination) const { ASSERT(is8Bit()); *destination = m_character; @@ -99,7 +99,7 @@ template<> class StringTypeAdapter { unsigned length() const { return U16_LENGTH(m_character); } bool is8Bit() const { return isLatin1(m_character); } - void writeTo(LChar* destination) const + void writeTo(Latin1Character* destination) const { ASSERT(is8Bit()); *destination = m_character; @@ -125,9 +125,9 @@ inline unsigned stringLength(size_t length) return static_cast(length); } -template<> class StringTypeAdapter { +template<> class StringTypeAdapter { public: - StringTypeAdapter(const LChar* characters) + StringTypeAdapter(const Latin1Character* characters) : m_characters { characters } , m_length { computeLength(characters) } { @@ -138,12 +138,12 @@ template<> class StringTypeAdapter { template void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, { m_characters, m_length }); } private: - static unsigned computeLength(const LChar* characters) + static unsigned computeLength(const Latin1Character* characters) { return stringLength(std::strlen(byteCast(characters))); } - const LChar* m_characters; + const Latin1Character* m_characters; unsigned m_length; }; @@ -157,8 +157,8 @@ template<> class StringTypeAdapter { unsigned length() const { return m_length; } bool is8Bit() const { return !m_length; } - void writeTo(LChar*) const { ASSERT(!m_length); } - void writeTo(UChar* destination) const { StringImpl::copyCharacters(destination, { m_characters, m_length }); } + void writeTo(Latin1Character*) const { ASSERT(!m_length); } + void writeTo(char16_t* destination) const { StringImpl::copyCharacters(destination, { m_characters, m_length }); } private: static unsigned computeLength(const UChar* characters) @@ -186,7 +186,7 @@ template class StringTypeAdapter void writeTo(DestinationCharacterType* destination) const { - using CharacterTypeForString = std::conditional_t; + using CharacterTypeForString = std::conditional_t; static_assert(sizeof(CharacterTypeForString) == sizeof(CharacterType)); StringImpl::copyCharacters(destination, { reinterpret_cast(m_characters), m_length }); } @@ -204,10 +204,10 @@ template<> class StringTypeAdapter : public StringTypeAdapter class StringTypeAdapter : public StringTypeAdapter, void> { +template<> class StringTypeAdapter : public StringTypeAdapter, void> { public: StringTypeAdapter(ASCIILiteral characters) - : StringTypeAdapter, void> { characters.span8() } + : StringTypeAdapter, void> { characters.span8() } { } }; @@ -301,8 +301,8 @@ template<> class StringTypeAdapter { unsigned length() const { return m_characters.lengthUTF16; } bool is8Bit() const { return m_characters.isAllASCII; } - void writeTo(LChar* destination) const { memcpy(destination, m_characters.characters.data(), m_characters.lengthUTF16); } - void writeTo(UChar* destination) const { Unicode::convert(m_characters.characters, std::span { destination, m_characters.lengthUTF16 }); } + void writeTo(Latin1Character* destination) const { memcpy(destination, m_characters.characters.data(), m_characters.lengthUTF16); } + void writeTo(char16_t* destination) const { Unicode::convert(m_characters.characters, std::span { destination, m_characters.lengthUTF16 }); } private: Unicode::CheckedUTF8 m_characters; @@ -354,14 +354,14 @@ template class StringTypeAdapter struct PaddingSpecification { - LChar character; + Latin1Character character; unsigned length; UnderlyingElementType underlyingElement; }; template PaddingSpecification pad(char character, unsigned length, UnderlyingElementType element) { - return { byteCast(character), length, element }; + return { byteCast(character), length, element }; } template class StringTypeAdapter> { diff --git a/Source/WTF/wtf/text/StringConcatenateNumbers.h b/Source/WTF/wtf/text/StringConcatenateNumbers.h index 26306b8ea745f..6f18ac2f01f49 100644 --- a/Source/WTF/wtf/text/StringConcatenateNumbers.h +++ b/Source/WTF/wtf/text/StringConcatenateNumbers.h @@ -80,7 +80,7 @@ class StringTypeAdapter void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, span()); } private: - std::span span() const { return spanReinterpretCast(std::span { m_buffer }).first(m_length); } + std::span span() const { return spanReinterpretCast(std::span { m_buffer }).first(m_length); } NumberToStringBuffer m_buffer; unsigned m_length; @@ -106,8 +106,8 @@ class FormattedNumber { } unsigned length() const { return m_length; } - const LChar* buffer() const { return byteCast(&m_buffer[0]); } - std::span span() const { return spanReinterpretCast(std::span { m_buffer }).first(m_length); } + const Latin1Character* buffer() const { return byteCast(&m_buffer[0]); } + std::span span() const { return spanReinterpretCast(std::span { m_buffer }).first(m_length); } private: NumberToStringBuffer m_buffer; @@ -141,8 +141,8 @@ class FormattedCSSNumber { } unsigned length() const { return m_length; } - const LChar* buffer() const { return byteCast(&m_buffer[0]); } - std::span span() const { return spanReinterpretCast(std::span { m_buffer }).first(m_length); } + const Latin1Character* buffer() const { return byteCast(&m_buffer[0]); } + std::span span() const { return spanReinterpretCast(std::span { m_buffer }).first(m_length); } private: NumberToCSSStringBuffer m_buffer; diff --git a/Source/WTF/wtf/text/StringHasher.h b/Source/WTF/wtf/text/StringHasher.h index 329f26494beb3..3fe42eaf7239b 100644 --- a/Source/WTF/wtf/text/StringHasher.h +++ b/Source/WTF/wtf/text/StringHasher.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include namespace WTF { diff --git a/Source/WTF/wtf/text/StringImpl.cpp b/Source/WTF/wtf/text/StringImpl.cpp index 3c4b20ae32e5f..183a16a8dce31 100644 --- a/Source/WTF/wtf/text/StringImpl.cpp +++ b/Source/WTF/wtf/text/StringImpl.cpp @@ -140,11 +140,11 @@ StringImpl::~StringImpl() case BufferOwned: // We use m_data8, but since it is a union with m_data16 this works either way. ASSERT(m_data8); - StringImplMalloc::free(const_cast(m_data8)); + StringImplMalloc::free(const_cast(m_data8)); break; case BufferExternal: { auto* external = static_cast(this); - external->freeExternalBuffer(const_cast(m_data8), sizeInBytes()); + external->freeExternalBuffer(const_cast(m_data8), sizeInBytes()); external->m_free.~ExternalStringImplFreeFunction(); break; } @@ -161,13 +161,13 @@ void StringImpl::destroy(StringImpl* stringImpl) StringImplMalloc::free(stringImpl); } -Ref StringImpl::createWithoutCopyingNonEmpty(std::span characters) +Ref StringImpl::createWithoutCopyingNonEmpty(std::span characters) { ASSERT(!characters.empty()); return adoptRef(*new StringImpl(characters, ConstructWithoutCopying)); } -Ref StringImpl::createWithoutCopyingNonEmpty(std::span characters) +Ref StringImpl::createWithoutCopyingNonEmpty(std::span characters) { ASSERT(!characters.empty()); return adoptRef(*new StringImpl(characters, ConstructWithoutCopying)); @@ -197,15 +197,15 @@ template inline Ref StringImpl::createUninit return constructInternal(*string, length); } -template Ref StringImpl::createUninitializedInternalNonEmpty(size_t length, std::span& data); -template Ref StringImpl::createUninitializedInternalNonEmpty(size_t length, std::span& data); +template Ref StringImpl::createUninitializedInternalNonEmpty(size_t length, std::span& data); +template Ref StringImpl::createUninitializedInternalNonEmpty(size_t length, std::span& data); -Ref StringImpl::createUninitialized(size_t length, std::span& data) +Ref StringImpl::createUninitialized(size_t length, std::span& data) { return createUninitializedInternal(length, data); } -Ref StringImpl::createUninitialized(size_t length, std::span& data) +Ref StringImpl::createUninitialized(size_t length, std::span& data) { return createUninitializedInternal(length, data); } @@ -234,15 +234,15 @@ template inline Ref StringImpl::createUninit return constructInternal(*string, length); } -template Ref StringImpl::createUninitializedInternalNonEmpty(size_t length, LChar*& data); -template Ref StringImpl::createUninitializedInternalNonEmpty(size_t length, UChar*& data); +template Ref StringImpl::createUninitializedInternalNonEmpty(size_t length, Latin1Character*& data); +template Ref StringImpl::createUninitializedInternalNonEmpty(size_t length, char16_t*& data); -Ref StringImpl::createUninitialized(size_t length, LChar*& data) +Ref StringImpl::createUninitialized(size_t length, Latin1Character*& data) { return createUninitializedInternal(length, data); } -Ref StringImpl::createUninitialized(size_t length, UChar*& data) +Ref StringImpl::createUninitialized(size_t length, char16_t*& data) { return createUninitializedInternal(length, data); } @@ -270,27 +270,27 @@ template inline Expected, UTF8Conversion return constructInternal(*string, length); } -Ref StringImpl::reallocate(Ref&& originalString, unsigned length, LChar*& data) +Ref StringImpl::reallocate(Ref&& originalString, unsigned length, Latin1Character*& data) { auto expectedStringImpl = tryReallocate(WTFMove(originalString), length, data); RELEASE_ASSERT(expectedStringImpl); return WTFMove(expectedStringImpl.value()); } -Ref StringImpl::reallocate(Ref&& originalString, unsigned length, UChar*& data) +Ref StringImpl::reallocate(Ref&& originalString, unsigned length, char16_t*& data) { auto expectedStringImpl = tryReallocate(WTFMove(originalString), length, data); RELEASE_ASSERT(expectedStringImpl); return WTFMove(expectedStringImpl.value()); } -Expected, UTF8ConversionError> StringImpl::tryReallocate(Ref&& originalString, unsigned length, LChar*& data) +Expected, UTF8ConversionError> StringImpl::tryReallocate(Ref&& originalString, unsigned length, Latin1Character*& data) { ASSERT(originalString->is8Bit()); return reallocateInternal(WTFMove(originalString), length, data); } -Expected, UTF8ConversionError> StringImpl::tryReallocate(Ref&& originalString, unsigned length, UChar*& data) +Expected, UTF8ConversionError> StringImpl::tryReallocate(Ref&& originalString, unsigned length, char16_t*& data) { ASSERT(!originalString->is8Bit()); return reallocateInternal(WTFMove(originalString), length, data); @@ -306,17 +306,17 @@ template inline Ref StringImpl::createIntern return string; } -Ref StringImpl::create(std::span characters) +Ref StringImpl::create(std::span characters) { return createInternal(characters); } -Ref StringImpl::create(std::span characters) +Ref StringImpl::create(std::span characters) { return createInternal(characters); } -Ref StringImpl::createStaticStringImpl(std::span characters) +Ref StringImpl::createStaticStringImpl(std::span characters) { if (characters.empty()) return *empty(); @@ -326,7 +326,7 @@ Ref StringImpl::createStaticStringImpl(std::span charac return result; } -Ref StringImpl::createStaticStringImpl(std::span characters) +Ref StringImpl::createStaticStringImpl(std::span characters) { if (characters.empty()) return *empty(); @@ -336,19 +336,19 @@ Ref StringImpl::createStaticStringImpl(std::span charac return result; } -Ref StringImpl::create8BitIfPossible(std::span characters) +Ref StringImpl::create8BitIfPossible(std::span characters) { if (characters.empty()) return *empty(); - std::span data; + std::span data; auto string = createUninitializedInternalNonEmpty(characters.size(), data); size_t i = 0; for (auto character : characters) { if (!isLatin1(character)) return create(characters); - data[i++] = static_cast(character); + data[i++] = static_cast(character); } return string; @@ -390,7 +390,7 @@ Ref StringImpl::convertToLowercaseWithoutLocale() // First scan the string for uppercase and non-ASCII characters: if (is8Bit()) { for (unsigned i = 0; i < m_length; ++i) { - LChar character = m_data8[i]; + Latin1Character character = m_data8[i]; if (UNLIKELY(!isASCII(character) || isASCIIUpper(character))) return convertToLowercaseWithoutLocaleStartingAtFailingIndex8Bit(i); } @@ -402,7 +402,7 @@ Ref StringImpl::convertToLowercaseWithoutLocale() unsigned ored = 0; for (unsigned i = 0; i < m_length; ++i) { - UChar character = m_data16[i]; + char16_t character = m_data16[i]; if (UNLIKELY(isASCIIUpper(character))) noUpper = false; ored |= character; @@ -412,7 +412,7 @@ Ref StringImpl::convertToLowercaseWithoutLocale() return *this; if (!(ored & ~0x7F)) { - std::span data16; + std::span data16; auto newImpl = createUninitializedInternalNonEmpty(m_length, data16); for (unsigned i = 0; i < m_length; ++i) data16[i] = toASCIILower(m_data16[i]); @@ -424,7 +424,7 @@ Ref StringImpl::convertToLowercaseWithoutLocale() int32_t length = m_length; // Do a slower implementation for cases that include non-ASCII characters. - std::span data16; + std::span data16; auto newImpl = createUninitializedInternalNonEmpty(m_length, data16); UErrorCode status = U_ZERO_ERROR; @@ -443,7 +443,7 @@ Ref StringImpl::convertToLowercaseWithoutLocale() Ref StringImpl::convertToLowercaseWithoutLocaleStartingAtFailingIndex8Bit(unsigned failingIndex) { ASSERT(is8Bit()); - std::span data8; + std::span data8; auto newImpl = createUninitializedInternalNonEmpty(m_length, data8); for (unsigned i = 0; i < failingIndex; ++i) { @@ -453,12 +453,12 @@ Ref StringImpl::convertToLowercaseWithoutLocaleStartingAtFailingInde } for (unsigned i = failingIndex; i < m_length; ++i) { - LChar character = m_data8[i]; + Latin1Character character = m_data8[i]; if (isASCII(character)) data8[i] = toASCIILower(character); else { ASSERT(isLatin1(u_tolower(character))); - data8[i] = static_cast(u_tolower(character)); + data8[i] = static_cast(u_tolower(character)); } } @@ -478,7 +478,7 @@ Ref StringImpl::convertToUppercaseWithoutLocale() // First scan the string for uppercase and non-ASCII characters: if (is8Bit()) { for (unsigned i = 0; i < m_length; ++i) { - LChar character = m_data8[i]; + Latin1Character character = m_data8[i]; if (UNLIKELY(!isASCII(character) || isASCIILower(character))) return convertToUppercaseWithoutLocaleStartingAtFailingIndex8Bit(i); } @@ -490,7 +490,7 @@ Ref StringImpl::convertToUppercaseWithoutLocale() Ref StringImpl::convertToUppercaseWithoutLocaleStartingAtFailingIndex8Bit(unsigned failingIndex) { ASSERT(is8Bit()); - std::span destination; + std::span destination; auto newImpl = createUninitialized(m_length, destination); for (unsigned i = 0; i < failingIndex; ++i) { @@ -502,7 +502,7 @@ Ref StringImpl::convertToUppercaseWithoutLocaleStartingAtFailingInde // Do a faster loop for the case where all the characters are ASCII. unsigned ored = 0; for (unsigned i = failingIndex; i < m_length; ++i) { - LChar character = m_data8[i]; + Latin1Character character = m_data8[i]; ored |= character; destination[i] = toASCIIUpper(character); } @@ -516,16 +516,16 @@ Ref StringImpl::convertToUppercaseWithoutLocaleStartingAtFailingInde // 1. Some Latin-1 characters when converted to upper case are 16 bit characters. // 2. Lower case sharp-S converts to "SS" (two characters) for (unsigned i = 0; i < m_length; ++i) { - LChar character = m_data8[i]; + Latin1Character character = m_data8[i]; if (UNLIKELY(character == smallLetterSharpS)) ++numberSharpSCharacters; ASSERT(u_toupper(character) <= 0xFFFF); - UChar upper = u_toupper(character); + char16_t upper = u_toupper(character); if (UNLIKELY(!isLatin1(upper))) { // Since this upper-cased character does not fit in an 8-bit string, we need to take the 16-bit path. return convertToUppercaseWithoutLocaleUpconvert(); } - destination[i] = static_cast(upper); + destination[i] = static_cast(upper); } if (!numberSharpSCharacters) @@ -538,13 +538,13 @@ Ref StringImpl::convertToUppercaseWithoutLocaleStartingAtFailingInde size_t destinationIndex = 0; for (unsigned i = 0; i < m_length; ++i) { - LChar character = m_data8[i]; + Latin1Character character = m_data8[i]; if (character == smallLetterSharpS) { destination[destinationIndex++] = 'S'; destination[destinationIndex++] = 'S'; } else { ASSERT(isLatin1(u_toupper(character))); - destination[destinationIndex++] = static_cast(u_toupper(character)); + destination[destinationIndex++] = static_cast(u_toupper(character)); } } @@ -556,13 +556,13 @@ Ref StringImpl::convertToUppercaseWithoutLocaleUpconvert() auto upconvertedCharacters = StringView(*this).upconvertedCharacters(); auto source16 = upconvertedCharacters.span(); - std::span data16; + std::span data16; auto newImpl = createUninitialized(source16.size(), data16); // Do a faster loop for the case where all the characters are ASCII. unsigned ored = 0; for (unsigned i = 0; i < m_length; ++i) { - UChar character = source16[i]; + char16_t character = source16[i]; ored |= character; data16[i] = toASCIIUpper(character); } @@ -585,8 +585,8 @@ Ref StringImpl::convertToUppercaseWithoutLocaleUpconvert() static inline bool needsTurkishCasingRules(const AtomString& locale) { // Either "tr" or "az" locale, with ASCII case insensitive comparison and allowing for an ignored subtag. - UChar first = locale[0]; - UChar second = locale[1]; + char16_t first = locale[0]; + char16_t second = locale[1]; return ((isASCIIAlphaCaselessEqual(first, 't') && isASCIIAlphaCaselessEqual(second, 'r')) || (isASCIIAlphaCaselessEqual(first, 'a') && isASCIIAlphaCaselessEqual(second, 'z'))) && (locale.length() == 2 || locale[2] == '-'); @@ -628,7 +628,7 @@ Ref StringImpl::convertToLowercaseWithLocale(const AtomString& local auto upconvertedCharacters = StringView(*this).upconvertedCharacters(); auto source16 = upconvertedCharacters.span(); - std::span data16; + std::span data16; auto newString = createUninitialized(source16.size(), data16); UErrorCode status = U_ZERO_ERROR; size_t realLength = u_strToLower(data16.data(), data16.size(), source16.data(), source16.size(), locale, &status); @@ -663,7 +663,7 @@ Ref StringImpl::convertToUppercaseWithLocale(const AtomString& local auto upconvertedCharacters = StringView(*this).upconvertedCharacters(); auto source16 = upconvertedCharacters.span(); - std::span data16; + std::span data16; auto newString = createUninitialized(source16.size(), data16); UErrorCode status = U_ZERO_ERROR; size_t realLength = u_strToUpper(data16.data(), data16.size(), source16.data(), source16.size(), locale, &status); @@ -702,7 +702,7 @@ Ref StringImpl::foldCase() } if (!need16BitCharacters) { - std::span data8; + std::span data8; auto folded = createUninitializedInternalNonEmpty(m_length, data8); copyCharacters(data8.data(), { m_data8, failingIndex }); for (unsigned i = failingIndex; i < m_length; ++i) { @@ -711,7 +711,7 @@ Ref StringImpl::foldCase() data8[i] = toASCIILower(character); else { ASSERT(isLatin1(u_foldCase(character, U_FOLD_CASE_DEFAULT))); - data8[i] = static_cast(u_foldCase(character, U_FOLD_CASE_DEFAULT)); + data8[i] = static_cast(u_foldCase(character, U_FOLD_CASE_DEFAULT)); } } return folded; @@ -721,7 +721,7 @@ Ref StringImpl::foldCase() bool noUpper = true; unsigned ored = 0; for (unsigned i = 0; i < m_length; ++i) { - UChar character = m_data16[i]; + char16_t character = m_data16[i]; if (UNLIKELY(isASCIIUpper(character))) noUpper = false; ored |= character; @@ -731,7 +731,7 @@ Ref StringImpl::foldCase() // String was all ASCII and no uppercase, so just return as-is. return *this; } - std::span data16; + std::span data16; auto folded = createUninitializedInternalNonEmpty(m_length, data16); for (unsigned i = 0; i < m_length; ++i) data16[i] = toASCIILower(m_data16[i]); @@ -745,7 +745,7 @@ Ref StringImpl::foldCase() auto upconvertedCharacters = StringView(*this).upconvertedCharacters(); auto source16 = upconvertedCharacters.span(); - std::span data; + std::span data; auto folded = createUninitializedInternalNonEmpty(source16.size(), data); UErrorCode status = U_ZERO_ERROR; size_t realLength = u_strFoldCase(data.data(), source16.size(), source16.data(), source16.size(), U_FOLD_CASE_DEFAULT, &status); @@ -865,8 +865,8 @@ template inline Ref St Ref StringImpl::simplifyWhiteSpace(CodeUnitMatchFunction isWhiteSpace) { if (is8Bit()) - return StringImpl::simplifyMatchedCharactersToSpace(isWhiteSpace); - return StringImpl::simplifyMatchedCharactersToSpace(isWhiteSpace); + return StringImpl::simplifyMatchedCharactersToSpace(isWhiteSpace); + return StringImpl::simplifyMatchedCharactersToSpace(isWhiteSpace); } double StringImpl::toDouble(bool* ok) @@ -883,7 +883,7 @@ float StringImpl::toFloat(bool* ok) return charactersToFloat(span16(), ok); } -size_t StringImpl::find(std::span matchString, size_t start) +size_t StringImpl::find(std::span matchString, size_t start) { ASSERT(!matchString.empty()); ASSERT(matchString.size() <= static_cast(MaxLength)); @@ -941,7 +941,7 @@ size_t StringImpl::find(std::span matchString, size_t start) return start + i; } -size_t StringImpl::reverseFind(std::span matchString, size_t start) +size_t StringImpl::reverseFind(std::span matchString, size_t start) { ASSERT(!matchString.empty()); @@ -1015,7 +1015,7 @@ size_t StringImpl::findIgnoringASCIICase(StringView matchString, size_t start) c return ::WTF::findIgnoringASCIICase(*this, matchString, start); } -size_t StringImpl::reverseFind(UChar character, size_t start) +size_t StringImpl::reverseFind(char16_t character, size_t start) { if (is8Bit()) return WTF::reverseFind(span8(), character, start); @@ -1059,8 +1059,8 @@ ALWAYS_INLINE static bool equalInner(const StringImpl& string, unsigned start, s ASSERT(start + matchString.size() <= string.length()); if (string.is8Bit()) - return equal(string.span8().data() + start, byteCast(matchString)); - return equal(string.span16().data() + start, byteCast(matchString)); + return equal(string.span8().data() + start, byteCast(matchString)); + return equal(string.span16().data() + start, byteCast(matchString)); } ALWAYS_INLINE static bool equalInner(const StringImpl& string, unsigned start, StringView matchString) @@ -1092,7 +1092,7 @@ bool StringImpl::startsWithIgnoringASCIICase(StringView prefix) const return prefix && ::WTF::startsWithIgnoringASCIICase(*this, prefix); } -bool StringImpl::startsWith(UChar character) const +bool StringImpl::startsWith(char16_t character) const { return m_length && (*this)[0] == character; } @@ -1117,7 +1117,7 @@ bool StringImpl::endsWithIgnoringASCIICase(StringView suffix) const return suffix && ::WTF::endsWithIgnoringASCIICase(*this, suffix); } -bool StringImpl::endsWith(UChar character) const +bool StringImpl::endsWith(char16_t character) const { return m_length && (*this)[m_length - 1] == character; } @@ -1132,7 +1132,7 @@ bool StringImpl::hasInfixEndingAt(StringView matchString, size_t end) const return end >= matchString.length() && equalInner(*this, end - matchString.length(), matchString); } -Ref StringImpl::replace(UChar target, UChar replacement) +Ref StringImpl::replace(char16_t target, char16_t replacement) { if (target == replacement) return *this; @@ -1144,7 +1144,7 @@ Ref StringImpl::replace(UChar target, UChar replacement) } unsigned i; for (i = 0; i != m_length; ++i) { - if (static_cast(m_data8[i]) == target) + if (static_cast(m_data8[i]) == target) break; } if (i == m_length) @@ -1174,7 +1174,7 @@ Ref StringImpl::replace(size_t position, size_t lengthToReplace, Str CRASH(); if (is8Bit() && (!string || string.is8Bit())) { - std::span data; + std::span data; auto newImpl = createUninitialized(length() - lengthToReplace + lengthToInsert, data); copyCharacters(data.data(), { m_data8, position }); if (string) @@ -1182,7 +1182,7 @@ Ref StringImpl::replace(size_t position, size_t lengthToReplace, Str copyCharacters(data.subspan(position + lengthToInsert).data(), { m_data8 + position + lengthToReplace, length() - position - lengthToReplace }); return newImpl; } - std::span data; + std::span data; auto newImpl = createUninitialized(length() - lengthToReplace + lengthToInsert, data); if (is8Bit()) copyCharacters(data.data(), { m_data8, position }); @@ -1201,7 +1201,7 @@ Ref StringImpl::replace(size_t position, size_t lengthToReplace, Str return newImpl; } -Ref StringImpl::replace(UChar pattern, StringView replacement) +Ref StringImpl::replace(char16_t pattern, StringView replacement) { if (!replacement) return *this; @@ -1210,7 +1210,7 @@ Ref StringImpl::replace(UChar pattern, StringView replacement) return replace(pattern, replacement.span16()); } -Ref StringImpl::replace(UChar pattern, std::span replacement) +Ref StringImpl::replace(char16_t pattern, std::span replacement) { ASSERT(replacement.data()); @@ -1244,7 +1244,7 @@ Ref StringImpl::replace(UChar pattern, std::span replac size_t dstOffset = 0; if (is8Bit()) { - std::span data; + std::span data; auto newImpl = createUninitialized(newSize, data); while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { @@ -1264,7 +1264,7 @@ Ref StringImpl::replace(UChar pattern, std::span replac return newImpl; } - std::span data; + std::span data; auto newImpl = createUninitialized(newSize, data); while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { @@ -1286,7 +1286,7 @@ Ref StringImpl::replace(UChar pattern, std::span replac return newImpl; } -Ref StringImpl::replace(UChar pattern, std::span replacement) +Ref StringImpl::replace(char16_t pattern, std::span replacement) { ASSERT(replacement.data()); @@ -1320,7 +1320,7 @@ Ref StringImpl::replace(UChar pattern, std::span replac size_t dstOffset = 0; if (is8Bit()) { - std::span data; + std::span data; auto newImpl = createUninitialized(newSize, data); while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { @@ -1342,7 +1342,7 @@ Ref StringImpl::replace(UChar pattern, std::span replac return newImpl; } - std::span data; + std::span data; auto newImpl = createUninitialized(newSize, data); while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { @@ -1412,7 +1412,7 @@ Ref StringImpl::replace(StringView pattern, StringView replacement) // 4. This is 16 bit and replacement is 8 bit. if (srcIs8Bit && replacementIs8Bit) { // Case 1 - std::span data; + std::span data; auto newImpl = createUninitialized(newSize, data); while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { srcSegmentLength = srcSegmentEnd - srcSegmentStart; @@ -1431,7 +1431,7 @@ Ref StringImpl::replace(StringView pattern, StringView replacement) return newImpl; } - std::span data; + std::span data; auto newImpl = createUninitialized(newSize, data); while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { srcSegmentLength = srcSegmentEnd - srcSegmentStart; @@ -1489,17 +1489,17 @@ template inline bool equalInternal(const StringImpl* a, return a->span16().front() == b.front() && equal(a->span16().data() + 1, b.subspan(1)); } -bool equal(const StringImpl* a, std::span b) +bool equal(const StringImpl* a, std::span b) { return equalInternal(a, b); } -bool equal(const StringImpl* a, std::span b) +bool equal(const StringImpl* a, std::span b) { return equalInternal(a, b); } -bool equal(const StringImpl* a, const LChar* b) +bool equal(const StringImpl* a, const Latin1Character* b) { if (!a) return !b; @@ -1511,8 +1511,8 @@ bool equal(const StringImpl* a, const LChar* b) if (a->is8Bit()) { auto aSpan = a->span8(); for (unsigned i = 0; i != length; ++i) { - LChar bc = b[i]; - LChar ac = aSpan[i]; + Latin1Character bc = b[i]; + Latin1Character ac = aSpan[i]; if (!bc) return false; if (ac != bc) @@ -1524,7 +1524,7 @@ bool equal(const StringImpl* a, const LChar* b) auto aSpan = a->span16(); for (unsigned i = 0; i != length; ++i) { - LChar bc = b[i]; + Latin1Character bc = b[i]; if (!bc) return false; if (aSpan[i] != bc) @@ -1577,14 +1577,14 @@ std::optional StringImpl::defaultWritingDirection() return std::nullopt; } -Ref StringImpl::adopt(StringBuffer&& buffer) +Ref StringImpl::adopt(StringBuffer&& buffer) { if (!buffer.length()) return *empty(); return adoptRef(*new StringImpl(buffer.releaseSpan())); } -Ref StringImpl::adopt(StringBuffer&& buffer) +Ref StringImpl::adopt(StringBuffer&& buffer) { if (!buffer.length()) return *empty(); @@ -1600,21 +1600,21 @@ size_t StringImpl::sizeInBytes() const return size + sizeof(*this); } -Expected StringImpl::utf8ForCharacters(std::span source) +Expected StringImpl::utf8ForCharacters(std::span source) { return tryGetUTF8ForCharacters([] (std::span converted) { return CString { converted }; }, source); } -Expected StringImpl::utf8ForCharacters(std::span characters, ConversionMode mode) +Expected StringImpl::utf8ForCharacters(std::span characters, ConversionMode mode) { return tryGetUTF8ForCharacters([] (std::span converted) { return CString { converted }; }, characters, mode); } -Expected StringImpl::utf8ForCharactersIntoBuffer(std::span span, ConversionMode mode, Vector& bufferVector) +Expected StringImpl::utf8ForCharactersIntoBuffer(std::span span, ConversionMode mode, Vector& bufferVector) { ASSERT(bufferVector.size() == span.size() * 3); ConversionResult result; @@ -1667,7 +1667,7 @@ unsigned StringImpl::concurrentHash() const return hash; } -bool equalIgnoringNullity(std::span a, StringImpl* b) +bool equalIgnoringNullity(std::span a, StringImpl* b) { if (!b) return a.empty(); diff --git a/Source/WTF/wtf/text/StringImpl.h b/Source/WTF/wtf/text/StringImpl.h index 3e4d7e974905b..0f87ef786f879 100644 --- a/Source/WTF/wtf/text/StringImpl.h +++ b/Source/WTF/wtf/text/StringImpl.h @@ -89,7 +89,7 @@ template struct HashAndCharactersTranslator; // Define STRING_STATS to 1 turn on runtime statistics of string sizes and memory usage. #define STRING_STATS 0 -template bool containsOnly(std::span); +template bool containsOnly(std::span); #if STRING_STATS @@ -154,8 +154,8 @@ class STRING_IMPL_ALIGNMENT StringImplShape { static constexpr unsigned MaxLength = std::numeric_limits::max(); protected: - StringImplShape(unsigned refCount, std::span, unsigned hashAndFlags); - StringImplShape(unsigned refCount, std::span, unsigned hashAndFlags); + StringImplShape(unsigned refCount, std::span, unsigned hashAndFlags); + StringImplShape(unsigned refCount, std::span, unsigned hashAndFlags); enum ConstructWithConstExprTag { ConstructWithConstExpr }; template constexpr StringImplShape(unsigned refCount, unsigned length, const char (&characters)[characterCount], unsigned hashAndFlags, ConstructWithConstExprTag); @@ -164,8 +164,8 @@ class STRING_IMPL_ALIGNMENT StringImplShape { unsigned m_refCount; unsigned m_length; union { - const LChar* m_data8; - const UChar* m_data16; + const Latin1Character* m_data8; + const char16_t* m_data16; // It seems that reinterpret_cast prevents constexpr's compile time initialization in VC++. // These are needed to avoid reinterpret_cast. const char* m_data8Char; @@ -241,25 +241,25 @@ class StringImpl : private StringImplShape { explicit StringImpl(unsigned length); // Create a StringImpl adopting ownership of the provided buffer (BufferOwned). - template StringImpl(MallocPtr, unsigned length); - template StringImpl(MallocPtr, unsigned length); - template explicit StringImpl(MallocSpan); - template explicit StringImpl(MallocSpan); + template StringImpl(MallocPtr, unsigned length); + template StringImpl(MallocPtr, unsigned length); + template explicit StringImpl(MallocSpan); + template explicit StringImpl(MallocSpan); enum ConstructWithoutCopyingTag { ConstructWithoutCopying }; - StringImpl(std::span, ConstructWithoutCopyingTag); - StringImpl(std::span, ConstructWithoutCopyingTag); + StringImpl(std::span, ConstructWithoutCopyingTag); + StringImpl(std::span, ConstructWithoutCopyingTag); // Used to create new strings that are a substring of an existing StringImpl (BufferSubstring). - StringImpl(std::span, Ref&&); - StringImpl(std::span, Ref&&); + StringImpl(std::span, Ref&&); + StringImpl(std::span, Ref&&); public: WTF_EXPORT_PRIVATE static void destroy(StringImpl*); - WTF_EXPORT_PRIVATE static Ref create(std::span); - WTF_EXPORT_PRIVATE static Ref create(std::span); - ALWAYS_INLINE static Ref create(std::span characters) { return create(byteCast(characters)); } - WTF_EXPORT_PRIVATE static Ref create8BitIfPossible(std::span); + WTF_EXPORT_PRIVATE static Ref create(std::span); + WTF_EXPORT_PRIVATE static Ref create(std::span); + ALWAYS_INLINE static Ref create(std::span characters) { return create(byteCast(characters)); } + WTF_EXPORT_PRIVATE static Ref create8BitIfPossible(std::span); // Not using create() naming to encourage developers to call create(ASCIILiteral) when they have a string literal. ALWAYS_INLINE static Ref createFromCString(const char* characters) { return create(WTF::span8(characters)); } @@ -268,35 +268,35 @@ class StringImpl : private StringImplShape { ALWAYS_INLINE static Ref create(ASCIILiteral literal) { return createWithoutCopying(literal.span8()); } - static Ref createWithoutCopying(std::span characters) { return characters.empty() ? Ref { *empty() } : createWithoutCopyingNonEmpty(characters); } - static Ref createWithoutCopying(std::span characters) { return characters.empty() ? Ref { *empty() } : createWithoutCopyingNonEmpty(characters); } - ALWAYS_INLINE static Ref createWithoutCopying(std::span characters) { return createWithoutCopying(byteCast(characters)); } + static Ref createWithoutCopying(std::span characters) { return characters.empty() ? Ref { *empty() } : createWithoutCopyingNonEmpty(characters); } + static Ref createWithoutCopying(std::span characters) { return characters.empty() ? Ref { *empty() } : createWithoutCopyingNonEmpty(characters); } + ALWAYS_INLINE static Ref createWithoutCopying(std::span characters) { return createWithoutCopying(byteCast(characters)); } - WTF_EXPORT_PRIVATE static Ref createUninitialized(size_t length, LChar*&); - WTF_EXPORT_PRIVATE static Ref createUninitialized(size_t length, UChar*&); + WTF_EXPORT_PRIVATE static Ref createUninitialized(size_t length, Latin1Character*&); + WTF_EXPORT_PRIVATE static Ref createUninitialized(size_t length, char16_t*&); template static RefPtr tryCreateUninitialized(size_t length, CharacterType*&); - WTF_EXPORT_PRIVATE static Ref createUninitialized(size_t length, std::span&); - WTF_EXPORT_PRIVATE static Ref createUninitialized(size_t length, std::span&); + WTF_EXPORT_PRIVATE static Ref createUninitialized(size_t length, std::span&); + WTF_EXPORT_PRIVATE static Ref createUninitialized(size_t length, std::span&); template static RefPtr tryCreateUninitialized(size_t length, std::span&); - static Ref createByReplacingInCharacters(std::span, UChar target, UChar replacement, size_t indexOfFirstTargetCharacter); - static Ref createByReplacingInCharacters(std::span, UChar target, UChar replacement, size_t indexOfFirstTargetCharacter); + static Ref createByReplacingInCharacters(std::span, char16_t target, char16_t replacement, size_t indexOfFirstTargetCharacter); + static Ref createByReplacingInCharacters(std::span, char16_t target, char16_t replacement, size_t indexOfFirstTargetCharacter); static Ref createStaticStringImpl(std::span characters) { - ASSERT(charactersAreAllASCII(byteCast(characters))); - return createStaticStringImpl(byteCast(characters)); + ASSERT(charactersAreAllASCII(byteCast(characters))); + return createStaticStringImpl(byteCast(characters)); } - WTF_EXPORT_PRIVATE static Ref createStaticStringImpl(std::span); - WTF_EXPORT_PRIVATE static Ref createStaticStringImpl(std::span); + WTF_EXPORT_PRIVATE static Ref createStaticStringImpl(std::span); + WTF_EXPORT_PRIVATE static Ref createStaticStringImpl(std::span); // Reallocate the StringImpl. The originalString must be only owned by the Ref, // and the buffer ownership must be BufferInternal. Just like the input pointer of realloc(), // the originalString can't be used after this function. - static Ref reallocate(Ref&& originalString, unsigned length, LChar*& data); - static Ref reallocate(Ref&& originalString, unsigned length, UChar*& data); - static Expected, UTF8ConversionError> tryReallocate(Ref&& originalString, unsigned length, LChar*& data); - static Expected, UTF8ConversionError> tryReallocate(Ref&& originalString, unsigned length, UChar*& data); + static Ref reallocate(Ref&& originalString, unsigned length, Latin1Character*& data); + static Ref reallocate(Ref&& originalString, unsigned length, char16_t*& data); + static Expected, UTF8ConversionError> tryReallocate(Ref&& originalString, unsigned length, Latin1Character*& data); + static Expected, UTF8ConversionError> tryReallocate(Ref&& originalString, unsigned length, char16_t*& data); static constexpr unsigned flagsOffset() { return OBJECT_OFFSETOF(StringImpl, m_hashAndFlags); } static constexpr unsigned flagIs8Bit() { return s_hashFlag8BitBuffer; } @@ -308,16 +308,16 @@ class StringImpl : private StringImplShape { template static Ref adopt(Vector&&); - WTF_EXPORT_PRIVATE static Ref adopt(StringBuffer&&); - WTF_EXPORT_PRIVATE static Ref adopt(StringBuffer&&); + WTF_EXPORT_PRIVATE static Ref adopt(StringBuffer&&); + WTF_EXPORT_PRIVATE static Ref adopt(StringBuffer&&); unsigned length() const { return m_length; } static constexpr ptrdiff_t lengthMemoryOffset() { return OBJECT_OFFSETOF(StringImpl, m_length); } bool isEmpty() const { return !m_length; } bool is8Bit() const { return m_hashAndFlags & s_hashFlag8BitBuffer; } - ALWAYS_INLINE std::span span8() const LIFETIME_BOUND { ASSERT(is8Bit()); return { m_data8, length() }; } - ALWAYS_INLINE std::span span16() const LIFETIME_BOUND { ASSERT(!is8Bit() || isEmpty()); return { m_data16, length() }; } + ALWAYS_INLINE std::span span8() const LIFETIME_BOUND { ASSERT(is8Bit()); return { m_data8, length() }; } + ALWAYS_INLINE std::span span16() const LIFETIME_BOUND { ASSERT(!is8Bit() || isEmpty()); return { m_data16, length() }; } template std::span span() const LIFETIME_BOUND; @@ -334,14 +334,14 @@ class StringImpl : private StringImplShape { bool isSubString() const { return bufferOwnership() == BufferSubstring; } - static WTF_EXPORT_PRIVATE Expected utf8ForCharacters(std::span characters); - static WTF_EXPORT_PRIVATE Expected utf8ForCharacters(std::span characters, ConversionMode = LenientConversion); - static WTF_EXPORT_PRIVATE Expected utf8ForCharactersIntoBuffer(std::span characters, ConversionMode, Vector&); + static WTF_EXPORT_PRIVATE Expected utf8ForCharacters(std::span characters); + static WTF_EXPORT_PRIVATE Expected utf8ForCharacters(std::span characters, ConversionMode = LenientConversion); + static WTF_EXPORT_PRIVATE Expected utf8ForCharactersIntoBuffer(std::span characters, ConversionMode, Vector&); template - static Expected>, UTF8ConversionError> tryGetUTF8ForCharacters(const Func&, std::span characters); + static Expected>, UTF8ConversionError> tryGetUTF8ForCharacters(NOESCAPE const Func&, std::span characters); template - static Expected>, UTF8ConversionError> tryGetUTF8ForCharacters(const Func&, std::span characters, ConversionMode = LenientConversion); + static Expected>, UTF8ConversionError> tryGetUTF8ForCharacters(const Func&, std::span characters, ConversionMode = LenientConversion); template Expected>, UTF8ConversionError> tryGetUTF8(const Func&, ConversionMode = LenientConversion) const; @@ -421,17 +421,17 @@ class StringImpl : private StringImplShape { return copyElements(destination, source.data(), source.size()); } - ALWAYS_INLINE static void copyCharacters(UChar* destination, std::span source) + ALWAYS_INLINE static void copyCharacters(char16_t* destination, std::span source) { - static_assert(sizeof(UChar) == sizeof(uint16_t)); - static_assert(sizeof(LChar) == sizeof(uint8_t)); + static_assert(sizeof(char16_t) == sizeof(uint16_t)); + static_assert(sizeof(Latin1Character) == sizeof(uint8_t)); return copyElements(std::bit_cast(destination), source.data(), source.size()); } - ALWAYS_INLINE static void copyCharacters(LChar* destination, std::span source) + ALWAYS_INLINE static void copyCharacters(Latin1Character* destination, std::span source) { - static_assert(sizeof(UChar) == sizeof(uint16_t)); - static_assert(sizeof(LChar) == sizeof(uint8_t)); + static_assert(sizeof(char16_t) == sizeof(uint16_t)); + static_assert(sizeof(Latin1Character) == sizeof(uint8_t)); #if ASSERT_ENABLED for (auto character : source) ASSERT(isLatin1(character)); @@ -446,8 +446,8 @@ class StringImpl : private StringImplShape { WTF_EXPORT_PRIVATE Ref substring(unsigned position, unsigned length = MaxLength); - UChar at(unsigned) const; - UChar operator[](unsigned i) const { return at(i); } + char16_t at(unsigned) const; + char16_t operator[](unsigned i) const { return at(i); } WTF_EXPORT_PRIVATE char32_t characterStartingAt(unsigned); // FIXME: Like the strict functions above, these give false for "ok" when there is trailing garbage. @@ -473,12 +473,12 @@ class StringImpl : private StringImplShape { bool containsOnlyASCII() const; bool containsOnlyLatin1() const; - template bool containsOnly() const; + template bool containsOnly() const; - size_t find(LChar character, size_t start = 0); - size_t find(char character, size_t start = 0); - size_t find(UChar character, size_t start = 0); - template>* = nullptr> + size_t find(Latin1Character, size_t start = 0); + size_t find(char, size_t start = 0); + size_t find(char16_t, size_t start = 0); + template>* = nullptr> size_t find(CodeUnitMatchFunction, size_t start = 0); ALWAYS_INLINE size_t find(ASCIILiteral literal, size_t start = 0) { return find(literal.span8(), start); } WTF_EXPORT_PRIVATE size_t find(StringView); @@ -486,27 +486,27 @@ class StringImpl : private StringImplShape { WTF_EXPORT_PRIVATE size_t findIgnoringASCIICase(StringView) const; WTF_EXPORT_PRIVATE size_t findIgnoringASCIICase(StringView, size_t start) const; - WTF_EXPORT_PRIVATE size_t reverseFind(UChar, size_t start = MaxLength); + WTF_EXPORT_PRIVATE size_t reverseFind(char16_t, size_t start = MaxLength); WTF_EXPORT_PRIVATE size_t reverseFind(StringView, size_t start = MaxLength); ALWAYS_INLINE size_t reverseFind(ASCIILiteral literal, size_t start = MaxLength) { return reverseFind(literal.span8(), start); } WTF_EXPORT_PRIVATE bool startsWith(StringView) const; WTF_EXPORT_PRIVATE bool startsWithIgnoringASCIICase(StringView) const; - WTF_EXPORT_PRIVATE bool startsWith(UChar) const; + WTF_EXPORT_PRIVATE bool startsWith(char16_t) const; WTF_EXPORT_PRIVATE bool startsWith(std::span) const; WTF_EXPORT_PRIVATE bool hasInfixStartingAt(StringView, size_t start) const; WTF_EXPORT_PRIVATE bool endsWith(StringView); WTF_EXPORT_PRIVATE bool endsWithIgnoringASCIICase(StringView) const; - WTF_EXPORT_PRIVATE bool endsWith(UChar) const; + WTF_EXPORT_PRIVATE bool endsWith(char16_t) const; WTF_EXPORT_PRIVATE bool endsWith(std::span) const; WTF_EXPORT_PRIVATE bool hasInfixEndingAt(StringView, size_t end) const; - WTF_EXPORT_PRIVATE Ref replace(UChar, UChar); - WTF_EXPORT_PRIVATE Ref replace(UChar, StringView); - ALWAYS_INLINE Ref replace(UChar pattern, std::span replacement) { return replace(pattern, byteCast(replacement)); } - WTF_EXPORT_PRIVATE Ref replace(UChar, std::span); - Ref replace(UChar, std::span); + WTF_EXPORT_PRIVATE Ref replace(char16_t, char16_t); + WTF_EXPORT_PRIVATE Ref replace(char16_t, StringView); + ALWAYS_INLINE Ref replace(char16_t pattern, std::span replacement) { return replace(pattern, byteCast(replacement)); } + WTF_EXPORT_PRIVATE Ref replace(char16_t, std::span); + Ref replace(char16_t, std::span); WTF_EXPORT_PRIVATE Ref replace(StringView, StringView); WTF_EXPORT_PRIVATE Ref replace(size_t start, size_t length, StringView); @@ -533,8 +533,8 @@ class StringImpl : private StringImplShape { // Used to create new symbol string that holds an existing [[Description]] string as a substring buffer (BufferSubstring). enum CreateSymbolTag { CreateSymbol }; - StringImpl(CreateSymbolTag, std::span); - StringImpl(CreateSymbolTag, std::span); + StringImpl(CreateSymbolTag, std::span); + StringImpl(CreateSymbolTag, std::span); // Null symbol. explicit StringImpl(CreateSymbolTag); @@ -544,8 +544,8 @@ class StringImpl : private StringImplShape { template static size_t maxInternalLength(); template static constexpr size_t tailOffset(); - WTF_EXPORT_PRIVATE size_t find(std::span, size_t start); - WTF_EXPORT_PRIVATE size_t reverseFind(std::span, size_t start); + WTF_EXPORT_PRIVATE size_t find(std::span, size_t start); + WTF_EXPORT_PRIVATE size_t reverseFind(std::span, size_t start); bool requiresCopy() const; template const T* tailPointer() const; @@ -556,8 +556,8 @@ class StringImpl : private StringImplShape { enum class CaseConvertType { Upper, Lower }; template static Ref convertASCIICase(StringImpl&, std::span); - WTF_EXPORT_PRIVATE static Ref createWithoutCopyingNonEmpty(std::span); - WTF_EXPORT_PRIVATE static Ref createWithoutCopyingNonEmpty(std::span); + WTF_EXPORT_PRIVATE static Ref createWithoutCopyingNonEmpty(std::span); + WTF_EXPORT_PRIVATE static Ref createWithoutCopyingNonEmpty(std::span); template Ref trimMatchedCharacters(CodeUnitPredicate); template ALWAYS_INLINE Ref removeCharactersImpl(std::span characters, const Predicate&); @@ -619,18 +619,18 @@ template<> struct ValueCheck { #endif // ASSERT_ENABLED WTF_EXPORT_PRIVATE bool equal(const StringImpl*, const StringImpl*); -WTF_EXPORT_PRIVATE bool equal(const StringImpl*, const LChar*); -inline bool equal(const StringImpl* a, const char* b) { return equal(a, byteCast(b)); } -WTF_EXPORT_PRIVATE bool equal(const StringImpl*, std::span); -WTF_EXPORT_PRIVATE bool equal(const StringImpl*, std::span); +WTF_EXPORT_PRIVATE bool equal(const StringImpl*, const Latin1Character*); +inline bool equal(const StringImpl* a, const char* b) { return equal(a, byteCast(b)); } +WTF_EXPORT_PRIVATE bool equal(const StringImpl*, std::span); +WTF_EXPORT_PRIVATE bool equal(const StringImpl*, std::span); ALWAYS_INLINE bool equal(const StringImpl* a, ASCIILiteral b) { return equal(a, b.span8()); } -inline bool equal(const StringImpl* a, std::span b) { return equal(a, byteCast(b)); } -inline bool equal(const LChar* a, StringImpl* b) { return equal(b, a); } -inline bool equal(const char* a, StringImpl* b) { return equal(b, byteCast(a)); } +inline bool equal(const StringImpl* a, std::span b) { return equal(a, byteCast(b)); } +inline bool equal(const Latin1Character* a, StringImpl* b) { return equal(b, a); } +inline bool equal(const char* a, StringImpl* b) { return equal(b, byteCast(a)); } WTF_EXPORT_PRIVATE bool equal(const StringImpl& a, const StringImpl& b); WTF_EXPORT_PRIVATE bool equalIgnoringNullity(StringImpl*, StringImpl*); -WTF_EXPORT_PRIVATE bool equalIgnoringNullity(std::span, StringImpl*); +WTF_EXPORT_PRIVATE bool equalIgnoringNullity(std::span, StringImpl*); bool equalIgnoringASCIICase(const StringImpl&, const StringImpl&); WTF_EXPORT_PRIVATE bool equalIgnoringASCIICase(const StringImpl*, const StringImpl*); @@ -647,22 +647,22 @@ size_t find(std::span, CodeUnitMatchFunction&&, size_t start = 0 template size_t reverseFindLineTerminator(std::span, size_t start = StringImpl::MaxLength); template size_t reverseFind(std::span, CharacterType matchCharacter, size_t start = StringImpl::MaxLength); -size_t reverseFind(std::span, LChar matchCharacter, size_t start = StringImpl::MaxLength); -size_t reverseFind(std::span, UChar matchCharacter, size_t start = StringImpl::MaxLength); +size_t reverseFind(std::span, Latin1Character matchCharacter, size_t start = StringImpl::MaxLength); +size_t reverseFind(std::span, char16_t matchCharacter, size_t start = StringImpl::MaxLength); -template bool equalIgnoringNullity(const Vector&, StringImpl*); +template bool equalIgnoringNullity(const Vector&, StringImpl*); template int codePointCompare(std::span, std::span); int codePointCompare(const StringImpl*, const StringImpl*); -bool isUnicodeWhitespace(UChar); +bool isUnicodeWhitespace(char16_t); // Deprecated as this excludes U+0085 and U+00A0 which are part of Unicode's White_Space definition: // https://www.unicode.org/Public/UCD/latest/ucd/PropList.txt -bool deprecatedIsSpaceOrNewline(UChar); +bool deprecatedIsSpaceOrNewline(char16_t); // Inverse of deprecatedIsSpaceOrNewline for predicates -bool deprecatedIsNotSpaceOrNewline(UChar); +bool deprecatedIsNotSpaceOrNewline(char16_t); // StringHash is the default hash for StringImpl* and RefPtr template struct DefaultHash; @@ -676,22 +676,22 @@ template<> struct DefaultHash>; return &impl; \ }()) -template<> ALWAYS_INLINE Ref StringImpl::constructInternal(StringImpl& string, unsigned length) +template<> ALWAYS_INLINE Ref StringImpl::constructInternal(StringImpl& string, unsigned length) { return adoptRef(*new (NotNull, &string) StringImpl { length, Force8BitConstructor }); } -template<> ALWAYS_INLINE Ref StringImpl::constructInternal(StringImpl& string, unsigned length) +template<> ALWAYS_INLINE Ref StringImpl::constructInternal(StringImpl& string, unsigned length) { return adoptRef(*new (NotNull, &string) StringImpl { length }); } -template<> ALWAYS_INLINE std::span StringImpl::span() const +template<> ALWAYS_INLINE std::span StringImpl::span() const { return span8(); } -template<> ALWAYS_INLINE std::span StringImpl::span() const +template<> ALWAYS_INLINE std::span StringImpl::span() const { return span16(); } @@ -735,19 +735,19 @@ template inline size_t reverseFind(std::span characters, LChar matchCharacter, size_t start) +ALWAYS_INLINE size_t reverseFind(std::span characters, Latin1Character matchCharacter, size_t start) { - return reverseFind(characters, static_cast(matchCharacter), start); + return reverseFind(characters, static_cast(matchCharacter), start); } -inline size_t reverseFind(std::span characters, UChar matchCharacter, size_t start) +inline size_t reverseFind(std::span characters, char16_t matchCharacter, size_t start) { if (!isLatin1(matchCharacter)) return notFound; - return reverseFind(characters, static_cast(matchCharacter), start); + return reverseFind(characters, static_cast(matchCharacter), start); } -inline size_t StringImpl::find(LChar character, size_t start) +inline size_t StringImpl::find(Latin1Character character, size_t start) { if (is8Bit()) return WTF::find(span8(), character, start); @@ -756,17 +756,17 @@ inline size_t StringImpl::find(LChar character, size_t start) ALWAYS_INLINE size_t StringImpl::find(char character, size_t start) { - return find(byteCast(character), start); + return find(byteCast(character), start); } -inline size_t StringImpl::find(UChar character, size_t start) +inline size_t StringImpl::find(char16_t character, size_t start) { if (is8Bit()) return WTF::find(span8(), character, start); return WTF::find(span16(), character, start); } -template>*> +template>*> size_t StringImpl::find(CodeUnitMatchFunction matchFunction, size_t start) { if (is8Bit()) @@ -774,7 +774,7 @@ size_t StringImpl::find(CodeUnitMatchFunction matchFunction, size_t start) return WTF::find(span16(), matchFunction, start); } -template inline bool equalIgnoringNullity(const Vector& a, StringImpl* b) +template inline bool equalIgnoringNullity(const Vector& a, StringImpl* b) { return equalIgnoringNullity(a.data(), a.size(), b); } @@ -820,25 +820,25 @@ inline int codePointCompare(const StringImpl* string1, const StringImpl* string2 return codePointCompare(string1->span16(), string2->span16()); } -// FIXME: For LChar, isUnicodeCompatibleASCIIWhitespace(character) || character == 0x0085 || character == noBreakSpace would be enough -inline bool isUnicodeWhitespace(UChar character) +// FIXME: For Latin1Character, isUnicodeCompatibleASCIIWhitespace(character) || character == 0x0085 || character == noBreakSpace would be enough +inline bool isUnicodeWhitespace(char16_t character) { return isASCII(character) ? isUnicodeCompatibleASCIIWhitespace(character) : u_isUWhiteSpace(character); } -inline bool deprecatedIsSpaceOrNewline(UChar character) +inline bool deprecatedIsSpaceOrNewline(char16_t character) { // Use isUnicodeCompatibleASCIIWhitespace() for all Latin-1 characters, which is incorrect as it // excludes U+0085 and U+00A0. return isLatin1(character) ? isUnicodeCompatibleASCIIWhitespace(character) : u_charDirection(character) == U_WHITE_SPACE_NEUTRAL; } -inline bool deprecatedIsNotSpaceOrNewline(UChar character) +inline bool deprecatedIsNotSpaceOrNewline(char16_t character) { return !deprecatedIsSpaceOrNewline(character); } -inline StringImplShape::StringImplShape(unsigned refCount, std::span data, unsigned hashAndFlags) +inline StringImplShape::StringImplShape(unsigned refCount, std::span data, unsigned hashAndFlags) : m_refCount(refCount) , m_length(data.size()) , m_data8(data.data()) @@ -847,7 +847,7 @@ inline StringImplShape::StringImplShape(unsigned refCount, std::span data, unsigned hashAndFlags) +inline StringImplShape::StringImplShape(unsigned refCount, std::span data, unsigned hashAndFlags) : m_refCount(refCount) , m_length(data.size()) , m_data16(data.data()) @@ -899,13 +899,13 @@ inline bool StringImpl::containsOnlyLatin1() const if (is8Bit()) return true; auto characters = span16(); - UChar mergedCharacterBits = 0; + char16_t mergedCharacterBits = 0; for (auto character : characters) mergedCharacterBits |= character; return isLatin1(mergedCharacterBits); } -template inline bool containsOnly(std::span characters) +template inline bool containsOnly(std::span characters) { for (auto character : characters) { if (!isSpecialCharacter(character)) @@ -914,7 +914,7 @@ template inline bool StringImpl::containsOnly() const +template inline bool StringImpl::containsOnly() const { if (is8Bit()) return WTF::containsOnly(span8()); @@ -922,7 +922,7 @@ template inline bool StringImpl::containsOnly() } inline StringImpl::StringImpl(unsigned length, Force8Bit) - : StringImplShape(s_refCountIncrement, { tailPointer(), length }, s_hashFlag8BitBuffer | StringNormal | BufferInternal) + : StringImplShape(s_refCountIncrement, { tailPointer(), length }, s_hashFlag8BitBuffer | StringNormal | BufferInternal) { ASSERT(m_data8); ASSERT(m_length); @@ -931,7 +931,7 @@ inline StringImpl::StringImpl(unsigned length, Force8Bit) } inline StringImpl::StringImpl(unsigned length) - : StringImplShape(s_refCountIncrement, { tailPointer(), length }, s_hashZeroValue | StringNormal | BufferInternal) + : StringImplShape(s_refCountIncrement, { tailPointer(), length }, s_hashZeroValue | StringNormal | BufferInternal) { ASSERT(m_data16); ASSERT(m_length); @@ -940,13 +940,13 @@ inline StringImpl::StringImpl(unsigned length) } template -inline StringImpl::StringImpl(MallocPtr characters, unsigned length) - : StringImplShape(s_refCountIncrement, { static_cast(nullptr), length }, s_hashFlag8BitBuffer | StringNormal | BufferOwned) +inline StringImpl::StringImpl(MallocPtr characters, unsigned length) + : StringImplShape(s_refCountIncrement, { static_cast(nullptr), length }, s_hashFlag8BitBuffer | StringNormal | BufferOwned) { if constexpr (std::is_same_v) m_data8 = characters.leakPtr(); else { - auto data8 = static_cast(StringImplMalloc::malloc(length * sizeof(LChar))); + auto data8 = static_cast(StringImplMalloc::malloc(length * sizeof(Latin1Character))); copyCharacters(data8, { characters.get(), length }); m_data8 = data8; } @@ -958,13 +958,13 @@ inline StringImpl::StringImpl(MallocPtr characters, unsigned leng } template -inline StringImpl::StringImpl(MallocSpan characters) - : StringImplShape(s_refCountIncrement, { static_cast(nullptr), characters.span().size() }, s_hashFlag8BitBuffer | StringNormal | BufferOwned) +inline StringImpl::StringImpl(MallocSpan characters) + : StringImplShape(s_refCountIncrement, { static_cast(nullptr), characters.span().size() }, s_hashFlag8BitBuffer | StringNormal | BufferOwned) { if constexpr (std::is_same_v) m_data8 = characters.leakSpan().data(); else { - auto* data8 = static_cast(StringImplMalloc::malloc(characters.sizeInBytes())); + auto* data8 = static_cast(StringImplMalloc::malloc(characters.sizeInBytes())); copyCharacters(data8, characters.span()); m_data8 = data8; } @@ -975,7 +975,7 @@ inline StringImpl::StringImpl(MallocSpan characters) STRING_STATS_ADD_8BIT_STRING(m_length); } -inline StringImpl::StringImpl(std::span characters, ConstructWithoutCopyingTag) +inline StringImpl::StringImpl(std::span characters, ConstructWithoutCopyingTag) : StringImplShape(s_refCountIncrement, characters, s_hashZeroValue | StringNormal | BufferInternal) { ASSERT(m_data16); @@ -984,7 +984,7 @@ inline StringImpl::StringImpl(std::span characters, ConstructWithou STRING_STATS_ADD_16BIT_STRING(m_length); } -inline StringImpl::StringImpl(std::span characters, ConstructWithoutCopyingTag) +inline StringImpl::StringImpl(std::span characters, ConstructWithoutCopyingTag) : StringImplShape(s_refCountIncrement, characters, s_hashFlag8BitBuffer | StringNormal | BufferInternal) { ASSERT(m_data8); @@ -994,13 +994,13 @@ inline StringImpl::StringImpl(std::span characters, ConstructWithou } template -inline StringImpl::StringImpl(MallocPtr characters, unsigned length) - : StringImplShape(s_refCountIncrement, { static_cast(nullptr), length }, s_hashZeroValue | StringNormal | BufferOwned) +inline StringImpl::StringImpl(MallocPtr characters, unsigned length) + : StringImplShape(s_refCountIncrement, { static_cast(nullptr), length }, s_hashZeroValue | StringNormal | BufferOwned) { if constexpr (std::is_same_v) m_data16 = characters.leakPtr(); else { - auto data16 = static_cast(StringImplMalloc::malloc(length * sizeof(UChar))); + auto data16 = static_cast(StringImplMalloc::malloc(length * sizeof(char16_t))); copyCharacters(data16, { characters.get(), length }); m_data16 = data16; } @@ -1012,13 +1012,13 @@ inline StringImpl::StringImpl(MallocPtr characters, unsigned leng } template -inline StringImpl::StringImpl(MallocSpan characters) - : StringImplShape(s_refCountIncrement, { static_cast(nullptr), characters.span().size() }, s_hashZeroValue | StringNormal | BufferOwned) +inline StringImpl::StringImpl(MallocSpan characters) + : StringImplShape(s_refCountIncrement, { static_cast(nullptr), characters.span().size() }, s_hashZeroValue | StringNormal | BufferOwned) { if constexpr (std::is_same_v) m_data16 = characters.leakSpan().data(); else { - auto* data16 = static_cast(StringImplMalloc::malloc(characters.sizeInBytes())); + auto* data16 = static_cast(StringImplMalloc::malloc(characters.sizeInBytes())); copyCharacters(data16, characters.span()); m_data16 = data16; } @@ -1029,7 +1029,7 @@ inline StringImpl::StringImpl(MallocSpan characters) STRING_STATS_ADD_16BIT_STRING(m_length); } -inline StringImpl::StringImpl(std::span characters, Ref&& base) +inline StringImpl::StringImpl(std::span characters, Ref&& base) : StringImplShape(s_refCountIncrement, characters, s_hashFlag8BitBuffer | StringNormal | BufferSubstring) { ASSERT(is8Bit()); @@ -1042,7 +1042,7 @@ inline StringImpl::StringImpl(std::span characters, Ref STRING_STATS_ADD_8BIT_STRING2(m_length, true); } -inline StringImpl::StringImpl(std::span characters, Ref&& base) +inline StringImpl::StringImpl(std::span characters, Ref&& base) : StringImplShape(s_refCountIncrement, characters, s_hashZeroValue | StringNormal | BufferSubstring) { ASSERT(!is8Bit()); @@ -1065,10 +1065,10 @@ ALWAYS_INLINE Ref StringImpl::createSubstringSharingImpl(StringImpl& // Copying the thing would save more memory sometimes, largely due to the size of pointer. size_t substringSize = allocationSize(1); if (rep.is8Bit()) { - if (substringSize >= allocationSize(length)) + if (substringSize >= allocationSize(length)) return create(rep.span8().subspan(offset, length)); } else { - if (substringSize >= allocationSize(length)) + if (substringSize >= allocationSize(length)) return create(rep.span16().subspan(offset, length)); } @@ -1229,13 +1229,13 @@ inline void StringImpl::deref() m_refCount = tempRefCount; } -inline UChar StringImpl::at(unsigned i) const +inline char16_t StringImpl::at(unsigned i) const { RELEASE_ASSERT(i < m_length); return is8Bit() ? m_data8[i] : m_data16[i]; } -inline StringImpl::StringImpl(CreateSymbolTag, std::span characters) +inline StringImpl::StringImpl(CreateSymbolTag, std::span characters) : StringImplShape(s_refCountIncrement, characters, s_hashFlag8BitBuffer | StringSymbol | BufferSubstring) { ASSERT(is8Bit()); @@ -1243,7 +1243,7 @@ inline StringImpl::StringImpl(CreateSymbolTag, std::span characters STRING_STATS_ADD_8BIT_STRING2(m_length, true); } -inline StringImpl::StringImpl(CreateSymbolTag, std::span characters) +inline StringImpl::StringImpl(CreateSymbolTag, std::span characters) : StringImplShape(s_refCountIncrement, characters, s_hashZeroValue | StringSymbol | BufferSubstring) { ASSERT(!is8Bit()); @@ -1282,8 +1282,8 @@ inline bool StringImpl::requiresCopy() const return true; if (is8Bit()) - return m_data8 == tailPointer(); - return m_data16 == tailPointer(); + return m_data8 == tailPointer(); + return m_data16 == tailPointer(); } template inline const T* StringImpl::tailPointer() const @@ -1405,23 +1405,23 @@ inline Ref StringImpl::removeCharacters(const Predicate& findMatch) return removeCharactersImpl(span16(), findMatch); } -inline Ref StringImpl::createByReplacingInCharacters(std::span characters, UChar target, UChar replacement, size_t indexOfFirstTargetCharacter) +inline Ref StringImpl::createByReplacingInCharacters(std::span characters, char16_t target, char16_t replacement, size_t indexOfFirstTargetCharacter) { ASSERT(indexOfFirstTargetCharacter < characters.size()); if (isLatin1(replacement)) { - std::span data; - LChar oldChar = target; - LChar newChar = replacement; + std::span data; + Latin1Character oldChar = target; + Latin1Character newChar = replacement; auto newImpl = createUninitializedInternalNonEmpty(characters.size(), data); memcpySpan(data, characters.first(indexOfFirstTargetCharacter)); for (size_t i = indexOfFirstTargetCharacter; i != characters.size(); ++i) { - LChar character = characters[i]; + Latin1Character character = characters[i]; data[i] = character == oldChar ? newChar : character; } return newImpl; } - std::span data; + std::span data; auto newImpl = createUninitializedInternalNonEmpty(characters.size(), data); size_t i = 0; for (auto character : characters) @@ -1429,14 +1429,14 @@ inline Ref StringImpl::createByReplacingInCharacters(std::span StringImpl::createByReplacingInCharacters(std::span characters, UChar target, UChar replacement, size_t indexOfFirstTargetCharacter) +inline Ref StringImpl::createByReplacingInCharacters(std::span characters, char16_t target, char16_t replacement, size_t indexOfFirstTargetCharacter) { ASSERT(indexOfFirstTargetCharacter < characters.size()); - std::span data; + std::span data; auto newImpl = createUninitializedInternalNonEmpty(characters.size(), data); copyCharacters(data.data(), characters.first(indexOfFirstTargetCharacter)); for (size_t i = indexOfFirstTargetCharacter; i != characters.size(); ++i) { - UChar character = characters[i]; + char16_t character = characters[i]; data[i] = character == target ? replacement : character; } return newImpl; @@ -1457,13 +1457,13 @@ static inline std::span nonNullEmptyUTF8Span() } template -inline Expected>, UTF8ConversionError> StringImpl::tryGetUTF8ForCharacters(const Func& function, std::span characters) +inline Expected>, UTF8ConversionError> StringImpl::tryGetUTF8ForCharacters(NOESCAPE const Func& function, std::span characters) { if (characters.empty()) return function(nonNullEmptyUTF8Span()); // Allocate a buffer big enough to hold all the characters - // (an individual LChar can only expand to 2 UTF-8 bytes). + // (an individual Latin1Character can only expand to 2 UTF-8 bytes). // Optimization ideas, if we find this function is hot: // * We could speculatively create a CStringBuffer to contain 'length' // characters, and resize if necessary (i.e. if the buffer contains @@ -1495,7 +1495,7 @@ inline Expected>, UTF8Conver } template -inline Expected>, UTF8ConversionError> StringImpl::tryGetUTF8ForCharacters(const Func& function, std::span characters, ConversionMode mode) +inline Expected>, UTF8ConversionError> StringImpl::tryGetUTF8ForCharacters(const Func& function, std::span characters, ConversionMode mode) { if (characters.empty()) return function(nonNullEmptyUTF8Span()); diff --git a/Source/WTF/wtf/text/StringView.cpp b/Source/WTF/wtf/text/StringView.cpp index 746976ce5a06b..56f72e71851a3 100644 --- a/Source/WTF/wtf/text/StringView.cpp +++ b/Source/WTF/wtf/text/StringView.cpp @@ -62,7 +62,7 @@ size_t StringView::findIgnoringASCIICase(StringView matchString, unsigned startO return ::WTF::findIgnoringASCIICase(*this, matchString, startOffset); } -bool StringView::startsWith(UChar character) const +bool StringView::startsWith(char16_t character) const { return m_length && (*this)[0] == character; } @@ -77,7 +77,7 @@ bool StringView::startsWithIgnoringASCIICase(StringView prefix) const return ::WTF::startsWithIgnoringASCIICase(*this, prefix); } -bool StringView::endsWith(UChar character) const +bool StringView::endsWith(char16_t character) const { return m_length && (*this)[m_length - 1] == character; } @@ -138,7 +138,7 @@ size_t StringView::find(AdaptiveStringSearcherTables& tables, StringView matchSt return searchString(tables, span16(), matchString.span16(), start); } -size_t StringView::find(std::span match, unsigned start) const +size_t StringView::find(std::span match, unsigned start) const { ASSERT(!match.empty()); auto length = this->length(); @@ -154,7 +154,7 @@ size_t StringView::find(std::span match, unsigned start) const return findInner(span16().subspan(start), match, start); } -size_t StringView::reverseFind(std::span match, unsigned start) const +size_t StringView::reverseFind(std::span match, unsigned start) const { ASSERT(!match.empty()); if (match.size() > length()) @@ -317,21 +317,21 @@ AtomString StringView::convertToASCIILowercaseAtom() const template void getCharactersWithASCIICaseInternal(StringView::CaseConvertType type, DestinationCharacterType* destination, std::span source) { - static_assert(std::is_same::value || std::is_same::value); - static_assert(std::is_same::value || std::is_same::value); + static_assert(std::is_same::value || std::is_same::value); + static_assert(std::is_same::value || std::is_same::value); static_assert(sizeof(DestinationCharacterType) >= sizeof(SourceCharacterType)); auto caseConvert = (type == StringView::CaseConvertType::Lower) ? toASCIILower : toASCIIUpper; for (auto character : source) *destination++ = caseConvert(character); } -void StringView::getCharactersWithASCIICase(CaseConvertType type, LChar* destination) const +void StringView::getCharactersWithASCIICase(CaseConvertType type, Latin1Character* destination) const { ASSERT(is8Bit()); getCharactersWithASCIICaseInternal(type, destination, span8()); } -void StringView::getCharactersWithASCIICase(CaseConvertType type, UChar* destination) const +void StringView::getCharactersWithASCIICase(CaseConvertType type, char16_t* destination) const { if (is8Bit()) { getCharactersWithASCIICaseInternal(type, destination, span8()); @@ -343,21 +343,21 @@ void StringView::getCharactersWithASCIICase(CaseConvertType type, UChar* destina template void getCharactersWithASCIICaseInternal(StringView::CaseConvertType type, std::span destination, std::span source) { - static_assert(std::is_same::value || std::is_same::value); - static_assert(std::is_same::value || std::is_same::value); + static_assert(std::is_same::value || std::is_same::value); + static_assert(std::is_same::value || std::is_same::value); static_assert(sizeof(DestinationCharacterType) >= sizeof(SourceCharacterType)); auto caseConvert = (type == StringView::CaseConvertType::Lower) ? toASCIILower : toASCIIUpper; for (auto [destinationCharacter, character] : zippedRange(destination, source)) destinationCharacter = caseConvert(character); } -void StringView::getCharactersWithASCIICase(CaseConvertType type, std::span destination) const +void StringView::getCharactersWithASCIICase(CaseConvertType type, std::span destination) const { ASSERT(is8Bit()); getCharactersWithASCIICaseInternal(type, destination, span8()); } -void StringView::getCharactersWithASCIICase(CaseConvertType type, std::span destination) const +void StringView::getCharactersWithASCIICase(CaseConvertType type, std::span destination) const { if (is8Bit()) { getCharactersWithASCIICaseInternal(type, destination, span8()); @@ -385,7 +385,7 @@ StringViewWithUnderlyingString normalizedNFC(StringView string) unsigned normalizedLength = unorm2_normalize(normalizer, span.data(), span.size(), nullptr, 0, &status); ASSERT(needsToGrowToProduceBuffer(status)); - UChar* characters; + char16_t* characters; String result = String::createUninitialized(normalizedLength, characters); status = U_ZERO_ERROR; @@ -440,7 +440,7 @@ size_t StringView::reverseFind(StringView matchString, unsigned start) const return reverseFindInner(span16(), matchString.span16(), start); } -String makeStringByReplacingAll(StringView string, UChar target, UChar replacement) +String makeStringByReplacingAll(StringView string, char16_t target, char16_t replacement) { if (string.is8Bit()) { if (!isLatin1(target)) { @@ -511,8 +511,8 @@ template static String makeStringBySimplifyingNewLinesSl String makeStringBySimplifyingNewLinesSlowCase(const String& string, unsigned firstCarriageReturn) { if (string.is8Bit()) - return makeStringBySimplifyingNewLinesSlowCase(string, firstCarriageReturn); - return makeStringBySimplifyingNewLinesSlowCase(string, firstCarriageReturn); + return makeStringBySimplifyingNewLinesSlowCase(string, firstCarriageReturn); + return makeStringBySimplifyingNewLinesSlowCase(string, firstCarriageReturn); } #if CHECK_STRINGVIEW_LIFETIME diff --git a/Source/WTF/wtf/text/StringView.h b/Source/WTF/wtf/text/StringView.h index f64a10cafb621..95cae18744024 100644 --- a/Source/WTF/wtf/text/StringView.h +++ b/Source/WTF/wtf/text/StringView.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include @@ -67,9 +67,9 @@ class StringView final { StringView(const String&); StringView(const StringImpl&); StringView(const StringImpl*); - StringView(std::span); - StringView(std::span); - StringView(std::span); // FIXME: Consider dropping this overload. Callers should pass LChars/UChars instead. + StringView(std::span); + StringView(std::span); + StringView(std::span); // FIXME: Consider dropping this overload. Callers should pass Latin1Characters/char16_ts instead. StringView(const void*, unsigned length, bool is8bit); StringView(ASCIILiteral); @@ -81,8 +81,8 @@ class StringView final { explicit operator bool() const; bool isNull() const; - UChar characterAt(unsigned index) const; - UChar operator[](unsigned index) const; + char16_t characterAt(unsigned index) const; + char16_t operator[](unsigned index) const; class CodeUnits; CodeUnits codeUnits() const; @@ -94,10 +94,10 @@ class StringView final { GraphemeClusters graphemeClusters() const; bool is8Bit() const; - const void* rawCharacters() const { return m_characters; } - std::span span8() const; - std::span span16() const; - template std::span span() const; + const void* rawCharacters() const LIFETIME_BOUND { return m_characters; } + std::span span8() const LIFETIME_BOUND; + std::span span16() const LIFETIME_BOUND; + template std::span span() const LIFETIME_BOUND; unsigned hash() const; @@ -141,10 +141,10 @@ class StringView final { template void getCharacters16(std::span) const; enum class CaseConvertType { Upper, Lower }; - WTF_EXPORT_PRIVATE void getCharactersWithASCIICase(CaseConvertType, LChar*) const; - WTF_EXPORT_PRIVATE void getCharactersWithASCIICase(CaseConvertType, UChar*) const; - WTF_EXPORT_PRIVATE void getCharactersWithASCIICase(CaseConvertType, std::span) const; - WTF_EXPORT_PRIVATE void getCharactersWithASCIICase(CaseConvertType, std::span) const; + WTF_EXPORT_PRIVATE void getCharactersWithASCIICase(CaseConvertType, Latin1Character*) const; + WTF_EXPORT_PRIVATE void getCharactersWithASCIICase(CaseConvertType, char16_t*) const; + WTF_EXPORT_PRIVATE void getCharactersWithASCIICase(CaseConvertType, std::span) const; + WTF_EXPORT_PRIVATE void getCharactersWithASCIICase(CaseConvertType, std::span) const; StringView substring(unsigned start, unsigned length = std::numeric_limits::max()) const; StringView left(unsigned length) const { return substring(0, length); } @@ -154,19 +154,19 @@ class StringView final { StringView trim(const MatchedCharacterPredicate&) const; class SplitResult; - SplitResult split(UChar) const; - SplitResult splitAllowingEmptyEntries(UChar) const; + SplitResult split(char16_t) const; + SplitResult splitAllowingEmptyEntries(char16_t) const; - size_t find(UChar, unsigned start = 0) const; - size_t find(LChar, unsigned start = 0) const; - ALWAYS_INLINE size_t find(char c, unsigned start = 0) const { return find(byteCast(c), start); } - template>* = nullptr> + size_t find(char16_t, unsigned start = 0) const; + size_t find(Latin1Character, unsigned start = 0) const; + ALWAYS_INLINE size_t find(char c, unsigned start = 0) const { return find(byteCast(c), start); } + template>* = nullptr> size_t find(CodeUnitMatchFunction&&, unsigned start = 0) const; ALWAYS_INLINE size_t find(ASCIILiteral literal, unsigned start = 0) const { return find(literal.span8(), start); } WTF_EXPORT_PRIVATE size_t find(StringView, unsigned start = 0) const; WTF_EXPORT_PRIVATE size_t find(AdaptiveStringSearcherTables&, StringView, unsigned start = 0) const; - size_t reverseFind(UChar, unsigned index = std::numeric_limits::max()) const; + size_t reverseFind(char16_t, unsigned index = std::numeric_limits::max()) const; ALWAYS_INLINE size_t reverseFind(ASCIILiteral literal, unsigned start = std::numeric_limits::max()) const { return reverseFind(literal.span8(), start); } WTF_EXPORT_PRIVATE size_t reverseFind(StringView, unsigned start = std::numeric_limits::max()) const; @@ -177,8 +177,8 @@ class StringView final { WTF_EXPORT_PRIVATE String convertToASCIIUppercase() const; WTF_EXPORT_PRIVATE AtomString convertToASCIILowercaseAtom() const; - bool contains(UChar) const; - template>* = nullptr> + bool contains(char16_t) const; + template>* = nullptr> bool contains(CodeUnitMatchFunction&&) const; bool contains(ASCIILiteral literal) const { return find(literal) != notFound; } bool contains(StringView string) const { return find(string) != notFound; } @@ -186,13 +186,13 @@ class StringView final { WTF_EXPORT_PRIVATE bool containsIgnoringASCIICase(StringView) const; WTF_EXPORT_PRIVATE bool containsIgnoringASCIICase(StringView, unsigned start) const; - template bool containsOnly() const; + template bool containsOnly() const; - WTF_EXPORT_PRIVATE bool startsWith(UChar) const; + WTF_EXPORT_PRIVATE bool startsWith(char16_t) const; WTF_EXPORT_PRIVATE bool startsWith(StringView) const; WTF_EXPORT_PRIVATE bool startsWithIgnoringASCIICase(StringView) const; - WTF_EXPORT_PRIVATE bool endsWith(UChar) const; + WTF_EXPORT_PRIVATE bool endsWith(char16_t) const; WTF_EXPORT_PRIVATE bool endsWith(StringView) const; WTF_EXPORT_PRIVATE bool endsWithIgnoringASCIICase(StringView) const; @@ -211,18 +211,18 @@ class StringView final { // Clients should use StringView(ASCIILiteral) or StringView::fromLatin1() instead. explicit StringView(const char*); - UChar unsafeCharacterAt(unsigned index) const; + char16_t unsafeCharacterAt(unsigned index) const; friend bool equal(StringView, StringView); friend bool equal(StringView, StringView, unsigned length); friend WTF_EXPORT_PRIVATE bool equalRespectingNullity(StringView, StringView); friend size_t findCommon(StringView haystack, StringView needle, unsigned start); - void initialize(std::span); - void initialize(std::span); + void initialize(std::span); + void initialize(std::span); - WTF_EXPORT_PRIVATE size_t find(std::span match, unsigned start) const; - WTF_EXPORT_PRIVATE size_t reverseFind(std::span match, unsigned start) const; + WTF_EXPORT_PRIVATE size_t find(std::span match, unsigned start) const; + WTF_EXPORT_PRIVATE size_t reverseFind(std::span match, unsigned start) const; template StringView trim(std::span, const MatchedCharacterPredicate&) const; @@ -256,7 +256,7 @@ class StringView final { template void append(Vector&, StringView); bool equal(StringView, StringView); -bool equal(StringView, const LChar* b); +bool equal(StringView, const Latin1Character* b); bool equalIgnoringASCIICase(StringView, StringView); bool equalIgnoringASCIICase(StringView, ASCIILiteral); @@ -386,26 +386,26 @@ inline StringView& StringView::operator=(const StringView& other) #endif // CHECK_STRINGVIEW_LIFETIME -inline void StringView::initialize(std::span characters) +inline void StringView::initialize(std::span characters) { m_characters = characters.data(); m_length = characters.size(); m_is8Bit = true; } -inline void StringView::initialize(std::span characters) +inline void StringView::initialize(std::span characters) { m_characters = characters.data(); m_length = characters.size(); m_is8Bit = false; } -inline StringView::StringView(std::span characters) +inline StringView::StringView(std::span characters) { initialize(characters); } -inline StringView::StringView(std::span characters) +inline StringView::StringView(std::span characters) { initialize(characters); } @@ -417,7 +417,7 @@ inline StringView::StringView(const char* characters) inline StringView::StringView(std::span characters) { - initialize(byteCast(characters)); + initialize(byteCast(characters)); } inline StringView::StringView(const void* characters, unsigned length, bool is8bit) @@ -479,18 +479,18 @@ inline void StringView::clear() m_is8Bit = true; } -inline std::span StringView::span8() const +inline std::span StringView::span8() const { ASSERT(is8Bit()); ASSERT(underlyingStringIsValid()); - return { static_cast(m_characters), m_length }; + return { static_cast(m_characters), m_length }; } -inline std::span StringView::span16() const +inline std::span StringView::span16() const { ASSERT(!is8Bit() || isEmpty()); ASSERT(underlyingStringIsValid()); - return { static_cast(m_characters), m_length }; + return { static_cast(m_characters), m_length }; } inline unsigned StringView::hash() const @@ -500,12 +500,12 @@ inline unsigned StringView::hash() const return StringHasher::computeHashAndMaskTop8Bits(span16()); } -template<> ALWAYS_INLINE std::span StringView::span() const +template<> ALWAYS_INLINE std::span StringView::span() const { return span8(); } -template<> ALWAYS_INLINE std::span StringView::span() const +template<> ALWAYS_INLINE std::span StringView::span() const { return span16(); } @@ -522,14 +522,14 @@ class StringView::UpconvertedCharactersWithSize { WTF_MAKE_FAST_ALLOCATED; public: explicit UpconvertedCharactersWithSize(StringView); - operator const UChar*() const { return m_characters.data(); } - const UChar* get() const { return m_characters.data(); } - operator std::span() const { return m_characters; } - std::span span() const { return m_characters; } + operator const char16_t*() const { return m_characters.data(); } + const char16_t* get() const { return m_characters.data(); } + operator std::span() const { return m_characters; } + std::span span() const { return m_characters; } private: - Vector m_upconvertedCharacters; - std::span m_characters; + Vector m_upconvertedCharacters; + std::span m_characters; }; template @@ -585,14 +585,14 @@ inline StringView StringView::substring(unsigned start, unsigned length) const return result; } -inline UChar StringView::characterAt(unsigned index) const +inline char16_t StringView::characterAt(unsigned index) const { if (is8Bit()) return span8()[index]; return span16()[index]; } -inline UChar StringView::unsafeCharacterAt(unsigned index) const +inline char16_t StringView::unsafeCharacterAt(unsigned index) const { ASSERT(index < length()); if (is8Bit()) @@ -600,23 +600,23 @@ inline UChar StringView::unsafeCharacterAt(unsigned index) const return span16().data()[index]; } -inline UChar StringView::operator[](unsigned index) const +inline char16_t StringView::operator[](unsigned index) const { return characterAt(index); } -inline bool StringView::contains(UChar character) const +inline bool StringView::contains(char16_t character) const { return find(character) != notFound; } -template>*> +template>*> inline bool StringView::contains(CodeUnitMatchFunction&& function) const { return find(std::forward(function)) != notFound; } -template inline bool StringView::containsOnly() const +template inline bool StringView::containsOnly() const { if (is8Bit()) return WTF::containsOnly(span8()); @@ -713,21 +713,21 @@ inline String StringView::toStringWithoutCopying() const return StringImpl::createWithoutCopying(span16()); } -inline size_t StringView::find(UChar character, unsigned start) const +inline size_t StringView::find(char16_t character, unsigned start) const { if (is8Bit()) return WTF::find(span8(), character, start); return WTF::find(span16(), character, start); } -inline size_t StringView::find(LChar character, unsigned start) const +inline size_t StringView::find(Latin1Character character, unsigned start) const { if (is8Bit()) return WTF::find(span8(), character, start); return WTF::find(span16(), character, start); } -template>*> +template>*> inline size_t StringView::find(CodeUnitMatchFunction&& matchFunction, unsigned start) const { if (is8Bit()) @@ -735,7 +735,7 @@ inline size_t StringView::find(CodeUnitMatchFunction&& matchFunction, unsigned s return WTF::find(span16(), std::forward(matchFunction), start); } -inline size_t StringView::reverseFind(UChar character, unsigned start) const +inline size_t StringView::reverseFind(char16_t character, unsigned start) const { if (is8Bit()) return WTF::reverseFind(span8(), character, start); @@ -792,7 +792,7 @@ ALWAYS_INLINE bool equal(StringView a, StringView b) return equalCommon(a, b); } -inline bool equal(StringView a, const LChar* b) +inline bool equal(StringView a, const Latin1Character* b) { if (!b) return !a.isEmpty(); @@ -826,7 +826,7 @@ inline bool equalIgnoringASCIICase(StringView a, ASCIILiteral b) class StringView::SplitResult { WTF_MAKE_FAST_ALLOCATED; public: - SplitResult(StringView, UChar separator, bool allowEmptyEntries); + SplitResult(StringView, char16_t separator, bool allowEmptyEntries); class Iterator; Iterator begin() const; @@ -834,7 +834,7 @@ class StringView::SplitResult { private: StringView m_string; - UChar m_separator; + char16_t m_separator; bool m_allowEmptyEntries; }; @@ -954,7 +954,7 @@ class StringView::CodeUnits::Iterator { public: Iterator(StringView, unsigned index); - UChar operator*() const; + char16_t operator*() const; Iterator& operator++(); bool operator==(const Iterator&) const; @@ -1006,11 +1006,11 @@ inline StringView::CodePoints::Iterator::Iterator(StringView stringView, unsigne #endif { if (m_is8Bit) { - const LChar* begin = stringView.span8().data(); + const Latin1Character* begin = stringView.span8().data(); m_current = begin + index; m_end = begin + stringView.length(); } else { - const UChar* begin = stringView.span16().data(); + const char16_t* begin = stringView.span16().data(); m_current = begin + index; m_end = begin + stringView.length(); } @@ -1023,12 +1023,12 @@ inline auto StringView::CodePoints::Iterator::operator++() -> Iterator& #endif ASSERT(m_current < m_end); if (m_is8Bit) - m_current = static_cast(m_current) + 1; + m_current = static_cast(m_current) + 1; else { unsigned i = 0; - size_t length = static_cast(m_end) - static_cast(m_current); - U16_FWD_1(static_cast(m_current), i, length); - m_current = static_cast(m_current) + i; + size_t length = static_cast(m_end) - static_cast(m_current); + U16_FWD_1(static_cast(m_current), i, length); + m_current = static_cast(m_current) + i; } return *this; } @@ -1040,10 +1040,10 @@ inline char32_t StringView::CodePoints::Iterator::operator*() const #endif ASSERT(m_current < m_end); if (m_is8Bit) - return *static_cast(m_current); + return *static_cast(m_current); char32_t codePoint; - size_t length = static_cast(m_end) - static_cast(m_current); - U16_GET(static_cast(m_current), 0, 0, length, codePoint); + size_t length = static_cast(m_end) - static_cast(m_current); + U16_GET(static_cast(m_current), 0, 0, length, codePoint); return codePoint; } @@ -1084,7 +1084,7 @@ inline auto StringView::CodeUnits::Iterator::operator++() -> Iterator& return *this; } -inline UChar StringView::CodeUnits::Iterator::operator*() const +inline char16_t StringView::CodeUnits::Iterator::operator*() const { return m_stringView.unsafeCharacterAt(m_index); } @@ -1106,17 +1106,17 @@ inline auto StringView::CodeUnits::end() const -> Iterator return Iterator(m_stringView, m_stringView.length()); } -inline auto StringView::split(UChar separator) const -> SplitResult +inline auto StringView::split(char16_t separator) const -> SplitResult { return SplitResult { *this, separator, false }; } -inline auto StringView::splitAllowingEmptyEntries(UChar separator) const -> SplitResult +inline auto StringView::splitAllowingEmptyEntries(char16_t separator) const -> SplitResult { return SplitResult { *this, separator, true }; } -inline StringView::SplitResult::SplitResult(StringView stringView, UChar separator, bool allowEmptyEntries) +inline StringView::SplitResult::SplitResult(StringView stringView, char16_t separator, bool allowEmptyEntries) : m_string { stringView } , m_separator { separator } , m_allowEmptyEntries { allowEmptyEntries } @@ -1190,8 +1190,8 @@ template StringView StringView::trim(const MatchedCharacterPredicate& predicate) const { if (is8Bit()) - return trim(span8(), predicate); - return trim(span16(), predicate); + return trim(span8(), predicate); + return trim(span16(), predicate); } inline bool equalLettersIgnoringASCIICase(StringView string, ASCIILiteral literal) @@ -1229,7 +1229,7 @@ inline size_t findCommon(StringView haystack, StringView needle, unsigned start) unsigned needleLength = needle.length(); if (needleLength == 1) { - UChar firstCharacter = needle.unsafeCharacterAt(0); + char16_t firstCharacter = needle.unsafeCharacterAt(0); if (haystack.is8Bit()) return WTF::find(haystack.span8(), firstCharacter, start); return WTF::find(haystack.span16(), firstCharacter, start); @@ -1403,14 +1403,14 @@ inline String WARN_UNUSED_RETURN makeStringByReplacing(const String& string, uns return string; } -inline String WARN_UNUSED_RETURN makeStringByReplacingAll(const String& string, UChar target, StringView replacement) +inline String WARN_UNUSED_RETURN makeStringByReplacingAll(const String& string, char16_t target, StringView replacement) { if (auto* impl = string.impl()) return String { impl->replace(target, replacement) }; return string; } -WTF_EXPORT_PRIVATE String WARN_UNUSED_RETURN makeStringByReplacingAll(StringView, UChar target, UChar replacement); +WTF_EXPORT_PRIVATE String WARN_UNUSED_RETURN makeStringByReplacingAll(StringView, char16_t target, char16_t replacement); WTF_EXPORT_PRIVATE String WARN_UNUSED_RETURN makeStringBySimplifyingNewLinesSlowCase(const String&, unsigned firstCarriageReturnOffset); inline String WARN_UNUSED_RETURN makeStringBySimplifyingNewLines(const String& string) diff --git a/Source/WTF/wtf/text/SuperFastHash.h b/Source/WTF/wtf/text/SuperFastHash.h index 73edc24c80d44..c72da30dbbb1d 100644 --- a/Source/WTF/wtf/text/SuperFastHash.h +++ b/Source/WTF/wtf/text/SuperFastHash.h @@ -29,7 +29,7 @@ namespace WTF { // Paul Hsieh's SuperFastHash // http://www.azillionmonkeys.com/qed/hash.html -// LChar data is interpreted as Latin-1-encoded (zero-extended to 16 bits). +// Latin1Character data is interpreted as Latin-1-encoded (zero-extended to 16 bits). // NOTE: The hash computation here must stay in sync with the create_hash_table script in // JavaScriptCore and the CodeGeneratorJS.pm script in WebCore. diff --git a/Source/WTF/wtf/text/SymbolImpl.h b/Source/WTF/wtf/text/SymbolImpl.h index 828675b2d3b20..b821cef8549a9 100644 --- a/Source/WTF/wtf/text/SymbolImpl.h +++ b/Source/WTF/wtf/text/SymbolImpl.h @@ -74,8 +74,8 @@ class SUPPRESS_REFCOUNTED_WITHOUT_VIRTUAL_DESTRUCTOR SymbolImpl : public Uniqued friend class StringImpl; - inline SymbolImpl(std::span, Ref&&, Flags = s_flagDefault); - inline SymbolImpl(std::span, Ref&&, Flags = s_flagDefault); + inline SymbolImpl(std::span, Ref&&, Flags = s_flagDefault); + inline SymbolImpl(std::span, Ref&&, Flags = s_flagDefault); inline SymbolImpl(Flags = s_flagDefault); // The pointer to the owner string should be immediately following after the StringImpl layout, @@ -86,7 +86,7 @@ class SUPPRESS_REFCOUNTED_WITHOUT_VIRTUAL_DESTRUCTOR SymbolImpl : public Uniqued }; static_assert(sizeof(SymbolImpl) == sizeof(SymbolImpl::StaticSymbolImpl)); -inline SymbolImpl::SymbolImpl(std::span characters, Ref&& base, Flags flags) +inline SymbolImpl::SymbolImpl(std::span characters, Ref&& base, Flags flags) : UniquedStringImpl(CreateSymbol, characters) , m_owner(&base.leakRef()) , m_hashForSymbolShiftedWithFlagCount(nextHashForSymbol()) @@ -134,7 +134,7 @@ class PrivateSymbolImpl final : public SymbolImpl { WTF_EXPORT_PRIVATE static Ref create(StringImpl& rep); private: - PrivateSymbolImpl(std::span characters, Ref&& base) + PrivateSymbolImpl(std::span characters, Ref&& base) : SymbolImpl(characters, WTFMove(base), s_flagIsPrivate) { } @@ -157,7 +157,7 @@ class RegisteredSymbolImpl final : public SymbolImpl { static Ref create(StringImpl& rep, SymbolRegistry&); static Ref createPrivate(StringImpl& rep, SymbolRegistry&); - RegisteredSymbolImpl(std::span characters, Ref&& base, SymbolRegistry& registry, Flags flags = s_flagIsRegistered) + RegisteredSymbolImpl(std::span characters, Ref&& base, SymbolRegistry& registry, Flags flags = s_flagIsRegistered) : SymbolImpl(characters, WTFMove(base), flags) , m_symbolRegistry(®istry) { diff --git a/Source/WTF/wtf/text/UniquedStringImpl.h b/Source/WTF/wtf/text/UniquedStringImpl.h index b08b4666ea5f1..3a93933621c34 100644 --- a/Source/WTF/wtf/text/UniquedStringImpl.h +++ b/Source/WTF/wtf/text/UniquedStringImpl.h @@ -35,12 +35,12 @@ class SUPPRESS_REFCOUNTED_WITHOUT_VIRTUAL_DESTRUCTOR UniquedStringImpl : public private: UniquedStringImpl() = delete; protected: - inline UniquedStringImpl(CreateSymbolTag, std::span); - inline UniquedStringImpl(CreateSymbolTag, std::span); + inline UniquedStringImpl(CreateSymbolTag, std::span); + inline UniquedStringImpl(CreateSymbolTag, std::span); inline UniquedStringImpl(CreateSymbolTag); }; -inline UniquedStringImpl::UniquedStringImpl(CreateSymbolTag, std::span characters) +inline UniquedStringImpl::UniquedStringImpl(CreateSymbolTag, std::span characters) : StringImpl(CreateSymbol, characters) { } diff --git a/Source/WTF/wtf/text/WTFString.cpp b/Source/WTF/wtf/text/WTFString.cpp index 6f63dfd07be54..d8f66c5b35f70 100644 --- a/Source/WTF/wtf/text/WTFString.cpp +++ b/Source/WTF/wtf/text/WTFString.cpp @@ -46,7 +46,7 @@ String::String(std::span characters) } // Construct a string with latin1 data. -String::String(std::span characters) +String::String(std::span characters) : m_impl(characters.data() ? RefPtr { StringImpl::create(characters) } : nullptr) { } @@ -447,7 +447,7 @@ CString String::utf8(ConversionMode mode) const String String::make8Bit(std::span source) { - LChar* destination; + Latin1Character* destination; String result = String::createUninitialized(source.size(), destination); StringImpl::copyCharacters(destination, source); return result; @@ -472,7 +472,7 @@ String fromUTF8Impl(std::span string) return emptyString(); if (charactersAreAllASCII(string)) - return StringImpl::create(spanReinterpretCast(string)); + return StringImpl::create(spanReinterpretCast(string)); Vector buffer(string.size()); @@ -506,7 +506,7 @@ String String::fromUTF8WithLatin1Fallback(std::span string) if (!utf8) { // Do this assertion before chopping the size_t down to unsigned. RELEASE_ASSERT(string.size() <= String::MaxLength); - return spanReinterpretCast(string); + return spanReinterpretCast(string); } return utf8; } @@ -542,10 +542,10 @@ static inline double toDoubleType(std::span data, bool* ok, return number; } -double charactersToDouble(std::span data, bool* ok) +double charactersToDouble(std::span data, bool* ok) { size_t parsedLength; - return toDoubleType(data, ok, parsedLength); + return toDoubleType(data, ok, parsedLength); } double charactersToDouble(std::span data, bool* ok) @@ -554,11 +554,11 @@ double charactersToDouble(std::span data, bool* ok) return toDoubleType(data, ok, parsedLength); } -float charactersToFloat(std::span data, bool* ok) +float charactersToFloat(std::span data, bool* ok) { // FIXME: This will return ok even when the string fits into a double but not a float. size_t parsedLength; - return static_cast(toDoubleType(data, ok, parsedLength)); + return static_cast(toDoubleType(data, ok, parsedLength)); } float charactersToFloat(std::span data, bool* ok) @@ -568,10 +568,10 @@ float charactersToFloat(std::span data, bool* ok) return static_cast(toDoubleType(data, ok, parsedLength)); } -float charactersToFloat(std::span data, size_t& parsedLength) +float charactersToFloat(std::span data, size_t& parsedLength) { // FIXME: This will return ok even when the string fits into a double but not a float. - return static_cast(toDoubleType(data, nullptr, parsedLength)); + return static_cast(toDoubleType(data, nullptr, parsedLength)); } float charactersToFloat(std::span data, size_t& parsedLength) diff --git a/Source/WTF/wtf/text/WTFString.h b/Source/WTF/wtf/text/WTFString.h index a97e53572ba33..c7ff1c199fe4c 100644 --- a/Source/WTF/wtf/text/WTFString.h +++ b/Source/WTF/wtf/text/WTFString.h @@ -39,12 +39,12 @@ namespace WTF { // Declarations of string operations -WTF_EXPORT_PRIVATE double charactersToDouble(std::span, bool* ok = nullptr); -WTF_EXPORT_PRIVATE double charactersToDouble(std::span, bool* ok = nullptr); -WTF_EXPORT_PRIVATE float charactersToFloat(std::span, bool* ok = nullptr); -WTF_EXPORT_PRIVATE float charactersToFloat(std::span, bool* ok = nullptr); -WTF_EXPORT_PRIVATE float charactersToFloat(std::span, size_t& parsedLength); -WTF_EXPORT_PRIVATE float charactersToFloat(std::span, size_t& parsedLength); +WTF_EXPORT_PRIVATE double charactersToDouble(std::span, bool* ok = nullptr); +WTF_EXPORT_PRIVATE double charactersToDouble(std::span, bool* ok = nullptr); +WTF_EXPORT_PRIVATE float charactersToFloat(std::span, bool* ok = nullptr); +WTF_EXPORT_PRIVATE float charactersToFloat(std::span, bool* ok = nullptr); +WTF_EXPORT_PRIVATE float charactersToFloat(std::span, size_t& parsedLength); +WTF_EXPORT_PRIVATE float charactersToFloat(std::span, size_t& parsedLength); template bool containsOnly(std::span); @@ -60,7 +60,7 @@ class String final { WTF_EXPORT_PRIVATE String(std::span characters); // Construct a string with Latin-1 data. - WTF_EXPORT_PRIVATE String(std::span characters); + WTF_EXPORT_PRIVATE String(std::span characters); WTF_EXPORT_PRIVATE String(std::span characters); ALWAYS_INLINE static String fromLatin1(const char* characters) { return String { characters }; } @@ -88,8 +88,8 @@ class String final { void swap(String& o) { m_impl.swap(o.m_impl); } - static String adopt(StringBuffer&& buffer) { return StringImpl::adopt(WTFMove(buffer)); } - static String adopt(StringBuffer&& buffer) { return StringImpl::adopt(WTFMove(buffer)); } + static String adopt(StringBuffer&& buffer) { return StringImpl::adopt(WTFMove(buffer)); } + static String adopt(StringBuffer&& buffer) { return StringImpl::adopt(WTFMove(buffer)); } template static String adopt(Vector&& vector) { return StringImpl::adopt(WTFMove(vector)); } @@ -100,15 +100,15 @@ class String final { RefPtr releaseImpl() { return WTFMove(m_impl); } unsigned length() const { return m_impl ? m_impl->length() : 0; } - std::span span8() const { return m_impl ? m_impl->span8() : std::span(); } - std::span span16() const { return m_impl ? m_impl->span16() : std::span(); } + std::span span8() const LIFETIME_BOUND { return m_impl ? m_impl->span8() : std::span(); } + std::span span16() const LIFETIME_BOUND { return m_impl ? m_impl->span16() : std::span(); } // Return span8() or span16() depending on CharacterType. template std::span span() const; bool is8Bit() const { return !m_impl || m_impl->is8Bit(); } - unsigned sizeInBytes() const { return m_impl ? m_impl->length() * (is8Bit() ? sizeof(LChar) : sizeof(UChar)) : 0; } + unsigned sizeInBytes() const { return m_impl ? m_impl->length() * (is8Bit() ? sizeof(Latin1Character) : sizeof(char16_t)) : 0; } WTF_EXPORT_PRIVATE CString ascii() const; WTF_EXPORT_PRIVATE CString latin1() const; @@ -139,8 +139,8 @@ class String final { AtomString toExistingAtomString() const; // Find a single character or string, also with match function & latin1 forms. - size_t find(UChar character, unsigned start = 0) const { return m_impl ? m_impl->find(character, start) : notFound; } - size_t find(LChar character, unsigned start = 0) const { return m_impl ? m_impl->find(character, start) : notFound; } + size_t find(char16_t character, unsigned start = 0) const { return m_impl ? m_impl->find(character, start) : notFound; } + size_t find(Latin1Character character, unsigned start = 0) const { return m_impl ? m_impl->find(character, start) : notFound; } size_t find(char character, unsigned start = 0) const { return m_impl ? m_impl->find(character, start) : notFound; } size_t find(StringView) const; @@ -205,8 +205,8 @@ class String final { // Returns an uninitialized string. The characters needs to be written // into the buffer returned in data before the returned string is used. - static String createUninitialized(unsigned length, UChar*& data) { return StringImpl::createUninitialized(length, data); } - static String createUninitialized(unsigned length, LChar*& data) { return StringImpl::createUninitialized(length, data); } + static String createUninitialized(unsigned length, char16_t*& data) { return StringImpl::createUninitialized(length, data); } + static String createUninitialized(unsigned length, Latin1Character*& data) { return StringImpl::createUninitialized(length, data); } using SplitFunctor = WTF::Function; @@ -263,15 +263,15 @@ class String final { // String::fromUTF8 will return a null string if the input data contains invalid UTF-8 sequences. WTF_EXPORT_PRIVATE static String fromUTF8(std::span); - static String fromUTF8(std::span characters) { return fromUTF8(byteCast(characters)); } + static String fromUTF8(std::span characters) { return fromUTF8(byteCast(characters)); } static String fromUTF8(std::span characters) { return fromUTF8(byteCast(characters)); } static String fromUTF8(const char* string) { return fromUTF8(WTF::span8(string)); } static String fromUTF8ReplacingInvalidSequences(std::span); - static String fromUTF8ReplacingInvalidSequences(std::span characters) { return fromUTF8ReplacingInvalidSequences(byteCast(characters)); } + static String fromUTF8ReplacingInvalidSequences(std::span characters) { return fromUTF8ReplacingInvalidSequences(byteCast(characters)); } // Tries to convert the passed in string to UTF-8, but will fall back to Latin-1 if the string is not valid UTF-8. WTF_EXPORT_PRIVATE static String fromUTF8WithLatin1Fallback(std::span); - static String fromUTF8WithLatin1Fallback(std::span characters) { return fromUTF8WithLatin1Fallback(byteCast(characters)); } + static String fromUTF8WithLatin1Fallback(std::span characters) { return fromUTF8WithLatin1Fallback(byteCast(characters)); } static String fromUTF8WithLatin1Fallback(std::span characters) { return fromUTF8WithLatin1Fallback(byteCast(characters)); } WTF_EXPORT_PRIVATE static String fromCodePoint(char32_t codePoint); @@ -371,7 +371,7 @@ template<> struct VectorTraits : VectorTraitsBase { template<> struct IntegerToStringConversionTrait { using ReturnType = String; using AdditionalArgumentType = void; - static String flush(std::span characters, void*) { return characters; } + static String flush(std::span characters, void*) { return characters; } }; #ifdef __OBJC__ @@ -431,7 +431,7 @@ inline String::String(ASCIILiteral characters) { } -template<> inline std::span String::span() const +template<> inline std::span String::span() const { return span8(); } diff --git a/Source/WTF/wtf/text/WYHash.h b/Source/WTF/wtf/text/WYHash.h index 4ac0a7989f4f3..91ccd7e49be35 100644 --- a/Source/WTF/wtf/text/WYHash.h +++ b/Source/WTF/wtf/text/WYHash.h @@ -178,8 +178,8 @@ class WYHash { } }; - // LChar data is interpreted as Latin-1-encoded (zero-extended to 16 bits). - // To match the hash value of UChar with same content, extend 16 bits (0xff) + // Latin1Character data is interpreted as Latin-1-encoded (zero-extended to 16 bits). + // To match the hash value of char16_t with same content, extend 16 bits (0xff) // to 32 bits (0x00ff). template struct Reader8Bit { diff --git a/Source/WTF/wtf/text/cf/StringCF.cpp b/Source/WTF/wtf/text/cf/StringCF.cpp index 1bda58f59bf20..49d3bb68aab41 100644 --- a/Source/WTF/wtf/text/cf/StringCF.cpp +++ b/Source/WTF/wtf/text/cf/StringCF.cpp @@ -41,7 +41,7 @@ String::String(CFStringRef str) } { - StringBuffer buffer(size); + StringBuffer buffer(size); CFIndex usedBufLen; CFIndex convertedSize = CFStringGetBytes(str, CFRangeMake(0, size), kCFStringEncodingISOLatin1, 0, false, buffer.characters(), size, &usedBufLen); if (convertedSize == size && usedBufLen == size) { diff --git a/Source/WTF/wtf/text/cf/StringConcatenateCF.h b/Source/WTF/wtf/text/cf/StringConcatenateCF.h index 02a81d226d734..fd200068f55a2 100644 --- a/Source/WTF/wtf/text/cf/StringConcatenateCF.h +++ b/Source/WTF/wtf/text/cf/StringConcatenateCF.h @@ -47,7 +47,7 @@ inline StringTypeAdapter::StringTypeAdapter(CFStringRef string) { } -template<> inline void StringTypeAdapter::writeTo(LChar* destination) const +template<> inline void StringTypeAdapter::writeTo(Latin1Character* destination) const { if (m_string) std::memcpy(destination, CFStringGetCStringPtr(m_string, kCFStringEncodingISOLatin1), CFStringGetLength(m_string)); diff --git a/Source/WTF/wtf/text/cocoa/ASCIILiteralCocoa.mm b/Source/WTF/wtf/text/cocoa/ASCIILiteralCocoa.mm index 9d965b52f8322..8d14c00a3c3e4 100644 --- a/Source/WTF/wtf/text/cocoa/ASCIILiteralCocoa.mm +++ b/Source/WTF/wtf/text/cocoa/ASCIILiteralCocoa.mm @@ -33,7 +33,7 @@ RetainPtr ASCIILiteral::createNSString() const { auto span = span8(); - return adoptNS([[NSString alloc] initWithBytesNoCopy:const_cast(span.data()) length:span.size() encoding:NSISOLatin1StringEncoding freeWhenDone:NO]); + return adoptNS([[NSString alloc] initWithBytesNoCopy:const_cast(span.data()) length:span.size() encoding:NSISOLatin1StringEncoding freeWhenDone:NO]); } } // namespace WTF diff --git a/Source/WTF/wtf/text/cocoa/StringViewCocoa.mm b/Source/WTF/wtf/text/cocoa/StringViewCocoa.mm index 70dca7f191857..55a61357656ce 100644 --- a/Source/WTF/wtf/text/cocoa/StringViewCocoa.mm +++ b/Source/WTF/wtf/text/cocoa/StringViewCocoa.mm @@ -34,7 +34,7 @@ { if (is8Bit()) { auto characters = span8(); - return adoptNS([[NSString alloc] initWithBytes:const_cast(characters.data()) length:characters.size() encoding:NSISOLatin1StringEncoding]); + return adoptNS([[NSString alloc] initWithBytes:const_cast(characters.data()) length:characters.size() encoding:NSISOLatin1StringEncoding]); } auto characters = span16(); return adoptNS([[NSString alloc] initWithCharacters:reinterpret_cast(const_cast(characters.data())) length:characters.size()]); @@ -44,7 +44,7 @@ { if (is8Bit()) { auto characters = span8(); - return adoptNS([[NSString alloc] initWithBytesNoCopy:const_cast(characters.data()) length:characters.size() encoding:NSISOLatin1StringEncoding freeWhenDone:NO]); + return adoptNS([[NSString alloc] initWithBytesNoCopy:const_cast(characters.data()) length:characters.size() encoding:NSISOLatin1StringEncoding freeWhenDone:NO]); } auto characters = span16(); return adoptNS([[NSString alloc] initWithCharactersNoCopy:reinterpret_cast(const_cast(characters.data())) length:characters.size() freeWhenDone:NO]); diff --git a/Source/WTF/wtf/text/icu/UTextProviderLatin1.cpp b/Source/WTF/wtf/text/icu/UTextProviderLatin1.cpp index 67cbd1b5e662f..977abbe2673dd 100644 --- a/Source/WTF/wtf/text/icu/UTextProviderLatin1.cpp +++ b/Source/WTF/wtf/text/icu/UTextProviderLatin1.cpp @@ -36,7 +36,7 @@ namespace WTF { static UText* uTextLatin1Clone(UText*, const UText*, UBool, UErrorCode*); static int64_t uTextLatin1NativeLength(UText*); static UBool uTextLatin1Access(UText*, int64_t, UBool); -static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode*); +static int32_t uTextLatin1Extract(UText*, int64_t, int64_t, char16_t*, int32_t, UErrorCode*); static int64_t uTextLatin1MapOffsetToNative(const UText*); static int32_t uTextLatin1MapNativeIndexToUTF16(const UText*, int64_t); static void uTextLatin1Close(UText*); @@ -67,7 +67,7 @@ static UText* uTextLatin1Clone(UText* destination, const UText* source, UBool de if (U_FAILURE(*status)) return nullptr; - UText* result = utext_setup(destination, sizeof(UChar) * UTextWithBufferInlineCapacity, status); + UText* result = utext_setup(destination, sizeof(char16_t) * UTextWithBufferInlineCapacity, status); if (U_FAILURE(*status)) return destination; @@ -81,8 +81,8 @@ static UText* uTextLatin1Clone(UText* destination, const UText* source, UBool de result->context = source->context; result->a = source->a; result->pFuncs = &uTextLatin1Funcs; - result->chunkContents = static_cast(result->pExtra); - memset(const_cast(result->chunkContents), 0, sizeof(UChar) * UTextWithBufferInlineCapacity); + result->chunkContents = static_cast(result->pExtra); + memset(const_cast(result->chunkContents), 0, sizeof(char16_t) * UTextWithBufferInlineCapacity); return result; } @@ -140,14 +140,14 @@ static UBool uTextLatin1Access(UText* uText, int64_t index, UBool forward) } uText->chunkLength = static_cast(uText->chunkNativeLimit - uText->chunkNativeStart); - StringImpl::copyCharacters(const_cast(uText->chunkContents), { static_cast(uText->context) + uText->chunkNativeStart, static_cast(uText->chunkLength) }); + StringImpl::copyCharacters(const_cast(uText->chunkContents), { static_cast(uText->context) + uText->chunkNativeStart, static_cast(uText->chunkLength) }); uText->nativeIndexingLimit = uText->chunkLength; return true; } -static int32_t uTextLatin1Extract(UText* uText, int64_t start, int64_t limit, UChar* dest, int32_t destCapacity, UErrorCode* status) +static int32_t uTextLatin1Extract(UText* uText, int64_t start, int64_t limit, char16_t* dest, int32_t destCapacity, UErrorCode* status) { int64_t length = uText->a; if (U_FAILURE(*status)) @@ -178,7 +178,7 @@ static int32_t uTextLatin1Extract(UText* uText, int64_t start, int64_t limit, UC if (trimmedLength > destCapacity) trimmedLength = destCapacity; - StringImpl::copyCharacters(dest, { static_cast(uText->context) + start, static_cast(trimmedLength) }); + StringImpl::copyCharacters(dest, { static_cast(uText->context) + start, static_cast(trimmedLength) }); } if (length < destCapacity) { @@ -211,7 +211,7 @@ static void uTextLatin1Close(UText* uText) uText->context = nullptr; } -UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, std::span string, UErrorCode* status) +UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, std::span string, UErrorCode* status) { if (U_FAILURE(*status)) return nullptr; @@ -228,8 +228,8 @@ UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, std::spancontext = string.data(); text->a = string.size(); text->pFuncs = &uTextLatin1Funcs; - text->chunkContents = static_cast(text->pExtra); - memset(const_cast(text->chunkContents), 0, sizeof(UChar) * UTextWithBufferInlineCapacity); + text->chunkContents = static_cast(text->pExtra); + memset(const_cast(text->chunkContents), 0, sizeof(char16_t) * UTextWithBufferInlineCapacity); return text; } @@ -240,7 +240,7 @@ UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, std::spanchunkNativeStart = nativeIndex; - text->chunkNativeLimit = nativeIndex + text->extraSize / sizeof(UChar); + text->chunkNativeLimit = nativeIndex + text->extraSize / sizeof(char16_t); if (text->chunkNativeLimit > nativeLength) text->chunkNativeLimit = nativeLength; } else { text->chunkNativeLimit = nativeIndex; - text->chunkNativeStart = nativeIndex - text->extraSize / sizeof(UChar); + text->chunkNativeStart = nativeIndex - text->extraSize / sizeof(char16_t); if (text->chunkNativeStart < text->b) text->chunkNativeStart = text->b; } @@ -291,13 +291,13 @@ static void textLatin1ContextAwareMoveInPrimaryContext(UText* text, int64_t nati text->chunkLength = length < std::numeric_limits::max() ? static_cast(length) : 0; text->nativeIndexingLimit = text->chunkLength; text->chunkOffset = forward ? 0 : text->chunkLength; - StringImpl::copyCharacters(const_cast(text->chunkContents), { static_cast(text->p) + (text->chunkNativeStart - text->b), static_cast(text->chunkLength) }); + StringImpl::copyCharacters(const_cast(text->chunkContents), { static_cast(text->p) + (text->chunkNativeStart - text->b), static_cast(text->chunkLength) }); } static void textLatin1ContextAwareSwitchToPrimaryContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward) { ASSERT(!text->chunkContents || text->chunkContents == text->q); - text->chunkContents = static_cast(text->pExtra); + text->chunkContents = static_cast(text->pExtra); textLatin1ContextAwareMoveInPrimaryContext(text, nativeIndex, nativeLength, forward); } @@ -319,7 +319,7 @@ static void textLatin1ContextAwareMoveInPriorContext(UText* text, int64_t native static void textLatin1ContextAwareSwitchToPriorContext(UText* text, int64_t nativeIndex, int64_t nativeLength, UBool forward) { ASSERT(!text->chunkContents || text->chunkContents == text->pExtra); - text->chunkContents = static_cast(text->q); + text->chunkContents = static_cast(text->q); textLatin1ContextAwareMoveInPriorContext(text, nativeIndex, nativeLength, forward); } @@ -359,7 +359,7 @@ static UBool uTextLatin1ContextAwareAccess(UText* text, int64_t nativeIndex, UBo return true; } -static int32_t uTextLatin1ContextAwareExtract(UText*, int64_t, int64_t, UChar*, int32_t, UErrorCode* errorCode) +static int32_t uTextLatin1ContextAwareExtract(UText*, int64_t, int64_t, char16_t*, int32_t, UErrorCode* errorCode) { // In the present context, this text provider is used only with ICU functions // that do not perform an extract operation. @@ -373,7 +373,7 @@ static void uTextLatin1ContextAwareClose(UText* text) text->context = nullptr; } -UText* openLatin1ContextAwareUTextProvider(UTextWithBuffer* utWithBuffer, std::span string, std::span priorContext, UErrorCode* status) +UText* openLatin1ContextAwareUTextProvider(UTextWithBuffer* utWithBuffer, std::span string, std::span priorContext, UErrorCode* status) { if (U_FAILURE(*status)) return nullptr; diff --git a/Source/WTF/wtf/text/icu/UTextProviderLatin1.h b/Source/WTF/wtf/text/icu/UTextProviderLatin1.h index eda22404eee2f..f8126a5e7b8d2 100644 --- a/Source/WTF/wtf/text/icu/UTextProviderLatin1.h +++ b/Source/WTF/wtf/text/icu/UTextProviderLatin1.h @@ -26,7 +26,7 @@ #pragma once #include -#include +#include namespace WTF { @@ -38,7 +38,7 @@ struct UTextWithBuffer { UChar buffer[UTextWithBufferInlineCapacity]; }; -UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, std::span string, UErrorCode* status); -WTF_EXPORT_PRIVATE UText* openLatin1ContextAwareUTextProvider(UTextWithBuffer* utWithBuffer, std::span string, std::span priorContext, UErrorCode* status); +UText* openLatin1UTextProvider(UTextWithBuffer* utWithBuffer, std::span string, UErrorCode* status); +WTF_EXPORT_PRIVATE UText* openLatin1ContextAwareUTextProvider(UTextWithBuffer* utWithBuffer, std::span string, std::span priorContext, UErrorCode* status); } // namespace WTF diff --git a/Source/WTF/wtf/unicode/UTF8Conversion.cpp b/Source/WTF/wtf/unicode/UTF8Conversion.cpp index f903eb1038c2a..6f245d180d6c5 100644 --- a/Source/WTF/wtf/unicode/UTF8Conversion.cpp +++ b/Source/WTF/wtf/unicode/UTF8Conversion.cpp @@ -41,7 +41,7 @@ enum class Replacement : bool { None, ReplaceInvalidSequences }; template static char32_t next(std::span, size_t& offset); template static bool append(std::span, size_t& offset, char32_t character); -template<> char32_t next(std::span characters, size_t& offset) +template<> char32_t next(std::span characters, size_t& offset) { return characters[offset++]; } @@ -135,7 +135,7 @@ ConversionResult convert(std::span source, std::span convert(std::span source, std::span buffer) +ConversionResult convert(std::span source, std::span buffer) { return convertInternal(source, buffer); } @@ -203,7 +203,7 @@ bool equal(std::span a, std::span b) return equalInternal(a, b); } -bool equal(std::span a, std::span b) +bool equal(std::span a, std::span b) { return equalInternal(a, b); } diff --git a/Source/WTF/wtf/unicode/UTF8Conversion.h b/Source/WTF/wtf/unicode/UTF8Conversion.h index 007b8fe3292f3..f507b6b97236e 100644 --- a/Source/WTF/wtf/unicode/UTF8Conversion.h +++ b/Source/WTF/wtf/unicode/UTF8Conversion.h @@ -25,7 +25,7 @@ #pragma once -#include +#include namespace WTF { namespace Unicode { @@ -44,14 +44,14 @@ template struct ConversionResult { WTF_EXPORT_PRIVATE ConversionResult convert(std::span, std::span); WTF_EXPORT_PRIVATE ConversionResult convert(std::span, std::span); -WTF_EXPORT_PRIVATE ConversionResult convert(std::span, std::span); +WTF_EXPORT_PRIVATE ConversionResult convert(std::span, std::span); // Invalid sequences are converted to the replacement character. WTF_EXPORT_PRIVATE ConversionResult convertReplacingInvalidSequences(std::span, std::span); WTF_EXPORT_PRIVATE ConversionResult convertReplacingInvalidSequences(std::span, std::span); WTF_EXPORT_PRIVATE bool equal(std::span, std::span); -WTF_EXPORT_PRIVATE bool equal(std::span, std::span); +WTF_EXPORT_PRIVATE bool equal(std::span, std::span); // The checkUTF8 function checks the UTF-8 and returns a span of the valid complete // UTF-8 sequences at the start of the passed-in characters, along with the UTF-16 diff --git a/Source/WTF/wtf/unicode/icu/CollatorICU.cpp b/Source/WTF/wtf/unicode/icu/CollatorICU.cpp index a03fbbea6c0b9..0c5b31e4cd5ea 100644 --- a/Source/WTF/wtf/unicode/icu/CollatorICU.cpp +++ b/Source/WTF/wtf/unicode/icu/CollatorICU.cpp @@ -183,7 +183,7 @@ static UChar32 currentLatin1(UCharIterator* iterator) ASSERT(iterator->index >= iterator->start); if (iterator->index >= iterator->limit) return U_SENTINEL; - return static_cast(iterator->context)[iterator->index]; + return static_cast(iterator->context)[iterator->index]; } static UChar32 nextLatin1(UCharIterator* iterator) @@ -191,14 +191,14 @@ static UChar32 nextLatin1(UCharIterator* iterator) ASSERT(iterator->index >= iterator->start); if (iterator->index >= iterator->limit) return U_SENTINEL; - return static_cast(iterator->context)[iterator->index++]; + return static_cast(iterator->context)[iterator->index++]; } static UChar32 previousLatin1(UCharIterator* iterator) { if (iterator->index <= iterator->start) return U_SENTINEL; - return static_cast(iterator->context)[--iterator->index]; + return static_cast(iterator->context)[--iterator->index]; } static uint32_t getStateLatin1(const UCharIterator* iterator) @@ -211,7 +211,7 @@ static void setStateLatin1(UCharIterator* iterator, uint32_t state, UErrorCode*) iterator->index = state; } -static UCharIterator createLatin1Iterator(std::span characters) +static UCharIterator createLatin1Iterator(std::span characters) { UCharIterator iterator; iterator.context = characters.data(); diff --git a/Source/WebCore/PAL/pal/Gunzip.h b/Source/WebCore/PAL/pal/Gunzip.h index 842ee3d75645e..47d980924ce81 100644 --- a/Source/WebCore/PAL/pal/Gunzip.h +++ b/Source/WebCore/PAL/pal/Gunzip.h @@ -26,13 +26,13 @@ #pragma once #include -#include +#include namespace PAL { // This function is only suitable for zip files which are guaranteed to not have any flags set in their headers. // See https://tools.ietf.org/html/rfc1952 for more information. -PAL_EXPORT Vector gunzip(const unsigned char* data, size_t length); +PAL_EXPORT Vector gunzip(const unsigned char* data, size_t length); } diff --git a/Source/WebCore/PAL/pal/cocoa/Gunzip.cpp b/Source/WebCore/PAL/pal/cocoa/Gunzip.cpp index 18cbb9949bd90..524597b101115 100644 --- a/Source/WebCore/PAL/pal/cocoa/Gunzip.cpp +++ b/Source/WebCore/PAL/pal/cocoa/Gunzip.cpp @@ -30,9 +30,9 @@ namespace PAL { -Vector gunzip(const unsigned char* data, size_t length) +Vector gunzip(const unsigned char* data, size_t length) { - Vector result; + Vector result; // Parse the gzip header. auto checks = [&]() { diff --git a/Source/WebCore/PAL/pal/text/TextCodecASCIIFastPath.h b/Source/WebCore/PAL/pal/text/TextCodecASCIIFastPath.h index 06c75137d7136..47d2ac3babcc8 100644 --- a/Source/WebCore/PAL/pal/text/TextCodecASCIIFastPath.h +++ b/Source/WebCore/PAL/pal/text/TextCodecASCIIFastPath.h @@ -32,7 +32,7 @@ namespace PAL { template struct UCharByteFiller; template<> struct UCharByteFiller<4> { - static void copy(LChar* destination, const uint8_t* source) + static void copy(Latin1Character* destination, const uint8_t* source) { memcpy(destination, source, 4); } @@ -46,7 +46,7 @@ template<> struct UCharByteFiller<4> { } }; template<> struct UCharByteFiller<8> { - static void copy(LChar* destination, const uint8_t* source) + static void copy(Latin1Character* destination, const uint8_t* source) { memcpy(destination, source, 8); } @@ -64,7 +64,7 @@ template<> struct UCharByteFiller<8> { } }; -inline void copyASCIIMachineWord(LChar* destination, const uint8_t* source) +inline void copyASCIIMachineWord(Latin1Character* destination, const uint8_t* source) { UCharByteFiller::copy(destination, source); } diff --git a/Source/WebCore/PAL/pal/text/TextCodecLatin1.cpp b/Source/WebCore/PAL/pal/text/TextCodecLatin1.cpp index 17bff34214530..686ea1a5e183f 100644 --- a/Source/WebCore/PAL/pal/text/TextCodecLatin1.cpp +++ b/Source/WebCore/PAL/pal/text/TextCodecLatin1.cpp @@ -33,7 +33,7 @@ namespace PAL { -static const UChar latin1ConversionTable[256] = { +static const char16_t latin1ConversionTable[256] = { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, // 00-07 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, // 08-0F 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, // 10-17 @@ -99,7 +99,7 @@ void TextCodecLatin1::registerCodecs(TextCodecRegistrar registrar) String TextCodecLatin1::decode(std::span bytes, bool, bool, bool& sawException) { - LChar* characters; + Latin1Character* characters; if (bytes.empty()) return emptyString(); if (UNLIKELY(bytes.size() > std::numeric_limits::max())) { @@ -112,7 +112,7 @@ String TextCodecLatin1::decode(std::span bytes, bool, bool, bool& const uint8_t* source = bytes.data(); const uint8_t* end = bytes.data() + bytes.size(); const uint8_t* alignedEnd = WTF::alignToMachineWord(end); - LChar* destination = characters; + Latin1Character* destination = characters; while (source < end) { if (isASCII(*source)) { @@ -121,7 +121,7 @@ String TextCodecLatin1::decode(std::span bytes, bool, bool, bool& while (source < alignedEnd) { auto chunk = *reinterpret_cast_ptr(source); - if (!WTF::containsOnlyASCII(chunk)) + if (!WTF::containsOnlyASCII(chunk)) goto useLookupTable; copyASCIIMachineWord(destination, source); @@ -152,14 +152,14 @@ String TextCodecLatin1::decode(std::span bytes, bool, bool, bool& return result; upConvertTo16Bit: - UChar* characters16; + char16_t* characters16; String result16 = String::createUninitialized(bytes.size(), characters16); - UChar* destination16 = characters16; + char16_t* destination16 = characters16; // Zero extend and copy already processed 8 bit data - LChar* ptr8 = characters; - LChar* endPtr8 = destination; + Latin1Character* ptr8 = characters; + Latin1Character* endPtr8 = destination; while (ptr8 < endPtr8) *destination16++ = *ptr8++; @@ -176,7 +176,7 @@ String TextCodecLatin1::decode(std::span bytes, bool, bool, bool& while (source < alignedEnd) { auto chunk = *reinterpret_cast_ptr(source); - if (!WTF::containsOnlyASCII(chunk)) + if (!WTF::containsOnlyASCII(chunk)) goto useLookupTable16; copyASCIIMachineWord(destination16, source); @@ -237,7 +237,7 @@ Vector TextCodecLatin1::encode(StringView string, UnencodableHandling h auto* bytes = result.data(); // Convert and simultaneously do a check to see if it's all ASCII. - UChar ored = 0; + char16_t ored = 0; for (auto character : string.codeUnits()) { *bytes++ = character; ored |= character; diff --git a/Source/WebCore/PAL/pal/text/TextCodecUTF8.cpp b/Source/WebCore/PAL/pal/text/TextCodecUTF8.cpp index e3702858f31c9..1d4a44ea114aa 100644 --- a/Source/WebCore/PAL/pal/text/TextCodecUTF8.cpp +++ b/Source/WebCore/PAL/pal/text/TextCodecUTF8.cpp @@ -162,7 +162,7 @@ static inline int decodeNonASCIISequence(const uint8_t* sequence, uint8_t& lengt return ((sequence[0] << 18) + (sequence[1] << 12) + (sequence[2] << 6) + sequence[3]) - 0x03C82080; } -static inline UChar* appendCharacter(UChar* destination, int character) +static inline char16_t* appendCharacter(char16_t* destination, int character) { ASSERT(character != nonCharacter); ASSERT(!U_IS_SURROGATE(character)); @@ -181,7 +181,7 @@ void TextCodecUTF8::consumePartialSequenceByte() memmove(m_partialSequence, m_partialSequence + 1, m_partialSequenceSize); } -bool TextCodecUTF8::handlePartialSequence(LChar*& destination, std::span& source, bool flush) +bool TextCodecUTF8::handlePartialSequence(Latin1Character*& destination, std::span& source, bool flush) { ASSERT(m_partialSequenceSize); do { @@ -232,7 +232,7 @@ bool TextCodecUTF8::handlePartialSequence(LChar*& destination, std::span& source, bool flush, bool stopOnError, bool& sawError) +void TextCodecUTF8::handlePartialSequence(char16_t*& destination, std::span& source, bool flush, bool stopOnError, bool& sawError) { ASSERT(m_partialSequenceSize); do { @@ -306,18 +306,18 @@ String TextCodecUTF8::decode(std::span bytes, bool flush, bool st sawError = true; return { }; } - StringBuffer buffer(bufferSize); + StringBuffer buffer(bufferSize); auto source = bytes; auto* alignedEnd = WTF::alignToMachineWord(bytes.data() + bytes.size()); - LChar* destination = buffer.characters(); + Latin1Character* destination = buffer.characters(); do { if (m_partialSequenceSize) { // Explicitly copy destination and source pointers to avoid taking pointers to the // local variables, which may harm code generation by disabling some optimizations // in some compilers. - LChar* destinationForHandlePartialSequence = destination; + Latin1Character* destinationForHandlePartialSequence = destination; if (handlePartialSequence(destinationForHandlePartialSequence, source, flush)) { goto upConvertTo16Bit; } @@ -332,7 +332,7 @@ String TextCodecUTF8::decode(std::span bytes, bool flush, bool st if (WTF::isAlignedToMachineWord(source.data())) { while (source.data() < alignedEnd) { auto chunk = *reinterpret_cast_ptr(source.data()); - if (!WTF::containsOnlyASCII(chunk)) + if (!WTF::containsOnlyASCII(chunk)) break; copyASCIIMachineWord(destination, source.data()); source = source.subspan(sizeof(WTF::MachineWord)); @@ -385,12 +385,12 @@ String TextCodecUTF8::decode(std::span bytes, bool flush, bool st return String::adopt(WTFMove(buffer)); upConvertTo16Bit: - StringBuffer buffer16(bufferSize); + StringBuffer buffer16(bufferSize); - UChar* destination16 = buffer16.characters(); + char16_t* destination16 = buffer16.characters(); // Copy the already converted characters - for (LChar* converted8 = buffer.characters(); converted8 < destination;) + for (Latin1Character* converted8 = buffer.characters(); converted8 < destination;) *destination16++ = *converted8++; do { @@ -398,7 +398,7 @@ String TextCodecUTF8::decode(std::span bytes, bool flush, bool st // Explicitly copy destination and source pointers to avoid taking pointers to the // local variables, which may harm code generation by disabling some optimizations // in some compilers. - UChar* destinationForHandlePartialSequence = destination16; + char16_t* destinationForHandlePartialSequence = destination16; handlePartialSequence(destinationForHandlePartialSequence, source, flush, stopOnError, sawError); destination16 = destinationForHandlePartialSequence; if (m_partialSequenceSize) @@ -411,7 +411,7 @@ String TextCodecUTF8::decode(std::span bytes, bool flush, bool st if (WTF::isAlignedToMachineWord(source.data())) { while (source.data() < alignedEnd) { auto chunk = *reinterpret_cast_ptr(source.data()); - if (!WTF::containsOnlyASCII(chunk)) + if (!WTF::containsOnlyASCII(chunk)) break; copyASCIIMachineWord(destination16, source.data()); source = source.subspan(sizeof(WTF::MachineWord)); diff --git a/Source/WebCore/PAL/pal/text/TextCodecUTF8.h b/Source/WebCore/PAL/pal/text/TextCodecUTF8.h index 873bc6b1ffad4..8277f740f9ee3 100644 --- a/Source/WebCore/PAL/pal/text/TextCodecUTF8.h +++ b/Source/WebCore/PAL/pal/text/TextCodecUTF8.h @@ -27,7 +27,7 @@ #include "TextCodec.h" #include -#include +#include namespace PAL { @@ -44,8 +44,8 @@ class TextCodecUTF8 final : public TextCodec { String decode(std::span, bool flush, bool stopOnError, bool& sawError) final; Vector encode(StringView, UnencodableHandling) const final; - bool handlePartialSequence(LChar*& destination, std::span& source, bool flush); - void handlePartialSequence(UChar*& destination, std::span& source, bool flush, bool stopOnError, bool& sawError); + bool handlePartialSequence(Latin1Character*& destination, std::span& source, bool flush); + void handlePartialSequence(char16_t*& destination, std::span& source, bool flush, bool stopOnError, bool& sawError); void consumePartialSequenceByte(); int m_partialSequenceSize { 0 }; diff --git a/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp b/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp index 26c6464aa0653..02193910bef6e 100644 --- a/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp +++ b/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp @@ -203,7 +203,7 @@ void DFABytecodeInterpreter::interpretTestFlagsAndAppendAction(uint32_t& program } template -inline void DFABytecodeInterpreter::interpretJumpTable(std::span url, uint32_t& urlIndex, uint32_t& programCounter) +inline void DFABytecodeInterpreter::interpretJumpTable(std::span url, uint32_t& urlIndex, uint32_t& programCounter) { DFABytecodeJumpSize jumpSize = getJumpSize(m_bytecode, programCounter); @@ -245,8 +245,8 @@ auto DFABytecodeInterpreter::actionsMatchingEverything() -> Actions auto DFABytecodeInterpreter::interpret(const String& urlString, ResourceFlags flags) -> Actions { CString urlCString; - std::span url; - if (LIKELY(urlString.is8Bit())) + std::span url; + if (urlString.is8Bit()) [[likely]] url = urlString.span8(); else { urlCString = urlString.utf8(); diff --git a/Source/WebCore/contentextensions/DFABytecodeInterpreter.h b/Source/WebCore/contentextensions/DFABytecodeInterpreter.h index 681ff8c0680e2..e12861c908d5d 100644 --- a/Source/WebCore/contentextensions/DFABytecodeInterpreter.h +++ b/Source/WebCore/contentextensions/DFABytecodeInterpreter.h @@ -50,7 +50,7 @@ class DFABytecodeInterpreter { void interpretTestFlagsAndAppendAction(unsigned& programCounter, ResourceFlags, Actions&); template - void interpretJumpTable(std::span url, uint32_t& urlIndex, uint32_t& programCounter); + void interpretJumpTable(std::span url, uint32_t& urlIndex, uint32_t& programCounter); const std::span m_bytecode; }; diff --git a/Source/WebCore/css/CSSVariableData.cpp b/Source/WebCore/css/CSSVariableData.cpp index a54dc6c4d8f55..250f4ee5e6cfb 100644 --- a/Source/WebCore/css/CSSVariableData.cpp +++ b/Source/WebCore/css/CSSVariableData.cpp @@ -75,7 +75,7 @@ CSSVariableData::CSSVariableData(const CSSParserTokenRange& range, const CSSPars if (!stringBuilder.isEmpty()) { m_backingString = stringBuilder.toString(); if (m_backingString.is8Bit()) - updateBackingStringsInTokens(); + updateBackingStringsInTokens(); else updateBackingStringsInTokens(); } diff --git a/Source/WebCore/css/parser/CSSParserToken.h b/Source/WebCore/css/parser/CSSParserToken.h index c11e707445a2e..1ef21802825b0 100644 --- a/Source/WebCore/css/parser/CSSParserToken.h +++ b/Source/WebCore/css/parser/CSSParserToken.h @@ -174,7 +174,7 @@ class CSSParserToken { bool m_valueIs8Bit : 1 { false }; bool m_isBackedByStringLiteral : 1 { false }; unsigned m_valueLength { 0 }; - const void* m_valueDataCharRaw { nullptr }; // Either LChar* or UChar*. + const void* m_valueDataCharRaw { nullptr }; // Either Latin1Character* or char16_t*. union { UChar m_delimiter; diff --git a/Source/WebCore/css/parser/CSSPropertyParser.cpp b/Source/WebCore/css/parser/CSSPropertyParser.cpp index 26b576b4565a5..5e73417725340 100644 --- a/Source/WebCore/css/parser/CSSPropertyParser.cpp +++ b/Source/WebCore/css/parser/CSSPropertyParser.cpp @@ -88,7 +88,7 @@ bool isCustomPropertyName(StringView propertyName) return propertyName.length() > 2 && propertyName.characterAt(0) == '-' && propertyName.characterAt(1) == '-'; } -static bool hasPrefix(std::span string, std::span prefix) +static bool hasPrefix(std::span string, std::span prefix) { if (string.size() < prefix.size()) return false; diff --git a/Source/WebCore/css/parser/CSSTokenizerInputStream.h b/Source/WebCore/css/parser/CSSTokenizerInputStream.h index 9f404d30ace73..0bf6081eb0681 100644 --- a/Source/WebCore/css/parser/CSSTokenizerInputStream.h +++ b/Source/WebCore/css/parser/CSSTokenizerInputStream.h @@ -33,7 +33,7 @@ namespace WebCore { -constexpr LChar kEndOfFileMarker = 0; +constexpr Latin1Character kEndOfFileMarker = 0; DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(CSSTokenizerInputStream); class CSSTokenizerInputStream { diff --git a/Source/WebCore/css/process-css-properties.py b/Source/WebCore/css/process-css-properties.py index 1f510631524dd..94c2a93860ffd 100755 --- a/Source/WebCore/css/process-css-properties.py +++ b/Source/WebCore/css/process-css-properties.py @@ -2560,7 +2560,7 @@ def _generate_lookup_functions(self, *, to): String nameForIDL(CSSPropertyID id) { - LChar characters[maxCSSPropertyNameLength]; + Latin1Character characters[maxCSSPropertyNameLength]; const char* nameForCSS = nameLiteral(id); if (!nameForCSS) return emptyString(); @@ -2576,7 +2576,7 @@ def _generate_lookup_functions(self, *, to): } *nextCharacter++ = character; } - return std::span { characters, nextCharacter }; + return std::span { characters, nextCharacter }; } """) diff --git a/Source/WebCore/css/process-css-pseudo-selectors.py b/Source/WebCore/css/process-css-pseudo-selectors.py index 49ed1cc65651a..de83a7f07a446 100644 --- a/Source/WebCore/css/process-css-pseudo-selectors.py +++ b/Source/WebCore/css/process-css-pseudo-selectors.py @@ -435,7 +435,7 @@ def prefix_value(prefix, value): def write_parsing_function_definitions_for_pseudo_class(self, writer): longest_keyword_length = len(max(self.mapping, key=len)) writer.write_block(""" - static inline const SelectorPseudoClassOrCompatibilityPseudoElementEntry* findPseudoClassAndCompatibilityElementName(std::span characters) + static inline const SelectorPseudoClassOrCompatibilityPseudoElementEntry* findPseudoClassAndCompatibilityElementName(std::span characters) { return SelectorPseudoClassAndCompatibilityElementMapHash::in_word_set(byteCast(characters.data()), characters.size()); }""") @@ -444,7 +444,7 @@ def write_parsing_function_definitions_for_pseudo_class(self, writer): static inline const SelectorPseudoClassOrCompatibilityPseudoElementEntry* findPseudoClassAndCompatibilityElementName(std::span characters) {{ constexpr unsigned maxKeywordLength = {longest_keyword_length}; - std::array buffer; + std::array buffer; if (characters.size() > maxKeywordLength) return nullptr; @@ -453,7 +453,7 @@ def write_parsing_function_definitions_for_pseudo_class(self, writer): if (!isLatin1(character)) return nullptr; - buffer[i] = static_cast(character); + buffer[i] = static_cast(character); }} return findPseudoClassAndCompatibilityElementName(std::span {{ buffer }}.first(characters.size())); }}""") @@ -475,7 +475,7 @@ def write_parsing_function_definitions_for_pseudo_class(self, writer): def write_parsing_function_definitions_for_pseudo_element(self, writer): longest_keyword_length = len(max(self.mapping, key=len)) writer.write_block(""" - static inline std::optional findPseudoElementName(std::span characters) + static inline std::optional findPseudoElementName(std::span characters) { if (auto entry = SelectorPseudoElementMapHash::in_word_set(byteCast(characters.data()), characters.size())) return entry->type; @@ -486,7 +486,7 @@ def write_parsing_function_definitions_for_pseudo_element(self, writer): static inline std::optional findPseudoElementName(std::span characters) {{ constexpr unsigned maxKeywordLength = {longest_keyword_length}; - std::array buffer; + std::array buffer; if (characters.size() > maxKeywordLength) return std::nullopt; @@ -495,7 +495,7 @@ def write_parsing_function_definitions_for_pseudo_element(self, writer): if (!isLatin1(character)) return std::nullopt; - buffer[i] = static_cast(character); + buffer[i] = static_cast(character); }} return findPseudoElementName(std::span {{ buffer }}.first(characters.size())); }}""") diff --git a/Source/WebCore/css/scripts/test/TestCSSPropertiesResults/CSSPropertyNames.gperf b/Source/WebCore/css/scripts/test/TestCSSPropertiesResults/CSSPropertyNames.gperf new file mode 100644 index 0000000000000..73943bf53762e --- /dev/null +++ b/Source/WebCore/css/scripts/test/TestCSSPropertiesResults/CSSPropertyNames.gperf @@ -0,0 +1,935 @@ +%{ +// This file is automatically generated from CSSProperties.json by the process-css-properties.py script. Do not edit it. + +#include "config.h" +#include "CSSPropertyNames.h" + +#include "BoxSides.h" +#include "CSSProperty.h" +#include "Settings.h" +#include +#include +#include +#include +#include + + +IGNORE_WARNINGS_BEGIN("implicit-fallthrough") +WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN + +// Older versions of gperf like to use the `register` keyword. +#define register + +namespace WebCore { + +static_assert(cssPropertyIDEnumValueCount <= (std::numeric_limits::max() + 1), "CSSPropertyID should fit into uint16_t."); + +const std::array computedPropertyIDs { + CSSPropertyID::CSSPropertyBackgroundFillLayerTestPrimary, + CSSPropertyID::CSSPropertyBackgroundFillLayerTestSecondary, + CSSPropertyID::CSSPropertyBackgroundFillLayerTestSecondaryWithConverter, + CSSPropertyID::CSSPropertyTestAnimationWrapper, + CSSPropertyID::CSSPropertyTestAnimationWrapperAccelerationAlways, + CSSPropertyID::CSSPropertyTestAnimationWrapperAccelerationThreadedOnly, + CSSPropertyID::CSSPropertyTestAutoFunctions, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommas, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommasFixed, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommasNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommasSingleItemOpt, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpaces, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesFixed, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesSingleItemOpt, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithType, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeWithDefaultPrevious, + CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeWithDefaultPreviousTwo, + CSSPropertyID::CSSPropertyTestColor, + CSSPropertyID::CSSPropertyTestColorAllowsTypesAbsolute, + CSSPropertyID::CSSPropertyTestColorPropertyWithNoVisitedLinkSupport, + CSSPropertyID::CSSPropertyTestColorPropertyWithVisitedLinkSupport, + CSSPropertyID::CSSPropertyTestCustomExtractor, + CSSPropertyID::CSSPropertyTestExtractorConverter, + CSSPropertyID::CSSPropertyTestFunctionBoundedParameters, + CSSPropertyID::CSSPropertyTestFunctionFixedParameters, + CSSPropertyID::CSSPropertyTestFunctionNoParameters, + CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllAnyOrder, + CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllAnyOrderWithOptional, + CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllOrdered, + CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllOrderedWithOptional, + CSSPropertyID::CSSPropertyTestFunctionParametersMatchOneOrMoreAnyOrder, + CSSPropertyID::CSSPropertyTestFunctionSingleParameter, + CSSPropertyID::CSSPropertyTestFunctionSingleParameterMatchOne, + CSSPropertyID::CSSPropertyTestFunctionSingleParameterOptional, + CSSPropertyID::CSSPropertyTestFunctionUnboundedParametersNoMin, + CSSPropertyID::CSSPropertyTestFunctionUnboundedParametersWithMinimum, + CSSPropertyID::CSSPropertyTestHighPriority, + CSSPropertyID::CSSPropertyTestImage, + CSSPropertyID::CSSPropertyTestImageNoImageSet, + CSSPropertyID::CSSPropertyTestKeyword, + CSSPropertyID::CSSPropertyTestKeywordWithAliasedTo, + CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalBlock, + CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalInline, + CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal, + CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrder, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithCustomType, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptional, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndCustomType, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndCustomType, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndCustomTypeNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndPreserveOrderAndCustomType, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndPreserveOrderAndCustomTypeNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndPreserveOrderAndCustomType, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalWithPreserveOrder, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalWithPreserveOrderNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithPreserveOrder, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithPreserveOrderAndCustomType, + CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithPreserveOrderNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchAllOrdered, + CSSPropertyID::CSSPropertyTestMatchAllOrderedWithCustomType, + CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptional, + CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndCustomType, + CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndCustomTypeAndNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndMultipleRequired, + CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndMultipleRequiredAndCustomType, + CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchOne, + CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrder, + CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithCustomType, + CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithCustomTypeNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrder, + CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderAndCustomType, + CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderAndCustomTypeNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestMatchOneWithGroupWithSettingsFlag, + CSSPropertyID::CSSPropertyTestMatchOneWithKeywordWithSettingsFlag, + CSSPropertyID::CSSPropertyTestMatchOneWithMultipleKeywords, + CSSPropertyID::CSSPropertyTestMatchOneWithReferenceWithSettingsFlag, + CSSPropertyID::CSSPropertyTestMatchOneWithSettingsFlag, + CSSPropertyID::CSSPropertyTestMediumPriority, + CSSPropertyID::CSSPropertyTestNumericValueRange, + CSSPropertyID::CSSPropertyTestProperty, + CSSPropertyID::CSSPropertyTestSettingsOne, + CSSPropertyID::CSSPropertyTestSharedBuilderExtractorConverter, + CSSPropertyID::CSSPropertyTestSinkPriority, + CSSPropertyID::CSSPropertyTestTopPriority, + CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithCommasWithMin, + CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithCommasWithMinNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithCommasWithMinSingleItemOpt, + CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesNoMin, + CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesNoMinNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesWithMin, + CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesWithMinNoSingleItemOpt, + CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesWithMinSingleItemOpt, + CSSPropertyID::CSSPropertyTestUrlWithModifiers, + CSSPropertyID::CSSPropertyTestUrlWithNoModifiers, + CSSPropertyID::CSSPropertyTestUsingSharedRule, + CSSPropertyID::CSSPropertyTestUsingSharedRuleExported, + CSSPropertyID::CSSPropertyTestUsingSharedRuleWithOverrideFunction, +}; + +constexpr ASCIILiteral propertyNameStrings[numCSSProperties] = { + "test-top-priority"_s, + "test-high-priority"_s, + "background-fill-layer-test-primary"_s, + "test-medium-priority"_s, + "background-fill-layer-test-secondary"_s, + "background-fill-layer-test-secondary-with-converter"_s, + "first-test-descriptor-for-first-descriptor"_s, + "first-test-descriptor-for-second-descriptor"_s, + "test-animation-wrapper"_s, + "test-animation-wrapper-acceleration-always"_s, + "test-animation-wrapper-acceleration-threaded-only"_s, + "test-auto-functions"_s, + "test-bounded-repetition-with-commas"_s, + "test-bounded-repetition-with-commas-fixed"_s, + "test-bounded-repetition-with-commas-no-single-item-opt"_s, + "test-bounded-repetition-with-commas-single-item-opt"_s, + "test-bounded-repetition-with-spaces"_s, + "test-bounded-repetition-with-spaces-fixed"_s, + "test-bounded-repetition-with-spaces-no-single-item-opt"_s, + "test-bounded-repetition-with-spaces-single-item-opt"_s, + "test-bounded-repetition-with-spaces-with-type"_s, + "test-bounded-repetition-with-spaces-with-type-no-single-item-opt"_s, + "test-bounded-repetition-with-spaces-with-type-with-default-previous"_s, + "test-bounded-repetition-with-spaces-with-type-with-default-previous-two"_s, + "test-color"_s, + "test-color-allows-types-absolute"_s, + "test-color-property-with-no-visited-link-support"_s, + "test-color-property-with-visited-link-support"_s, + "test-custom-extractor"_s, + "test-extractor-converter"_s, + "test-function-bounded-parameters"_s, + "test-function-fixed-parameters"_s, + "test-function-no-parameters"_s, + "test-function-parameters-match-all-any-order"_s, + "test-function-parameters-match-all-any-order-with-optional"_s, + "test-function-parameters-match-all-ordered"_s, + "test-function-parameters-match-all-ordered-with-optional"_s, + "test-function-parameters-match-one-or-more-any-order"_s, + "test-function-single-parameter"_s, + "test-function-single-parameter-match-one"_s, + "test-function-single-parameter-optional"_s, + "test-function-unbounded-parameters-no-min"_s, + "test-function-unbounded-parameters-with-minimum"_s, + "test-image"_s, + "test-image-no-image-set"_s, + "test-keyword"_s, + "test-keyword-with-aliased-to"_s, + "test-match-all-any-order"_s, + "test-match-all-any-order-with-custom-type"_s, + "test-match-all-any-order-with-optional"_s, + "test-match-all-any-order-with-optional-and-custom-type"_s, + "test-match-all-any-order-with-optional-and-multiple-required-and-custom-type"_s, + "test-match-all-any-order-with-optional-and-multiple-required-and-custom-type-no-single-item-opt"_s, + "test-match-all-any-order-with-optional-and-multiple-required-and-preserve-order-and-custom-type"_s, + "test-match-all-any-order-with-optional-and-multiple-required-and-preserve-order-and-custom-type-no-single-item-opt"_s, + "test-match-all-any-order-with-optional-and-preserve-order-and-custom-type"_s, + "test-match-all-any-order-with-optional-no-single-item-opt"_s, + "test-match-all-any-order-with-optional-single-item-opt"_s, + "test-match-all-any-order-with-optional-with-preserve-order"_s, + "test-match-all-any-order-with-optional-with-preserve-order-no-single-item-opt"_s, + "test-match-all-any-order-with-preserve-order"_s, + "test-match-all-any-order-with-preserve-order-and-custom-type"_s, + "test-match-all-any-order-with-preserve-order-no-single-item-opt"_s, + "test-match-all-ordered"_s, + "test-match-all-ordered-with-custom-type"_s, + "test-match-all-ordered-with-optional"_s, + "test-match-all-ordered-with-optional-and-custom-type"_s, + "test-match-all-ordered-with-optional-and-custom-type-and-no-single-item-opt"_s, + "test-match-all-ordered-with-optional-and-multiple-required"_s, + "test-match-all-ordered-with-optional-and-multiple-required-and-custom-type"_s, + "test-match-all-ordered-with-optional-no-single-item-opt"_s, + "test-match-all-ordered-with-optional-single-item-opt"_s, + "test-match-one"_s, + "test-match-one-or-more-any-order"_s, + "test-match-one-or-more-any-order-no-single-item-opt"_s, + "test-match-one-or-more-any-order-with-custom-type"_s, + "test-match-one-or-more-any-order-with-custom-type-no-single-item-opt"_s, + "test-match-one-or-more-any-order-with-preserve-order"_s, + "test-match-one-or-more-any-order-with-preserve-order-and-custom-type"_s, + "test-match-one-or-more-any-order-with-preserve-order-and-custom-type-no-single-item-opt"_s, + "test-match-one-or-more-any-order-with-preserve-order-no-single-item-opt"_s, + "test-match-one-with-group-with-settings-flag"_s, + "test-match-one-with-keyword-with-settings-flag"_s, + "test-match-one-with-multiple-keywords"_s, + "test-match-one-with-reference-with-settings-flag"_s, + "test-match-one-with-settings-flag"_s, + "test-numeric-value-range"_s, + "test-property"_s, + "test-settings-one"_s, + "test-shared-builder-extractor-converter"_s, + "test-unbounded-repetition-with-commas-with-min"_s, + "test-unbounded-repetition-with-commas-with-min-no-single-item-opt"_s, + "test-unbounded-repetition-with-commas-with-min-single-item-opt"_s, + "test-unbounded-repetition-with-spaces-no-min"_s, + "test-unbounded-repetition-with-spaces-no-min-no-single-item-opt"_s, + "test-unbounded-repetition-with-spaces-with-min"_s, + "test-unbounded-repetition-with-spaces-with-min-no-single-item-opt"_s, + "test-unbounded-repetition-with-spaces-with-min-single-item-opt"_s, + "test-url-with-modifiers"_s, + "test-url-with-no-modifiers"_s, + "test-using-shared-rule"_s, + "test-using-shared-rule-exported"_s, + "test-using-shared-rule-with-override-function"_s, + "test-sink-priority"_s, + "test-logical-property-group-physical-horizontal"_s, + "test-logical-property-group-physical-vertical"_s, + "test-logical-property-group-logical-block"_s, + "test-logical-property-group-logical-inline"_s, + "all"_s, + "font"_s, + "test-shorthand-one"_s, + "test-shorthand-two"_s, +}; + +%} +%struct-type +struct CSSPropertyHashTableEntry { + const char* name; + uint16_t id; +}; +%language=C++ +%readonly-tables +%global-table +%7bit +%compare-strncmp +%define class-name CSSPropertyNamesHash +%enum + +%% +all, CSSPropertyID::CSSPropertyAll +background-fill-layer-test-primary, CSSPropertyID::CSSPropertyBackgroundFillLayerTestPrimary +background-fill-layer-test-secondary, CSSPropertyID::CSSPropertyBackgroundFillLayerTestSecondary +background-fill-layer-test-secondary-with-converter, CSSPropertyID::CSSPropertyBackgroundFillLayerTestSecondaryWithConverter +first-test-descriptor-for-first-descriptor, CSSPropertyID::CSSPropertyFirstTestDescriptorForFirstDescriptor +first-test-descriptor-for-second-descriptor, CSSPropertyID::CSSPropertyFirstTestDescriptorForSecondDescriptor +font, CSSPropertyID::CSSPropertyFont +test-animation-wrapper, CSSPropertyID::CSSPropertyTestAnimationWrapper +test-animation-wrapper-acceleration-always, CSSPropertyID::CSSPropertyTestAnimationWrapperAccelerationAlways +test-animation-wrapper-acceleration-threaded-only, CSSPropertyID::CSSPropertyTestAnimationWrapperAccelerationThreadedOnly +test-auto-functions, CSSPropertyID::CSSPropertyTestAutoFunctions +test-bounded-repetition-with-commas, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommas +test-bounded-repetition-with-commas-fixed, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommasFixed +test-bounded-repetition-with-commas-no-single-item-opt, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommasNoSingleItemOpt +test-bounded-repetition-with-commas-single-item-opt, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommasSingleItemOpt +test-bounded-repetition-with-spaces, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpaces +test-bounded-repetition-with-spaces-fixed, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesFixed +test-bounded-repetition-with-spaces-no-single-item-opt, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesNoSingleItemOpt +test-bounded-repetition-with-spaces-single-item-opt, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesSingleItemOpt +test-bounded-repetition-with-spaces-with-type, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithType +test-bounded-repetition-with-spaces-with-type-no-single-item-opt, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeNoSingleItemOpt +test-bounded-repetition-with-spaces-with-type-with-default-previous, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeWithDefaultPrevious +test-bounded-repetition-with-spaces-with-type-with-default-previous-two, CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeWithDefaultPreviousTwo +test-color, CSSPropertyID::CSSPropertyTestColor +test-color-allows-types-absolute, CSSPropertyID::CSSPropertyTestColorAllowsTypesAbsolute +test-color-property-with-no-visited-link-support, CSSPropertyID::CSSPropertyTestColorPropertyWithNoVisitedLinkSupport +test-color-property-with-visited-link-support, CSSPropertyID::CSSPropertyTestColorPropertyWithVisitedLinkSupport +test-custom-extractor, CSSPropertyID::CSSPropertyTestCustomExtractor +test-extractor-converter, CSSPropertyID::CSSPropertyTestExtractorConverter +test-function-bounded-parameters, CSSPropertyID::CSSPropertyTestFunctionBoundedParameters +test-function-fixed-parameters, CSSPropertyID::CSSPropertyTestFunctionFixedParameters +test-function-no-parameters, CSSPropertyID::CSSPropertyTestFunctionNoParameters +test-function-parameters-match-all-any-order, CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllAnyOrder +test-function-parameters-match-all-any-order-with-optional, CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllAnyOrderWithOptional +test-function-parameters-match-all-ordered, CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllOrdered +test-function-parameters-match-all-ordered-with-optional, CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllOrderedWithOptional +test-function-parameters-match-one-or-more-any-order, CSSPropertyID::CSSPropertyTestFunctionParametersMatchOneOrMoreAnyOrder +test-function-single-parameter, CSSPropertyID::CSSPropertyTestFunctionSingleParameter +test-function-single-parameter-match-one, CSSPropertyID::CSSPropertyTestFunctionSingleParameterMatchOne +test-function-single-parameter-optional, CSSPropertyID::CSSPropertyTestFunctionSingleParameterOptional +test-function-unbounded-parameters-no-min, CSSPropertyID::CSSPropertyTestFunctionUnboundedParametersNoMin +test-function-unbounded-parameters-with-minimum, CSSPropertyID::CSSPropertyTestFunctionUnboundedParametersWithMinimum +test-high-priority, CSSPropertyID::CSSPropertyTestHighPriority +test-image, CSSPropertyID::CSSPropertyTestImage +test-image-no-image-set, CSSPropertyID::CSSPropertyTestImageNoImageSet +test-keyword, CSSPropertyID::CSSPropertyTestKeyword +test-keyword-with-aliased-to, CSSPropertyID::CSSPropertyTestKeywordWithAliasedTo +test-logical-property-group-logical-block, CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalBlock +test-logical-property-group-logical-inline, CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalInline +test-logical-property-group-physical-horizontal, CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal +test-logical-property-group-physical-vertical, CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical +test-match-all-any-order, CSSPropertyID::CSSPropertyTestMatchAllAnyOrder +test-match-all-any-order-with-custom-type, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithCustomType +test-match-all-any-order-with-optional, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptional +test-match-all-any-order-with-optional-and-custom-type, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndCustomType +test-match-all-any-order-with-optional-and-multiple-required-and-custom-type, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndCustomType +test-match-all-any-order-with-optional-and-multiple-required-and-custom-type-no-single-item-opt, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndCustomTypeNoSingleItemOpt +test-match-all-any-order-with-optional-and-multiple-required-and-preserve-order-and-custom-type, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndPreserveOrderAndCustomType +test-match-all-any-order-with-optional-and-multiple-required-and-preserve-order-and-custom-type-no-single-item-opt, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndPreserveOrderAndCustomTypeNoSingleItemOpt +test-match-all-any-order-with-optional-and-preserve-order-and-custom-type, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndPreserveOrderAndCustomType +test-match-all-any-order-with-optional-no-single-item-opt, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalNoSingleItemOpt +test-match-all-any-order-with-optional-single-item-opt, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalSingleItemOpt +test-match-all-any-order-with-optional-with-preserve-order, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalWithPreserveOrder +test-match-all-any-order-with-optional-with-preserve-order-no-single-item-opt, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalWithPreserveOrderNoSingleItemOpt +test-match-all-any-order-with-preserve-order, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithPreserveOrder +test-match-all-any-order-with-preserve-order-and-custom-type, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithPreserveOrderAndCustomType +test-match-all-any-order-with-preserve-order-no-single-item-opt, CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithPreserveOrderNoSingleItemOpt +test-match-all-ordered, CSSPropertyID::CSSPropertyTestMatchAllOrdered +test-match-all-ordered-with-custom-type, CSSPropertyID::CSSPropertyTestMatchAllOrderedWithCustomType +test-match-all-ordered-with-optional, CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptional +test-match-all-ordered-with-optional-and-custom-type, CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndCustomType +test-match-all-ordered-with-optional-and-custom-type-and-no-single-item-opt, CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndCustomTypeAndNoSingleItemOpt +test-match-all-ordered-with-optional-and-multiple-required, CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndMultipleRequired +test-match-all-ordered-with-optional-and-multiple-required-and-custom-type, CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndMultipleRequiredAndCustomType +test-match-all-ordered-with-optional-no-single-item-opt, CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalNoSingleItemOpt +test-match-all-ordered-with-optional-single-item-opt, CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalSingleItemOpt +test-match-one, CSSPropertyID::CSSPropertyTestMatchOne +test-match-one-or-more-any-order, CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrder +test-match-one-or-more-any-order-no-single-item-opt, CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderNoSingleItemOpt +test-match-one-or-more-any-order-with-custom-type, CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithCustomType +test-match-one-or-more-any-order-with-custom-type-no-single-item-opt, CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithCustomTypeNoSingleItemOpt +test-match-one-or-more-any-order-with-preserve-order, CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrder +test-match-one-or-more-any-order-with-preserve-order-and-custom-type, CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderAndCustomType +test-match-one-or-more-any-order-with-preserve-order-and-custom-type-no-single-item-opt, CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderAndCustomTypeNoSingleItemOpt +test-match-one-or-more-any-order-with-preserve-order-no-single-item-opt, CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderNoSingleItemOpt +test-match-one-with-group-with-settings-flag, CSSPropertyID::CSSPropertyTestMatchOneWithGroupWithSettingsFlag +test-match-one-with-keyword-with-settings-flag, CSSPropertyID::CSSPropertyTestMatchOneWithKeywordWithSettingsFlag +test-match-one-with-multiple-keywords, CSSPropertyID::CSSPropertyTestMatchOneWithMultipleKeywords +test-match-one-with-reference-with-settings-flag, CSSPropertyID::CSSPropertyTestMatchOneWithReferenceWithSettingsFlag +test-match-one-with-settings-flag, CSSPropertyID::CSSPropertyTestMatchOneWithSettingsFlag +test-medium-priority, CSSPropertyID::CSSPropertyTestMediumPriority +test-numeric-value-range, CSSPropertyID::CSSPropertyTestNumericValueRange +test-property, CSSPropertyID::CSSPropertyTestProperty +test-settings-one, CSSPropertyID::CSSPropertyTestSettingsOne +test-shared-builder-extractor-converter, CSSPropertyID::CSSPropertyTestSharedBuilderExtractorConverter +test-shorthand-one, CSSPropertyID::CSSPropertyTestShorthandOne +test-shorthand-two, CSSPropertyID::CSSPropertyTestShorthandTwo +test-sink-priority, CSSPropertyID::CSSPropertyTestSinkPriority +test-top-priority, CSSPropertyID::CSSPropertyTestTopPriority +test-unbounded-repetition-with-commas-with-min, CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithCommasWithMin +test-unbounded-repetition-with-commas-with-min-no-single-item-opt, CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithCommasWithMinNoSingleItemOpt +test-unbounded-repetition-with-commas-with-min-single-item-opt, CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithCommasWithMinSingleItemOpt +test-unbounded-repetition-with-spaces-no-min, CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesNoMin +test-unbounded-repetition-with-spaces-no-min-no-single-item-opt, CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesNoMinNoSingleItemOpt +test-unbounded-repetition-with-spaces-with-min, CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesWithMin +test-unbounded-repetition-with-spaces-with-min-no-single-item-opt, CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesWithMinNoSingleItemOpt +test-unbounded-repetition-with-spaces-with-min-single-item-opt, CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesWithMinSingleItemOpt +test-url-with-modifiers, CSSPropertyID::CSSPropertyTestUrlWithModifiers +test-url-with-no-modifiers, CSSPropertyID::CSSPropertyTestUrlWithNoModifiers +test-using-shared-rule, CSSPropertyID::CSSPropertyTestUsingSharedRule +test-using-shared-rule-exported, CSSPropertyID::CSSPropertyTestUsingSharedRuleExported +test-using-shared-rule-with-override-function, CSSPropertyID::CSSPropertyTestUsingSharedRuleWithOverrideFunction +%% + +CSSPropertyID findCSSProperty(const char* characters, unsigned length) +{ + auto* value = CSSPropertyNamesHash::in_word_set(characters, length); + return value ? static_cast(value->id) : CSSPropertyID::CSSPropertyInvalid; +} + +ASCIILiteral nameLiteral(CSSPropertyID id) +{ + if (id < firstCSSProperty) + return { }; + unsigned index = id - firstCSSProperty; + if (index >= numCSSProperties) + return { }; + return propertyNameStrings[index]; +} + +const AtomString& nameString(CSSPropertyID id) +{ + if (id < firstCSSProperty) + return nullAtom(); + unsigned index = id - firstCSSProperty; + if (index >= numCSSProperties) + return nullAtom(); + + static NeverDestroyed> atomStrings; + auto& string = atomStrings.get()[index]; + if (string.isNull()) + string = propertyNameStrings[index]; + return string; +} + +String nameForIDL(CSSPropertyID id) +{ + Latin1Character characters[maxCSSPropertyNameLength]; + const char* nameForCSS = nameLiteral(id); + if (!nameForCSS) + return emptyString(); + + auto* propertyNamePointer = nameForCSS; + auto* nextCharacter = characters; + while (char character = *propertyNamePointer++) { + if (character == '-') { + char nextCharacter = *propertyNamePointer++; + if (!nextCharacter) + break; + character = (propertyNamePointer - 2 != nameForCSS) ? toASCIIUpper(nextCharacter) : nextCharacter; + } + *nextCharacter++ = character; + } + return std::span { characters, nextCharacter }; +} + + +bool isInternal(CSSPropertyID id) +{ + switch (id) { + return true; + default: + return false; + } +} + +static bool isExposedNotInvalidAndNotInternal(CSSPropertyID id, const CSSPropertySettings& settings) +{ + switch (id) { + case CSSPropertyID::CSSPropertyFirstTestDescriptorForFirstDescriptor: + return settings.cssDescriptorEnabled; + case CSSPropertyID::CSSPropertyTestSettingsOne: + return settings.cssSettingsOneEnabled; + case CSSPropertyID::CSSPropertyTestShorthandTwo: + return settings.cssSettingsShorthandEnabled; + default: + return true; + } +} + +static bool isExposedNotInvalidAndNotInternal(CSSPropertyID id, const Settings& settings) +{ + switch (id) { + case CSSPropertyID::CSSPropertyFirstTestDescriptorForFirstDescriptor: + return settings.cssDescriptorEnabled(); + case CSSPropertyID::CSSPropertyTestSettingsOne: + return settings.cssSettingsOneEnabled(); + case CSSPropertyID::CSSPropertyTestShorthandTwo: + return settings.cssSettingsShorthandEnabled(); + default: + return true; + } +} + +bool isExposed(CSSPropertyID id, const CSSPropertySettings* settings) +{ + if (id == CSSPropertyID::CSSPropertyInvalid || isInternal(id)) + return false; + if (!settings) + return true; + return isExposedNotInvalidAndNotInternal(id, *settings); +} + +bool isExposed(CSSPropertyID id, const CSSPropertySettings& settings) +{ + if (id == CSSPropertyID::CSSPropertyInvalid || isInternal(id)) + return false; + return isExposedNotInvalidAndNotInternal(id, settings); +} + +bool isExposed(CSSPropertyID id, const Settings* settings) +{ + if (id == CSSPropertyID::CSSPropertyInvalid || isInternal(id)) + return false; + if (!settings) + return true; + return isExposedNotInvalidAndNotInternal(id, *settings); +} + +bool isExposed(CSSPropertyID id, const Settings& settings) +{ + if (id == CSSPropertyID::CSSPropertyInvalid || isInternal(id)) + return false; + return isExposedNotInvalidAndNotInternal(id, settings); +} + +constexpr bool isInheritedPropertyTable[cssPropertyIDEnumValueCount] = { + false, // CSSPropertyID::CSSPropertyInvalid + true , // CSSPropertyID::CSSPropertyCustom + false, // CSSPropertyID::CSSPropertyTestTopPriority + false, // CSSPropertyID::CSSPropertyTestHighPriority + false, // CSSPropertyID::CSSPropertyBackgroundFillLayerTestPrimary + false, // CSSPropertyID::CSSPropertyTestMediumPriority + false, // CSSPropertyID::CSSPropertyBackgroundFillLayerTestSecondary + false, // CSSPropertyID::CSSPropertyBackgroundFillLayerTestSecondaryWithConverter + false, // CSSPropertyID::CSSPropertyFirstTestDescriptorForFirstDescriptor + false, // CSSPropertyID::CSSPropertyFirstTestDescriptorForSecondDescriptor + false, // CSSPropertyID::CSSPropertyTestAnimationWrapper + false, // CSSPropertyID::CSSPropertyTestAnimationWrapperAccelerationAlways + false, // CSSPropertyID::CSSPropertyTestAnimationWrapperAccelerationThreadedOnly + false, // CSSPropertyID::CSSPropertyTestAutoFunctions + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommas + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommasFixed + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommasNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommasSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpaces + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesFixed + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithType + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeWithDefaultPrevious + false, // CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeWithDefaultPreviousTwo + false, // CSSPropertyID::CSSPropertyTestColor + false, // CSSPropertyID::CSSPropertyTestColorAllowsTypesAbsolute + false, // CSSPropertyID::CSSPropertyTestColorPropertyWithNoVisitedLinkSupport + false, // CSSPropertyID::CSSPropertyTestColorPropertyWithVisitedLinkSupport + false, // CSSPropertyID::CSSPropertyTestCustomExtractor + false, // CSSPropertyID::CSSPropertyTestExtractorConverter + false, // CSSPropertyID::CSSPropertyTestFunctionBoundedParameters + false, // CSSPropertyID::CSSPropertyTestFunctionFixedParameters + false, // CSSPropertyID::CSSPropertyTestFunctionNoParameters + false, // CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllAnyOrder + false, // CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllAnyOrderWithOptional + false, // CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllOrdered + false, // CSSPropertyID::CSSPropertyTestFunctionParametersMatchAllOrderedWithOptional + false, // CSSPropertyID::CSSPropertyTestFunctionParametersMatchOneOrMoreAnyOrder + false, // CSSPropertyID::CSSPropertyTestFunctionSingleParameter + false, // CSSPropertyID::CSSPropertyTestFunctionSingleParameterMatchOne + false, // CSSPropertyID::CSSPropertyTestFunctionSingleParameterOptional + false, // CSSPropertyID::CSSPropertyTestFunctionUnboundedParametersNoMin + false, // CSSPropertyID::CSSPropertyTestFunctionUnboundedParametersWithMinimum + false, // CSSPropertyID::CSSPropertyTestImage + false, // CSSPropertyID::CSSPropertyTestImageNoImageSet + false, // CSSPropertyID::CSSPropertyTestKeyword + false, // CSSPropertyID::CSSPropertyTestKeywordWithAliasedTo + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrder + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithCustomType + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptional + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndCustomType + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndCustomType + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndCustomTypeNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndPreserveOrderAndCustomType + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndMultipleRequiredAndPreserveOrderAndCustomTypeNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndPreserveOrderAndCustomType + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalWithPreserveOrder + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalWithPreserveOrderNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithPreserveOrder + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithPreserveOrderAndCustomType + false, // CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithPreserveOrderNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchAllOrdered + false, // CSSPropertyID::CSSPropertyTestMatchAllOrderedWithCustomType + false, // CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptional + false, // CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndCustomType + false, // CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndCustomTypeAndNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndMultipleRequired + false, // CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndMultipleRequiredAndCustomType + false, // CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchOne + false, // CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrder + false, // CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithCustomType + false, // CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithCustomTypeNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrder + false, // CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderAndCustomType + false, // CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderAndCustomTypeNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestMatchOneWithGroupWithSettingsFlag + false, // CSSPropertyID::CSSPropertyTestMatchOneWithKeywordWithSettingsFlag + false, // CSSPropertyID::CSSPropertyTestMatchOneWithMultipleKeywords + false, // CSSPropertyID::CSSPropertyTestMatchOneWithReferenceWithSettingsFlag + false, // CSSPropertyID::CSSPropertyTestMatchOneWithSettingsFlag + false, // CSSPropertyID::CSSPropertyTestNumericValueRange + false, // CSSPropertyID::CSSPropertyTestProperty + false, // CSSPropertyID::CSSPropertyTestSettingsOne + false, // CSSPropertyID::CSSPropertyTestSharedBuilderExtractorConverter + false, // CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithCommasWithMin + false, // CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithCommasWithMinNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithCommasWithMinSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesNoMin + false, // CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesNoMinNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesWithMin + false, // CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesWithMinNoSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesWithMinSingleItemOpt + false, // CSSPropertyID::CSSPropertyTestUrlWithModifiers + false, // CSSPropertyID::CSSPropertyTestUrlWithNoModifiers + false, // CSSPropertyID::CSSPropertyTestUsingSharedRule + false, // CSSPropertyID::CSSPropertyTestUsingSharedRuleExported + false, // CSSPropertyID::CSSPropertyTestUsingSharedRuleWithOverrideFunction + false, // CSSPropertyID::CSSPropertyTestSinkPriority + false, // CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal + false, // CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical + false, // CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalBlock + false, // CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalInline + false, // CSSPropertyID::CSSPropertyAll + false, // CSSPropertyID::CSSPropertyFont + false, // CSSPropertyID::CSSPropertyTestShorthandOne + false, // CSSPropertyID::CSSPropertyTestShorthandTwo +}; + +bool CSSProperty::isInheritedProperty(CSSPropertyID id) +{ + ASSERT(id < cssPropertyIDEnumValueCount); + ASSERT(id != CSSPropertyID::CSSPropertyInvalid); + return isInheritedPropertyTable[id]; +} + +CSSPropertyID cascadeAliasProperty(CSSPropertyID id) +{ + switch (id) { + default: + return id; + } +} + +Vector CSSProperty::aliasesForProperty(CSSPropertyID id) +{ + switch (id) { + default: + return { }; + } +} + +const WTF::BitSet CSSProperty::colorProperties = ([]() -> WTF::BitSet { + WTF::BitSet result; + result.set(CSSPropertyID::CSSPropertyTestColor); + result.set(CSSPropertyID::CSSPropertyTestColorAllowsTypesAbsolute); + result.set(CSSPropertyID::CSSPropertyTestColorPropertyWithNoVisitedLinkSupport); + result.set(CSSPropertyID::CSSPropertyTestColorPropertyWithVisitedLinkSupport); + return result; +})(); + +const WTF::BitSet CSSProperty::physicalProperties = ([]() -> WTF::BitSet { + WTF::BitSet result; + result.set(CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal); + result.set(CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical); + return result; +})(); + +char16_t CSSProperty::listValuedPropertySeparator(CSSPropertyID id) +{ + switch (id) { + default: + break; + } + return '\0'; +} + +bool CSSProperty::allowsNumberOrIntegerInput(CSSPropertyID id) +{ + switch (id) { + case CSSPropertyID::CSSPropertyTestTopPriority: + case CSSPropertyID::CSSPropertyTestHighPriority: + case CSSPropertyID::CSSPropertyBackgroundFillLayerTestPrimary: + case CSSPropertyID::CSSPropertyTestMediumPriority: + case CSSPropertyID::CSSPropertyBackgroundFillLayerTestSecondary: + case CSSPropertyID::CSSPropertyBackgroundFillLayerTestSecondaryWithConverter: + case CSSPropertyID::CSSPropertyTestAnimationWrapper: + case CSSPropertyID::CSSPropertyTestAnimationWrapperAccelerationAlways: + case CSSPropertyID::CSSPropertyTestAnimationWrapperAccelerationThreadedOnly: + case CSSPropertyID::CSSPropertyTestAutoFunctions: + case CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommasNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestBoundedRepetitionWithCommasSingleItemOpt: + case CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesSingleItemOpt: + case CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithType: + case CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeWithDefaultPrevious: + case CSSPropertyID::CSSPropertyTestBoundedRepetitionWithSpacesWithTypeWithDefaultPreviousTwo: + case CSSPropertyID::CSSPropertyTestCustomExtractor: + case CSSPropertyID::CSSPropertyTestExtractorConverter: + case CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndCustomType: + case CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalAndPreserveOrderAndCustomType: + case CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalSingleItemOpt: + case CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalWithPreserveOrder: + case CSSPropertyID::CSSPropertyTestMatchAllAnyOrderWithOptionalWithPreserveOrderNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndCustomType: + case CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalAndCustomTypeAndNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestMatchAllOrderedWithOptionalSingleItemOpt: + case CSSPropertyID::CSSPropertyTestMatchOne: + case CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrder: + case CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithCustomType: + case CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithCustomTypeNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrder: + case CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderAndCustomType: + case CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderAndCustomTypeNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestMatchOneOrMoreAnyOrderWithPreserveOrderNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestMatchOneWithGroupWithSettingsFlag: + case CSSPropertyID::CSSPropertyTestMatchOneWithKeywordWithSettingsFlag: + case CSSPropertyID::CSSPropertyTestMatchOneWithMultipleKeywords: + case CSSPropertyID::CSSPropertyTestMatchOneWithReferenceWithSettingsFlag: + case CSSPropertyID::CSSPropertyTestNumericValueRange: + case CSSPropertyID::CSSPropertyTestProperty: + case CSSPropertyID::CSSPropertyTestSettingsOne: + case CSSPropertyID::CSSPropertyTestSharedBuilderExtractorConverter: + case CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithCommasWithMinNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithCommasWithMinSingleItemOpt: + case CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesNoMin: + case CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesNoMinNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesWithMinNoSingleItemOpt: + case CSSPropertyID::CSSPropertyTestUnboundedRepetitionWithSpacesWithMinSingleItemOpt: + case CSSPropertyID::CSSPropertyTestUsingSharedRule: + case CSSPropertyID::CSSPropertyTestSinkPriority: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalBlock: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalInline: + return true; + default: + return false; + } +} + +bool CSSProperty::disablesNativeAppearance(CSSPropertyID id) +{ + switch (id) { + return true; + default: + return false; + } +} + +bool CSSProperty::isTestGroupProperty(CSSPropertyID id) +{ + switch (id) { + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalBlock: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalInline: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical: + case CSSPropertyID::CSSPropertyTestShorthandOne: + case CSSPropertyID::CSSPropertyTestShorthandTwo: + return true; + default: + return false; + } +} + +bool CSSProperty::isInLogicalPropertyGroup(CSSPropertyID id) +{ + switch (id) { + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalBlock: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalInline: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical: + return true; + default: + return false; + } +} + +bool CSSProperty::areInSameLogicalPropertyGroupWithDifferentMappingLogic(CSSPropertyID id1, CSSPropertyID id2) +{ + switch (id1) { + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalBlock: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalInline: + switch (id2) { + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical: + return true; + default: + return false; + } + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical: + switch (id2) { + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalBlock: + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalInline: + return true; + default: + return false; + } + default: + return false; + } +} + +CSSPropertyID CSSProperty::resolveDirectionAwareProperty(CSSPropertyID id, WritingMode writingMode) +{ + switch (id) { + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalBlock: { + static constexpr CSSPropertyID properties[2] = { CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal, CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical }; + return properties[static_cast(mapAxisLogicalToPhysical(writingMode, LogicalBoxAxis::Block))]; + } + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalInline: { + static constexpr CSSPropertyID properties[2] = { CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal, CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical }; + return properties[static_cast(mapAxisLogicalToPhysical(writingMode, LogicalBoxAxis::Inline))]; + } + default: + return id; + } +} + +CSSPropertyID CSSProperty::unresolvePhysicalProperty(CSSPropertyID id, WritingMode writingMode) +{ + switch (id) { + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalHorizontal: { + static constexpr CSSPropertyID properties[2] = { CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalInline, CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalBlock }; + return properties[static_cast(mapAxisPhysicalToLogical(writingMode, BoxAxis::Horizontal))]; + } + case CSSPropertyID::CSSPropertyTestLogicalPropertyGroupPhysicalVertical: { + static constexpr CSSPropertyID properties[2] = { CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalInline, CSSPropertyID::CSSPropertyTestLogicalPropertyGroupLogicalBlock }; + return properties[static_cast(mapAxisPhysicalToLogical(writingMode, BoxAxis::Vertical))]; + } + default: + return id; + } +} + +bool CSSProperty::isDescriptorOnly(CSSPropertyID id) +{ + switch (id) { + case CSSPropertyID::CSSPropertyFirstTestDescriptorForFirstDescriptor: + case CSSPropertyID::CSSPropertyFirstTestDescriptorForSecondDescriptor: + return true; + default: + return false; + } +} + +bool CSSProperty::acceptsQuirkyColor(CSSPropertyID id) +{ + switch (id) { + return true; + default: + return false; + } +} + +bool CSSProperty::acceptsQuirkyLength(CSSPropertyID id) +{ + switch (id) { + return true; + default: + return false; + } +} + +bool CSSProperty::acceptsQuirkyAngle(CSSPropertyID id) +{ + switch (id) { + return true; + default: + return false; + } +} + +bool CSSProperty::animationUsesNonAdditiveOrCumulativeInterpolation(CSSPropertyID id) +{ + switch (id) { + return true; + default: + return false; + } +} + +bool CSSProperty::animationUsesNonNormalizedDiscreteInterpolation(CSSPropertyID id) +{ + switch (id) { + return true; + default: + return false; + } +} + +bool CSSProperty::animationIsAccelerated(CSSPropertyID id, [[maybe_unused]] const Settings& settings) +{ + switch (id) { + case CSSPropertyID::CSSPropertyTestAnimationWrapperAccelerationAlways: + return true; + default: + return false; + } +} + +std::span CSSProperty::allAcceleratedAnimationProperties([[maybe_unused]] const Settings& settings) +{ + static constexpr std::array propertiesExcludingThreadedOnly { + CSSPropertyID::CSSPropertyTestAnimationWrapperAccelerationAlways, + }; + return std::span { propertiesExcludingThreadedOnly }; +} + +CSSPropertySettings::CSSPropertySettings(const Settings& settings) + : cssDescriptorEnabled { settings.cssDescriptorEnabled() } + , cssSettingsOneEnabled { settings.cssSettingsOneEnabled() } + , cssSettingsShorthandEnabled { settings.cssSettingsShorthandEnabled() } +{ +} + +bool operator==(const CSSPropertySettings& a, const CSSPropertySettings& b) +{ + return a.cssDescriptorEnabled == b.cssDescriptorEnabled + && a.cssSettingsOneEnabled == b.cssSettingsOneEnabled + && a.cssSettingsShorthandEnabled == b.cssSettingsShorthandEnabled; +} + +void add(Hasher& hasher, const CSSPropertySettings& settings) +{ + uint64_t bits = settings.cssDescriptorEnabled << 0 + | settings.cssSettingsOneEnabled << 1 + | settings.cssSettingsShorthandEnabled << 2; + add(hasher, bits); +} + + +TextStream& operator<<(TextStream& stream, CSSPropertyID property) +{ + return stream << nameLiteral(property); +} + +} // namespace WebCore + +WTF_ALLOW_UNSAFE_BUFFER_USAGE_END +IGNORE_WARNINGS_END diff --git a/Source/WebCore/dom/DatasetDOMStringMap.cpp b/Source/WebCore/dom/DatasetDOMStringMap.cpp index a0daa09eef8a3..4daf6ae38a2b3 100644 --- a/Source/WebCore/dom/DatasetDOMStringMap.cpp +++ b/Source/WebCore/dom/DatasetDOMStringMap.cpp @@ -111,8 +111,8 @@ static AtomString convertPropertyNameToAttributeName(const String& name) StringImpl* nameImpl = name.impl(); if (nameImpl->is8Bit()) - return convertPropertyNameToAttributeName(*nameImpl); - return convertPropertyNameToAttributeName(*nameImpl); + return convertPropertyNameToAttributeName(*nameImpl); + return convertPropertyNameToAttributeName(*nameImpl); } void DatasetDOMStringMap::ref() diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp index e222e35c1941f..617d44dbce67f 100644 --- a/Source/WebCore/dom/Document.cpp +++ b/Source/WebCore/dom/Document.cpp @@ -1669,7 +1669,7 @@ enum class CustomElementNameCharacterKind : uint8_t { Upper, }; -static ALWAYS_INLINE CustomElementNameCharacterKind customElementNameCharacterKind(LChar character) +static ALWAYS_INLINE CustomElementNameCharacterKind customElementNameCharacterKind(Latin1Character character) { using Kind = CustomElementNameCharacterKind; static const Kind table[] = { @@ -6574,7 +6574,7 @@ void Document::updateCachedCookiesEnabled() }); } -static bool isValidNameNonASCII(std::span characters) +static bool isValidNameNonASCII(std::span characters) { if (!isValidNameStart(characters[0])) return false; @@ -6616,7 +6616,7 @@ static inline bool isValidNameASCII(std::span characters) return true; } -static bool isValidNameASCIIWithoutColon(std::span characters) +static bool isValidNameASCIIWithoutColon(std::span characters) { auto c = characters.front(); if (!(isASCIIAlpha(c) || c == '_')) diff --git a/Source/WebCore/dom/SpaceSplitString.cpp b/Source/WebCore/dom/SpaceSplitString.cpp index 8e5ef6a4df56e..7499a72ac794d 100644 --- a/Source/WebCore/dom/SpaceSplitString.cpp +++ b/Source/WebCore/dom/SpaceSplitString.cpp @@ -140,8 +140,8 @@ bool SpaceSplitString::spaceSplitStringContainsValue(StringView spaceSplitString return false; if (value.is8Bit()) - return spaceSplitStringContainsValueInternal(shouldFoldCase == ShouldFoldCase::Yes ? StringView { spaceSplitString.convertToASCIILowercase() } : spaceSplitString, value); - return spaceSplitStringContainsValueInternal(shouldFoldCase == ShouldFoldCase::Yes ? StringView { spaceSplitString.convertToASCIILowercase() } : spaceSplitString, value); + return spaceSplitStringContainsValueInternal(shouldFoldCase == ShouldFoldCase::Yes ? StringView { spaceSplitString.convertToASCIILowercase() } : spaceSplitString, value); + return spaceSplitStringContainsValueInternal(shouldFoldCase == ShouldFoldCase::Yes ? StringView { spaceSplitString.convertToASCIILowercase() } : spaceSplitString, value); } class TokenCounter { diff --git a/Source/WebCore/dom/make_names.pl b/Source/WebCore/dom/make_names.pl index 043e9cd6539f0..b914e5b3038b3 100755 --- a/Source/WebCore/dom/make_names.pl +++ b/Source/WebCore/dom/make_names.pl @@ -1114,8 +1114,8 @@ sub printNodeNameHeaderFile print F "} // namespace AttributeNames\n"; print F "\n"; print F "NodeName findNodeName(Namespace, const String&);\n"; - print F "ElementName findHTMLElementName(std::span);\n"; - print F "ElementName findHTMLElementName(std::span);\n"; + print F "ElementName findHTMLElementName(std::span);\n"; + print F "ElementName findHTMLElementName(std::span);\n"; print F "ElementName findHTMLElementName(const String&);\n"; print F "ElementName findSVGElementName(const String&);\n"; print F "ElementName findMathMLElementName(const String&);\n"; @@ -1252,7 +1252,7 @@ sub printNodeNameCppFile print F " return findNodeNameFromBuffer(ns, name.span16());\n"; print F "}\n"; print F "\n"; - print F "ElementName findHTMLElementName(std::span buffer)\n"; + print F "ElementName findHTMLElementName(std::span buffer)\n"; print F "{\n"; print F " return findHTMLNodeName(buffer);\n"; print F "}\n"; diff --git a/Source/WebCore/editing/Editing.cpp b/Source/WebCore/editing/Editing.cpp index 96acec93aefb3..4ef5d294d9426 100644 --- a/Source/WebCore/editing/Editing.cpp +++ b/Source/WebCore/editing/Editing.cpp @@ -377,7 +377,7 @@ String stringWithRebalancedWhitespace(const String& string, bool startIsStartOfP previousCharacterWasSpace = false; continue; } - LChar selectedWhitespaceCharacter; + Latin1Character selectedWhitespaceCharacter; // We need to ensure there is no next sibling text node. See https://bugs.webkit.org/show_bug.cgi?id=123163 if (previousCharacterWasSpace || (!i && startIsStartOfParagraph) || (i == length - 1 && shouldEmitNBSPbeforeEnd)) { selectedWhitespaceCharacter = noBreakSpace; diff --git a/Source/WebCore/editing/MarkupAccumulator.cpp b/Source/WebCore/editing/MarkupAccumulator.cpp index 35f4d22ee8258..e639caa6dc39f 100644 --- a/Source/WebCore/editing/MarkupAccumulator.cpp +++ b/Source/WebCore/editing/MarkupAccumulator.cpp @@ -189,7 +189,7 @@ void MarkupAccumulator::appendCharactersReplacingEntities(StringBuilder& result, return; if (source.is8Bit()) - appendCharactersReplacingEntitiesInternal(result, source, offset, length, entityMask); + appendCharactersReplacingEntitiesInternal(result, source, offset, length, entityMask); else appendCharactersReplacingEntitiesInternal(result, source, offset, length, entityMask); } diff --git a/Source/WebCore/editing/cocoa/NodeHTMLConverter.mm b/Source/WebCore/editing/cocoa/NodeHTMLConverter.mm new file mode 100644 index 0000000000000..575d52022b532 --- /dev/null +++ b/Source/WebCore/editing/cocoa/NodeHTMLConverter.mm @@ -0,0 +1,2325 @@ +/* + * Copyright (C) 2011-2025 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "config.h" +#import "NodeHTMLConverter.h" + +#import "ArchiveResource.h" +#import "BoundaryPointInlines.h" +#import "CSSColorValue.h" +#import "CSSComputedStyleDeclaration.h" +#import "CSSPrimitiveValue.h" +#import "CSSSerializationContext.h" +#import "CachedImage.h" +#import "CharacterData.h" +#import "ColorCocoa.h" +#import "ColorMac.h" +#import "CommonAtomStrings.h" +#import "ComposedTreeIterator.h" +#import "ContainerNodeInlines.h" +#import "Document.h" +#import "DocumentLoader.h" +#import "Editing.h" +#import "ElementChildIteratorInlines.h" +#import "ElementInlines.h" +#import "ElementRareData.h" +#import "ElementTraversal.h" +#import "File.h" +#import "FontAttributes.h" +#import "FontCascade.h" +#import "FrameLoader.h" +#import "HTMLAttachmentElement.h" +#import "HTMLConverter.h" +#import "HTMLElement.h" +#import "HTMLFrameElement.h" +#import "HTMLIFrameElement.h" +#import "HTMLImageElement.h" +#import "HTMLInputElement.h" +#import "HTMLMetaElement.h" +#import "HTMLNames.h" +#import "HTMLOListElement.h" +#import "HTMLTableCellElement.h" +#import "HTMLTextAreaElement.h" +#import "ImageAdapter.h" +#import "LoaderNSURLExtras.h" +#import "LocalFrame.h" +#import "LocalizedStrings.h" +#import "NodeName.h" +#import "Quirks.h" +#import "RenderImage.h" +#import "RenderText.h" +#import "StyleExtractor.h" +#import "StyleProperties.h" +#import "StyledElement.h" +#import "TextIterator.h" +#import "VisibleSelection.h" +#import "WebContentReader.h" +#import "WebCoreTextAttachment.h" +#import "markup.h" +#import +#import +#import +#import +#import +#import +#import +#import + +#if ENABLE(DATA_DETECTION) +#import "DataDetection.h" +#endif + +#if ENABLE(MULTI_REPRESENTATION_HEIC) +#import "PlatformNSAdaptiveImageGlyph.h" +#endif + +#if PLATFORM(IOS_FAMILY) +#import "UIFoundationSoftLink.h" +#import "WAKAppKitStubs.h" +#import +#import +#endif + +using namespace WebCore; +using namespace HTMLNames; + +#if PLATFORM(IOS_FAMILY) + +enum { + NSEnterCharacter = 0x0003, + NSBackspaceCharacter = 0x0008, + NSTabCharacter = 0x0009, + NSNewlineCharacter = 0x000a, + NSFormFeedCharacter = 0x000c, + NSCarriageReturnCharacter = 0x000d, + NSBackTabCharacter = 0x0019, + NSDeleteCharacter = 0x007f, + NSLineSeparatorCharacter = 0x2028, + NSParagraphSeparatorCharacter = 0x2029, +}; + +@interface NSTextBlock () +- (void)setWidth:(CGFloat)val type:(NSTextBlockValueType)type forLayer:(NSTextBlockLayer)layer edge:(NSRectEdge)edge; +- (void)setBorderColor:(UIColor *)color forEdge:(NSRectEdge)edge; +@end + +#endif + +// Additional control Unicode characters +const unichar WebNextLineCharacter = 0x0085; + +static const CGFloat defaultFontSize = 12; +static const CGFloat minimumFontSize = 1; + +using NodeSet = HashSet>; + +class HTMLConverterCaches { + WTF_MAKE_TZONE_ALLOCATED(HTMLConverterCaches); +public: + String propertyValueForNode(Node&, CSSPropertyID ); + bool floatPropertyValueForNode(Node&, CSSPropertyID, float&); + Color colorPropertyValueForNode(Node&, CSSPropertyID); + + bool isBlockElement(Element&); + bool elementHasOwnBackgroundColor(Element&); + + RefPtr computedStylePropertyForElement(Element&, CSSPropertyID); + RefPtr inlineStylePropertyForElement(Element&, CSSPropertyID); + + Node* cacheAncestorsOfStartToBeConverted(const Position&, const Position&); + bool isAncestorsOfStartToBeConverted(Node& node) const { return m_ancestorsUnderCommonAncestor.contains(&node); } + +private: + HashMap> m_computedStyles; + NodeSet m_ancestorsUnderCommonAncestor; +}; + +WTF_MAKE_TZONE_ALLOCATED_IMPL(HTMLConverterCaches); + +@interface NSTextList (WebCoreNSTextListDetails) ++ (NSDictionary *)_standardMarkerAttributesForAttributes:(NSDictionary *)attrs; +@end + +@interface NSObject(WebMessageDocumentSimulation) ++ (void)document:(NSObject **)outDocument attachment:(NSTextAttachment **)outAttachment forURL:(NSURL *)url; +@end + +class HTMLConverter { +public: + explicit HTMLConverter(const SimpleRange&, IgnoreUserSelectNone); + ~HTMLConverter(); + + AttributedString convert(); + +private: + Position m_start; + Position m_end; + DocumentLoader* m_dataSource { nullptr }; + + HashMap, RetainPtr> m_attributesForElements; + HashMap, RefPtr> m_textTableFooters; + HashMap, RetainPtr> m_aggregatedAttributesForElements; + + UserSelectNoneStateCache m_userSelectNoneStateCache; + bool m_ignoreUserSelectNoneContent { false }; + + RetainPtr _attrStr; + RetainPtr _documentAttrs; + RetainPtr _topPresentationIntent; + NSInteger _topPresentationIntentIdentity; + RetainPtr _textLists; + RetainPtr _textBlocks; + RetainPtr _textTables; + RetainPtr _textTableSpacings; + RetainPtr _textTablePaddings; + RetainPtr _textTableRows; + RetainPtr _textTableRowArrays; + RetainPtr _textTableRowBackgroundColors; + RetainPtr _fontCache; + RetainPtr _writingDirectionArray; + + CGFloat _defaultTabInterval; + NSUInteger _domRangeStartIndex; + NSInteger _quoteLevel; + + std::unique_ptr _caches; + + struct { + unsigned int isSoft:1; + unsigned int reachedStart:1; + unsigned int reachedEnd:1; + unsigned int hasTrailingNewline:1; + unsigned int pad:26; + } _flags; + + RetainPtr _colorForElement(Element&, CSSPropertyID); + + void _traverseNode(Node&, unsigned depth, bool embedded); + void _traverseFooterNode(Element&, unsigned depth); + + NSDictionary *computedAttributesForElement(Element&); + NSDictionary *attributesForElement(Element&); + NSDictionary *aggregatedAttributesForAncestors(CharacterData&); + NSDictionary* aggregatedAttributesForElementAndItsAncestors(Element&); + + Element* _blockLevelElementForNode(Node*); + +#if ENABLE(MULTI_REPRESENTATION_HEIC) + BOOL _addMultiRepresentationHEICAttachmentForImageElement(HTMLImageElement&); +#endif + + void _newParagraphForElement(Element&, NSString *tag, BOOL flag, BOOL suppressTrailingSpace); + void _newLineForElement(Element&); + void _newTabForElement(Element&); + BOOL _addAttachmentForElement(Element&, NSURL *url, BOOL needsParagraph, BOOL usePlaceholder); + void _addQuoteForElement(Element&, BOOL opening, NSInteger level); + void _addValue(NSString *value, Element&); + void _fillInBlock(NSTextBlock *block, Element&, PlatformColor *backgroundColor, CGFloat extraMargin, CGFloat extraPadding, BOOL isTable); + void _enterBlockquote(); + void _exitBlockquote(); + + BOOL _enterElement(Element&, BOOL embedded); + BOOL _processElement(Element&, NSInteger depth); + void _exitElement(Element&, NSInteger depth, NSUInteger startIndex); + + void _processHeadElement(Element&); + void _processMetaElementWithName(NSString *name, NSString *content); + + void _addLinkForElement(Element&, NSRange); + void _addTableForElement(Element* tableElement); + void _addTableCellForElement(Element* tableCellElement); + void _addMarkersToList(NSTextList *list, NSRange range); + void _processText(Text&); + void _adjustTrailingNewline(); +}; + +HTMLConverter::HTMLConverter(const SimpleRange& range, IgnoreUserSelectNone treatment) + : m_start(makeContainerOffsetPosition(range.start)) + , m_end(makeContainerOffsetPosition(range.end)) + , m_userSelectNoneStateCache(ComposedTree) + , m_ignoreUserSelectNoneContent(treatment == IgnoreUserSelectNone::Yes && !range.start.document().quirks().needsToCopyUserSelectNoneQuirk()) +{ + _attrStr = adoptNS([[NSMutableAttributedString alloc] init]); + _documentAttrs = adoptNS([[NSMutableDictionary alloc] init]); + _topPresentationIntent = nil; + _topPresentationIntentIdentity = 0; + _textLists = adoptNS([[NSMutableArray alloc] init]); + _textBlocks = adoptNS([[NSMutableArray alloc] init]); + _textTables = adoptNS([[NSMutableArray alloc] init]); + _textTableSpacings = adoptNS([[NSMutableArray alloc] init]); + _textTablePaddings = adoptNS([[NSMutableArray alloc] init]); + _textTableRows = adoptNS([[NSMutableArray alloc] init]); + _textTableRowArrays = adoptNS([[NSMutableArray alloc] init]); + _textTableRowBackgroundColors = adoptNS([[NSMutableArray alloc] init]); + _fontCache = adoptNS([[NSMutableDictionary alloc] init]); + _writingDirectionArray = adoptNS([[NSMutableArray alloc] init]); + + _defaultTabInterval = 36; + _domRangeStartIndex = 0; + _quoteLevel = 0; + + _flags.isSoft = false; + _flags.reachedStart = false; + _flags.reachedEnd = false; + + _caches = makeUnique(); +} + +HTMLConverter::~HTMLConverter() = default; + +AttributedString HTMLConverter::convert() +{ + if (m_start > m_end) + return { }; + + Node* commonAncestorContainer = _caches->cacheAncestorsOfStartToBeConverted(m_start, m_end); + ASSERT(commonAncestorContainer); + + m_dataSource = commonAncestorContainer->document().frame()->loader().documentLoader(); + + Document& document = commonAncestorContainer->document(); + if (auto* body = document.bodyOrFrameset()) { + if (auto backgroundColor = _colorForElement(*body, CSSPropertyBackgroundColor)) + [_documentAttrs setObject:backgroundColor.get() forKey:NSBackgroundColorDocumentAttribute]; + } + + _domRangeStartIndex = 0; + _traverseNode(*commonAncestorContainer, 0, false /* embedded */); + if (_domRangeStartIndex > 0 && _domRangeStartIndex <= [_attrStr length]) + [_attrStr deleteCharactersInRange:NSMakeRange(0, _domRangeStartIndex)]; + + return AttributedString::fromNSAttributedStringAndDocumentAttributes(WTFMove(_attrStr), WTFMove(_documentAttrs)); +} + +#if !PLATFORM(IOS_FAMILY) +static RetainPtr fileWrapperForURL(DocumentLoader* dataSource, NSURL *URL) +{ + if ([URL isFileURL]) + return adoptNS([[NSFileWrapper alloc] initWithURL:[URL URLByResolvingSymlinksInPath] options:0 error:nullptr]); + + if (dataSource) { + if (RefPtr resource = dataSource->subresource(URL)) { + auto wrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:resource->data().makeContiguous()->createNSData().get()]); + RetainPtr filename = resource->response().suggestedFilename().createNSString(); + if (!filename || ![filename length]) + filename = suggestedFilenameWithMIMEType(resource->url().createNSURL().get(), resource->mimeType()); + [wrapper setPreferredFilename:filename.get()]; + return wrapper; + } + } + + NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:adoptNS([[NSMutableURLRequest alloc] initWithURL:URL]).get()]; + if (cachedResponse) { + auto wrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:[cachedResponse data]]); + [wrapper setPreferredFilename:[[cachedResponse response] suggestedFilename]]; + return wrapper; + } + + return nil; +} +#endif // !PLATFORM(IOS_FAMILY) + +static PlatformFont *_fontForNameAndSize(NSString *fontName, CGFloat size, NSMutableDictionary *cache) +{ + PlatformFont *font = [cache objectForKey:fontName]; +#if PLATFORM(IOS_FAMILY) + if (font) + return [font fontWithSize:size]; + + font = [PlatformFontClass fontWithName:fontName size:size]; +#else + NSFontManager *fontManager = [NSFontManager sharedFontManager]; + if (font) { + font = [fontManager convertFont:font toSize:size]; + return font; + } + font = [fontManager fontWithFamily:fontName traits:0 weight:0 size:size]; +#endif + if (!font) { +#if PLATFORM(IOS_FAMILY) + NSArray *availableFamilyNames = [PlatformFontClass familyNames]; +#else + NSArray *availableFamilyNames = [fontManager availableFontFamilies]; +#endif + NSRange dividingRange; + NSRange dividingSpaceRange = [fontName rangeOfString:@" " options:NSBackwardsSearch]; + NSRange dividingDashRange = [fontName rangeOfString:@"-" options:NSBackwardsSearch]; + dividingRange = (0 < dividingSpaceRange.length && 0 < dividingDashRange.length) ? (dividingSpaceRange.location > dividingDashRange.location ? dividingSpaceRange : dividingDashRange) : (0 < dividingSpaceRange.length ? dividingSpaceRange : dividingDashRange); + + while (dividingRange.length > 0) { + NSString *familyName = [fontName substringToIndex:dividingRange.location]; + if ([availableFamilyNames containsObject:familyName]) { +#if PLATFORM(IOS_FAMILY) + NSString *faceName = [fontName substringFromIndex:(dividingRange.location + dividingRange.length)]; + NSArray *familyMemberFaceNames = [PlatformFontClass fontNamesForFamilyName:familyName]; + for (NSString *familyMemberFaceName in familyMemberFaceNames) { + if ([familyMemberFaceName compare:faceName options:NSCaseInsensitiveSearch] == NSOrderedSame) { + font = [PlatformFontClass fontWithName:familyMemberFaceName size:size]; + break; + } + } + if (!font && [familyMemberFaceNames count]) + font = [PlatformFontClass fontWithName:familyName size:size]; +#else + NSArray *familyMemberArray; + NSString *faceName = [fontName substringFromIndex:(dividingRange.location + dividingRange.length)]; + NSArray *familyMemberArrays = [fontManager availableMembersOfFontFamily:familyName]; + NSEnumerator *familyMemberArraysEnum = [familyMemberArrays objectEnumerator]; + while ((familyMemberArray = [familyMemberArraysEnum nextObject])) { + NSString *familyMemberFaceName = [familyMemberArray objectAtIndex:1]; + if ([familyMemberFaceName compare:faceName options:NSCaseInsensitiveSearch] == NSOrderedSame) { + NSFontTraitMask traits = [[familyMemberArray objectAtIndex:3] integerValue]; + NSInteger weight = [[familyMemberArray objectAtIndex:2] integerValue]; + font = [fontManager fontWithFamily:familyName traits:traits weight:weight size:size]; + break; + } + } + if (!font) { + if (0 < [familyMemberArrays count]) { + NSArray *familyMemberArray = [familyMemberArrays objectAtIndex:0]; + NSFontTraitMask traits = [[familyMemberArray objectAtIndex:3] integerValue]; + NSInteger weight = [[familyMemberArray objectAtIndex:2] integerValue]; + font = [fontManager fontWithFamily:familyName traits:traits weight:weight size:size]; + } + } +#endif + break; + } else { + dividingSpaceRange = [familyName rangeOfString:@" " options:NSBackwardsSearch]; + dividingDashRange = [familyName rangeOfString:@"-" options:NSBackwardsSearch]; + dividingRange = (0 < dividingSpaceRange.length && 0 < dividingDashRange.length) ? (dividingSpaceRange.location > dividingDashRange.location ? dividingSpaceRange : dividingDashRange) : (0 < dividingSpaceRange.length ? dividingSpaceRange : dividingDashRange); + } + } + } +#if PLATFORM(IOS_FAMILY) + if (!font) + font = [PlatformFontClass systemFontOfSize:size]; +#else + if (!font) + font = [NSFont fontWithName:@"Times" size:size]; + if (!font) + font = [NSFont userFontOfSize:size]; + if (!font) + font = [fontManager convertFont:WebDefaultFont() toSize:size]; + if (!font) + font = WebDefaultFont(); +#endif + [cache setObject:font forKey:fontName]; + + return font; +} + +static NSParagraphStyle *defaultParagraphStyle() +{ + static NeverDestroyed style = [] { + auto style = adoptNS([[PlatformNSParagraphStyle defaultParagraphStyle] mutableCopy]); + [style setDefaultTabInterval:36]; + [style setTabStops:@[]]; + return style; + }(); + return style.get().get(); +} + +RefPtr HTMLConverterCaches::computedStylePropertyForElement(Element& element, CSSPropertyID propertyId) +{ + if (propertyId == CSSPropertyInvalid) + return nullptr; + + auto result = m_computedStyles.add(&element, nullptr); + if (result.isNewEntry) + result.iterator->value = makeUnique(&element, true); + auto& computedStyle = *result.iterator->value; + return computedStyle.propertyValue(propertyId); +} + +RefPtr HTMLConverterCaches::inlineStylePropertyForElement(Element& element, CSSPropertyID propertyId) +{ + if (propertyId == CSSPropertyInvalid) + return nullptr; + + RefPtr styledElement = dynamicDowncast(element); + if (!styledElement) + return nullptr; + + const auto* properties = styledElement->inlineStyle(); + if (!properties) + return nullptr; + return properties->getPropertyCSSValue(propertyId); +} + +static bool stringFromCSSValue(CSSValue& value, String& result) +{ + if (auto* primitiveValue = dynamicDowncast(value)) { + // FIXME: Use isStringType(CSSUnitType)? + auto primitiveType = primitiveValue->primitiveType(); + if (primitiveType == CSSUnitType::CSS_STRING || primitiveType == CSSUnitType::CSS_IDENT || primitiveType == CSSUnitType::CSS_ATTR) { + auto stringValue = value.cssText(CSS::defaultSerializationContext()); + if (stringValue.length()) { + result = stringValue; + return true; + } + } + } else if (value.isValueList() || value.isAppleColorFilterValue() || value.isFilterValue() || value.isTextShadowPropertyValue() || value.isBoxShadowPropertyValue() || value.isURL()) { + result = value.cssText(CSS::defaultSerializationContext()); + return true; + } + return false; +} + +String HTMLConverterCaches::propertyValueForNode(Node& node, CSSPropertyID propertyId) +{ + using namespace ElementNames; + + RefPtr element = dynamicDowncast(node); + if (!element) { + if (RefPtr parent = node.parentInComposedTree()) + return propertyValueForNode(*parent, propertyId); + return String(); + } + + bool inherit = false; + if (RefPtr value = computedStylePropertyForElement(*element, propertyId)) { + String result; + if (stringFromCSSValue(*value, result)) + return result; + } + + if (RefPtr value = inlineStylePropertyForElement(*element, propertyId)) { + String result; + if (isValueID(*value, CSSValueInherit)) + inherit = true; + else if (stringFromCSSValue(*value, result)) + return result; + } + + switch (propertyId) { + case CSSPropertyDisplay: + switch (element->elementName()) { + case HTML::head: + case HTML::script: + case HTML::applet: + case HTML::noframes: + return noneAtom(); + case HTML::address: + case HTML::blockquote: + case HTML::body: + case HTML::center: + case HTML::dd: + case HTML::dir: + case HTML::div: + case HTML::dl: + case HTML::dt: + case HTML::fieldset: + case HTML::form: + case HTML::frame: + case HTML::frameset: + case HTML::hr: + case HTML::html: + case HTML::h1: + case HTML::h2: + case HTML::h3: + case HTML::h4: + case HTML::h5: + case HTML::h6: + case HTML::iframe: + case HTML::menu: + case HTML::noscript: + case HTML::ol: + case HTML::p: + case HTML::pre: + case HTML::ul: + return "block"_s; + case HTML::li: + return "list-item"_s; + case HTML::table: + return "table"_s; + case HTML::tr: + return "table-row"_s; + case HTML::th: + case HTML::td: + return "table-cell"_s; + case HTML::thead: + return "table-header-group"_s; + case HTML::tbody: + return "table-row-group"_s; + case HTML::tfoot: + return "table-footer-group"_s; + case HTML::col: + return "table-column"_s; + case HTML::colgroup: + return "table-column-group"_s; + case HTML::caption: + return "table-caption"_s; + default: + break; + } + break; + case CSSPropertyWhiteSpace: + if (element->hasTagName(preTag)) + return "pre"_s; + inherit = true; + break; + case CSSPropertyFontStyle: + if (element->hasTagName(iTag) || element->hasTagName(citeTag) || element->hasTagName(emTag) || element->hasTagName(varTag) || element->hasTagName(addressTag)) + return "italic"_s; + inherit = true; + break; + case CSSPropertyFontWeight: + if (element->hasTagName(bTag) || element->hasTagName(strongTag) || element->hasTagName(thTag)) + return "bolder"_s; + inherit = true; + break; + case CSSPropertyTextDecorationLine: + switch (element->elementName()) { + case HTML::u: + case HTML::ins: + return "underline"_s; + case HTML::s: + case HTML::strike: + case HTML::del: + return "line-through"_s; + default: + break; + } + inherit = true; // FIXME: This is not strictly correct + break; + case CSSPropertyTextAlign: + if (element->hasTagName(centerTag) || element->hasTagName(captionTag) || element->hasTagName(thTag)) + return "center"_s; + inherit = true; + break; + case CSSPropertyVerticalAlign: + switch (element->elementName()) { + case HTML::sup: + return "super"_s; + case HTML::sub: + return "sub"_s; + case HTML::thead: + case HTML::tbody: + case HTML::tfoot: + return "middle"_s; + case HTML::tr: + case HTML::th: + case HTML::td: + inherit = true; + break; + default: + break; + } + break; + case CSSPropertyFontFamily: + case CSSPropertyFontVariantCaps: + case CSSPropertyTextTransform: + case CSSPropertyTextShadow: + case CSSPropertyVisibility: + case CSSPropertyBorderCollapse: + case CSSPropertyEmptyCells: + case CSSPropertyWordSpacing: + case CSSPropertyListStyleType: + case CSSPropertyDirection: + inherit = true; // FIXME: Let classes in the css component figure this out. + break; + default: + break; + } + + if (inherit) { + if (RefPtr parent = node.parentInComposedTree()) + return propertyValueForNode(*parent, propertyId); + } + + return String(); +} + +static inline bool floatValueFromPrimitiveValue(CSSPrimitiveValue& primitiveValue, float& result) +{ + switch (primitiveValue.primitiveType()) { + case CSSUnitType::CSS_PX: + case CSSUnitType::CSS_PT: + case CSSUnitType::CSS_PC: + case CSSUnitType::CSS_CM: + case CSSUnitType::CSS_MM: + case CSSUnitType::CSS_Q: + case CSSUnitType::CSS_IN: + result = primitiveValue.resolveAsLengthDeprecated(); + return true; + default: + return false; + } +} + +bool HTMLConverterCaches::floatPropertyValueForNode(Node& node, CSSPropertyID propertyId, float& result) +{ + RefPtr element = dynamicDowncast(node); + if (!element) { + if (RefPtr parent = node.parentInComposedTree()) + return floatPropertyValueForNode(*parent, propertyId, result); + return false; + } + + if (RefPtr value = computedStylePropertyForElement(*element, propertyId)) { + if (RefPtr primitiveValue = dynamicDowncast(*value); primitiveValue && floatValueFromPrimitiveValue(*primitiveValue, result)) + return true; + } + + bool inherit = false; + if (RefPtr value = inlineStylePropertyForElement(*element, propertyId)) { + if (RefPtr primitiveValue = dynamicDowncast(*value); primitiveValue && floatValueFromPrimitiveValue(*primitiveValue, result)) + return true; + if (isValueID(*value, CSSValueInherit)) + inherit = true; + } + + switch (propertyId) { + case CSSPropertyTextIndent: + case CSSPropertyLetterSpacing: + case CSSPropertyWordSpacing: + case CSSPropertyLineHeight: + case CSSPropertyWidows: + case CSSPropertyOrphans: + inherit = true; + break; + default: + break; + } + + if (inherit) { + if (RefPtr parent = node.parentInComposedTree()) + return floatPropertyValueForNode(*parent, propertyId, result); + } + + return false; +} + +static inline NSShadow *_shadowForShadowStyle(NSString *shadowStyle) +{ + RetainPtr shadow; + NSUInteger shadowStyleLength = [shadowStyle length]; + NSRange openParenRange = [shadowStyle rangeOfString:@"("]; + NSRange closeParenRange = [shadowStyle rangeOfString:@")"]; + NSRange firstRange = NSMakeRange(NSNotFound, 0); + NSRange secondRange = NSMakeRange(NSNotFound, 0); + NSRange thirdRange = NSMakeRange(NSNotFound, 0); + NSRange spaceRange; + if (openParenRange.length > 0 && closeParenRange.length > 0 && NSMaxRange(openParenRange) < closeParenRange.location) { + NSArray *components = [[shadowStyle substringWithRange:NSMakeRange(NSMaxRange(openParenRange), closeParenRange.location - NSMaxRange(openParenRange))] componentsSeparatedByString:@","]; + if ([components count] >= 3) { + CGFloat red = [[components objectAtIndex:0] floatValue] / 255; + CGFloat green = [[components objectAtIndex:1] floatValue] / 255; + CGFloat blue = [[components objectAtIndex:2] floatValue] / 255; + CGFloat alpha = ([components count] >= 4) ? [[components objectAtIndex:3] floatValue] / 255 : 1; + NSColor *shadowColor = [PlatformNSColorClass colorWithCalibratedRed:red green:green blue:blue alpha:alpha]; + NSSize shadowOffset; + CGFloat shadowBlurRadius; + firstRange = [shadowStyle rangeOfString:@"px"]; + if (firstRange.length > 0 && NSMaxRange(firstRange) < shadowStyleLength) + secondRange = [shadowStyle rangeOfString:@"px" options:0 range:NSMakeRange(NSMaxRange(firstRange), shadowStyleLength - NSMaxRange(firstRange))]; + if (secondRange.length > 0 && NSMaxRange(secondRange) < shadowStyleLength) + thirdRange = [shadowStyle rangeOfString:@"px" options:0 range:NSMakeRange(NSMaxRange(secondRange), shadowStyleLength - NSMaxRange(secondRange))]; + if (firstRange.location > 0 && firstRange.length > 0 && secondRange.length > 0 && thirdRange.length > 0) { + spaceRange = [shadowStyle rangeOfString:@" " options:NSBackwardsSearch range:NSMakeRange(0, firstRange.location)]; + if (spaceRange.length == 0) + spaceRange = NSMakeRange(0, 0); + shadowOffset.width = [[shadowStyle substringWithRange:NSMakeRange(NSMaxRange(spaceRange), firstRange.location - NSMaxRange(spaceRange))] floatValue]; + spaceRange = [shadowStyle rangeOfString:@" " options:NSBackwardsSearch range:NSMakeRange(0, secondRange.location)]; + if (!spaceRange.length) + spaceRange = NSMakeRange(0, 0); + CGFloat shadowHeight = [[shadowStyle substringWithRange:NSMakeRange(NSMaxRange(spaceRange), secondRange.location - NSMaxRange(spaceRange))] floatValue]; + // I don't know why we have this difference between the two platforms. +#if PLATFORM(IOS_FAMILY) + shadowOffset.height = shadowHeight; +#else + shadowOffset.height = -shadowHeight; +#endif + spaceRange = [shadowStyle rangeOfString:@" " options:NSBackwardsSearch range:NSMakeRange(0, thirdRange.location)]; + if (!spaceRange.length) + spaceRange = NSMakeRange(0, 0); + shadowBlurRadius = [[shadowStyle substringWithRange:NSMakeRange(NSMaxRange(spaceRange), thirdRange.location - NSMaxRange(spaceRange))] floatValue]; + shadow = adoptNS([(NSShadow *)[PlatformNSShadow alloc] init]); + [shadow setShadowColor:shadowColor]; + [shadow setShadowOffset:shadowOffset]; + [shadow setShadowBlurRadius:shadowBlurRadius]; + } + } + } + return shadow.autorelease(); +} + +bool HTMLConverterCaches::isBlockElement(Element& element) +{ + String displayValue = propertyValueForNode(element, CSSPropertyDisplay); + if (displayValue == "block"_s || displayValue == "list-item"_s || displayValue.startsWith("table"_s)) + return true; + String floatValue = propertyValueForNode(element, CSSPropertyFloat); + if (floatValue == "left"_s || floatValue == "right"_s) + return true; + return false; +} + +bool HTMLConverterCaches::elementHasOwnBackgroundColor(Element& element) +{ + if (!isBlockElement(element)) + return false; + // In the text system, text blocks (table elements) and documents (body elements) + // have their own background colors, which should not be inherited. + return element.hasTagName(htmlTag) || element.hasTagName(bodyTag) || propertyValueForNode(element, CSSPropertyDisplay).startsWith("table"_s); +} + +Element* HTMLConverter::_blockLevelElementForNode(Node* node) +{ + RefPtr element = dynamicDowncast(node); + if (!element) + element = node->parentElement(); + if (element && !_caches->isBlockElement(*element)) + element = _blockLevelElementForNode(element->parentInComposedTree()); + return element.get(); +} + +static Color normalizedColor(Color color, bool ignoreDefaultColor, Element& element) +{ + if (!ignoreDefaultColor) + return color; + + bool useDarkAppearance = element.document().useDarkAppearance(element.existingComputedStyle()); + if (useDarkAppearance && Color::isWhiteColor(color)) + return Color(); + + if (!useDarkAppearance && Color::isBlackColor(color)) + return Color(); + + return color; +} + +Color HTMLConverterCaches::colorPropertyValueForNode(Node& node, CSSPropertyID propertyId) +{ + RefPtr element = dynamicDowncast(node); + if (!element) { + if (RefPtr parent = node.parentInComposedTree()) + return colorPropertyValueForNode(*parent, propertyId); + return Color(); + } + + bool ignoreDefaultColor = propertyId == CSSPropertyColor; + + if (auto value = computedStylePropertyForElement(*element, propertyId); value && value->isColor()) + return normalizedColor(CSSColorValue::absoluteColor(*value), ignoreDefaultColor, *element); + + bool inherit = false; + if (auto value = inlineStylePropertyForElement(*element, propertyId)) { + if (value->isColor()) + return normalizedColor(CSSColorValue::absoluteColor(*value), ignoreDefaultColor, *element); + if (isValueID(*value, CSSValueInherit)) + inherit = true; + } + + switch (propertyId) { + case CSSPropertyColor: + inherit = true; + break; + case CSSPropertyBackgroundColor: + if (!elementHasOwnBackgroundColor(*element)) { + if (auto* parentElement = node.parentElement()) { + if (!elementHasOwnBackgroundColor(*parentElement)) + inherit = true; + } + } + break; + default: + break; + } + + if (inherit) { + if (RefPtr parent = node.parentInComposedTree()) + return colorPropertyValueForNode(*parent, propertyId); + } + + return Color(); +} + +RetainPtr HTMLConverter::_colorForElement(Element& element, CSSPropertyID propertyId) +{ + Color result = _caches->colorPropertyValueForNode(element, propertyId); + if (!result.isValid()) + return nil; + auto platformResult = cocoaColor(result); + if ([[PlatformColorClass clearColor] isEqual:platformResult.get()] || ([platformResult alphaComponent] == 0.0)) + return nil; + return platformResult; +} + +static PlatformFont *_font(Element& element) +{ + auto* renderer = element.renderer(); + if (!renderer) + return nil; + Ref primaryFont = renderer->style().fontCascade().primaryFont(); + if (primaryFont->attributes().origin == FontOrigin::Remote) + return [PlatformFontClass systemFontOfSize:defaultFontSize]; + return (__bridge PlatformFont *)primaryFont->ctFont(); +} + +NSDictionary *HTMLConverter::computedAttributesForElement(Element& element) +{ + NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; +#if !PLATFORM(IOS_FAMILY) + NSFontManager *fontManager = [NSFontManager sharedFontManager]; +#endif + + PlatformFont *font = nil; + PlatformFont *actualFont = _font(element); + auto foregroundColor = _colorForElement(element, CSSPropertyColor); + auto backgroundColor = _colorForElement(element, CSSPropertyBackgroundColor); + auto strokeColor = _colorForElement(element, CSSPropertyWebkitTextStrokeColor); + + float fontSize = 0; + if (!_caches->floatPropertyValueForNode(element, CSSPropertyFontSize, fontSize) || fontSize <= 0.0) + fontSize = defaultFontSize; + if (fontSize < minimumFontSize) + fontSize = minimumFontSize; + if (std::abs(floor(2.0 * fontSize + 0.5) / 2.0 - fontSize) < 0.05) + fontSize = floor(2.0 * fontSize + 0.5) / 2; + else if (std::abs(floor(10.0 * fontSize + 0.5) / 10.0 - fontSize) < 0.005) + fontSize = floor(10.0 * fontSize + 0.5) / 10; + + if (fontSize <= 0.0) + fontSize = defaultFontSize; + +#if PLATFORM(IOS_FAMILY) + if (actualFont) + font = [actualFont fontWithSize:fontSize]; +#else + if (actualFont) + font = [fontManager convertFont:actualFont toSize:fontSize]; +#endif + if (!font) { + String fontName = _caches->propertyValueForNode(element, CSSPropertyFontFamily); + if (fontName.length()) + font = _fontForNameAndSize(fontName.convertToASCIILowercase().createNSString().get(), fontSize, _fontCache.get()); + if (!font) + font = [PlatformFontClass fontWithName:@"Times" size:fontSize]; + + String fontStyle = _caches->propertyValueForNode(element, CSSPropertyFontStyle); + if (fontStyle == "italic"_s || fontStyle == "oblique"_s) { + PlatformFont *originalFont = font; +#if PLATFORM(IOS_FAMILY) + font = [PlatformFontClass fontWithFamilyName:[font familyName] traits:UIFontTraitItalic size:[font pointSize]]; +#else + font = [fontManager convertFont:font toHaveTrait:NSItalicFontMask]; +#endif + if (!font) + font = originalFont; + } + + String fontWeight = _caches->propertyValueForNode(element, CSSPropertyFontStyle); + if (fontWeight.startsWith("bold"_s) || parseIntegerAllowingTrailingJunk(fontWeight).value_or(0) >= 700) { + // ??? handle weight properly using NSFontManager + PlatformFont *originalFont = font; +#if PLATFORM(IOS_FAMILY) + font = [PlatformFontClass fontWithFamilyName:[font familyName] traits:UIFontTraitBold size:[font pointSize]]; +#else + font = [fontManager convertFont:font toHaveTrait:NSBoldFontMask]; +#endif + if (!font) + font = originalFont; + } +#if !PLATFORM(IOS_FAMILY) // IJB: No small caps support on iOS + if (_caches->propertyValueForNode(element, CSSPropertyFontVariantCaps) == "small-caps"_s) { + // ??? synthesize small-caps if [font isEqual:originalFont] + NSFont *originalFont = font; + font = [fontManager convertFont:font toHaveTrait:NSSmallCapsFontMask]; + if (!font) + font = originalFont; + } +#endif + } + if (font) + [attrs setObject:font forKey:NSFontAttributeName]; + if (foregroundColor) + [attrs setObject:foregroundColor.get() forKey:NSForegroundColorAttributeName]; + if (backgroundColor && !_caches->elementHasOwnBackgroundColor(element)) + [attrs setObject:backgroundColor.get() forKey:NSBackgroundColorAttributeName]; + + float strokeWidth = 0.0; + if (_caches->floatPropertyValueForNode(element, CSSPropertyWebkitTextStrokeWidth, strokeWidth)) { + float textStrokeWidth = strokeWidth / ([font pointSize] * 0.01); + [attrs setObject:@(textStrokeWidth) forKey:NSStrokeWidthAttributeName]; + } + if (strokeColor) + [attrs setObject:strokeColor.get() forKey:NSStrokeColorAttributeName]; + + String fontKerning = _caches->propertyValueForNode(element, CSSPropertyFontKerning); + String letterSpacing = _caches->propertyValueForNode(element, CSSPropertyLetterSpacing); + if (fontKerning.length() || letterSpacing.length()) { + if (fontKerning == noneAtom()) + [attrs setObject:@0.0 forKey:NSKernAttributeName]; + else { + double kernVal = letterSpacing.length() ? letterSpacing.toDouble() : 0.0; + if (std::abs(kernVal - 0) < FLT_EPSILON) + [attrs setObject:@0.0 forKey:NSKernAttributeName]; // auto and normal, the other possible values, are both "kerning enabled" + else + [attrs setObject:@(kernVal) forKey:NSKernAttributeName]; + } + } + + String fontLigatures = _caches->propertyValueForNode(element, CSSPropertyFontVariantLigatures); + if (fontLigatures.length()) { + if (fontLigatures.contains("normal"_s)) + ; // default: whatever the system decides to do + else if (fontLigatures.contains("common-ligatures"_s)) + [attrs setObject:@1 forKey:NSLigatureAttributeName]; // explicitly enabled + else if (fontLigatures.contains("no-common-ligatures"_s)) + [attrs setObject:@0 forKey:NSLigatureAttributeName]; // explicitly disabled + } + + String textDecoration = _caches->propertyValueForNode(element, CSSPropertyTextDecorationLine); + if (textDecoration.length()) { + if (textDecoration.contains("underline"_s)) + [attrs setObject:[NSNumber numberWithInteger:NSUnderlineStyleSingle] forKey:NSUnderlineStyleAttributeName]; + if (textDecoration.contains("line-through"_s)) + [attrs setObject:[NSNumber numberWithInteger:NSUnderlineStyleSingle] forKey:NSStrikethroughStyleAttributeName]; + } + + String verticalAlign = _caches->propertyValueForNode(element, CSSPropertyVerticalAlign); + if (verticalAlign.length()) { + if (verticalAlign == "super"_s) + [attrs setObject:[NSNumber numberWithInteger:1] forKey:NSSuperscriptAttributeName]; + else if (verticalAlign == "sub"_s) + [attrs setObject:[NSNumber numberWithInteger:-1] forKey:NSSuperscriptAttributeName]; + } + + float baselineOffset = 0.0; + if (_caches->floatPropertyValueForNode(element, CSSPropertyVerticalAlign, baselineOffset)) + [attrs setObject:@(baselineOffset) forKey:NSBaselineOffsetAttributeName]; + + String textShadow = _caches->propertyValueForNode(element, CSSPropertyTextShadow); + if (textShadow.length() > 4) { + NSShadow *shadow = _shadowForShadowStyle(textShadow.createNSString().get()); + if (shadow) + [attrs setObject:shadow forKey:NSShadowAttributeName]; + } + + Element* blockElement = _blockLevelElementForNode(&element); + if (&element != blockElement && [_writingDirectionArray count] > 0) + [attrs setObject:[NSArray arrayWithArray:_writingDirectionArray.get()] forKey:NSWritingDirectionAttributeName]; + + if (blockElement) { + Element& coreBlockElement = *blockElement; + RetainPtr paragraphStyle = adoptNS([defaultParagraphStyle() mutableCopy]); + unsigned heading = 0; + if (coreBlockElement.hasTagName(h1Tag)) + heading = 1; + else if (coreBlockElement.hasTagName(h2Tag)) + heading = 2; + else if (coreBlockElement.hasTagName(h3Tag)) + heading = 3; + else if (coreBlockElement.hasTagName(h4Tag)) + heading = 4; + else if (coreBlockElement.hasTagName(h5Tag)) + heading = 5; + else if (coreBlockElement.hasTagName(h6Tag)) + heading = 6; + else if (coreBlockElement.hasTagName(blockquoteTag) && _topPresentationIntent) + [attrs setObject:_topPresentationIntent.get() forKey:NSPresentationIntentAttributeName]; + bool isParagraph = coreBlockElement.hasTagName(pTag) || coreBlockElement.hasTagName(liTag) || heading || coreBlockElement.hasTagName(blockquoteTag); + + String textAlign = _caches->propertyValueForNode(coreBlockElement, CSSPropertyTextAlign); + if (textAlign.length()) { + // WebKit can return -khtml-left, -khtml-right, -khtml-center + if (textAlign.endsWith("left"_s)) + [paragraphStyle setAlignment:NSTextAlignmentLeft]; + else if (textAlign.endsWith("right"_s)) + [paragraphStyle setAlignment:NSTextAlignmentRight]; + else if (textAlign.endsWith("center"_s)) + [paragraphStyle setAlignment:NSTextAlignmentCenter]; + else if (textAlign.endsWith("justify"_s)) + [paragraphStyle setAlignment:NSTextAlignmentJustified]; + } + + String direction = _caches->propertyValueForNode(coreBlockElement, CSSPropertyDirection); + if (direction.length()) { + if (direction == "ltr"_s) + [paragraphStyle setBaseWritingDirection:NSWritingDirectionLeftToRight]; + else if (direction == "rtl"_s) + [paragraphStyle setBaseWritingDirection:NSWritingDirectionRightToLeft]; + } + + String hyphenation = _caches->propertyValueForNode(coreBlockElement, CSSPropertyHyphens); + if (hyphenation.length()) { + if (hyphenation == autoAtom()) + [paragraphStyle setHyphenationFactor:1.0]; + else + [paragraphStyle setHyphenationFactor:0.0]; + } + if (heading) + [paragraphStyle setHeaderLevel:heading]; + if (isParagraph) { + // FIXME: Why are we ignoring margin-top? + float marginLeft = 0.0; + if (_caches->floatPropertyValueForNode(coreBlockElement, CSSPropertyMarginLeft, marginLeft) && marginLeft > 0.0) + [paragraphStyle setHeadIndent:marginLeft]; + float textIndent = 0.0; + if (_caches->floatPropertyValueForNode(coreBlockElement, CSSPropertyTextIndent, textIndent) && textIndent > 0.0) + [paragraphStyle setFirstLineHeadIndent:[paragraphStyle headIndent] + textIndent]; + float marginRight = 0.0; + if (_caches->floatPropertyValueForNode(coreBlockElement, CSSPropertyMarginRight, marginRight) && marginRight > 0.0) + [paragraphStyle setTailIndent:-marginRight]; + float marginBottom = 0.0; + if (_caches->floatPropertyValueForNode(coreBlockElement, CSSPropertyMarginBottom, marginBottom) && marginBottom > 0.0) + [paragraphStyle setParagraphSpacing:marginBottom]; + } + if ([_textLists count] > 0) + [paragraphStyle setTextLists:_textLists.get()]; + if ([_textBlocks count] > 0) + [paragraphStyle setTextBlocks:_textBlocks.get()]; + [attrs setObject:paragraphStyle.get() forKey:NSParagraphStyleAttributeName]; + } + return attrs; +} + + +NSDictionary* HTMLConverter::attributesForElement(Element& element) +{ + auto& attributes = m_attributesForElements.add(&element, nullptr).iterator->value; + if (!attributes) + attributes = computedAttributesForElement(element); + return attributes.get(); +} + +NSDictionary* HTMLConverter::aggregatedAttributesForAncestors(CharacterData& node) +{ + Node* ancestor = node.parentInComposedTree(); + while (ancestor && !is(*ancestor)) + ancestor = ancestor->parentInComposedTree(); + if (!ancestor) + return nullptr; + return aggregatedAttributesForElementAndItsAncestors(downcast(*ancestor)); +} + +NSDictionary* HTMLConverter::aggregatedAttributesForElementAndItsAncestors(Element& element) +{ + auto& cachedAttributes = m_aggregatedAttributesForElements.add(&element, nullptr).iterator->value; + if (cachedAttributes) + return cachedAttributes.get(); + + NSDictionary* attributesForCurrentElement = attributesForElement(element); + ASSERT(attributesForCurrentElement); + + Node* ancestor = element.parentInComposedTree(); + while (ancestor && !is(*ancestor)) + ancestor = ancestor->parentInComposedTree(); + + if (!ancestor) { + cachedAttributes = attributesForCurrentElement; + return attributesForCurrentElement; + } + + RetainPtr attributesForAncestors = adoptNS([aggregatedAttributesForElementAndItsAncestors(downcast(*ancestor)) mutableCopy]); + [attributesForAncestors addEntriesFromDictionary:attributesForCurrentElement]; + m_aggregatedAttributesForElements.set(&element, attributesForAncestors); + + return attributesForAncestors.get(); +} + +void HTMLConverter::_newParagraphForElement(Element& element, NSString *tag, BOOL flag, BOOL suppressTrailingSpace) +{ + NSUInteger textLength = [_attrStr length]; + unichar lastChar = (textLength > 0) ? [[_attrStr string] characterAtIndex:textLength - 1] : '\n'; + NSRange rangeToReplace = (suppressTrailingSpace && _flags.isSoft && (lastChar == ' ' || lastChar == NSLineSeparatorCharacter)) ? NSMakeRange(textLength - 1, 1) : NSMakeRange(textLength, 0); + BOOL needBreak = (flag || lastChar != '\n'); + if (needBreak) { + NSString *string = (([@"BODY" isEqualToString:tag] || [@"HTML" isEqualToString:tag]) ? @"" : @"\n"); + [_writingDirectionArray removeAllObjects]; + [_attrStr replaceCharactersInRange:rangeToReplace withString:string]; + if (rangeToReplace.location < _domRangeStartIndex) + _domRangeStartIndex += [string length] - rangeToReplace.length; + rangeToReplace.length = [string length]; + NSDictionary *attrs = attributesForElement(element); + if (rangeToReplace.length > 0) + [_attrStr setAttributes:attrs range:rangeToReplace]; + _flags.isSoft = YES; + } +} + +void HTMLConverter::_newLineForElement(Element& element) +{ + unichar c = NSLineSeparatorCharacter; + RetainPtr string = adoptNS([[NSString alloc] initWithCharacters:&c length:1]); + NSUInteger textLength = [_attrStr length]; + NSRange rangeToReplace = NSMakeRange(textLength, 0); + [_attrStr replaceCharactersInRange:rangeToReplace withString:string.get()]; + rangeToReplace.length = [string length]; + if (rangeToReplace.location < _domRangeStartIndex) + _domRangeStartIndex += rangeToReplace.length; + NSDictionary *attrs = attributesForElement(element); + if (rangeToReplace.length > 0) + [_attrStr setAttributes:attrs range:rangeToReplace]; + _flags.isSoft = YES; +} + +void HTMLConverter::_newTabForElement(Element& element) +{ + NSString *string = @"\t"; + NSUInteger textLength = [_attrStr length]; + unichar lastChar = (textLength > 0) ? [[_attrStr string] characterAtIndex:textLength - 1] : '\n'; + NSRange rangeToReplace = (_flags.isSoft && lastChar == ' ') ? NSMakeRange(textLength - 1, 1) : NSMakeRange(textLength, 0); + [_attrStr replaceCharactersInRange:rangeToReplace withString:string]; + rangeToReplace.length = [string length]; + if (rangeToReplace.location < _domRangeStartIndex) + _domRangeStartIndex += rangeToReplace.length; + NSDictionary *attrs = attributesForElement(element); + if (rangeToReplace.length > 0) + [_attrStr setAttributes:attrs range:rangeToReplace]; + _flags.isSoft = YES; +} + +static Class _WebMessageDocumentClassSingleton() +{ + static Class _WebMessageDocumentClass = Nil; + static BOOL lookedUpClass = NO; + if (!lookedUpClass) { + // If the class is not there, we don't want to try again +#if PLATFORM(MAC) + _WebMessageDocumentClass = objc_lookUpClass("EditableWebMessageDocument"); +#endif + if (!_WebMessageDocumentClass) + _WebMessageDocumentClass = objc_lookUpClass("WebMessageDocument"); + + if (_WebMessageDocumentClass && ![_WebMessageDocumentClass respondsToSelector:@selector(document:attachment:forURL:)]) + _WebMessageDocumentClass = Nil; + lookedUpClass = YES; + } + return _WebMessageDocumentClass; +} + +#if ENABLE(MULTI_REPRESENTATION_HEIC) +BOOL HTMLConverter::_addMultiRepresentationHEICAttachmentForImageElement(HTMLImageElement& element) +{ + RefPtr image = element.image(); + if (!image) + return NO; + + NSAdaptiveImageGlyph *attachment = image->adapter().multiRepresentationHEIC(); + if (!attachment) + return NO; + + NSUInteger textLength = [_attrStr length]; + + RetainPtr string = adoptNS([[NSString alloc] initWithFormat:@"%C", static_cast(NSAttachmentCharacter)]); + NSRange rangeToReplace = NSMakeRange(textLength, 0); + + [_attrStr replaceCharactersInRange:rangeToReplace withString:string.get()]; + rangeToReplace.length = [string length]; + if (rangeToReplace.location < _domRangeStartIndex) + _domRangeStartIndex += rangeToReplace.length; + + [_attrStr addAttribute:NSAdaptiveImageGlyphAttributeName value:attachment range:rangeToReplace]; + + _flags.isSoft = NO; + return YES; +} +#endif // ENABLE(MULTI_REPRESENTATION_HEIC) + +BOOL HTMLConverter::_addAttachmentForElement(Element& element, NSURL *url, BOOL needsParagraph, BOOL usePlaceholder) +{ + BOOL retval = NO; + BOOL notFound = NO; + RetainPtr fileWrapper; + auto* frame = element.document().frame(); + DocumentLoader *dataSource = frame->loader().frameHasLoaded() ? frame->loader().documentLoader() : 0; + BOOL ignoreOrientation = YES; + + if ([url isFileURL]) { + NSString *path = [[url path] stringByStandardizingPath]; + if (path) + fileWrapper = adoptNS([[NSFileWrapper alloc] initWithURL:url options:0 error:NULL]); + } + if (!fileWrapper && dataSource) { + if (auto resource = dataSource->subresource(url)) { + auto& mimeType = resource->mimeType(); + if (!usePlaceholder || mimeType != textHTMLContentTypeAtom()) { + fileWrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:resource->data().makeContiguous()->createNSData().get()]); + [fileWrapper setPreferredFilename:suggestedFilenameWithMIMEType(url, mimeType)]; + } else + notFound = YES; + } + } +#if !PLATFORM(IOS_FAMILY) + if (!fileWrapper && !notFound) { + fileWrapper = fileWrapperForURL(dataSource, url); + if (usePlaceholder && fileWrapper && [[[[fileWrapper preferredFilename] pathExtension] lowercaseString] hasPrefix:@"htm"]) + notFound = YES; + if (notFound) + fileWrapper = nil; + } + if (!fileWrapper && !notFound) { + fileWrapper = fileWrapperForURL(m_dataSource, url); + if (usePlaceholder && fileWrapper && [[[[fileWrapper preferredFilename] pathExtension] lowercaseString] hasPrefix:@"htm"]) + notFound = YES; + if (notFound) + fileWrapper = nil; + } +#endif + if (!fileWrapper && !notFound && url) { + // Special handling for Mail attachments, until WebKit provides a standard way to get the data. + Class WebMessageDocumentClass = _WebMessageDocumentClassSingleton(); + if (WebMessageDocumentClass) { + NSTextAttachment *mimeTextAttachment = nil; + [WebMessageDocumentClass document:NULL attachment:&mimeTextAttachment forURL:url]; + if (mimeTextAttachment && [mimeTextAttachment respondsToSelector:@selector(fileWrapper)]) { + fileWrapper = [mimeTextAttachment fileWrapper]; + ignoreOrientation = NO; + } + } + } + if (fileWrapper || usePlaceholder) { + RetainPtr attachment; + NSAttributedStringKey attributeName = NSAttachmentAttributeName; + + NSUInteger textLength = [_attrStr length]; + RetainPtr string = adoptNS([[NSString alloc] initWithFormat:(needsParagraph ? @"%C\n" : @"%C"), static_cast(NSAttachmentCharacter)]); + NSRange rangeToReplace = NSMakeRange(textLength, 0); + NSDictionary *attrs; + +#if ENABLE(MULTI_REPRESENTATION_HEIC) + if (RetainPtr data = [fileWrapper regularFileContents]) { + RefPtr imageElement = dynamicDowncast(element); + if (imageElement && imageElement->isMultiRepresentationHEIC()) + attachment = adoptNS([[PlatformNSAdaptiveImageGlyph alloc] initWithImageContent:data.get()]); + if (attachment) + attributeName = NSAdaptiveImageGlyphAttributeName; + } +#endif + + if (!attachment) { + RetainPtr textAttachment = adoptNS([[PlatformNSTextAttachment alloc] initWithFileWrapper:fileWrapper.get()]); + + if (auto& ariaLabel = element.getAttribute("aria-label"_s); !ariaLabel.isEmpty()) + [textAttachment setAccessibilityLabel:ariaLabel.createNSString().get()]; + if (auto& altText = element.getAttribute("alt"_s); !altText.isEmpty()) + [textAttachment setAccessibilityLabel:altText.createNSString().get()]; + +#if PLATFORM(IOS_FAMILY) + float verticalAlign = 0.0; + _caches->floatPropertyValueForNode(element, CSSPropertyVerticalAlign, verticalAlign); + [textAttachment setBounds:CGRectMake(0, (verticalAlign / 100) * element.clientHeight(), element.clientWidth(), element.clientHeight())]; +#endif + if (fileWrapper) { +#if PLATFORM(IOS_FAMILY) + UNUSED_VARIABLE(ignoreOrientation); +#else + if (ignoreOrientation) + [textAttachment setIgnoresOrientation:YES]; +#endif + } else { + textAttachment = adoptNS([[PlatformNSTextAttachment alloc] initWithData:nil ofType:nil]); + [textAttachment setImage:webCoreTextAttachmentMissingPlatformImage()]; + } + + attachment = textAttachment; + } + + [_attrStr replaceCharactersInRange:rangeToReplace withString:string.get()]; + rangeToReplace.length = [string length]; + if (rangeToReplace.location < _domRangeStartIndex) + _domRangeStartIndex += rangeToReplace.length; + attrs = attributesForElement(element); + if (rangeToReplace.length > 0) { + [_attrStr setAttributes:attrs range:rangeToReplace]; + rangeToReplace.length = 1; + [_attrStr addAttribute:attributeName value:attachment.get() range:rangeToReplace]; + } + _flags.isSoft = NO; + retval = YES; + } + return retval; +} + +void HTMLConverter::_addQuoteForElement(Element& element, BOOL opening, NSInteger level) +{ + unichar c = ((level % 2) == 0) ? (opening ? 0x201c : 0x201d) : (opening ? 0x2018 : 0x2019); + RetainPtr string = adoptNS([[NSString alloc] initWithCharacters:&c length:1]); + NSUInteger textLength = [_attrStr length]; + NSRange rangeToReplace = NSMakeRange(textLength, 0); + [_attrStr replaceCharactersInRange:rangeToReplace withString:string.get()]; + rangeToReplace.length = [string length]; + if (rangeToReplace.location < _domRangeStartIndex) + _domRangeStartIndex += rangeToReplace.length; + RetainPtr attrs = attributesForElement(element); + if (rangeToReplace.length > 0) + [_attrStr setAttributes:attrs.get() range:rangeToReplace]; + _flags.isSoft = NO; +} + +void HTMLConverter::_addValue(NSString *value, Element& element) +{ + NSUInteger textLength = [_attrStr length]; + NSUInteger valueLength = [value length]; + NSRange rangeToReplace = NSMakeRange(textLength, 0); + if (valueLength) { + [_attrStr replaceCharactersInRange:rangeToReplace withString:value]; + rangeToReplace.length = valueLength; + if (rangeToReplace.location < _domRangeStartIndex) + _domRangeStartIndex += rangeToReplace.length; + RetainPtr attrs = attributesForElement(element); + if (rangeToReplace.length > 0) + [_attrStr setAttributes:attrs.get() range:rangeToReplace]; + _flags.isSoft = NO; + } +} + +void HTMLConverter::_fillInBlock(NSTextBlock *block, Element& element, PlatformColor *backgroundColor, CGFloat extraMargin, CGFloat extraPadding, BOOL isTable) +{ + float result = 0; + + RetainPtr width = element.getAttribute(widthAttr).createNSString(); + if ((width && [width length]) || !isTable) { + if (_caches->floatPropertyValueForNode(element, CSSPropertyWidth, result)) + [block setValue:result type:NSTextBlockAbsoluteValueType forDimension:NSTextBlockWidth]; + } + + if (_caches->floatPropertyValueForNode(element, CSSPropertyMinWidth, result)) + [block setValue:result type:NSTextBlockAbsoluteValueType forDimension:NSTextBlockMinimumWidth]; + if (_caches->floatPropertyValueForNode(element, CSSPropertyMaxWidth, result)) + [block setValue:result type:NSTextBlockAbsoluteValueType forDimension:NSTextBlockMaximumWidth]; + if (_caches->floatPropertyValueForNode(element, CSSPropertyMinHeight, result)) + [block setValue:result type:NSTextBlockAbsoluteValueType forDimension:NSTextBlockMinimumHeight]; + if (_caches->floatPropertyValueForNode(element, CSSPropertyMaxHeight, result)) + [block setValue:result type:NSTextBlockAbsoluteValueType forDimension:NSTextBlockMaximumHeight]; + + if (_caches->floatPropertyValueForNode(element, CSSPropertyPaddingLeft, result)) + [block setWidth:result + extraPadding type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockPadding edge:NSMinXEdge]; + else + [block setWidth:extraPadding type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockPadding edge:NSMinXEdge]; + + if (_caches->floatPropertyValueForNode(element, CSSPropertyPaddingTop, result)) + [block setWidth:result + extraPadding type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockPadding edge:NSMinYEdge]; + else + [block setWidth:extraPadding type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockPadding edge:NSMinYEdge]; + + if (_caches->floatPropertyValueForNode(element, CSSPropertyPaddingRight, result)) + [block setWidth:result + extraPadding type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockPadding edge:NSMaxXEdge]; + else + [block setWidth:extraPadding type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockPadding edge:NSMaxXEdge]; + + if (_caches->floatPropertyValueForNode(element, CSSPropertyPaddingBottom, result)) + [block setWidth:result + extraPadding type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockPadding edge:NSMaxYEdge]; + else + [block setWidth:extraPadding type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockPadding edge:NSMaxYEdge]; + + if (_caches->floatPropertyValueForNode(element, CSSPropertyBorderLeftWidth, result)) + [block setWidth:result type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockBorder edge:NSMinXEdge]; + if (_caches->floatPropertyValueForNode(element, CSSPropertyBorderTopWidth, result)) + [block setWidth:result type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockBorder edge:NSMinYEdge]; + if (_caches->floatPropertyValueForNode(element, CSSPropertyBorderRightWidth, result)) + [block setWidth:result type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockBorder edge:NSMaxXEdge]; + if (_caches->floatPropertyValueForNode(element, CSSPropertyBorderBottomWidth, result)) + [block setWidth:result type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockBorder edge:NSMaxYEdge]; + + if (_caches->floatPropertyValueForNode(element, CSSPropertyMarginLeft, result)) + [block setWidth:result + extraMargin type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockMargin edge:NSMinXEdge]; + else + [block setWidth:extraMargin type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockMargin edge:NSMinXEdge]; + if (_caches->floatPropertyValueForNode(element, CSSPropertyMarginTop, result)) + [block setWidth:result + extraMargin type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockMargin edge:NSMinYEdge]; + else + [block setWidth:extraMargin type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockMargin edge:NSMinYEdge]; + if (_caches->floatPropertyValueForNode(element, CSSPropertyMarginRight, result)) + [block setWidth:result + extraMargin type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockMargin edge:NSMaxXEdge]; + else + [block setWidth:extraMargin type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockMargin edge:NSMaxXEdge]; + if (_caches->floatPropertyValueForNode(element, CSSPropertyMarginBottom, result)) + [block setWidth:result + extraMargin type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockMargin edge:NSMaxYEdge]; + else + [block setWidth:extraMargin type:NSTextBlockAbsoluteValueType forLayer:NSTextBlockMargin edge:NSMaxYEdge]; + + RetainPtr color; + if ((color = _colorForElement(element, CSSPropertyBackgroundColor))) + [block setBackgroundColor:color.get()]; + if (!color && backgroundColor) + [block setBackgroundColor:backgroundColor]; + + if ((color = _colorForElement(element, CSSPropertyBorderLeftColor))) + [block setBorderColor:color.get() forEdge:NSMinXEdge]; + + if ((color = _colorForElement(element, CSSPropertyBorderTopColor))) + [block setBorderColor:color.get() forEdge:NSMinYEdge]; + if ((color = _colorForElement(element, CSSPropertyBorderRightColor))) + [block setBorderColor:color.get() forEdge:NSMaxXEdge]; + if ((color = _colorForElement(element, CSSPropertyBorderBottomColor))) + [block setBorderColor:color.get() forEdge:NSMaxYEdge]; +} + +static inline BOOL read2DigitNumber(std::span& p, int8_t& outval) +{ + BOOL result = NO; + char c1 = consume(p); + if (isASCIIDigit(c1)) { + char c2 = consume(p); + if (isASCIIDigit(c2)) { + outval = 10 * (c1 - '0') + (c2 - '0'); + result = YES; + } + } + return result; +} + +static inline NSDate *_dateForString(NSString *string) +{ + auto p = unsafeSpanIncludingNullTerminator([string UTF8String]); + RetainPtr dateComponents = adoptNS([[NSDateComponents alloc] init]); + + // Set the time zone to GMT + [dateComponents setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; + + NSInteger year = 0; + while (p.front() && isASCIIDigit(p.front())) + year = 10 * year + consume(p) - '0'; + if (consume(p) != '-') + return nil; + [dateComponents setYear:year]; + + int8_t component; + if (!read2DigitNumber(p, component) || consume(p) != '-') + return nil; + [dateComponents setMonth:component]; + + if (!read2DigitNumber(p, component) || consume(p) != 'T') + return nil; + [dateComponents setDay:component]; + + if (!read2DigitNumber(p, component) || consume(p) != ':') + return nil; + [dateComponents setHour:component]; + + if (!read2DigitNumber(p, component) || consume(p) != ':') + return nil; + [dateComponents setMinute:component]; + + if (!read2DigitNumber(p, component) || consume(p) != 'Z') + return nil; + [dateComponents setSecond:component]; + + auto calendar = adoptNS([[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]); + return [calendar dateFromComponents:dateComponents.get()]; +} + +static NSInteger _colCompare(id block1, id block2, void *) +{ + NSInteger col1 = [(NSTextTableBlock *)block1 startingColumn]; + NSInteger col2 = [(NSTextTableBlock *)block2 startingColumn]; + return ((col1 < col2) ? NSOrderedAscending : ((col1 == col2) ? NSOrderedSame : NSOrderedDescending)); +} + +void HTMLConverter::_processMetaElementWithName(NSString *name, NSString *content) +{ + NSString *key = nil; + if (NSOrderedSame == [@"CocoaVersion" compare:name options:NSCaseInsensitiveSearch]) { + CGFloat versionNumber = [content doubleValue]; + if (versionNumber > 0.0) { + // ??? this should be keyed off of version number in future + [_documentAttrs removeObjectForKey:NSConvertedDocumentAttribute]; + [_documentAttrs setObject:@(versionNumber) forKey:NSCocoaVersionDocumentAttribute]; + } +#if PLATFORM(IOS_FAMILY) + } else if (NSOrderedSame == [@"Generator" compare:name options:NSCaseInsensitiveSearch]) { + key = NSGeneratorDocumentAttribute; +#endif + } else if (NSOrderedSame == [@"Keywords" compare:name options:NSCaseInsensitiveSearch]) { + if (content && [content length] > 0) { + NSArray *array; + // ??? need better handling here and throughout + if ([content rangeOfString:@", "].length == 0 && [content rangeOfString:@","].length > 0) + array = [content componentsSeparatedByString:@","]; + else if ([content rangeOfString:@", "].length == 0 && [content rangeOfString:@" "].length > 0) + array = [content componentsSeparatedByString:@" "]; + else + array = [content componentsSeparatedByString:@", "]; + [_documentAttrs setObject:array forKey:NSKeywordsDocumentAttribute]; + } + } else if (NSOrderedSame == [@"Author" compare:name options:NSCaseInsensitiveSearch]) + key = NSAuthorDocumentAttribute; + else if (NSOrderedSame == [@"LastAuthor" compare:name options:NSCaseInsensitiveSearch]) + key = NSEditorDocumentAttribute; + else if (NSOrderedSame == [@"Company" compare:name options:NSCaseInsensitiveSearch]) + key = NSCompanyDocumentAttribute; + else if (NSOrderedSame == [@"Copyright" compare:name options:NSCaseInsensitiveSearch]) + key = NSCopyrightDocumentAttribute; + else if (NSOrderedSame == [@"Subject" compare:name options:NSCaseInsensitiveSearch]) + key = NSSubjectDocumentAttribute; + else if (NSOrderedSame == [@"Description" compare:name options:NSCaseInsensitiveSearch] || NSOrderedSame == [@"Comment" compare:name options:NSCaseInsensitiveSearch]) + key = NSCommentDocumentAttribute; + else if (NSOrderedSame == [@"CreationTime" compare:name options:NSCaseInsensitiveSearch]) { + if (content && [content length] > 0) { + NSDate *date = _dateForString(content); + if (date) + [_documentAttrs setObject:date forKey:NSCreationTimeDocumentAttribute]; + } + } else if (NSOrderedSame == [@"ModificationTime" compare:name options:NSCaseInsensitiveSearch]) { + if (content && [content length] > 0) { + NSDate *date = _dateForString(content); + if (date) + [_documentAttrs setObject:date forKey:NSModificationTimeDocumentAttribute]; + } + } +#if PLATFORM(IOS_FAMILY) + else if (NSOrderedSame == [@"DisplayName" compare:name options:NSCaseInsensitiveSearch] || NSOrderedSame == [@"IndexTitle" compare:name options:NSCaseInsensitiveSearch]) + key = NSDisplayNameDocumentAttribute; + else if (NSOrderedSame == [@"robots" compare:name options:NSCaseInsensitiveSearch]) { + if ([content rangeOfString:@"noindex" options:NSCaseInsensitiveSearch].length > 0) + [_documentAttrs setObject:[NSNumber numberWithInteger:1] forKey:NSNoIndexDocumentAttribute]; + } +#endif + if (key && content && [content length] > 0) + [_documentAttrs setObject:content forKey:key]; +} + +void HTMLConverter::_processHeadElement(Element& element) +{ + // FIXME: Should gather data from other sources e.g. Word, but for that we would need to be able to get comments from DOM + + for (HTMLMetaElement* child = Traversal::firstChild(element); child; child = Traversal::nextSibling(*child)) { + RetainPtr name = child->name().createNSString(); + RetainPtr content = child->content().createNSString(); + if (name && content) + _processMetaElementWithName(name.get(), content.get()); + } +} + +void HTMLConverter::_enterBlockquote() +{ + _topPresentationIntent = [NSPresentationIntent blockQuoteIntentWithIdentity:++_topPresentationIntentIdentity nestedInsideIntent:_topPresentationIntent.get()]; +} + +void HTMLConverter::_exitBlockquote() +{ + if (_topPresentationIntent) + _topPresentationIntent = [_topPresentationIntent parentIntent]; +} + +BOOL HTMLConverter::_enterElement(Element& element, BOOL embedded) +{ + String displayValue = _caches->propertyValueForNode(element, CSSPropertyDisplay); + if (element.hasTagName(blockquoteTag)) + _enterBlockquote(); + + if (element.hasTagName(headTag) && !embedded) + _processHeadElement(element); + else if ((!m_ignoreUserSelectNoneContent || !m_userSelectNoneStateCache.nodeOnlyContainsUserSelectNone(element)) && (!displayValue.length() || !(displayValue == noneAtom() || displayValue == "table-column"_s || displayValue == "table-column-group"_s))) { + if (_caches->isBlockElement(element) && !element.hasTagName(brTag) && !(displayValue == "table-cell"_s && ![_textTables count]) + && !([_textLists count] > 0 && displayValue == "block"_s && !element.hasTagName(liTag) && !element.hasTagName(ulTag) && !element.hasTagName(olTag))) + _newParagraphForElement(element, element.tagName().createNSString().get(), NO, YES); + return YES; + } + return NO; +} + +void HTMLConverter::_addLinkForElement(Element& element, NSRange range) +{ +#if ENABLE(DATA_DETECTION) + if (DataDetection::isDataDetectorElement(element)) + return; +#endif + + RetainPtr urlString = element.getAttribute(hrefAttr).createNSString(); + RetainPtr strippedString = [urlString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + if (urlString && [urlString length] > 0 && strippedString && [strippedString length] > 0 && ![strippedString hasPrefix:@"#"]) { + RetainPtr url = element.document().completeURL(urlString.get()).createNSURL(); + if (!url) + url = element.document().completeURL(strippedString.get()).createNSURL(); + if (!url) + url = [NSURL _web_URLWithString:strippedString.get() relativeToURL:nil]; + [_attrStr addAttribute:NSLinkAttributeName value:url ? (id)url.get() : (id)urlString.get() range:range]; + } +} + +void HTMLConverter::_addTableForElement(Element *tableElement) +{ + RetainPtr table = adoptNS([(NSTextTable *)[PlatformNSTextTable alloc] init]); + CGFloat cellSpacingVal = 1; + CGFloat cellPaddingVal = 1; + [table setNumberOfColumns:1]; + [table setLayoutAlgorithm:NSTextTableAutomaticLayoutAlgorithm]; + [table setCollapsesBorders:NO]; + [table setHidesEmptyCells:NO]; + + if (tableElement) { + ASSERT(tableElement); + Element& coreTableElement = *tableElement; + + RetainPtr cellSpacing = coreTableElement.getAttribute(cellspacingAttr).createNSString(); + if (cellSpacing && [cellSpacing length] > 0 && ![cellSpacing hasSuffix:@"%"]) + cellSpacingVal = [cellSpacing floatValue]; + RetainPtr cellPadding = coreTableElement.getAttribute(cellpaddingAttr).createNSString(); + if (cellPadding && [cellPadding length] > 0 && ![cellPadding hasSuffix:@"%"]) + cellPaddingVal = [cellPadding floatValue]; + + _fillInBlock(table.get(), coreTableElement, nil, 0, 0, YES); + + if (_caches->propertyValueForNode(coreTableElement, CSSPropertyBorderCollapse) == "collapse"_s) { + [table setCollapsesBorders:YES]; + cellSpacingVal = 0; + } + if (_caches->propertyValueForNode(coreTableElement, CSSPropertyEmptyCells) == "hide"_s) + [table setHidesEmptyCells:YES]; + if (_caches->propertyValueForNode(coreTableElement, CSSPropertyTableLayout) == "fixed"_s) + [table setLayoutAlgorithm:NSTextTableFixedLayoutAlgorithm]; + } + + [_textTables addObject:table.get()]; + [_textTableSpacings addObject:@(cellSpacingVal)]; + [_textTablePaddings addObject:@(cellPaddingVal)]; + [_textTableRows addObject:[NSNumber numberWithInteger:0]]; + [_textTableRowArrays addObject:[NSMutableArray array]]; +} + +void HTMLConverter::_addTableCellForElement(Element* element) +{ + NSTextTable *table = [_textTables lastObject]; + NSInteger rowNumber = [[_textTableRows lastObject] integerValue]; + NSInteger columnNumber = 0; + NSInteger rowSpan = 1; + NSInteger colSpan = 1; + NSMutableArray *rowArray = [_textTableRowArrays lastObject]; + NSUInteger count = [rowArray count]; + PlatformColor *color = ([_textTableRowBackgroundColors count] > 0) ? [_textTableRowBackgroundColors lastObject] : nil; + NSTextTableBlock *previousBlock; + CGFloat cellSpacingVal = [[_textTableSpacings lastObject] floatValue]; + if ([color isEqual:[PlatformColorClass clearColor]]) color = nil; + for (NSUInteger i = 0; i < count; i++) { + previousBlock = [rowArray objectAtIndex:i]; + if (columnNumber >= [previousBlock startingColumn] && columnNumber < [previousBlock startingColumn] + [previousBlock columnSpan]) + columnNumber = [previousBlock startingColumn] + [previousBlock columnSpan]; + } + + RetainPtr block; + + if (element) { + if (RefPtr tableCellElement = dynamicDowncast(*element)) { + rowSpan = tableCellElement->rowSpan(); + if (rowSpan < 1) + rowSpan = 1; + colSpan = tableCellElement->colSpan(); + if (colSpan < 1) + colSpan = 1; + } + + block = adoptNS([[PlatformNSTextTableBlock alloc] initWithTable:table startingRow:rowNumber rowSpan:rowSpan startingColumn:columnNumber columnSpan:colSpan]); + + String verticalAlign = _caches->propertyValueForNode(*element, CSSPropertyVerticalAlign); + + _fillInBlock(block.get(), *element, color, cellSpacingVal / 2, 0, NO); + if (verticalAlign == "middle"_s) + [block setVerticalAlignment:NSTextBlockMiddleAlignment]; + else if (verticalAlign == "bottom"_s) + [block setVerticalAlignment:NSTextBlockBottomAlignment]; + else if (verticalAlign == "baseline"_s) + [block setVerticalAlignment:NSTextBlockBaselineAlignment]; + else if (verticalAlign == "top"_s) + [block setVerticalAlignment:NSTextBlockTopAlignment]; + } else { + block = adoptNS([[PlatformNSTextTableBlock alloc] initWithTable:table startingRow:rowNumber rowSpan:rowSpan startingColumn:columnNumber columnSpan:colSpan]); + } + + [_textBlocks addObject:block.get()]; + [rowArray addObject:block.get()]; + [rowArray sortUsingFunction:_colCompare context:NULL]; +} + +BOOL HTMLConverter::_processElement(Element& element, NSInteger depth) +{ + BOOL retval = YES; + BOOL isBlockLevel = _caches->isBlockElement(element); + String displayValue = _caches->propertyValueForNode(element, CSSPropertyDisplay); + if (isBlockLevel) + [_writingDirectionArray removeAllObjects]; + else { + String bidi = _caches->propertyValueForNode(element, CSSPropertyUnicodeBidi); + if (bidi == "embed"_s) { + NSUInteger val = NSWritingDirectionEmbedding; + if (_caches->propertyValueForNode(element, CSSPropertyDirection) == "rtl"_s) + val |= NSWritingDirectionRightToLeft; + [_writingDirectionArray addObject:[NSNumber numberWithUnsignedInteger:val]]; + } else if (bidi == "bidi-override"_s) { + NSUInteger val = NSWritingDirectionOverride; + if (_caches->propertyValueForNode(element, CSSPropertyDirection) == "rtl"_s) + val |= NSWritingDirectionRightToLeft; + [_writingDirectionArray addObject:[NSNumber numberWithUnsignedInteger:val]]; + } + } + if (displayValue == "table"_s || (![_textTables count] && displayValue == "table-row-group"_s)) { + Element* tableElement = &element; + if (displayValue == "table-row-group"_s) { + // If we are starting in medias res, the first thing we see may be the tbody, so go up to the table + tableElement = _blockLevelElementForNode(element.parentInComposedTree()); + if (!tableElement || _caches->propertyValueForNode(*tableElement, CSSPropertyDisplay) != "table"_s) + tableElement = &element; + } + while ([_textTables count] > [_textBlocks count]) + _addTableCellForElement(nil); + _addTableForElement(tableElement); + } else if (displayValue == "table-footer-group"_s && [_textTables count] > 0) { + m_textTableFooters.add((__bridge CFTypeRef)[_textTables lastObject], &element); + retval = NO; + } else if (displayValue == "table-row"_s && [_textTables count] > 0) { + auto color = _colorForElement(element, CSSPropertyBackgroundColor); + if (!color) + color = (PlatformColor *)[PlatformColorClass clearColor]; + [_textTableRowBackgroundColors addObject:color.get()]; + } else if (displayValue == "table-cell"_s) { + while ([_textTables count] < [_textBlocks count] + 1) + _addTableForElement(nil); + _addTableCellForElement(&element); +#if ENABLE(ATTACHMENT_ELEMENT) + } else if (RefPtr attachment = dynamicDowncast(element)) { + if (attachment->file()) { + RetainPtr url = [NSURL fileURLWithPath:attachment->file()->path().createNSString().get()]; + if (url) + _addAttachmentForElement(element, url.get(), isBlockLevel, NO); + } + retval = NO; +#endif + } else if (RefPtr imageElement = dynamicDowncast(element)) { +#if ENABLE(MULTI_REPRESENTATION_HEIC) + if (imageElement->isMultiRepresentationHEIC()) + retval = !_addMultiRepresentationHEICAttachmentForImageElement(*imageElement); +#endif + RetainPtr urlString = element.imageSourceURL().createNSString(); + if (retval && urlString && [urlString length] > 0) { + RetainPtr url = element.document().completeURL(urlString.get()).createNSURL(); + if (!url) + url = [NSURL _web_URLWithString:[urlString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] relativeToURL:nil]; +#if PLATFORM(IOS_FAMILY) + BOOL usePlaceholderImage = NO; +#else + BOOL usePlaceholderImage = YES; +#endif + if (url) + _addAttachmentForElement(element, url.get(), isBlockLevel, usePlaceholderImage); + } + retval = NO; + } else if (element.hasTagName(objectTag)) { + RetainPtr baseString = element.getAttribute(codebaseAttr).createNSString(); + RetainPtr urlString = element.getAttribute(dataAttr).createNSString(); + RetainPtr declareString = element.getAttribute(declareAttr).createNSString(); + if (urlString && [urlString length] > 0 && ![@"true" isEqualToString:declareString.get()]) { + RetainPtr baseURL; + RetainPtr url; + if (baseString && [baseString length] > 0) { + baseURL = element.document().completeURL(baseString.get()).createNSURL(); + if (!baseURL) + baseURL = [NSURL _web_URLWithString:[baseString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] relativeToURL:nil]; + } + if (baseURL) + url = [NSURL _web_URLWithString:[urlString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] relativeToURL:baseURL.get()]; + if (!url) + url = element.document().completeURL(urlString.get()).createNSURL(); + if (!url) + url = [NSURL _web_URLWithString:[urlString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] relativeToURL:nil]; + if (url) + retval = !_addAttachmentForElement(element, url.get(), isBlockLevel, NO); + } + } else if (auto* frameElement = dynamicDowncast(element)) { + if (RefPtr contentDocument = frameElement->contentDocument()) { + _traverseNode(*contentDocument, depth + 1, true /* embedded */); + retval = NO; + } + } else if (element.hasTagName(brTag)) { + Element* blockElement = _blockLevelElementForNode(element.parentInComposedTree()); + RetainPtr breakClass = element.getAttribute(classAttr).createNSString(); + RetainPtr blockTag = blockElement ? blockElement->tagName().createNSString() : nil; + BOOL isExtraBreak = [AppleInterchangeNewline.createNSString() isEqualToString:breakClass.get()]; + BOOL blockElementIsParagraph = ([@"P" isEqualToString:blockTag.get()] || [@"LI" isEqualToString:blockTag.get()] || ([blockTag hasPrefix:@"H"] && 2 == [blockTag length])); + if (isExtraBreak) + _flags.hasTrailingNewline = YES; + else { + if (blockElement && blockElementIsParagraph) + _newLineForElement(element); + else + _newParagraphForElement(element, element.tagName().createNSString().get(), YES, NO); + } + } else if (element.hasTagName(ulTag)) { + TextList textList; + textList.ordered = false; + + if (CheckedPtr renderer = element.renderer()) + textList.styleType = renderer->style().listStyleType(); + + [_textLists addObject:textList.createTextList().get()]; + } else if (element.hasTagName(olTag)) { + TextList textList; + textList.ordered = true; + + if (CheckedPtr renderer = element.renderer()) + textList.styleType = renderer->style().listStyleType(); + + if (RefPtr olElement = dynamicDowncast(element)) + textList.startingItemNumber = olElement->start(); + else + textList.startingItemNumber = 1; + + [_textLists addObject:textList.createTextList().get()]; + } else if (element.hasTagName(qTag)) { + _addQuoteForElement(element, YES, _quoteLevel++); + } else if (element.hasTagName(inputTag)) { + if (RefPtr inputElement = dynamicDowncast(element)) { + if (inputElement->type() == textAtom()) { + RetainPtr value = inputElement->value()->createNSString(); + if (value && [value length] > 0) + _addValue(value.get(), element); + } + } + } else if (element.hasTagName(textareaTag)) { + if (RefPtr textAreaElement = dynamicDowncast(element)) { + RetainPtr value = textAreaElement->value()->createNSString(); + if (value && [value length] > 0) + _addValue(value.get(), element); + } + retval = NO; + } + return retval; +} + +void HTMLConverter::_addMarkersToList(NSTextList *list, NSRange range) +{ + NSInteger itemNum = [list startingItemNumber]; + NSString *string = [_attrStr string]; + NSString *stringToInsert; + NSDictionary *attrsToInsert = nil; + NSParagraphStyle *paragraphStyle; + NSTextTab *tab = nil; + NSTextTab *tabToRemove; + NSRange paragraphRange; + NSRange styleRange; + NSUInteger textLength = [_attrStr length]; + NSUInteger listIndex; + NSUInteger insertLength; + NSUInteger i; + NSUInteger count; + NSArray *textLists; + CGFloat markerLocation; + CGFloat listLocation; + + if (range.length == 0 || range.location >= textLength) + return; + if (NSMaxRange(range) > textLength) + range.length = textLength - range.location; + paragraphStyle = [_attrStr attribute:NSParagraphStyleAttributeName atIndex:range.location effectiveRange:NULL]; + if (paragraphStyle) { + textLists = [paragraphStyle textLists]; + listIndex = [textLists indexOfObject:list]; + if (textLists && listIndex != NSNotFound) { + for (NSUInteger idx = range.location; idx < NSMaxRange(range);) { + paragraphRange = [string paragraphRangeForRange:NSMakeRange(idx, 0)]; + paragraphStyle = [_attrStr attribute:NSParagraphStyleAttributeName atIndex:idx effectiveRange:&styleRange]; + if ([[paragraphStyle textLists] count] == listIndex + 1) { + stringToInsert = [NSString stringWithFormat:@"\t%@\t", [list markerForItemNumber:itemNum++]]; + insertLength = [stringToInsert length]; + attrsToInsert = [PlatformNSTextList _standardMarkerAttributesForAttributes:[_attrStr attributesAtIndex:paragraphRange.location effectiveRange:NULL]]; + + [_attrStr replaceCharactersInRange:NSMakeRange(paragraphRange.location, 0) withString:stringToInsert]; + [_attrStr setAttributes:attrsToInsert range:NSMakeRange(paragraphRange.location, insertLength)]; + range.length += insertLength; + paragraphRange.length += insertLength; + if (paragraphRange.location < _domRangeStartIndex) + _domRangeStartIndex += insertLength; + + auto newStyle = adoptNS([paragraphStyle mutableCopy]); + listLocation = (listIndex + 1) * 36; + markerLocation = listLocation - 25; + [newStyle setFirstLineHeadIndent:0]; + [newStyle setHeadIndent:listLocation]; + while ((count = [[newStyle tabStops] count]) > 0) { + for (i = 0, tabToRemove = nil; !tabToRemove && i < count; i++) { + tab = [[newStyle tabStops] objectAtIndex:i]; + if ([tab location] <= listLocation) + tabToRemove = tab; + } + if (tabToRemove) + [newStyle removeTabStop:tab]; + else + break; + } + [newStyle addTabStop:adoptNS([[PlatformNSTextTab alloc] initWithType:NSLeftTabStopType location:markerLocation]).get()]; + [newStyle addTabStop:adoptNS([[PlatformNSTextTab alloc] initWithTextAlignment:NSTextAlignmentNatural location:listLocation options:@{ }]).get()]; + [_attrStr addAttribute:NSParagraphStyleAttributeName value:newStyle.get() range:paragraphRange]; + + idx = NSMaxRange(paragraphRange); + } else { + // skip any deeper-nested lists + idx = NSMaxRange(styleRange); + } + } + } + } +} + +void HTMLConverter::_exitElement(Element& element, NSInteger depth, NSUInteger startIndex) +{ + String displayValue = _caches->propertyValueForNode(element, CSSPropertyDisplay); + NSRange range = NSMakeRange(startIndex, [_attrStr length] - startIndex); + if (range.length > 0 && element.hasTagName(aTag)) + _addLinkForElement(element, range); + if (!_flags.reachedEnd && _caches->isBlockElement(element)) { + [_writingDirectionArray removeAllObjects]; + if (displayValue == "table-cell"_s && ![_textBlocks count]) { + _newTabForElement(element); + } else if ([_textLists count] > 0 && displayValue == "block"_s && !element.hasTagName(liTag) && !element.hasTagName(ulTag) && !element.hasTagName(olTag)) { + _newLineForElement(element); + } else { + _newParagraphForElement(element, element.tagName().createNSString().get(), !range.length, YES); + } + } else if ([_writingDirectionArray count] > 0) { + String bidi = _caches->propertyValueForNode(element, CSSPropertyUnicodeBidi); + if (bidi == "embed"_s || bidi == "bidi-override"_s) + [_writingDirectionArray removeLastObject]; + } + range = NSMakeRange(startIndex, [_attrStr length] - startIndex); + if (displayValue == "table"_s && [_textTables count] > 0) { + NSTextTable *key = [_textTables lastObject]; + Element* footer = m_textTableFooters.get((__bridge CFTypeRef)key); + while ([_textTables count] < [_textBlocks count] + 1) + [_textBlocks removeLastObject]; + if (footer) { + _traverseFooterNode(*footer, depth + 1); + m_textTableFooters.remove((__bridge CFTypeRef)key); + } + [_textTables removeLastObject]; + [_textTableSpacings removeLastObject]; + [_textTablePaddings removeLastObject]; + [_textTableRows removeLastObject]; + [_textTableRowArrays removeLastObject]; + } else if (displayValue == "table-row"_s && [_textTables count] > 0) { + NSTextTable *table = [_textTables lastObject]; + NSTextTableBlock *block; + NSMutableArray *rowArray = [_textTableRowArrays lastObject], *previousRowArray; + NSUInteger i, count; + NSInteger numberOfColumns = [table numberOfColumns]; + NSInteger openColumn; + NSInteger rowNumber = [[_textTableRows lastObject] integerValue]; + do { + rowNumber++; + previousRowArray = rowArray; + rowArray = [NSMutableArray array]; + count = [previousRowArray count]; + for (i = 0; i < count; i++) { + block = [previousRowArray objectAtIndex:i]; + if ([block startingColumn] + [block columnSpan] > numberOfColumns) numberOfColumns = [block startingColumn] + [block columnSpan]; + if ([block startingRow] + [block rowSpan] > rowNumber) [rowArray addObject:block]; + } + count = [rowArray count]; + openColumn = 0; + for (i = 0; i < count; i++) { + block = [rowArray objectAtIndex:i]; + if (openColumn >= [block startingColumn] && openColumn < [block startingColumn] + [block columnSpan]) openColumn = [block startingColumn] + [block columnSpan]; + } + } while (openColumn >= numberOfColumns); + if ((NSUInteger)numberOfColumns > [table numberOfColumns]) + [table setNumberOfColumns:numberOfColumns]; + [_textTableRows removeLastObject]; + [_textTableRows addObject:[NSNumber numberWithInteger:rowNumber]]; + [_textTableRowArrays removeLastObject]; + [_textTableRowArrays addObject:rowArray]; + if ([_textTableRowBackgroundColors count] > 0) + [_textTableRowBackgroundColors removeLastObject]; + } else if (displayValue == "table-cell"_s && [_textBlocks count] > 0) { + while ([_textTables count] > [_textBlocks count]) { + [_textTables removeLastObject]; + [_textTableSpacings removeLastObject]; + [_textTablePaddings removeLastObject]; + [_textTableRows removeLastObject]; + [_textTableRowArrays removeLastObject]; + } + [_textBlocks removeLastObject]; + } else if ((element.hasTagName(ulTag) || element.hasTagName(olTag)) && [_textLists count] > 0) { + NSTextList *list = [_textLists lastObject]; + _addMarkersToList(list, range); + [_textLists removeLastObject]; + } else if (element.hasTagName(qTag)) { + _addQuoteForElement(element, NO, --_quoteLevel); + } else if (element.hasTagName(spanTag)) { + RetainPtr className = element.getAttribute(classAttr).createNSString(); + NSMutableString *mutableString; + NSUInteger i, count = 0; + unichar c; + if ([@"Apple-converted-space" isEqualToString:className.get()]) { + mutableString = [_attrStr mutableString]; + for (i = range.location; i < NSMaxRange(range); i++) { + c = [mutableString characterAtIndex:i]; + if (0xa0 == c) + [mutableString replaceCharactersInRange:NSMakeRange(i, 1) withString:@" "]; + } + } else if ([@"Apple-converted-tab" isEqualToString:className.get()]) { + mutableString = [_attrStr mutableString]; + for (i = range.location; i < NSMaxRange(range); i++) { + NSRange rangeToReplace = NSMakeRange(NSNotFound, 0); + c = [mutableString characterAtIndex:i]; + if (' ' == c || 0xa0 == c) { + count++; + if (count >= 4 || i + 1 >= NSMaxRange(range)) + rangeToReplace = NSMakeRange(i + 1 - count, count); + } else { + if (count > 0) + rangeToReplace = NSMakeRange(i - count, count); + } + if (rangeToReplace.length > 0) { + [mutableString replaceCharactersInRange:rangeToReplace withString:@"\t"]; + range.length -= (rangeToReplace.length - 1); + i -= (rangeToReplace.length - 1); + if (NSMaxRange(rangeToReplace) <= _domRangeStartIndex) { + _domRangeStartIndex -= (rangeToReplace.length - 1); + } else if (rangeToReplace.location < _domRangeStartIndex) { + _domRangeStartIndex = rangeToReplace.location; + } + count = 0; + } + } + } + } + + if (element.hasTagName(blockquoteTag)) + _exitBlockquote(); +} + +void HTMLConverter::_processText(Text& text) +{ + if (m_ignoreUserSelectNoneContent && m_userSelectNoneStateCache.nodeOnlyContainsUserSelectNone(text)) + return; + NSUInteger textLength = [_attrStr length]; + unichar lastChar = (textLength > 0) ? [[_attrStr string] characterAtIndex:textLength - 1] : '\n'; + BOOL suppressLeadingSpace = ((_flags.isSoft && lastChar == ' ') || lastChar == '\n' || lastChar == '\r' || lastChar == '\t' || lastChar == NSParagraphSeparatorCharacter || lastChar == NSLineSeparatorCharacter || lastChar == NSFormFeedCharacter || lastChar == WebNextLineCharacter); + NSRange rangeToReplace = NSMakeRange(textLength, 0); + + String originalString = text.data(); + unsigned startOffset = 0; + unsigned endOffset = originalString.length(); + if (&text == m_start.containerNode()) { + startOffset = m_start.offsetInContainerNode(); + _domRangeStartIndex = [_attrStr length]; + _flags.reachedStart = YES; + } + if (&text == m_end.containerNode()) { + endOffset = m_end.offsetInContainerNode(); + _flags.reachedEnd = YES; + } + if ((startOffset > 0 || endOffset < originalString.length()) && endOffset >= startOffset) + originalString = originalString.substring(startOffset, endOffset - startOffset); + String outputString = originalString; + + // FIXME: Use RenderText's content instead. + bool wasSpace = false; + if (_caches->propertyValueForNode(text, CSSPropertyWhiteSpace).startsWith("pre"_s)) { + if (textLength && originalString.length() && _flags.isSoft) { + unichar c = originalString.characterAt(0); + if (c == '\n' || c == '\r' || c == NSParagraphSeparatorCharacter || c == NSLineSeparatorCharacter || c == NSFormFeedCharacter || c == WebNextLineCharacter) + rangeToReplace = NSMakeRange(textLength - 1, 1); + } + } else { + unsigned count = originalString.length(); + bool wasLeading = true; + StringBuilder builder; + Latin1Character noBreakSpaceRepresentation = 0; + for (unsigned i = 0; i < count; i++) { + char16_t c = originalString.characterAt(i); + bool isWhitespace = c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == 0xc || c == 0x200b; + if (isWhitespace) + wasSpace = (!wasLeading || !suppressLeadingSpace); + else { + if (wasSpace) + builder.append(' '); + if (c != noBreakSpace) + builder.append(c); + else { + if (!noBreakSpaceRepresentation) + noBreakSpaceRepresentation = _caches->propertyValueForNode(text, CSSPropertyWebkitNbspMode) == "space"_s ? ' ' : noBreakSpace; + builder.append(noBreakSpaceRepresentation); + } + wasSpace = false; + wasLeading = false; + } + } + if (wasSpace) + builder.append(' '); + outputString = builder.toString(); + } + + if (outputString.length()) { + String textTransform = _caches->propertyValueForNode(text, CSSPropertyTextTransform); + if (textTransform == "capitalize"_s) + outputString = capitalize(outputString); // FIXME: Needs to take locale into account to work correctly. + else if (textTransform == "uppercase"_s) + outputString = outputString.convertToUppercaseWithoutLocale(); // FIXME: Needs locale to work correctly. + else if (textTransform == "lowercase"_s) + outputString = outputString.convertToLowercaseWithoutLocale(); // FIXME: Needs locale to work correctly. + + [_attrStr replaceCharactersInRange:rangeToReplace withString:outputString.createNSString().get()]; + rangeToReplace.length = outputString.length(); + if (rangeToReplace.length) + [_attrStr setAttributes:aggregatedAttributesForAncestors(text) range:rangeToReplace]; + _flags.isSoft = wasSpace; + } +} + +void HTMLConverter::_traverseNode(Node& node, unsigned depth, bool embedded) +{ + if (_flags.reachedEnd) + return; + if (!_flags.reachedStart && !_caches->isAncestorsOfStartToBeConverted(node)) + return; + + unsigned startOffset = 0; + unsigned endOffset = UINT_MAX; + bool isStart = false; + bool isEnd = false; + if (&node == m_start.containerNode()) { + startOffset = m_start.computeOffsetInContainerNode(); + isStart = true; + _flags.reachedStart = YES; + } + if (&node == m_end.containerNode()) { + endOffset = m_end.computeOffsetInContainerNode(); + isEnd = true; + } + + if (node.isDocumentNode() || node.isDocumentFragment()) { + Node* child = node.firstChild(); + ASSERT(child == firstChildInComposedTreeIgnoringUserAgentShadow(node)); + for (NSUInteger i = 0; child; i++) { + if (isStart && i == startOffset) + _domRangeStartIndex = [_attrStr length]; + if ((!isStart || startOffset <= i) && (!isEnd || endOffset > i)) + _traverseNode(*child, depth + 1, embedded); + if (isEnd && i + 1 >= endOffset) + _flags.reachedEnd = YES; + if (_flags.reachedEnd) + break; + ASSERT(child->nextSibling() == nextSiblingInComposedTreeIgnoringUserAgentShadow(*child)); + child = child->nextSibling(); + } + } else if (RefPtr element = dynamicDowncast(node)) { + if (_enterElement(*element, embedded)) { + NSUInteger startIndex = [_attrStr length]; + if (_processElement(*element, depth)) { + if (auto* shadowRoot = shadowRootIgnoringUserAgentShadow(*element)) // Traverse through shadow root to detect start and end. + _traverseNode(*shadowRoot, depth + 1, embedded); + else { + auto* child = firstChildInComposedTreeIgnoringUserAgentShadow(node); + for (NSUInteger i = 0; child; i++) { + if (isStart && i == startOffset) + _domRangeStartIndex = [_attrStr length]; + if ((!isStart || startOffset <= i) && (!isEnd || endOffset > i)) + _traverseNode(*child, depth + 1, embedded); + if (isEnd && i + 1 >= endOffset) + _flags.reachedEnd = YES; + if (_flags.reachedEnd) + break; + child = nextSiblingInComposedTreeIgnoringUserAgentShadow(*child); + } + } + _exitElement(*element, depth, std::min(startIndex, [_attrStr length])); + } + } + } else if (RefPtr text = dynamicDowncast(node)) + _processText(*text); + + if (isEnd) + _flags.reachedEnd = YES; +} + +void HTMLConverter::_traverseFooterNode(Element& element, unsigned depth) +{ + if (_flags.reachedEnd) + return; + if (!_flags.reachedStart && !_caches->isAncestorsOfStartToBeConverted(element)) + return; + + unsigned startOffset = 0; + unsigned endOffset = UINT_MAX; + bool isStart = false; + bool isEnd = false; + if (&element == m_start.containerNode()) { + startOffset = m_start.computeOffsetInContainerNode(); + isStart = true; + _flags.reachedStart = YES; + } + if (&element == m_end.containerNode()) { + endOffset = m_end.computeOffsetInContainerNode(); + isEnd = true; + } + + if (_enterElement(element, YES)) { + NSUInteger startIndex = [_attrStr length]; + if (_processElement(element, depth)) { + auto* child = firstChildInComposedTreeIgnoringUserAgentShadow(element); + for (NSUInteger i = 0; child; i++) { + if (isStart && i == startOffset) + _domRangeStartIndex = [_attrStr length]; + if ((!isStart || startOffset <= i) && (!isEnd || endOffset > i)) + _traverseNode(*child, depth + 1, true /* embedded */); + if (isEnd && i + 1 >= endOffset) + _flags.reachedEnd = YES; + if (_flags.reachedEnd) + break; + child = nextSiblingInComposedTreeIgnoringUserAgentShadow(*child); + } + _exitElement(element, depth, startIndex); + } + } + if (isEnd) + _flags.reachedEnd = YES; +} + +void HTMLConverter::_adjustTrailingNewline() +{ + NSUInteger textLength = [_attrStr length]; + unichar lastChar = (textLength > 0) ? [[_attrStr string] characterAtIndex:textLength - 1] : 0; + BOOL alreadyHasTrailingNewline = (lastChar == '\n' || lastChar == '\r' || lastChar == NSParagraphSeparatorCharacter || lastChar == NSLineSeparatorCharacter || lastChar == WebNextLineCharacter); + if (_flags.hasTrailingNewline && !alreadyHasTrailingNewline) + [_attrStr replaceCharactersInRange:NSMakeRange(textLength, 0) withString:@"\n"]; +} + +Node* HTMLConverterCaches::cacheAncestorsOfStartToBeConverted(const Position& start, const Position& end) +{ + auto commonAncestor = commonInclusiveAncestor(start, end); + Node* ancestor = start.containerNode(); + + while (ancestor) { + m_ancestorsUnderCommonAncestor.add(*ancestor); + if (ancestor == commonAncestor) + break; + ancestor = ancestor->parentInComposedTree(); + } + + return commonAncestor; +} + +namespace WebCore { + +// This function supports more HTML features than the editing variant below, such as tables. +AttributedString attributedString(const SimpleRange& range, IgnoreUserSelectNone treatment) +{ + return HTMLConverter { range, treatment }.convert(); +} + +} diff --git a/Source/WebCore/html/MediaFragmentURIParser.cpp b/Source/WebCore/html/MediaFragmentURIParser.cpp index a17af4bd0bc7a..fd5aa7462e0f7 100644 --- a/Source/WebCore/html/MediaFragmentURIParser.cpp +++ b/Source/WebCore/html/MediaFragmentURIParser.cpp @@ -45,7 +45,7 @@ constexpr int secondsPerHour = 3600; constexpr int secondsPerMinute = 60; constexpr unsigned nptIdentifierLength = 4; // "npt:" -static String collectDigits(std::span input, unsigned& position) +static String collectDigits(std::span input, unsigned& position) { StringBuilder digits; @@ -56,7 +56,7 @@ static String collectDigits(std::span input, unsigned& position) return digits.toString(); } -static StringView collectFraction(std::span input, unsigned& position) +static StringView collectFraction(std::span input, unsigned& position) { // http://www.ietf.org/rfc/rfc2326.txt // [ "." *DIGIT ] @@ -192,7 +192,7 @@ void MediaFragmentURIParser::parseTimeFragment() m_fragments.clear(); } -bool MediaFragmentURIParser::parseNPTFragment(std::span timeString, MediaTime& startTime, MediaTime& endTime) +bool MediaFragmentURIParser::parseNPTFragment(std::span timeString, MediaTime& startTime, MediaTime& endTime) { unsigned offset = 0; if (timeString.size() >= nptIdentifierLength && timeString[0] == 'n' && timeString[1] == 'p' && timeString[2] == 't' && timeString[3] == ':') @@ -231,7 +231,7 @@ bool MediaFragmentURIParser::parseNPTFragment(std::span timeString, return true; } -bool MediaFragmentURIParser::parseNPTTime(std::span timeString, unsigned& offset, MediaTime& time) +bool MediaFragmentURIParser::parseNPTTime(std::span timeString, unsigned& offset, MediaTime& time) { enum Mode { minutes, hours }; Mode mode = minutes; diff --git a/Source/WebCore/html/MediaFragmentURIParser.h b/Source/WebCore/html/MediaFragmentURIParser.h index 8d44aed23fe48..13571305151b1 100644 --- a/Source/WebCore/html/MediaFragmentURIParser.h +++ b/Source/WebCore/html/MediaFragmentURIParser.h @@ -47,8 +47,8 @@ class MediaFragmentURIParser final { enum TimeFormat { None, Invalid, NormalPlayTime, SMPTETimeCode, WallClockTimeCode }; void parseTimeFragment(); - bool parseNPTFragment(std::span, MediaTime& startTime, MediaTime& endTime); - bool parseNPTTime(std::span, unsigned& offset, MediaTime&); + bool parseNPTFragment(std::span, MediaTime& startTime, MediaTime& endTime); + bool parseNPTTime(std::span, unsigned& offset, MediaTime&); URL m_url; TimeFormat m_timeFormat; diff --git a/Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp b/Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp index ea7fa367d9644..ad16efe035eab 100644 --- a/Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp +++ b/Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp @@ -192,7 +192,7 @@ template static bool insertInUniquedSortedVector(Vector& vector, template class HTMLFastPathParser { using CharacterSpan = std::span; - static_assert(std::is_same_v || std::is_same_v); + static_assert(std::is_same_v || std::is_same_v); public: HTMLFastPathParser(CharacterSpan source, Document& document, ContainerNode& destinationParent) @@ -473,7 +473,7 @@ class HTMLFastPathParser { // We first try to scan text as an unmodified subsequence of the input. // However, if there are escape sequences, we have to copy the text to a // separate buffer and we might go outside of `Char` range if we are in an - // `LChar` parser. + // `Latin1Character` parser. String scanText() { auto* start = m_parsingBuffer.position(); diff --git a/Source/WebCore/html/parser/HTMLEntityParser.cpp b/Source/WebCore/html/parser/HTMLEntityParser.cpp index f686432072cfa..b1af08f91a3b6 100644 --- a/Source/WebCore/html/parser/HTMLEntityParser.cpp +++ b/Source/WebCore/html/parser/HTMLEntityParser.cpp @@ -281,9 +281,9 @@ DecodedHTMLEntity consumeHTMLEntity(SegmentedString& source, UChar additionalAll return consumeHTMLEntity(SegmentedStringSource { source }, additionalAllowedCharacter); } -DecodedHTMLEntity consumeHTMLEntity(StringParsingBuffer& source) +DecodedHTMLEntity consumeHTMLEntity(StringParsingBuffer& source) { - return consumeHTMLEntity(StringParsingBufferSource { source }, 0); + return consumeHTMLEntity(StringParsingBufferSource { source }, 0); } DecodedHTMLEntity consumeHTMLEntity(StringParsingBuffer& source) diff --git a/Source/WebCore/html/parser/HTMLEntityParser.h b/Source/WebCore/html/parser/HTMLEntityParser.h index 7063190a5cfeb..2e84673171c40 100644 --- a/Source/WebCore/html/parser/HTMLEntityParser.h +++ b/Source/WebCore/html/parser/HTMLEntityParser.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include namespace WebCore { @@ -41,8 +41,8 @@ class SegmentedString; DecodedHTMLEntity consumeHTMLEntity(SegmentedString&, UChar additionalAllowedCharacter = 0); // This function assumes the source is complete, and does not expect a null character. -DecodedHTMLEntity consumeHTMLEntity(StringParsingBuffer&); -DecodedHTMLEntity consumeHTMLEntity(StringParsingBuffer&); +DecodedHTMLEntity consumeHTMLEntity(StringParsingBuffer&); +DecodedHTMLEntity consumeHTMLEntity(StringParsingBuffer&); // This function does not check for "not enough characters" at all. DecodedHTMLEntity decodeNamedHTMLEntityForXMLParser(const char*); diff --git a/Source/WebCore/html/parser/HTMLNameCache.h b/Source/WebCore/html/parser/HTMLNameCache.h index 2946cf5982344..55794d51a3654 100644 --- a/Source/WebCore/html/parser/HTMLNameCache.h +++ b/Source/WebCore/html/parser/HTMLNameCache.h @@ -39,7 +39,7 @@ class HTMLNameCache { return makeQualifiedName(string); } - ALWAYS_INLINE static QualifiedName makeAttributeQualifiedName(std::span string) + ALWAYS_INLINE static QualifiedName makeAttributeQualifiedName(std::span string) { return makeQualifiedName(string); } @@ -49,7 +49,7 @@ class HTMLNameCache { return makeAtomString(string); } - ALWAYS_INLINE static AtomString makeAttributeValue(std::span string) + ALWAYS_INLINE static AtomString makeAttributeValue(std::span string) { return makeAtomString(string); } diff --git a/Source/WebCore/html/parser/HTMLParserIdioms.h b/Source/WebCore/html/parser/HTMLParserIdioms.h index 0a95d9a79d99d..9b34a4d21c03b 100644 --- a/Source/WebCore/html/parser/HTMLParserIdioms.h +++ b/Source/WebCore/html/parser/HTMLParserIdioms.h @@ -102,8 +102,8 @@ inline bool isHTMLLineBreak(UChar character) ALWAYS_INLINE bool containsHTMLLineBreak(StringView view) { if (view.is8Bit()) - return charactersContain(view.span8()); - return charactersContain(view.span16()); + return charactersContain(view.span8()); + return charactersContain(view.span16()); } template inline bool isComma(CharacterType character) diff --git a/Source/WebCore/html/parser/HTMLSrcsetParser.cpp b/Source/WebCore/html/parser/HTMLSrcsetParser.cpp index b7e09f6f065e5..827244b08cc95 100644 --- a/Source/WebCore/html/parser/HTMLSrcsetParser.cpp +++ b/Source/WebCore/html/parser/HTMLSrcsetParser.cpp @@ -210,7 +210,7 @@ Vector parseImageCandidatesFromSrcsetAttribute(StringView attrib { // FIXME: We should consider replacing the direct pointers in the parsing process with StringView and positions. if (attribute.is8Bit()) - return parseImageCandidatesFromSrcsetAttribute(attribute.span8()); + return parseImageCandidatesFromSrcsetAttribute(attribute.span8()); else return parseImageCandidatesFromSrcsetAttribute(attribute.span16()); } diff --git a/Source/WebCore/html/parser/HTMLToken.h b/Source/WebCore/html/parser/HTMLToken.h index 83967aede180d..e53d14fbed68b 100644 --- a/Source/WebCore/html/parser/HTMLToken.h +++ b/Source/WebCore/html/parser/HTMLToken.h @@ -97,10 +97,10 @@ class HTMLToken { bool selfClosing() const; const AttributeList& attributes() const; - void beginStartTag(LChar); + void beginStartTag(Latin1Character); - void beginEndTag(LChar); - void beginEndTag(const Vector&); + void beginEndTag(Latin1Character); + void beginEndTag(const Vector&); void beginAttribute(); void appendToAttributeName(UChar); @@ -120,9 +120,9 @@ class HTMLToken { const DataVector& characters() const; bool charactersIsAll8BitData() const; - void appendToCharacter(LChar); - void appendToCharacter(UChar); - void appendToCharacter(const Vector&); + void appendToCharacter(Latin1Character); + void appendToCharacter(char16_t); + void appendToCharacter(const Vector&); template void appendToCharacter(std::span); // Comment. @@ -251,7 +251,7 @@ inline void HTMLToken::setSelfClosing() m_selfClosing = true; } -inline void HTMLToken::beginStartTag(LChar character) +inline void HTMLToken::beginStartTag(Latin1Character character) { ASSERT(character); ASSERT(m_type == Type::Uninitialized); @@ -266,7 +266,7 @@ inline void HTMLToken::beginStartTag(LChar character) m_data.append(character); } -inline void HTMLToken::beginEndTag(LChar character) +inline void HTMLToken::beginEndTag(Latin1Character character) { ASSERT(m_type == Type::Uninitialized); m_type = Type::EndTag; @@ -280,7 +280,7 @@ inline void HTMLToken::beginEndTag(LChar character) m_data.append(character); } -inline void HTMLToken::beginEndTag(const Vector& characters) +inline void HTMLToken::beginEndTag(const Vector& characters) { ASSERT(m_type == Type::Uninitialized); m_type = Type::EndTag; @@ -358,7 +358,7 @@ inline bool HTMLToken::charactersIsAll8BitData() const return m_data8BitCheck <= 0xFF; } -inline void HTMLToken::appendToCharacter(LChar character) +inline void HTMLToken::appendToCharacter(Latin1Character character) { ASSERT(m_type == Type::Uninitialized || m_type == Type::Character); m_type = Type::Character; @@ -373,7 +373,7 @@ inline void HTMLToken::appendToCharacter(UChar character) m_data8BitCheck |= character; } -inline void HTMLToken::appendToCharacter(const Vector& characters) +inline void HTMLToken::appendToCharacter(const Vector& characters) { ASSERT(m_type == Type::Uninitialized || m_type == Type::Character); m_type = Type::Character; diff --git a/Source/WebCore/html/parser/HTMLTokenizer.cpp b/Source/WebCore/html/parser/HTMLTokenizer.cpp index da8a0c788212e..30641889e1d27 100644 --- a/Source/WebCore/html/parser/HTMLTokenizer.cpp +++ b/Source/WebCore/html/parser/HTMLTokenizer.cpp @@ -39,7 +39,7 @@ namespace WebCore { using namespace HTMLNames; -static inline LChar convertASCIIAlphaToLower(UChar character) +static inline Latin1Character convertASCIIAlphaToLower(char16_t character) { ASSERT(isASCIIAlpha(character)); return toASCIILowerUnchecked(character); @@ -72,7 +72,7 @@ inline void HTMLTokenizer::bufferASCIICharacter(UChar character) { ASSERT(character != kEndOfFileMarker); ASSERT(isASCII(character)); - LChar narrowedCharacter = character; + Latin1Character narrowedCharacter = character; m_token.appendToCharacter(narrowedCharacter); } diff --git a/Source/WebCore/html/parser/HTMLTokenizer.h b/Source/WebCore/html/parser/HTMLTokenizer.h index 60758a64fc509..1fb5d423d80dd 100644 --- a/Source/WebCore/html/parser/HTMLTokenizer.h +++ b/Source/WebCore/html/parser/HTMLTokenizer.h @@ -200,12 +200,12 @@ class HTMLTokenizer { Vector m_appropriateEndTagName; // https://html.spec.whatwg.org/#temporary-buffer - Vector m_temporaryBuffer; + Vector m_temporaryBuffer; // We occasionally want to emit both a character token and an end tag // token (e.g., when lexing script). We buffer the name of the end tag // token here so we remember it next time we re-enter the tokenizer. - Vector m_bufferedEndTagName; + Vector m_bufferedEndTagName; const HTMLParserOptions m_options; }; diff --git a/Source/WebCore/html/parser/HTMLTreeBuilder.cpp b/Source/WebCore/html/parser/HTMLTreeBuilder.cpp index 51ee40f937c8f..c8a27b6a60f2d 100644 --- a/Source/WebCore/html/parser/HTMLTreeBuilder.cpp +++ b/Source/WebCore/html/parser/HTMLTreeBuilder.cpp @@ -193,7 +193,7 @@ class HTMLTreeBuilder::ExternalCharacterTokenBuffer { String takeRemainingWhitespace() { ASSERT(!isEmpty()); - Vector whitespace; + Vector whitespace; do { UChar character = m_text[0]; if (isASCIIWhitespace(character)) diff --git a/Source/WebCore/html/track/VTTScanner.cpp b/Source/WebCore/html/track/VTTScanner.cpp index f880ef3b15dc7..9b9a729aaea77 100644 --- a/Source/WebCore/html/track/VTTScanner.cpp +++ b/Source/WebCore/html/track/VTTScanner.cpp @@ -55,7 +55,7 @@ bool VTTScanner::scan(char c) return true; } -bool VTTScanner::scan(std::span characters) +bool VTTScanner::scan(std::span characters) { unsigned matchLength = m_is8Bit ? m_end.characters8 - m_data.characters8 : m_end.characters16 - m_data.characters16; if (matchLength < characters.size()) diff --git a/Source/WebCore/html/track/VTTScanner.h b/Source/WebCore/html/track/VTTScanner.h index 8abb31c17ae00..fe47090b7b634 100644 --- a/Source/WebCore/html/track/VTTScanner.h +++ b/Source/WebCore/html/track/VTTScanner.h @@ -50,7 +50,7 @@ class VTTScanner { public: explicit VTTScanner(const String& line); - typedef const LChar* Position; + typedef const Latin1Character* Position; class Run { public: @@ -78,7 +78,7 @@ class VTTScanner { // Scan the character |c|. bool scan(char); // Scan the first |charactersCount| characters of the string |characters|. - bool scan(std::span characters); + bool scan(std::span characters); // Scan the literal |characters|. template @@ -87,21 +87,21 @@ class VTTScanner { // Skip (advance the input pointer) as long as the specified // |characterPredicate| returns true, and the input pointer is not passed // the end of the input. - template + template void skipWhile(); // Like skipWhile, but using a negated predicate. - template + template void skipUntil(); // Return the run of characters for which the specified // |characterPredicate| returns true. The start of the run will be the // current input pointer. - template + template Run collectWhile(); // Like collectWhile, but using a negated predicate. - template + template Run collectUntil(); // Scan the string |toMatch|, using the specified |run| as the sequence to @@ -132,19 +132,19 @@ class VTTScanner { Position position() const { return m_data.characters8; } Position end() const { return m_end.characters8; } void seekTo(Position); - UChar currentChar() const; + char16_t currentChar() const; void advance(unsigned amount = 1); - // Adapt a UChar-predicate to an LChar-predicate. + // Adapt a char16_t-predicate to an Latin1Character-predicate. // (For use with skipWhile/Until from ParsingUtilities.h). - template - static inline bool LCharPredicateAdapter(LChar c) { return characterPredicate(c); } + template + static inline bool Latin1CharacterPredicateAdapter(Latin1Character c) { return characterPredicate(c); } union { - const LChar* characters8; - const UChar* characters16; + const Latin1Character* characters8; + const char16_t* characters16; } m_data; union { - const LChar* characters8; - const UChar* characters16; + const Latin1Character* characters8; + const char16_t* characters16; } m_end; const String m_source; bool m_is8Bit; @@ -154,55 +154,55 @@ inline size_t VTTScanner::Run::length() const { if (m_is8Bit) return m_end - m_start; - return reinterpret_cast(m_end) - reinterpret_cast(m_start); + return reinterpret_cast(m_end) - reinterpret_cast(m_start); } template inline bool VTTScanner::scan(const char (&characters)[charactersCount]) { - return scan({ byteCast(&characters[0]), charactersCount - 1 }); + return scan({ byteCast(&characters[0]), charactersCount - 1 }); } -template +template inline void VTTScanner::skipWhile() { if (m_is8Bit) - WebCore::skipWhile >(m_data.characters8, m_end.characters8); + WebCore::skipWhile >(m_data.characters8, m_end.characters8); else WebCore::skipWhile(m_data.characters16, m_end.characters16); } -template +template inline void VTTScanner::skipUntil() { if (m_is8Bit) - WebCore::skipUntil >(m_data.characters8, m_end.characters8); + WebCore::skipUntil >(m_data.characters8, m_end.characters8); else WebCore::skipUntil(m_data.characters16, m_end.characters16); } -template +template inline VTTScanner::Run VTTScanner::collectWhile() { if (m_is8Bit) { - const LChar* current = m_data.characters8; - WebCore::skipWhile>(current, m_end.characters8); + const Latin1Character* current = m_data.characters8; + WebCore::skipWhile>(current, m_end.characters8); return Run(position(), current, m_is8Bit); } - const UChar* current = m_data.characters16; + const char16_t* current = m_data.characters16; WebCore::skipWhile(current, m_end.characters16); return Run(position(), reinterpret_cast(current), m_is8Bit); } -template +template inline VTTScanner::Run VTTScanner::collectUntil() { if (m_is8Bit) { - const LChar* current = m_data.characters8; - WebCore::skipUntil >(current, m_end.characters8); + const Latin1Character* current = m_data.characters8; + WebCore::skipUntil >(current, m_end.characters8); return Run(position(), current, m_is8Bit); } - const UChar* current = m_data.characters16; + const char16_t* current = m_data.characters16; WebCore::skipUntil(current, m_end.characters16); return Run(position(), reinterpret_cast(current), m_is8Bit); } @@ -213,7 +213,7 @@ inline void VTTScanner::seekTo(Position position) m_data.characters8 = position; } -inline UChar VTTScanner::currentChar() const +inline char16_t VTTScanner::currentChar() const { ASSERT(position() < end()); return m_is8Bit ? *m_data.characters8 : *m_data.characters16; diff --git a/Source/WebCore/inspector/InspectorStyleSheet.cpp b/Source/WebCore/inspector/InspectorStyleSheet.cpp index 413d123ab28a8..cca8f403f605c 100644 --- a/Source/WebCore/inspector/InspectorStyleSheet.cpp +++ b/Source/WebCore/inspector/InspectorStyleSheet.cpp @@ -343,7 +343,7 @@ void StyleSheetHandler::endRuleHeader(unsigned offset) ASSERT(!m_currentRuleDataStack.isEmpty()); if (m_parsedText.is8Bit()) - setRuleHeaderEnd(m_parsedText.span8().first(offset)); + setRuleHeaderEnd(m_parsedText.span8().first(offset)); else setRuleHeaderEnd(m_parsedText.span16().first(offset)); } @@ -465,7 +465,7 @@ void StyleSheetHandler::fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData) return; if (m_parsedText.is8Bit()) { - fixUnparsedProperties(m_parsedText.span8(), ruleData); + fixUnparsedProperties(m_parsedText.span8(), ruleData); return; } diff --git a/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp b/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp index c56e0889c728b..cfb869ed7ce00 100644 --- a/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp +++ b/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp @@ -684,8 +684,8 @@ bool TextUtil::canUseSimplifiedTextMeasuring(StringView textContent, const FontC bool TextUtil::hasPositionDependentContentWidth(StringView textContent) { if (textContent.is8Bit()) - return charactersContain(textContent.span8()); - return charactersContain(textContent.span16()); + return charactersContain(textContent.span8()); + return charactersContain(textContent.span16()); } } diff --git a/Source/WebCore/loader/ResourceCryptographicDigest.cpp b/Source/WebCore/loader/ResourceCryptographicDigest.cpp index b946c510d3800..3abd0e05d3e7b 100644 --- a/Source/WebCore/loader/ResourceCryptographicDigest.cpp +++ b/Source/WebCore/loader/ResourceCryptographicDigest.cpp @@ -85,7 +85,7 @@ std::optional parseCryptographicDigest(StringParsin return parseCryptographicDigestImpl(buffer); } -std::optional parseCryptographicDigest(StringParsingBuffer& buffer) +std::optional parseCryptographicDigest(StringParsingBuffer& buffer) { return parseCryptographicDigestImpl(buffer); } @@ -118,7 +118,7 @@ std::optional parseEncodedCryptographicDiges return parseEncodedCryptographicDigestImpl(buffer); } -std::optional parseEncodedCryptographicDigest(StringParsingBuffer& buffer) +std::optional parseEncodedCryptographicDigest(StringParsingBuffer& buffer) { return parseEncodedCryptographicDigestImpl(buffer); } diff --git a/Source/WebCore/loader/ResourceCryptographicDigest.h b/Source/WebCore/loader/ResourceCryptographicDigest.h index 2be4f4fb52b67..48c853978444b 100644 --- a/Source/WebCore/loader/ResourceCryptographicDigest.h +++ b/Source/WebCore/loader/ResourceCryptographicDigest.h @@ -29,6 +29,7 @@ #include #include #include +#include #include namespace WebCore { @@ -65,11 +66,11 @@ struct EncodedResourceCryptographicDigest { String digest; }; -std::optional parseCryptographicDigest(StringParsingBuffer&); -std::optional parseCryptographicDigest(StringParsingBuffer&); +std::optional parseCryptographicDigest(StringParsingBuffer&); +std::optional parseCryptographicDigest(StringParsingBuffer&); -std::optional parseEncodedCryptographicDigest(StringParsingBuffer&); -std::optional parseEncodedCryptographicDigest(StringParsingBuffer&); +std::optional parseEncodedCryptographicDigest(StringParsingBuffer&); +std::optional parseEncodedCryptographicDigest(StringParsingBuffer&); std::optional decodeEncodedResourceCryptographicDigest(const EncodedResourceCryptographicDigest&); diff --git a/Source/WebCore/platform/graphics/AV1Utilities.cpp b/Source/WebCore/platform/graphics/AV1Utilities.cpp index 312c32ebbaa76..6daea111b96d0 100644 --- a/Source/WebCore/platform/graphics/AV1Utilities.cpp +++ b/Source/WebCore/platform/graphics/AV1Utilities.cpp @@ -213,18 +213,18 @@ String createAV1CodecParametersString(const AV1CodecConfigurationRecord& configu builder.append("av01"_s); auto appendOneDigit = [&](uint8_t number) { - builder.append(static_cast('0' + number % 10)); + builder.append(static_cast('0' + number % 10)); }; auto appendTwoDigits = [&](uint8_t number) { - builder.append(static_cast('0' + number / 10 % 10)); - builder.append(static_cast('0' + number % 10)); + builder.append(static_cast('0' + number / 10 % 10)); + builder.append(static_cast('0' + number % 10)); }; auto appendThreeDigits = [&](uint8_t number) { - builder.append(static_cast('0' + number / 100 % 10)); - builder.append(static_cast('0' + number / 10 % 10)); - builder.append(static_cast('0' + number % 10)); + builder.append(static_cast('0' + number / 100 % 10)); + builder.append(static_cast('0' + number / 10 % 10)); + builder.append(static_cast('0' + number % 10)); }; // The parameters sample entry 4CC, profile, level, tier, and bitDepth are diff --git a/Source/WebCore/platform/graphics/FontCascade.cpp b/Source/WebCore/platform/graphics/FontCascade.cpp index 513c41ba81daa..97eb651e5356a 100644 --- a/Source/WebCore/platform/graphics/FontCascade.cpp +++ b/Source/WebCore/platform/graphics/FontCascade.cpp @@ -584,7 +584,7 @@ static inline String normalizeSpacesInternal(std::span char return normalized.toString(); } -String FontCascade::normalizeSpaces(std::span characters) +String FontCascade::normalizeSpaces(std::span characters) { return normalizeSpacesInternal(characters); } @@ -1097,7 +1097,7 @@ bool FontCascade::isCJKIdeographOrSymbol(char32_t c) return isCJKIdeograph(c); } -std::pair FontCascade::expansionOpportunityCountInternal(std::span characters, TextDirection direction, ExpansionBehavior expansionBehavior) +std::pair FontCascade::expansionOpportunityCountInternal(std::span characters, TextDirection direction, ExpansionBehavior expansionBehavior) { unsigned count = 0; bool isAfterExpansion = expansionBehavior.left == ExpansionBehavior::Behavior::Forbid; diff --git a/Source/WebCore/platform/graphics/FontCascade.h b/Source/WebCore/platform/graphics/FontCascade.h index 181becbced7a2..a7df4d5bdfb06 100644 --- a/Source/WebCore/platform/graphics/FontCascade.h +++ b/Source/WebCore/platform/graphics/FontCascade.h @@ -217,8 +217,8 @@ class FontCascade final : public CanMakeWeakPtr, public CanMakeChec enum class CodePath : uint8_t { Auto, Simple, Complex, SimpleWithGlyphOverflow }; WEBCORE_EXPORT CodePath codePath(const TextRun&, std::optional from = std::nullopt, std::optional to = std::nullopt) const; - static CodePath characterRangeCodePath(std::span) { return CodePath::Simple; } - WEBCORE_EXPORT static CodePath characterRangeCodePath(std::span); + static CodePath characterRangeCodePath(std::span) { return CodePath::Simple; } + WEBCORE_EXPORT static CodePath characterRangeCodePath(std::span); bool primaryFontIsSystemFont() const; @@ -252,8 +252,8 @@ class FontCascade final : public CanMakeWeakPtr, public CanMakeChec int offsetForPositionForComplexText(const TextRun&, float position, bool includePartialGlyphs) const; void adjustSelectionRectForComplexText(const TextRun&, LayoutRect& selectionRect, unsigned from, unsigned to) const; - static std::pair expansionOpportunityCountInternal(std::span, TextDirection, ExpansionBehavior); - static std::pair expansionOpportunityCountInternal(std::span, TextDirection, ExpansionBehavior); + static std::pair expansionOpportunityCountInternal(std::span, TextDirection, ExpansionBehavior); + static std::pair expansionOpportunityCountInternal(std::span, TextDirection, ExpansionBehavior); friend struct WidthIterator; friend class ComplexTextController; @@ -304,7 +304,7 @@ class FontCascade final : public CanMakeWeakPtr, public CanMakeChec static bool treatAsZeroWidthSpaceInComplexScript(char32_t c) { return c < space || (c >= deleteCharacter && c < noBreakSpace) || c == softHyphen || c == zeroWidthSpace || (c >= leftToRightMark && c <= rightToLeftMark) || (c >= leftToRightEmbed && c <= rightToLeftOverride) || c == zeroWidthNoBreakSpace || isInvisibleReplacementObjectCharacter(c); } static bool canReceiveTextEmphasis(char32_t); - static inline UChar normalizeSpaces(UChar character) + static inline char16_t normalizeSpaces(char16_t character) { if (treatAsSpace(character)) return space; @@ -315,8 +315,8 @@ class FontCascade final : public CanMakeWeakPtr, public CanMakeChec return character; } - static String normalizeSpaces(std::span); - static String normalizeSpaces(std::span); + static String normalizeSpaces(std::span); + static String normalizeSpaces(std::span); static String normalizeSpaces(StringView); bool useBackslashAsYenSymbol() const { return m_useBackslashAsYenSymbol; } diff --git a/Source/WebCore/platform/graphics/Latin1TextIterator.h b/Source/WebCore/platform/graphics/Latin1TextIterator.h index 55e49d40a0f38..76193683ddf15 100644 --- a/Source/WebCore/platform/graphics/Latin1TextIterator.h +++ b/Source/WebCore/platform/graphics/Latin1TextIterator.h @@ -27,9 +27,9 @@ namespace WebCore { class Latin1TextIterator { public: - // The passed in LChar pointer starts at 'currentIndex'. The iterator operates on the range [currentIndex, lastIndex]. - // 'endCharacter' denotes the maximum length of the UChar array, which might exceed 'lastIndex'. - Latin1TextIterator(std::span characters, unsigned currentIndex, unsigned lastIndex) + // The passed in Latin1Character pointer starts at 'currentIndex'. The iterator operates on the range [currentIndex, lastIndex]. + // 'endCharacter' denotes the maximum length of the char16_t array, which might exceed 'lastIndex'. + Latin1TextIterator(std::span characters, unsigned currentIndex, unsigned lastIndex) : m_characters(characters.data()) , m_currentIndex(currentIndex) , m_originalIndex(currentIndex) @@ -60,17 +60,17 @@ class Latin1TextIterator { m_currentIndex = index; } - const LChar* remainingCharacters() const + const Latin1Character* remainingCharacters() const { auto relativeIndex = m_currentIndex - m_originalIndex; return m_characters + relativeIndex; } unsigned currentIndex() const { return m_currentIndex; } - const LChar* characters() const { return m_characters; } + const Latin1Character* characters() const { return m_characters; } private: - const LChar* const m_characters; + const Latin1Character* const m_characters; unsigned m_currentIndex; const unsigned m_originalIndex; const unsigned m_lastIndex; diff --git a/Source/WebCore/platform/graphics/TextRun.h b/Source/WebCore/platform/graphics/TextRun.h index 443395b660a02..8e63978174421 100644 --- a/Source/WebCore/platform/graphics/TextRun.h +++ b/Source/WebCore/platform/graphics/TextRun.h @@ -116,11 +116,11 @@ class TextRun final : public CanMakeCheckedPtr { return result; } - UChar operator[](unsigned i) const { RELEASE_ASSERT(i < m_text.length()); return m_text[i]; } - std::span span8() const { ASSERT(is8Bit()); return m_text.span8(); } - std::span span16() const { ASSERT(!is8Bit()); return m_text.span16(); } - std::span subspan8(unsigned i) const { return span8().subspan(i); } - std::span subspan16(unsigned i) const { return span16().subspan(i); } + char16_t operator[](unsigned i) const { RELEASE_ASSERT(i < m_text.length()); return m_text[i]; } + std::span span8() const { ASSERT(is8Bit()); return m_text.span8(); } + std::span span16() const { ASSERT(!is8Bit()); return m_text.span16(); } + std::span subspan8(unsigned i) const { return span8().subspan(i); } + std::span subspan16(unsigned i) const { return span16().subspan(i); } bool is8Bit() const { return m_text.is8Bit(); } unsigned length() const { return m_text.length(); } diff --git a/Source/WebCore/platform/graphics/iso/ISOVTTCue.cpp b/Source/WebCore/platform/graphics/iso/ISOVTTCue.cpp index 5afabdb1b2357..3be921814151a 100644 --- a/Source/WebCore/platform/graphics/iso/ISOVTTCue.cpp +++ b/Source/WebCore/platform/graphics/iso/ISOVTTCue.cpp @@ -56,7 +56,7 @@ class ISOStringBox final : public ISOBox { if (characterCount > bytesRemaining) return false; - Vector characters; + Vector characters; characters.reserveInitialCapacity(static_cast(characterCount)); while (characterCount--) { int8_t character = 0; diff --git a/Source/WebCore/platform/network/curl/CookieUtil.cpp b/Source/WebCore/platform/network/curl/CookieUtil.cpp index 4a4fc1f086cf5..2e99563d8b6ae 100644 --- a/Source/WebCore/platform/network/curl/CookieUtil.cpp +++ b/Source/WebCore/platform/network/curl/CookieUtil.cpp @@ -81,7 +81,7 @@ bool domainMatch(const String& cookieDomain, const String& host) return false; } -static std::optional parseExpiresMS(std::span expires) +static std::optional parseExpiresMS(std::span expires) { double tmp = parseDate(expires); if (isnan(tmp)) diff --git a/Source/WebCore/platform/text/SegmentedString.h b/Source/WebCore/platform/text/SegmentedString.h index e3cd024c1042a..824bbb93148f1 100644 --- a/Source/WebCore/platform/text/SegmentedString.h +++ b/Source/WebCore/platform/text/SegmentedString.h @@ -93,8 +93,8 @@ class SegmentedString { unsigned originalLength { 0 }; unsigned length { 0 }; union { - const LChar* currentCharacter8 { nullptr }; - const UChar* currentCharacter16; + const Latin1Character* currentCharacter8 { nullptr }; + const char16_t* currentCharacter16; }; bool is8Bit { true }; bool doNotExcludeLineNumbers { true }; @@ -133,7 +133,7 @@ class SegmentedString { bool m_isClosed { false }; - UChar m_currentCharacter { 0 }; + char16_t m_currentCharacter { 0 }; unsigned m_numberOfCharactersConsumedPriorToCurrentSubstring { 0 }; unsigned m_numberOfCharactersConsumedPriorToCurrentLine { 0 }; @@ -176,13 +176,13 @@ inline unsigned SegmentedString::Substring::numberOfCharactersConsumed() const return originalLength - length; } -ALWAYS_INLINE UChar SegmentedString::Substring::currentCharacter() const +ALWAYS_INLINE char16_t SegmentedString::Substring::currentCharacter() const { ASSERT(length); return is8Bit ? *currentCharacter8 : *currentCharacter16; } -ALWAYS_INLINE UChar SegmentedString::Substring::currentCharacterPreIncrement() +ALWAYS_INLINE char16_t SegmentedString::Substring::currentCharacterPreIncrement() { ASSERT(length); return is8Bit ? *++currentCharacter8 : *++currentCharacter16; diff --git a/Source/WebCore/rendering/BreakLines.h b/Source/WebCore/rendering/BreakLines.h index 6e2a51f6d2c27..e9ec67d26d925 100644 --- a/Source/WebCore/rendering/BreakLines.h +++ b/Source/WebCore/rendering/BreakLines.h @@ -288,8 +288,8 @@ inline unsigned BreakLines::nextBreakablePosition(CachedLineBreakIteratorFactory if (stringView.is8Bit()) { return words == WordBreakBehavior::KeepAll - ? nextBreakableSpace(stringView.span8(), startPosition) - : nextBreakablePosition(lineBreakIteratorFactory, stringView.span8(), startPosition); + ? nextBreakableSpace(stringView.span8(), startPosition) + : nextBreakablePosition(lineBreakIteratorFactory, stringView.span8(), startPosition); } return words == WordBreakBehavior::KeepAll ? nextBreakableSpace(stringView.span16(), startPosition) diff --git a/Source/WebCore/rendering/RenderBlock.cpp b/Source/WebCore/rendering/RenderBlock.cpp index c1a90fb193d6c..935b6b0385298 100644 --- a/Source/WebCore/rendering/RenderBlock.cpp +++ b/Source/WebCore/rendering/RenderBlock.cpp @@ -3106,7 +3106,7 @@ TextRun RenderBlock::constructTextRun(const RenderText& text, unsigned offset, u return constructTextRun(text.stringView(offset, stop), style, expansion); } -TextRun RenderBlock::constructTextRun(std::span characters, const RenderStyle& style, ExpansionBehavior expansion) +TextRun RenderBlock::constructTextRun(std::span characters, const RenderStyle& style, ExpansionBehavior expansion) { return constructTextRun(StringView { characters }, style, expansion); } diff --git a/Source/WebCore/rendering/RenderBlock.h b/Source/WebCore/rendering/RenderBlock.h index 3076d632cc424..4606f28786f7c 100644 --- a/Source/WebCore/rendering/RenderBlock.h +++ b/Source/WebCore/rendering/RenderBlock.h @@ -186,7 +186,7 @@ class RenderBlock : public RenderBox { ExpansionBehavior = ExpansionBehavior::defaultBehavior()); static TextRun constructTextRun(const RenderText&, unsigned offset, unsigned length, const RenderStyle&, ExpansionBehavior = ExpansionBehavior::defaultBehavior()); - static TextRun constructTextRun(std::span characters, const RenderStyle&, + static TextRun constructTextRun(std::span characters, const RenderStyle&, ExpansionBehavior = ExpansionBehavior::defaultBehavior()); static TextRun constructTextRun(std::span characters, const RenderStyle&, ExpansionBehavior = ExpansionBehavior::defaultBehavior()); diff --git a/Source/WebCore/svg/SVGFitToViewBox.cpp b/Source/WebCore/svg/SVGFitToViewBox.cpp index 5e447880fc185..e6a7b78e1ae13 100644 --- a/Source/WebCore/svg/SVGFitToViewBox.cpp +++ b/Source/WebCore/svg/SVGFitToViewBox.cpp @@ -93,7 +93,7 @@ std::optional SVGFitToViewBox::parseViewBox(StringView value) }); } -std::optional SVGFitToViewBox::parseViewBox(StringParsingBuffer& buffer, bool validate) +std::optional SVGFitToViewBox::parseViewBox(StringParsingBuffer& buffer, bool validate) { return parseViewBoxGeneric(buffer, validate); } diff --git a/Source/WebCore/svg/SVGFitToViewBox.h b/Source/WebCore/svg/SVGFitToViewBox.h index eb523ed7fdcc1..2968f44ca349d 100644 --- a/Source/WebCore/svg/SVGFitToViewBox.h +++ b/Source/WebCore/svg/SVGFitToViewBox.h @@ -65,8 +65,8 @@ class SVGFitToViewBox { void reset(); bool parseAttribute(const QualifiedName&, const AtomString&); std::optional parseViewBox(StringView); - std::optional parseViewBox(StringParsingBuffer&, bool validate = true); - std::optional parseViewBox(StringParsingBuffer&, bool validate = true); + std::optional parseViewBox(StringParsingBuffer&, bool validate = true); + std::optional parseViewBox(StringParsingBuffer&, bool validate = true); private: template std::optional parseViewBoxGeneric(StringParsingBuffer&, bool validate = true); diff --git a/Source/WebCore/svg/SVGParserUtilities.cpp b/Source/WebCore/svg/SVGParserUtilities.cpp index 198f551b7adff..e1f1ac3d11c53 100644 --- a/Source/WebCore/svg/SVGParserUtilities.cpp +++ b/Source/WebCore/svg/SVGParserUtilities.cpp @@ -139,7 +139,7 @@ template static std::option return number; } -std::optional parseNumber(StringParsingBuffer& buffer, SuffixSkippingPolicy skip) +std::optional parseNumber(StringParsingBuffer& buffer, SuffixSkippingPolicy skip) { return genericParseNumber(buffer, skip); } @@ -182,7 +182,7 @@ template std::optional genericParseArcFlag(String return flag; } -std::optional parseArcFlag(StringParsingBuffer& buffer) +std::optional parseArcFlag(StringParsingBuffer& buffer) { return genericParseArcFlag(buffer); } @@ -407,7 +407,7 @@ template static std::optional genericParseF return FloatPoint { *x, *y }; } -std::optional parseFloatPoint(StringParsingBuffer& buffer) +std::optional parseFloatPoint(StringParsingBuffer& buffer) { return genericParseFloatPoint(buffer); } diff --git a/Source/WebCore/svg/SVGParserUtilities.h b/Source/WebCore/svg/SVGParserUtilities.h index 947ad1452a0bd..f6bf1fb7bbbea 100644 --- a/Source/WebCore/svg/SVGParserUtilities.h +++ b/Source/WebCore/svg/SVGParserUtilities.h @@ -37,20 +37,20 @@ enum class SuffixSkippingPolicy { Skip }; -std::optional parseNumber(StringParsingBuffer&, SuffixSkippingPolicy = SuffixSkippingPolicy::Skip); -std::optional parseNumber(StringParsingBuffer&, SuffixSkippingPolicy = SuffixSkippingPolicy::Skip); +std::optional parseNumber(StringParsingBuffer&, SuffixSkippingPolicy = SuffixSkippingPolicy::Skip); +std::optional parseNumber(StringParsingBuffer&, SuffixSkippingPolicy = SuffixSkippingPolicy::Skip); std::optional parseNumber(StringView, SuffixSkippingPolicy = SuffixSkippingPolicy::Skip); std::optional> parseNumberOptionalNumber(StringView); -std::optional parseArcFlag(StringParsingBuffer&); -std::optional parseArcFlag(StringParsingBuffer&); +std::optional parseArcFlag(StringParsingBuffer&); +std::optional parseArcFlag(StringParsingBuffer&); std::optional parsePoint(StringView); std::optional parseRect(StringView); -std::optional parseFloatPoint(StringParsingBuffer&); -std::optional parseFloatPoint(StringParsingBuffer&); +std::optional parseFloatPoint(StringParsingBuffer&); +std::optional parseFloatPoint(StringParsingBuffer&); std::optional>> parseKerningUnicodeString(StringView); std::optional> parseGlyphName(StringView); diff --git a/Source/WebCore/svg/SVGPathStringViewSource.h b/Source/WebCore/svg/SVGPathStringViewSource.h index b819f9d95ac7e..375ba077ebe8c 100644 --- a/Source/WebCore/svg/SVGPathStringViewSource.h +++ b/Source/WebCore/svg/SVGPathStringViewSource.h @@ -50,8 +50,8 @@ class SVGPathStringViewSource final : public SVGPathSource { bool m_is8BitSource; union { - StringParsingBuffer m_buffer8; - StringParsingBuffer m_buffer16; + StringParsingBuffer m_buffer8; + StringParsingBuffer m_buffer16; }; }; diff --git a/Source/WebCore/svg/SVGPreserveAspectRatioValue.cpp b/Source/WebCore/svg/SVGPreserveAspectRatioValue.cpp index 35537931f7cd1..982c306fd71f7 100644 --- a/Source/WebCore/svg/SVGPreserveAspectRatioValue.cpp +++ b/Source/WebCore/svg/SVGPreserveAspectRatioValue.cpp @@ -69,7 +69,7 @@ bool SVGPreserveAspectRatioValue::parse(StringView value) }); } -bool SVGPreserveAspectRatioValue::parse(StringParsingBuffer& buffer, bool validate) +bool SVGPreserveAspectRatioValue::parse(StringParsingBuffer& buffer, bool validate) { return parseInternal(buffer, validate); } diff --git a/Source/WebCore/svg/SVGPreserveAspectRatioValue.h b/Source/WebCore/svg/SVGPreserveAspectRatioValue.h index 6ffe9fd451841..02e6a99511888 100644 --- a/Source/WebCore/svg/SVGPreserveAspectRatioValue.h +++ b/Source/WebCore/svg/SVGPreserveAspectRatioValue.h @@ -72,8 +72,8 @@ class SVGPreserveAspectRatioValue { AffineTransform getCTM(float logicalX, float logicalY, float logicalWidth, float logicalHeight, float physicalWidth, float physicalHeight) const; bool parse(StringView); - bool parse(StringParsingBuffer&, bool validate); - bool parse(StringParsingBuffer&, bool validate); + bool parse(StringParsingBuffer&, bool validate); + bool parse(StringParsingBuffer&, bool validate); String valueAsString() const; diff --git a/Source/WebCore/svg/SVGTransformList.cpp b/Source/WebCore/svg/SVGTransformList.cpp index 5da3b3f5482f2..f4abfc3c9a206 100644 --- a/Source/WebCore/svg/SVGTransformList.cpp +++ b/Source/WebCore/svg/SVGTransformList.cpp @@ -102,7 +102,7 @@ void SVGTransformList::parse(StringView value) clearItems(); } -bool SVGTransformList::parse(StringParsingBuffer& buffer) +bool SVGTransformList::parse(StringParsingBuffer& buffer) { return parseGeneric(buffer); } diff --git a/Source/WebCore/svg/SVGTransformList.h b/Source/WebCore/svg/SVGTransformList.h index b8fc0776693fc..6cc9ee7a65c0f 100644 --- a/Source/WebCore/svg/SVGTransformList.h +++ b/Source/WebCore/svg/SVGTransformList.h @@ -64,8 +64,8 @@ class SVGTransformList final : public SVGValuePropertyList { private: template bool parseGeneric(StringParsingBuffer&); - bool parse(StringParsingBuffer&); - bool parse(StringParsingBuffer&); + bool parse(StringParsingBuffer&); + bool parse(StringParsingBuffer&); }; } // namespace WebCore diff --git a/Source/WebCore/svg/SVGTransformable.cpp b/Source/WebCore/svg/SVGTransformable.cpp index ca6714fa3827b..0d9b301aeeaff 100644 --- a/Source/WebCore/svg/SVGTransformable.cpp +++ b/Source/WebCore/svg/SVGTransformable.cpp @@ -152,12 +152,12 @@ template static std::optional parseTr return std::nullopt; } -std::optional SVGTransformable::parseTransformValue(SVGTransformValue::SVGTransformType type, StringParsingBuffer& buffer) +std::optional SVGTransformable::parseTransformValue(SVGTransformValue::SVGTransformType type, StringParsingBuffer& buffer) { return parseTransformValueGeneric(type, buffer); } -std::optional SVGTransformable::parseTransformValue(SVGTransformValue::SVGTransformType type, StringParsingBuffer& buffer) +std::optional SVGTransformable::parseTransformValue(SVGTransformValue::SVGTransformType type, StringParsingBuffer& buffer) { return parseTransformValueGeneric(type, buffer); } @@ -201,12 +201,12 @@ std::optional SVGTransformable::parseTransf }); } -std::optional SVGTransformable::parseTransformType(StringParsingBuffer& buffer) +std::optional SVGTransformable::parseTransformType(StringParsingBuffer& buffer) { return parseTransformTypeGeneric(buffer); } -std::optional SVGTransformable::parseTransformType(StringParsingBuffer& buffer) +std::optional SVGTransformable::parseTransformType(StringParsingBuffer& buffer) { return parseTransformTypeGeneric(buffer); } diff --git a/Source/WebCore/svg/SVGTransformable.h b/Source/WebCore/svg/SVGTransformable.h index b05d7d3303510..3fd6e60789ca2 100644 --- a/Source/WebCore/svg/SVGTransformable.h +++ b/Source/WebCore/svg/SVGTransformable.h @@ -31,12 +31,12 @@ class SVGTransformable : public SVGLocatable { public: virtual ~SVGTransformable(); - static std::optional parseTransformValue(SVGTransformValue::SVGTransformType, StringParsingBuffer&); - static std::optional parseTransformValue(SVGTransformValue::SVGTransformType, StringParsingBuffer&); + static std::optional parseTransformValue(SVGTransformValue::SVGTransformType, StringParsingBuffer&); + static std::optional parseTransformValue(SVGTransformValue::SVGTransformType, StringParsingBuffer&); static std::optional parseTransformType(StringView); - static std::optional parseTransformType(StringParsingBuffer&); - static std::optional parseTransformType(StringParsingBuffer&); + static std::optional parseTransformType(StringParsingBuffer&); + static std::optional parseTransformType(StringParsingBuffer&); AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope) const override { return animatedLocalTransform(); } virtual AffineTransform animatedLocalTransform() const = 0; diff --git a/Source/WebCore/svg/SVGZoomAndPan.cpp b/Source/WebCore/svg/SVGZoomAndPan.cpp index 265795da37832..f7669438348b5 100644 --- a/Source/WebCore/svg/SVGZoomAndPan.cpp +++ b/Source/WebCore/svg/SVGZoomAndPan.cpp @@ -40,7 +40,7 @@ template static std::optional parseZo return std::nullopt; } -std::optional SVGZoomAndPan::parseZoomAndPan(StringParsingBuffer& buffer) +std::optional SVGZoomAndPan::parseZoomAndPan(StringParsingBuffer& buffer) { return parseZoomAndPanGeneric(buffer); } diff --git a/Source/WebCore/svg/SVGZoomAndPan.h b/Source/WebCore/svg/SVGZoomAndPan.h index fcd35d0225da5..d989c4746f425 100644 --- a/Source/WebCore/svg/SVGZoomAndPan.h +++ b/Source/WebCore/svg/SVGZoomAndPan.h @@ -48,8 +48,8 @@ class SVGZoomAndPan { protected: SVGZoomAndPan() = default; - static std::optional parseZoomAndPan(StringParsingBuffer&); - static std::optional parseZoomAndPan(StringParsingBuffer&); + static std::optional parseZoomAndPan(StringParsingBuffer&); + static std::optional parseZoomAndPan(StringParsingBuffer&); private: SVGZoomAndPanType m_zoomAndPan { SVGPropertyTraits::initialValue() }; diff --git a/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp b/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp index 9643fb908d215..fd643988ae563 100644 --- a/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp +++ b/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp @@ -1374,7 +1374,7 @@ xmlDocPtr xmlDocPtrForString(CachedResourceLoader& cachedResourceLoader, const S const bool is8Bit = source.is8Bit(); auto characters = is8Bit ? byteCast(source.span8()) : spanReinterpretCast(source.span16()); - size_t sizeInBytes = source.length() * (is8Bit ? sizeof(LChar) : sizeof(UChar)); + size_t sizeInBytes = source.length() * (is8Bit ? sizeof(Latin1Character) : sizeof(char16_t)); const char* encoding = is8Bit ? "iso-8859-1" : nativeEndianUTF16Encoding(); XMLDocumentParserScope scope(&cachedResourceLoader, errorFunc); diff --git a/Source/WebGPU/WGSL/Lexer.cpp b/Source/WebGPU/WGSL/Lexer.cpp index afd43ac2ab916..3acc3b083eacf 100644 --- a/Source/WebGPU/WGSL/Lexer.cpp +++ b/Source/WebGPU/WGSL/Lexer.cpp @@ -61,12 +61,12 @@ static unsigned isIdentifierContinue(UChar character, std::span cod return 0; } -static unsigned isIdentifierStart(LChar character, std::span) +static unsigned isIdentifierStart(Latin1Character character, std::span) { return isASCIIAlpha(character) || character == '_'; } -static unsigned isIdentifierContinue(LChar character, std::span) +static unsigned isIdentifierContinue(Latin1Character character, std::span) { return isASCIIAlphanumeric(character) || character == '_'; } @@ -1052,7 +1052,7 @@ Token Lexer::lexNumber() return convert(result); } -template class Lexer; -template class Lexer; +template class Lexer; +template class Lexer; } diff --git a/Source/WebGPU/WGSL/Lexer.h b/Source/WebGPU/WGSL/Lexer.h index e3896b107fc25..b238667661d15 100644 --- a/Source/WebGPU/WGSL/Lexer.h +++ b/Source/WebGPU/WGSL/Lexer.h @@ -37,10 +37,10 @@ class Lexer { public: Lexer(const String& wgsl) { - if constexpr (std::is_same::value) + if constexpr (std::is_same::value) m_code = wgsl.span8(); else { - static_assert(std::is_same::value, "The lexer expects its template parameter to be either LChar or UChar"); + static_assert(std::is_same::value, "The lexer expects its template parameter to be either Latin1Character or char16_t"); m_code = wgsl.span16(); ASSERT(!(wgsl.sizeInBytes() % 2)); } diff --git a/Source/WebGPU/WGSL/Parser.cpp b/Source/WebGPU/WGSL/Parser.cpp index 70f09ac2cf4ca..1238166ee9ec8 100644 --- a/Source/WebGPU/WGSL/Parser.cpp +++ b/Source/WebGPU/WGSL/Parser.cpp @@ -317,8 +317,8 @@ std::optional parse(ShaderModule& shaderModule) std::optional parse(ShaderModule& shaderModule) { if (shaderModule.source().is8Bit()) - return parse>(shaderModule); - return parse>(shaderModule); + return parse>(shaderModule); + return parse>(shaderModule); } template diff --git a/Source/WebKit/Platform/IPC/ArgumentCoders.cpp b/Source/WebKit/Platform/IPC/ArgumentCoders.cpp index 21bdffb4aa31d..25a9984a5d119 100644 --- a/Source/WebKit/Platform/IPC/ArgumentCoders.cpp +++ b/Source/WebKit/Platform/IPC/ArgumentCoders.cpp @@ -83,8 +83,8 @@ WARN_UNUSED_RETURN std::optional ArgumentCoder::decode(Decoder& return std::nullopt; if (*is8Bit) - return decodeStringText(decoder, *length); - return decodeStringText(decoder, *length); + return decodeStringText(decoder, *length); + return decodeStringText(decoder, *length); } template std::optional ArgumentCoder::decode(Decoder&); diff --git a/Source/WebKit/Platform/IPC/DaemonCoders.h b/Source/WebKit/Platform/IPC/DaemonCoders.h index aafc5324650a3..13979dd36517f 100644 --- a/Source/WebKit/Platform/IPC/DaemonCoders.h +++ b/Source/WebKit/Platform/IPC/DaemonCoders.h @@ -184,8 +184,8 @@ template<> struct Coder { return std::nullopt; if (*is8Bit) - return decodeStringText(decoder, *length); - return decodeStringText(decoder, *length); + return decodeStringText(decoder, *length); + return decodeStringText(decoder, *length); } }; diff --git a/Source/WebKit/WebProcess/glib/WebProcessGLib.cpp b/Source/WebKit/WebProcess/glib/WebProcessGLib.cpp index ff543f944a320..14954238bb668 100644 --- a/Source/WebKit/WebProcess/glib/WebProcessGLib.cpp +++ b/Source/WebKit/WebProcess/glib/WebProcessGLib.cpp @@ -181,7 +181,7 @@ void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& para bool useAcceleratedBuffers = true; #endif - if (const auto enableCPURendering = StringView::fromLatin1(g_getenv("WEBKIT_SKIA_ENABLE_CPU_RENDERING")).trim(isASCIIWhitespace)) + if (const auto enableCPURendering = StringView::fromLatin1(g_getenv("WEBKIT_SKIA_ENABLE_CPU_RENDERING")).trim(isASCIIWhitespace)) useAcceleratedBuffers = (enableCPURendering == "0"_s); ProcessCapabilities::setCanUseAcceleratedBuffers(useAcceleratedBuffers); diff --git a/Tools/Scripts/do-webcore-rename b/Tools/Scripts/do-webcore-rename index 068c440aff340..2479e7dd54e33 100755 --- a/Tools/Scripts/do-webcore-rename +++ b/Tools/Scripts/do-webcore-rename @@ -65,10 +65,15 @@ if (!$getOptionsResult || $showHelp) { my @directoriesToIgnoreList = ( "expected", - "icu", ); my %directoriesToIgnore = map { $_ => 1 } @directoriesToIgnoreList; +my @pathsToIgnoreList = ( + "Source/WTF/icu", + "Source/WebKitLegacy/mac/icu", +); +my %pathsToIgnore = map { $_ => 1 } @pathsToIgnoreList; + # find all files we want to process my @paths; @@ -76,6 +81,7 @@ find(\&wanted, "Source/JavaScriptCore"); find(\&wanted, "Source/WTF"); find(\&wanted, "Source/WebCore"); find(\&wanted, "Source/WebDriver"); +find(\&wanted, "Source/WebGPU"); find(\&wanted, "Source/WebKitLegacy"); find(\&wanted, "Source/WebKit"); find(\&wanted, "Tools/gdb"); @@ -89,6 +95,14 @@ find(\&wanted, "Tools/WebKitTestRunner"); sub wanted { my $file = $_; + my $fullPath = $File::Find::name; + + # Check for specific full paths to ignore + if ($pathsToIgnore{$fullPath}) { + print "Ignoring $fullPath\n" if $verbose; + $File::Find::prune = 1; + return; + } # Ignore excluded and hidden files/directories. if ($directoriesToIgnore{$file} or $file =~ /^\../ or $file =~ /^ChangeLog/) { @@ -107,6 +121,7 @@ sub wanted my $isDOMTypeRename = 0; my %renames = ( # Renames go here in the form of: + "LChar" => "Latin1Character", "RandomNumber.h" => "WeakRandomNumber.h", "RandomNumber.cpp" => "WeakRandomNumber.cpp", ); diff --git a/Tools/TestWebKitAPI/Tests/WGSL/ConstLiteralTests.cpp b/Tools/TestWebKitAPI/Tests/WGSL/ConstLiteralTests.cpp index 2e7422698b276..9245e251d1916 100644 --- a/Tools/TestWebKitAPI/Tests/WGSL/ConstLiteralTests.cpp +++ b/Tools/TestWebKitAPI/Tests/WGSL/ConstLiteralTests.cpp @@ -33,7 +33,7 @@ static Expected, WGSL::Error> parseLCharPrimaryExpression(const String& input) { WGSL::ShaderModule shaderModule(input, { }); - WGSL::Lexer lexer(input); + WGSL::Lexer lexer(input); WGSL::Parser parser(shaderModule, lexer); auto expression = parser.parsePrimaryExpression(); diff --git a/Tools/TestWebKitAPI/Tests/WGSL/LexerTests.cpp b/Tools/TestWebKitAPI/Tests/WGSL/LexerTests.cpp index 55e98d82caeac..cfd94353cab05 100644 --- a/Tools/TestWebKitAPI/Tests/WGSL/LexerTests.cpp +++ b/Tools/TestWebKitAPI/Tests/WGSL/LexerTests.cpp @@ -28,8 +28,8 @@ namespace TestWGSLAPI { -class TestLexer : public WGSL::Lexer { - using Base = WGSL::Lexer; +class TestLexer : public WGSL::Lexer { + using Base = WGSL::Lexer; public: TestLexer(const String& input) diff --git a/Tools/TestWebKitAPI/Tests/WTF/HexNumber.cpp b/Tools/TestWebKitAPI/Tests/WTF/HexNumber.cpp index 5640588b363cd..0b5b77c81bef7 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/HexNumber.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/HexNumber.cpp @@ -36,7 +36,7 @@ namespace TestWebKitAPI { #define expectBuilderContent(expected, builder) \ { \ if (builder.is8Bit()) \ - EXPECT_EQ(String(expected), String(builder.span())); \ + EXPECT_EQ(String(expected), String(builder.span())); \ else \ EXPECT_EQ(String(expected), String(builder.span())); \ } \ diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp index 3adb94b013749..82a2c049c71cd 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp @@ -45,8 +45,8 @@ static String builderContent(const StringBuilder& builder) // Not using builder.toString() or builder.toStringPreserveCapacity() because they all // change internal state of builder. if (builder.is8Bit()) - return builder.span(); - return builder.span(); + return builder.span(); + return builder.span(); } void expectEmpty(const StringBuilder& builder) @@ -69,7 +69,7 @@ TEST(StringBuilderTest, Append) EXPECT_EQ("0123456789"_s, builderContent(builder)); builder.append("abcd"_s); EXPECT_EQ("0123456789abcd"_s, builderContent(builder)); - builder.append(std::span { reinterpret_cast("efgh"), 3 }); + builder.append(std::span { reinterpret_cast("efgh"), 3 }); EXPECT_EQ("0123456789abcdefg"_s, builderContent(builder)); builder.append(""_s); EXPECT_EQ("0123456789abcdefg"_s, builderContent(builder)); @@ -80,15 +80,15 @@ TEST(StringBuilderTest, Append) StringBuilder builder1; builder.append(""_span); EXPECT_EQ("0123456789abcdefg#"_s, builderContent(builder)); - builder1.append(builder.span()); + builder1.append(builder.span()); builder1.append("XYZ"_s); - builder.append(builder1.span()); + builder.append(builder1.span()); EXPECT_EQ("0123456789abcdefg#0123456789abcdefg#XYZ"_s, builderContent(builder)); StringBuilder builder2; builder2.reserveCapacity(100); builder2.append("xyz"_s); - const LChar* characters = builder2.span8().data(); + const Latin1Character* characters = builder2.span8().data(); builder2.append("0123456789"_s); EXPECT_EQ(characters, builder2.span8().data()); builder2.toStringPreserveCapacity(); // Test after reifyString with buffer preserved. @@ -397,7 +397,7 @@ TEST(StringBuilderTest, Equal) StringBuilder builder1; StringBuilder builder2; EXPECT_TRUE(builder1 == builder2); - EXPECT_TRUE(equal(builder1, static_cast(0), 0)); + EXPECT_TRUE(equal(builder1, static_cast(0), 0)); EXPECT_TRUE(builder1 == String()); EXPECT_TRUE(String() == builder1); EXPECT_TRUE(builder1 != String("abc"_s)); diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp index 7d63b2f5cf128..9ff1b49cbe00f 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp @@ -39,7 +39,7 @@ namespace TestWebKitAPI { #if CPU(ARM64) TEST(WTF_StringCommon, Find8NonASCII) { - Vector vector(4096); + Vector vector(4096); vector.fill('a'); EXPECT_FALSE(WTF::find8NonASCII(vector.subspan(0, 4096))); @@ -206,41 +206,41 @@ TEST(WTF_StringCommon, CopyElements32To16) TEST(WTF_StringCommon, CharactersContain8) { { - Vector source; - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); + Vector source; + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); } { - Vector source; + Vector source; for (unsigned i = 0; i < 15; ++i) source.append(i); - EXPECT_TRUE((charactersContain(source.span()))); - EXPECT_TRUE((charactersContain(source.span()))); - EXPECT_TRUE((charactersContain(source.span()))); - EXPECT_TRUE((charactersContain(source.span()))); - EXPECT_TRUE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_TRUE((charactersContain(source.span()))); + EXPECT_TRUE((charactersContain(source.span()))); + EXPECT_TRUE((charactersContain(source.span()))); + EXPECT_TRUE((charactersContain(source.span()))); + EXPECT_TRUE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); } { - Vector source; + Vector source; for (unsigned i = 0; i < 250; ++i) { if (i & 0x1) source.append(i); } - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_TRUE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_TRUE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_TRUE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_TRUE((charactersContain(source.span()))); } } @@ -293,21 +293,21 @@ TEST(WTF_StringCommon, CharactersContain16) if (i & 0x1) source.append(i + 0x1000); } - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_TRUE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); - EXPECT_TRUE((charactersContain(source.span()))); - EXPECT_TRUE((charactersContain(source.span()))); - EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_TRUE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); + EXPECT_TRUE((charactersContain(source.span()))); + EXPECT_TRUE((charactersContain(source.span()))); + EXPECT_FALSE((charactersContain(source.span()))); } } diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringHasher.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringHasher.cpp index 602f0c0465735..e728d3b8dfbb3 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringHasher.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringHasher.cpp @@ -37,7 +37,7 @@ static bool dumpHashingSpeedComparison = false; TEST(WTF, StringHasher) { auto generateLCharArray = [&](size_t size) { - auto array = std::unique_ptr(new LChar[size]); + auto array = std::unique_ptr(new Latin1Character[size]); for (size_t i = 0; i < size; i++) array[i] = i; return array; @@ -53,8 +53,8 @@ TEST(WTF, StringHasher) StringHasher hash; unsigned max8Bit = std::numeric_limits::max(); for (size_t size = 0; size <= max8Bit; size++) { - std::unique_ptr arr1 = generateLCharArray(size); - std::unique_ptr arr2 = generateUCharArray(size); + std::unique_ptr arr1 = generateLCharArray(size); + std::unique_ptr arr2 = generateUCharArray(size); unsigned left = StringHasher::computeHashAndMaskTop8Bits(std::span { arr1.get(), size }); unsigned right = StringHasher::computeHashAndMaskTop8Bits(std::span { arr2.get(), size }); ASSERT_EQ(left, right); @@ -95,15 +95,15 @@ TEST(WTF, StringHasher_SuperFastHash_VS_WYHash) dataLogLn("STH ", size, " -> ", MonotonicTime::now() - start); } - dataLogLn("LChar"); + dataLogLn("Latin1Character"); for (size_t size = 2; size < (1 << 16); size *= 2) { - Vector vector; + Vector vector; vector.resize(size); for (unsigned i = 0; i < size; ++i) vector[i] = i & 0x7f; - sum += SuperFastHash::computeHashAndMaskTop8Bits(std::span { vector.data(), size }); - sum += WYHash::computeHashAndMaskTop8Bits(std::span { vector.data(), size }); - sum += StringHasher::computeHashAndMaskTop8Bits(std::span { vector.data(), size }); + sum += SuperFastHash::computeHashAndMaskTop8Bits(std::span { vector.data(), size }); + sum += WYHash::computeHashAndMaskTop8Bits(std::span { vector.data(), size }); + sum += StringHasher::computeHashAndMaskTop8Bits(std::span { vector.data(), size }); auto start = MonotonicTime::now(); for (unsigned i = 0; i < 1e5; ++i) sum += SuperFastHash::computeHashAndMaskTop8Bits(std::span { vector.data(), size }); diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp index 3c79ec0ede332..7b3568f3e9e9d 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp @@ -753,7 +753,7 @@ TEST(WTF, StaticPrivateSymbolImpl) TEST(WTF, ExternalStringImplCreate8bit) { - constexpr LChar buffer[] = "hello"; + constexpr Latin1Character buffer[] = "hello"; constexpr size_t bufferStringLength = sizeof(buffer) - 1; bool freeFunctionCalled = false; @@ -804,7 +804,7 @@ TEST(WTF, StringImplNotExternal) TEST(WTF, ExternalStringAtom) { - constexpr LChar buffer[] = "hello"; + constexpr Latin1Character buffer[] = "hello"; constexpr size_t bufferStringLength = sizeof(buffer) - 1; bool freeFunctionCalled = false; diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringParsingBuffer.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringParsingBuffer.cpp index b55ae15dd3b11..ca66624b0fd8b 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringParsingBuffer.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringParsingBuffer.cpp @@ -34,7 +34,7 @@ namespace TestWebKitAPI { TEST(WTF, StringParsingBufferEmpty) { - StringParsingBuffer parsingBuffer; + StringParsingBuffer parsingBuffer; EXPECT_TRUE(parsingBuffer.atEnd()); EXPECT_FALSE(parsingBuffer.hasCharactersRemaining()); diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp index 6567dec16b06d..2ea6a6555b45d 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp @@ -323,7 +323,7 @@ TEST(WTF, StringViewEqualBasic) EXPECT_FALSE(a == "Hello World!!"_s); auto test = "Hell\0"; - a = StringView { std::span { (const LChar*)test, 5 } }; + a = StringView { std::span { (const Latin1Character*)test, 5 } }; EXPECT_FALSE(a == "Hell\0"_s); EXPECT_FALSE(a == "Hell"_s); @@ -393,10 +393,10 @@ TEST(WTF, StringViewEqualIgnoringASCIICaseWithEmpty) TEST(WTF, StringViewEqualIgnoringASCIICaseWithLatin1Characters) { - RefPtr a = StringImpl::create(std::span { reinterpret_cast("aBcéeFG"), 7 }); - RefPtr b = StringImpl::create(std::span { reinterpret_cast("ABCÉEFG"), 7 }); - RefPtr c = StringImpl::create(std::span { reinterpret_cast("ABCéEFG"), 7 }); - RefPtr d = StringImpl::create(std::span { reinterpret_cast("abcéefg"), 7 }); + RefPtr a = StringImpl::create(std::span { reinterpret_cast("aBcéeFG"), 7 }); + RefPtr b = StringImpl::create(std::span { reinterpret_cast("ABCÉEFG"), 7 }); + RefPtr c = StringImpl::create(std::span { reinterpret_cast("ABCéEFG"), 7 }); + RefPtr d = StringImpl::create(std::span { reinterpret_cast("abcéefg"), 7 }); StringView stringViewA(*a.get()); StringView stringViewB(*b.get()); StringView stringViewC(*c.get()); @@ -893,8 +893,8 @@ TEST(WTF, StringView8Bit) EXPECT_TRUE(StringView().is8Bit()); EXPECT_TRUE(emptyStringView().is8Bit()); - std::span lcharSpan; - std::span ucharSpan; + std::span lcharSpan; + std::span ucharSpan; EXPECT_TRUE(StringView(lcharSpan).is8Bit()); EXPECT_FALSE(StringView(ucharSpan).is8Bit()); diff --git a/Tools/TestWebKitAPI/Tests/WTF/SuperFastHash.cpp b/Tools/TestWebKitAPI/Tests/WTF/SuperFastHash.cpp index b3c55486312a6..483c7139d57ef 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/SuperFastHash.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/SuperFastHash.cpp @@ -28,15 +28,15 @@ namespace TestWebKitAPI { -static const LChar nullLChars[2] = { 0, 0 }; -static const UChar nullUChars[2] = { 0, 0 }; +static const Latin1Character nullLChars[2] = { 0, 0 }; +static const char16_t nullUChars[2] = { 0, 0 }; static const unsigned emptyStringHash = 0x4EC889EU; static const unsigned singleNullCharacterHash = 0x3D3ABF44U; -static const LChar testALChars[6] = { 0x41, 0x95, 0xFF, 0x50, 0x01, 0 }; -static const UChar testAUChars[6] = { 0x41, 0x95, 0xFF, 0x50, 0x01, 0 }; -static const UChar testBUChars[6] = { 0x41, 0x95, 0xFFFF, 0x1080, 0x01, 0 }; +static const Latin1Character testALChars[6] = { 0x41, 0x95, 0xFF, 0x50, 0x01, 0 }; +static const char16_t testAUChars[6] = { 0x41, 0x95, 0xFF, 0x50, 0x01, 0 }; +static const char16_t testBUChars[6] = { 0x41, 0x95, 0xFFFF, 0x1080, 0x01, 0 }; static const unsigned testAHash1 = 0xEA32B004; static const unsigned testAHash2 = 0x93F0F71E; @@ -112,7 +112,7 @@ TEST(WTF, SuperFastHash_addCharacters) // Hashing zero characters. hasher = SuperFastHash(); - hasher.addCharacters(static_cast(0), 0); + hasher.addCharacters(static_cast(0), 0); ASSERT_EQ(emptyStringHash, hasher.hash()); ASSERT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); hasher = SuperFastHash(); @@ -308,7 +308,7 @@ TEST(WTF, SuperFastHash_addCharactersAssumingAligned) // Hashing zero characters. hasher = SuperFastHash(); - hasher.addCharactersAssumingAligned(static_cast(0), 0); + hasher.addCharactersAssumingAligned(static_cast(0), 0); ASSERT_EQ(emptyStringHash, hasher.hash()); ASSERT_EQ(emptyStringHash & 0xFFFFFF, hasher.hashWithTop8BitsMasked()); hasher = SuperFastHash(); @@ -437,7 +437,7 @@ TEST(WTF, SuperFastHash_computeHash) // Ambiguous constructor call error when calling std::span(T*, 0). // https://bugs.llvm.org/show_bug.cgi?id=49295 static constexpr size_t zeroLength = 0; - ASSERT_EQ(emptyStringHash, SuperFastHash::computeHash(std::span { static_cast(0), zeroLength })); + ASSERT_EQ(emptyStringHash, SuperFastHash::computeHash(std::span { static_cast(0), zeroLength })); ASSERT_EQ(emptyStringHash, SuperFastHash::computeHash(std::span { nullLChars, zeroLength })); ASSERT_EQ(emptyStringHash, SuperFastHash::computeHash(std::span { static_cast(0), zeroLength })); ASSERT_EQ(emptyStringHash, SuperFastHash::computeHash(std::span { nullUChars, zeroLength })); @@ -456,7 +456,7 @@ TEST(WTF, SuperFastHash_computeHashAndMaskTop8Bits) // Ambiguous constructor call error when calling std::span(T*, 0). // https://bugs.llvm.org/show_bug.cgi?id=49295 static constexpr size_t zeroLength = 0; - ASSERT_EQ(emptyStringHash & 0xFFFFFF, SuperFastHash::computeHashAndMaskTop8Bits(std::span { static_cast(0), zeroLength })); + ASSERT_EQ(emptyStringHash & 0xFFFFFF, SuperFastHash::computeHashAndMaskTop8Bits(std::span { static_cast(0), zeroLength })); ASSERT_EQ(emptyStringHash & 0xFFFFFF, SuperFastHash::computeHashAndMaskTop8Bits(std::span { nullLChars, zeroLength })); ASSERT_EQ(emptyStringHash & 0xFFFFFF, SuperFastHash::computeHashAndMaskTop8Bits(std::span { static_cast(0), zeroLength })); ASSERT_EQ(emptyStringHash & 0xFFFFFF, SuperFastHash::computeHashAndMaskTop8Bits(std::span { nullUChars, zeroLength })); diff --git a/Tools/TestWebKitAPI/Tests/WTF/UTF8Conversion.cpp b/Tools/TestWebKitAPI/Tests/WTF/UTF8Conversion.cpp index 4333a24977dcd..f58246454a709 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/UTF8Conversion.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/UTF8Conversion.cpp @@ -46,7 +46,7 @@ template constexpr auto char16Array(ValueTypes... values template constexpr auto latin1Array(ValueTypes... values) { - return std::array { static_cast(values)... }; + return std::array { static_cast(values)... }; } template const char* serialize(const WTF::Unicode::ConversionResult& result) diff --git a/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp b/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp index 46962ca4313e2..af0ce854cedee 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp @@ -352,8 +352,8 @@ TEST(WTF_Vector, CopyFromOtherMinCapacity) TEST(WTF_Vector, ConstructorOtherRawPointerTypeAndLength) { - const UChar uchars[] = { 'b', 'a', 'r' }; - Vector vector(std::span(uchars, static_cast(3))); + const char16_t uchars[] = { 'b', 'a', 'r' }; + Vector vector(std::span(uchars, static_cast(3))); EXPECT_EQ(vector.size(), 3U); EXPECT_EQ(vector[0], 'b'); EXPECT_EQ(vector[1], 'a'); diff --git a/Tools/TestWebKitAPI/Tests/WTF/WYHash.cpp b/Tools/TestWebKitAPI/Tests/WTF/WYHash.cpp index 8051c6314456c..dbc2d28065f6b 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/WYHash.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/WYHash.cpp @@ -54,7 +54,7 @@ static const unsigned expected[256] = { TEST(WTF, WYHasher) { auto generateLCharArray = [&](size_t size) { - auto array = std::unique_ptr(new LChar[size]); + auto array = std::unique_ptr(new Latin1Character[size]); for (size_t i = 0; i < size; i++) array[i] = i; return array; @@ -69,8 +69,8 @@ TEST(WTF, WYHasher) unsigned max8Bit = std::numeric_limits::max(); for (size_t size = 0; size <= max8Bit; size++) { - std::unique_ptr arr1 = generateLCharArray(size); - std::unique_ptr arr2 = generateUCharArray(size); + std::unique_ptr arr1 = generateLCharArray(size); + std::unique_ptr arr2 = generateUCharArray(size); unsigned left = WYHash::computeHashAndMaskTop8Bits(std::span { arr1.get(), size }); unsigned right = WYHash::computeHashAndMaskTop8Bits(std::span { arr2.get(), size }); ASSERT_EQ(left, right); diff --git a/Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm b/Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm index f4a11d465d8f3..8699302796574 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm +++ b/Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm @@ -306,7 +306,7 @@ EXPECT_FALSE(url3.isValid()); EXPECT_STREQ([[url3 absoluteString] UTF8String], "%C3%82%C2%B6"); - std::array latin1 { 0xC2, 0xB6 }; + std::array latin1 { 0xC2, 0xB6 }; WTF::URL url4 { String(latin1) }; EXPECT_FALSE(url4.isValid()); EXPECT_TRUE(url4.string().is8Bit()); diff --git a/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp b/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp index 12d06586865e7..6e5bf6f5d04cb 100644 --- a/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp +++ b/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp @@ -421,7 +421,7 @@ TEST_F(SharedBufferChunkReaderTest, includeSeparator) check(builder.take()); for (size_t i = 0; i < 256; ++i) { - LChar c = i; + Latin1Character c = i; builder.append(std::span { &c, 1 }); } check(builder.take()); diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm index aa4c63ac0a6e9..4e92d31d5aa51 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm @@ -1176,9 +1176,9 @@ HTTPServer server([receivedFirstConnection = false] (Connection connection) muta } template -String longString(LChar c) +String longString(Latin1Character c) { - Vector vector(length, c); + Vector vector(length, c); return vector.span(); } diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIWebNavigation.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIWebNavigation.mm index 3602ee5b0ff7e..41eb8119d11c7 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIWebNavigation.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIWebNavigation.mm @@ -266,9 +266,9 @@ } template -String longString(LChar c) +String longString(Latin1Character c) { - Vector vector(length, c); + Vector vector(length, c); return vector.span(); } diff --git a/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp b/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp index aed7e2e7f177c..26885f8f1dffc 100644 --- a/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp +++ b/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp @@ -80,11 +80,11 @@ inline StringTypeAdapter::StringTypeAdapter(WKStringRef string) { } -template<> inline void StringTypeAdapter::writeTo(LChar*) const +template<> inline void StringTypeAdapter::writeTo(std::span) const { } -template<> inline void StringTypeAdapter::writeTo(UChar* destination) const +template<> inline void StringTypeAdapter::writeTo(char16_t* destination) const { if (m_string) WKStringGetCharacters(m_string, reinterpret_cast(destination), WKStringGetLength(m_string)); diff --git a/Tools/gdb/webkit.py b/Tools/gdb/webkit.py index cbea8e228bad1..3c8620648048a 100644 --- a/Tools/gdb/webkit.py +++ b/Tools/gdb/webkit.py @@ -72,7 +72,7 @@ def ustring_to_string(ptr, length=None): def lstring_to_string(ptr, length=None): - """Convert a pointer to LChar* data into a Python (non-Unicode) string. + """Convert a pointer to Latin1Character* data into a Python (non-Unicode) string. ptr and length are both gdb.Value objects. If length is unspecified, will guess at the length.""" @@ -101,7 +101,7 @@ def to_string(self): class LCharStringPrinter(StringPrinter): - "Print a LChar*; we must guess at the length" + "Print a Latin1Character*; we must guess at the length" def to_string(self): return lstring_to_string(self.val) @@ -325,7 +325,7 @@ def lookup_function(val): name = str(type.target().unqualified()) if name == 'UChar': return UCharStringPrinter(val) - if name == 'LChar': + if name == 'Latin1Character': return LCharStringPrinter(val) return None From 2660dd4303702682c37ec4426749892271a1c790 Mon Sep 17 00:00:00 2001 From: Darin Adler Date: Sat, 27 Sep 2025 20:45:04 -0700 Subject: [PATCH 11/22] Simplify some character-related code to ease future changes to Latin1Character https://bugs.webkit.org/show_bug.cgi?id=299671 rdar://161487282 Reviewed by Sam Weinig. * Source/JavaScriptCore/heap/HeapSnapshotBuilder.cpp: (JSC::edgeTypeToNumber): Deleted. (JSC::HeapSnapshotBuilder::json): Remove call to edgeTypeToNumber function so we can serialize the edge type enumeration as a number. It's not needed because serialization done by StringBuilder::append already serializes enumerations as their underlying= numeric values. * Source/WTF/wtf/HexNumber.cpp: (WTF::Internal::hexDigitsForMode): Moved this function out of the header since it's only used in this file. * Source/WTF/wtf/HexNumber.h: (WTF::Internal::hexDigitsForMode): Deleted. * Source/WebCore/Modules/url-pattern/URLPatternParser.cpp: (WebCore::URLPatternUtilities::escapeRegexStringForCharacters): Use an array of CharacterType rather than an array of char. (WebCore::URLPatternUtilities::escapePatternStringForCharacters): Ditto. Canonical link: https://commits.webkit.org/300658@main Signed-off-by: Xabier Rodriguez Calvar --- Source/JavaScriptCore/heap/HeapSnapshotBuilder.cpp | 7 +------ Source/WTF/wtf/HexNumber.cpp | 7 +++++++ Source/WTF/wtf/HexNumber.h | 7 ------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Source/JavaScriptCore/heap/HeapSnapshotBuilder.cpp b/Source/JavaScriptCore/heap/HeapSnapshotBuilder.cpp index c1901978968f7..0af51f64f7959 100644 --- a/Source/JavaScriptCore/heap/HeapSnapshotBuilder.cpp +++ b/Source/JavaScriptCore/heap/HeapSnapshotBuilder.cpp @@ -351,11 +351,6 @@ enum class NodeFlags { ObjectSubtype = 1 << 1, }; -static uint8_t edgeTypeToNumber(EdgeType type) -{ - return static_cast(type); -} - static ASCIILiteral edgeTypeToString(EdgeType type) { switch (type) { @@ -530,7 +525,7 @@ void HeapSnapshotBuilder::writeJson(Function&& a firstEdge = false; // , , , - json.append(edge.from.identifier, ',', edge.to.identifier, ',', edgeTypeToNumber(edge.type), ','); + json.append(edge.from.identifier, ',', edge.to.identifier, ',', edge.type, ','); switch (edge.type) { case EdgeType::Property: case EdgeType::Variable: { diff --git a/Source/WTF/wtf/HexNumber.cpp b/Source/WTF/wtf/HexNumber.cpp index 8daf9f8513c13..80d9d05ff288b 100644 --- a/Source/WTF/wtf/HexNumber.cpp +++ b/Source/WTF/wtf/HexNumber.cpp @@ -27,6 +27,13 @@ namespace WTF { namespace Internal { +static const Latin1Character* hexDigitsForMode(HexConversionMode mode) +{ + static const Latin1Character lowercaseHexDigits[17] = "0123456789abcdef"; + static const Latin1Character uppercaseHexDigits[17] = "0123456789ABCDEF"; + return mode == Lowercase ? lowercaseHexDigits : uppercaseHexDigits; +} + std::pair appendHex(Latin1Character* buffer, unsigned bufferSize, std::uintmax_t number, unsigned minimumDigits, HexConversionMode mode) { auto end = buffer + bufferSize; diff --git a/Source/WTF/wtf/HexNumber.h b/Source/WTF/wtf/HexNumber.h index f2cb9253c77d6..8e95629bfe3ec 100644 --- a/Source/WTF/wtf/HexNumber.h +++ b/Source/WTF/wtf/HexNumber.h @@ -29,13 +29,6 @@ enum HexConversionMode { Lowercase, Uppercase }; namespace Internal { -inline const Latin1Character* hexDigitsForMode(HexConversionMode mode) -{ - static const Latin1Character lowercaseHexDigits[17] = "0123456789abcdef"; - static const Latin1Character uppercaseHexDigits[17] = "0123456789ABCDEF"; - return mode == Lowercase ? lowercaseHexDigits : uppercaseHexDigits; -} - WTF_EXPORT_PRIVATE std::pair appendHex(Latin1Character* buffer, unsigned bufferSize, std::uintmax_t number, unsigned minimumDigits, HexConversionMode); template From 3a5bd784335d8830dd5766f3154b96a3e2fbfcae Mon Sep 17 00:00:00 2001 From: Darin Adler Date: Sun, 5 Oct 2025 15:05:39 -0700 Subject: [PATCH 12/22] Add casts that will be needed once Latin1Character is a distinct type rdar://161524685 https://bugs.webkit.org/show_bug.cgi?id=299706 Reviewed by Geoffrey Garen. * Source/JavaScriptCore/API/JSScript.mm: (+[JSScript scriptOfType:memoryMappedFromASCIIFile:withSourceURL:andBytecodeCache:inVirtualMachine:error:]): Cast to Latin1Character. * Source/JavaScriptCore/API/JSStringRefCF.cpp: (JSStringCreateWithCFString): Cast to UInt8. (JSStringCopyCFString): Ditto. * Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.cpp: (Inspector::RemoteInspector::backendCommands const): Eliminate use of String::adopt. It doesn't really work for vectors any more, and likely we should remove it to avoid making a promise we can't keep. It doesn't work with byteCast, which is why we need to do this here now. * Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototype.cpp: (JSC::uint8ArrayPrototypeToHex): Cast to uint8_t. * Source/JavaScriptCore/runtime/LiteralParser.cpp: (JSC::reviverMode>::Lexer::lexString): Reduce mixing char with Latin1Character a bit. * Source/WTF/wtf/URLParser.cpp: (WTF::URLParser::appendNumberToASCIIBuffer): Cast to char. * Source/WTF/wtf/cf/CFURLExtras.cpp: (WTF::bytesAsString): Cast to UInt8. (WTF::isSameOrigin): Cast to Latin1Character. * Source/WTF/wtf/cf/URLCF.cpp: (WTF::URL::createCFURL): Cast to UInt8. * Source/WTF/wtf/cocoa/NSURLExtras.mm: (WTF::userVisibleString): Cast to Latin1Character. * Source/WTF/wtf/persistence/PersistentCoders.cpp: (WTF::Persistence::Coder::encodeForPersistence): Use asBytes. * Source/WTF/wtf/text/StringBuilder.h: (WTF::StringBuilder::operator[] const): Cast so the conditional operator does not mix types. * Source/WTF/wtf/text/WTFString.cpp: (WTF::String::String): Cast to Latin1Character. (WTF::String::ascii const): Cast so the conditional operator does not mix types. * Source/WTF/wtf/text/cf/StringCF.cpp: (WTF::String::String): Cast to UInt8. * Source/WTF/wtf/text/cf/StringImplCF.cpp: (WTF::StringImpl::createCFString): Ditto. * Source/WTF/wtf/text/cf/StringViewCF.cpp: (WTF::StringView::createCFString const): Ditto. (WTF::StringView::createCFStringWithoutCopying const): Ditto. * Source/WebCore/Modules/encryptedmedia/InitDataRegistry.cpp: (WebCore::extractKeyIDsKeyids): Cast to Latin1Character to pass to parseJSON and remove the unnecessary copy into a temporary String. * Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp: (WebCore::PeerConnectionBackend::handleLogMessage): Cast to uint8_t. * Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp: (WebCore::RTCRtpSFrameTransformer::computeSaltKey): Ditto. (WebCore::createBaseSFrameKey): Ditto. (WebCore::RTCRtpSFrameTransformer::computeAuthenticationKey): Ditto. (WebCore::RTCRtpSFrameTransformer::computeEncryptionKey): Ditto. * Source/WebCore/Modules/mediastream/gstreamer/GStreamerDtlsTransportBackend.cpp: (WebCore::GStreamerDtlsTransportBackendObserver::stateChanged): Ditto. * Source/WebCore/Modules/push-api/PushMessageCrypto.cpp: (WebCore::PushCrypto::decryptAES128GCMPayload): Ditto. (WebCore::PushCrypto::decryptAESGCMPayload): Ditto. * Source/WebCore/Modules/websockets/WebSocketHandshake.cpp: (WebCore::trimInputSample): Cast to Latin1Character. (WebCore::WebSocketHandshake::readStatusLine): Ditto. * Source/WebCore/bindings/js/ScriptBufferSourceProvider.h: Cast to Latin1Character. * Source/WebCore/bindings/js/SerializedScriptValue.cpp: (WebCore::CloneDeserializer::readString): Ditto. * Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp: (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretJumpTable): Cast so the conditional operator does not mix types. (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret): Ditto. * Source/WebCore/crypto/SubtleCrypto.cpp: (WebCore::SubtleCrypto::unwrapKey): Cast to Latin1Character to pass to JSONParse and remove the unnecessary copy into a temporary String. * Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm: (WebCore::replaceRichContentWithAttachments): Cast to Latin1Character. * Source/WebCore/fileapi/FileReaderLoader.cpp: (WebCore::FileReaderLoader::stringResult): Ditto. * Source/WebCore/html/FTPDirectoryDocument.cpp: (WebCore::FTPDirectoryDocumentParser::loadDocumentTemplate): Ditto. * Source/WebCore/html/parser/HTMLEntityParser.cpp: (WebCore::StringParsingBufferSource::currentCharacter const): Cast so the conditional operator does not mix types. * Source/WebCore/html/track/VTTScanner.h: (WebCore::VTTScanner::currentChar const): Ditto. * Source/WebCore/html/track/WebVTTParser.cpp: (WebCore::WebVTTParser::fileFinished): Cast to uint8_t. * Source/WebCore/loader/FTPDirectoryParser.cpp: (WebCore::parseOneFTPLine): Cast to Latin1Character. * Source/WebCore/loader/FormSubmission.cpp: (WebCore::appendMailtoPostFormDataToURL): Cast to Latin1Character. (WebCore::FormSubmission::create): Ditto. * Source/WebCore/loader/TextResourceDecoder.cpp: (WebCore::findXMLEncoding): Cast to uint8_t. (WebCore::TextResourceDecoder::checkForCSSCharset): Cast to uint8_t and Latin1Character. (WebCore::TextResourceDecoder::checkForHeadCharset): Ditto. * Source/WebCore/loader/cache/CachedScript.cpp: (WebCore::CachedScript::script): Cast to Latin1Character. (WebCore::CachedScript::codeBlockHashConcurrently): Ditto. * Source/WebCore/platform/encryptedmedia/CDMUtilities.cpp: (WebCore::CDMUtilities::parseJSONObject): Cast to Latin1Character to pass to parseJSON and remove the unnecessary copy into a temporary String. * Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp: (WebCore::extractSinfData): Ditto. (WebCore::CDMPrivateFairPlayStreaming::extractKeyIDsMpts): Ditto. * Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm: (WebCore::parseJSONValue): Cast to Latin1Character. * Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp: (WebCore::fontNameMapName): Ditto. * Source/WebCore/platform/graphics/gstreamer/eme/CDMThunder.cpp: (WebCore::ParsedResponseMessage::ParsedResponseMessage): Cast to Latin1Character. (WebCore::CDMInstanceSessionThunder::loadSession): Ditto. * Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp: (WebCore::MermaidBuilder::span const): Cast to uint8_t. * Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp: (WebCore::decodingWarning): Cast to char. (WebCore::PNGImageDecoder::readChunks): Ditto. * Source/WebCore/platform/mediarecorder/MediaRecorderPrivateMock.cpp: (WebCore::MediaRecorderPrivateMock::fetchData): Cast to uint8_t. * Source/WebCore/platform/network/curl/OpenSSLHelper.cpp: (OpenSSL::BIO::getDataAsString const): Cast to Latin1Character. (OpenSSL::toString): Ditto. * Source/WebCore/platform/network/soup/CertificateInfoSoup.cpp: (WebCore::CertificateInfo::summary const): Ditto. * Source/WebCore/platform/text/SegmentedString.h: (WebCore::SegmentedString::Substring::currentCharacter const): Cast so the conditional operator does not mix types. * Source/WebCore/testing/MockCDMFactory.cpp: (WebCore::MockCDM::sanitizeResponse const): Cast to Latin1Character. (WebCore::MockCDMInstance::setServerCertificate): Ditto. (WebCore::MockCDMInstanceSession::updateLicense): Ditto. * Source/WebGPU/WebGPU/Pipeline.mm: (WebKit::printToFileForPsoRepro): Cast to uint8_t. * Source/WebKit/NetworkProcess/cache/NetworkCache.cpp: (WebKit::NetworkCache::Cache::dumpContentsToFile): Ditto. * Source/WebKit/NetworkProcess/storage/CacheStorageManager.cpp: (WebKit::readSizeFile): Cast to Latin1Character. * Source/WebKit/Platform/IPC/DaemonCoders.h: (WebKit::Daemon::Coder::encode): Cast to uint8_t. * Source/WebKit/Shared/API/c/cf/WKStringCF.mm: (WKStringCopyCFString): Cast to UInt8. * Source/WebKit/Shared/Cocoa/SandboxExtensionCocoa.mm: (WebKit::SandboxExtensionImpl::SandboxExtensionImpl): Cast to Latin1Character. * Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp: (API::getContentRuleListSourceFromMappedFile): Cast to Latin1Character. * Source/WebKit/UIProcess/API/C/WKPage.cpp: (dataFrom): Cast to uint8_t. * Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm: (WebKit::WebPasteboardProxy::testIPCSharedMemory): Cast to Latin1Character. * Source/WebKit/UIProcess/Extensions/WebExtensionDeclarativeNetRequestSQLiteStore.cpp: (WebKit::WebExtensionDeclarativeNetRequestSQLiteStore::getKeysAndValuesFromRowIterator): Ditto. * Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp: (WebKit::RemoteInspectorClient::setBackendCommands): Cast to std::byte. * Source/WebKit/UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm: (WebKit::RemoteWebInspectorUIProxy::platformLoad): Cast to Latin1Character. * Source/WebKit/UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm: (WebKit::WebInspectorUIProxy::platformLoad): Ditto. * Source/WebKit/UIProcess/wpe/WebPasteboardProxyWPE.cpp: (WebKit::WebPasteboardProxy::readURLFromPasteboard): Ditto. * Source/WebKit/WebProcess/Network/webrtc/RTCDataChannelRemoteManager.cpp: (WebKit::RTCDataChannelRemoteManager::sendData): Ditto. * Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::registerLogClient): Cast to uint8_t. * Tools/TestWebKitAPI/Tests/WTF/Base64.cpp: (TestWebKitAPI::TEST(Base64, Encode)): Cast to uint8_t. (TestWebKitAPI::TEST(Base64, EncodeOmitPadding)): Ditto. (TestWebKitAPI::TEST(Base64, EncodeURL)): Ditto. (TestWebKitAPI::TEST(Base64, EncodeURLOmitPadding)): Ditto. * Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp: (TestWebKitAPI::createTestFile): Ditto. (TestWebKitAPI::TEST_F(FileSystemTest, openExistingFileTruncate)): Ditto. (TestWebKitAPI::TEST_F(FileSystemTest, openExistingFileReadWrite)): Ditto. (TestWebKitAPI::TEST_F(FileSystemTest, deleteEmptyDirectoryContainingDSStoreFile)): Ditto. (TestWebKitAPI::TEST_F(FileSystemTest, deleteEmptyDirectoryOnNonEmptyDirectory)): Ditto. (TestWebKitAPI::TEST_F(FileSystemTest, moveDirectory)): Ditto. (TestWebKitAPI::runGetFileModificationTimeTest): Ditto. (TestWebKitAPI::TEST_F(FileSystemTest, readEntireFile)): Ditto. * Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp: (TestWebKitAPI::TEST(WTF, ExternalStringImplCreate8bit)): Use char and cast to Latin1Character. (TestWebKitAPI::TEST(WTF, ExternalStringAtom)): Ditto. * Tools/TestWebKitAPI/Tests/WTF/StringView.cpp: (TestWebKitAPI::TEST(WTF, StringViewEqualIgnoringASCIICaseWithLatin1Characters)): Use byteCast instead of reinterpret_cast. * Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm: (TestWebKitAPI::dataAsString): Pass a character instead of an int. * Tools/TestWebKitAPI/Tests/WebCore/PushMessageCrypto.cpp: (TestWebKitAPI::mustBase64URLDecode): Use ASCIILiteral. (TestWebKitAPI::stringView): Added. (TestWebKitAPI::TEST(PushMessageCrypto, AES128GCMPayloadWithMinimalPadding)): Use stringView. (TestWebKitAPI::TEST(PushMessageCrypto, AES128GCMPayloadWithPadding)): Ditto. (TestWebKitAPI::TEST(PushMessageCrypto, AESGCMPayloadWithMinimalPadding)): Ditto. (TestWebKitAPI::TEST(PushMessageCrypto, AESGCMPayloadWithPadding)): Ditto. * Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp: (TestWebKitAPI::TEST_F(FragmentedSharedBufferTest, createWithContentsOfExistingFile)): Cast to Latin1Character. (TestWebKitAPI::TEST_F(FragmentedSharedBufferTest, read)): Ditto. (TestWebKitAPI::TEST_F(SharedBufferChunkReaderTest, includeSeparator)): Use uint8_t. (TestWebKitAPI::TEST_F(SharedBufferChunkReaderTest, peekData)): Cast to Latin1Character. * Tools/TestWebKitAPI/Tests/WebCore/SharedBufferTest.cpp: (TestWebKitAPI::FragmentedSharedBufferTest::SetUp): Cast to uint8_t. * Tools/TestWebKitAPI/Tests/WebCore/curl/CurlMultipartHandleTests.cpp: (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, SimpleMessage)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, NoHeader)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, NoBody)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, TransportPadding)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, NoEndOfBoundary)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, NoEndOfBoundaryAfterCompleted)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, NoCloseDelimiter)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, NoCloseDelimiterAfterCompleted)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, CloseDelimiter)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, CloseDelimiterAfterCompleted)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, DivideFirstDelimiter)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, DivideSecondDelimiter)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, DivideLastDelimiter)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, DivideCloseDelimiter)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, DivideTransportPadding)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, DivideHeader)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, DivideBody)): Ditto. (TestWebKitAPI::Curl::TEST(CurlMultipartHandleTests, CompleteWhileHeaderProcessing)): Ditto. * Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBPersistence.mm: (-[IndexedDBOpenPanelUIDelegate webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:]): Ditto. * Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm: (TestWebKitAPI::WebPushDTestWebView::injectPushMessage): Cast to Latin1Character. Canonical link: https://commits.webkit.org/301031@main Signed-off-by: Xabier Rodriguez Calvar --- Source/JavaScriptCore/API/JSScript.mm | 2 +- Source/JavaScriptCore/API/JSStringRefCF.cpp | 4 +- .../remote/socket/RemoteInspectorSocket.cpp | 2 +- .../JSGenericTypedArrayViewPrototype.cpp | 6 +- .../JavaScriptCore/runtime/LiteralParser.cpp | 6 +- Source/WTF/wtf/cf/CFURLExtras.cpp | 4 +- Source/WTF/wtf/cocoa/NSURLExtras.mm | 2 +- .../WTF/wtf/persistence/PersistentCoders.cpp | 2 +- Source/WTF/wtf/text/StringBuilder.h | 3 +- Source/WTF/wtf/text/WTFString.cpp | 7 ++- Source/WTF/wtf/text/cf/StringCF.cpp | 2 +- Source/WTF/wtf/text/cf/StringImplCF.cpp | 4 +- Source/WTF/wtf/text/cf/StringViewCF.cpp | 4 +- .../encryptedmedia/InitDataRegistry.cpp | 4 +- .../mediastream/PeerConnectionBackend.cpp | 2 +- .../RTCRtpSFrameTransformerCocoa.cpp | 8 +-- .../GStreamerDtlsTransportBackend.cpp | 5 +- .../Modules/push-api/PushMessageCrypto.cpp | 6 +- .../Modules/websockets/WebSocketHandshake.cpp | 17 +++--- .../bindings/js/ScriptBufferSourceProvider.h | 2 +- .../DFABytecodeInterpreter.cpp | 10 ++-- Source/WebCore/crypto/SubtleCrypto.cpp | 3 +- .../editing/cocoa/WebContentReaderCocoa.mm | 2 +- Source/WebCore/fileapi/FileReaderLoader.cpp | 2 +- Source/WebCore/html/FTPDirectoryDocument.cpp | 2 +- .../WebCore/html/parser/HTMLEntityParser.cpp | 2 +- Source/WebCore/html/track/VTTScanner.h | 2 +- Source/WebCore/html/track/WebVTTParser.cpp | 2 +- Source/WebCore/loader/FormSubmission.cpp | 4 +- Source/WebCore/loader/TextResourceDecoder.cpp | 2 +- Source/WebCore/loader/cache/CachedScript.cpp | 2 +- .../platform/encryptedmedia/CDMUtilities.cpp | 8 +-- .../avfoundation/CDMFairPlayStreaming.cpp | 6 +- .../CDMInstanceFairPlayStreamingAVFObjC.mm | 2 +- .../graphics/freetype/FontCacheFreeType.cpp | 2 +- .../graphics/gstreamer/eme/CDMThunder.cpp | 4 +- .../gstreamer/GStreamerElementHarness.cpp | 2 +- .../MediaRecorderPrivateMock.cpp | 3 +- .../platform/network/curl/OpenSSLHelper.cpp | 4 +- .../WebCore/platform/text/SegmentedString.h | 2 +- Source/WebCore/testing/MockCDMFactory.cpp | 6 +- .../NetworkProcess/cache/NetworkCache.cpp | 2 +- .../storage/CacheStorageManager.cpp | 2 +- Source/WebKit/Platform/IPC/DaemonCoders.h | 2 +- Source/WebKit/Shared/API/c/cf/WKStringCF.mm | 2 +- .../UIProcess/API/APIContentRuleListStore.cpp | 2 +- Source/WebKit/UIProcess/API/C/WKPage.cpp | 4 +- .../Cocoa/WebPasteboardProxyCocoa.mm | 2 +- .../Inspector/glib/RemoteInspectorClient.cpp | 2 +- .../mac/RemoteWebInspectorUIProxyMac.mm | 2 +- .../Inspector/mac/WebInspectorUIProxyMac.mm | 2 +- .../webrtc/RTCDataChannelRemoteManager.cpp | 2 +- Tools/TestWebKitAPI/Tests/WTF/Base64.cpp | 56 +++++++++---------- Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp | 24 ++++---- Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp | 12 ++-- Tools/TestWebKitAPI/Tests/WTF/StringView.cpp | 8 +-- .../Tests/WebCore/PushMessageCrypto.cpp | 22 +++++--- .../Tests/WebCore/SharedBuffer.cpp | 14 ++--- .../Tests/WebCore/SharedBufferTest.cpp | 2 +- .../WebCore/curl/CurlMultipartHandleTests.cpp | 56 +++++++++---------- .../Tests/WebKitCocoa/WebPushDaemon.mm | 2 +- 61 files changed, 190 insertions(+), 194 deletions(-) diff --git a/Source/JavaScriptCore/API/JSScript.mm b/Source/JavaScriptCore/API/JSScript.mm index 03f595b3ed4ef..fa17449412aa5 100644 --- a/Source/JavaScriptCore/API/JSScript.mm +++ b/Source/JavaScriptCore/API/JSScript.mm @@ -146,7 +146,7 @@ + (instancetype)scriptOfType:(JSScriptType)type memoryMappedFromASCIIFile:(NSURL auto result = adoptNS([[JSScript alloc] init]); result->m_virtualMachine = vm; result->m_type = type; - result->m_source = String(StringImpl::createWithoutCopying(fileData.span())); + result->m_source = StringImpl::createWithoutCopying(byteCast(fileData.span())); result->m_mappedSource = WTFMove(fileData); result->m_sourceURL = sourceURL; result->m_cachePath = cachePath; diff --git a/Source/JavaScriptCore/API/JSStringRefCF.cpp b/Source/JavaScriptCore/API/JSStringRefCF.cpp index 156202a0d6a9a..e16b3e843d7a2 100644 --- a/Source/JavaScriptCore/API/JSStringRefCF.cpp +++ b/Source/JavaScriptCore/API/JSStringRefCF.cpp @@ -47,7 +47,7 @@ JSStringRef JSStringCreateWithCFString(CFStringRef string) Vector lcharBuffer(length); CFIndex usedBufferLength; - CFIndex convertedSize = CFStringGetBytes(string, CFRangeMake(0, length), kCFStringEncodingISOLatin1, 0, false, lcharBuffer.data(), length, &usedBufferLength); + CFIndex convertedSize = CFStringGetBytes(string, CFRangeMake(0, length), kCFStringEncodingISOLatin1, 0, false, byteCast(lcharBuffer.data()), length, &usedBufferLength); if (static_cast(convertedSize) == length && static_cast(usedBufferLength) == length) return &OpaqueJSString::create(lcharBuffer.span()).leakRef(); @@ -64,7 +64,7 @@ CFStringRef JSStringCopyCFString(CFAllocatorRef allocator, JSStringRef string) if (string->is8Bit()) { auto characters = string->span8(); - return CFStringCreateWithBytes(allocator, characters.data(), characters.size(), kCFStringEncodingISOLatin1, false); + return CFStringCreateWithBytes(allocator, byteCast(characters.data()), characters.size(), kCFStringEncodingISOLatin1, false); } auto characters = string->span16(); return CFStringCreateWithCharacters(allocator, reinterpret_cast(characters.data()), characters.size()); diff --git a/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.cpp b/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.cpp index d7c5b88573fd1..da3fc0c052bd1 100644 --- a/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.cpp +++ b/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.cpp @@ -262,7 +262,7 @@ String RemoteInspector::backendCommands() const auto contents = FileSystem::readEntireFile(m_backendCommandsPath); - return contents ? String::adopt(WTFMove(*contents)) : emptyString(); + return contents ? String { byteCast(contents->span()) } : emptyString(); } // RemoteInspectorConnectionClient handlers diff --git a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototype.cpp b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototype.cpp index b6f526ac03183..042161661de6b 100644 --- a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototype.cpp +++ b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototype.cpp @@ -233,7 +233,6 @@ JSC_DEFINE_HOST_FUNCTION(uint8ArrayPrototypeToHex, (JSGlobalObject* globalObject std::span buffer; auto result = StringImpl::createUninitialized(length * 2, buffer); - Latin1Character* bufferEnd = std::to_address(buffer.end()); constexpr size_t stride = 8; // Because loading uint8x8_t. if (length >= stride) { auto encodeVector = [&](auto input) { @@ -259,11 +258,10 @@ JSC_DEFINE_HOST_FUNCTION(uint8ArrayPrototypeToHex, (JSGlobalObject* globalObject }; const auto* cursor = data; - auto* output = buffer.data(); - for (; cursor + stride <= end; cursor += stride, output += stride * 2) + for (auto* output = byteCast(buffer.data()); cursor + stride <= end; cursor += stride, output += stride * 2) simde_vst1q_u8(output, encodeVector(simde_vld1_u8(cursor))); if (cursor < end) - simde_vst1q_u8(bufferEnd - stride * 2, encodeVector(simde_vld1_u8(end - stride))); + simde_vst1q_u8(byteCast(std::to_address(buffer.end())) - stride * 2, encodeVector(simde_vld1_u8(end - stride))); } else { const auto* cursor = data; auto* output = buffer.data(); diff --git a/Source/JavaScriptCore/runtime/LiteralParser.cpp b/Source/JavaScriptCore/runtime/LiteralParser.cpp index 15298a51b0568..54a4844209c85 100644 --- a/Source/JavaScriptCore/runtime/LiteralParser.cpp +++ b/Source/JavaScriptCore/runtime/LiteralParser.cpp @@ -911,7 +911,7 @@ ALWAYS_INLINE TokenType LiteralParser::Lexer::lexString(L if (m_mode == StrictJSON) { ASSERT(terminator == '"'); if constexpr (hint == JSONIdentifierHint::MaybeIdentifier) { - while (m_ptr < m_end && isSafeStringCharacterForIdentifier(*m_ptr, '"')) + while (m_ptr < m_end && isSafeStringCharacterForIdentifier(*m_ptr, terminator)) ++m_ptr; } else { using UnsignedType = std::make_unsigned_t; @@ -926,8 +926,8 @@ ALWAYS_INLINE TokenType LiteralParser::Lexer::lexString(L return SIMD::findFirstNonZeroIndex(mask); }; - auto scalarMatch = [&](auto character) ALWAYS_INLINE_LAMBDA { - return !isSafeStringCharacter(character, '"'); + auto scalarMatch = [&](CharType character) ALWAYS_INLINE_LAMBDA { + return !isSafeStringCharacter(character, terminator); }; m_ptr = SIMD::find(std::span { m_ptr, m_end }, vectorMatch, scalarMatch); diff --git a/Source/WTF/wtf/cf/CFURLExtras.cpp b/Source/WTF/wtf/cf/CFURLExtras.cpp index 686c2dd031f94..b9cd0896af2ef 100644 --- a/Source/WTF/wtf/cf/CFURLExtras.cpp +++ b/Source/WTF/wtf/cf/CFURLExtras.cpp @@ -56,7 +56,7 @@ String bytesAsString(CFURLRef url) RELEASE_ASSERT(bytesLength <= static_cast(String::MaxLength)); Latin1Character* buffer; auto result = String::createUninitialized(bytesLength, buffer); - CFURLGetBytes(url, buffer, bytesLength); + CFURLGetBytes(url, byteCast(buffer()), bytesLength); return result; } @@ -90,7 +90,7 @@ bool isSameOrigin(CFURLRef a, const URL& b) auto aBytes = bytesAsVector(a); RELEASE_ASSERT(aBytes.size() <= String::MaxLength); - StringView aString { aBytes.span() }; + StringView aString { byteCast(aBytes.span()) }; StringView bString { b.string() }; if (!b.hasPath()) diff --git a/Source/WTF/wtf/cocoa/NSURLExtras.mm b/Source/WTF/wtf/cocoa/NSURLExtras.mm index 9388cc947b9fa..893c9dcfce4c5 100644 --- a/Source/WTF/wtf/cocoa/NSURLExtras.mm +++ b/Source/WTF/wtf/cocoa/NSURLExtras.mm @@ -317,7 +317,7 @@ static bool hasQuestionMarkOnlyQueryString(NSURL *URL) NSString *userVisibleString(NSURL *URL) { - return URLHelpers::userVisibleURL(span(originalURLData(URL))); + return URLHelpers::userVisibleURL(byteCast(span(originalURLData(URL)))); } BOOL isUserVisibleURL(NSString *string) diff --git a/Source/WTF/wtf/persistence/PersistentCoders.cpp b/Source/WTF/wtf/persistence/PersistentCoders.cpp index 024b7c22b3abd..2b8160d588af5 100644 --- a/Source/WTF/wtf/persistence/PersistentCoders.cpp +++ b/Source/WTF/wtf/persistence/PersistentCoders.cpp @@ -100,7 +100,7 @@ void Coder::encodeForPersistence(Encoder& encoder, const String& string) encoder << string.length() << is8Bit; if (is8Bit) - encoder.encodeFixedLengthData(string.span8()); + encoder.encodeFixedLengthData(asBytes(string.span8())); else encoder.encodeFixedLengthData(asBytes(string.span16())); } diff --git a/Source/WTF/wtf/text/StringBuilder.h b/Source/WTF/wtf/text/StringBuilder.h index be2a2adee02f4..029ef556af06a 100644 --- a/Source/WTF/wtf/text/StringBuilder.h +++ b/Source/WTF/wtf/text/StringBuilder.h @@ -278,8 +278,7 @@ inline unsigned StringBuilder::capacity() const inline char16_t StringBuilder::operator[](unsigned i) const { - RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(i < length()); - return is8Bit() ? characters()[i] : characters()[i]; + return is8Bit() ? char16_t { span8()[i] } : span16()[i]; } inline bool StringBuilder::is8Bit() const diff --git a/Source/WTF/wtf/text/WTFString.cpp b/Source/WTF/wtf/text/WTFString.cpp index d8f66c5b35f70..8db7dc964e5aa 100644 --- a/Source/WTF/wtf/text/WTFString.cpp +++ b/Source/WTF/wtf/text/WTFString.cpp @@ -51,8 +51,9 @@ String::String(std::span characters) { } +// Construct a string with Latin-1 data. String::String(std::span characters) - : m_impl(characters.data() ? RefPtr { StringImpl::create(byteCast(characters)) } : nullptr) + : m_impl(characters.data() ? RefPtr { StringImpl::create(byteCast(characters)) } : nullptr) { } @@ -392,9 +393,9 @@ CString String::ascii() const CString result = CString::newUninitialized(characters.size(), characterBuffer); for (auto character : characters) - *characterBuffer++ = character && (character < 0x20 || character > 0x7f) ? '?' : character; + *characterBuffer++ = character && (character < 0x20 || character > 0x7f) ? '?' : byteCast(character); - return result; + return result; } auto characters = span16(); diff --git a/Source/WTF/wtf/text/cf/StringCF.cpp b/Source/WTF/wtf/text/cf/StringCF.cpp index 49d3bb68aab41..96a403441df65 100644 --- a/Source/WTF/wtf/text/cf/StringCF.cpp +++ b/Source/WTF/wtf/text/cf/StringCF.cpp @@ -43,7 +43,7 @@ String::String(CFStringRef str) { StringBuffer buffer(size); CFIndex usedBufLen; - CFIndex convertedSize = CFStringGetBytes(str, CFRangeMake(0, size), kCFStringEncodingISOLatin1, 0, false, buffer.characters(), size, &usedBufLen); + CFIndex convertedSize = CFStringGetBytes(str, CFRangeMake(0, size), kCFStringEncodingISOLatin1, 0, false, byteCast(buffer.characters()), size, &usedBufLen); if (convertedSize == size && usedBufLen == size) { m_impl = StringImpl::adopt(WTFMove(buffer)); return; diff --git a/Source/WTF/wtf/text/cf/StringImplCF.cpp b/Source/WTF/wtf/text/cf/StringImplCF.cpp index 425ee52899cb0..acb0b66aa0371 100644 --- a/Source/WTF/wtf/text/cf/StringImplCF.cpp +++ b/Source/WTF/wtf/text/cf/StringImplCF.cpp @@ -120,7 +120,7 @@ RetainPtr StringImpl::createCFString() if (!m_length || !isMainThread()) { if (is8Bit()) { auto characters = span8(); - return adoptCF(CFStringCreateWithBytes(nullptr, characters.data(), characters.size(), kCFStringEncodingISOLatin1, false)); + return adoptCF(CFStringCreateWithBytes(nullptr, byteCast(characters.data()), characters.size(), kCFStringEncodingISOLatin1, false)); } auto characters = span16(); return adoptCF(CFStringCreateWithCharacters(nullptr, reinterpret_cast(characters.data()), characters.size())); @@ -134,7 +134,7 @@ RetainPtr StringImpl::createCFString() RetainPtr string; if (is8Bit()) { auto characters = span8(); - string = adoptCF(CFStringCreateWithBytesNoCopy(allocator, characters.data(), characters.size(), kCFStringEncodingISOLatin1, false, kCFAllocatorNull)); + string = adoptCF(CFStringCreateWithBytesNoCopy(allocator, byteCast(characters.data()), characters.size(), kCFStringEncodingISOLatin1, false, kCFAllocatorNull)); } else { auto characters = span16(); string = adoptCF(CFStringCreateWithCharactersNoCopy(allocator, reinterpret_cast(characters.data()), characters.size(), kCFAllocatorNull)); diff --git a/Source/WTF/wtf/text/cf/StringViewCF.cpp b/Source/WTF/wtf/text/cf/StringViewCF.cpp index 381d2e1b5e7e6..6111de46bfd85 100644 --- a/Source/WTF/wtf/text/cf/StringViewCF.cpp +++ b/Source/WTF/wtf/text/cf/StringViewCF.cpp @@ -37,7 +37,7 @@ RetainPtr StringView::createCFString() const { if (is8Bit()) { auto characters = span8(); - return adoptCF(CFStringCreateWithBytes(kCFAllocatorDefault, characters.data(), characters.size(), kCFStringEncodingISOLatin1, false)); + return adoptCF(CFStringCreateWithBytes(kCFAllocatorDefault, byteCast(characters.data()), characters.size(), kCFStringEncodingISOLatin1, false)); } auto characters = span16(); return adoptCF(CFStringCreateWithCharacters(kCFAllocatorDefault, reinterpret_cast(characters.data()), characters.size())); @@ -47,7 +47,7 @@ RetainPtr StringView::createCFStringWithoutCopying() const { if (is8Bit()) { auto characters = span8(); - return adoptCF(CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, characters.data(), characters.size(), kCFStringEncodingISOLatin1, false, kCFAllocatorNull)); + return adoptCF(CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, byteCast(characters.data()), characters.size(), kCFStringEncodingISOLatin1, false, kCFAllocatorNull)); } auto characters = span16(); return adoptCF(CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast(characters.data()), characters.size(), kCFAllocatorNull)); diff --git a/Source/WebCore/Modules/encryptedmedia/InitDataRegistry.cpp b/Source/WebCore/Modules/encryptedmedia/InitDataRegistry.cpp index b18017bed2aba..1af12539c3ef3 100644 --- a/Source/WebCore/Modules/encryptedmedia/InitDataRegistry.cpp +++ b/Source/WebCore/Modules/encryptedmedia/InitDataRegistry.cpp @@ -69,9 +69,9 @@ static std::optional>> extractKeyIDsKeyids(const Shared // https://w3c.github.io/encrypted-media/format-registry/initdata/keyids.html#format if (buffer.size() > std::numeric_limits::max()) return std::nullopt; - String json { buffer.span() }; - auto value = JSON::Value::parseJSON(json); + // FIXME: Specification says this should be parsed as UTF-8, not Latin-1. + auto value = JSON::Value::parseJSON(byteCast(buffer.span())); if (!value) return std::nullopt; diff --git a/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp b/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp index d9c85af5c3a2d..2220c492cf5e6 100644 --- a/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp +++ b/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp @@ -225,7 +225,7 @@ void PeerConnectionBackend::handleLogMessage(const WTFLogChannel& channel, WTFLo // Check if the third message is a multi-lines string, concatenating such message would look ugly in log events. if (values.size() >= 3 && values[2].value.find("\r\n"_s) != notFound) - event = generateJSONLogEvent(MessageLogEvent { values[1].value, { values[2].value.span8() } }, false); + event = generateJSONLogEvent(MessageLogEvent { values[1].value, { byteCast(values[2].value.span8()) } }, false); else { StringBuilder builder; for (auto& value : values.subvector(1)) diff --git a/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp b/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp index 06c0d81e7d56a..a866431b4184a 100644 --- a/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp +++ b/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp @@ -35,12 +35,12 @@ namespace WebCore { ExceptionOr> RTCRtpSFrameTransformer::computeSaltKey(const Vector& rawKey) { - return deriveHDKFSHA256Bits(rawKey.subspan(0, 16), "SFrame10"_span, "salt"_span, 96); + return deriveHDKFSHA256Bits(rawKey.subspan(0, 16), byteCast("SFrame10"_span), byteCast("salt"_span), 96); } static ExceptionOr> createBaseSFrameKey(const Vector& rawKey) { - return deriveHDKFSHA256Bits(rawKey.subspan(0, 16), "SFrame10"_span, "key"_span, 128); + return deriveHDKFSHA256Bits(rawKey.subspan(0, 16), byteCast("SFrame10"_span), byteCast("key"_span), 128); } ExceptionOr> RTCRtpSFrameTransformer::computeAuthenticationKey(const Vector& rawKey) @@ -49,7 +49,7 @@ ExceptionOr> RTCRtpSFrameTransformer::computeAuthenticationKey(c if (key.hasException()) return key; - return deriveHDKFSHA256Bits(key.returnValue().subspan(0, 16), "SFrame10 AES CM AEAD"_span, "auth"_span, 256); + return deriveHDKFSHA256Bits(key.returnValue().subspan(0, 16), byteCast("SFrame10 AES CM AEAD"_span), byteCast("auth"_span), 256); } ExceptionOr> RTCRtpSFrameTransformer::computeEncryptionKey(const Vector& rawKey) @@ -58,7 +58,7 @@ ExceptionOr> RTCRtpSFrameTransformer::computeEncryptionKey(const if (key.hasException()) return key; - return deriveHDKFSHA256Bits(key.returnValue().subspan(0, 16), "SFrame10 AES CM AEAD"_span, "enc"_span, 128); + return deriveHDKFSHA256Bits(key.returnValue().subspan(0, 16), byteCast("SFrame10 AES CM AEAD"_span), byteCast("enc"_span), 128); } ExceptionOr> RTCRtpSFrameTransformer::decryptData(std::span data, const Vector& iv, const Vector& key) diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerDtlsTransportBackend.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerDtlsTransportBackend.cpp index ce40b272f6054..1ca453b1b0e98 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerDtlsTransportBackend.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerDtlsTransportBackend.cpp @@ -80,12 +80,11 @@ void GStreamerDtlsTransportBackendObserver::stateChanged() GUniqueOutPtr remoteCertificate; GUniqueOutPtr certificate; g_object_get(m_backend.get(), "remote-certificate", &remoteCertificate.outPtr(), "certificate", &certificate.outPtr(), nullptr); - if (remoteCertificate) - certificates.append(JSC::ArrayBuffer::create(span8(remoteCertificate.get()))); + certificates.append(JSC::ArrayBuffer::create(byteCast(span8(remoteCertificate.get())))); if (certificate) - certificates.append(JSC::ArrayBuffer::create(span8(certificate.get()))); + certificates.append(JSC::ArrayBuffer::create(byteCast(span8(certificate.get())))); } m_client->onStateChanged(toRTCDtlsTransportState(state), WTFMove(certificates)); }); diff --git a/Source/WebCore/Modules/push-api/PushMessageCrypto.cpp b/Source/WebCore/Modules/push-api/PushMessageCrypto.cpp index 54d5defbf97f2..346be6cf171a8 100644 --- a/Source/WebCore/Modules/push-api/PushMessageCrypto.cpp +++ b/Source/WebCore/Modules/push-api/PushMessageCrypto.cpp @@ -151,7 +151,7 @@ std::optional> decryptAES128GCMPayload(const ClientKeys& clientK * CEK = HMAC-SHA-256(PRK, cek_info || 0x01)[0..15] */ static const uint8_t cekInfo[] = "Content-Encoding: aes128gcm\x00\x01"; - auto cek = hmacSHA256(prk, std::span(cekInfo, sizeof(cekInfo) - 1)); + auto cek = hmacSHA256(prk, byteCast(std::span(cekInfo, sizeof(cekInfo) - 1))); cek.shrink(16); /* @@ -160,7 +160,7 @@ std::optional> decryptAES128GCMPayload(const ClientKeys& clientK * NONCE = HMAC-SHA-256(PRK, nonce_info || 0x01)[0..11] */ static const uint8_t nonceInfo[] = "Content-Encoding: nonce\x00\x01"; - auto nonce = hmacSHA256(prk, std::span(nonceInfo, sizeof(nonceInfo) - 1)); + auto nonce = hmacSHA256(prk, byteCast(std::span(nonceInfo, sizeof(nonceInfo) - 1))); nonce.shrink(12); // Finally, decrypt with AES128GCM and return the unpadded plaintext. @@ -238,7 +238,7 @@ std::optional> decryptAESGCMPayload(const ClientKeys& clientKeys */ static const uint8_t authInfo[] = "Content-Encoding: auth\x00\x01"; auto prkCombine = hmacSHA256(clientKeys.sharedAuthSecret, *ecdhSecretResult); - auto ikm = hmacSHA256(prkCombine, std::span(authInfo, sizeof(authInfo) - 1)); + auto ikm = hmacSHA256(prkCombine, byteCast(std::span(authInfo, sizeof(authInfo) - 1))); auto prk = hmacSHA256(salt, ikm); /* diff --git a/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp b/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp index 60657b749d1b6..b259df8a9edf7 100644 --- a/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp +++ b/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp @@ -86,9 +86,10 @@ static String hostName(const URL& url, bool secure) static constexpr size_t maxInputSampleSize = 128; static String trimInputSample(std::span input) { + // FIXME: Unclear why this is Latin-1 and not UTF-8. if (input.size() <= maxInputSampleSize) - return input; - return makeString(input.first(maxInputSampleSize), horizontalEllipsis); + return byteCast(input); + return makeString(byteCast(input.first(maxInputSampleSize)), horizontalEllipsis); } static String generateSecWebSocketKey() @@ -409,24 +410,24 @@ int WebSocketHandshake::readStatusLine(std::span header, int& sta return lineLength; } - StringView httpStatusLine(header.first(*firstSpaceIndex)); + StringView httpStatusLine(byteCast(header.first(*firstSpaceIndex))); if (!headerHasValidHTTPVersion(httpStatusLine)) { m_failureReason = makeString("Invalid HTTP version string: "_s, httpStatusLine); return lineLength; } - StringView statusCodeString(header.subspan(*firstSpaceIndex + 1, *secondSpaceIndex - *firstSpaceIndex - 1)); - if (statusCodeString.length() != 3) // Status code must consist of three digits. + auto statusCodeString = byteCast(header.subspan(*firstSpaceIndex + 1, *secondSpaceIndex - *firstSpaceIndex - 1)); + if (statusCodeString.size() != 3) // Status code must consist of three digits. return lineLength; - for (int i = 0; i < 3; ++i) { - if (!isASCIIDigit(statusCodeString[i])) { + for (auto digit : statusCodeString) { + if (!isASCIIDigit(digit)) { m_failureReason = makeString("Invalid status code: "_s, statusCodeString); return lineLength; } } statusCode = parseInteger(statusCodeString).value(); - statusText = String(header.subspan(*secondSpaceIndex + 1, index - *secondSpaceIndex - 3)); // Exclude "\r\n". + statusText = String(byteCast(header.subspan(*secondSpaceIndex + 1, index - *secondSpaceIndex - 3))); // Exclude "\r\n". return lineLength; } diff --git a/Source/WebCore/bindings/js/ScriptBufferSourceProvider.h b/Source/WebCore/bindings/js/ScriptBufferSourceProvider.h index adb20d913303e..83f23dbf94fee 100644 --- a/Source/WebCore/bindings/js/ScriptBufferSourceProvider.h +++ b/Source/WebCore/bindings/js/ScriptBufferSourceProvider.h @@ -76,7 +76,7 @@ class ScriptBufferSourceProvider final : public JSC::SourceProvider, public Abst m_scriptHash = StringHasher::computeHashAndMaskTop8Bits(m_contiguousBuffer->span()); } if (*m_containsOnlyASCII) - return m_contiguousBuffer->span(); + return byteCast(m_contiguousBuffer->span()); if (!m_cachedScriptString) { m_cachedScriptString = m_scriptBuffer.toString(); diff --git a/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp b/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp index 02193910bef6e..cee426e7c4c0f 100644 --- a/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp +++ b/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp @@ -207,7 +207,7 @@ inline void DFABytecodeInterpreter::interpretJumpTable(std::span(url[urlIndex]) : 0; char character = caseSensitive ? c : toASCIILower(c); uint8_t firstCharacter = getBits(m_bytecode, programCounter + sizeof(DFABytecodeInstruction)); uint8_t lastCharacter = getBits(m_bytecode, programCounter + sizeof(DFABytecodeInstruction) + sizeof(uint8_t)); @@ -299,7 +299,7 @@ auto DFABytecodeInterpreter::interpret(const String& urlString, ResourceFlags fl goto nextDFA; // Check to see if the next character in the url is the value stored with the bytecode. - char character = urlIndex < url.size() ? url[urlIndex] : 0; + char character = urlIndex < url.size() ? byteCast(url[urlIndex]) : 0; DFABytecodeJumpSize jumpSize = getJumpSize(m_bytecode, programCounter); if (character == getBits(m_bytecode, programCounter + sizeof(DFABytecodeInstruction))) { uint32_t jumpLocation = programCounter + sizeof(DFABytecodeInstruction) + sizeof(uint8_t); @@ -315,7 +315,7 @@ auto DFABytecodeInterpreter::interpret(const String& urlString, ResourceFlags fl goto nextDFA; // Check to see if the next character in the url is the value stored with the bytecode. - char character = urlIndex < url.size() ? toASCIILower(url[urlIndex]) : 0; + char character = urlIndex < url.size() ? byteCast(toASCIILower(url[urlIndex])) : 0; DFABytecodeJumpSize jumpSize = getJumpSize(m_bytecode, programCounter); if (character == getBits(m_bytecode, programCounter + sizeof(DFABytecodeInstruction))) { uint32_t jumpLocation = programCounter + sizeof(DFABytecodeInstruction) + sizeof(uint8_t); @@ -343,7 +343,7 @@ auto DFABytecodeInterpreter::interpret(const String& urlString, ResourceFlags fl if (urlIndex > url.size()) goto nextDFA; - char character = urlIndex < url.size() ? url[urlIndex] : 0; + char character = urlIndex < url.size() ? byteCast(url[urlIndex]) : 0; DFABytecodeJumpSize jumpSize = getJumpSize(m_bytecode, programCounter); if (character >= getBits(m_bytecode, programCounter + sizeof(DFABytecodeInstruction)) && character <= getBits(m_bytecode, programCounter + sizeof(DFABytecodeInstruction) + sizeof(uint8_t))) { @@ -359,7 +359,7 @@ auto DFABytecodeInterpreter::interpret(const String& urlString, ResourceFlags fl if (urlIndex > url.size()) goto nextDFA; - char character = urlIndex < url.size() ? toASCIILower(url[urlIndex]) : 0; + char character = urlIndex < url.size() ? byteCast(toASCIILower(url[urlIndex])) : 0; DFABytecodeJumpSize jumpSize = getJumpSize(m_bytecode, programCounter); if (character >= getBits(m_bytecode, programCounter + sizeof(DFABytecodeInstruction)) && character <= getBits(m_bytecode, programCounter + sizeof(DFABytecodeInstruction) + sizeof(uint8_t))) { diff --git a/Source/WebCore/crypto/SubtleCrypto.cpp b/Source/WebCore/crypto/SubtleCrypto.cpp index 0a38e9e289328..599dedd7ae0aa 100644 --- a/Source/WebCore/crypto/SubtleCrypto.cpp +++ b/Source/WebCore/crypto/SubtleCrypto.cpp @@ -1269,9 +1269,8 @@ void SubtleCrypto::unwrapKey(JSC::JSGlobalObject& state, KeyFormat format, Buffe auto& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); - String jwkString(bytes.span()); JSLockHolder locker(vm); - auto jwkObject = JSONParse(&state, jwkString); + auto jwkObject = JSONParse(&state, byteCast(bytes.span())); if (!jwkObject) { promise->reject(ExceptionCode::DataError, "WrappedKey cannot be converted to a JSON object"_s); return; diff --git a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm index ed7711e8216a4..6bceb5fcabd04 100644 --- a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm +++ b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm @@ -383,7 +383,7 @@ static void replaceRichContentWithAttachments(LocalFrame& frame, DocumentFragmen // See `HTMLConverter.mm` for more details. if (info.fileName.startsWith(WebContentReader::placeholderAttachmentFilenamePrefix)) { RefPtr document = frame.document(); - if (RefPtr existingAttachment = document->attachmentForIdentifier({ info.data->span() })) { + if (RefPtr existingAttachment = document->attachmentForIdentifier({ byteCast(info.data->span()) })) { parent->replaceChild(*existingAttachment.get(), WTFMove(originalElement)); continue; } diff --git a/Source/WebCore/fileapi/FileReaderLoader.cpp b/Source/WebCore/fileapi/FileReaderLoader.cpp index 29b2d8998d207..2aba718e95c32 100644 --- a/Source/WebCore/fileapi/FileReaderLoader.cpp +++ b/Source/WebCore/fileapi/FileReaderLoader.cpp @@ -327,7 +327,7 @@ String FileReaderLoader::stringResult() // No conversion is needed. break; case ReadAsBinaryString: - m_stringResult = m_rawData->span().first(m_bytesLoaded); + m_stringResult = byteCast(m_rawData->span().first(m_bytesLoaded)); break; case ReadAsText: convertToText(); diff --git a/Source/WebCore/html/FTPDirectoryDocument.cpp b/Source/WebCore/html/FTPDirectoryDocument.cpp index 8a3d263655581..0e890482a74d5 100644 --- a/Source/WebCore/html/FTPDirectoryDocument.cpp +++ b/Source/WebCore/html/FTPDirectoryDocument.cpp @@ -295,7 +295,7 @@ bool FTPDirectoryDocumentParser::loadDocumentTemplate() return false; } - HTMLDocumentParser::insert(String(templateDocumentData.get()->span())); + HTMLDocumentParser::insert(String(byteCast(templateDocumentData.get()->span()))); Ref document = *this->document(); diff --git a/Source/WebCore/html/parser/HTMLEntityParser.cpp b/Source/WebCore/html/parser/HTMLEntityParser.cpp index b1af08f91a3b6..f030b8835a66e 100644 --- a/Source/WebCore/html/parser/HTMLEntityParser.cpp +++ b/Source/WebCore/html/parser/HTMLEntityParser.cpp @@ -123,7 +123,7 @@ template class StringParsingBufferSource { explicit StringParsingBufferSource(StringParsingBuffer&); static bool isEmpty() { return false; } - UChar currentCharacter() const { return m_source.atEnd() ? 0 : *m_source; } + char16_t currentCharacter() const { return m_source.atEnd() ? 0 : char16_t { *m_source }; } void advance() { m_source.advance(); } void pushEverythingBack() { m_source.setPosition(m_startPosition); } void pushBackButKeep(unsigned keepCount) { m_source.setPosition(m_startPosition + keepCount); } diff --git a/Source/WebCore/html/track/VTTScanner.h b/Source/WebCore/html/track/VTTScanner.h index fe47090b7b634..de22ae7333b33 100644 --- a/Source/WebCore/html/track/VTTScanner.h +++ b/Source/WebCore/html/track/VTTScanner.h @@ -216,7 +216,7 @@ inline void VTTScanner::seekTo(Position position) inline char16_t VTTScanner::currentChar() const { ASSERT(position() < end()); - return m_is8Bit ? *m_data.characters8 : *m_data.characters16; + return m_is8Bit ? char16_t { *m_data.characters8 } : *m_data.characters16; } inline void VTTScanner::advance(unsigned amount) diff --git a/Source/WebCore/html/track/WebVTTParser.cpp b/Source/WebCore/html/track/WebVTTParser.cpp index 5bad85caeeaf1..c7fcca3808a96 100644 --- a/Source/WebCore/html/track/WebVTTParser.cpp +++ b/Source/WebCore/html/track/WebVTTParser.cpp @@ -231,7 +231,7 @@ void WebVTTParser::parse() void WebVTTParser::fileFinished() { ASSERT(m_state != Finished); - parseBytes("\n\n"_span); + parseBytes(byteCast("\n\n"_span)); m_state = Finished; } diff --git a/Source/WebCore/loader/FormSubmission.cpp b/Source/WebCore/loader/FormSubmission.cpp index f47cbc47d836d..9dfe1ad553933 100644 --- a/Source/WebCore/loader/FormSubmission.cpp +++ b/Source/WebCore/loader/FormSubmission.cpp @@ -77,7 +77,7 @@ static void appendMailtoPostFormDataToURL(URL& url, const FormData& data, const Vector bodyData(std::span("body=", static_cast(5))); FormDataBuilder::encodeStringAsFormData(bodyData, body.utf8()); - body = makeStringByReplacingAll(bodyData.span(), '+', "%20"_s); + body = makeStringByReplacingAll(byteCast(bodyData.span()), '+', "%20"_s); auto query = url.query(); if (query.isEmpty()) @@ -223,7 +223,7 @@ Ref FormSubmission::create(HTMLFormElement& form, HTMLFormContro if (isMultiPartForm) { formData = FormData::createMultiPart(domFormData); - boundary = String(formData->boundary()); + boundary = String(byteCast(formData->boundary().span())); } else { formData = FormData::create(domFormData, attributes.method() == Method::Get ? FormData::EncodingType::FormURLEncoded : FormData::parseEncodingType(encodingType)); if (copiedAttributes.method() == Method::Post && isMailtoForm) { diff --git a/Source/WebCore/loader/TextResourceDecoder.cpp b/Source/WebCore/loader/TextResourceDecoder.cpp index 0cd4fe1873ee1..fa7d9ef2e7917 100644 --- a/Source/WebCore/loader/TextResourceDecoder.cpp +++ b/Source/WebCore/loader/TextResourceDecoder.cpp @@ -531,7 +531,7 @@ bool TextResourceDecoder::checkForHeadCharset(std::span data, boo int len = 0; int pos = findXMLEncoding(ptr, xmlDeclarationEnd - ptr, len); if (pos != -1) - setEncoding(findTextEncoding(ptr + pos, len), EncodingFromXMLHeader); + setEncoding(findTextEncoding(byteCast(ptr + pos), len), EncodingFromXMLHeader); // continue looking for a charset - it may be specified in an HTTP-Equiv meta } else if (bytesEqual(ptr, '<', 0, '?', 0, 'x', 0)) { setEncoding(PAL::UTF16LittleEndianEncoding(), AutoDetectedEncoding); diff --git a/Source/WebCore/loader/cache/CachedScript.cpp b/Source/WebCore/loader/cache/CachedScript.cpp index 10b363dbda0c1..970594548d039 100644 --- a/Source/WebCore/loader/cache/CachedScript.cpp +++ b/Source/WebCore/loader/cache/CachedScript.cpp @@ -82,7 +82,7 @@ StringView CachedScript::script(ShouldDecodeAsUTF8Only shouldDecodeAsUTF8Only) } if (m_decodingState == DataAndDecodedStringHaveSameBytes) - return { contiguousData->span() }; + return { byteCast(contiguousData->span()) }; bool shouldForceRedecoding = m_wasForceDecodedAsUTF8 != (shouldDecodeAsUTF8Only == ShouldDecodeAsUTF8Only::Yes); if (!m_script || shouldForceRedecoding) { diff --git a/Source/WebCore/platform/encryptedmedia/CDMUtilities.cpp b/Source/WebCore/platform/encryptedmedia/CDMUtilities.cpp index 077e4fb4ae3e4..78d829d9007cb 100644 --- a/Source/WebCore/platform/encryptedmedia/CDMUtilities.cpp +++ b/Source/WebCore/platform/encryptedmedia/CDMUtilities.cpp @@ -45,17 +45,15 @@ RefPtr parseJSONObject(const SharedBuffer& buffer) return nullptr; // Parse the buffer contents as JSON, returning the root object (if any). - String json { buffer.span() }; - - auto value = JSON::Value::parseJSON(json); + auto value = JSON::Value::parseJSON(byteCast(buffer.span())); if (!value) return nullptr; return value->asObject(); } -}; +} -}; +} #endif // ENABLE(ENCRYPTED_MEDIA) diff --git a/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp b/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp index bdbf11165b463..95211d8a898bc 100644 --- a/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp +++ b/Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp @@ -92,9 +92,8 @@ static Vector> extractSinfData(const SharedBuffer& buffer) // JSON of the format: "{ sinf: [ ] }" if (buffer.size() > std::numeric_limits::max()) return { }; - String json { buffer.makeContiguous()->span() }; - auto value = JSON::Value::parseJSON(json); + auto value = JSON::Value::parseJSON(byteCast(buffer.makeContiguous()->span())); if (!value) return { }; @@ -214,9 +213,8 @@ std::optional>> CDMPrivateFairPlayStreaming::extractKey // JSON of the format: "{ "codc" : [integer], "mtyp" : [integer], "cont" : "mpts"} }" if (buffer.size() > std::numeric_limits::max()) return { }; - String json { buffer.makeContiguous()->span() }; - auto value = JSON::Value::parseJSON(json); + auto value = JSON::Value::parseJSON(byteCast(buffer.makeContiguous()->span())); if (!value) return { }; diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm b/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm index 79cd641b084be..cd564dc81b45a 100644 --- a/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm +++ b/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm @@ -340,7 +340,7 @@ void fail() return nullptr; // Parse the buffer contents as JSON, returning the root object (if any). - return JSON::Value::parseJSON(buffer.makeContiguous()->span()); + return JSON::Value::parseJSON(byteCast(buffer.makeContiguous()->span())); } bool CDMInstanceFairPlayStreamingAVFObjC::supportsPersistableState() diff --git a/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp b/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp index 271e30a68097f..1ff1dab277ee7 100644 --- a/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp +++ b/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp @@ -494,7 +494,7 @@ static String fontNameMapName(FT_Face face, unsigned id) switch (name.platform_id) { case TT_PLATFORM_MACINTOSH: if (name.encoding_id == TT_MAC_ID_ROMAN) - return String({ name.string, name.string_len }); + return String({ byteCast(name.string), name.string_len }); // FIXME: implement other macintosh encodings. break; case TT_PLATFORM_APPLE_UNICODE: diff --git a/Source/WebCore/platform/graphics/gstreamer/eme/CDMThunder.cpp b/Source/WebCore/platform/graphics/gstreamer/eme/CDMThunder.cpp index 191303629b63a..e7def092d8582 100644 --- a/Source/WebCore/platform/graphics/gstreamer/eme/CDMThunder.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/eme/CDMThunder.cpp @@ -326,7 +326,7 @@ class ParsedResponseMessage { unsigned offset = 0u; if (buffer->size() >= 7) { auto data = buffer->read(0, 7); - StringView dataString(data.span()); + StringView dataString(byteCast(data.span())); if (dataString.endsWith(":Type:"_s)) { m_type.emplace(static_cast(dataString.characterAt(0) - '0')); offset = 7; @@ -627,7 +627,7 @@ void CDMInstanceSessionThunder::loadSession(LicenseType, const String& sessionID callback(std::nullopt, std::nullopt, std::nullopt, SuccessValue::Failed, sessionLoadFailureFromThunder({ })); else { auto responseData = responseMessage->extractData(); - StringView response(responseData.span()); + StringView response(byteCast(responseData.span())); GST_DEBUG("Error message: %s", response.utf8().data()); callback(std::nullopt, std::nullopt, std::nullopt, SuccessValue::Failed, sessionLoadFailureFromThunder(response)); } diff --git a/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp b/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp index 93deb612372a1..1306d68e524c2 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp @@ -670,7 +670,7 @@ String MermaidBuilder::describeCaps(const GRefPtr& caps) std::span MermaidBuilder::span() const { - return m_stringBuilder.span(); + return byteCast(m_stringBuilder.span8()); } #endif diff --git a/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateMock.cpp b/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateMock.cpp index 5b49dcee66115..c2aed622f63a0 100644 --- a/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateMock.cpp +++ b/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateMock.cpp @@ -95,9 +95,8 @@ void MediaRecorderPrivateMock::fetchData(FetchDataCallback&& completionHandler) RefPtr buffer; { Locker locker { m_bufferLock }; - Vector value(m_buffer.span()); + buffer = SharedBuffer::create(byteCast(m_buffer.span())); m_buffer.clear(); - buffer = SharedBuffer::create(WTFMove(value)); } // Delay calling the completion handler a bit to mimick real writer behavior. diff --git a/Source/WebCore/platform/network/curl/OpenSSLHelper.cpp b/Source/WebCore/platform/network/curl/OpenSSLHelper.cpp index c9eb331084dd2..69ec1b11deaed 100644 --- a/Source/WebCore/platform/network/curl/OpenSSLHelper.cpp +++ b/Source/WebCore/platform/network/curl/OpenSSLHelper.cpp @@ -135,7 +135,7 @@ class BIO { if (length < 0) return String(); - return String({ data, static_cast(length) }); + return String({ byteCast(data), static_cast(length) }); } std::unique_ptr> readX509() @@ -191,7 +191,7 @@ static String toString(const ASN1_STRING* name) if (length <= 0) return String(); - String result({ data, static_cast(length) }); + String result({ byteCast(data), static_cast(length) }); OPENSSL_free(data); return result; } diff --git a/Source/WebCore/platform/text/SegmentedString.h b/Source/WebCore/platform/text/SegmentedString.h index 824bbb93148f1..9df2373a8197a 100644 --- a/Source/WebCore/platform/text/SegmentedString.h +++ b/Source/WebCore/platform/text/SegmentedString.h @@ -179,7 +179,7 @@ inline unsigned SegmentedString::Substring::numberOfCharactersConsumed() const ALWAYS_INLINE char16_t SegmentedString::Substring::currentCharacter() const { ASSERT(length); - return is8Bit ? *currentCharacter8 : *currentCharacter16; + return is8Bit ? char16_t { *currentCharacter8 } : *currentCharacter16; } ALWAYS_INLINE char16_t SegmentedString::Substring::currentCharacterPreIncrement() diff --git a/Source/WebCore/testing/MockCDMFactory.cpp b/Source/WebCore/testing/MockCDMFactory.cpp index 3a3c84825a887..bd0261d37cdb5 100644 --- a/Source/WebCore/testing/MockCDMFactory.cpp +++ b/Source/WebCore/testing/MockCDMFactory.cpp @@ -227,7 +227,7 @@ RefPtr MockCDM::sanitizeResponse(const SharedBuffer& response) con if (!charactersAreAllASCII(contiguousResponse->span())) return nullptr; - for (auto word : StringView(contiguousResponse->span()).split(' ')) { + for (auto word : StringView(byteCast(contiguousResponse->span())).split(' ')) { if (word == "valid-response"_s) return contiguousResponse; } @@ -283,7 +283,7 @@ void MockCDMInstance::initializeWithConfiguration(const MediaKeySystemConfigurat void MockCDMInstance::setServerCertificate(Ref&& certificate, SuccessCallback&& callback) { Ref contiguousData = certificate->makeContiguous(); - callback(equalLettersIgnoringASCIICase(StringView { contiguousData->span() }, "valid"_s) ? Succeeded : Failed); + callback(equalLettersIgnoringASCIICase(StringView { byteCast(contiguousData->span()) }, "valid"_s) ? Succeeded : Failed); } void MockCDMInstance::setStorageDirectory(const String&) @@ -341,7 +341,7 @@ void MockCDMInstanceSession::updateLicense(const String& sessionID, LicenseType, return; } - Vector responseVector = String(response->makeContiguous()->span()).split(' '); + Vector responseVector = String(byteCast(response->makeContiguous()->span())).split(' '); if (responseVector.contains(String("invalid-format"_s))) { callback(false, std::nullopt, std::nullopt, std::nullopt, SuccessValue::Failed); diff --git a/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp b/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp index d870a4fbffdda..ad075a4869fa4 100644 --- a/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp +++ b/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp @@ -643,7 +643,7 @@ void Cache::dumpContentsToFile() return; constexpr auto prologue = "{\n\"entries\": [\n"_s; - writeToFile(fd, prologue.span8()); + writeToFile(fd, byteCast(prologue.span8())); struct Totals { unsigned count { 0 }; diff --git a/Source/WebKit/NetworkProcess/storage/CacheStorageManager.cpp b/Source/WebKit/NetworkProcess/storage/CacheStorageManager.cpp index 9a37f782cb87e..950c9b3b27d8e 100644 --- a/Source/WebKit/NetworkProcess/storage/CacheStorageManager.cpp +++ b/Source/WebKit/NetworkProcess/storage/CacheStorageManager.cpp @@ -135,7 +135,7 @@ static std::optional readSizeFile(const String& sizeDirectoryPath) if (!buffer) return std::nullopt; - return parseInteger(buffer->span()); + return parseInteger(byteCast(buffer->span())); } static bool writeSizeFile(const String& sizeDirectoryPath, uint64_t size) diff --git a/Source/WebKit/Platform/IPC/DaemonCoders.h b/Source/WebKit/Platform/IPC/DaemonCoders.h index 13979dd36517f..286c8578b4729 100644 --- a/Source/WebKit/Platform/IPC/DaemonCoders.h +++ b/Source/WebKit/Platform/IPC/DaemonCoders.h @@ -145,7 +145,7 @@ template<> struct Coder { encoder << string.length() << is8Bit; if (is8Bit) - encoder.encodeFixedLengthData(string.span8()); + encoder.encodeFixedLengthData(byteCast(string.span8())); else encoder.encodeFixedLengthData(asBytes(string.span16())); } diff --git a/Source/WebKit/Shared/API/c/cf/WKStringCF.mm b/Source/WebKit/Shared/API/c/cf/WKStringCF.mm index 50f68e478800e..73f7d5f04240c 100644 --- a/Source/WebKit/Shared/API/c/cf/WKStringCF.mm +++ b/Source/WebKit/Shared/API/c/cf/WKStringCF.mm @@ -60,7 +60,7 @@ CFStringRef WKStringCopyCFString(CFAllocatorRef allocatorRef, WKStringRef string // expects to be called on the thread running WebCore. if (string.is8Bit()) { auto characters = string.span8(); - return CFStringCreateWithBytes(allocatorRef, characters.data(), characters.size(), kCFStringEncodingISOLatin1, true); + return CFStringCreateWithBytes(allocatorRef, byteCast(characters.data()), characters.size(), kCFStringEncodingISOLatin1, true); } auto characters = string.span16(); return CFStringCreateWithCharacters(allocatorRef, reinterpret_cast(characters.data()), characters.size()); diff --git a/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp b/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp index 413f7d4fa9efe..da91dcd3560a5 100644 --- a/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp +++ b/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp @@ -482,7 +482,7 @@ static WTF::String getContentRuleListSourceFromMappedFile(const MappedData& mapp size_t length = sourceSizeBytes - sizeof(bool); if (is8Bit) - return dataSpan.subspan(start, length); + return byteCast(dataSpan.subspan(start, length)); if (length % sizeof(UChar)) { ASSERT_NOT_REACHED(); diff --git a/Source/WebKit/UIProcess/API/C/WKPage.cpp b/Source/WebKit/UIProcess/API/C/WKPage.cpp index eab3997a18877..d295516f84cc2 100644 --- a/Source/WebKit/UIProcess/API/C/WKPage.cpp +++ b/Source/WebKit/UIProcess/API/C/WKPage.cpp @@ -268,8 +268,8 @@ static String encodingOf(const String& string) static std::span dataFrom(const String& string) { if (string.isNull() || !string.is8Bit()) - return asBytes(string.span16()); - return string.span8(); + return asBytes(string.span()); + return asBytes(string.span()); } static Ref dataReferenceFrom(const String& string) diff --git a/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm b/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm index dd18da337affa..eece74cacf503 100644 --- a/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm +++ b/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm @@ -730,7 +730,7 @@ return; } - completionHandler(sharedMemoryBuffer->size(), sharedMemoryBuffer->span()); + completionHandler(sharedMemoryBuffer->size(), byteCast(sharedMemoryBuffer->span())); } #endif diff --git a/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp b/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp index 4ebf8ea51f524..efc2b850134be 100644 --- a/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp +++ b/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp @@ -242,7 +242,7 @@ void RemoteInspectorClient::setBackendCommands(const char* backendCommands) return; } - m_backendCommandsURL = makeString("data:text/javascript;base64,"_s, base64Encoded(span8(backendCommands))); + m_backendCommandsURL = makeString("data:text/javascript;base64,"_s, base64Encoded(byteCast(span8(backendCommands)))); } void RemoteInspectorClient::connectionDidClose() diff --git a/Source/WebKit/UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm b/Source/WebKit/UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm index 0ce1a6460dbe6..999bf6c4f46b7 100644 --- a/Source/WebKit/UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm +++ b/Source/WebKit/UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm @@ -177,7 +177,7 @@ - (BOOL)inspectorViewControllerInspectorIsUnderTest:(WKInspectorViewController * void RemoteWebInspectorUIProxy::platformLoad(const String& path, CompletionHandler&& completionHandler) { if (auto contents = FileSystem::readEntireFile(path)) - completionHandler(String::adopt(WTFMove(*contents))); + completionHandler(String { byteCast(contents->span()) }); else completionHandler(nullString()); } diff --git a/Source/WebKit/UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm b/Source/WebKit/UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm index 1e669fad76db5..be4ff20ca5798 100644 --- a/Source/WebKit/UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm +++ b/Source/WebKit/UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm @@ -691,7 +691,7 @@ - (IBAction)_popUpButtonAction:(id)sender void WebInspectorUIProxy::platformLoad(const String& path, CompletionHandler&& completionHandler) { if (auto contents = FileSystem::readEntireFile(path)) - completionHandler(String::adopt(WTFMove(*contents))); + completionHandler(String { byteCast(contents->span()) }); else completionHandler(nullString()); } diff --git a/Source/WebKit/WebProcess/Network/webrtc/RTCDataChannelRemoteManager.cpp b/Source/WebKit/WebProcess/Network/webrtc/RTCDataChannelRemoteManager.cpp index 334121eab8c48..7c6ac0acd4913 100644 --- a/Source/WebKit/WebProcess/Network/webrtc/RTCDataChannelRemoteManager.cpp +++ b/Source/WebKit/WebProcess/Network/webrtc/RTCDataChannelRemoteManager.cpp @@ -122,7 +122,7 @@ void RTCDataChannelRemoteManager::sendData(WebCore::RTCDataChannelIdentifier sou if (isRaw) source->sendRawData(data); else - source->sendStringData(CString(data)); + source->sendStringData(CString(byteCast(data))); } } diff --git a/Tools/TestWebKitAPI/Tests/WTF/Base64.cpp b/Tools/TestWebKitAPI/Tests/WTF/Base64.cpp index 2951a0ba8adee..6f9ae4eb84de3 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/Base64.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/Base64.cpp @@ -36,13 +36,13 @@ TEST(Base64, Encode) { static constexpr OptionSet options; - EXPECT_ENCODE("", ""_s.span8()); - EXPECT_ENCODE("Zg==", "f"_s.span8()); - EXPECT_ENCODE("Zm8=", "fo"_s.span8()); - EXPECT_ENCODE("Zm9v", "foo"_s.span8()); - EXPECT_ENCODE("Zm9vYg==", "foob"_s.span8()); - EXPECT_ENCODE("Zm9vYmE=", "fooba"_s.span8()); - EXPECT_ENCODE("Zm9vYmFy", "foobar"_s.span8()); + EXPECT_ENCODE("", byteCast(""_s.span8())); + EXPECT_ENCODE("Zg==", byteCast("f"_s.span8())); + EXPECT_ENCODE("Zm8=", byteCast("fo"_s.span8())); + EXPECT_ENCODE("Zm9v", byteCast("foo"_s.span8())); + EXPECT_ENCODE("Zm9vYg==", byteCast("foob"_s.span8())); + EXPECT_ENCODE("Zm9vYmE=", byteCast("fooba"_s.span8())); + EXPECT_ENCODE("Zm9vYmFy", byteCast("foobar"_s.span8())); EXPECT_ENCODE("AA==", Vector({ 0 })); EXPECT_ENCODE("AQ==", Vector({ 1 })); @@ -58,13 +58,13 @@ TEST(Base64, EncodeOmitPadding) { static constexpr OptionSet options = { Base64EncodeOption::OmitPadding }; - EXPECT_ENCODE("", ""_s.span8()); - EXPECT_ENCODE("Zg", "f"_s.span8()); - EXPECT_ENCODE("Zm8", "fo"_s.span8()); - EXPECT_ENCODE("Zm9v", "foo"_s.span8()); - EXPECT_ENCODE("Zm9vYg", "foob"_s.span8()); - EXPECT_ENCODE("Zm9vYmE", "fooba"_s.span8()); - EXPECT_ENCODE("Zm9vYmFy", "foobar"_s.span8()); + EXPECT_ENCODE("", byteCast(""_s.span8())); + EXPECT_ENCODE("Zg", byteCast("f"_s.span8())); + EXPECT_ENCODE("Zm8", byteCast("fo"_s.span8())); + EXPECT_ENCODE("Zm9v", byteCast("foo"_s.span8())); + EXPECT_ENCODE("Zm9vYg", byteCast("foob"_s.span8())); + EXPECT_ENCODE("Zm9vYmE", byteCast("fooba"_s.span8())); + EXPECT_ENCODE("Zm9vYmFy", byteCast("foobar"_s.span8())); EXPECT_ENCODE("AA", Vector({ 0 })); EXPECT_ENCODE("AQ", Vector({ 1 })); @@ -80,13 +80,13 @@ TEST(Base64, EncodeURL) { static constexpr OptionSet options = { Base64EncodeOption::URL }; - EXPECT_ENCODE("", ""_s.span8()); - EXPECT_ENCODE("Zg==", "f"_s.span8()); - EXPECT_ENCODE("Zm8=", "fo"_s.span8()); - EXPECT_ENCODE("Zm9v", "foo"_s.span8()); - EXPECT_ENCODE("Zm9vYg==", "foob"_s.span8()); - EXPECT_ENCODE("Zm9vYmE=", "fooba"_s.span8()); - EXPECT_ENCODE("Zm9vYmFy", "foobar"_s.span8()); + EXPECT_ENCODE("", byteCast(""_s.span8())); + EXPECT_ENCODE("Zg==", byteCast("f"_s.span8())); + EXPECT_ENCODE("Zm8=", byteCast("fo"_s.span8())); + EXPECT_ENCODE("Zm9v", byteCast("foo"_s.span8())); + EXPECT_ENCODE("Zm9vYg==", byteCast("foob"_s.span8())); + EXPECT_ENCODE("Zm9vYmE=", byteCast("fooba"_s.span8())); + EXPECT_ENCODE("Zm9vYmFy", byteCast("foobar"_s.span8())); EXPECT_ENCODE("AA==", Vector({ 0 })); EXPECT_ENCODE("AQ==", Vector({ 1 })); @@ -102,13 +102,13 @@ TEST(Base64, EncodeURLOmitPadding) { static constexpr OptionSet options = { Base64EncodeOption::URL, Base64EncodeOption::OmitPadding }; - EXPECT_ENCODE("", ""_s.span8()); - EXPECT_ENCODE("Zg", "f"_s.span8()); - EXPECT_ENCODE("Zm8", "fo"_s.span8()); - EXPECT_ENCODE("Zm9v", "foo"_s.span8()); - EXPECT_ENCODE("Zm9vYg", "foob"_s.span8()); - EXPECT_ENCODE("Zm9vYmE", "fooba"_s.span8()); - EXPECT_ENCODE("Zm9vYmFy", "foobar"_s.span8()); + EXPECT_ENCODE("", byteCast(""_s.span8())); + EXPECT_ENCODE("Zg", byteCast("f"_s.span8())); + EXPECT_ENCODE("Zm8", byteCast("fo"_s.span8())); + EXPECT_ENCODE("Zm9v", byteCast("foo"_s.span8())); + EXPECT_ENCODE("Zm9vYg", byteCast("foob"_s.span8())); + EXPECT_ENCODE("Zm9vYmE", byteCast("fooba"_s.span8())); + EXPECT_ENCODE("Zm9vYmFy", byteCast("foobar"_s.span8())); EXPECT_ENCODE("AA", Vector({ 0 })); EXPECT_ENCODE("AQ", Vector({ 1 })); diff --git a/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp b/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp index fcbce7bb53d7e..45796f0680083 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp @@ -41,7 +41,7 @@ static void createTestFile(const String& path) { auto fileHandle = FileSystem::openFile(path, FileSystem::FileOpenMode::Truncate); EXPECT_TRUE(FileSystem::isHandleValid(fileHandle)); - FileSystem::writeToFile(fileHandle, FileSystemTestData.span8()); + FileSystem::writeToFile(fileHandle, byteCast(FileSystemTestData.span8())); FileSystem::closeFile(fileHandle); }; @@ -56,7 +56,7 @@ class FileSystemTest : public testing::Test { auto result = FileSystem::openTemporaryFile("tempTestFile"_s); m_tempFilePath = result.first; auto handle = result.second; - FileSystem::writeToFile(handle, FileSystemTestData.span8()); + FileSystem::writeToFile(handle, byteCast(FileSystemTestData.span8())); FileSystem::closeFile(handle); m_tempFileSymlinkPath = FileSystem::createTemporaryFile("tempTestFile-symlink"_s); @@ -237,7 +237,7 @@ TEST_F(FileSystemTest, openExistingFileTruncate) // Check the existing file WAS truncated when the operation succeded. EXPECT_EQ(FileSystem::fileSize(tempFilePath()), 0); // Write data to it and check the file size grows. - FileSystem::writeToFile(handle, FileSystemTestData.span8()); + FileSystem::writeToFile(handle, byteCast(FileSystemTestData.span8())); EXPECT_EQ(FileSystem::fileSize(tempFilePath()), strlen(FileSystemTestData)); FileSystem::closeFile(handle); } @@ -257,8 +257,8 @@ TEST_F(FileSystemTest, openExistingFileReadWrite) // ReadWrite mode shouldn't truncate the contents of the file. EXPECT_EQ(FileSystem::fileSize(tempFilePath()), strlen(FileSystemTestData)); // Write data to it and check the file size grows. - FileSystem::writeToFile(handle, FileSystemTestData.span8()); - FileSystem::writeToFile(handle, FileSystemTestData.span8()); + FileSystem::writeToFile(handle, byteCast(FileSystemTestData.span8())); + FileSystem::writeToFile(handle, byteCast(FileSystemTestData.span8())); EXPECT_EQ(FileSystem::fileSize(tempFilePath()), strlen(FileSystemTestData) * 2); FileSystem::closeFile(handle); } @@ -451,7 +451,7 @@ TEST_F(FileSystemTest, deleteEmptyDirectoryContainingDSStoreFile) // Create .DSStore file. auto dsStorePath = FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), ".DS_Store"_s); auto dsStoreHandle = FileSystem::openFile(dsStorePath, FileSystem::FileOpenMode::Truncate); - FileSystem::writeToFile(dsStoreHandle, FileSystemTestData.span8()); + FileSystem::writeToFile(dsStoreHandle, byteCast(FileSystemTestData.span8())); FileSystem::closeFile(dsStoreHandle); EXPECT_TRUE(FileSystem::fileExists(dsStorePath)); @@ -467,14 +467,14 @@ TEST_F(FileSystemTest, deleteEmptyDirectoryOnNonEmptyDirectory) // Create .DSStore file. auto dsStorePath = FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), ".DS_Store"_s); auto dsStoreHandle = FileSystem::openFile(dsStorePath, FileSystem::FileOpenMode::Truncate); - FileSystem::writeToFile(dsStoreHandle, FileSystemTestData.span8()); + FileSystem::writeToFile(dsStoreHandle, byteCast(FileSystemTestData.span8())); FileSystem::closeFile(dsStoreHandle); EXPECT_TRUE(FileSystem::fileExists(dsStorePath)); // Create a dummy file. auto dummyFilePath = FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "dummyFile"_s); auto dummyFileHandle = FileSystem::openFile(dummyFilePath, FileSystem::FileOpenMode::Truncate); - FileSystem::writeToFile(dummyFileHandle, FileSystemTestData.span8()); + FileSystem::writeToFile(dummyFileHandle, byteCast(FileSystemTestData.span8())); FileSystem::closeFile(dummyFileHandle); EXPECT_TRUE(FileSystem::fileExists(dummyFilePath)); @@ -542,7 +542,7 @@ TEST_F(FileSystemTest, moveDirectory) EXPECT_TRUE(FileSystem::makeAllDirectories(temporaryTestFolder)); auto testFilePath = FileSystem::pathByAppendingComponent(temporaryTestFolder, "testFile"_s); auto fileHandle = FileSystem::openFile(testFilePath, FileSystem::FileOpenMode::Truncate); - FileSystem::writeToFile(fileHandle, FileSystemTestData.span8()); + FileSystem::writeToFile(fileHandle, byteCast(FileSystemTestData.span8())); FileSystem::closeFile(fileHandle); EXPECT_TRUE(FileSystem::fileExists(testFilePath)); @@ -751,7 +751,7 @@ static void runGetFileModificationTimeTest(const String& path, Function("foo"_span)); FileSystem::closeFile(fileHandle); auto newModificationTime = fileModificationTime(path); @@ -934,8 +934,8 @@ TEST_F(FileSystemTest, readEntireFile) auto buffer = FileSystem::readEntireFile(tempFilePath()); EXPECT_TRUE(buffer); - auto contents = String::adopt(WTFMove(buffer.value())); - EXPECT_STREQ(contents.utf8().data(), FileSystemTestData); + auto contents = String { byteCast(buffer.value().span()) }.utf8(); + EXPECT_STREQ(contents.data(), FileSystemTestData); } TEST_F(FileSystemTest, makeSafeToUseMemoryMapForPath) diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp index 7b3568f3e9e9d..ad3393dab25d1 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp @@ -753,12 +753,12 @@ TEST(WTF, StaticPrivateSymbolImpl) TEST(WTF, ExternalStringImplCreate8bit) { - constexpr Latin1Character buffer[] = "hello"; + constexpr char buffer[] = "hello"; constexpr size_t bufferStringLength = sizeof(buffer) - 1; bool freeFunctionCalled = false; { - auto external = ExternalStringImpl::create({ buffer, bufferStringLength }, [&freeFunctionCalled](ExternalStringImpl* externalStringImpl, void* buffer, unsigned bufferSize) mutable { + auto external = ExternalStringImpl::create({ byteCast(&buffer[0]), bufferStringLength }, [&freeFunctionCalled](ExternalStringImpl* externalStringImpl, void* buffer, unsigned bufferSize) mutable { freeFunctionCalled = true; }); @@ -767,7 +767,7 @@ TEST(WTF, ExternalStringImplCreate8bit) ASSERT_FALSE(external->isSymbol()); ASSERT_FALSE(external->isAtom()); ASSERT_EQ(external->length(), bufferStringLength); - ASSERT_EQ(external->span8().data(), buffer); + ASSERT_EQ(byteCast(external->span8().data()), buffer); } ASSERT_TRUE(freeFunctionCalled); @@ -804,12 +804,12 @@ TEST(WTF, StringImplNotExternal) TEST(WTF, ExternalStringAtom) { - constexpr Latin1Character buffer[] = "hello"; + constexpr char buffer[] = "hello"; constexpr size_t bufferStringLength = sizeof(buffer) - 1; bool freeFunctionCalled = false; { - auto external = ExternalStringImpl::create({ buffer, bufferStringLength }, [&freeFunctionCalled](ExternalStringImpl* externalStringImpl, void* buffer, unsigned bufferSize) mutable { + auto external = ExternalStringImpl::create(byteCast(std::span { buffer, bufferStringLength }), [&freeFunctionCalled](ExternalStringImpl* externalStringImpl, void* buffer, unsigned bufferSize) mutable { freeFunctionCalled = true; }); @@ -818,7 +818,7 @@ TEST(WTF, ExternalStringAtom) ASSERT_FALSE(external->isSymbol()); ASSERT_TRUE(external->is8Bit()); ASSERT_EQ(external->length(), bufferStringLength); - ASSERT_EQ(external->span8().data(), buffer); + ASSERT_EQ(byteCast(external->span8().data()), buffer); auto result = AtomStringImpl::lookUp(external.ptr()); ASSERT_FALSE(result); diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp index 2ea6a6555b45d..0691fb6743ead 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp @@ -393,10 +393,10 @@ TEST(WTF, StringViewEqualIgnoringASCIICaseWithEmpty) TEST(WTF, StringViewEqualIgnoringASCIICaseWithLatin1Characters) { - RefPtr a = StringImpl::create(std::span { reinterpret_cast("aBcéeFG"), 7 }); - RefPtr b = StringImpl::create(std::span { reinterpret_cast("ABCÉEFG"), 7 }); - RefPtr c = StringImpl::create(std::span { reinterpret_cast("ABCéEFG"), 7 }); - RefPtr d = StringImpl::create(std::span { reinterpret_cast("abcéefg"), 7 }); + RefPtr a = StringImpl::create(byteCast(std::span { "aBcéeFG", 7 })); + RefPtr b = StringImpl::create(byteCast(std::span { "ABCÉEFG", 7 })); + RefPtr c = StringImpl::create(byteCast(std::span { "ABCéEFG", 7 })); + RefPtr d = StringImpl::create(byteCast(std::span { "abcéefg", 7 })); StringView stringViewA(*a.get()); StringView stringViewB(*b.get()); StringView stringViewC(*c.get()); diff --git a/Tools/TestWebKitAPI/Tests/WebCore/PushMessageCrypto.cpp b/Tools/TestWebKitAPI/Tests/WebCore/PushMessageCrypto.cpp index 17c937bc5ddc7..6b584d9a466a2 100644 --- a/Tools/TestWebKitAPI/Tests/WebCore/PushMessageCrypto.cpp +++ b/Tools/TestWebKitAPI/Tests/WebCore/PushMessageCrypto.cpp @@ -30,13 +30,21 @@ #include namespace TestWebKitAPI { + using namespace WebCore::PushCrypto; -static Vector mustBase64URLDecode(const String& encoded) +static Vector mustBase64URLDecode(ASCIILiteral encoded) { return base64URLDecode(encoded).value(); } +static StringView stringView(const std::optional>& vector) +{ + if (!vector) + return ""_s; + return StringView { byteCast(vector->span()) }; +} + static ClientKeys makeAES128GCMClientKeys(void) { // Example values from RFC8291 Section 5. @@ -59,8 +67,7 @@ TEST(PushMessageCrypto, AES128GCMPayloadWithMinimalPadding) auto result = decryptAES128GCMPayload(clientKeys, payload); ASSERT_TRUE(result.has_value()); - auto actual = String::adopt(WTFMove(*result)); - ASSERT_EQ("When I grow up, I want to be a watermelon"_s, actual); + EXPECT_EQ("When I grow up, I want to be a watermelon"_s, stringView(result)); } TEST(PushMessageCrypto, AES128GCMPayloadWithPadding) @@ -71,8 +78,7 @@ TEST(PushMessageCrypto, AES128GCMPayloadWithPadding) auto result = decryptAES128GCMPayload(clientKeys, payload); ASSERT_TRUE(result.has_value()); - auto actual = String::adopt(WTFMove(*result)); - ASSERT_EQ("foobar"_s, actual); + EXPECT_EQ("foobar"_s, stringView(result)); } TEST(PushMessageCrypto, AES128GCMPayloadWithIncorrectPadding) @@ -118,8 +124,7 @@ TEST(PushMessageCrypto, AESGCMPayloadWithMinimalPadding) auto result = decryptAESGCMPayload(clientKeys, serverPublicKey, salt, payload); ASSERT_TRUE(result.has_value()); - auto actual = String::adopt(WTFMove(*result)); - ASSERT_EQ("I am the walrus"_s, actual); + EXPECT_EQ("I am the walrus"_s, stringView(result)); } TEST(PushMessageCrypto, AESGCMPayloadWithPadding) @@ -132,8 +137,7 @@ TEST(PushMessageCrypto, AESGCMPayloadWithPadding) auto result = decryptAESGCMPayload(clientKeys, serverPublicKey, salt, payload); ASSERT_TRUE(result.has_value()); - auto actual = String::adopt(WTFMove(*result)); - ASSERT_EQ("foobar"_s, actual); + EXPECT_EQ("foobar"_s, stringView(result)); } TEST(PushMessageCrypto, AESGCMPayloadWithIncorrectPadding) diff --git a/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp b/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp index 6e5bf6f5d04cb..97b8f6d5487c2 100644 --- a/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp +++ b/Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp @@ -53,7 +53,7 @@ TEST_F(FragmentedSharedBufferTest, createWithContentsOfExistingFile) auto buffer = SharedBuffer::createWithContentsOfFile(tempFilePath()); ASSERT_NOT_NULL(buffer); EXPECT_TRUE(buffer->size() == strlen(FragmentedSharedBufferTest::testData())); - EXPECT_TRUE(String::fromLatin1(FragmentedSharedBufferTest::testData()) == String(buffer->makeContiguous()->span())); + EXPECT_TRUE(String::fromLatin1(FragmentedSharedBufferTest::testData()) == String(byteCast(buffer->makeContiguous()->span()))); } TEST_F(FragmentedSharedBufferTest, createWithContentsOfExistingEmptyFile) @@ -318,12 +318,12 @@ TEST_F(FragmentedSharedBufferTest, read) auto check = [](FragmentedSharedBuffer& sharedBuffer) { Vector data = sharedBuffer.read(4, 3); EXPECT_EQ(data.size(), 3u); - EXPECT_EQ(StringView(data.subspan(0, 3)), " is"_s); + EXPECT_EQ(" is"_s, StringView(byteCast(data.subspan(0, 3)))); data = sharedBuffer.read(4, 1000); EXPECT_EQ(data.size(), 18u); - EXPECT_EQ(StringView(data.subspan(0, 18)), " is a simple test."_s); + EXPECT_EQ(" is a simple test."_s, StringView(byteCast(data.subspan(0, 18)))); }; auto sharedBuffer = SharedBuffer::create(simpleText); check(sharedBuffer); @@ -421,8 +421,8 @@ TEST_F(SharedBufferChunkReaderTest, includeSeparator) check(builder.take()); for (size_t i = 0; i < 256; ++i) { - Latin1Character c = i; - builder.append(std::span { &c, 1 }); + const uint8_t byte = i; + builder.append(std::span { &byte, 1 }); } check(builder.take()); } @@ -441,12 +441,12 @@ TEST_F(SharedBufferChunkReaderTest, peekData) size_t read = chunkReader.peek(data, 3); EXPECT_EQ(read, 3u); - EXPECT_EQ(String({ data.data(), 3 }), " is"_s); + EXPECT_EQ(String(byteCast({ data.data(), 3 })), " is"_s); read = chunkReader.peek(data, 1000); EXPECT_EQ(read, 18u); - EXPECT_EQ(String({ data.data(), 18 }), " is a simple test."_s); + EXPECT_EQ(String(byteCast({ data.data(), 18 })), " is a simple test."_s); // Ensure the cursor has not changed. chunk = chunkReader.nextChunkAsUTF8StringWithLatin1Fallback(); diff --git a/Tools/TestWebKitAPI/Tests/WebCore/SharedBufferTest.cpp b/Tools/TestWebKitAPI/Tests/WebCore/SharedBufferTest.cpp index 0a172328a304b..b0437dd334c1d 100644 --- a/Tools/TestWebKitAPI/Tests/WebCore/SharedBufferTest.cpp +++ b/Tools/TestWebKitAPI/Tests/WebCore/SharedBufferTest.cpp @@ -38,7 +38,7 @@ void FragmentedSharedBufferTest::SetUp() // create temp file auto result = FileSystem::openTemporaryFile("tempTestFile"_s); m_tempFilePath = result.first; - FileSystem::writeToFile(result.second, testData().span8()); + FileSystem::writeToFile(result.second, byteCast(testData().span8())); FileSystem::closeFile(result.second); m_tempEmptyFilePath = FileSystem::createTemporaryFile("tempEmptyTestFile"_s); diff --git a/Tools/TestWebKitAPI/Tests/WebCore/curl/CurlMultipartHandleTests.cpp b/Tools/TestWebKitAPI/Tests/WebCore/curl/CurlMultipartHandleTests.cpp index 214b3f4b1ac52..21ec5ba1070ce 100644 --- a/Tools/TestWebKitAPI/Tests/WebCore/curl/CurlMultipartHandleTests.cpp +++ b/Tools/TestWebKitAPI/Tests/WebCore/curl/CurlMultipartHandleTests.cpp @@ -153,7 +153,7 @@ TEST(CurlMultipartHandleTests, SimpleMessage) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -184,7 +184,7 @@ TEST(CurlMultipartHandleTests, NoHeader) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 0); handle->completeHeaderProcessing(); @@ -206,7 +206,7 @@ TEST(CurlMultipartHandleTests, NoBody) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -239,7 +239,7 @@ TEST(CurlMultipartHandleTests, TransportPadding) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -271,7 +271,7 @@ TEST(CurlMultipartHandleTests, NoEndOfBoundary) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -305,7 +305,7 @@ TEST(CurlMultipartHandleTests, NoEndOfBoundaryAfterCompleted) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); @@ -339,7 +339,7 @@ TEST(CurlMultipartHandleTests, NoCloseDelimiter) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -374,7 +374,7 @@ TEST(CurlMultipartHandleTests, NoCloseDelimiterAfterCompleted) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); @@ -408,7 +408,7 @@ TEST(CurlMultipartHandleTests, CloseDelimiter) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -441,7 +441,7 @@ TEST(CurlMultipartHandleTests, CloseDelimiterAfterCompleted) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); @@ -476,10 +476,10 @@ TEST(CurlMultipartHandleTests, DivideFirstDelimiter) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 0); - handle->didReceiveMessage(span(nextData)); + handle->didReceiveMessage(byteCast(span(nextData))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -513,7 +513,7 @@ TEST(CurlMultipartHandleTests, DivideSecondDelimiter) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -521,7 +521,7 @@ TEST(CurlMultipartHandleTests, DivideSecondDelimiter) handle->completeHeaderProcessing(); EXPECT_EQ(client.headers().size(), 0); - handle->didReceiveMessage(span(nextData)); + handle->didReceiveMessage(byteCast(span(nextData))); EXPECT_TRUE(!memcmp(static_cast(client.data().data()), "ABCDEF", 6)); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/html\r\n"_s); @@ -550,7 +550,7 @@ TEST(CurlMultipartHandleTests, DivideLastDelimiter) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -566,7 +566,7 @@ TEST(CurlMultipartHandleTests, DivideLastDelimiter) EXPECT_TRUE(!memcmp(static_cast(client.data().data()), "didReceiveMessage(span(nextData)); + handle->didReceiveMessage(byteCast(span(nextData))); EXPECT_TRUE(!memcmp(static_cast(client.data().data()), "", 13)); handle->didCompleteMessage(); @@ -588,7 +588,7 @@ TEST(CurlMultipartHandleTests, DivideCloseDelimiter) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -604,7 +604,7 @@ TEST(CurlMultipartHandleTests, DivideCloseDelimiter) EXPECT_TRUE(!memcmp(static_cast(client.data().data()), "didReceiveMessage(span(nextData)); + handle->didReceiveMessage(byteCast(span(nextData))); EXPECT_TRUE(!memcmp(static_cast(client.data().data()), "", 13)); handle->didCompleteMessage(); @@ -627,7 +627,7 @@ TEST(CurlMultipartHandleTests, DivideTransportPadding) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -636,7 +636,7 @@ TEST(CurlMultipartHandleTests, DivideTransportPadding) EXPECT_EQ(client.headers().size(), 0); EXPECT_TRUE(!memcmp(static_cast(client.data().data()), "ABCDEF", 6)); - handle->didReceiveMessage(span(nextData)); + handle->didReceiveMessage(byteCast(span(nextData))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/html\r\n"_s); client.clear(); @@ -664,7 +664,7 @@ TEST(CurlMultipartHandleTests, DivideHeader) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -673,7 +673,7 @@ TEST(CurlMultipartHandleTests, DivideHeader) EXPECT_TRUE(!memcmp(static_cast(client.data().data()), "ABCDEF", 6)); EXPECT_EQ(client.headers().size(), 0); - handle->didReceiveMessage(span(nextData)); + handle->didReceiveMessage(byteCast(span(nextData))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/html\r\n"_s); client.clear(); @@ -703,7 +703,7 @@ TEST(CurlMultipartHandleTests, DivideBody) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); client.clear(); @@ -711,7 +711,7 @@ TEST(CurlMultipartHandleTests, DivideBody) handle->completeHeaderProcessing(); EXPECT_EQ(client.data().size(), 0); - handle->didReceiveMessage(span(secondData)); + handle->didReceiveMessage(byteCast(span(secondData))); EXPECT_TRUE(!memcmp(static_cast(client.data().data()), "ABCDEF", 6)); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/html\r\n"_s); @@ -720,7 +720,7 @@ TEST(CurlMultipartHandleTests, DivideBody) handle->completeHeaderProcessing(); EXPECT_EQ(client.data().size(), 0); - handle->didReceiveMessage(span(lastData)); + handle->didReceiveMessage(byteCast(span(lastData))); EXPECT_TRUE(!memcmp(static_cast(client.data().data()), "", 13)); EXPECT_TRUE(!client.complete()); @@ -744,17 +744,17 @@ TEST(CurlMultipartHandleTests, CompleteWhileHeaderProcessing) auto curlResponse = createCurlResponse(); auto handle = CurlMultipartHandle::createIfNeeded(client, curlResponse); - handle->didReceiveMessage(span(data)); + handle->didReceiveMessage(byteCast(span(data))); EXPECT_EQ(client.headers().size(), 1); EXPECT_TRUE(client.headers().at(0) == "Content-type: text/plain\r\n"_s); EXPECT_EQ(client.data().size(), 0); client.clear(); - handle->didReceiveMessage(span(secondData)); + handle->didReceiveMessage(byteCast(span(secondData))); EXPECT_EQ(client.headers().size(), 0); EXPECT_EQ(client.data().size(), 0); - handle->didReceiveMessage(span(lastData)); + handle->didReceiveMessage(byteCast(span(lastData))); EXPECT_EQ(client.headers().size(), 0); EXPECT_EQ(client.data().size(), 0); diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm index bcd30643004b6..005cff6ad6b39 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm @@ -984,7 +984,7 @@ void injectPushMessage(NSDictionary *apsUserInfo) @"userInfo": apsUserInfo }; - String message { span([NSJSONSerialization dataWithJSONObject:obj options:0 error:nullptr]) }; + String message { byteCast(span([NSJSONSerialization dataWithJSONObject:obj options:0 error:nullptr])) }; auto utilityConnection = createAndConfigureConnectionToService("org.webkit.webpushtestdaemon.service"); auto sender = WebPushXPCConnectionMessageSender { utilityConnection.get() }; From e4caf887ab20fc789ab4f32758b3a4390fecfa7f Mon Sep 17 00:00:00 2001 From: Darin Adler Date: Fri, 31 Oct 2025 17:20:31 -0700 Subject: [PATCH 13/22] Add constructor for String that takes span https://bugs.webkit.org/show_bug.cgi?id=301739 rdar://163764627 Reviewed by Sam Weinig. * Source/WTF/wtf/Logger.h: (WTF::LogArgument::toString): Added overload that takes std::span. * Source/WTF/wtf/PrintStream.cpp: (WTF::printInternal): Added overload that takes std::span. * Source/WTF/wtf/PrintStream.h: Ditto. * Source/WTF/wtf/text/StringImpl.cpp: (WTF::StringImpl::create): Added overload that takes std::span. * Source/WTF/wtf/text/StringImpl.h: Ditto. * Source/WTF/wtf/text/WTFString.cpp: (WTF::String::String): Added overload that takes std::span. (WTF::fromUTF8Impl): Deleted. (WTF::String::fromUTF8): Changed to call the constructor. (WTF::String::fromUTF8ReplacingInvalidSequences): Moved code here from the fromUTF8Impl function. (WTF::String::fromUTF8WithLatin1Fallback): Call the constructor rather than the fromUTF8 function. * Source/WTF/wtf/text/WTFString.h: Added constructor that takes std::span. Canonical link: https://commits.webkit.org/302417@main Signed-off-by: Xabier Rodriguez Calvar --- Source/WTF/wtf/Logger.h | 1 + Source/WTF/wtf/PrintStream.cpp | 5 ++++ Source/WTF/wtf/PrintStream.h | 1 + Source/WTF/wtf/text/StringImpl.cpp | 22 ++++++++++++++++ Source/WTF/wtf/text/StringImpl.h | 3 +++ Source/WTF/wtf/text/WTFString.cpp | 41 ++++++++++++++---------------- Source/WTF/wtf/text/WTFString.h | 3 +++ 7 files changed, 54 insertions(+), 22 deletions(-) diff --git a/Source/WTF/wtf/Logger.h b/Source/WTF/wtf/Logger.h index 9f0de7bc2bdf5..19189285e6049 100644 --- a/Source/WTF/wtf/Logger.h +++ b/Source/WTF/wtf/Logger.h @@ -57,6 +57,7 @@ struct LogArgument { template static std::enable_if_t, StringBuilder*>, String> toString(StringBuilder* argument) { return argument->toString(); } template static std::enable_if_t, String> toString(const char* argument) { return String::fromLatin1(argument); } template static std::enable_if_t, String> toString(ASCIILiteral argument) { return argument; } + template static std::enable_if_t>, String> toString(std::span argument) { return argument; } #ifdef __OBJC__ template static std::enable_if_t>, String> toString(NSError *argument) { return String(argument.localizedDescription); } template static std::enable_if_t>, String> toString(NSObject *argument) { return String(argument.description); } diff --git a/Source/WTF/wtf/PrintStream.cpp b/Source/WTF/wtf/PrintStream.cpp index 250febc4b75d6..01f00ae5c83de 100644 --- a/Source/WTF/wtf/PrintStream.cpp +++ b/Source/WTF/wtf/PrintStream.cpp @@ -119,6 +119,11 @@ void printInternal(PrintStream& out, const StringImpl* string) printExpectedCStringHelper(out, "StringImpl*", string->tryGetUTF8()); } +void printInternal(PrintStream& stream, std::span codeUnits) +{ + printInternal(stream, byteCast(codeUnits)); +} + void printInternal(PrintStream& out, bool value) { out.print(boolForPrinting(value)); diff --git a/Source/WTF/wtf/PrintStream.h b/Source/WTF/wtf/PrintStream.h index 352637c34f52f..aa8e5961f5166 100644 --- a/Source/WTF/wtf/PrintStream.h +++ b/Source/WTF/wtf/PrintStream.h @@ -113,6 +113,7 @@ WTF_EXPORT_PRIVATE void printInternal(PrintStream&, const CString&); WTF_EXPORT_PRIVATE void printInternal(PrintStream&, const String&); WTF_EXPORT_PRIVATE void printInternal(PrintStream&, const AtomString&); WTF_EXPORT_PRIVATE void printInternal(PrintStream&, const StringImpl*); +WTF_EXPORT_PRIVATE void printInternal(PrintStream&, std::span); inline void printInternal(PrintStream& out, const AtomStringImpl* value) { printInternal(out, std::bit_cast(value)); } inline void printInternal(PrintStream& out, const UniquedStringImpl* value) { printInternal(out, std::bit_cast(value)); } inline void printInternal(PrintStream& out, const UniquedStringImpl& value) { printInternal(out, &value); } diff --git a/Source/WTF/wtf/text/StringImpl.cpp b/Source/WTF/wtf/text/StringImpl.cpp index 183a16a8dce31..155dd8f5a00c4 100644 --- a/Source/WTF/wtf/text/StringImpl.cpp +++ b/Source/WTF/wtf/text/StringImpl.cpp @@ -316,6 +316,28 @@ Ref StringImpl::create(std::span characters) return createInternal(characters); } +RefPtr StringImpl::create(std::span codeUnits) +{ + RELEASE_ASSERT(codeUnits.size() <= String::MaxLength); + + if (!codeUnits.data()) + return nullptr; + if (codeUnits.empty()) + return empty(); + + if (charactersAreAllASCII(codeUnits)) + return create(byteCast(codeUnits)); + + Vector buffer(codeUnits.size()); + + auto result = Unicode::convert(codeUnits, buffer.mutableSpan()); + if (result.code != Unicode::ConversionResultCode::Success) + return nullptr; + + RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.buffer.size() <= codeUnits.size()); + return create(result.buffer); +} + Ref StringImpl::createStaticStringImpl(std::span characters) { if (characters.empty()) diff --git a/Source/WTF/wtf/text/StringImpl.h b/Source/WTF/wtf/text/StringImpl.h index 0f87ef786f879..f4d712100876c 100644 --- a/Source/WTF/wtf/text/StringImpl.h +++ b/Source/WTF/wtf/text/StringImpl.h @@ -261,6 +261,9 @@ class StringImpl : private StringImplShape { ALWAYS_INLINE static Ref create(std::span characters) { return create(byteCast(characters)); } WTF_EXPORT_PRIVATE static Ref create8BitIfPossible(std::span); + // Construct a string with UTF-8 data, null if it contains invalid UTF-8 sequences. + WTF_EXPORT_PRIVATE static RefPtr create(std::span); + // Not using create() naming to encourage developers to call create(ASCIILiteral) when they have a string literal. ALWAYS_INLINE static Ref createFromCString(const char* characters) { return create(WTF::span8(characters)); } diff --git a/Source/WTF/wtf/text/WTFString.cpp b/Source/WTF/wtf/text/WTFString.cpp index 8db7dc964e5aa..5df22edf4053d 100644 --- a/Source/WTF/wtf/text/WTFString.cpp +++ b/Source/WTF/wtf/text/WTFString.cpp @@ -51,6 +51,12 @@ String::String(std::span characters) { } +// Construct a string with UTF-8 data. +String::String(std::span characters) + : m_impl(StringImpl::create(characters)) +{ +} + // Construct a string with Latin-1 data. String::String(std::span characters) : m_impl(characters.data() ? RefPtr { StringImpl::create(byteCast(characters)) } : nullptr) @@ -464,9 +470,16 @@ void String::convertTo16Bit() *this = WTFMove(convertedString); } -template -String fromUTF8Impl(std::span string) +String String::fromUTF8(std::span codeUnits) +{ + return codeUnits; +} + +String String::fromUTF8ReplacingInvalidSequences(std::span string) { + if (!string.data()) + return { }; + RELEASE_ASSERT(string.size() <= String::MaxLength); if (string.empty()) @@ -475,11 +488,9 @@ String fromUTF8Impl(std::span string) if (charactersAreAllASCII(string)) return StringImpl::create(spanReinterpretCast(string)); - Vector buffer(string.size()); - - auto result = replaceInvalidSequences - ? Unicode::convertReplacingInvalidSequences(string, buffer.mutableSpan()) - : Unicode::convert(string, buffer.mutableSpan()); + Vector buffer(string.size()); + + auto result = Unicode::convertReplacingInvalidSequences(string, buffer.mutableSpan()); if (result.code != Unicode::ConversionResultCode::Success) return { }; @@ -487,23 +498,9 @@ String fromUTF8Impl(std::span string) return StringImpl::create(result.buffer); } -String String::fromUTF8(std::span string) -{ - if (!string.data()) - return { }; - return fromUTF8Impl(string); -} - -String String::fromUTF8ReplacingInvalidSequences(std::span characters) -{ - if (!characters.data()) - return { }; - return fromUTF8Impl(characters); -} - String String::fromUTF8WithLatin1Fallback(std::span string) { - String utf8 = fromUTF8(string); + String utf8 { string }; if (!utf8) { // Do this assertion before chopping the size_t down to unsigned. RELEASE_ASSERT(string.size() <= String::MaxLength); diff --git a/Source/WTF/wtf/text/WTFString.h b/Source/WTF/wtf/text/WTFString.h index c7ff1c199fe4c..dd5fcb0f41f60 100644 --- a/Source/WTF/wtf/text/WTFString.h +++ b/Source/WTF/wtf/text/WTFString.h @@ -64,6 +64,9 @@ class String final { WTF_EXPORT_PRIVATE String(std::span characters); ALWAYS_INLINE static String fromLatin1(const char* characters) { return String { characters }; } + // Construct a string with UTF-8 data, null string if it contains invalid UTF-8 sequences. + WTF_EXPORT_PRIVATE String(std::span); + // Construct a string referencing an existing StringImpl. String(StringImpl&); String(StringImpl*); From a710402284709cc9f62fc044797d8dc825b37c65 Mon Sep 17 00:00:00 2001 From: Xabier Rodriguez-Calvar Date: Thu, 13 Nov 2025 15:02:24 -0800 Subject: [PATCH 14/22] [WTF] Make CStringView handle only null termination related methods and add some helpers for spans to StringCommon https://bugs.webkit.org/show_bug.cgi?id=299946 Reviewed by Darin Adler. Improved several comparisons, like starts, ends, contains, find, both case and aware and not. Also some more useful conversions and parsing. For this, some more tweaks and templating was needed as many string management methods consider Latin1Character only and CStringView handles char8_t. Fly-by: fix return value of isEmpty to be bool instead of size_t and renamed length into lengthInBytes. GStreamer code using CStringView already was adapted to this. Tests: Tools/TestWebKitAPI/Tests/WTF/CString.cpp Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp * Source/WTF/wtf/StdLibExtras.h: (WTF::find): (WTF::contains): (WTF::ByteCastTraits::cast): (WTF::ByteCastTraits --- Source/WTF/wtf/StdLibExtras.h | 71 ++++- Source/WTF/wtf/text/ASCIILiteral.h | 14 +- Source/WTF/wtf/text/CString.cpp | 26 ++ Source/WTF/wtf/text/CString.h | 6 + Source/WTF/wtf/text/CStringView.cpp | 9 +- Source/WTF/wtf/text/CStringView.h | 28 +- Source/WTF/wtf/text/ParsingUtilities.h | 50 ++++ Source/WTF/wtf/text/StringCommon.h | 242 +++++++++++++++++- .../WTF/wtf/text/StringToIntegerConversion.h | 61 +++-- .../gstreamer/GStreamerMediaEndpoint.cpp | 2 +- .../gstreamer/GStreamerRtpReceiverBackend.cpp | 6 +- .../GStreamerRtpTransceiverBackend.cpp | 2 +- .../gstreamer/GStreamerStatsCollector.cpp | 38 +-- .../gstreamer/GStreamerWebRTCUtils.cpp | 14 +- .../graphics/gstreamer/GStreamerCommon.cpp | 2 +- .../gstreamer/GStreamerRegistryScanner.cpp | 16 +- .../gstreamer/MediaPlayerPrivateGStreamer.cpp | 9 +- ...bKitCommonEncryptionDecryptorGStreamer.cpp | 2 +- .../graphics/gstreamer/mse/AppendPipeline.cpp | 4 +- .../gstreamer/GStreamerElementHarness.cpp | 2 +- .../VideoEncoderPrivateGStreamer.cpp | 6 +- .../gstreamer/GStreamerAudioRTPPacketizer.cpp | 9 +- .../GStreamerCaptureDeviceManager.cpp | 2 +- .../GStreamerIncomingTrackProcessor.cpp | 16 +- .../gstreamer/GStreamerRTPPacketizer.cpp | 2 +- .../gstreamer/GStreamerVideoCapturer.cpp | 8 +- .../gstreamer/GStreamerVideoRTPPacketizer.cpp | 9 +- .../RealtimeOutgoingMediaSourceGStreamer.cpp | 2 +- Tools/TestWebKitAPI/Tests/WTF/CString.cpp | 24 ++ Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp | 35 ++- .../TestWebKitAPI/Tests/WTF/StringBuilder.cpp | 6 + .../TestWebKitAPI/Tests/WTF/StringCommon.cpp | 108 ++++++++ 32 files changed, 673 insertions(+), 158 deletions(-) diff --git a/Source/WTF/wtf/StdLibExtras.h b/Source/WTF/wtf/StdLibExtras.h index 35a5e57b63cd0..94a76962e798a 100644 --- a/Source/WTF/wtf/StdLibExtras.h +++ b/Source/WTF/wtf/StdLibExtras.h @@ -37,6 +37,7 @@ #include #include #include +#include #include // Use this macro to declare and define a debug-only global variable that may have a @@ -779,31 +780,77 @@ int compareSpans(std::span a, std::span b) return result; } -template concept ByteType = sizeof(T) == 1 && ((std::is_integral_v && !std::same_as) || std::same_as) && !std::is_const_v; +template +concept TriviallyComparableCodeUnits = std::is_same_v, std::remove_const_t> || (!std::is_same_v, char8_t> && !std::is_same_v, char8_t>); + +template +concept CanBeConstByteType = sizeof(T) == 1 && ((std::is_integral_v && !std::same_as) || std::same_as); + +template +concept TriviallyComparableOneByteCodeUnits = TriviallyComparableCodeUnits && CanBeConstByteType && CanBeConstByteType; + +// Returns the index of the first occurrence of |needed| in |haystack| or notFound if not present. +template + requires(TriviallyComparableOneByteCodeUnits) +size_t find(std::span haystack, std::span needle) +{ +#if !HAVE(MEMMEM) + if (needle.empty()) + return 0; + + if (haystack.size() < needle.size()) + return notFound; + + size_t lastPossiblePosition = haystack.size() - needle.size(); + + for (size_t i = 0; i <= lastPossiblePosition; ++i) { + auto candidateSpan = haystack.subspan(i, needle.size()); + if (equalSpans(candidateSpan, needle)) + return i; + } + + return notFound; +#else + auto* result = static_cast(memmem(haystack.data(), haystack.size(), needle.data(), needle.size())); // NOLINT + if (!result) + return notFound; + return result - haystack.data(); +#endif +} + +template + requires(TriviallyComparableOneByteCodeUnits) +size_t contains(std::span haystack, std::span needle) +{ + return find(haystack, needle) != notFound; +} + +template +concept NonConstByteType = CanBeConstByteType && !std::is_const_v; template struct ByteCastTraits; -template struct ByteCastTraits { - template static constexpr U cast(T character) { return static_cast(character); } +template struct ByteCastTraits { + template static constexpr U cast(T character) { return static_cast(character); } }; -template struct ByteCastTraits { - template static constexpr auto cast(T* pointer) { return std::bit_cast(pointer); } +template struct ByteCastTraits { + template static constexpr auto cast(T* pointer) { return std::bit_cast(pointer); } }; -template struct ByteCastTraits { - template static constexpr auto cast(const T* pointer) { return std::bit_cast(pointer); } +template struct ByteCastTraits { + template static constexpr auto cast(const T* pointer) { return std::bit_cast(pointer); } }; -template struct ByteCastTraits> { - template static constexpr auto cast(std::span span) { return spanReinterpretCast(span); } +template struct ByteCastTraits> { + template static constexpr auto cast(std::span span) { return spanReinterpretCast(span); } }; -template struct ByteCastTraits> { - template static constexpr auto cast(std::span span) { return spanReinterpretCast(span); } +template struct ByteCastTraits> { + template static constexpr auto cast(std::span span) { return spanReinterpretCast(span); } }; -template constexpr auto byteCast(const U& value) +template constexpr auto byteCast(const U& value) { return ByteCastTraits::template cast(value); } diff --git a/Source/WTF/wtf/text/ASCIILiteral.h b/Source/WTF/wtf/text/ASCIILiteral.h index b3ee726680060..8d340c30eb058 100644 --- a/Source/WTF/wtf/text/ASCIILiteral.h +++ b/Source/WTF/wtf/text/ASCIILiteral.h @@ -63,7 +63,9 @@ class ASCIILiteral final { constexpr const char* characters() const { return m_charactersWithNullTerminator.data(); } constexpr size_t length() const { return !m_charactersWithNullTerminator.empty() ? m_charactersWithNullTerminator.size() - 1 : 0; } - std::span span8() const { return { std::bit_cast(characters()), length() }; } + constexpr std::span span() const { return m_charactersWithNullTerminator.first(length()); } + std::span span8() const { return byteCast(m_charactersWithNullTerminator.first(length())); } + std::span spanChar8() const { return byteCast(m_charactersWithNullTerminator.first(length())); } std::span spanIncludingNullTerminator() const { return m_charactersWithNullTerminator; } size_t isEmpty() const { return m_charactersWithNullTerminator.size() <= 1; } @@ -148,6 +150,16 @@ constexpr std::span operator"" _span(const char* characte return std::span { std::bit_cast(characters), n }; } +constexpr std::span operator""_spanChar8(const char* characters, size_t n) +{ + auto span = byteCast(unsafeMakeSpan(characters, n)); +#if ASSERT_ENABLED + for (size_t i = 0, size = span.size(); i < size; ++i) + ASSERT_UNDER_CONSTEXPR_CONTEXT(isASCII(span[i])); +#endif + return span; +} + } // inline StringLiterals } // namespace WTF diff --git a/Source/WTF/wtf/text/CString.cpp b/Source/WTF/wtf/text/CString.cpp index 571a851bc0381..1e62ab3ca4ed3 100644 --- a/Source/WTF/wtf/text/CString.cpp +++ b/Source/WTF/wtf/text/CString.cpp @@ -177,4 +177,30 @@ bool CStringHash::equal(const CString& a, const CString& b) return a == b; } +enum class ASCIICase { Lower, Upper }; + +template +CString convertASCIICase(std::span input) +{ + if (input.empty()) + return CString(""_s); + + std::span characters; + auto result = CString::newUninitialized(input.size(), characters); + size_t i = 0; + for (auto character : input) + characters[i++] = type == ASCIICase::Lower ? toASCIILower(character) : toASCIIUpper(character); + return result; +} + +CString convertToASCIILowercase(std::span string) +{ + return convertASCIICase(string); +} + +CString convertToASCIIUppercase(std::span string) +{ + return convertASCIICase(string); +} + } // namespace WTF diff --git a/Source/WTF/wtf/text/CString.h b/Source/WTF/wtf/text/CString.h index 1da2ad5681d70..9770e4aec404d 100644 --- a/Source/WTF/wtf/text/CString.h +++ b/Source/WTF/wtf/text/CString.h @@ -93,6 +93,7 @@ class CString final { size_t length() const; bool isNull() const { return !m_buffer; } + bool isEmpty() const { return isNull() || m_buffer->length() <= 1; } bool isSafeToSendToAnotherThread() const; CStringBuffer* buffer() const LIFETIME_BOUND { return m_buffer.get(); } @@ -114,6 +115,9 @@ WTF_EXPORT_PRIVATE bool operator==(const CString&, const CString&); WTF_EXPORT_PRIVATE bool operator==(const CString&, const char*); WTF_EXPORT_PRIVATE bool operator<(const CString&, const CString&); +WTF_EXPORT_PRIVATE CString convertToASCIILowercase(std::span); +WTF_EXPORT_PRIVATE CString convertToASCIIUppercase(std::span); + struct CStringHash { static unsigned hash(const CString& string) { return string.hash(); } WTF_EXPORT_PRIVATE static bool equal(const CString& a, const CString& b); @@ -158,3 +162,5 @@ inline size_t CString::length() const } // namespace WTF using WTF::CString; +using WTF::convertToASCIILowercase; +using WTF::convertToASCIIUppercase; diff --git a/Source/WTF/wtf/text/CStringView.cpp b/Source/WTF/wtf/text/CStringView.cpp index 97eef8fa45278..0c0eea1c1d33c 100644 --- a/Source/WTF/wtf/text/CStringView.cpp +++ b/Source/WTF/wtf/text/CStringView.cpp @@ -30,19 +30,12 @@ #include #include -#include -#include namespace WTF { -String CStringView::toString() const -{ - return String::fromUTF8(span8()); -} - void CStringView::dump(PrintStream& out) const { - out.print(span8()); + out.print(span()); } } // namespace WTF diff --git a/Source/WTF/wtf/text/CStringView.h b/Source/WTF/wtf/text/CStringView.h index d50f72a5dfbf4..ad801bb04972e 100644 --- a/Source/WTF/wtf/text/CStringView.h +++ b/Source/WTF/wtf/text/CStringView.h @@ -34,19 +34,15 @@ #include #include #include -#include #include #include -#include namespace WTF { class PrintStream; -class String; -// This is a class designed to contain a UTF8 string, untouched. Interactions with other string classes in WebKit should -// be handled with care or perform a string conversion through the String class, with the exception of ASCIILiteral -// because ASCII characters are also UTF8. +// This is a class designed to contain a null terminated UTF8 string, untouched. It contains char8_t to avoid mixing +// incompatible encodings at compile time. class CStringView final { WTF_FORBID_HEAP_ALLOCATION; public: @@ -70,17 +66,15 @@ class CStringView final { m_spanWithNullTerminator = byteCast(literal.spanIncludingNullTerminator()); } - unsigned hash() const; bool isNull() const { return m_spanWithNullTerminator.empty(); } - // This method is designed to interface with external C functions handling UTF8 strings. Interactions with other - // strings should be done through String with the exception of ASCIILiteral because ASCII is also UTF8. + // This member function is designed to interface with external C functions handling UTF8 strings. Interactions with + // other strings should be handled by using the span. const char* utf8() const LIFETIME_BOUND { return reinterpret_cast(m_spanWithNullTerminator.data()); } - size_t length() const { return m_spanWithNullTerminator.size() > 0 ? m_spanWithNullTerminator.size() - 1 : 0; } - std::span span8() const LIFETIME_BOUND { return m_spanWithNullTerminator.first(length()); } + size_t lengthInBytes() const { return m_spanWithNullTerminator.size() > 0 ? m_spanWithNullTerminator.size() - 1 : 0; } + std::span span() const LIFETIME_BOUND { return m_spanWithNullTerminator.first(lengthInBytes()); } std::span spanIncludingNullTerminator() const LIFETIME_BOUND { return m_spanWithNullTerminator; } - size_t isEmpty() const { return m_spanWithNullTerminator.size() <= 1; } - WTF_EXPORT_PRIVATE String toString() const; + bool isEmpty() const { return m_spanWithNullTerminator.size() <= 1; } explicit operator bool() const { return !isEmpty(); } bool operator!() const { return isEmpty(); } @@ -96,16 +90,12 @@ class CStringView final { inline bool operator==(CStringView a, CStringView b) { - if (!a || !b) - return a.utf8() == b.utf8(); - return equalSpans(a.span8(), b.span8()); + return equalSpans(a.span(), b.span()); } inline bool operator==(CStringView a, ASCIILiteral b) { - if (a.isEmpty() || b.isEmpty()) - return a.utf8() == b.characters(); - return equalSpans(a.span8(), byteCast(b.span8())); + return equalSpans(a.span(), byteCast(b.span())); } inline bool operator==(ASCIILiteral a, CStringView b) diff --git a/Source/WTF/wtf/text/ParsingUtilities.h b/Source/WTF/wtf/text/ParsingUtilities.h index 3d3e4d2ea152a..439526e56eb8f 100644 --- a/Source/WTF/wtf/text/ParsingUtilities.h +++ b/Source/WTF/wtf/text/ParsingUtilities.h @@ -130,6 +130,24 @@ template bool skipExactly(std::span bool skipExactly(std::span& buffer) requires(std::is_same_v, char8_t>) +{ + if (!buffer.empty() && characterPredicate(buffer[0])) { + skip(buffer, 1); + return true; + } + return false; +} + +template bool skipExactly(std::span& buffer) requires(std::is_same_v, char>) +{ + if (!buffer.empty() && characterPredicate(buffer[0])) { + skip(buffer, 1); + return true; + } + return false; +} + template void skipUntil(StringParsingBuffer& buffer, DelimiterType delimiter) { while (buffer.hasCharactersRemaining() && *buffer != delimiter) @@ -160,6 +178,22 @@ template void skipUntil(std::span void skipUntil(std::span& data) requires(std::is_same_v, char8_t>) +{ + size_t index = 0; + while (index < data.size() && !characterPredicate(data[index])) + ++index; + skip(data, index); +} + +template void skipUntil(std::span& data) requires(std::is_same_v, char>) +{ + size_t index = 0; + while (index < data.size() && !characterPredicate(data[index])) + ++index; + skip(data, index); +} + template void skipUntil(StringParsingBuffer& buffer) { while (buffer.hasCharactersRemaining() && !characterPredicate(*buffer)) @@ -202,6 +236,22 @@ template void skipWhile(std::span void skipWhile(std::span& data) requires(std::is_same_v, char8_t>) +{ + size_t index = 0; + while (index < data.size() && characterPredicate(data[index])) + ++index; + skip(data, index); +} + +template void skipWhile(std::span& data) requires(std::is_same_v, char>) +{ + size_t index = 0; + while (index < data.size() && characterPredicate(data[index])) + ++index; + skip(data, index); +} + template void skipWhile(StringParsingBuffer& buffer) { while (buffer.hasCharactersRemaining() && characterPredicate(*buffer)) diff --git a/Source/WTF/wtf/text/StringCommon.h b/Source/WTF/wtf/text/StringCommon.h index 3b1d57f7d50a2..c0f5d82601e89 100644 --- a/Source/WTF/wtf/text/StringCommon.h +++ b/Source/WTF/wtf/text/StringCommon.h @@ -36,6 +36,7 @@ #include #include #include +#include namespace WTF { @@ -54,6 +55,11 @@ inline std::span span8(const char* string) return { byteCast(string), string ? strlen(string) : 0 }; } +inline std::span unsafeSpanChar8(const char* string) +{ + return unsafeMakeSpan(byteCast(string), string ? strlen(string) : 0); +} + inline std::span span(const char* string) { return { string, string ? strlen(string) : 0 }; @@ -79,7 +85,9 @@ template<> ALWAYS_INLINE constexpr bool isLatin1(Latin1Character) using CodeUnitMatchFunction = bool (*)(UChar); -template bool equalIgnoringASCIICase(std::span, std::span); +template + requires(TriviallyComparableCodeUnits) +bool equalIgnoringASCIICase(std::span, std::span); template bool equalIgnoringASCIICaseCommon(const StringClassA&, const StringClassB&); @@ -90,9 +98,13 @@ template bool equalLettersIgnoringASCIICaseCommon(const St bool equalIgnoringASCIICase(const char*, const char*); +template +concept OneByteCharacterType = std::is_same_v, Latin1Character> || std::is_same_v, char8_t> || std::is_same_v, char>; + // Do comparisons 8 or 4 bytes-at-a-time on architectures where it's safe. #if (CPU(X86_64) || CPU(ARM64)) && !ASAN_ENABLED -ALWAYS_INLINE bool equal(const Latin1Character* aLChar, std::span bLChar) +template +ALWAYS_INLINE bool equal(const CharacterType* a, std::span b) { ASSERT(bLChar.size() <= std::numeric_limits::max()); unsigned length = bLChar.size(); @@ -193,7 +205,8 @@ ALWAYS_INLINE bool equal(const UChar* aUChar, std::span bUChar) } } #elif CPU(X86) && !ASAN_ENABLED -ALWAYS_INLINE bool equal(const Latin1Character* aLChar, std::span bLChar) +template +ALWAYS_INLINE bool equal(const CharacterType* a, std::span b) { ASSERT(bLChar.size() <= std::numeric_limits::max()); unsigned length = bLChar.size(); @@ -212,8 +225,8 @@ ALWAYS_INLINE bool equal(const Latin1Character* aLChar, std::span(a); - const Latin1Character* bRemainder = byteCast(b); + auto* aRemainder = byteCast(aString); + auto* bRemainder = byteCast(bString); for (unsigned i = 0; i < length; ++i) { if (aRemainder[i] != bRemainder[i]) @@ -246,7 +259,11 @@ ALWAYS_INLINE bool equal(const UChar* aUChar, std::span bUChar) return true; } #else -ALWAYS_INLINE bool equal(const Latin1Character* a, std::span b) { return !memcmp(a, b.data(), b.size()); } +template +ALWAYS_INLINE bool equal(const CharacterType* a, std::span b) +{ + return !memcmp(a, b.data(), b.size()); +} ALWAYS_INLINE bool equal(const char16_t* a, std::span b) { return !memcmp(a, b.data(), b.size_bytes()); } #endif @@ -306,6 +323,20 @@ ALWAYS_INLINE bool equal(const char16_t* a, std::span b) return equal(b.data(), { a, b.size() }); } +template +ALWAYS_INLINE bool equal(std::span a, std::span b) +{ + if (a.size() != b.size()) + return false; + return equal(a.data(), b); +} + +template +ALWAYS_INLINE bool equal(std::span a, ASCIILiteral b) +{ + return equal(a, byteCast(b.span())); +} + template ALWAYS_INLINE bool equalCommon(const StringClassA& a, const StringClassB& b, unsigned length) { @@ -362,6 +393,23 @@ template bool equal(const StringClass& a, return equal(a.span16().data(), { codeUnits, length }); } +template +concept ContainsEncodingAwareSpans = requires(T t) +{ + { t.is8Bit() } -> std::convertible_to; + { t.span8() } -> std::convertible_to>; + { t.span16() } -> std::convertible_to>; +}; + +template +bool equal(const StringClass& string, std::span span) +{ + if (string.is8Bit()) + return Unicode::equal(string.span8(), span); + + return Unicode::equal(string.span16(), span); +} + template inline bool equalIgnoringASCIICaseWithLength(std::span a, std::span b, size_t lengthToCheck) { ASSERT(a.size() >= lengthToCheck); @@ -373,11 +421,26 @@ template inline bool equalIgno return true; } -template inline bool equalIgnoringASCIICase(std::span a, std::span b) +template inline bool spanHasPrefixIgnoringASCIICase(std::span span, std::span prefix) +{ + if (span.size() < prefix.size()) + return false; + return equalIgnoringASCIICaseWithLength(span, prefix, prefix.size()); +} + +template + requires(TriviallyComparableCodeUnits) +inline bool equalIgnoringASCIICase(std::span a, std::span b) { return a.size() == b.size() && equalIgnoringASCIICaseWithLength(a, b, a.size()); } +template +inline bool equalIgnoringASCIICase(std::span a, ASCIILiteral b) +{ + return equalIgnoringASCIICase(a, byteCast(b.span())); +} + template bool equalIgnoringASCIICaseCommon(const StringClassA& a, const StringClassB& b) { @@ -404,8 +467,9 @@ template bool equalIgnoringASCIICaseCommon(const StringCl return equalIgnoringASCIICaseWithLength(a.span16(), bSpan, bSpan.size()); } -template -size_t findIgnoringASCIICase(std::span source, std::span matchCharacters, size_t startOffset) +template + requires(TriviallyComparableCodeUnits) +size_t findIgnoringASCIICase(std::span source, std::span matchCharacters, size_t startOffset = 0) { ASSERT(source.size() >= matchCharacters.size()); @@ -421,6 +485,24 @@ size_t findIgnoringASCIICase(std::span source, std::s return notFound; } +template +size_t findIgnoringASCIICase(std::span source, ASCIILiteral matchCharacters) +{ + return findIgnoringASCIICase(source, byteCast(matchCharacters.span())); +} + +template +bool containsIgnoringASCIICase(std::span source, std::span matchCharacters) +{ + return findIgnoringASCIICase(source, matchCharacters) != notFound; +} + +template +bool containsIgnoringASCIICase(std::span source, ASCIILiteral matchCharacters) +{ + return containsIgnoringASCIICase(source, byteCast(matchCharacters.span())); +} + inline size_t findIgnoringASCIICaseWithoutLength(const char* source, const char* matchCharacters) { auto searchSpan = span(source); @@ -677,6 +759,24 @@ inline size_t find(std::span characters, char16_t matchCh return find(characters, static_cast(matchCharacter), index); } +template +inline size_t find(std::span characters, ASCIILiteral matchCharacters) +{ + return find(characters, byteCast(matchCharacters.span())); +} + +template +inline bool contains(std::span characters, CharacterType2 matchCharacter, size_t index = 0) +{ + return find(characters, matchCharacter, index) != notFound; +} + +template +inline bool contains(std::span characters, ASCIILiteral matchCharacters) +{ + return contains(characters, byteCast(matchCharacters.span())); +} + template ALWAYS_INLINE static size_t reverseFindInner(std::span searchCharacters, std::span matchCharacters, size_t start) { @@ -704,7 +804,28 @@ ALWAYS_INLINE static size_t reverseFindInner(std::span inline bool equalLettersIgnoringASCIICaseWithLength(std::span characters, std::span lowercaseLetters, size_t length) +template + requires(TriviallyComparableCodeUnits) +ALWAYS_INLINE static size_t reverseFind(std::span searchCharacters, std::span matchCharacters, size_t start = std::numeric_limits::max()) +{ + return reverseFindInner(searchCharacters, matchCharacters, start); +} + +template +ALWAYS_INLINE static size_t reverseFind(std::span searchCharacters, ASCIILiteral matchCharacters) +{ + return reverseFind(searchCharacters, byteCast(matchCharacters.span())); +} + +template +concept SearchableStringByOneByteCharacter = + sizeof(OneByteCharT) == 1 + && (std::is_same_v, std::remove_const_t> + || std::is_same_v, Latin1Character>); + +template + requires SearchableStringByOneByteCharacter +inline bool equalLettersIgnoringASCIICaseWithLength(std::span characters, std::span lowercaseLetters, size_t length) { ASSERT(characters.size() >= length); ASSERT(lowercaseLetters.size() >= length); @@ -752,6 +873,93 @@ template bool equalLettersIgnoringASCIICaseCommon(const St return hasPrefixWithLettersIgnoringASCIICaseCommon(string, literal); } +template + requires(TriviallyComparableCodeUnits) +bool startsWith(std::span string, std::span prefix) +{ + if (prefix.size() > string.size()) + return false; + + return equal(string.data(), prefix); +} + +template +bool startsWith(std::span string, ASCIILiteral prefix) +{ + return startsWith(string, byteCast(prefix.span())); +} + +template + requires(TriviallyComparableCodeUnits) +bool endsWith(std::span string, std::span suffix) +{ + unsigned suffixSize = suffix.size(); + unsigned referenceSize = string.size(); + if (suffixSize > referenceSize) + return false; + + unsigned startOffset = referenceSize - suffixSize; + + return equal(string.subspan(startOffset).data(), suffix); +} + +template +bool endsWith(std::span string, ASCIILiteral suffix) +{ + return endsWith(string, byteCast(suffix.span())); +} + +template + requires(TriviallyComparableCodeUnits) +bool endsWithLettersIgnoringASCIICaseCommon(std::span string, std::span suffix) +{ + unsigned suffixLength = suffix.size(); + unsigned referenceLength = string.size(); + if (suffixLength > referenceLength) + return false; + + unsigned startOffset = referenceLength - suffixLength; + + return equalIgnoringASCIICaseWithLength(string.subspan(startOffset), suffix, suffixLength); +} + +template + requires(TriviallyComparableCodeUnits) +bool endsWithLettersIgnoringASCIICase(std::span string, std::span suffix) +{ + return endsWithLettersIgnoringASCIICaseCommon(string, suffix); +} + +template +bool endsWithLettersIgnoringASCIICase(std::span string, ASCIILiteral suffix) +{ + return endsWithLettersIgnoringASCIICase(string, byteCast(suffix.span())); +} + +template + requires(TriviallyComparableCodeUnits) +bool startsWithLettersIgnoringASCIICaseCommon(std::span string, std::span prefix) +{ + if (prefix.empty()) + return true; + if (string.size() < prefix.size()) + return false; + return equalLettersIgnoringASCIICaseWithLength(string, prefix, prefix.size()); +} + +template + requires(TriviallyComparableCodeUnits) +bool startsWithLettersIgnoringASCIICase(std::span string, std::span prefix) +{ + return startsWithLettersIgnoringASCIICaseCommon(string, prefix); +} + +template +bool startsWithLettersIgnoringASCIICase(std::span string, ASCIILiteral prefix) +{ + return startsWithLettersIgnoringASCIICase(string, byteCast(prefix.span())); +} + template bool startsWithLettersIgnoringASCIICaseCommon(const StringClass& string, std::span prefix) { if (prefix.empty()) @@ -1068,11 +1276,21 @@ inline size_t countMatchedCharacters(std::span span, Charac } +using WTF::charactersContain; +using WTF::contains; +using WTF::containsIgnoringASCIICase; +using WTF::endsWith; +using WTF::endsWithLettersIgnoringASCIICase; using WTF::equalIgnoringASCIICase; using WTF::equalIgnoringASCIICaseWithLength; using WTF::equalLettersIgnoringASCIICase; using WTF::equalLettersIgnoringASCIICaseWithLength; +using WTF::findIgnoringASCIICase; using WTF::isLatin1; -using WTF::span; +using WTF::reverseFind; using WTF::span8; -using WTF::charactersContain; +using WTF::span; +using WTF::spanHasPrefixIgnoringASCIICase; +using WTF::startsWith; +using WTF::startsWithLettersIgnoringASCIICase; +using WTF::unsafeSpanChar8; diff --git a/Source/WTF/wtf/text/StringToIntegerConversion.h b/Source/WTF/wtf/text/StringToIntegerConversion.h index bc59617ed838f..3ca6e78fe8448 100644 --- a/Source/WTF/wtf/text/StringToIntegerConversion.h +++ b/Source/WTF/wtf/text/StringToIntegerConversion.h @@ -26,36 +26,39 @@ #pragma once #include +#include #include namespace WTF { -// The parseInteger function template allows leading and trailing spaces as defined by isUnicodeCompatibleASCIIWhitespace, and, after the leading spaces, allows a single leading "+". +// The parseInteger function template may allow leading and trailing spaces as defined by isUnicodeCompatibleASCIIWhitespace, and, after the leading spaces, allows a single leading "+". // The parseIntegerAllowingTrailingJunk function template is like parseInteger, but allows any characters after the integer. // FIXME: Should we add a version that does not allow "+"? // FIXME: Should we add a version that allows other definitions of spaces, like isASCIIWhitespace or isASCIIWhitespaceWithoutFF? -// FIXME: Should we add a version that does not allow leading and trailing spaces? -template std::optional parseInteger(StringView, uint8_t base = 10); +enum class ParseIntegerWhitespacePolicy : bool { Disallow, Allow }; + +template std::optional parseInteger(StringView, uint8_t base = 10, ParseIntegerWhitespacePolicy = ParseIntegerWhitespacePolicy::Allow); template std::optional parseIntegerAllowingTrailingJunk(StringView, uint8_t base = 10); +template std::optional parseInteger(std::span, uint8_t base = 10, ParseIntegerWhitespacePolicy = ParseIntegerWhitespacePolicy::Allow); +template std::optional parseIntegerAllowingTrailingJunk(std::span, uint8_t base = 10); -enum class TrailingJunkPolicy { Disallow, Allow }; +enum class TrailingJunkPolicy : bool { Disallow, Allow }; -template std::optional parseInteger(std::span data, uint8_t base, TrailingJunkPolicy policy) +template std::optional parseInteger(std::span data, uint8_t base, TrailingJunkPolicy policy, ParseIntegerWhitespacePolicy whitespacePolicy = ParseIntegerWhitespacePolicy::Allow) { if (!data.data()) return std::nullopt; - while (!data.empty() && isUnicodeCompatibleASCIIWhitespace(data.front())) - data = data.subspan(1); + if (whitespacePolicy == ParseIntegerWhitespacePolicy::Allow) + skipWhile(data); bool isNegative = false; - if (std::is_signed_v && !data.empty() && data.front() == '-') { - data = data.subspan(1); + if (std::is_signed_v && skipExactly(data, '-')) isNegative = true; - } else if (!data.empty() && data.front() == '+') - data = data.subspan(1); + else + skipExactly(data, '+'); auto isCharacterAllowedInBase = [] (auto character, auto base) { if (isASCIIDigit(character)) @@ -68,8 +71,8 @@ template std::optional value; do { - IntegralType digitValue = isASCIIDigit(data.front()) ? data.front() - '0' : toASCIILowerUnchecked(data.front()) - 'a' + 10; - data = data.subspan(1); + auto c = consume(data); + IntegralType digitValue = isASCIIDigit(c) ? c - '0' : toASCIILowerUnchecked(c) - 'a' + 10; value *= static_cast(base); if (isNegative) value -= digitValue; @@ -77,12 +80,12 @@ template std::optional(data); if (!data.empty()) return std::nullopt; } @@ -90,18 +93,32 @@ template std::optional std::optional parseInteger(StringView string, uint8_t base) +template +std::optional parseInteger(std::span data, uint8_t base, ParseIntegerWhitespacePolicy whitespacePolicy) +{ + return parseInteger(data, base, TrailingJunkPolicy::Disallow, whitespacePolicy); +} + +template +std::optional parseIntegerAllowingTrailingJunk(std::span data, uint8_t base) +{ + return parseInteger(data, base, TrailingJunkPolicy::Allow); +} + +template +std::optional parseInteger(StringView string, uint8_t base, ParseIntegerWhitespacePolicy whitespacePolicy) { if (string.is8Bit()) - return parseInteger(string.span8(), base, TrailingJunkPolicy::Disallow); - return parseInteger(string.span16(), base, TrailingJunkPolicy::Disallow); + return parseInteger(string.span8(), base, whitespacePolicy); + return parseInteger(string.span16(), base, whitespacePolicy); } -template std::optional parseIntegerAllowingTrailingJunk(StringView string, uint8_t base) +template +std::optional parseIntegerAllowingTrailingJunk(StringView string, uint8_t base) { if (string.is8Bit()) - return parseInteger(string.span8(), base, TrailingJunkPolicy::Allow); - return parseInteger(string.span16(), base, TrailingJunkPolicy::Allow); + return parseIntegerAllowingTrailingJunk(string.span8(), base); + return parseIntegerAllowingTrailingJunk(string.span16(), base); } } diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp index 5f936b1f26f7c..2cc751ba9db13 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp @@ -1053,7 +1053,7 @@ GRefPtr GStreamerMediaEndpoint::requestPad(const GRefPtr& allow } std::optional payloadType; if (auto encodingName = gstStructureGetString(structure, "encoding-name"_s)) - payloadType = payloadTypeForEncodingName(encodingName.toString()); + payloadType = payloadTypeForEncodingName(encodingName.span()); if (!payloadType) { if (availablePayloadType < 128) diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpReceiverBackend.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpReceiverBackend.cpp index c02a7e2a768b0..7f5e9b108ae7b 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpReceiverBackend.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpReceiverBackend.cpp @@ -68,7 +68,7 @@ RTCRtpParameters GStreamerRtpReceiverBackend::getParameters() auto media = gstStructureGetString(structure, "media"_s); auto encodingName = gstStructureGetString(structure, "encoding-name"_s); if (!media.isEmpty() && !encodingName.isEmpty()) - codec.mimeType = makeString(media.toString(), '/', encodingName.toString().convertToASCIILowercase()); + codec.mimeType = makeString(media.span(), '/', String(encodingName.span()).convertToASCIILowercase()); if (auto clockRate = gstStructureGet(structure, "clock-rate"_s)) codec.clockRate = *clockRate; @@ -77,7 +77,7 @@ RTCRtpParameters GStreamerRtpReceiverBackend::getParameters() codec.channels = *channels; if (auto fmtpLine = gstStructureGetString(structure, "fmtp-line"_s)) - codec.sdpFmtpLine = fmtpLine.toString(); + codec.sdpFmtpLine = fmtpLine.span(); parameters.codecs.append(WTFMove(codec)); @@ -86,7 +86,7 @@ RTCRtpParameters GStreamerRtpReceiverBackend::getParameters() if (!name.startsWith("extmap-"_s)) return true; - auto extensionId = parseInteger(name.toStringWithoutCopying().substring(7)); + auto extensionId = parseInteger(name.substring(7)); if (!extensionId) return true; diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpTransceiverBackend.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpTransceiverBackend.cpp index 4d01f0fad9316..0c818607b0fc2 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpTransceiverBackend.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpTransceiverBackend.cpp @@ -156,7 +156,7 @@ ExceptionOr GStreamerRtpTransceiverBackend::setCodecPreferences(const Vect if (gst_caps_get_size(currentCaps.get()) > 0) { auto structure = gst_caps_get_structure(currentCaps.get(), 0); if (auto msIdValue = gstStructureGetString(structure, "a-msid"_s)) - msid = msIdValue.toString(); + msid = msIdValue.span(); gstStructureForeach(structure, [&](auto id, const auto& value) -> bool { auto key = gstIdToString(id); diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerStatsCollector.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerStatsCollector.cpp index c66f90096d37c..7ee6567b45ac6 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerStatsCollector.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerStatsCollector.cpp @@ -40,7 +40,7 @@ namespace WebCore { RTCStatsReport::Stats::Stats(Type type, const GstStructure* structure) : type(type) - , id(gstStructureGetString(structure, "id"_s).toString()) + , id(gstStructureGetString(structure, "id"_s).span()) { if (auto value = gstStructureGet(structure, "timestamp"_s)) timestamp = Seconds::fromMicroseconds(*value).milliseconds(); @@ -48,9 +48,9 @@ RTCStatsReport::Stats::Stats(Type type, const GstStructure* structure) RTCStatsReport::RtpStreamStats::RtpStreamStats(Type type, const GstStructure* structure) : Stats(type, structure) - , kind(gstStructureGetString(structure, "kind"_s).toString()) - , transportId(gstStructureGetString(structure, "transport-id"_s).toString()) - , codecId(gstStructureGetString(structure, "codec-id"_s).toString()) + , kind(gstStructureGetString(structure, "kind"_s).span()) + , transportId(gstStructureGetString(structure, "transport-id"_s).span()) + , codecId(gstStructureGetString(structure, "codec-id"_s).span()) { if (auto value = gstStructureGet(structure, "ssrc"_s)) ssrc = *value; @@ -65,8 +65,8 @@ RTCStatsReport::SentRtpStreamStats::SentRtpStreamStats(Type type, const GstStruc RTCStatsReport::CodecStats::CodecStats(const GstStructure* structure) : Stats(Type::Codec, structure) - , mimeType(gstStructureGetString(structure, "mime-type"_s).toString()) - , sdpFmtpLine(gstStructureGetString(structure, "sdp-fmtp-line"_s).toString()) + , mimeType(gstStructureGetString(structure, "mime-type"_s).span()) + , sdpFmtpLine(gstStructureGetString(structure, "sdp-fmtp-line"_s).span()) { clockRate = gstStructureGet(structure, "clock-rate"_s); channels = gstStructureGet(structure, "channels"_s); @@ -98,7 +98,7 @@ RTCStatsReport::ReceivedRtpStreamStats::ReceivedRtpStreamStats(Type type, const RTCStatsReport::RemoteInboundRtpStreamStats::RemoteInboundRtpStreamStats(const GstStructure* structure) : ReceivedRtpStreamStats(Type::RemoteInboundRtp, structure) - , localId(gstStructureGetString(structure, "local-id"_s).toString()) + , localId(gstStructureGetString(structure, "local-id"_s).span()) { roundTripTime = gstStructureGet(structure, "round-trip-time"_s); fractionLost = gstStructureGet(structure, "fraction-lost"_s); @@ -110,7 +110,7 @@ RTCStatsReport::RemoteInboundRtpStreamStats::RemoteInboundRtpStreamStats(const G RTCStatsReport::RemoteOutboundRtpStreamStats::RemoteOutboundRtpStreamStats(const GstStructure* structure) : SentRtpStreamStats(Type::RemoteOutboundRtp, structure) - , localId(gstStructureGetString(structure, "local-id"_s).toString()) + , localId(gstStructureGetString(structure, "local-id"_s).span()) { remoteTimestamp = gstStructureGet(structure, "remote-timestamp"_s); @@ -139,7 +139,7 @@ RTCStatsReport::InboundRtpStreamStats::InboundRtpStreamStats(const GstStructure* frameHeight = gstStructureGet(structure, "frame-height"_s); if (auto identifier = gstStructureGetString(structure, "track-identifier"_s)) - trackIdentifier = identifier.toString(); + trackIdentifier = identifier.span(); // FIXME: // stats.fractionLost = @@ -155,7 +155,7 @@ RTCStatsReport::InboundRtpStreamStats::InboundRtpStreamStats(const GstStructure* RTCStatsReport::OutboundRtpStreamStats::OutboundRtpStreamStats(const GstStructure* structure) : SentRtpStreamStats(Type::OutboundRtp, structure) - , remoteId(gstStructureGetString(structure, "remote-id"_s).toString()) + , remoteId(gstStructureGetString(structure, "remote-id"_s).span()) { firCount = gstStructureGet(structure, "fir-count"_s); pliCount = gstStructureGet(structure, "pli-count"_s); @@ -169,9 +169,9 @@ RTCStatsReport::OutboundRtpStreamStats::OutboundRtpStreamStats(const GstStructur framesPerSecond = gstStructureGet(structure, "frames-per-second"_s); if (auto midValue = gstStructureGetString(structure, "mid"_s)) - mid = midValue.toString(); + mid = midValue.span(); if (auto ridValue = gstStructureGetString(structure, "rid"_s)) - rid = ridValue.toString(); + rid = ridValue.span(); } RTCStatsReport::PeerConnectionStats::PeerConnectionStats(const GstStructure* structure) @@ -183,7 +183,7 @@ RTCStatsReport::PeerConnectionStats::PeerConnectionStats(const GstStructure* str RTCStatsReport::TransportStats::TransportStats(const GstStructure* structure) : Stats(Type::Transport, structure) - , selectedCandidatePairId(gstStructureGetString(structure, "selected-candidate-pair-id"_s).toString()) + , selectedCandidatePairId(gstStructureGetString(structure, "selected-candidate-pair-id"_s).span()) { // FIXME: This field is required, GstWebRTC doesn't provide it, so hard-code a value here. dtlsState = RTCDtlsTransportState::Connected; @@ -215,10 +215,10 @@ static inline RTCIceCandidateType iceCandidateType(CStringView type) RTCStatsReport::IceCandidateStats::IceCandidateStats(GstWebRTCStatsType statsType, const GstStructure* structure) : Stats(statsType == GST_WEBRTC_STATS_REMOTE_CANDIDATE ? Type::RemoteCandidate : Type::LocalCandidate, structure) - , transportId(gstStructureGetString(structure, "transport-id"_s).toString()) - , address(gstStructureGetString(structure, "address"_s).toString()) - , protocol(gstStructureGetString(structure, "protocol"_s).toString()) - , url(gstStructureGetString(structure, "url"_s).toString()) + , transportId(gstStructureGetString(structure, "transport-id"_s).span()) + , address(gstStructureGetString(structure, "address"_s).span()) + , protocol(gstStructureGetString(structure, "protocol"_s).span()) + , url(gstStructureGetString(structure, "url"_s).span()) { port = gstStructureGet(structure, "port"_s); priority = gstStructureGet(structure, "priority"_s); @@ -229,8 +229,8 @@ RTCStatsReport::IceCandidateStats::IceCandidateStats(GstWebRTCStatsType statsTyp RTCStatsReport::IceCandidatePairStats::IceCandidatePairStats(const GstStructure* structure) : Stats(Type::CandidatePair, structure) - , localCandidateId(gstStructureGetString(structure, "local-candidate-id"_s).toString()) - , remoteCandidateId(gstStructureGetString(structure, "remote-candidate-id"_s).toString()) + , localCandidateId(gstStructureGetString(structure, "local-candidate-id"_s).span()) + , remoteCandidateId(gstStructureGetString(structure, "remote-candidate-id"_s).span()) { // FIXME // stats.transportId = diff --git a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp index 19a180ce57765..da3401a86d667 100644 --- a/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp +++ b/Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp @@ -164,7 +164,7 @@ static inline RTCRtpEncodingParameters toRTCEncodingParameters(const GstStructur parameters.maxFramerate = *maxFramerate; if (auto rid = gstStructureGetString(rtcParameters, "rid"_s)) - parameters.rid = rid.toString(); + parameters.rid = rid.span(); if (auto scaleResolutionDownBy = gstStructureGet(rtcParameters, "scale-resolution-down-by"_s)) parameters.scaleResolutionDownBy = *scaleResolutionDownBy; @@ -186,7 +186,7 @@ static inline RTCRtpCodecParameters toRTCCodecParameters(const GstStructure* rtc parameters.payloadType = *pt; if (auto mimeType = gstStructureGetString(rtcParameters, "mime-type"_s)) - parameters.mimeType = mimeType.toString(); + parameters.mimeType = mimeType.span(); if (auto clockRate = gstStructureGet(rtcParameters, "clock-rate"_s)) parameters.clockRate = *clockRate; @@ -195,7 +195,7 @@ static inline RTCRtpCodecParameters toRTCCodecParameters(const GstStructure* rtc parameters.channels = *channels; if (auto fmtpLine = gstStructureGetString(rtcParameters, "fmtp-line"_s)) - parameters.sdpFmtpLine = fmtpLine.toString(); + parameters.sdpFmtpLine = fmtpLine.span(); return parameters; } @@ -207,7 +207,7 @@ RTCRtpSendParameters toRTCRtpSendParameters(const GstStructure* rtcParameters) RTCRtpSendParameters parameters; if (auto transactionId = gstStructureGetString(rtcParameters, "transaction-id"_s)) - parameters.transactionId = transactionId.toString(); + parameters.transactionId = transactionId.span(); if (auto encodings = gst_structure_get_value(rtcParameters, "encodings")) { unsigned size = gst_value_list_get_size(encodings); @@ -587,7 +587,7 @@ GRefPtr capsFromRtpCapabilities(const RTCRtpCapabilities& capabilities, gst_structure_set(codecStructure, "encoding-params", G_TYPE_STRING, makeString(*codec.channels).ascii().data(), nullptr); if (auto encodingName = gstStructureGetString(codecStructure, "encoding-name"_s)) { - if (auto payloadType = payloadTypeForEncodingName(encodingName.toString())) + if (auto payloadType = payloadTypeForEncodingName(encodingName.span())) gst_structure_set(codecStructure, "payload", G_TYPE_INT, *payloadType, nullptr); } @@ -660,8 +660,8 @@ GRefPtr capsFromSDPMedia(const GstSDPMedia* media) "a-sendonly", "a-recvonly", "a-end-of-candidates", nullptr); if (auto name = gstStructureGetString(structure, "encoding-name"_s)) { - auto encodingName = name.toString().convertToASCIIUppercase(); - gst_structure_set(structure, "encoding-name", G_TYPE_STRING, encodingName.ascii().data(), nullptr); + auto encodingName = convertToASCIIUppercase(name.span()); + gst_structure_set(structure, "encoding-name", G_TYPE_STRING, encodingName.data(), nullptr); } // Remove ssrc- attributes that end up being accumulated in fmtp SDP media parameters. diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp index 7a4fbb5c29292..311b71a86415b 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp @@ -304,7 +304,7 @@ bool doCapsHaveType(const GstCaps* caps, ASCIILiteral type) GST_WARNING("Failed to get MediaType"); return false; } - return mediaType.toString().startsWith(type); + return startsWith(mediaType.span(), type); } bool areEncryptedCaps(const GstCaps* caps) diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp index 949b9ffa4c5e5..3ad4d23a4bf70 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp @@ -1147,14 +1147,14 @@ void GStreamerRegistryScanner::fillVideoRtpCapabilities(Configuration configurat element = gst_element_factory_make("webkitvideoencoder", nullptr); if (element) { - Vector profiles = { - "42e01f"_s, - "640c1f"_s, - "42001f"_s, - "4d001f"_s, - }; - - for (auto& profileLevelId : profiles) { + static constexpr std::array, 4> profiles = { { + { "42e01f"_s, 0x42e01f }, + { "640c1f"_s, 0x640c1f }, + { "42001f"_s, 0x42001f }, + { "4d001f"_s, 0x4d001f }, + } }; + + for (auto& [profileLevelId, spsAsInteger] : profiles) { if (WEBKIT_IS_VIDEO_ENCODER(element.get())) { auto codec = makeString("avc1."_s, profileLevelId); if (!videoEncoderSupportsCodec(WEBKIT_VIDEO_ENCODER(element.get()), codec)) diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp index c600f224acace..84b733a0d6225 100644 --- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp @@ -2223,7 +2223,7 @@ void MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message) if (gst_structure_has_name(structure, "http-headers")) { GST_DEBUG_OBJECT(pipeline(), "Processing HTTP headers: %" GST_PTR_FORMAT, structure); if (auto uri = gstStructureGetString(structure, "uri"_s)) { - URL url { uri.toString() }; + URL url { uri.span() }; if (url != m_url) { GST_DEBUG_OBJECT(pipeline(), "Ignoring HTTP response headers for non-main URI."); @@ -2248,7 +2248,7 @@ void MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message) // handle it here, until we remove the webkit+ protocol // prefix from webkitwebsrc. if (auto contentLengthValue = gstStructureGetString(responseHeaders.get(), contentLengthHeaderName)) { - if (auto parsedContentLength = parseInteger(contentLengthValue.toString())) + if (auto parsedContentLength = parseInteger(contentLengthValue.span())) contentLength = *parsedContentLength; } } else @@ -3051,9 +3051,8 @@ bool MediaPlayerPrivateGStreamer::loadNextLocation() // Found a candidate. new-location is not always an absolute url // though. We need to take the base of the current url and // append the value of new-location to it. - auto locationString = newLocation.toString(); - URL baseURL = gst_uri_is_valid(locationString.utf8().data()) ? URL() : m_url; - URL newURL = URL(baseURL, WTFMove(locationString)); + URL baseURL = gst_uri_is_valid(newLocation.utf8()) ? URL() : m_url; + URL newURL = URL(baseURL, newLocation.span()); GUniqueOutPtr playbinURLStr; g_object_get(m_pipeline.get(), "current-uri", &playbinURLStr.outPtr(), nullptr); diff --git a/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp index 7c40dfdc375d4..f6b0ef8b9a97f 100644 --- a/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp @@ -269,7 +269,7 @@ static GstFlowReturn transformInPlace(GstBaseTransform* base, GstBuffer* buffer) bool isCbcs = false; if (auto cipherMode = WebCore::gstStructureGetString(protectionMeta->info, "cipher-mode"_s)) - isCbcs = WTF::equalIgnoringASCIICase(cipherMode.toString(), "cbcs"_s); + isCbcs = WTF::equalIgnoringASCIICase(cipherMode.span(), "cbcs"_s); auto ivSizeFromMeta = WebCore::gstStructureGet(protectionMeta->info, "iv_size"_s); if (!ivSizeFromMeta) { diff --git a/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp b/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp index 7b884b640d69b..e8cbf87f84b64 100644 --- a/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp @@ -428,11 +428,11 @@ std::tuple, AppendPipeline::StreamType, FloatSize> AppendPipeli auto originalMediaType = capsMediaType(demuxerSrcPadCaps); auto& gstRegistryScanner = GStreamerRegistryScannerMSE::singleton(); auto shouldIgnore = std::find_if(s_ignoreMediaTypes.begin(), s_ignoreMediaTypes.end(), [&originalMediaType](const ASCIILiteral& type) { - return originalMediaType.toString().startsWithIgnoringASCIICase(type); + return startsWithLettersIgnoringASCIICase(originalMediaType.span(), type); }) != s_ignoreMediaTypes.end(); if (shouldIgnore) { streamType = StreamType::Ignore; - } else if (!gstRegistryScanner.isCodecSupported(GStreamerRegistryScanner::Configuration::Decoding, originalMediaType.toString())) { + } else if (!gstRegistryScanner.isCodecSupported(GStreamerRegistryScanner::Configuration::Decoding, originalMediaType.span())) { streamType = StreamType::Invalid; } else if (doCapsHaveType(demuxerSrcPadCaps, GST_VIDEO_CAPS_TYPE_PREFIX)) { presentationSize = getVideoResolutionFromCaps(demuxerSrcPadCaps).value_or(FloatSize()); diff --git a/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp b/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp index 1306d68e524c2..3122c7b5fd650 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp @@ -646,7 +646,7 @@ String MermaidBuilder::describeCaps(const GRefPtr& caps) for (unsigned i = 0; i < capsSize; i++) { auto* features = gst_caps_get_features(caps.get(), i); const auto* structure = gst_caps_get_structure(caps.get(), i); - builder.append(gstStructureGetName(structure).toString(), "
"_s); + builder.append(gstStructureGetName(structure).span(), "
"_s); if (features && (gst_caps_features_is_any(features) || !gst_caps_features_is_equal(features, GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) { GUniquePtr serializedFeature(gst_caps_features_to_string(features)); builder.append('(', WTF::span(serializedFeature.get()), ')'); diff --git a/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp b/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp index 4a177cde4f76a..117c3e465d4ae 100644 --- a/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp +++ b/Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp @@ -665,11 +665,11 @@ static void webkit_video_encoder_class_init(WebKitVideoEncoderClass* klass) const auto& encodedCaps = self->priv->encodedCaps; if (LIKELY(!gst_caps_is_any(encodedCaps.get()) && !gst_caps_is_empty(encodedCaps.get()))) { auto structure = gst_caps_get_structure(encodedCaps.get(), 0); - auto profile = gstStructureGetString(structure, "profile"_s).toString(); + auto profile = gstStructureGetString(structure, "profile"_s); - if (profile.findIgnoringASCIICase("high"_s) != notFound) + if (containsIgnoringASCIICase(profile.span(), "high"_s)) gst_preset_load_preset(GST_PRESET(self->priv->encoder.get()), "Profile High"); - else if (profile.findIgnoringASCIICase("main"_s) != notFound) + else if (containsIgnoringASCIICase(profile.span(), "main"_s)) gst_preset_load_preset(GST_PRESET(self->priv->encoder.get()), "Profile Main"); } }, "bitrate"_s, setBitrateKbitPerSec, "key-int-max"_s, [](GstElement* encoder, BitrateMode mode) { diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp index 52d410ef4a1a6..bf35b60b0fddf 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerAudioRTPPacketizer.cpp @@ -42,9 +42,8 @@ RefPtr GStreamerAudioRTPPacketizer::create(RefPtr GStreamerAudioRTPPacketizer::create(RefPtr(encodingParameters.toString())) + if (auto channels = parseIntegerAllowingTrailingJunk(encodingParameters.span())) inputCaps = adoptGRef(gst_caps_new_simple("audio/x-raw", "channels", G_TYPE_INT, *channels, nullptr)); } } @@ -116,7 +115,7 @@ RefPtr GStreamerAudioRTPPacketizer::create(RefPtr(minPTime.toString())) { + if (auto value = parseIntegerAllowingTrailingJunk(minPTime.span())) { if (gstObjectHasProperty(payloader.get(), "min-ptime"_s)) g_object_set(payloader.get(), "min-ptime", *value * GST_MSECOND, nullptr); else diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp index 59a1c93113124..60d3400f962ac 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp @@ -209,7 +209,7 @@ void GStreamerCaptureDeviceManager::addDevice(GRefPtr&& device) auto identifier = label; bool isMock = false; if (auto persistentId = gstStructureGetString(properties.get(), "persistent-id"_s)) { - identifier = persistentId.toString(); + identifier = persistentId.span(); isMock = true; } diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp index f1ee99955e7fd..d18c2ca2af8e0 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp @@ -69,17 +69,17 @@ void GStreamerIncomingTrackProcessor::configure(ThreadSafeWeakPtr GStreamerIncomingTrackProcessor::incomingTrackProcessor() if (!forceEarlyVideoDecoding) { auto structure = gst_caps_get_structure(m_data.caps.get(), 0); ASSERT(gst_structure_has_name(structure, "application/x-rtp")); - auto encodingName = gstStructureGetString(structure, "encoding-name"_s).toString(); - auto mediaType = makeString("video/x-"_s, encodingName.convertToASCIILowercase()); + auto encodingName = gstStructureGetString(structure, "encoding-name"_s); + auto mediaType = makeString("video/x-"_s, String(encodingName.span()).convertToASCIILowercase()); auto codecCaps = adoptGRef(gst_caps_new_empty_simple(mediaType.ascii().data())); auto& scanner = GStreamerRegistryScanner::singleton(); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerRTPPacketizer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerRTPPacketizer.cpp index a1e4655f05106..5573e650f799c 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerRTPPacketizer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerRTPPacketizer.cpp @@ -172,7 +172,7 @@ String GStreamerRTPPacketizer::rtpStreamId() const return emptyString(); if (auto rid = gstStructureGetString(m_encodingParameters.get(), "rid"_s)) - return rid.toString(); + return rid.span(); return emptyString(); } diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp index 93ec4d88a756f..2b55b7a76a894 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp @@ -346,10 +346,10 @@ void GStreamerVideoCapturer::reconfigure() selector->maxWidth = *width; selector->maxHeight = *height; selector->maxFrameRate = *frameRate; - selector->mimeType = gstStructureGetName(structure).toString(); + selector->mimeType = gstStructureGetName(structure).span(); if (gst_structure_has_name(structure, "video/x-raw")) { if (gst_structure_has_field(structure, "format")) - selector->format = gstStructureGetString(structure, "format"_s).toString(); + selector->format = gstStructureGetString(structure, "format"_s).span(); else return TRUE; } @@ -360,10 +360,10 @@ void GStreamerVideoCapturer::reconfigure() selector->maxWidth = *width; selector->maxHeight = *height; selector->maxFrameRate = *frameRate; - selector->mimeType = gstStructureGetName(structure).toString(); + selector->mimeType = gstStructureGetName(structure).span(); if (gst_structure_has_name(structure, "video/x-raw")) { if (gst_structure_has_field(structure, "format")) - selector->format = gstStructureGetString(structure, "format"_s).toString(); + selector->format = gstStructureGetString(structure, "format"_s).span(); else return TRUE; } diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp index a2a187c4e8ff1..0e39e43e5d022 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoRTPPacketizer.cpp @@ -46,9 +46,8 @@ RefPtr GStreamerVideoRTPPacketizer::create(RefPtr GStreamerVideoRTPPacketizer::create(RefPtr(vp9Profile.toString())) + if (auto vp9Profile = gstStructureGetString(codecParameters.get(), "profile-id"_s)) { + if (auto profile = parseInteger(vp9Profile.span())) record.profile = *profile; } codec = createVPCodecParametersString(record); diff --git a/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp b/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp index 332f5cda224b8..53b76fc39f378 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/RealtimeOutgoingMediaSourceGStreamer.cpp @@ -378,7 +378,7 @@ void RealtimeOutgoingMediaSourceGStreamer::setParameters(GUniquePtr +#include TEST(WTF, CStringNullStringConstructor) { CString string; constexpr size_t zeroLength = 0; ASSERT_TRUE(string.isNull()); + EXPECT_TRUE(string.isEmpty()); ASSERT_EQ(string.data(), static_cast(0)); ASSERT_EQ(string.length(), zeroLength); CString stringFromCharPointer(static_cast(0)); ASSERT_TRUE(stringFromCharPointer.isNull()); + EXPECT_TRUE(stringFromCharPointer.isEmpty()); ASSERT_EQ(stringFromCharPointer.data(), static_cast(0)); ASSERT_EQ(stringFromCharPointer.length(), zeroLength); CString stringFromCharAndLength({ static_cast(0), zeroLength }); ASSERT_TRUE(stringFromCharAndLength.isNull()); + EXPECT_TRUE(stringFromCharAndLength.isEmpty()); ASSERT_EQ(stringFromCharAndLength.data(), static_cast(0)); ASSERT_EQ(stringFromCharAndLength.length(), zeroLength); } @@ -49,13 +53,21 @@ TEST(WTF, CStringNullStringConstructor) TEST(WTF, CStringEmptyEmptyConstructor) { const char* emptyString = ""; + + CString stringFromEmptySpanWithNonNullPointer(unsafeMakeSpan(emptyString, 0)); + EXPECT_FALSE(stringFromEmptySpanWithNonNullPointer.isNull()); + EXPECT_TRUE(stringFromEmptySpanWithNonNullPointer.isEmpty()); + EXPECT_EQ(stringFromEmptySpanWithNonNullPointer.length(), 0UZ); + CString string(emptyString); ASSERT_FALSE(string.isNull()); + EXPECT_TRUE(string.isEmpty()); ASSERT_EQ(string.length(), static_cast(0)); ASSERT_EQ(string.data()[0], 0); CString stringWithLength(""_span); ASSERT_FALSE(stringWithLength.isNull()); + EXPECT_TRUE(stringWithLength.isEmpty()); ASSERT_EQ(stringWithLength.length(), static_cast(0)); ASSERT_EQ(stringWithLength.data()[0], 0); } @@ -195,3 +207,15 @@ TEST(WTF, CStringComparison) ASSERT_FALSE(c == d); ASSERT_TRUE(c != d); } + +TEST(WTF, CStringViewASCIICaseConversions) +{ + EXPECT_EQ(WTF::convertToASCIILowercase("Test"_spanChar8), CString("test")); + EXPECT_EQ(WTF::convertToASCIIUppercase("Test"_spanChar8), CString("TEST")); + EXPECT_EQ(WTF::convertToASCIILowercase(unsafeSpanChar8("Water🍉Melon")), CString("water🍉melon")); + EXPECT_EQ(WTF::convertToASCIIUppercase(unsafeSpanChar8("Water🍉Melon")), CString("WATER🍉MELON")); + EXPECT_EQ(WTF::convertToASCIILowercase(std::span()), CString(""_s)); + EXPECT_EQ(WTF::convertToASCIIUppercase(std::span()), CString(""_s)); + EXPECT_EQ(WTF::convertToASCIILowercase(""_spanChar8), CString(""_s)); + EXPECT_EQ(WTF::convertToASCIIUppercase(""_spanChar8), CString(""_s)); +} diff --git a/Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp b/Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp index 9423a3511da26..70fcdac3fa9b1 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/CStringView.cpp @@ -63,30 +63,43 @@ TEST(WTF, CStringViewNullAndEmpty) EXPECT_TRUE(string); } -TEST(WTF, CStringViewLength) +TEST(WTF, CStringViewSize) { CStringView string; - EXPECT_EQ(string.length(), static_cast(0)); - EXPECT_EQ(string.span8().size(), static_cast(0)); + EXPECT_EQ(string.lengthInBytes(), 0UZ); + EXPECT_EQ(string.span().size(), 0UZ); + EXPECT_EQ(string.spanIncludingNullTerminator().size(), 0UZ); string = CStringView("test"_s); - EXPECT_EQ(string.length(), static_cast(4)); - EXPECT_EQ(string.span8().size(), static_cast(4)); + EXPECT_EQ(string.lengthInBytes(), 4UZ); + EXPECT_EQ(string.span().size(), 4UZ); + EXPECT_EQ(string.spanIncludingNullTerminator().size(), 5UZ); + + string = CStringView::unsafeFromUTF8("water🍉melon"); + EXPECT_EQ(string.lengthInBytes(), 14UZ); + EXPECT_EQ(string.span().size(), 14UZ); + EXPECT_EQ(string.spanIncludingNullTerminator().size(), 15UZ); } TEST(WTF, CStringViewFrom) { const char* stringPtr = "test"; CStringView string = CStringView::unsafeFromUTF8(stringPtr); - EXPECT_EQ(string.length(), static_cast(4)); + EXPECT_EQ(string.lengthInBytes(), 4UZ); EXPECT_TRUE(string); EXPECT_EQ(string.utf8(), stringPtr); stringPtr = ""; string = CStringView::unsafeFromUTF8(stringPtr); - EXPECT_EQ(string.length(), static_cast(0)); + EXPECT_EQ(string.lengthInBytes(), 0UZ); EXPECT_FALSE(string); EXPECT_EQ(string.utf8(), stringPtr); + + stringPtr = "water🍉melon"; + string = CStringView::unsafeFromUTF8(stringPtr); + EXPECT_EQ(string.lengthInBytes(), 14UZ); + EXPECT_TRUE(string); + EXPECT_EQ(string.utf8(), stringPtr); } TEST(WTF, CStringViewEquality) @@ -101,6 +114,14 @@ TEST(WTF, CStringViewEquality) EXPECT_EQ(string, sameString); EXPECT_TRUE(string != anotherString); EXPECT_EQ(emptyString, nullString); + + char* bareEmptyString = strdup(""); + char* bareEmptyString2 = strdup(""); + emptyString = CStringView::unsafeFromUTF8(bareEmptyString); + auto emptyString2 = CStringView::unsafeFromUTF8(bareEmptyString2); + EXPECT_EQ(emptyString, emptyString2); + free(bareEmptyString); + free(bareEmptyString2); } } // namespace TestWebKitAPI diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp index 82a2c049c71cd..a62af94702bd2 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp @@ -119,6 +119,12 @@ TEST(StringBuilderTest, Append) const UChar resultArray[] = { U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar), U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar) }; EXPECT_EQ(String({ resultArray, std::size(resultArray) }), builderContent(builder)); } + + { + StringBuilder builder; + builder.append(unsafeSpanChar8("Water🍉Melon")); + EXPECT_EQ(builder.toString(), unsafeSpanChar8("Water🍉Melon")); + } } TEST(StringBuilderTest, AppendIntMin) diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp index 9ff1b49cbe00f..e15723a700df4 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp @@ -107,6 +107,114 @@ TEST(WTF_StringCommon, FindIgnoringASCIICaseWithoutLengthIdentical) EXPECT_EQ(WTF::findIgnoringASCIICaseWithoutLength("needley", "needle"), 0UL); } +TEST(WTF_StringCommon, Equal) +{ + EXPECT_TRUE(WTF::equal(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("Water🍉Melon"))); + EXPECT_FALSE(WTF::equal(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉WaterMelon🍉"))); + // EXPECT_TRUE(WTF::equal("test"_spanChar8, "test"_span8)); // This should not compile. + String string(unsafeSpanChar8("Water🍉Melon")); + EXPECT_FALSE(string.is8Bit()); + EXPECT_TRUE(WTF::equal(string, unsafeSpanChar8("Water🍉Melon"))); + EXPECT_FALSE(WTF::equal(string, unsafeSpanChar8("🍉WaterMelon🍉"))); +} + +TEST(WTF_StringCommon, EqualIgnoringASCIICase) +{ + EXPECT_TRUE(WTF::equalIgnoringASCIICase("Test"_spanChar8, "test"_spanChar8)); + EXPECT_FALSE(WTF::equalIgnoringASCIICase("another test"_spanChar8, "test"_spanChar8)); + // EXPECT_TRUE(WTF::equalIgnoringASCIICase("test"_spanChar8, "test"_span8)); // This should not compile. +} + +TEST(WTF_StringCommon, StartsWith) +{ + EXPECT_TRUE(WTF::startsWith(unsafeSpanChar8("Water🍉Melon"), "Water"_s)); + EXPECT_FALSE(WTF::startsWith(unsafeSpanChar8("Water🍉Melon"), "water"_s)); + EXPECT_FALSE(WTF::startsWith(unsafeSpanChar8("🍉WaterMelon🍉"), "Water"_s)); + EXPECT_TRUE(WTF::startsWith(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉"))); + EXPECT_FALSE(WTF::startsWith(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉"))); + // EXPECT_TRUE(WTF::startsWith("test"_spanChar8, "test"_span8)); // This should not compile. +} + +TEST(WTF_StringCommon, EndsWith) +{ + EXPECT_TRUE(WTF::endsWith(unsafeSpanChar8("Water🍉Melon"), "Melon"_s)); + EXPECT_FALSE(WTF::endsWith(unsafeSpanChar8("Water🍉Melon"), "melon"_s)); + EXPECT_FALSE(WTF::endsWith(unsafeSpanChar8("🍉WaterMelon🍉"), "Melon"_s)); + EXPECT_TRUE(WTF::endsWith(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉"))); + EXPECT_FALSE(WTF::endsWith(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉"))); + // EXPECT_TRUE(WTF::endsWith("test"_spanChar8, "test"_span8)); // This should not compile. +} + +TEST(WTF_StringCommon, Find) +{ + EXPECT_EQ(WTF::find(unsafeSpanChar8("Water🍉Melon"), "ter"_s), 2UZ); + EXPECT_EQ(WTF::find(unsafeSpanChar8("🍉WaterMelon🍉"), "ter"_s), 6UZ); + EXPECT_EQ(WTF::find(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉")), 5UZ); + EXPECT_EQ(WTF::find(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉")), 0UZ); + // EXPECT_NEQ(WTF::find("test"_spanChar8, "test"_span8), notFound); // This should not compile. +} + +TEST(WTF_StringCommon, ReverseFind) +{ + EXPECT_EQ(WTF::reverseFind(unsafeSpanChar8("Water🍉Melon"), "ter"_s), 2UZ); + EXPECT_EQ(WTF::reverseFind(unsafeSpanChar8("🍉WaterMelon🍉"), "ter"_s), 6UZ); + EXPECT_EQ(WTF::reverseFind(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉")), 5UZ); + EXPECT_EQ(WTF::reverseFind(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉")), 14UZ); + // EXPECT_NEQ(WTF::reverseFind("test"_spanChar8, "test"_span8), notFound); // This should not compile. +} + +TEST(WTF_StringCommon, Contains) +{ + EXPECT_TRUE(WTF::contains(unsafeSpanChar8("Water🍉Melon"), "Water"_s)); + EXPECT_TRUE(WTF::contains(unsafeSpanChar8("🍉WaterMelon🍉"), "Water"_s)); + EXPECT_TRUE(WTF::contains(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉"))); + EXPECT_TRUE(WTF::contains(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉"))); + EXPECT_FALSE(WTF::contains(unsafeSpanChar8("Water🍉Melon"), "pear"_s)); + EXPECT_FALSE(WTF::contains(unsafeSpanChar8("🍉WaterMelon🍉"), "pear"_s)); + EXPECT_FALSE(WTF::contains(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍈"))); + EXPECT_FALSE(WTF::contains(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍈"))); + // EXPECT_TRUE(WTF::contains("test"_spanChar8, "test"_span8)); // This should not compile. +} + +TEST(WTF_StringCommon, StartsWithLettersIgnoringASCIICase) +{ + EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), "water"_s)); + EXPECT_FALSE(WTF::startsWithLettersIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), "water"_s)); + // EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase("test"_spanChar8, "test"_span8)); // This should not compile. +} + +TEST(WTF_StringCommon, EndsWithLettersIgnoringASCIICase) +{ + EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), "melon"_s)); + EXPECT_FALSE(WTF::endsWithLettersIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), "melon"_s)); + // EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase("test"_spanChar8, "test"_span8)); // This should not compile. +} + +TEST(WTF_StringCommon, FindIgnoringASCIICase) +{ + EXPECT_EQ(WTF::findIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), "water"_s), 0UZ); + EXPECT_EQ(WTF::findIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), "water"_s), 4UZ); + EXPECT_EQ(WTF::findIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉")), 5UZ); + EXPECT_EQ(WTF::findIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉")), 0UZ); + // EXPECT_NEQ(WTF::findIgnoringASCIICase("test"_spanChar8, "test"_span8), notFound); // This should not compile. +} + +TEST(WTF_StringCommon, ContainsIgnoringASCIICase) +{ + EXPECT_TRUE(WTF::containsIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), "melon"_s)); + EXPECT_TRUE(WTF::containsIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), "melon"_s)); + EXPECT_TRUE(WTF::containsIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉"))); + EXPECT_TRUE(WTF::containsIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉"))); + // EXPECT_TRUE(WTF::containsIgnoringASCIICase("test"_spanChar8, "test"_span8)); // This should not compile. +} + +TEST(WTF_StringCommon, CharactersAreAllASCII) +{ + EXPECT_TRUE(WTF::charactersAreAllASCII("Test"_spanChar8)); + EXPECT_TRUE(WTF::charactersAreAllASCII(std::span())); + EXPECT_FALSE(WTF::charactersAreAllASCII(unsafeSpanChar8("🍉"))); +} + TEST(WTF_StringCommon, CopyElements64To8) { Vector destination; From e489922eac96c0afde32165fceac6b2c9002a13e Mon Sep 17 00:00:00 2001 From: Darin Adler Date: Mon, 24 Nov 2025 19:56:08 -0800 Subject: [PATCH 15/22] 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. * 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 --- Source/JavaScriptCore/API/JSStringRef.cpp | 4 +- Source/JavaScriptCore/API/JSValue.mm | 4 +- .../API/glib/JSCCallbackFunction.cpp | 2 +- Source/JavaScriptCore/API/glib/JSCContext.cpp | 4 +- Source/JavaScriptCore/API/glib/JSCValue.cpp | 4 +- .../bytecompiler/NodesCodegen.cpp | 2 +- Source/JavaScriptCore/runtime/Error.cpp | 4 +- Source/JavaScriptCore/runtime/Identifier.h | 20 -- Source/JavaScriptCore/runtime/Options.cpp | 14 +- Source/JavaScriptCore/runtime/RegExp.cpp | 2 +- .../runtime/SamplingProfiler.cpp | 2 +- .../tools/FunctionOverrides.cpp | 2 +- Source/JavaScriptCore/wasm/WasmParser.h | 2 +- Source/WTF/wtf/Assertions.cpp | 6 +- Source/WTF/wtf/DateMath.cpp | 4 +- Source/WTF/wtf/FileSystem.cpp | 6 +- Source/WTF/wtf/Logger.cpp | 4 +- Source/WTF/wtf/WTFConfig.cpp | 2 +- Source/WTF/wtf/glib/Application.cpp | 2 +- Source/WTF/wtf/text/ASCIILiteral.h | 10 +- Source/WTF/wtf/text/AtomString.h | 3 +- Source/WTF/wtf/text/AtomStringImpl.h | 3 +- Source/WTF/wtf/text/CString.cpp | 2 +- Source/WTF/wtf/text/StringCommon.h | 40 ++-- Source/WTF/wtf/text/StringConcatenate.h | 38 +--- Source/WTF/wtf/text/StringImpl.h | 7 +- Source/WTF/wtf/text/StringView.h | 19 +- Source/WTF/wtf/text/TextStream.cpp | 2 +- Source/WTF/wtf/text/WTFString.cpp | 2 +- Source/WTF/wtf/text/WTFString.h | 10 +- .../server/SQLiteIDBBackingStore.cpp | 34 +-- .../mediastream/libwebrtc/LibWebRTCUtils.cpp | 2 +- .../WebCore/Modules/webdatabase/Database.cpp | 2 +- Source/WebCore/Modules/webdatabase/SQLError.h | 2 +- .../bindings/js/JSDOMExceptionHandling.cpp | 4 +- Source/WebCore/bridge/IdentifierRep.cpp | 2 +- Source/WebCore/dom/Document.cpp | 2 +- Source/WebCore/editing/TextIterator.cpp | 2 +- .../loader/PrivateClickMeasurement.cpp | 2 +- Source/WebCore/page/NavigatorBase.cpp | 2 +- Source/WebCore/page/PrintContext.cpp | 2 +- Source/WebCore/platform/Decimal.cpp | 2 +- .../platform/SharedBufferChunkReader.cpp | 2 +- .../audio/gstreamer/AudioEncoderGStreamer.cpp | 2 +- .../gstreamer/AudioFileReaderGStreamer.cpp | 2 +- .../WebCore/platform/glib/UserAgentGLib.cpp | 2 +- .../platform/graphics/ColorSerialization.cpp | 2 +- .../graphics/cocoa/GraphicsContextGLCocoa.mm | 10 +- .../freetype/FontPlatformDataFreeType.cpp | 2 +- .../graphics/gstreamer/GStreamerCommon.cpp | 10 +- .../gstreamer/MediaPlayerPrivateGStreamer.cpp | 2 +- .../gstreamer/TrackPrivateBaseGStreamer.cpp | 12 +- .../gstreamer/VideoFrameGStreamer.cpp | 4 +- .../graphics/gstreamer/eme/CDMThunder.cpp | 2 +- .../graphics/gstreamer/mse/AppendPipeline.cpp | 4 +- .../mse/WebKitMediaSourceGStreamer.cpp | 2 +- .../texmap/TextureMapperShaderProgram.cpp | 16 +- .../gstreamer/GStreamerElementHarness.cpp | 24 +-- .../GStreamerCaptureDeviceManager.cpp | 2 +- .../gstreamer/GStreamerCapturer.cpp | 4 +- .../GStreamerVideoDecoderFactory.cpp | 2 +- .../platform/network/FormDataBuilder.cpp | 2 +- .../soup/AuthenticationChallengeSoup.cpp | 2 +- .../WebCore/platform/sql/SQLiteDatabase.cpp | 2 +- Source/WebCore/xml/XMLErrors.cpp | 2 +- .../soup/NetworkDataTaskSoup.cpp | 4 +- .../soup/NetworkProcessSoup.cpp | 2 +- .../webrtc/NetworkRTCMonitor.cpp | 2 +- .../Shared/unix/AuxiliaryProcessMain.cpp | 6 +- .../API/glib/WebKitProtocolHandler.cpp | 16 +- .../UIProcess/API/glib/WebKitWebView.cpp | 2 +- .../Inspector/glib/RemoteInspectorClient.cpp | 2 +- .../GPU/media/RemoteVideoCodecFactory.cpp | 2 +- .../API/gtk/DOM/GObjectEventListener.cpp | 2 +- .../API/gtk/DOM/GObjectEventListener.h | 3 +- Tools/TestWebKitAPI/Tests/WTF/CString.cpp | 12 +- .../TestWebKitAPI/Tests/WTF/StringBuilder.cpp | 4 +- .../TestWebKitAPI/Tests/WTF/StringCommon.cpp | 116 +++++------ .../WebKitCocoa/ProcessSwapOnNavigation.mm | 197 +++++++++--------- 79 files changed, 368 insertions(+), 400 deletions(-) diff --git a/Source/JavaScriptCore/API/JSStringRef.cpp b/Source/JavaScriptCore/API/JSStringRef.cpp index 26efd304ee504..1640ffae6efca 100644 --- a/Source/JavaScriptCore/API/JSStringRef.cpp +++ b/Source/JavaScriptCore/API/JSStringRef.cpp @@ -45,12 +45,12 @@ JSStringRef JSStringCreateWithUTF8CString(const char* string) { JSC::initialize(); if (string) { - auto stringSpan = span8(string); + auto stringSpan = byteCast(unsafeSpan(string)); Vector buffer(stringSpan.size()); auto result = WTF::Unicode::convert(spanReinterpretCast(stringSpan), buffer.mutableSpan()); if (result.code == WTF::Unicode::ConversionResultCode::Success) { if (result.isAllASCII) - return &OpaqueJSString::create(stringSpan).leakRef(); + return &OpaqueJSString::create(byteCast(stringSpan)).leakRef(); return &OpaqueJSString::create(result.buffer).leakRef(); } } diff --git a/Source/JavaScriptCore/API/JSValue.mm b/Source/JavaScriptCore/API/JSValue.mm index ecd7bf0e53868..d8f7ec1b58942 100644 --- a/Source/JavaScriptCore/API/JSValue.mm +++ b/Source/JavaScriptCore/API/JSValue.mm @@ -1281,8 +1281,8 @@ - (JSValue *)initWithValue:(JSValueRef)value inContext:(JSContext *)context if (strcmp(idType, "@") != 0) return; { - auto type = adoptSystem(method_copyArgumentType(method, 2)); - structHandlers->add(StringImpl::createFromCString(type.get()), (StructTagHandler) { selector, 0 }); + auto type = adoptSystem(method_copyArgumentType(method, 2)); + structHandlers->add(byteCast(unsafeSpan(type.get()), (StructTagHandler) { selector, 0 }); } }); diff --git a/Source/JavaScriptCore/API/glib/JSCCallbackFunction.cpp b/Source/JavaScriptCore/API/glib/JSCCallbackFunction.cpp index eaf0aca348534..d6446b82f0de5 100644 --- a/Source/JavaScriptCore/API/glib/JSCCallbackFunction.cpp +++ b/Source/JavaScriptCore/API/glib/JSCCallbackFunction.cpp @@ -228,7 +228,7 @@ JSObjectRef JSCCallbackFunction::construct(JSContextRef callerContext, size_t ar *exception = toRef(JSC::createTypeError(toJS(jsContext), "constructor returned null"_s)); break; default: - *exception = toRef(JSC::createTypeError(toJS(jsContext), makeString("invalid type "_s, span(g_type_name(G_VALUE_TYPE(&returnValue))), " returned by constructor"_s))); + *exception = toRef(JSC::createTypeError(toJS(jsContext), makeString("invalid type "_s, unsafeSpan(g_type_name(G_VALUE_TYPE(&returnValue))), " returned by constructor"_s))); break; } g_value_unset(&returnValue); diff --git a/Source/JavaScriptCore/API/glib/JSCContext.cpp b/Source/JavaScriptCore/API/glib/JSCContext.cpp index 31d780d52b1f1..005efdc6c6fcd 100644 --- a/Source/JavaScriptCore/API/glib/JSCContext.cpp +++ b/Source/JavaScriptCore/API/glib/JSCContext.cpp @@ -467,7 +467,7 @@ JSValueRef jscContextGValueToJSValue(JSCContext* context, const GValue* value, J break; } - *exception = toRef(JSC::createTypeError(globalObject, makeString("unsupported type "_s, span(g_type_name(G_VALUE_TYPE(value)))))); + *exception = toRef(JSC::createTypeError(globalObject, makeString("unsupported type "_s, unsafeSpan(g_type_name(G_VALUE_TYPE(value)))))); return JSValueMakeUndefined(priv->jsContext.get()); } @@ -587,7 +587,7 @@ void jscContextJSValueToGValue(JSCContext* context, JSValueRef jsValue, GType ty case G_TYPE_INTERFACE: case G_TYPE_VARIANT: default: - *exception = toRef(JSC::createTypeError(globalObject, makeString("unsupported type "_s, span(g_type_name(G_VALUE_TYPE(value)))))); + *exception = toRef(JSC::createTypeError(globalObject, makeString("unsupported type "_s, unsafeSpan(g_type_name(G_VALUE_TYPE(value)))))); break; } } diff --git a/Source/JavaScriptCore/API/glib/JSCValue.cpp b/Source/JavaScriptCore/API/glib/JSCValue.cpp index 7a26478a8471d..885eae6409c73 100644 --- a/Source/JavaScriptCore/API/glib/JSCValue.cpp +++ b/Source/JavaScriptCore/API/glib/JSCValue.cpp @@ -503,7 +503,7 @@ JSCValue* jsc_value_new_array(JSCContext* context, GType firstItemType, ...) G_VALUE_COLLECT_INIT(&item, itemType, args, G_VALUE_NOCOPY_CONTENTS, &error.outPtr()); WTF_ALLOW_UNSAFE_BUFFER_USAGE_END if (error) { - exception = toRef(JSC::createTypeError(globalObject, makeString("failed to collect array item: "_s, span(error.get())))); + exception = toRef(JSC::createTypeError(globalObject, makeString("failed to collect array item: "_s, unsafeSpan(error.get())))); jscContextHandleExceptionIfNeeded(context, exception); jsArray = nullptr; break; @@ -905,7 +905,7 @@ static GRefPtr jscValueCallFunction(JSCValue* value, JSObjectRef funct G_VALUE_COLLECT_INIT(¶meter, parameterType, args, G_VALUE_NOCOPY_CONTENTS, &error.outPtr()); WTF_ALLOW_UNSAFE_BUFFER_USAGE_END if (error) { - exception = toRef(JSC::createTypeError(globalObject, makeString("failed to collect function paramater: "_s, span(error.get())))); + exception = toRef(JSC::createTypeError(globalObject, makeString("failed to collect function paramater: "_s, unsafeSpan(error.get())))); jscContextHandleExceptionIfNeeded(priv->context.get(), exception); return adoptGRef(jsc_value_new_undefined(priv->context.get())); } diff --git a/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp b/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp index 8c3535f8d6dec..0c320516a57e7 100644 --- a/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp +++ b/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp @@ -168,7 +168,7 @@ RegisterID* RegExpNode::emitBytecode(BytecodeGenerator& generator, RegisterID* d if (regExp->isValid()) return generator.emitNewRegExp(generator.finalDestination(dst), regExp); - auto& message = generator.parserArena().identifierArena().makeIdentifier(generator.vm(), span8(regExp->errorMessage())); + auto& message = generator.parserArena().identifierArena().makeIdentifier(generator.vm(), byteCast(unsafeSpan(regExp->errorMessage()))); generator.emitThrowStaticError(ErrorTypeWithExtension::SyntaxError, message); return generator.emitLoad(generator.finalDestination(dst), jsUndefined()); } diff --git a/Source/JavaScriptCore/runtime/Error.cpp b/Source/JavaScriptCore/runtime/Error.cpp index 3c996f9770088..11f6ce03162d9 100644 --- a/Source/JavaScriptCore/runtime/Error.cpp +++ b/Source/JavaScriptCore/runtime/Error.cpp @@ -291,13 +291,13 @@ JSObject* createTypeErrorCopy(JSGlobalObject* globalObject, JSValue error) String makeDOMAttributeGetterTypeErrorMessage(const char* interfaceName, const String& attributeName) { - auto interfaceNameSpan = span(interfaceName); + auto interfaceNameSpan = unsafeSpan(interfaceName); return makeString("The "_s, interfaceNameSpan, '.', attributeName, " getter can only be used on instances of "_s, interfaceNameSpan); } String makeDOMAttributeSetterTypeErrorMessage(const char* interfaceName, const String& attributeName) { - auto interfaceNameSpan = span(interfaceName); + auto interfaceNameSpan = unsafeSpan(interfaceName); return makeString("The "_s, interfaceNameSpan, '.', attributeName, " setter can only be used on instances of "_s, interfaceNameSpan); } diff --git a/Source/JavaScriptCore/runtime/Identifier.h b/Source/JavaScriptCore/runtime/Identifier.h index 2d77d8bad54ff..5632283dc1ea9 100644 --- a/Source/JavaScriptCore/runtime/Identifier.h +++ b/Source/JavaScriptCore/runtime/Identifier.h @@ -144,11 +144,7 @@ class Identifier { bool isPrivateName() const { return isSymbol() && static_cast(impl())->isPrivate(); } friend bool operator==(const Identifier&, const Identifier&); - friend bool operator==(const Identifier&, const Latin1Character*); - friend bool operator==(const Identifier&, const char*); - static bool equal(const StringImpl*, const Latin1Character*); - static inline bool equal(const StringImpl* a, const char* b) { return Identifier::equal(a, byteCast(b)); }; static bool equal(const StringImpl*, std::span); static bool equal(const StringImpl*, std::span); static bool equal(const StringImpl* a, const StringImpl* b) { return ::equal(a, b); } @@ -175,7 +171,6 @@ class Identifier { { } static bool equal(const Identifier& a, const Identifier& b) { return a.m_string.impl() == b.m_string.impl(); } - static bool equal(const Identifier& a, const Latin1Character* b) { return equal(a.m_string.impl(), b); } template static Ref add(VM&, std::span); static Ref add8(VM&, std::span); @@ -228,21 +223,6 @@ inline bool operator==(const Identifier& a, const Identifier& b) return Identifier::equal(a, b); } -inline bool operator==(const Identifier& a, const Latin1Character* b) -{ - return Identifier::equal(a, b); -} - -inline bool operator==(const Identifier& a, const char* b) -{ - return Identifier::equal(a, byteCast(b)); -} - -inline bool Identifier::equal(const StringImpl* r, const Latin1Character* s) -{ - return WTF::equal(r, s); -} - inline bool Identifier::equal(const StringImpl* r, std::span s) { return WTF::equal(r, s); diff --git a/Source/JavaScriptCore/runtime/Options.cpp b/Source/JavaScriptCore/runtime/Options.cpp index 51ccc94ae0996..d8ef7517039e4 100644 --- a/Source/JavaScriptCore/runtime/Options.cpp +++ b/Source/JavaScriptCore/runtime/Options.cpp @@ -207,7 +207,7 @@ std::optional parse(const char* string); template<> std::optional parse(const char* string) { - auto span = WTF::span(string); + auto span = WTF::unsafeSpan(string); if (equalLettersIgnoringASCIICase(span, "true"_s) || equalLettersIgnoringASCIICase(span, "yes"_s) || !strcmp(string, "1")) return true; if (equalLettersIgnoringASCIICase(span, "false"_s) || equalLettersIgnoringASCIICase(span, "no"_s) || !strcmp(string, "0")) @@ -278,7 +278,7 @@ std::optional parse(const char* string) template<> std::optional parse(const char* string) { - auto span = WTF::span(string); + auto span = WTF::unsafeSpan(string); if (equalLettersIgnoringASCIICase(span, "none"_s) || equalLettersIgnoringASCIICase(span, "no"_s) || equalLettersIgnoringASCIICase(span, "false"_s) || !strcmp(string, "0")) return GCLogging::None; @@ -296,7 +296,7 @@ std::optional parse(const char* string) { std::optional result; - auto span = WTF::span(string); + auto span = WTF::unsafeSpan(string); if (equalLettersIgnoringASCIICase(span, "none"_s) || equalLettersIgnoringASCIICase(span, "false"_s) || !strcmp(string, "0")) result = OSLogType::None; else if (equalLettersIgnoringASCIICase(span, "true"_s) || !strcmp(string, "1")) @@ -428,7 +428,7 @@ bool Options::overrideAliasedOptionWithHeuristic(const char* name) if (!stringValue) return false; - auto aliasedOption = makeString(span(&name[4]), '=', span(stringValue)); + auto aliasedOption = makeString(unsafeSpan(&name[4]), '=', unsafeSpan(stringValue)); if (Options::setOption(aliasedOption.utf8().data())) return true; @@ -1262,7 +1262,7 @@ bool Options::setAliasedOption(const char* arg, bool verify) && !strncasecmp(arg, #aliasedName_, equalStr - arg)) { \ auto unaliasedOption = String::fromLatin1(#unaliasedName_); \ if (equivalence == SameOption) \ - unaliasedOption = makeString(unaliasedOption, span(equalStr)); \ + unaliasedOption = makeString(unaliasedOption, unsafeSpan(equalStr)); \ else { \ ASSERT(equivalence == InvertedOption); \ auto invertedValueStr = invertBoolOptionValue(equalStr + 1); \ @@ -1439,10 +1439,10 @@ void Option::dump(StringBuilder& builder) const builder.append(m_int32); break; case Options::Type::OptionRange: - builder.append(span(m_optionRange.rangeString())); + builder.append(unsafeSpan(m_optionRange.rangeString())); break; case Options::Type::OptionString: - builder.append('"', m_optionString ? span8(m_optionString) : ""_span, '"'); + builder.append('"', m_optionString ? byteCast(unsafeSpan(m_optionString)) : ""_span, '"'); break; case Options::Type::GCLogLevel: builder.append(m_gcLogLevel); diff --git a/Source/JavaScriptCore/runtime/RegExp.cpp b/Source/JavaScriptCore/runtime/RegExp.cpp index b418e3fa804a5..45ede5672d96d 100644 --- a/Source/JavaScriptCore/runtime/RegExp.cpp +++ b/Source/JavaScriptCore/runtime/RegExp.cpp @@ -683,7 +683,7 @@ String RegExp::escapedPattern() const String RegExp::toSourceString() const { - return makeString('/', escapedPattern(), '/', span(Yarr::flagsString(flags()).data())); + return makeString('/', escapedPattern(), '/', unsafeSpan(Yarr::flagsString(flags()).data())); } } // namespace JSC diff --git a/Source/JavaScriptCore/runtime/SamplingProfiler.cpp b/Source/JavaScriptCore/runtime/SamplingProfiler.cpp index a313789370fb6..7f768ce78322f 100644 --- a/Source/JavaScriptCore/runtime/SamplingProfiler.cpp +++ b/Source/JavaScriptCore/runtime/SamplingProfiler.cpp @@ -1315,7 +1315,7 @@ void SamplingProfiler::reportTopBytecodes(PrintStream& out) auto frameDescription = makeString(frame.displayName(m_vm), descriptionForLocation(frame.semanticLocation, frame.wasmCompilationMode, frame.wasmOffset)); if (std::optional> machineLocation = frame.machineLocation) { frameDescription = makeString(frameDescription, " <-- "_s, - span(machineLocation->second->inferredName().data()), descriptionForLocation(machineLocation->first, std::nullopt, BytecodeIndex())); + unsafeSpan(machineLocation->second->inferredName().data()), descriptionForLocation(machineLocation->first, std::nullopt, BytecodeIndex())); } bytecodeCounts.add(frameDescription, 0).iterator->value++; diff --git a/Source/JavaScriptCore/tools/FunctionOverrides.cpp b/Source/JavaScriptCore/tools/FunctionOverrides.cpp index 960d961893e79..f038d4fce3ab8 100644 --- a/Source/JavaScriptCore/tools/FunctionOverrides.cpp +++ b/Source/JavaScriptCore/tools/FunctionOverrides.cpp @@ -244,7 +244,7 @@ WTF_ALLOW_UNSAFE_BUFFER_USAGE_END builder.append(std::span { line, p + 1 }); return builder.toString(); } - builder.append(span(line)); + builder.append(unsafeSpan(line)); WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN } while ((line = fgets(buffer, bufferSize, file))); diff --git a/Source/JavaScriptCore/wasm/WasmParser.h b/Source/JavaScriptCore/wasm/WasmParser.h index c889ca6fde2f8..9f2ad49517866 100644 --- a/Source/JavaScriptCore/wasm/WasmParser.h +++ b/Source/JavaScriptCore/wasm/WasmParser.h @@ -183,7 +183,7 @@ ALWAYS_INLINE bool ParserBase::consumeUTF8String(Name& result, size_t stringLeng if (!result.tryReserveCapacity(stringLength)) return false; - auto string = spanReinterpretCast(m_source.subspan(m_offset, stringLength)); + auto string = byteCast(m_source.subspan(m_offset, stringLength)); if (auto checkResult = WTF::Unicode::checkUTF8(string); checkResult.characters.size() != string.size()) return false; diff --git a/Source/WTF/wtf/Assertions.cpp b/Source/WTF/wtf/Assertions.cpp index 56ee4c7bbf91a..36acb5f7c2f4c 100644 --- a/Source/WTF/wtf/Assertions.cpp +++ b/Source/WTF/wtf/Assertions.cpp @@ -200,8 +200,8 @@ ALLOW_NONLITERAL_FORMAT_END WTF_ATTRIBUTE_PRINTF(2, 0) static void vprintf_stderr_with_prefix(const char* rawPrefix, const char* rawFormat, va_list args) { - auto prefix = span(rawPrefix); - auto format = span(rawFormat); + auto prefix = unsafeSpan(rawPrefix); + auto format = unsafeSpan(rawFormat); Vector formatWithPrefix(prefix.size() + format.size() + 1); memcpySpan(formatWithPrefix.mutableSpan(), prefix); memcpySpan(formatWithPrefix.mutableSpan().subspan(prefix.size()), format); @@ -215,7 +215,7 @@ ALLOW_NONLITERAL_FORMAT_END WTF_ATTRIBUTE_PRINTF(2, 0) static void vprintf_stderr_with_trailing_newline(WTFLogChannel* channel, const char* rawFormat, va_list args) { - auto format = span(rawFormat); + auto format = unsafeSpan(rawFormat); if (!format.empty() && format.back() == '\n') { vprintf_stderr_common(channel, rawFormat, args); return; diff --git a/Source/WTF/wtf/DateMath.cpp b/Source/WTF/wtf/DateMath.cpp index 7f4a9f4f72da4..e03b26ab2cb1d 100644 --- a/Source/WTF/wtf/DateMath.cpp +++ b/Source/WTF/wtf/DateMath.cpp @@ -70,6 +70,8 @@ */ #include "config.h" +#include "StdLibExtras.h" +#include "text/StringCommon.h" #include #include @@ -959,7 +961,7 @@ double parseDate(std::span dateString, bool& isLocalTime) for (auto& knownZone : knownZones) { // Since the passed-in length is used for both strings, the following checks that // dateString has the time zone name as a prefix, not that it is equal. - auto tzName = span8(knownZone.tzName); + auto tzName = byteCast(unsafeSpan(knownZone.tzName)); if (dateString.size() >= tzName.size() && equalLettersIgnoringASCIICaseWithLength(dateString, tzName, tzName.size())) { offset = knownZone.tzOffset; dateString = dateString.subspan(tzName.size()); diff --git a/Source/WTF/wtf/FileSystem.cpp b/Source/WTF/wtf/FileSystem.cpp index 8b8ef752e0cb4..efa42c826808e 100644 --- a/Source/WTF/wtf/FileSystem.cpp +++ b/Source/WTF/wtf/FileSystem.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #if !OS(WINDOWS) #include @@ -64,9 +65,10 @@ ALLOW_DEPRECATED_DECLARATIONS_END static String fromStdFileSystemPath(const std::filesystem::path& path) { #if HAVE(MISSING_U8STRING) - return String::fromUTF8(span8(path.u8string().c_str())); + // FIXME: This uses u8string so how can it be correct inside HAVE(MISSING_U8STRING)? + return String::fromUTF8(unsafeSpan(path.u8string().c_str())); #else - return String::fromUTF8(span(path.u8string())); + return span(path.u8string()); #endif } diff --git a/Source/WTF/wtf/Logger.cpp b/Source/WTF/wtf/Logger.cpp index c806bfec5efac..dc96a9d4fbedd 100644 --- a/Source/WTF/wtf/Logger.cpp +++ b/Source/WTF/wtf/Logger.cpp @@ -39,8 +39,8 @@ Lock messageHandlerLoggerObserverLock; String Logger::LogSiteIdentifier::toString() const { if (className) - return makeString(className, "::"_s, span(methodName), '(', hex(objectPtr), ") "_s); - return makeString(span(methodName), '(', hex(objectPtr), ") "_s); + return makeString(className, "::"_s, unsafeSpan(methodName), '(', hex(objectPtr), ") "_s); + return makeString(unsafeSpan(methodName), '(', hex(objectPtr), ") "_s); } String LogArgument::toString(const void* argument) diff --git a/Source/WTF/wtf/WTFConfig.cpp b/Source/WTF/wtf/WTFConfig.cpp index 828d97700787b..7a69980c9a982 100644 --- a/Source/WTF/wtf/WTFConfig.cpp +++ b/Source/WTF/wtf/WTFConfig.cpp @@ -117,7 +117,7 @@ void Config::initialize() reservedConfigBytes[WebConfig::ReservedByteForAllocationProfiling] = 0; const char* useAllocationProfilingRaw = getenv("JSC_useAllocationProfiling"); if (useAllocationProfilingRaw) { - auto useAllocationProfiling = span(useAllocationProfilingRaw); + auto useAllocationProfiling = unsafeSpan(useAllocationProfilingRaw); if (equalLettersIgnoringASCIICase(useAllocationProfiling, "true"_s) || equalLettersIgnoringASCIICase(useAllocationProfiling, "yes"_s) || equal(useAllocationProfiling, "1"_s)) diff --git a/Source/WTF/wtf/glib/Application.cpp b/Source/WTF/wtf/glib/Application.cpp index 349c1ccbf367b..760a0f196b6cf 100644 --- a/Source/WTF/wtf/glib/Application.cpp +++ b/Source/WTF/wtf/glib/Application.cpp @@ -57,7 +57,7 @@ const CString& applicationID() // and won't flood xdg-desktop-portal with new ids. if (auto executablePath = FileSystem::currentExecutablePath(); !executablePath.isNull()) { GUniquePtr digest(g_compute_checksum_for_data(G_CHECKSUM_SHA256, reinterpret_cast(executablePath.data()), executablePath.length())); - id.get() = makeString("org.webkit.app-"_s, span(digest.get())).utf8(); + id.get() = makeString("org.webkit.app-"_s, unsafeSpan(digest.get())).utf8(); return; } diff --git a/Source/WTF/wtf/text/ASCIILiteral.h b/Source/WTF/wtf/text/ASCIILiteral.h index 8d340c30eb058..15dd7cd4c0ddc 100644 --- a/Source/WTF/wtf/text/ASCIILiteral.h +++ b/Source/WTF/wtf/text/ASCIILiteral.h @@ -65,7 +65,6 @@ class ASCIILiteral final { constexpr size_t length() const { return !m_charactersWithNullTerminator.empty() ? m_charactersWithNullTerminator.size() - 1 : 0; } constexpr std::span span() const { return m_charactersWithNullTerminator.first(length()); } std::span span8() const { return byteCast(m_charactersWithNullTerminator.first(length())); } - std::span spanChar8() const { return byteCast(m_charactersWithNullTerminator.first(length())); } std::span spanIncludingNullTerminator() const { return m_charactersWithNullTerminator; } size_t isEmpty() const { return m_charactersWithNullTerminator.size() <= 1; } @@ -150,14 +149,9 @@ constexpr std::span operator"" _span(const char* characte return std::span { std::bit_cast(characters), n }; } -constexpr std::span operator""_spanChar8(const char* characters, size_t n) +constexpr std::span operator""_span(const char8_t* characters, size_t n) { - auto span = byteCast(unsafeMakeSpan(characters, n)); -#if ASSERT_ENABLED - for (size_t i = 0, size = span.size(); i < size; ++i) - ASSERT_UNDER_CONSTEXPR_CONTEXT(isASCII(span[i])); -#endif - return span; + return unsafeMakeSpan(characters, n); } } // inline StringLiterals diff --git a/Source/WTF/wtf/text/AtomString.h b/Source/WTF/wtf/text/AtomString.h index f248991785ac3..2a1cfdc815be6 100644 --- a/Source/WTF/wtf/text/AtomString.h +++ b/Source/WTF/wtf/text/AtomString.h @@ -20,6 +20,7 @@ #pragma once +#include "StringCommon.h" #include #include #include @@ -282,7 +283,7 @@ inline AtomString AtomString::fromUTF8(const char* characters) return nullAtom(); if (!*characters) return emptyAtom(); - return fromUTF8Internal(span(characters)); + return fromUTF8Internal(unsafeSpan(characters)); } inline AtomString String::toExistingAtomString() const diff --git a/Source/WTF/wtf/text/AtomStringImpl.h b/Source/WTF/wtf/text/AtomStringImpl.h index 5d12d7e9c8528..8b733962c8184 100644 --- a/Source/WTF/wtf/text/AtomStringImpl.h +++ b/Source/WTF/wtf/text/AtomStringImpl.h @@ -20,6 +20,7 @@ #pragma once +#include "StringCommon.h" #include namespace WTF { @@ -113,7 +114,7 @@ ALWAYS_INLINE Ref AtomStringImpl::add(ASCIILiteral literal) ALWAYS_INLINE RefPtr AtomStringImpl::addCString(const char* s) { - return s ? add(WTF::span8(s)) : nullptr; + return s ? add(byteCast(WTF::unsafeSpan(s))) : nullptr; } template diff --git a/Source/WTF/wtf/text/CString.cpp b/Source/WTF/wtf/text/CString.cpp index 1e62ab3ca4ed3..8847fe3cc5d86 100644 --- a/Source/WTF/wtf/text/CString.cpp +++ b/Source/WTF/wtf/text/CString.cpp @@ -50,7 +50,7 @@ CString::CString(const char* string) if (!string) return; - init(WTF::span(string)); + init(WTF::unsafeSpan(string)); } CString::CString(std::span string) diff --git a/Source/WTF/wtf/text/StringCommon.h b/Source/WTF/wtf/text/StringCommon.h index c0f5d82601e89..3526eadc2d227 100644 --- a/Source/WTF/wtf/text/StringCommon.h +++ b/Source/WTF/wtf/text/StringCommon.h @@ -45,25 +45,36 @@ inline std::span span(const Latin1Character& character) return { &character, 1 }; } -inline std::span span(const UChar& character) +inline std::span span(const char16_t& character) { return { &character, 1 }; } -inline std::span span8(const char* string) +inline std::span unsafeSpan(const char* string) { - return { byteCast(string), string ? strlen(string) : 0 }; +WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN + return unsafeMakeSpan(string, string ? strlen(string) : 0); +WTF_ALLOW_UNSAFE_BUFFER_USAGE_END } -inline std::span unsafeSpanChar8(const char* string) +inline std::span unsafeSpanIncludingNullTerminator(const char* string) { - return unsafeMakeSpan(byteCast(string), string ? strlen(string) : 0); +WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN + return unsafeMakeSpan(string, string ? strlen(string) + 1 : 0); +WTF_ALLOW_UNSAFE_BUFFER_USAGE_END } -inline std::span span(const char* string) +WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN +inline std::span unsafeSpan(const char16_t* string) { - return { string, string ? strlen(string) : 0 }; + if (!string) + return { }; + size_t length = 0; + while (string[length]) + ++length; + return unsafeMakeSpan(string, length); } +WTF_ALLOW_UNSAFE_BUFFER_USAGE_END #if !HAVE(MISSING_U8STRING) inline std::span span(const std::u8string& string) @@ -459,7 +470,7 @@ bool equalIgnoringASCIICaseCommon(const StringClassA& a, const StringClassB& b) template bool equalIgnoringASCIICaseCommon(const StringClassA& a, const char* b) { - auto bSpan = span8(b); + auto bSpan = unsafeSpan(b); if (a.length() != bSpan.size()) return false; if (a.is8Bit()) @@ -505,8 +516,8 @@ bool containsIgnoringASCIICase(std::span source, ASCIILiter inline size_t findIgnoringASCIICaseWithoutLength(const char* source, const char* matchCharacters) { - auto searchSpan = span(source); - auto matchSpan = span(matchCharacters); + auto searchSpan = unsafeSpan(source); + auto matchSpan = unsafeSpan(matchCharacters); return matchSpan.size() <= searchSpan.size() ? findIgnoringASCIICase(searchSpan, matchSpan, 0) : notFound; } @@ -981,7 +992,7 @@ template inline bool startsWithLettersIgnoringASCIICaseCom inline bool equalIgnoringASCIICase(const char* a, const char* b) { - return equalIgnoringASCIICase(span8(a), span8(b)); + return equalIgnoringASCIICase(unsafeSpan(a), unsafeSpan(b)); } inline bool equalLettersIgnoringASCIICase(ASCIILiteral a, ASCIILiteral b) @@ -991,7 +1002,7 @@ inline bool equalLettersIgnoringASCIICase(ASCIILiteral a, ASCIILiteral b) inline bool equalIgnoringASCIICase(const char* string, ASCIILiteral literal) { - return equalIgnoringASCIICase(span8(string), literal.span8()); + return equalIgnoringASCIICase(unsafeSpan(string), literal.span()); } inline bool equalIgnoringASCIICase(ASCIILiteral a, ASCIILiteral b) @@ -1288,9 +1299,10 @@ using WTF::equalLettersIgnoringASCIICaseWithLength; using WTF::findIgnoringASCIICase; using WTF::isLatin1; using WTF::reverseFind; -using WTF::span8; using WTF::span; using WTF::spanHasPrefixIgnoringASCIICase; using WTF::startsWith; using WTF::startsWithLettersIgnoringASCIICase; -using WTF::unsafeSpanChar8; +using WTF::unsafeSpan; +using WTF::unsafeSpanIncludingNullTerminator; + diff --git a/Source/WTF/wtf/text/StringConcatenate.h b/Source/WTF/wtf/text/StringConcatenate.h index 183adb83a4dca..ee0e78ca81b73 100644 --- a/Source/WTF/wtf/text/StringConcatenate.h +++ b/Source/WTF/wtf/text/StringConcatenate.h @@ -67,9 +67,9 @@ template<> class StringTypeAdapter { char m_character; }; -template<> class StringTypeAdapter { +template<> class StringTypeAdapter { public: - StringTypeAdapter(UChar character) + StringTypeAdapter(char16_t character) : m_character { character } { } @@ -83,10 +83,10 @@ template<> class StringTypeAdapter { *destination = m_character; } - void writeTo(UChar* destination) const { *destination = m_character; } + void writeTo(char16_t* destination) const { *destination = m_character; } private: - UChar m_character; + char16_t m_character; }; template<> class StringTypeAdapter { @@ -125,31 +125,9 @@ inline unsigned stringLength(size_t length) return static_cast(length); } -template<> class StringTypeAdapter { +template<> class StringTypeAdapter { public: - StringTypeAdapter(const Latin1Character* characters) - : m_characters { characters } - , m_length { computeLength(characters) } - { - } - - unsigned length() const { return m_length; } - bool is8Bit() const { return true; } - template void writeTo(CharacterType* destination) const { StringImpl::copyCharacters(destination, { m_characters, m_length }); } - -private: - static unsigned computeLength(const Latin1Character* characters) - { - return stringLength(std::strlen(byteCast(characters))); - } - - const Latin1Character* m_characters; - unsigned m_length; -}; - -template<> class StringTypeAdapter { -public: - StringTypeAdapter(const UChar* characters) + StringTypeAdapter(const char16_t* characters) : m_characters { characters } , m_length { computeLength(characters) } { @@ -161,7 +139,7 @@ template<> class StringTypeAdapter { void writeTo(char16_t* destination) const { StringImpl::copyCharacters(destination, { m_characters, m_length }); } private: - static unsigned computeLength(const UChar* characters) + static unsigned computeLength(const char16_t* characters) { size_t length = 0; while (characters[length]) @@ -169,7 +147,7 @@ template<> class StringTypeAdapter { return stringLength(length); } - const UChar* m_characters; + const char16_t* m_characters; unsigned m_length; }; diff --git a/Source/WTF/wtf/text/StringImpl.h b/Source/WTF/wtf/text/StringImpl.h index f4d712100876c..6f79fb1ea1951 100644 --- a/Source/WTF/wtf/text/StringImpl.h +++ b/Source/WTF/wtf/text/StringImpl.h @@ -264,9 +264,6 @@ class StringImpl : private StringImplShape { // Construct a string with UTF-8 data, null if it contains invalid UTF-8 sequences. WTF_EXPORT_PRIVATE static RefPtr create(std::span); - // Not using create() naming to encourage developers to call create(ASCIILiteral) when they have a string literal. - ALWAYS_INLINE static Ref createFromCString(const char* characters) { return create(WTF::span8(characters)); } - static Ref createSubstringSharingImpl(StringImpl&, unsigned offset, unsigned length); ALWAYS_INLINE static Ref create(ASCIILiteral literal) { return createWithoutCopying(literal.span8()); } @@ -623,13 +620,13 @@ template<> struct ValueCheck { WTF_EXPORT_PRIVATE bool equal(const StringImpl*, const StringImpl*); WTF_EXPORT_PRIVATE bool equal(const StringImpl*, const Latin1Character*); -inline bool equal(const StringImpl* a, const char* b) { return equal(a, byteCast(b)); } WTF_EXPORT_PRIVATE bool equal(const StringImpl*, std::span); WTF_EXPORT_PRIVATE bool equal(const StringImpl*, std::span); +inline bool equal(const StringImpl* a, const char* b) { return equal(a, byteCast(unsafeSpan(b))); } ALWAYS_INLINE bool equal(const StringImpl* a, ASCIILiteral b) { return equal(a, b.span8()); } inline bool equal(const StringImpl* a, std::span b) { return equal(a, byteCast(b)); } inline bool equal(const Latin1Character* a, StringImpl* b) { return equal(b, a); } -inline bool equal(const char* a, StringImpl* b) { return equal(b, byteCast(a)); } +inline bool equal(const char* a, StringImpl* b) { return equal(b, byteCast(unsafeSpan(a))); } WTF_EXPORT_PRIVATE bool equal(const StringImpl& a, const StringImpl& b); WTF_EXPORT_PRIVATE bool equalIgnoringNullity(StringImpl*, StringImpl*); diff --git a/Source/WTF/wtf/text/StringView.h b/Source/WTF/wtf/text/StringView.h index 95cae18744024..4a48dc3d61433 100644 --- a/Source/WTF/wtf/text/StringView.h +++ b/Source/WTF/wtf/text/StringView.h @@ -256,7 +256,7 @@ class StringView final { template void append(Vector&, StringView); bool equal(StringView, StringView); -bool equal(StringView, const Latin1Character* b); +bool equal(StringView, std::span); bool equalIgnoringASCIICase(StringView, StringView); bool equalIgnoringASCIICase(StringView, ASCIILiteral); @@ -411,8 +411,8 @@ inline StringView::StringView(std::span characters) } inline StringView::StringView(const char* characters) + : StringView { unsafeSpan(characters) } { - initialize(WTF::span8(characters)); } inline StringView::StringView(std::span characters) @@ -792,25 +792,24 @@ ALWAYS_INLINE bool equal(StringView a, StringView b) return equalCommon(a, b); } -inline bool equal(StringView a, const Latin1Character* b) +inline bool equal(StringView a, std::span b) { - if (!b) + if (!b.data()) return !a.isEmpty(); if (a.isEmpty()) - return !b; + return !b.data(); - auto bSpan = span8(byteCast(b)); - if (a.length() != bSpan.size()) + if (a.length() != b.size()) return false; if (a.is8Bit()) - return equal(a.span8().data(), bSpan); - return equal(a.span16().data(), bSpan); + return equal(a.span8().data(), b); + return equal(a.span16().data(), b); } ALWAYS_INLINE bool equal(StringView a, ASCIILiteral b) { - return equal(a, b.span8().data()); + return equal(a, b.span8()); } inline bool equalIgnoringASCIICase(StringView a, StringView b) diff --git a/Source/WTF/wtf/text/TextStream.cpp b/Source/WTF/wtf/text/TextStream.cpp index ba792aa95dbb4..c3647c8eb778a 100644 --- a/Source/WTF/wtf/text/TextStream.cpp +++ b/Source/WTF/wtf/text/TextStream.cpp @@ -108,7 +108,7 @@ TextStream& TextStream::operator<<(double d) TextStream& TextStream::operator<<(const char* string) { - m_text.append(span(string)); + m_text.append(unsafeSpan(string)); return *this; } diff --git a/Source/WTF/wtf/text/WTFString.cpp b/Source/WTF/wtf/text/WTFString.cpp index 5df22edf4053d..46e0443addc61 100644 --- a/Source/WTF/wtf/text/WTFString.cpp +++ b/Source/WTF/wtf/text/WTFString.cpp @@ -65,7 +65,7 @@ String::String(std::span characters) // Construct a string with Latin-1 data, from a null-terminated source. String::String(const char* nullTerminatedString) - : m_impl(nullTerminatedString ? RefPtr { StringImpl::createFromCString(nullTerminatedString) } : nullptr) + : m_impl(nullTerminatedString ? RefPtr { StringImpl::create(byteCast(unsafeSpan(nullTerminatedString))) } : nullptr) { } diff --git a/Source/WTF/wtf/text/WTFString.h b/Source/WTF/wtf/text/WTFString.h index dd5fcb0f41f60..969e3b6b5a2d8 100644 --- a/Source/WTF/wtf/text/WTFString.h +++ b/Source/WTF/wtf/text/WTFString.h @@ -265,14 +265,18 @@ class String final { WTF_EXPORT_PRIVATE void convertTo16Bit(); // String::fromUTF8 will return a null string if the input data contains invalid UTF-8 sequences. + // FIXME: Deprecated: Use constructor that takes span. WTF_EXPORT_PRIVATE static String fromUTF8(std::span); - static String fromUTF8(std::span characters) { return fromUTF8(byteCast(characters)); } - static String fromUTF8(std::span characters) { return fromUTF8(byteCast(characters)); } - static String fromUTF8(const char* string) { return fromUTF8(WTF::span8(string)); } + static String fromUTF8(std::span characters) { return byteCast(characters); } + static String fromUTF8(std::span characters) { return byteCast(characters); } + static String fromUTF8(const char* string) { return byteCast(unsafeSpan(string)); } + + // Convert each invalid UTF-8 sequence into a replacement character. static String fromUTF8ReplacingInvalidSequences(std::span); static String fromUTF8ReplacingInvalidSequences(std::span characters) { return fromUTF8ReplacingInvalidSequences(byteCast(characters)); } // Tries to convert the passed in string to UTF-8, but will fall back to Latin-1 if the string is not valid UTF-8. + // FIXME: Deprecated: Use fromUTF8ReplacingInvalidSequences. WTF_EXPORT_PRIVATE static String fromUTF8WithLatin1Fallback(std::span); static String fromUTF8WithLatin1Fallback(std::span characters) { return fromUTF8WithLatin1Fallback(byteCast(characters)); } static String fromUTF8WithLatin1Fallback(std::span characters) { return fromUTF8WithLatin1Fallback(byteCast(characters)); } diff --git a/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp b/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp index 984d024419054..f2882095c93af 100644 --- a/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp +++ b/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp @@ -253,7 +253,7 @@ static IDBError createOrMigrateRecordsTableIfNecessary(SQLiteDatabase& database) String tableStatement = database.tableSQL("Records"_s); if (tableStatement.isEmpty()) { if (!database.executeCommand(v3RecordsTableSchema())) - return IDBError { ExceptionCode::UnknownError, makeString("Error creating Records table ("_s, database.lastError(), ") - "_s, span(database.lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error creating Records table ("_s, database.lastError(), ") - "_s, unsafeSpan(database.lastErrorMsg())) }; return IDBError { }; } @@ -273,16 +273,16 @@ static IDBError createOrMigrateRecordsTableIfNecessary(SQLiteDatabase& database) // Create a temporary table with the correct schema and migrate all existing content over. if (!database.executeCommand(v3RecordsTableSchemaTemp())) - return IDBError { ExceptionCode::UnknownError, makeString("Error creating temporary Records table ("_s, database.lastError(), ") - "_s, span(database.lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error creating temporary Records table ("_s, database.lastError(), ") - "_s, unsafeSpan(database.lastErrorMsg())) }; if (!database.executeCommand("INSERT INTO _Temp_Records (objectStoreID, key, value) SELECT objectStoreID, CAST(key AS TEXT), value FROM Records"_s)) - return IDBError { ExceptionCode::UnknownError, makeString("Error migrating Records table ("_s, database.lastError(), ") - "_s, span(database.lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error migrating Records table ("_s, database.lastError(), ") - "_s, unsafeSpan(database.lastErrorMsg())) }; if (!database.executeCommand("DROP TABLE Records"_s)) - return IDBError { ExceptionCode::UnknownError, makeString("Error dropping Records table ("_s, database.lastError(), ") - "_s, span(database.lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error dropping Records table ("_s, database.lastError(), ") - "_s, unsafeSpan(database.lastErrorMsg())) }; if (!database.executeCommand("ALTER TABLE _Temp_Records RENAME TO Records"_s)) - return IDBError { ExceptionCode::UnknownError, makeString("Error renaming temporary Records table ("_s, database.lastError(), ") - "_s, span(database.lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error renaming temporary Records table ("_s, database.lastError(), ") - "_s, unsafeSpan(database.lastErrorMsg())) }; transaction.commit(); @@ -297,7 +297,7 @@ IDBError SQLiteIDBBackingStore::ensureValidBlobTables() String recordsTableStatement = m_sqliteDB->tableSQL("BlobRecords"_s); if (recordsTableStatement.isEmpty()) { if (!m_sqliteDB->executeCommand(blobRecordsTableSchema())) - return IDBError { ExceptionCode::UnknownError, makeString("Error creating BlobRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error creating BlobRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; recordsTableStatement = blobRecordsTableSchema(); } @@ -307,7 +307,7 @@ IDBError SQLiteIDBBackingStore::ensureValidBlobTables() String filesTableStatement = m_sqliteDB->tableSQL("BlobFiles"_s); if (filesTableStatement.isEmpty()) { if (!m_sqliteDB->executeCommand(blobFilesTableSchema())) - return IDBError { ExceptionCode::UnknownError, makeString("Error creating BlobFiles table ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error creating BlobFiles table ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; filesTableStatement = blobFilesTableSchema(); } @@ -328,7 +328,7 @@ IDBError SQLiteIDBBackingStore::ensureValidRecordsTable() // Whether the updated records table already existed or if it was just created and the data migrated over, // make sure the uniqueness index exists. if (!m_sqliteDB->executeCommand("CREATE UNIQUE INDEX IF NOT EXISTS RecordsIndex ON Records (objectStoreID, key);"_s)) - error = IDBError { ExceptionCode::UnknownError, makeString("Error creating RecordsIndex on Records table ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + error = IDBError { ExceptionCode::UnknownError, makeString("Error creating RecordsIndex on Records table ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; return error; } @@ -341,7 +341,7 @@ IDBError SQLiteIDBBackingStore::ensureValidIndexRecordsTable() String tableStatement = m_sqliteDB->tableSQL("IndexRecords"_s); if (tableStatement.isEmpty()) { if (!m_sqliteDB->executeCommand(v3IndexRecordsTableSchema())) - return IDBError { ExceptionCode::UnknownError, makeString("Error creating IndexRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error creating IndexRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; return IDBError { }; } @@ -357,16 +357,16 @@ IDBError SQLiteIDBBackingStore::ensureValidIndexRecordsTable() // Create a temporary table with the correct schema and migrate all existing content over. if (!m_sqliteDB->executeCommand(v3IndexRecordsTableSchemaTemp())) - return IDBError { ExceptionCode::UnknownError, makeString("Error creating temporary IndexRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error creating temporary IndexRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; if (!m_sqliteDB->executeCommand("INSERT INTO _Temp_IndexRecords SELECT IndexRecords.indexID, IndexRecords.objectStoreID, IndexRecords.key, IndexRecords.value, Records.rowid FROM IndexRecords INNER JOIN Records ON Records.key = IndexRecords.value AND Records.objectStoreID = IndexRecords.objectStoreID"_s)) - return IDBError { ExceptionCode::UnknownError, makeString("Error migrating IndexRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error migrating IndexRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; if (!m_sqliteDB->executeCommand("DROP TABLE IndexRecords"_s)) - return IDBError { ExceptionCode::UnknownError, makeString("Error dropping IndexRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error dropping IndexRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; if (!m_sqliteDB->executeCommand("ALTER TABLE _Temp_IndexRecords RENAME TO IndexRecords"_s)) - return IDBError { ExceptionCode::UnknownError, makeString("Error renaming temporary IndexRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error renaming temporary IndexRecords table ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; transaction.commit(); @@ -383,10 +383,10 @@ IDBError SQLiteIDBBackingStore::ensureValidIndexRecordsIndex() return IDBError { }; if (!m_sqliteDB->executeCommand("DROP INDEX IF EXISTS IndexRecordsIndex"_s)) - return IDBError { ExceptionCode::UnknownError, makeString("Error dropping IndexRecordsIndex index ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error dropping IndexRecordsIndex index ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; if (!m_sqliteDB->executeCommand(IndexRecordsIndexSchema)) - return IDBError { ExceptionCode::UnknownError, makeString("Error creating IndexRecordsIndex index ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error creating IndexRecordsIndex index ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; return IDBError { }; } @@ -401,10 +401,10 @@ IDBError SQLiteIDBBackingStore::ensureValidIndexRecordsRecordIndex() return IDBError { }; if (!m_sqliteDB->executeCommand("DROP INDEX IF EXISTS IndexRecordsRecordIndex"_s)) - return IDBError { ExceptionCode::UnknownError, makeString("Error dropping IndexRecordsRecordIndex index ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error dropping IndexRecordsRecordIndex index ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; if (!m_sqliteDB->executeCommand(v1IndexRecordsRecordIndexSchema)) - return IDBError { ExceptionCode::UnknownError, makeString("Error creating IndexRecordsRecordIndex index ("_s, m_sqliteDB->lastError(), ") - "_s, span(m_sqliteDB->lastErrorMsg())) }; + return IDBError { ExceptionCode::UnknownError, makeString("Error creating IndexRecordsRecordIndex index ("_s, m_sqliteDB->lastError(), ") - "_s, unsafeSpan(m_sqliteDB->lastErrorMsg())) }; return IDBError { }; } diff --git a/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCUtils.cpp b/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCUtils.cpp index df79b7572360b..08626458993cf 100644 --- a/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCUtils.cpp +++ b/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCUtils.cpp @@ -193,7 +193,7 @@ static inline RTCRtpCodecParameters toRTCCodecParameters(const webrtc::RtpCodecP sdpFmtpLineBuilder.append(';'); else isFirst = false; - sdpFmtpLineBuilder.append(span(keyValue.first.c_str()), '=', span(keyValue.second.c_str())); + sdpFmtpLineBuilder.append(unsafeSpan(keyValue.first.c_str()), '=', unsafeSpan(keyValue.second.c_str())); } parameters.sdpFmtpLine = sdpFmtpLineBuilder.toString(); diff --git a/Source/WebCore/Modules/webdatabase/Database.cpp b/Source/WebCore/Modules/webdatabase/Database.cpp index e194d3543e8f3..d2560b61dc457 100644 --- a/Source/WebCore/Modules/webdatabase/Database.cpp +++ b/Source/WebCore/Modules/webdatabase/Database.cpp @@ -107,7 +107,7 @@ static const String& fullyQualifiedInfoTableName() static String formatErrorMessage(ASCIILiteral message, int sqliteErrorCode, const char* sqliteErrorMessage) { - return makeString(message, " ("_s, sqliteErrorCode, ' ', span(sqliteErrorMessage), ')'); + return makeString(message, " ("_s, sqliteErrorCode, ' ', unsafeSpan(sqliteErrorMessage), ')'); } static bool setTextValueInDatabase(SQLiteDatabase& db, StringView query, const String& value) diff --git a/Source/WebCore/Modules/webdatabase/SQLError.h b/Source/WebCore/Modules/webdatabase/SQLError.h index 72f5053a0c842..13078763c0ded 100644 --- a/Source/WebCore/Modules/webdatabase/SQLError.h +++ b/Source/WebCore/Modules/webdatabase/SQLError.h @@ -42,7 +42,7 @@ class SQLError : public ThreadSafeRefCounted { } static Ref create(unsigned code, ASCIILiteral message, int sqliteCode, const char* sqliteMessage) { - return create(code, makeString(message, " ("_s, sqliteCode, ' ', span(sqliteMessage), ')')); + return create(code, makeString(message, " ("_s, sqliteCode, ' ', unsafeSpan(sqliteMessage), ')')); } unsigned code() const { return m_code; } diff --git a/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp b/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp index 06abf198aa081..f1ad7dbe7ed27 100644 --- a/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp +++ b/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp @@ -295,8 +295,8 @@ JSC::EncodedJSValue rejectPromiseWithGetterTypeError(JSC::JSGlobalObject& lexica String makeThisTypeErrorMessage(const char* interfaceName, const char* functionName) { - auto interfaceNameSpan = span(interfaceName); - return makeString("Can only call "_s, interfaceNameSpan, '.', span(functionName), " on instances of "_s, interfaceNameSpan); + auto interfaceNameSpan = unsafeSpan(interfaceName); + return makeString("Can only call "_s, interfaceNameSpan, '.', unsafeSpan(functionName), " on instances of "_s, interfaceNameSpan); } String makeUnsupportedIndexedSetterErrorMessage(ASCIILiteral interfaceName) diff --git a/Source/WebCore/bridge/IdentifierRep.cpp b/Source/WebCore/bridge/IdentifierRep.cpp index 626f7f780787b..32bad5261b07b 100644 --- a/Source/WebCore/bridge/IdentifierRep.cpp +++ b/Source/WebCore/bridge/IdentifierRep.cpp @@ -91,7 +91,7 @@ IdentifierRep* IdentifierRep::get(const char* name) if (!name) return nullptr; - String string = String::fromUTF8WithLatin1Fallback(span(name)); + String string = String::fromUTF8WithLatin1Fallback(unsafeSpan(name)); StringIdentifierMap::AddResult result = stringIdentifierMap().add(string.impl(), nullptr); if (result.isNewEntry) { ASSERT(!result.iterator->value); diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp index 617d44dbce67f..e6755fa9a2ae5 100644 --- a/Source/WebCore/dom/Document.cpp +++ b/Source/WebCore/dom/Document.cpp @@ -10153,7 +10153,7 @@ RefPtr Document::attachmentForIdentifier(const String& id static MessageSource messageSourceForWTFLogChannel(const WTFLogChannel& channel) { - auto channelName = span(channel.name); + auto channelName = unsafeSpan(channel.name); if (equalLettersIgnoringASCIICase(channelName, "media"_s)) return MessageSource::Media; diff --git a/Source/WebCore/editing/TextIterator.cpp b/Source/WebCore/editing/TextIterator.cpp index 45838976b1d9b..19b597f049955 100644 --- a/Source/WebCore/editing/TextIterator.cpp +++ b/Source/WebCore/editing/TextIterator.cpp @@ -1763,7 +1763,7 @@ static UStringSearch* createSearcher() // but it doesn't matter exactly what it is, since we don't perform any searches // without setting both the pattern and the text. UErrorCode status = U_ZERO_ERROR; - auto searchCollatorName = makeString(span(currentSearchLocaleID()), "@collation=search"_s); + auto searchCollatorName = makeString(unsafeSpan(currentSearchLocaleID()), "@collation=search"_s); UStringSearch* searcher = usearch_open(&newlineCharacter, 1, &newlineCharacter, 1, searchCollatorName.utf8().data(), 0, &status); ASSERT(U_SUCCESS(status) || status == U_USING_FALLBACK_WARNING || status == U_USING_DEFAULT_WARNING); return searcher; diff --git a/Source/WebCore/loader/PrivateClickMeasurement.cpp b/Source/WebCore/loader/PrivateClickMeasurement.cpp index d8921dd1fc204..6e20b0613c551 100644 --- a/Source/WebCore/loader/PrivateClickMeasurement.cpp +++ b/Source/WebCore/loader/PrivateClickMeasurement.cpp @@ -263,7 +263,7 @@ bool PrivateClickMeasurement::hasHigherPriorityThan(const PrivateClickMeasuremen static URL makeValidURL(const RegistrableDomain& domain, const char* path) { - URL validURL { makeString("https://"_s, domain.string(), span(path)) }; + URL validURL { makeString("https://"_s, domain.string(), unsafeSpan(path)) }; return validURL.isValid() ? validURL : URL { }; } diff --git a/Source/WebCore/page/NavigatorBase.cpp b/Source/WebCore/page/NavigatorBase.cpp index 71cb38b1cf266..5aed65a74f3e7 100644 --- a/Source/WebCore/page/NavigatorBase.cpp +++ b/Source/WebCore/page/NavigatorBase.cpp @@ -94,7 +94,7 @@ String NavigatorBase::platform() const static std::once_flag onceKey; std::call_once(onceKey, [] { struct utsname osname; - platformName.construct(uname(&osname) >= 0 ? makeString(span(osname.sysname), " "_s, span(osname.machine)) : emptyString()); + platformName.construct(uname(&osname) >= 0 ? makeString(unsafeSpan(osname.sysname), " "_s, unsafeSpan(osname.machine)) : emptyString()); }); return platformName->isolatedCopy(); #elif PLATFORM(IOS_FAMILY) diff --git a/Source/WebCore/page/PrintContext.cpp b/Source/WebCore/page/PrintContext.cpp index f1b72fc4c2854..7f96ed5358045 100644 --- a/Source/WebCore/page/PrintContext.cpp +++ b/Source/WebCore/page/PrintContext.cpp @@ -385,7 +385,7 @@ String PrintContext::pageProperty(LocalFrame* frame, const char* propertyName, i if (!strcmp(propertyName, "size")) return makeString(style->pageSize().width.value(), ' ', style->pageSize().height.value()); - return makeString("pageProperty() unimplemented for: "_s, span(propertyName)); + return makeString("pageProperty() unimplemented for: "_s, unsafeSpan(propertyName)); } bool PrintContext::isPageBoxVisible(LocalFrame* frame, int pageNumber) diff --git a/Source/WebCore/platform/Decimal.cpp b/Source/WebCore/platform/Decimal.cpp index 5dbd49dee25f6..ae1662524e19b 100644 --- a/Source/WebCore/platform/Decimal.cpp +++ b/Source/WebCore/platform/Decimal.cpp @@ -545,7 +545,7 @@ Decimal Decimal::fromDouble(double doubleValue) if (std::isfinite(doubleValue)) { NumberToStringBuffer buffer; auto* result = numberToString(doubleValue, buffer); - return fromString(span8(result)); + return fromString(byteCast(unsafeSpan(result))); } if (std::isinf(doubleValue)) diff --git a/Source/WebCore/platform/SharedBufferChunkReader.cpp b/Source/WebCore/platform/SharedBufferChunkReader.cpp index c750e817e2195..5cc46b06f86ca 100644 --- a/Source/WebCore/platform/SharedBufferChunkReader.cpp +++ b/Source/WebCore/platform/SharedBufferChunkReader.cpp @@ -60,7 +60,7 @@ void SharedBufferChunkReader::setSeparator(const Vector& separator) void SharedBufferChunkReader::setSeparator(const char* separator) { m_separator.clear(); - m_separator.append(span(separator)); + m_separator.append(unsafeSpan(separator)); } bool SharedBufferChunkReader::nextChunk(Vector& chunk, bool includeSeparator) diff --git a/Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp index 06d52cd70e7da..3d810e6c0d4c1 100644 --- a/Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/AudioEncoderGStreamer.cpp @@ -189,7 +189,7 @@ GStreamerInternalAudioEncoder::GStreamerInternalAudioEncoder(AudioEncoder::Descr , m_encoder(WTFMove(encoderElement)) { static Atomic counter = 0; - auto binName = makeString("audio-encoder-"_s, span(GST_OBJECT_NAME(m_encoder.get())), '-', counter.exchangeAdd(1)); + auto binName = makeString("audio-encoder-"_s, unsafeSpan(GST_OBJECT_NAME(m_encoder.get())), '-', counter.exchangeAdd(1)); GRefPtr harnessedElement = gst_bin_new(binName.ascii().data()); auto audioconvert = gst_element_factory_make("audioconvert", nullptr); diff --git a/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp index 16877a5cd3104..acc53bed9cae5 100644 --- a/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp @@ -275,7 +275,7 @@ void AudioFileReader::handleMessage(GstMessage* message) GST_INFO_OBJECT(m_pipeline.get(), "State changed (old: %s, new: %s, pending: %s)", gst_element_state_get_name(oldState), gst_element_state_get_name(newState), gst_element_state_get_name(pending)); - auto dotFileName = makeString(span(GST_OBJECT_NAME(m_pipeline.get())), '_', span(gst_element_state_get_name(oldState)), '_', span(gst_element_state_get_name(newState))); + auto dotFileName = makeString(unsafeSpan(GST_OBJECT_NAME(m_pipeline.get())), '_', unsafeSpan(gst_element_state_get_name(oldState)), '_', unsafeSpan(gst_element_state_get_name(newState))); GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN_CAST(m_pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.utf8().data()); break; } diff --git a/Source/WebCore/platform/glib/UserAgentGLib.cpp b/Source/WebCore/platform/glib/UserAgentGLib.cpp index f0313e9154d39..50d134bf418a1 100644 --- a/Source/WebCore/platform/glib/UserAgentGLib.cpp +++ b/Source/WebCore/platform/glib/UserAgentGLib.cpp @@ -66,7 +66,7 @@ static const String platformVersionForUAString() struct utsname name; uname(&name); - static NeverDestroyed uaOSVersion(makeString(span(name.sysname), ' ', span(name.machine))); + static NeverDestroyed uaOSVersion(makeString(unsafeSpan(name.sysname), ' ', unsafeSpan(name.machine))); return uaOSVersion; #else // We will always claim to be Safari in Intel Mac OS X, since Safari without diff --git a/Source/WebCore/platform/graphics/ColorSerialization.cpp b/Source/WebCore/platform/graphics/ColorSerialization.cpp index 894d36cb8fa7b..9b4262bf7f349 100644 --- a/Source/WebCore/platform/graphics/ColorSerialization.cpp +++ b/Source/WebCore/platform/graphics/ColorSerialization.cpp @@ -592,7 +592,7 @@ String serializationForCSS(SRGBA color, bool useColorFunctionSerializat case 0xFF: return makeString("rgb("_s, red, ", "_s, green, ", "_s, blue, ')'); default: - return makeString("rgba("_s, red, ", "_s, green, ", "_s, blue, ", 0."_s, span(fractionDigitsForFractionalAlphaValue(alpha).data()), ')'); + return makeString("rgba("_s, red, ", "_s, green, ", "_s, blue, ", 0."_s, unsafeSpan(fractionDigitsForFractionalAlphaValue(alpha).data()), ')'); } } diff --git a/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm b/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm index 7de3bbba73808..e877997d3590e 100644 --- a/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm +++ b/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm @@ -104,8 +104,8 @@ static EGLDisplay initializeEGLDisplay(const GraphicsContextGLAttributes& attrs) } #if ASSERT_ENABLED - const char* clientExtensions = EGL_QueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); - ASSERT(clientExtensions); + auto clientExtensions = unsafeSpan(EGL_QueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS)); + ASSERT(clientExtensions.data()); #endif Vector displayAttributes; @@ -149,9 +149,9 @@ static EGLDisplay initializeEGLDisplay(const GraphicsContextGLAttributes& attrs) } LOG(WebGL, "ANGLE initialised Major: %d Minor: %d", majorVersion, minorVersion); -#if ASSERT_ENABLED && ENABLE(WEBXR) - const char* displayExtensions = EGL_QueryString(display, EGL_EXTENSIONS); - ASSERT(strstr(displayExtensions, "EGL_ANGLE_metal_shared_event_sync")); +#if ASSERT_ENABLED + auto displayExtensions = unsafeSpan(EGL_QueryString(display, EGL_EXTENSIONS)); + ASSERT(WTF::contains(displayExtensions, "EGL_ANGLE_metal_shared_event_sync"_span)); #endif return display; diff --git a/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp b/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp index c51a63adb1599..0e47050460fc6 100644 --- a/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp +++ b/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp @@ -205,7 +205,7 @@ String FontPlatformData::familyName() const { FcChar8* family = nullptr; FcPatternGetString(m_pattern.get(), FC_FAMILY, 0, &family); - return String::fromUTF8(span8(reinterpret_cast(family))); + return byteCast(unsafeSpan(byteCast(family))); } Vector FontPlatformData::variationAxes(ShouldLocalizeAxisNames shouldLocalizeAxisNames) const diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp index 311b71a86415b..b17c11a8ac528 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp @@ -571,14 +571,14 @@ void registerActivePipeline(const GRefPtr& pipeline) { GUniquePtr name(gst_object_get_name(GST_OBJECT_CAST(pipeline.get()))); Locker locker { s_activePipelinesMapLock }; - activePipelinesMap().add(span(name.get()), GRefPtr(pipeline)); + activePipelinesMap().add(unsafeSpan(name.get()), GRefPtr(pipeline)); } void unregisterPipeline(const GRefPtr& pipeline) { GUniquePtr name(gst_object_get_name(GST_OBJECT_CAST(pipeline.get()))); Locker locker { s_activePipelinesMapLock }; - activePipelinesMap().remove(span(name.get())); + activePipelinesMap().remove(unsafeSpan(name.get())); } void WebCoreLogObserver::didLogMessage(const WTFLogChannel& channel, WTFLogLevel level, Vector&& values) @@ -890,7 +890,7 @@ void connectSimpleBusMessageCallback(GstElement* pipeline, Function> gstStructureValueToJSON(const GValue* } if (valueType == G_TYPE_STRING) - return JSON::Value::create(makeString(span(g_value_get_string(value))))->asValue(); + return JSON::Value::create(makeString(unsafeSpan(g_value_get_string(value))))->asValue(); #if USE(GSTREAMER_WEBRTC) if (valueType == GST_TYPE_WEBRTC_STATS_TYPE) { diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp index 84b733a0d6225..45154476d8623 100644 --- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp @@ -2622,7 +2622,7 @@ void MediaPlayerPrivateGStreamer::configureElement(GstElement* element) configureElementPlatformQuirks(element); GUniquePtr elementName(gst_element_get_name(element)); - String elementClass = WTF::span(gst_element_get_metadata(element, GST_ELEMENT_METADATA_KLASS)); + String elementClass = WTF::unsafeSpan(gst_element_get_metadata(element, GST_ELEMENT_METADATA_KLASS)); auto classifiers = elementClass.split('/'); // In GStreamer 1.20 and older urisourcebin mishandles source elements with dynamic pads. This diff --git a/Source/WebCore/platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp index aca899902d3e0..04d3020e2219d 100644 --- a/Source/WebCore/platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp @@ -89,7 +89,7 @@ TrackPrivateBaseGStreamer::TrackPrivateBaseGStreamer(TrackType type, TrackPrivat TrackPrivateBaseGStreamer::TrackPrivateBaseGStreamer(TrackType type, TrackPrivateBase* owner, unsigned index, GstStream* stream) : m_notifier(MainThreadNotifier::create()) , m_index(index) - , m_gstStreamId(AtomString::fromLatin1(gst_stream_get_stream_id(stream))) + , m_gstStreamId(byteCast(unsafeSpan(gst_stream_get_stream_id(stream)))) , m_id(parseStreamId(m_gstStreamId).value_or(index)) , m_stream(stream) , m_type(type) @@ -114,7 +114,7 @@ void TrackPrivateBaseGStreamer::setPad(GRefPtr&& pad) m_pad = WTFMove(pad); m_bestUpstreamPad = findBestUpstreamPad(m_pad); - m_gstStreamId = AtomString::fromLatin1(gst_pad_get_stream_id(m_pad.get())); + m_gstStreamId = byteCast(unsafeSpan(gst_pad_get_stream_id(m_pad.get()))); if (m_shouldUsePadStreamId) m_id = parseStreamId(m_gstStreamId).value_or(m_index); @@ -226,8 +226,8 @@ bool TrackPrivateBaseGStreamer::getLanguageCode(GstTagList* tags, AtomString& va { String language; if (getTag(tags, GST_TAG_LANGUAGE_CODE, language)) { - AtomString convertedLanguage = AtomString::fromLatin1(gst_tag_get_language_code_iso_639_1(language.utf8().data())); - GST_DEBUG("Converted track %d's language code to %s.", m_index, convertedLanguage.string().utf8().data()); + AtomString convertedLanguage = byteCast(unsafeSpan(gst_tag_get_language_code_iso_639_1(language.utf8().data()))); + GST_DEBUG("Converted track %" PRIu64 "'s language code to %s.", m_id, convertedLanguage.string().utf8().data()); if (convertedLanguage != value) { value = WTFMove(convertedLanguage); return true; @@ -286,7 +286,7 @@ void TrackPrivateBaseGStreamer::notifyTrackOfStreamChanged() if (!m_pad) return; - auto gstStreamId = AtomString::fromLatin1(gst_pad_get_stream_id(m_pad.get())); + AtomString gstStreamId = byteCast(unsafeSpan(gst_pad_get_stream_id(m_pad.get()))); auto streamId = parseStreamId(gstStreamId); if (!streamId) return; @@ -372,7 +372,7 @@ bool TrackPrivateBaseGStreamer::updateTrackIDFromTags(const GRefPtr& if (!gst_tag_list_get_string(tags.get(), "container-specific-track-id", &trackIDString.outPtr())) return false; - auto trackID = WTF::parseInteger(StringView { std::span { trackIDString.get(), strlen(trackIDString.get()) } }); + auto trackID = WTF::parseInteger(byteCast(unsafeSpan(trackIDString.get()))); if (trackID && *trackID != m_trackID.value_or(0)) { m_trackID = *trackID; ASSERT(m_trackID); diff --git a/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp index cf00d08cf6939..30566a11bafc0 100644 --- a/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp @@ -336,7 +336,7 @@ RefPtr VideoFrameGStreamer::createFromPixelBuffer(Ref VideoFrameGStreamer::convert(GstVideoFormat format, const Int auto width = destinationSize.width(); auto height = destinationSize.height(); - auto formatName = span(gst_video_format_to_string(format)); + auto formatName = unsafeSpan(gst_video_format_to_string(format)); auto outputCaps = adoptGRef(gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, formatName.data(), "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, "framerate", GST_TYPE_FRACTION, frameRateNumerator, frameRateDenominator, nullptr)); if (gst_caps_is_equal(caps, outputCaps.get())) diff --git a/Source/WebCore/platform/graphics/gstreamer/eme/CDMThunder.cpp b/Source/WebCore/platform/graphics/gstreamer/eme/CDMThunder.cpp index e7def092d8582..6dee3898445e2 100644 --- a/Source/WebCore/platform/graphics/gstreamer/eme/CDMThunder.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/eme/CDMThunder.cpp @@ -299,7 +299,7 @@ CDMInstanceSessionThunder::CDMInstanceSessionThunder(CDMInstanceThunder& instanc }; m_thunderSessionCallbacks.error_message_callback = [](OpenCDMSession*, void* userData, const char message[]) { GST_ERROR("Got 'error' OCDM notification: %s", message); - callOnMainThread([session = WeakPtr { static_cast(userData) }, buffer = WebCore::SharedBuffer::create(span(message))]() mutable { + callOnMainThread([session = WeakPtr { static_cast(userData) }, buffer = WebCore::SharedBuffer::create(unsafeSpan(message))]() mutable { if (!session) return; session->errorCallback(WTFMove(buffer)); diff --git a/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp b/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp index e8cbf87f84b64..7dd61ffd8c860 100644 --- a/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp @@ -105,7 +105,7 @@ void AppendPipeline::configureOptionalDemuxerFromAnyThread() { ASSERT(m_demux); - String elementClass = span(gst_element_get_metadata(m_demux.get(), GST_ELEMENT_METADATA_KLASS)); + String elementClass = unsafeSpan(gst_element_get_metadata(m_demux.get(), GST_ELEMENT_METADATA_KLASS)); // We try to detect special cases of demuxers that have a single static src pad, such as id3demux. GRefPtr demuxerSrcPad = adoptGRef(gst_element_get_static_pad(m_demux.get(), "src")); if (!demuxerSrcPad && elementClass.split('/').contains("Demuxer"_s)) { @@ -954,7 +954,7 @@ bool AppendPipeline::recycleTrackForPad(GstPad* demuxerSrcPad) { ASSERT(isMainThread()); ASSERT(m_hasReceivedFirstInitializationSegment); - auto trackId = AtomString::fromLatin1(GST_PAD_NAME(demuxerSrcPad)); + AtomString trackId = byteCast(unsafeSpan(GST_PAD_NAME(demuxerSrcPad))); auto [parsedCaps, streamType, presentationSize] = parseDemuxerSrcPadCaps(adoptGRef(gst_pad_get_current_caps(demuxerSrcPad)).get()); GST_DEBUG_OBJECT(demuxerSrcPad, "Caps: %" GST_PTR_FORMAT, parsedCaps.get()); diff --git a/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp index bb8e1721354c8..ddb4641f6fe54 100644 --- a/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp @@ -219,7 +219,7 @@ static void dumpPipeline([[maybe_unused]] ASCIILiteral description, [[maybe_unus { #ifndef GST_DISABLE_GST_DEBUG auto pipeline = findPipeline(GRefPtr(GST_ELEMENT(stream->source))); - auto fileName = makeString(span(GST_OBJECT_NAME(pipeline.get())), '-', stream->track->id(), '-', description); + auto fileName = makeString(unsafeSpan(GST_OBJECT_NAME(pipeline.get())), '-', stream->track->id(), '-', description); GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN_CAST(pipeline.get()), GST_DEBUG_GRAPH_SHOW_ALL, fileName.utf8().data()); #endif } diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp index f3324e55d657f..53440e6b199a4 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp @@ -536,7 +536,7 @@ Ref TextureMapperShaderProgram::create(TextureMapper { #define SET_APPLIER_FROM_OPTIONS(Applier) \ optionsApplierBuilder.append(\ - (options & TextureMapperShaderProgram::Applier) ? span(ENABLE_APPLIER(Applier)) : span(DISABLE_APPLIER(Applier))) + (options & TextureMapperShaderProgram::Applier) ? unsafeSpan(ENABLE_APPLIER(Applier)) : unsafeSpan(DISABLE_APPLIER(Applier))) unsigned glVersion = GLContext::current()->version(); @@ -574,10 +574,10 @@ Ref TextureMapperShaderProgram::create(TextureMapper vertexShaderBuilder.append(optionsApplierBuilder.toString()); // Append the appropriate input/output variable definitions. - vertexShaderBuilder.append(span(vertexTemplateLT320Vars)); + vertexShaderBuilder.append(unsafeSpan(vertexTemplateLT320Vars)); // Append the common code. - vertexShaderBuilder.append(span(vertexTemplateCommon)); + vertexShaderBuilder.append(unsafeSpan(vertexTemplateCommon)); StringBuilder fragmentShaderBuilder; @@ -585,18 +585,18 @@ Ref TextureMapperShaderProgram::create(TextureMapper fragmentShaderBuilder.append(optionsApplierBuilder.toString()); if (glVersion >= 300) - fragmentShaderBuilder.append(span(GLSL_DIRECTIVE(define GaussianKernelHalfSize u_gaussianKernelHalfSize))); + fragmentShaderBuilder.append(unsafeSpan(GLSL_DIRECTIVE(define GaussianKernelHalfSize u_gaussianKernelHalfSize))); else - fragmentShaderBuilder.append(span(GLSL_DIRECTIVE(define GaussianKernelHalfSize GAUSSIAN_KERNEL_MAX_HALF_SIZE))); + fragmentShaderBuilder.append(unsafeSpan(GLSL_DIRECTIVE(define GaussianKernelHalfSize GAUSSIAN_KERNEL_MAX_HALF_SIZE))); // Append the common header. - fragmentShaderBuilder.append(span(fragmentTemplateHeaderCommon)); + fragmentShaderBuilder.append(unsafeSpan(fragmentTemplateHeaderCommon)); // Append the appropriate input/output variable definitions. - fragmentShaderBuilder.append(span(fragmentTemplateLT320Vars)); + fragmentShaderBuilder.append(unsafeSpan(fragmentTemplateLT320Vars)); // Append the common code. - fragmentShaderBuilder.append(span(fragmentTemplateCommon)); + fragmentShaderBuilder.append(unsafeSpan(fragmentTemplateCommon)); return adoptRef(*new TextureMapperShaderProgram(vertexShaderBuilder.toString(), fragmentShaderBuilder.toString())); } diff --git a/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp b/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp index 3122c7b5fd650..8df0aaa68d5f2 100644 --- a/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp +++ b/Source/WebCore/platform/gstreamer/GStreamerElementHarness.cpp @@ -190,7 +190,7 @@ void GStreamerElementHarness::start(GRefPtr&& inputCaps, std::optional< gst_element_get_state(m_element.get(), nullptr, nullptr, GST_CLOCK_TIME_NONE); static Atomic uniqueStreamId; - auto streamId = makeString(WTF::span(GST_OBJECT_NAME(m_element.get())), '-', uniqueStreamId.exchangeAdd(1)); + auto streamId = makeString(WTF::unsafeSpan(GST_OBJECT_NAME(m_element.get())), '-', uniqueStreamId.exchangeAdd(1)); pushEvent(adoptGRef(gst_event_new_stream_start(streamId.ascii().data()))); pushStickyEvents(WTFMove(inputCaps), WTFMove(segment)); @@ -510,8 +510,8 @@ String MermaidBuilder::generatePadId(GStreamerElementHarness& harness, GstPad* p { auto parent = adoptGRef(gst_pad_get_parent(GST_OBJECT_CAST(pad))); if (!parent) - return makeString(WTF::span(GST_ELEMENT_NAME(harness.element())), "-harness-"_s, WTF::span(GST_PAD_NAME(pad))); - return makeString(WTF::span(GST_OBJECT_NAME(parent.get())), '_', WTF::span(GST_PAD_NAME(pad))); + return makeString(WTF::unsafeSpan(GST_ELEMENT_NAME(harness.element())), "-harness-"_s, WTF::unsafeSpan(GST_PAD_NAME(pad))); + return makeString(WTF::unsafeSpan(GST_OBJECT_NAME(parent.get())), '_', WTF::unsafeSpan(GST_PAD_NAME(pad))); } String MermaidBuilder::getPadClass(const GRefPtr& pad) @@ -531,7 +531,7 @@ void MermaidBuilder::process(GStreamerElementHarness& harness, bool generateFoot for (auto& outputStream : harness.outputStreams()) { auto pad = outputStream->targetPad(); auto padId = generatePadId(harness, pad.get()); - m_stringBuilder.append("subgraph "_s, padId, " ["_s, WTF::span(GST_PAD_NAME(pad.get())), "]\n"_s); + m_stringBuilder.append("subgraph "_s, padId, " ["_s, WTF::unsafeSpan(GST_PAD_NAME(pad.get())), "]\n"_s); m_stringBuilder.append("end\n"_s); auto downstreamHarness = outputStream->downstreamHarness(); @@ -567,7 +567,7 @@ void MermaidBuilder::dumpPad(GStreamerElementHarness& harness, GstPad* pad) { if (!pad) pad = harness.inputPad(); - m_stringBuilder.append("subgraph "_s, generatePadId(harness, pad), " ["_s, WTF::span(GST_PAD_NAME(pad)), "]\n"_s); + m_stringBuilder.append("subgraph "_s, generatePadId(harness, pad), " ["_s, WTF::unsafeSpan(GST_PAD_NAME(pad)), "]\n"_s); if (gst_pad_is_linked(pad)) { auto peerPad = adoptGRef(gst_pad_get_peer(pad)); @@ -598,9 +598,9 @@ void MermaidBuilder::dumpElement(GStreamerElementHarness& harness, GstElement* e { if (!element) element= harness.element(); - auto elementId = makeString(WTF::span(GST_ELEMENT_NAME(element)), '_', m_elementCounter); + auto elementId = makeString(WTF::unsafeSpan(GST_ELEMENT_NAME(element)), '_', m_elementCounter); m_elementCounter++; - m_stringBuilder.append("subgraph "_s, elementId, " [
"_s, WTF::span(G_OBJECT_TYPE_NAME(element)), "\\n"_s, WTF::span(GST_ELEMENT_NAME(element)), "]\n"_s); + m_stringBuilder.append("subgraph "_s, elementId, " [
"_s, WTF::unsafeSpan(G_OBJECT_TYPE_NAME(element)), "\\n"_s, WTF::unsafeSpan(GST_ELEMENT_NAME(element)), "]\n"_s); if (GST_IS_BIN(element)) { for (auto element : GstIteratorAdaptor(GUniquePtr(gst_bin_iterate_recurse(GST_BIN_CAST(element))))) @@ -638,7 +638,7 @@ String MermaidBuilder::describeCaps(const GRefPtr& caps) { if (gst_caps_is_any(caps.get()) || gst_caps_is_empty(caps.get())) { GUniquePtr capsString(gst_caps_to_string(caps.get())); - return WTF::span(capsString.get()); + return WTF::unsafeSpan(capsString.get()); } StringBuilder builder; @@ -649,16 +649,16 @@ String MermaidBuilder::describeCaps(const GRefPtr& caps) builder.append(gstStructureGetName(structure).span(), "
"_s); if (features && (gst_caps_features_is_any(features) || !gst_caps_features_is_equal(features, GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) { GUniquePtr serializedFeature(gst_caps_features_to_string(features)); - builder.append('(', WTF::span(serializedFeature.get()), ')'); + builder.append('(', WTF::unsafeSpan(serializedFeature.get()), ')'); } gstStructureForeach(structure, [&](auto id, const auto value) -> bool { builder.append(gstIdToString(id), ": "_s); GUniquePtr serializedValue(gst_value_serialize(value)); - String valueString = WTF::span(serializedValue.get()); + String valueString = WTF::unsafeSpan(serializedValue.get()); if (valueString.length() > 25) - builder.append(valueString.substring(0, 25), WTF::span("…")); + builder.append(valueString.substring(0, 25), WTF::unsafeSpan("…")); else builder.append(valueString); builder.append("
"_s); @@ -683,7 +683,7 @@ void GStreamerElementHarness::dumpGraph(ASCIILiteral filenamePrefix) auto elapsed = gst_util_get_timestamp() - webkitGstInitTime(); GUniquePtr elapsedTimeStamp(gst_info_strdup_printf("%" GST_TIME_FORMAT, GST_TIME_ARGS(elapsed))); - auto filename = makeString(WTF::span(elapsedTimeStamp.get()), '-', filenamePrefix, "-harness-"_s, WTF::span(GST_ELEMENT_NAME(m_element.get())), ".mmd"_s); + auto filename = makeString(WTF::unsafeSpan(elapsedTimeStamp.get()), '-', filenamePrefix, "-harness-"_s, WTF::unsafeSpan(GST_ELEMENT_NAME(m_element.get())), ".mmd"_s); MermaidBuilder builder; builder.process(*this); diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp index 60d3400f962ac..645ff6d32ea6c 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCaptureDeviceManager.cpp @@ -204,7 +204,7 @@ void GStreamerCaptureDeviceManager::addDevice(GRefPtr&& device) GUniquePtr deviceName(gst_device_get_display_name(device.get())); GST_INFO("Registering device %s", deviceName.get()); auto isDefault = gstStructureGet(properties.get(), "is-default"_s).value_or(false); - auto label = makeString(isDefault ? "default: "_s : ""_s, span(deviceName.get())); + auto label = makeString(isDefault ? "default: "_s : ""_s, unsafeSpan(deviceName.get())); auto identifier = label; bool isMock = false; diff --git a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp index 6329827cbe45e..06c60be704968 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/GStreamerCapturer.cpp @@ -154,7 +154,7 @@ GstElement* GStreamerCapturer::createSource() } } else { ASSERT(m_device); - auto sourceName = makeString(WTF::span(name()), hex(reinterpret_cast(this))); + auto sourceName = makeString(WTF::unsafeSpan(name()), hex(reinterpret_cast(this))); m_src = gst_device_create_element(m_device->device(), sourceName.ascii().data()); ASSERT(m_src); g_object_set(m_src.get(), "do-timestamp", TRUE, nullptr); @@ -231,7 +231,7 @@ void GStreamerCapturer::setupPipeline() GstElement* GStreamerCapturer::makeElement(ASCIILiteral factoryName) { auto* element = makeGStreamerElement(factoryName); - auto elementName = makeString(span(name()), "_capturer_"_s, span(GST_OBJECT_NAME(element)), '_', hex(reinterpret_cast(this))); + auto elementName = makeString(unsafeSpan(name()), "_capturer_"_s, unsafeSpan(GST_OBJECT_NAME(element)), '_', hex(reinterpret_cast(this))); gst_object_set_name(GST_OBJECT(element), elementName.ascii().data()); return element; diff --git a/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp b/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp index 0a667c7a51068..efac8ece46a71 100644 --- a/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp +++ b/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp @@ -71,7 +71,7 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder { GstElement* makeElement(ASCIILiteral factoryName) { static Atomic elementId; - auto name = makeString(span(Name()), "-dec-"_s, factoryName, "-"_s, elementId.exchangeAdd(1)); + auto name = makeString(unsafeSpan(Name()), "-dec-"_s, factoryName, "-"_s, elementId.exchangeAdd(1)); return makeGStreamerElement(factoryName, name); } diff --git a/Source/WebCore/platform/network/FormDataBuilder.cpp b/Source/WebCore/platform/network/FormDataBuilder.cpp index 64b9cffb38d5f..5297c3cfe17fa 100644 --- a/Source/WebCore/platform/network/FormDataBuilder.cpp +++ b/Source/WebCore/platform/network/FormDataBuilder.cpp @@ -50,7 +50,7 @@ static inline void append(Vector& buffer, std::span byte static inline void append(Vector& buffer, const char* string) { - buffer.append(span8(string)); + buffer.append(byteCast(unsafeSpan(string))); } static inline void append(Vector& buffer, const CString& string) diff --git a/Source/WebCore/platform/network/soup/AuthenticationChallengeSoup.cpp b/Source/WebCore/platform/network/soup/AuthenticationChallengeSoup.cpp index 9fc226996e485..4a37f0f9c9d33 100644 --- a/Source/WebCore/platform/network/soup/AuthenticationChallengeSoup.cpp +++ b/Source/WebCore/platform/network/soup/AuthenticationChallengeSoup.cpp @@ -68,7 +68,7 @@ static ProtectionSpace protectionSpaceFromSoupAuthAndURL(SoupAuth* soupAuth, con if (!port) port = defaultPortForProtocol(url.protocol()); #else - URL authURL({ }, makeString("http://"_s, WTF::span(soup_auth_get_authority(soupAuth)))); + URL authURL({ }, makeString("http://"_s, WTF::unsafeSpan(soup_auth_get_authority(soupAuth)))); auto host = authURL.host(); auto port = authURL.port(); #endif diff --git a/Source/WebCore/platform/sql/SQLiteDatabase.cpp b/Source/WebCore/platform/sql/SQLiteDatabase.cpp index aac252081d555..511b3a73dcd64 100644 --- a/Source/WebCore/platform/sql/SQLiteDatabase.cpp +++ b/Source/WebCore/platform/sql/SQLiteDatabase.cpp @@ -58,7 +58,7 @@ static constexpr auto notOpenErrorMessage = "database is not open"_s; static void unauthorizedSQLFunction(sqlite3_context *context, int, sqlite3_value **) { auto* functionName = static_cast(sqlite3_user_data(context)); - sqlite3_result_error(context, makeString("Function "_s, span(functionName), " is unauthorized"_s).utf8().data(), -1); + sqlite3_result_error(context, makeString("Function "_s, unsafeSpan(functionName), " is unauthorized"_s).utf8().data(), -1); } static void initializeSQLiteIfNecessary() diff --git a/Source/WebCore/xml/XMLErrors.cpp b/Source/WebCore/xml/XMLErrors.cpp index 70f85f83b79d3..47f8b0a0e7021 100644 --- a/Source/WebCore/xml/XMLErrors.cpp +++ b/Source/WebCore/xml/XMLErrors.cpp @@ -78,7 +78,7 @@ void XMLErrors::handleError(ErrorType type, const char* message, TextPosition po void XMLErrors::appendErrorMessage(ASCIILiteral typeString, TextPosition position, const char* message) { // on line at column : - m_errorMessages.append(typeString, " on line "_s, position.m_line.oneBasedInt(), " at column "_s, position.m_column.oneBasedInt(), ": "_s, span(message)); + m_errorMessages.append(typeString, " on line "_s, position.m_line.oneBasedInt(), " at column "_s, position.m_column.oneBasedInt(), ": "_s, unsafeSpan(message)); } static inline Ref createXHTMLParserErrorHeader(Document& document, String&& errorMessages) diff --git a/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp b/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp index 451e6927f294b..5c90820960dad 100644 --- a/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp +++ b/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp @@ -1266,7 +1266,7 @@ void NetworkDataTaskSoup::didGetHeaders() auto* address = soup_message_get_remote_address(m_soupMessage.get()); if (G_IS_INET_SOCKET_ADDRESS(address)) { GUniquePtr ipAddress(g_inet_address_to_string(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(address)))); - additionalMetrics.remoteAddress = makeString(span(ipAddress.get()), ':', g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(address))); + additionalMetrics.remoteAddress = makeString(unsafeSpan(ipAddress.get()), ':', g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(address))); } additionalMetrics.tlsProtocol = tlsProtocolVersionToString(soup_message_get_tls_protocol_version(m_soupMessage.get())); additionalMetrics.tlsCipher = String::fromUTF8(soup_message_get_tls_ciphersuite_name(m_soupMessage.get())); @@ -1556,7 +1556,7 @@ void NetworkDataTaskSoup::networkEvent(GSocketClientEvent event, GIOStream* stre GRefPtr address = adoptGRef(g_socket_connection_get_remote_address(G_SOCKET_CONNECTION(stream), nullptr)); if (G_IS_INET_SOCKET_ADDRESS(address.get())) { GUniquePtr ipAddress(g_inet_address_to_string(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(address.get())))); - additionalNetworkLoadMetricsForWebInspector().remoteAddress = makeString(span(ipAddress.get()), ':', g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(address.get()))); + additionalNetworkLoadMetricsForWebInspector().remoteAddress = makeString(unsafeSpan(ipAddress.get()), ':', g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(address.get()))); } } // Web Timing considers that connection time involves dns, proxy & TLS negotiation... diff --git a/Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp b/Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp index b70fd42411504..e034247e3bb38 100644 --- a/Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp +++ b/Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp @@ -89,7 +89,7 @@ static CString buildAcceptLanguages(const Vector& languages) if (quality > 0 && quality < 100) { std::array buffer; g_ascii_formatd(buffer.data(), 8, "%.2f", quality / 100.0); - builder.append(";q="_s, span(buffer.data())); + builder.append(";q="_s, unsafeSpan(buffer.data())); } } diff --git a/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.cpp b/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.cpp index dd8a0720d1394..1233dc4f11c22 100644 --- a/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.cpp +++ b/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.cpp @@ -209,7 +209,7 @@ static HashMap gatherNetworkMap() auto prefixLength = rtc::CountIPMaskBits(address->second.rtcAddress()); - auto name = span(iterator->ifa_name); + auto name = unsafeSpan(iterator->ifa_name); auto prefixString = address->second.rtcAddress().ToString(); auto networkKey = makeString(StringView { name }, "-"_s, prefixLength, "-"_s, StringView { std::span(prefixString.c_str(), prefixString.length()) }); diff --git a/Source/WebKit/Shared/unix/AuxiliaryProcessMain.cpp b/Source/WebKit/Shared/unix/AuxiliaryProcessMain.cpp index 525310d70aa39..a633847c5272a 100644 --- a/Source/WebKit/Shared/unix/AuxiliaryProcessMain.cpp +++ b/Source/WebKit/Shared/unix/AuxiliaryProcessMain.cpp @@ -56,12 +56,12 @@ bool AuxiliaryProcessMainCommon::parseCommandLine(int argc, char** argv) if (argc < argIndex + 2) return false; - if (auto processIdentifier = parseInteger(span(argv[argIndex++]))) + if (auto processIdentifier = parseInteger(unsafeSpan(argv[argIndex++]))) m_parameters.processIdentifier = LegacyNullableObjectIdentifier(*processIdentifier); else return false; - if (auto connectionIdentifier = parseInteger(span(argv[argIndex++]))) + if (auto connectionIdentifier = parseInteger(unsafeSpan(argv[argIndex++]))) m_parameters.connectionIdentifier = IPC::Connection::Identifier { *connectionIdentifier }; else return false; @@ -72,7 +72,7 @@ bool AuxiliaryProcessMainCommon::parseCommandLine(int argc, char** argv) #if USE(GLIB) && OS(LINUX) // Parse pidSocket if available if (argc > argIndex) { - auto pidSocket = parseInteger(span(argv[argIndex])); + auto pidSocket = parseInteger(unsafeSpan(argv[argIndex])); if (pidSocket && *pidSocket >= 0) { IPC::sendPIDToPeer(*pidSocket); RELEASE_ASSERT(!close(*pidSocket)); diff --git a/Source/WebKit/UIProcess/API/glib/WebKitProtocolHandler.cpp b/Source/WebKit/UIProcess/API/glib/WebKitProtocolHandler.cpp index b19263a73ffe9..9a4f1533f25c1 100644 --- a/Source/WebKit/UIProcess/API/glib/WebKitProtocolHandler.cpp +++ b/Source/WebKit/UIProcess/API/glib/WebKitProtocolHandler.cpp @@ -403,7 +403,7 @@ void WebKitProtocolHandler::handleGPU(WebKitURISchemeRequest* request) for (GLint i = 0; i < numExtensions; ++i) { if (i) extensionsBuilder.append(' '); - extensionsBuilder.append(span(reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)))); + extensionsBuilder.append(unsafeSpan(reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)))); } addTableRow(jsonObject, "GL_EXTENSIONS"_s, extensionsBuilder.toString()); break; @@ -413,31 +413,31 @@ void WebKitProtocolHandler::handleGPU(WebKitURISchemeRequest* request) auto eglDisplay = eglGetCurrentDisplay(); addTableRow(jsonObject, "EGL_VERSION"_s, String::fromUTF8(eglQueryString(eglDisplay, EGL_VERSION))); addTableRow(jsonObject, "EGL_VENDOR"_s, String::fromUTF8(eglQueryString(eglDisplay, EGL_VENDOR))); - addTableRow(jsonObject, "EGL_EXTENSIONS"_s, makeString(span(eglQueryString(nullptr, EGL_EXTENSIONS)), ' ', span(eglQueryString(eglDisplay, EGL_EXTENSIONS)))); + addTableRow(jsonObject, "EGL_EXTENSIONS"_s, makeString(unsafeSpan(eglQueryString(nullptr, EGL_EXTENSIONS)), ' ', unsafeSpan(eglQueryString(eglDisplay, EGL_EXTENSIONS)))); }; auto jsonObject = JSON::Object::create(); startTable("Version Information"_s); auto versionObject = JSON::Object::create(); - addTableRow(versionObject, "WebKit version"_s, makeString(webkitPortName(), ' ', WEBKIT_MAJOR_VERSION, '.', WEBKIT_MINOR_VERSION, '.', WEBKIT_MICRO_VERSION, " ("_s, WTF::span(BUILD_REVISION), ')')); + addTableRow(versionObject, "WebKit version"_s, makeString(webkitPortName(), ' ', WEBKIT_MAJOR_VERSION, '.', WEBKIT_MINOR_VERSION, '.', WEBKIT_MICRO_VERSION, " ("_s, WTF::unsafeSpan(BUILD_REVISION), ')')); #if OS(UNIX) struct utsname osName; uname(&osName); - addTableRow(versionObject, "Operating system"_s, makeString(span(osName.sysname), ' ', span(osName.release), ' ', span(osName.version), ' ', span(osName.machine))); + addTableRow(versionObject, "Operating system"_s, makeString(unsafeSpan(osName.sysname), ' ', unsafeSpan(osName.release), ' ', unsafeSpan(osName.version), ' ', unsafeSpan(osName.machine))); #endif const char* desktopName = g_getenv("XDG_CURRENT_DESKTOP"); addTableRow(versionObject, "Desktop"_s, (desktopName && *desktopName) ? String::fromUTF8(desktopName) : "Unknown"_s); #if USE(CAIRO) - addTableRow(versionObject, "Cairo version"_s, makeString(WTF::span(CAIRO_VERSION_STRING), " (build) "_s, WTF::span(cairo_version_string()), " (runtime)"_s)); + addTableRow(versionObject, "Cairo version"_s, makeString(WTF::unsafeSpan(CAIRO_VERSION_STRING), " (build) "_s, WTF::unsafeSpan(cairo_version_string()), " (runtime)"_s)); #endif #if USE(GSTREAMER) GUniquePtr gstVersion(gst_version_string()); - addTableRow(versionObject, "GStreamer version"_s, makeString(GST_VERSION_MAJOR, '.', GST_VERSION_MINOR, '.', GST_VERSION_MICRO, " (build) "_s, span(gstVersion.get()), " (runtime)"_s)); + addTableRow(versionObject, "GStreamer version"_s, makeString(GST_VERSION_MAJOR, '.', GST_VERSION_MINOR, '.', GST_VERSION_MICRO, " (build) "_s, unsafeSpan(gstVersion.get()), " (runtime)"_s)); #endif #if PLATFORM(GTK) @@ -578,7 +578,7 @@ void WebKitProtocolHandler::handleGPU(WebKitURISchemeRequest* request) #if USE(GBM) if (platformDisplay->type() == PlatformDisplay::Type::GBM) { if (drmVersion* version = drmGetVersion(gbm_device_get_fd(device))) { - addTableRow(hardwareAccelerationObject, "DRM version"_s, makeString(span(version->name), " ("_s, span(version->desc), ") "_s, version->version_major, '.', version->version_minor, '.', version->version_patchlevel, ". "_s, span(version->date))); + addTableRow(hardwareAccelerationObject, "DRM version"_s, makeString(unsafeSpan(version->name), " ("_s, unsafeSpan(version->desc), ") "_s, version->version_major, '.', version->version_minor, '.', version->version_patchlevel, ". "_s, unsafeSpan(version->date))); drmFreeVersion(version); } } @@ -637,7 +637,7 @@ void WebKitProtocolHandler::handleGPU(WebKitURISchemeRequest* request) #if USE(GBM) if (platformDisplay->type() == PlatformDisplay::Type::GBM) { if (drmVersion* version = drmGetVersion(fd.value())) { - addTableRow(hardwareAccelerationObject, "DRM version"_s, makeString(span(version->name), " ("_s, span(version->desc), ") "_s, version->version_major, '.', version->version_minor, '.', version->version_patchlevel, ". "_s, span(version->date))); + addTableRow(hardwareAccelerationObject, "DRM version"_s, makeString(unsafeSpan(version->name), " ("_s, unsafeSpan(version->desc), ") "_s, version->version_major, '.', version->version_minor, '.', version->version_patchlevel, ". "_s, unsafeSpan(version->date))); drmFreeVersion(version); } } diff --git a/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp b/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp index 67fc16690e9e4..a5d0fd55ea074 100644 --- a/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp +++ b/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp @@ -3421,7 +3421,7 @@ void webkit_web_view_load_plain_text(WebKitWebView* webView, const gchar* plainT g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); g_return_if_fail(plainText); - getPage(webView).loadData(WebCore::SharedBuffer::create(span8(plainText)), "text/plain"_s, "UTF-8"_s, aboutBlankURL().string()); + getPage(webView).loadData(WebCore::SharedBuffer::create(byteCast(unsafeSpan(plainText))), "text/plain"_s, "UTF-8"_s, aboutBlankURL().string()); } /** diff --git a/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp b/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp index efc2b850134be..bca66f5674bb5 100644 --- a/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp +++ b/Source/WebKit/UIProcess/Inspector/glib/RemoteInspectorClient.cpp @@ -242,7 +242,7 @@ void RemoteInspectorClient::setBackendCommands(const char* backendCommands) return; } - m_backendCommandsURL = makeString("data:text/javascript;base64,"_s, base64Encoded(byteCast(span8(backendCommands)))); + m_backendCommandsURL = makeString("data:text/javascript;base64,"_s, base64Encoded(byteCast(byteCast(unsafeSpan(backendCommands))))); } void RemoteInspectorClient::connectionDidClose() diff --git a/Source/WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp b/Source/WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp index 96c27a287a1b7..53425df78dfdb 100644 --- a/Source/WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp +++ b/Source/WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp @@ -181,7 +181,7 @@ void RemoteVideoCodecFactory::createEncoder(const String& codec, const WebCore:: std::map parameters; if (type == VideoCodecType::H264) { if (auto position = codec.find('.');position != notFound && position != codec.length()) { - auto profileLevelId = spanReinterpretCast(codec.span8().subspan(position + 1)); + auto profileLevelId = byteCast(codec.span8().subspan(position + 1)); parameters["profile-level-id"] = std::string(profileLevelId.data(), profileLevelId.size()); } } diff --git a/Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.cpp b/Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.cpp index 698685a55a7c2..76b9449ba182e 100644 --- a/Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.cpp +++ b/Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.cpp @@ -32,7 +32,7 @@ GObjectEventListener::GObjectEventListener(GObject* target, EventTarget* coreTar : EventListener(GObjectEventListenerType) , m_target(target) , m_coreTarget(coreTarget) - , m_domEventName(domEventName) + , m_eventType(byteCast(unsafeSpan(domEventName))) , m_handler(handler) , m_capture(capture) { diff --git a/Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.h b/Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.h index 74be158adce54..cba0bc3f47707 100644 --- a/Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.h +++ b/Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/GObjectEventListener.h @@ -32,7 +32,6 @@ namespace WebKit { class GObjectEventListener : public WebCore::EventListener { public: - static bool addEventListener(GObject* target, WebCore::EventTarget* coreTarget, const char* domEventName, GClosure* handler, bool useCapture) { Ref listener(adoptRef(*new GObjectEventListener(target, coreTarget, domEventName, handler, useCapture))); @@ -70,7 +69,7 @@ class GObjectEventListener : public WebCore::EventListener { // We do not need to keep a reference to the m_coreTarget, because // we only use it when the GObject and thus the m_coreTarget object is alive. WebCore::EventTarget* m_coreTarget; - CString m_domEventName; + AtomString m_eventType; GRefPtr m_handler; bool m_capture; }; diff --git a/Tools/TestWebKitAPI/Tests/WTF/CString.cpp b/Tools/TestWebKitAPI/Tests/WTF/CString.cpp index 69c78335e9d28..4b445c005af9f 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/CString.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/CString.cpp @@ -210,12 +210,12 @@ TEST(WTF, CStringComparison) TEST(WTF, CStringViewASCIICaseConversions) { - EXPECT_EQ(WTF::convertToASCIILowercase("Test"_spanChar8), CString("test")); - EXPECT_EQ(WTF::convertToASCIIUppercase("Test"_spanChar8), CString("TEST")); - EXPECT_EQ(WTF::convertToASCIILowercase(unsafeSpanChar8("Water🍉Melon")), CString("water🍉melon")); - EXPECT_EQ(WTF::convertToASCIIUppercase(unsafeSpanChar8("Water🍉Melon")), CString("WATER🍉MELON")); + EXPECT_EQ(WTF::convertToASCIILowercase(u8"Test"_span), CString("test")); + EXPECT_EQ(WTF::convertToASCIIUppercase(u8"Test"_span), CString("TEST")); + EXPECT_EQ(WTF::convertToASCIILowercase(u8"Water🍉Melon"_span), CString("water🍉melon")); + EXPECT_EQ(WTF::convertToASCIIUppercase(u8"Water🍉Melon"_span), CString("WATER🍉MELON")); EXPECT_EQ(WTF::convertToASCIILowercase(std::span()), CString(""_s)); EXPECT_EQ(WTF::convertToASCIIUppercase(std::span()), CString(""_s)); - EXPECT_EQ(WTF::convertToASCIILowercase(""_spanChar8), CString(""_s)); - EXPECT_EQ(WTF::convertToASCIIUppercase(""_spanChar8), CString(""_s)); + EXPECT_EQ(WTF::convertToASCIILowercase(u8""_span), CString(""_s)); + EXPECT_EQ(WTF::convertToASCIIUppercase(u8""_span), CString(""_s)); } diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp index a62af94702bd2..4559fee26e293 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp @@ -122,8 +122,8 @@ TEST(StringBuilderTest, Append) { StringBuilder builder; - builder.append(unsafeSpanChar8("Water🍉Melon")); - EXPECT_EQ(builder.toString(), unsafeSpanChar8("Water🍉Melon")); + builder.append(u8"Water🍉Melon"_span); + EXPECT_EQ(builder.toString(), u8"Water🍉Melon"_span); } } diff --git a/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp b/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp index e15723a700df4..5ecd8ffc56cc5 100644 --- a/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp +++ b/Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp @@ -109,110 +109,110 @@ TEST(WTF_StringCommon, FindIgnoringASCIICaseWithoutLengthIdentical) TEST(WTF_StringCommon, Equal) { - EXPECT_TRUE(WTF::equal(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("Water🍉Melon"))); - EXPECT_FALSE(WTF::equal(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉WaterMelon🍉"))); - // EXPECT_TRUE(WTF::equal("test"_spanChar8, "test"_span8)); // This should not compile. - String string(unsafeSpanChar8("Water🍉Melon")); + EXPECT_TRUE(WTF::equal(u8"Water🍉Melon"_span, u8"Water🍉Melon"_span)); + EXPECT_FALSE(WTF::equal(u8"Water🍉Melon"_span, u8"🍉WaterMelon🍉"_span)); + // EXPECT_TRUE(WTF::equal("test"_span, "test"_span8)); // This should not compile. + String string(u8"Water🍉Melon"_span); EXPECT_FALSE(string.is8Bit()); - EXPECT_TRUE(WTF::equal(string, unsafeSpanChar8("Water🍉Melon"))); - EXPECT_FALSE(WTF::equal(string, unsafeSpanChar8("🍉WaterMelon🍉"))); + EXPECT_TRUE(WTF::equal(string, u8"Water🍉Melon"_span)); + EXPECT_FALSE(WTF::equal(string, u8"🍉WaterMelon🍉"_span)); } TEST(WTF_StringCommon, EqualIgnoringASCIICase) { - EXPECT_TRUE(WTF::equalIgnoringASCIICase("Test"_spanChar8, "test"_spanChar8)); - EXPECT_FALSE(WTF::equalIgnoringASCIICase("another test"_spanChar8, "test"_spanChar8)); - // EXPECT_TRUE(WTF::equalIgnoringASCIICase("test"_spanChar8, "test"_span8)); // This should not compile. + EXPECT_TRUE(WTF::equalIgnoringASCIICase(u8"Test"_span, u8"test"_span)); + EXPECT_FALSE(WTF::equalIgnoringASCIICase(u8"another test"_span, u8"test"_span)); + // EXPECT_TRUE(WTF::equalIgnoringASCIICase(u8"test"_span, "test"_span8)); // This should not compile. } TEST(WTF_StringCommon, StartsWith) { - EXPECT_TRUE(WTF::startsWith(unsafeSpanChar8("Water🍉Melon"), "Water"_s)); - EXPECT_FALSE(WTF::startsWith(unsafeSpanChar8("Water🍉Melon"), "water"_s)); - EXPECT_FALSE(WTF::startsWith(unsafeSpanChar8("🍉WaterMelon🍉"), "Water"_s)); - EXPECT_TRUE(WTF::startsWith(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉"))); - EXPECT_FALSE(WTF::startsWith(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉"))); - // EXPECT_TRUE(WTF::startsWith("test"_spanChar8, "test"_span8)); // This should not compile. + EXPECT_TRUE(WTF::startsWith(u8"Water🍉Melon"_span, "Water"_s)); + EXPECT_FALSE(WTF::startsWith(u8"Water🍉Melon"_span, "water"_s)); + EXPECT_FALSE(WTF::startsWith(u8"🍉WaterMelon🍉"_span, "Water"_s)); + EXPECT_TRUE(WTF::startsWith(u8"🍉WaterMelon🍉"_span, u8"🍉"_span)); + EXPECT_FALSE(WTF::startsWith(u8"Water🍉Melon"_span, u8"🍉"_span)); + // EXPECT_TRUE(WTF::startsWith(u8"test"_span, "test"_span8)); // This should not compile. } TEST(WTF_StringCommon, EndsWith) { - EXPECT_TRUE(WTF::endsWith(unsafeSpanChar8("Water🍉Melon"), "Melon"_s)); - EXPECT_FALSE(WTF::endsWith(unsafeSpanChar8("Water🍉Melon"), "melon"_s)); - EXPECT_FALSE(WTF::endsWith(unsafeSpanChar8("🍉WaterMelon🍉"), "Melon"_s)); - EXPECT_TRUE(WTF::endsWith(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉"))); - EXPECT_FALSE(WTF::endsWith(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉"))); - // EXPECT_TRUE(WTF::endsWith("test"_spanChar8, "test"_span8)); // This should not compile. + EXPECT_TRUE(WTF::endsWith(u8"Water🍉Melon"_span, "Melon"_s)); + EXPECT_FALSE(WTF::endsWith(u8"Water🍉Melon"_span, "melon"_s)); + EXPECT_FALSE(WTF::endsWith(u8"🍉WaterMelon🍉"_span, "Melon"_s)); + EXPECT_TRUE(WTF::endsWith(u8"🍉WaterMelon🍉"_span, u8"🍉"_span)); + EXPECT_FALSE(WTF::endsWith(u8"Water🍉Melon"_span, u8"🍉"_span)); + // EXPECT_TRUE(WTF::endsWith(u8"test"_span, "test"_span8)); // This should not compile. } TEST(WTF_StringCommon, Find) { - EXPECT_EQ(WTF::find(unsafeSpanChar8("Water🍉Melon"), "ter"_s), 2UZ); - EXPECT_EQ(WTF::find(unsafeSpanChar8("🍉WaterMelon🍉"), "ter"_s), 6UZ); - EXPECT_EQ(WTF::find(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉")), 5UZ); - EXPECT_EQ(WTF::find(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉")), 0UZ); - // EXPECT_NEQ(WTF::find("test"_spanChar8, "test"_span8), notFound); // This should not compile. + EXPECT_EQ(WTF::find(u8"Water🍉Melon"_span, "ter"_s), 2UZ); + EXPECT_EQ(WTF::find(u8"🍉WaterMelon🍉"_span, "ter"_s), 6UZ); + EXPECT_EQ(WTF::find(u8"Water🍉Melon"_span, u8"🍉"_span), 5UZ); + EXPECT_EQ(WTF::find(u8"🍉WaterMelon🍉"_span, u8"🍉"_span), 0UZ); + // EXPECT_NEQ(WTF::find(u8"test"_span, "test"_span8), notFound); // This should not compile. } TEST(WTF_StringCommon, ReverseFind) { - EXPECT_EQ(WTF::reverseFind(unsafeSpanChar8("Water🍉Melon"), "ter"_s), 2UZ); - EXPECT_EQ(WTF::reverseFind(unsafeSpanChar8("🍉WaterMelon🍉"), "ter"_s), 6UZ); - EXPECT_EQ(WTF::reverseFind(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉")), 5UZ); - EXPECT_EQ(WTF::reverseFind(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉")), 14UZ); - // EXPECT_NEQ(WTF::reverseFind("test"_spanChar8, "test"_span8), notFound); // This should not compile. + EXPECT_EQ(WTF::reverseFind(u8"Water🍉Melon"_span, "ter"_s), 2UZ); + EXPECT_EQ(WTF::reverseFind(u8"🍉WaterMelon🍉"_span, "ter"_s), 6UZ); + EXPECT_EQ(WTF::reverseFind(u8"Water🍉Melon"_span, u8"🍉"_span), 5UZ); + EXPECT_EQ(WTF::reverseFind(u8"🍉WaterMelon🍉"_span, u8"🍉"_span), 14UZ); + // EXPECT_NEQ(WTF::reverseFind(u8"test"_span, "test"_span8), notFound); // This should not compile. } TEST(WTF_StringCommon, Contains) { - EXPECT_TRUE(WTF::contains(unsafeSpanChar8("Water🍉Melon"), "Water"_s)); - EXPECT_TRUE(WTF::contains(unsafeSpanChar8("🍉WaterMelon🍉"), "Water"_s)); - EXPECT_TRUE(WTF::contains(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉"))); - EXPECT_TRUE(WTF::contains(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉"))); - EXPECT_FALSE(WTF::contains(unsafeSpanChar8("Water🍉Melon"), "pear"_s)); - EXPECT_FALSE(WTF::contains(unsafeSpanChar8("🍉WaterMelon🍉"), "pear"_s)); - EXPECT_FALSE(WTF::contains(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍈"))); - EXPECT_FALSE(WTF::contains(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍈"))); - // EXPECT_TRUE(WTF::contains("test"_spanChar8, "test"_span8)); // This should not compile. + EXPECT_TRUE(WTF::contains(u8"Water🍉Melon"_span, "Water"_s)); + EXPECT_TRUE(WTF::contains(u8"🍉WaterMelon🍉"_span, "Water"_s)); + EXPECT_TRUE(WTF::contains(u8"Water🍉Melon"_span, u8"🍉"_span)); + EXPECT_TRUE(WTF::contains(u8"🍉WaterMelon🍉"_span, u8"🍉"_span)); + EXPECT_FALSE(WTF::contains(u8"Water🍉Melon"_span, "pear"_s)); + EXPECT_FALSE(WTF::contains(u8"🍉WaterMelon🍉"_span, "pear"_s)); + EXPECT_FALSE(WTF::contains(u8"Water🍉Melon"_span, u8"🍈"_span)); + EXPECT_FALSE(WTF::contains(u8"🍉WaterMelon🍉"_span, u8"🍈"_span)); + // EXPECT_TRUE(WTF::contains(u8"test"_span, "test"_span8)); // This should not compile. } TEST(WTF_StringCommon, StartsWithLettersIgnoringASCIICase) { - EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), "water"_s)); - EXPECT_FALSE(WTF::startsWithLettersIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), "water"_s)); - // EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase("test"_spanChar8, "test"_span8)); // This should not compile. + EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(u8"Water🍉Melon"_span, "water"_s)); + EXPECT_FALSE(WTF::startsWithLettersIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, "water"_s)); + // EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(u8"test"_span, "test"_span8)); // This should not compile. } TEST(WTF_StringCommon, EndsWithLettersIgnoringASCIICase) { - EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), "melon"_s)); - EXPECT_FALSE(WTF::endsWithLettersIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), "melon"_s)); - // EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase("test"_spanChar8, "test"_span8)); // This should not compile. + EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(u8"Water🍉Melon"_span, "melon"_s)); + EXPECT_FALSE(WTF::endsWithLettersIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, "melon"_s)); + // EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(u8"test"_span, "test"_span8)); // This should not compile. } TEST(WTF_StringCommon, FindIgnoringASCIICase) { - EXPECT_EQ(WTF::findIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), "water"_s), 0UZ); - EXPECT_EQ(WTF::findIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), "water"_s), 4UZ); - EXPECT_EQ(WTF::findIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉")), 5UZ); - EXPECT_EQ(WTF::findIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉")), 0UZ); - // EXPECT_NEQ(WTF::findIgnoringASCIICase("test"_spanChar8, "test"_span8), notFound); // This should not compile. + EXPECT_EQ(WTF::findIgnoringASCIICase(u8"Water🍉Melon"_span, "water"_s), 0UZ); + EXPECT_EQ(WTF::findIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, "water"_s), 4UZ); + EXPECT_EQ(WTF::findIgnoringASCIICase(u8"Water🍉Melon"_span, u8"🍉"_span), 5UZ); + EXPECT_EQ(WTF::findIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, u8"🍉"_span), 0UZ); + // EXPECT_NEQ(WTF::findIgnoringASCIICase(u8"test"_span, "test"_span8), notFound); // This should not compile. } TEST(WTF_StringCommon, ContainsIgnoringASCIICase) { - EXPECT_TRUE(WTF::containsIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), "melon"_s)); - EXPECT_TRUE(WTF::containsIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), "melon"_s)); - EXPECT_TRUE(WTF::containsIgnoringASCIICase(unsafeSpanChar8("Water🍉Melon"), unsafeSpanChar8("🍉"))); - EXPECT_TRUE(WTF::containsIgnoringASCIICase(unsafeSpanChar8("🍉WaterMelon🍉"), unsafeSpanChar8("🍉"))); - // EXPECT_TRUE(WTF::containsIgnoringASCIICase("test"_spanChar8, "test"_span8)); // This should not compile. + EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"Water🍉Melon"_span, "melon"_s)); + EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, "melon"_s)); + EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"Water🍉Melon"_span, u8"🍉"_span)); + EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, u8"🍉"_span)); + // EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"test"_span, "test"_span8)); // This should not compile. } TEST(WTF_StringCommon, CharactersAreAllASCII) { - EXPECT_TRUE(WTF::charactersAreAllASCII("Test"_spanChar8)); + EXPECT_TRUE(WTF::charactersAreAllASCII(u8"Test"_span)); EXPECT_TRUE(WTF::charactersAreAllASCII(std::span())); - EXPECT_FALSE(WTF::charactersAreAllASCII(unsafeSpanChar8("🍉"))); + EXPECT_FALSE(WTF::charactersAreAllASCII(u8"🍉"_span)); } TEST(WTF_StringCommon, CopyElements64To8) diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm index afa5f3a568fcb..79c74edccef17 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm @@ -303,20 +303,20 @@ - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSStrin @end @interface PSONScheme : NSObject { - const char* _bytes; + ASCIILiteral _bytes; HashMap _redirects; HashMap> _dataMappings; HashSet> _runningTasks; bool _shouldRespondAsynchronously; } -- (instancetype)initWithBytes:(const char*)bytes; +- (instancetype)initWithBytes:(ASCIILiteral)bytes; - (void)addRedirectFromURLString:(NSString *)sourceURLString toURLString:(NSString *)destinationURLString; -- (void)addMappingFromURLString:(NSString *)urlString toData:(const char*)data; +- (void)addMappingFromURLString:(NSString *)urlString toData:(ASCIILiteral)data; @end @implementation PSONScheme -- (instancetype)initWithBytes:(const char*)bytes +- (instancetype)initWithBytes:(ASCIILiteral)bytes { self = [super init]; _bytes = bytes; @@ -328,7 +328,7 @@ - (void)addRedirectFromURLString:(NSString *)sourceURLString toURLString:(NSStri _redirects.set(sourceURLString, destinationURLString); } -- (void)addMappingFromURLString:(NSString *)urlString toData:(const char*)data +- (void)addMappingFromURLString:(NSString *)urlString toData:(ASCIILiteral)data { _dataMappings.set(urlString, [NSData dataWithBytesNoCopy:(void*)data length:strlen(data) freeWhenDone:NO]); } @@ -399,7 +399,7 @@ - (void)webView:(WKWebView *)webView stopURLSchemeTask:(id )tas @end -static const char* testBytes = R"PSONRESOURCE( +static constexpr auto testBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* linkToCrossSiteClientSideRedirectBytes = R"PSONRESOURCE( +static constexpr auto linkToCrossSiteClientSideRedirectBytes = R"PSONRESOURCE( Link to cross-site client-side redirect -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* crossSiteClientSideRedirectBytes = R"PSONRESOURCE( +static constexpr auto crossSiteClientSideRedirectBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* navigationWithLockedHistoryBytes = R"PSONRESOURCE( +static constexpr auto navigationWithLockedHistoryBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* pageCache1Bytes = R"PSONRESOURCE( +static constexpr auto pageCache1Bytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* windowOpenCrossSiteNoOpenerTestBytes = R"PSONRESOURCE( +static constexpr auto windowOpenCrossSiteNoOpenerTestBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* windowOpenCrossOriginButSameSiteNoOpenerTestBytes = R"PSONRESOURCE( +static constexpr auto windowOpenCrossOriginButSameSiteNoOpenerTestBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* windowOpenCrossSiteWithOpenerTestBytes = R"PSONRESOURCE( +static constexpr auto windowOpenCrossSiteWithOpenerTestBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* windowOpenSameSiteWithOpenerTestBytes = R"PSONRESOURCE( +static constexpr auto windowOpenSameSiteWithOpenerTestBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* windowOpenSameSiteNoOpenerTestBytes = R"PSONRESOURCE( +static constexpr auto windowOpenSameSiteNoOpenerTestBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* windowOpenWithNameSameSiteNoOpenerTestBytes = R"PSONRESOURCE( +static constexpr auto windowOpenWithNameSameSiteNoOpenerTestBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* targetBlankCrossSiteWithExplicitOpenerTestBytes = R"PSONRESOURCE( +static constexpr auto targetBlankCrossSiteWithExplicitOpenerTestBytes = R"PSONRESOURCE( Link -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* targetBlankCrossSiteWithImplicitNoOpenerTestBytes = R"PSONRESOURCE( +static constexpr auto targetBlankCrossSiteWithImplicitNoOpenerTestBytes = R"PSONRESOURCE( Link -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* targetBlankCrossSiteNoOpenerTestBytes = R"PSONRESOURCE( +static constexpr auto targetBlankCrossSiteNoOpenerTestBytes = R"PSONRESOURCE( Link -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* targetBlankSameSiteNoOpenerTestBytes = R"PSONRESOURCE( +static constexpr auto targetBlankSameSiteNoOpenerTestBytes = R"PSONRESOURCE( Link -)PSONRESOURCE"; +)PSONRESOURCE"_s; #if PLATFORM(MAC) -static const char* linkToAppleTestBytes = R"PSONRESOURCE( +static constexpr auto linkToAppleTestBytes = R"PSONRESOURCE( Navigate -)PSONRESOURCE"; +)PSONRESOURCE"_s; #endif static RetainPtr<_WKProcessPoolConfiguration> psonProcessPoolConfiguration() @@ -992,9 +992,9 @@ static void runBasicTest(SchemeHandlerShouldBeAsync schemeHandlerShouldBeAsync) EXPECT_EQ(5u, seenPIDs.size()); } -static const char* pageWithFragmentTestBytes = R"PSONRESOURCE( +static constexpr auto pageWithFragmentTestBytes = R"PSONRESOURCE(
TEST
-)PSONRESOURCE"; +)PSONRESOURCE"_s; TEST(ProcessSwap, HistoryNavigationToFragmentURL) { @@ -1933,11 +1933,11 @@ static void runSameOriginServerRedirectTest(ShouldCacheProcessFirst shouldCacheP TestWebKitAPI::Util::runFor(0.5_s); } -static const char* linkToWebKitBytes = R"PSONRESOURCE( +static constexpr auto linkToWebKitBytes = R"PSONRESOURCE( Link -)PSONRESOURCE"; +)PSONRESOURCE"_s; TEST(ProcessSwap, PolicyCancelAfterServerRedirect) { @@ -2036,21 +2036,21 @@ static void runSameOriginServerRedirectTest(ShouldCacheProcessFirst shouldCacheP #if USE(SYSTEM_PREVIEW) -static const char* systemPreviewSameOriginTestBytes = R"PSONRESOURCE( +static constexpr auto systemPreviewSameOriginTestBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; -static const char* systemPreviewCrossOriginTestBytes = R"PSONRESOURCE( +static constexpr auto systemPreviewCrossOriginTestBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; TEST(ProcessSwap, SameOriginSystemPreview) { @@ -2533,7 +2533,7 @@ static void runQuickBackForwardNavigationTest(ShouldEnablePSON shouldEnablePSON) runNavigationWithLockedHistoryTest(ShouldEnablePSON::No); } -static const char* sessionStorageTestBytes = R"PSONRESOURCE( +static constexpr auto sessionStorageTestBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; TEST(ProcessSwap, SessionStorage) { @@ -2662,14 +2662,14 @@ function log(msg) EXPECT_EQ(applePID, [webView _webProcessIdentifier]); } -static const char* failsToEnterPageCacheTestBytes = R"PSONRESOURCE( +static constexpr auto failsToEnterPageCacheTestBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; TEST(ProcessSwap, ReuseSuspendedProcessEvenIfPageCacheFails) { @@ -2764,12 +2764,12 @@ function log(msg) EXPECT_EQ(webkitPID, [webView _webProcessIdentifier]); } -static const char* withSubframesTestBytes = R"PSONRESOURCE( +static constexpr auto withSubframesTestBytes = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; TEST(ProcessSwap, HistoryItemIDConfusion) { @@ -2967,7 +2967,7 @@ function log(msg) EXPECT_NE(privateSessionWebkitPID, regularSessionWebkitPID); } -static const char* keepNavigatingFrameBytes = R"PSONRESOURCE( +static constexpr auto keepNavigatingFrameBytes = R"PSONRESOURCE( @@ -2992,7 +2992,7 @@ function navigateFrames() }, 0); -)PSONRESOURCE"; +)PSONRESOURCE"_s; enum class RetainPageInBundle : bool { No, Yes }; @@ -3051,7 +3051,7 @@ void testReuseSuspendedProcessForRegularNavigation(RetainPageInBundle retainPage testReuseSuspendedProcessForRegularNavigation(RetainPageInBundle::No); } -static const char* mainFramesOnlyMainFrame = R"PSONRESOURCE( +static constexpr auto mainFramesOnlyMainFrame = R"PSONRESOURCE( -)PSONRESOURCE"; +)PSONRESOURCE"_s; TEST(ProcessSwap, MainFramesOnly) { @@ -3105,7 +3104,7 @@ function loaded() { #if PLATFORM(MAC) -static const char* getClientWidthBytes = R"PSONRESOURCE( +static constexpr auto getClientWidthBytes = R"PSONRESOURCE( TEST -)PSONRESOURCE"; +)PSONRESOURCE"_s; static unsigned waitUntilClientWidthIs(WKWebView *webView, unsigned expectedClientWidth) { @@ -3189,7 +3188,7 @@ static unsigned waitUntilClientWidthIs(WKWebView *webView, unsigned expectedClie #endif // PLATFORM(MAC) -static const char* mediaTypeBytes = R"PSONRESOURCE( +static constexpr auto mediaTypeBytes = R"PSONRESOURCE(