Title: [277246] trunk/Source/WebCore
Revision
277246
Author
[email protected]
Date
2021-05-09 11:31:34 -0700 (Sun, 09 May 2021)

Log Message

Remove uses of the String::toInt family of functions from the WebCore/platform directory
https://bugs.webkit.org/show_bug.cgi?id=225575

Reviewed by Sam Weinig.

* platform/DateComponents.cpp: Tweak a comment on the local parseInt function here
that should likely be consolidated with parseInteger at some point.

* platform/Length.cpp:
(WebCore::parseLength): Use parseInteger<int> instead of charactersToIntStrict.

* platform/encryptedmedia/clearkey/CDMClearKey.cpp:
(WebCore::CDMPrivateClearKey::sanitizeSessionId const): Use parseInteger<uint32_t>
instead of String::toUIntStrict.

* platform/graphics/HEVCUtilities.cpp:
(WebCore::parseHEVCCodecParameters): Use parseInteger<uint8/32_t> instead of
toIntegralType<uint8/32_t>.
(WebCore::parseDoViCodecParameters): Ditto.
* platform/graphics/VP9Utilities.cpp:
(WebCore::parseVPCodecParameters): Ditto.

* platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm:
(WebCore::CDMPrivateMediaSourceAVFObjC::parseKeySystem): Use parseInteger<int>
instead of String::toInt. There's no need for the "allow trailing junk" here
because a regular _expression_ is used to check format before we call parseInteger.
Also removed an unnecessary empty string check, since the regular _expression_
match check will fail on an empty string.

* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::SourceBufferPrivateAVFObjC::trackDidChangeSelected): Use
parseIntegerAllowingTrailingJunk<uint64_t> instead ot toUInt64.
(WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled): Ditto.
(WebCore::SourceBufferPrivateAVFObjC::flush): Ditto.
(WebCore::SourceBufferPrivateAVFObjC::enqueueSample): Ditto.
(WebCore::SourceBufferPrivateAVFObjC::isReadyForMoreSamples): Ditto.
(WebCore::SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples): Ditto.
(WebCore::SourceBufferPrivateAVFObjC::canSetMinimumUpcomingPresentationTime const): Ditto.

* platform/graphics/cocoa/HEVCUtilitiesCocoa.mm:
(WebCore::parseStringArrayFromDictionaryToUInt16Vector): Use
parseInteger<uint16_t> instead of toIntegralType<uint16_t>. We could also
consider using -[NSString intValue] here with some range checking instead
of converting to WTF::String.

* platform/mediastream/mac/ScreenDisplayCapturerMac.mm:
(WebCore::ScreenDisplayCapturerMac::create): Use parseInteger<uint32_t>
instead of String::toUIntStrict.
(WebCore::ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID): Ditto.
* platform/mediastream/mac/WindowDisplayCapturerMac.mm:
(WebCore::WindowDisplayCapturerMac::create): Ditto.
(WebCore::WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID): Ditto.

* platform/network/HTTPParsers.cpp:
(WebCore::parseRange): Use parseInteger<long long> instead of
String::toInt64Strict. Also use StringView so we don't allocate substrings on
the heap just to parse integers within an existing string. And removed unneeded
call to stripWhiteSpace in one place since parseInteger already allows leading
and trailing spaces, and in another case where we need to strip because of an
empty string check, used stripLeadingAndTrailingHTTPSpaces instead.

* platform/network/ParsedContentRange.cpp:
(WebCore::parseContentRange): Use parseInteger<int64_t> instead of
StringView::toInt64Strict.

* platform/network/ParsedRequestRange.cpp:
(WebCore::ParsedRequestRange::parse): Use parseInteger<uint64_t> instead of
StringView::toUInt64Strict.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277245 => 277246)


--- trunk/Source/WebCore/ChangeLog	2021-05-09 18:22:23 UTC (rev 277245)
+++ trunk/Source/WebCore/ChangeLog	2021-05-09 18:31:34 UTC (rev 277246)
@@ -1,5 +1,147 @@
 2021-05-09  Darin Adler  <[email protected]>
 
+        Remove uses of the String::toInt family of functions from the WebCore/platform directory
+        https://bugs.webkit.org/show_bug.cgi?id=225575
+
+        Reviewed by Sam Weinig.
+
+        * platform/DateComponents.cpp: Tweak a comment on the local parseInt function here
+        that should likely be consolidated with parseInteger at some point.
+
+        * platform/Length.cpp:
+        (WebCore::parseLength): Use parseInteger<int> instead of charactersToIntStrict.
+
+        * platform/encryptedmedia/clearkey/CDMClearKey.cpp:
+        (WebCore::CDMPrivateClearKey::sanitizeSessionId const): Use parseInteger<uint32_t>
+        instead of String::toUIntStrict.
+
+        * platform/graphics/HEVCUtilities.cpp:
+        (WebCore::parseHEVCCodecParameters): Use parseInteger<uint8/32_t> instead of
+        toIntegralType<uint8/32_t>.
+        (WebCore::parseDoViCodecParameters): Ditto.
+        * platform/graphics/VP9Utilities.cpp:
+        (WebCore::parseVPCodecParameters): Ditto.
+
+        * platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm:
+        (WebCore::CDMPrivateMediaSourceAVFObjC::parseKeySystem): Use parseInteger<int>
+        instead of String::toInt. There's no need for the "allow trailing junk" here
+        because a regular _expression_ is used to check format before we call parseInteger.
+        Also removed an unnecessary empty string check, since the regular _expression_
+        match check will fail on an empty string.
+
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+        (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeSelected): Use
+        parseIntegerAllowingTrailingJunk<uint64_t> instead ot toUInt64.
+        (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled): Ditto.
+        (WebCore::SourceBufferPrivateAVFObjC::flush): Ditto.
+        (WebCore::SourceBufferPrivateAVFObjC::enqueueSample): Ditto.
+        (WebCore::SourceBufferPrivateAVFObjC::isReadyForMoreSamples): Ditto.
+        (WebCore::SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples): Ditto.
+        (WebCore::SourceBufferPrivateAVFObjC::canSetMinimumUpcomingPresentationTime const): Ditto.
+
+        * platform/graphics/cocoa/HEVCUtilitiesCocoa.mm:
+        (WebCore::parseStringArrayFromDictionaryToUInt16Vector): Use
+        parseInteger<uint16_t> instead of toIntegralType<uint16_t>. We could also
+        consider using -[NSString intValue] here with some range checking instead
+        of converting to WTF::String.
+        
+        * platform/mediastream/mac/ScreenDisplayCapturerMac.mm:
+        (WebCore::ScreenDisplayCapturerMac::create): Use parseInteger<uint32_t>
+        instead of String::toUIntStrict.
+        (WebCore::ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID): Ditto.
+        * platform/mediastream/mac/WindowDisplayCapturerMac.mm:
+        (WebCore::WindowDisplayCapturerMac::create): Ditto.
+        (WebCore::WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID): Ditto.
+
+        * platform/network/HTTPParsers.cpp:
+        (WebCore::parseRange): Use parseInteger<long long> instead of
+        String::toInt64Strict. Also use StringView so we don't allocate substrings on
+        the heap just to parse integers within an existing string. And removed unneeded
+        call to stripWhiteSpace in one place since parseInteger already allows leading
+        and trailing spaces, and in another case where we need to strip because of an
+        empty string check, used stripLeadingAndTrailingHTTPSpaces instead.
+
+        * platform/network/ParsedContentRange.cpp:
+        (WebCore::parseContentRange): Use parseInteger<int64_t> instead of
+        StringView::toInt64Strict.
+
+        * platform/network/ParsedRequestRange.cpp:
+        (WebCore::ParsedRequestRange::parse): Use parseInteger<uint64_t> instead of
+        StringView::toUInt64Strict.
+
+2021-05-08  Darin Adler  <[email protected]>
+
+        Remove uses of the String::toInt family of functions from the WebCore/platform directory
+        https://bugs.webkit.org/show_bug.cgi?id=225575
+
+        Reviewed by Sam Weinig.
+
+        * platform/DateComponents.cpp: Tweak a comment on the local parseInt function here
+        that should likely be consolidated with parseInteger at some point.
+
+        * platform/Length.cpp:
+        (WebCore::parseLength): Use parseInteger<int> instead of charactersToIntStrict.
+
+        * platform/encryptedmedia/clearkey/CDMClearKey.cpp:
+        (WebCore::CDMPrivateClearKey::sanitizeSessionId const): Use parseInteger<uint32_t>
+        instead of String::toUIntStrict.
+
+        * platform/graphics/HEVCUtilities.cpp:
+        (WebCore::parseHEVCCodecParameters): Use parseInteger<uint8/32_t> instead of
+        toIntegralType<uint8/32_t>.
+        (WebCore::parseDoViCodecParameters): Ditto.
+        * platform/graphics/VP9Utilities.cpp:
+        (WebCore::parseVPCodecParameters): Ditto.
+
+        * platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm:
+        (WebCore::CDMPrivateMediaSourceAVFObjC::parseKeySystem): Use parseInteger<int>
+        instead of String::toInt. There's no need for the "allow trailing junk" here
+        because a regular _expression_ is used to check format before we call parseInteger.
+        Also removed an unnecessary empty string check, since the regular _expression_
+        match check will fail on an empty string.
+
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+        (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeSelected): Use
+        parseIntegerAllowingTrailingJunk<uint64_t> instead ot toUInt64.
+        (WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled): Ditto.
+        (WebCore::SourceBufferPrivateAVFObjC::flush): Ditto.
+        (WebCore::SourceBufferPrivateAVFObjC::enqueueSample): Ditto.
+        (WebCore::SourceBufferPrivateAVFObjC::isReadyForMoreSamples): Ditto.
+        (WebCore::SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples): Ditto.
+        (WebCore::SourceBufferPrivateAVFObjC::canSetMinimumUpcomingPresentationTime const): Ditto.
+
+        * platform/graphics/cocoa/HEVCUtilitiesCocoa.mm:
+        (WebCore::parseStringArrayFromDictionaryToUInt16Vector): Use
+        parseInteger<uint16_t> instead of toIntegralType<uint16_t>. We could also
+        consider using -[NSString intValue] here with some range checking instead
+        of converting to WTF::String.
+        
+        * platform/mediastream/mac/ScreenDisplayCapturerMac.mm:
+        (WebCore::ScreenDisplayCapturerMac::create): Use parseInteger<uint32_t>
+        instead of String::toUIntStrict.
+        (WebCore::ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID): Ditto.
+        * platform/mediastream/mac/WindowDisplayCapturerMac.mm:
+        (WebCore::WindowDisplayCapturerMac::create): Ditto.
+        (WebCore::WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID): Ditto.
+
+        * platform/network/HTTPParsers.cpp:
+        (WebCore::parseRange): Use parseInteger<long long> instead of
+        String::toInt64Strict. Also use StringView so we don't allocate substrings on
+        the heap just to parse integers within an existing string. And removed unneeded
+        call to stripWhiteSpace in one place since parseInteger already allows leading
+        and trailing spaces, and in another case where we need to strip because of an
+        empty string check, used stripLeadingAndTrailingHTTPSpaces instead.
+
+        * platform/network/ParsedContentRange.cpp:
+        (WebCore::parseContentRange): Use parseInteger<int64_t> instead of
+        StringView::toInt64Strict.
+
+        * platform/network/ParsedRequestRange.cpp:
+        (WebCore::ParsedRequestRange::parse): Use parseInteger<uint64_t> instead of
+        StringView::toUInt64Strict.
+
+2021-05-09  Darin Adler  <[email protected]>
+
         Remove uses of the String::toInt family of functions from WebCore/html and similar directories
         https://bugs.webkit.org/show_bug.cgi?id=225577
 

Modified: trunk/Source/WebCore/platform/DateComponents.cpp (277245 => 277246)


--- trunk/Source/WebCore/platform/DateComponents.cpp	2021-05-09 18:22:23 UTC (rev 277245)
+++ trunk/Source/WebCore/platform/DateComponents.cpp	2021-05-09 18:31:34 UTC (rev 277246)
@@ -105,7 +105,7 @@
     return buffer.position() - begin;
 }
 
-// Very strict integer parser. Do not allow leading or trailing whitespace unlike charactersToIntStrict().
+// Differences from parseInteger<int>: Takes StringParsingBuffer. Does not allow leading or trailing spaces. Does not allow leading "+".
 template<typename CharacterType> static Optional<int> parseInt(StringParsingBuffer<CharacterType>& buffer, unsigned maximumNumberOfDigitsToParse)
 {
     if (maximumNumberOfDigitsToParse > buffer.lengthRemaining() || !maximumNumberOfDigitsToParse)

Modified: trunk/Source/WebCore/platform/Length.cpp (277245 => 277246)


--- trunk/Source/WebCore/platform/Length.cpp	2021-05-09 18:22:23 UTC (rev 277245)
+++ trunk/Source/WebCore/platform/Length.cpp	2021-05-09 18:31:34 UTC (rev 277246)
@@ -32,6 +32,7 @@
 #include <wtf/MallocPtr.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/StdLibExtras.h>
+#include <wtf/text/StringToIntegerConversion.h>
 #include <wtf/text/StringView.h>
 #include <wtf/text/TextStream.h>
 
@@ -67,14 +68,11 @@
             return Length(r, LengthType::Percent);
         return Length(1, LengthType::Relative);
     }
-    int r = charactersToIntStrict(data, intLength, &ok);
-    if (next == '*') {
-        if (ok)
-            return Length(r, LengthType::Relative);
-        return Length(1, LengthType::Relative);
-    }
-    if (ok)
-        return Length(r, LengthType::Fixed);
+    auto r = parseInteger<int>({ data, intLength });
+    if (next == '*')
+        return Length(r.valueOr(1), LengthType::Relative);
+    if (r)
+        return Length(*r, LengthType::Fixed);
     return Length(0, LengthType::Relative);
 }
 

Modified: trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp (277245 => 277246)


--- trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp	2021-05-09 18:22:23 UTC (rev 277245)
+++ trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp	2021-05-09 18:31:34 UTC (rev 277246)
@@ -43,6 +43,7 @@
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/text/Base64.h>
+#include <wtf/text/StringToIntegerConversion.h>
 
 namespace WebCore {
 
@@ -415,9 +416,7 @@
 Optional<String> CDMPrivateClearKey::sanitizeSessionId(const String& sessionId) const
 {
     // Validate the session ID string as an 32-bit integer.
-    bool ok;
-    sessionId.toUIntStrict(&ok);
-    if (!ok)
+    if (!parseInteger<uint32_t>(sessionId))
         return WTF::nullopt;
     return sessionId;
 }

Modified: trunk/Source/WebCore/platform/graphics/HEVCUtilities.cpp (277245 => 277246)


--- trunk/Source/WebCore/platform/graphics/HEVCUtilities.cpp	2021-05-09 18:22:23 UTC (rev 277245)
+++ trunk/Source/WebCore/platform/graphics/HEVCUtilities.cpp	2021-05-09 18:31:34 UTC (rev 277246)
@@ -64,10 +64,10 @@
         profileSpace = profileSpace.substring(1);
     }
 
-    bool isValidProfileIDC = false;
-    parameters.generalProfileIDC = toIntegralType<uint8_t>(profileSpace, &isValidProfileIDC);
-    if (!isValidProfileIDC)
+    auto profileIDC = parseInteger<uint8_t>(profileSpace);
+    if (!profileIDC)
         return WTF::nullopt;
+    parameters.generalProfileIDC = *profileIDC;
 
     if (++nextElement == codecSplit.end())
         return WTF::nullopt;
@@ -74,11 +74,10 @@
 
     // Second element: 32 bit of General Profile Compatibility Flags, in reverse bit order,
     // in hex with leading zeros omitted.
-    auto compatibilityFlags = *nextElement;
-    bool isValidCompatibilityFlags = false;
-    parameters.generalProfileCompatibilityFlags = toIntegralType<uint32_t>(compatibilityFlags, &isValidCompatibilityFlags, 16);
-    if (!isValidCompatibilityFlags)
+    auto compatibilityFlags = parseInteger<uint32_t>(*nextElement, 16);
+    if (!compatibilityFlags)
         return WTF::nullopt;
+    parameters.generalProfileCompatibilityFlags = *compatibilityFlags;
 
     if (++nextElement == codecSplit.end())
         return WTF::nullopt;
@@ -90,10 +89,10 @@
     if (firstCharacter != 'L' && firstCharacter != 'H')
         return WTF::nullopt;
 
-    bool isValidGeneralLevelIDC = false;
-    parameters.generalLevelIDC = toIntegralType<uint8_t>(generalTier.substring(1), &isValidGeneralLevelIDC);
-    if (!isValidGeneralLevelIDC)
+    auto generalLevelIDC = parseInteger<uint8_t>(generalTier.substring(1));
+    if (!generalLevelIDC)
         return WTF::nullopt;
+    parameters.generalLevelIDC = *generalLevelIDC;
 
     // Optional fourth and remaining elements: a sequence of 6 1-byte constraint flags, each byte encoded
     // in hex, and separated by a period, with trailing zero bytes omitted.
@@ -100,9 +99,7 @@
     for (unsigned i = 0; i < 6; ++i) {
         if (++nextElement == codecSplit.end())
             break;
-        bool isValidFlag = false;
-        toIntegralType<uint8_t>(*nextElement, &isValidFlag, 16);
-        if (!isValidFlag)
+        if (!parseInteger<uint8_t>(*nextElement, 16))
             return WTF::nullopt;
     }
 
@@ -198,13 +195,13 @@
     if (!profileID.length())
         return WTF::nullopt;
 
-    bool isIntegral = false;
     auto firstCharacter = profileID[0];
     // Profile definition can either be numeric or alpha:
     if (firstCharacter == '0') {
-        parameters.bitstreamProfileID = toIntegralType<uint8_t>(profileID, &isIntegral, 10);
-        if (!isIntegral)
+        auto bitstreamProfileID = parseInteger<uint8_t>(profileID);
+        if (!bitstreamProfileID)
             return WTF::nullopt;
+        parameters.bitstreamProfileID = *bitstreamProfileID;
     } else {
         auto bitstreamProfileID = profileIDForAlphabeticDoViProfile(codecView.left(5 + profileID.length()));
         if (!bitstreamProfileID)
@@ -221,14 +218,11 @@
     if (++nextElement == codecSplit.end())
         return WTF::nullopt;
 
-    auto levelID = *nextElement;
-    if (!levelID.length())
+    auto bitstreamLevelID = parseInteger<uint8_t>(*nextElement);
+    if (!bitstreamLevelID)
         return WTF::nullopt;
+    parameters.bitstreamLevelID = *bitstreamLevelID;
 
-    parameters.bitstreamLevelID = toIntegralType<uint8_t>(levelID, &isIntegral, 10);
-    if (!isIntegral)
-        return WTF::nullopt;
-
     auto maximumLevelID = maximumLevelIDForDoViProfileID(parameters.bitstreamProfileID);
     if (!maximumLevelID || parameters.bitstreamLevelID > *maximumLevelID)
         return WTF::nullopt;

Modified: trunk/Source/WebCore/platform/graphics/VP9Utilities.cpp (277245 => 277246)


--- trunk/Source/WebCore/platform/graphics/VP9Utilities.cpp	2021-05-09 18:22:23 UTC (rev 277245)
+++ trunk/Source/WebCore/platform/graphics/VP9Utilities.cpp	2021-05-09 18:31:34 UTC (rev 277246)
@@ -152,7 +152,7 @@
         return WTF::nullopt;
 
     // First element: profile. Legal values are 0-3.
-    auto profile = ""
+    auto profile = ""
     if (!profile || *profile > 3)
         return WTF::nullopt;
     configuration.profile = ""
@@ -161,7 +161,7 @@
         return WTF::nullopt;
 
     // Second element: level. Legal values are enumerated in validVPLevels above.
-    auto level = toIntegralType<uint8_t>(*nextElement);
+    auto level = parseInteger<uint8_t>(*nextElement);
     if (!level || !isValidVPLevel(*level))
         return WTF::nullopt;
     configuration.level = *level;
@@ -170,7 +170,7 @@
         return WTF::nullopt;
 
     // Third element: bitDepth. Legal values are 8, 10, and 12.
-    auto bitDepth = toIntegralType<uint8_t>(*nextElement);
+    auto bitDepth = parseInteger<uint8_t>(*nextElement);
     if (!bitDepth || (*bitDepth != 8 && *bitDepth != 10 && *bitDepth != 12))
         return WTF::nullopt;
     configuration.bitDepth = *bitDepth;
@@ -183,7 +183,7 @@
         return configuration;
 
     // Fourth element: chromaSubsampling. Legal values are 0-3.
-    auto chromaSubsampling = toIntegralType<uint8_t>(*nextElement);
+    auto chromaSubsampling = parseInteger<uint8_t>(*nextElement);
     if (!chromaSubsampling || *chromaSubsampling > VPConfigurationChromaSubsampling::Subsampling_444)
         return WTF::nullopt;
     configuration.chromaSubsampling = *chromaSubsampling;
@@ -191,9 +191,9 @@
     if (++nextElement == codecSplit.end())
         return WTF::nullopt;
 
-    // Fifth element: colorPrimaries. Legal values are defined by  ISO/IEC 23001-8:2016, superceded
+    // Fifth element: colorPrimaries. Legal values are defined by ISO/IEC 23001-8:2016, superseded
     // by ISO/IEC 23091-2:2019.
-    auto colorPrimaries = toIntegralType<uint8_t>(*nextElement);
+    auto colorPrimaries = parseInteger<uint8_t>(*nextElement);
     if (!colorPrimaries || !isValidVPColorPrimaries(*colorPrimaries))
         return WTF::nullopt;
     configuration.colorPrimaries = *colorPrimaries;
@@ -201,9 +201,9 @@
     if (++nextElement == codecSplit.end())
         return WTF::nullopt;
 
-    // Sixth element: transferCharacteristics. Legal values are defined by  ISO/IEC 23001-8:2016, superceded
+    // Sixth element: transferCharacteristics. Legal values are defined by ISO/IEC 23001-8:2016, superseded
     // by ISO/IEC 23091-2:2019.
-    auto transferCharacteristics = toIntegralType<uint8_t>(*nextElement);
+    auto transferCharacteristics = parseInteger<uint8_t>(*nextElement);
     if (!transferCharacteristics || !isValidVPTransferCharacteristics(*transferCharacteristics))
         return WTF::nullopt;
     configuration.transferCharacteristics = *transferCharacteristics;
@@ -211,9 +211,9 @@
     if (++nextElement == codecSplit.end())
         return WTF::nullopt;
 
-    // Seventh element: matrixCoefficients. Legal values are defined by  ISO/IEC 23001-8:2016, superceded
+    // Seventh element: matrixCoefficients. Legal values are defined by ISO/IEC 23001-8:2016, superseded
     // by ISO/IEC 23091-2:2019.
-    auto matrixCoefficients = toIntegralType<uint8_t>(*nextElement);
+    auto matrixCoefficients = parseInteger<uint8_t>(*nextElement);
     if (!matrixCoefficients || !isValidVPMatrixCoefficients(*matrixCoefficients))
         return WTF::nullopt;
     configuration.matrixCoefficients = *matrixCoefficients;
@@ -226,7 +226,7 @@
         return WTF::nullopt;
 
     // Eighth element: videoFullRangeFlag. Legal values are 0 and 1.
-    auto videoFullRangeFlag = toIntegralType<uint8_t>(*nextElement);
+    auto videoFullRangeFlag = parseInteger<uint8_t>(*nextElement);
     if (!videoFullRangeFlag || *videoFullRangeFlag > 1)
         return WTF::nullopt;
     configuration.videoFullRangeFlag = *videoFullRangeFlag;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm (277245 => 277246)


--- trunk/Source/WebCore/platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm	2021-05-09 18:22:23 UTC (rev 277245)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm	2021-05-09 18:31:34 UTC (rev 277246)
@@ -35,6 +35,7 @@
 #import "MediaPlayerPrivateMediaSourceAVFObjC.h"
 #import <_javascript_Core/RegularExpression.h>
 #import <wtf/NeverDestroyed.h>
+#import <wtf/text/StringToIntegerConversion.h>
 #import <wtf/text/StringView.h>
 
 #import "VideoToolboxSoftLink.h"
@@ -47,21 +48,16 @@
 {
     static NeverDestroyed<RegularExpression> keySystemRE("^com\\.apple\\.fps\\.[23]_\\d+(?:,\\d+)*$", JSC::Yarr::TextCaseInsensitive);
 
-    if (keySystem.isEmpty())
-        return WTF::nullopt;
-    
     if (keySystemRE.get().match(keySystem) < 0)
         return WTF::nullopt;
-    
+
     StringView keySystemView { keySystem };
 
-    int cdmVersion = keySystemView.substring(14, 1).toInt();
-    
+    int cdmVersion = parseInteger<int>(keySystemView.substring(14, 1)).value();
     Vector<int> protocolVersions;
-    for (StringView protocolVersionString : keySystemView.substring(16).split(','))
-        protocolVersions.append(protocolVersionString.toInt());
-    
-    return {{ cdmVersion, WTFMove(protocolVersions) }};
+    for (auto protocolVersionString : keySystemView.substring(16).split(','))
+        protocolVersions.append(parseInteger<int>(protocolVersionString).value());
+    return { { cdmVersion, WTFMove(protocolVersions) } };
 }
 
 CDMPrivateMediaSourceAVFObjC::~CDMPrivateMediaSourceAVFObjC()
@@ -72,12 +68,13 @@
 
 static bool queryDecoderAvailability()
 {
-    if (!canLoad_VideoToolbox_VTGetGVADecoderAvailability())
+    if (!canLoad_VideoToolbox_VTGetGVADecoderAvailability()) {
 #if HAVE(AVSTREAMSESSION)
         return false;
 #else
         return true;
 #endif
+    }
     uint32_t totalInstanceCount = 0;
     OSStatus status = VTGetGVADecoderAvailability(&totalInstanceCount, nullptr);
     return status == noErr && totalInstanceCount;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm (277245 => 277246)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm	2021-05-09 18:22:23 UTC (rev 277245)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm	2021-05-09 18:31:34 UTC (rev 277246)
@@ -62,6 +62,7 @@
 #import <wtf/WeakPtr.h>
 #import <wtf/text/AtomString.h>
 #import <wtf/text/CString.h>
+#import <wtf/text/StringToIntegerConversion.h>
 
 #pragma mark - Soft Linking
 
@@ -768,7 +769,7 @@
 
 void SourceBufferPrivateAVFObjC::trackDidChangeSelected(VideoTrackPrivate& track, bool selected)
 {
-    auto trackID = track.id().string().toUInt64();
+    auto trackID = parseIntegerAllowingTrailingJunk<uint64_t>(track.id()).valueOr(0);
 
     ALWAYS_LOG(LOGIDENTIFIER, "video trackID = ", trackID, ", selected = ", selected);
 
@@ -794,7 +795,7 @@
 
 void SourceBufferPrivateAVFObjC::trackDidChangeEnabled(AudioTrackPrivate& track, bool enabled)
 {
-    auto trackID = track.id().string().toUInt64();
+    auto trackID = parseIntegerAllowingTrailingJunk<uint64_t>(track.id()).valueOr(0);
 
     ALWAYS_LOG(LOGIDENTIFIER, "audio trackID = ", trackID, ", selected = ", enabled);
 
@@ -1016,7 +1017,7 @@
 
 void SourceBufferPrivateAVFObjC::flush(const AtomString& trackIDString)
 {
-    auto trackID = trackIDString.string().toUInt64();
+    auto trackID = parseIntegerAllowingTrailingJunk<uint64_t>(trackIDString).valueOr(0);
     DEBUG_LOG(LOGIDENTIFIER, trackID);
 
     if (trackID == m_enabledVideoTrackID) {
@@ -1058,7 +1059,7 @@
 
 void SourceBufferPrivateAVFObjC::enqueueSample(Ref<MediaSample>&& sample, const AtomString& trackIDString)
 {
-    auto trackID = trackIDString.string().toUInt64();
+    auto trackID = parseIntegerAllowingTrailingJunk<uint64_t>(trackIDString).valueOr(0);
     if (trackID != m_enabledVideoTrackID && !m_audioRenderers.contains(trackID))
         return;
 
@@ -1171,7 +1172,7 @@
 
 bool SourceBufferPrivateAVFObjC::isReadyForMoreSamples(const AtomString& trackIDString)
 {
-    auto trackID = trackIDString.string().toUInt64();
+    auto trackID = parseIntegerAllowingTrailingJunk<uint64_t>(trackIDString).valueOr(0);
     if (trackID == m_enabledVideoTrackID) {
         if (m_decompressionSession)
             return m_decompressionSession->isReadyForMoreMediaData();
@@ -1235,7 +1236,7 @@
 
 void SourceBufferPrivateAVFObjC::notifyClientWhenReadyForMoreSamples(const AtomString& trackIDString)
 {
-    auto trackID = trackIDString.string().toUInt64();
+    auto trackID = parseIntegerAllowingTrailingJunk<uint64_t>(trackIDString).valueOr(0);
     if (trackID == m_enabledVideoTrackID) {
         if (m_decompressionSession) {
             m_decompressionSession->requestMediaDataWhenReady([this, trackID] {
@@ -1260,10 +1261,8 @@
 
 bool SourceBufferPrivateAVFObjC::canSetMinimumUpcomingPresentationTime(const AtomString& trackIDString) const
 {
-    auto trackID = trackIDString.string().toUInt64();
-    if (trackID == m_enabledVideoTrackID)
-        return [getAVSampleBufferDisplayLayerClass() instancesRespondToSelector:@selector(expectMinimumUpcomingSampleBufferPresentationTime:)];
-    return false;
+    return parseIntegerAllowingTrailingJunk<uint64_t>(trackIDString).valueOr(0) == m_enabledVideoTrackID
+        && [getAVSampleBufferDisplayLayerClass() instancesRespondToSelector:@selector(expectMinimumUpcomingSampleBufferPresentationTime:)];
 }
 
 void SourceBufferPrivateAVFObjC::setMinimumUpcomingPresentationTime(const AtomString& trackIDString, const MediaTime& presentationTime)

Modified: trunk/Source/WebCore/platform/graphics/cocoa/HEVCUtilitiesCocoa.mm (277245 => 277246)


--- trunk/Source/WebCore/platform/graphics/cocoa/HEVCUtilitiesCocoa.mm	2021-05-09 18:22:23 UTC (rev 277245)
+++ trunk/Source/WebCore/platform/graphics/cocoa/HEVCUtilitiesCocoa.mm	2021-05-09 18:31:34 UTC (rev 277246)
@@ -31,12 +31,10 @@
 #import "FourCC.h"
 #import "HEVCUtilities.h"
 #import "MediaCapabilitiesInfo.h"
-
-#import <wtf/RobinHoodHashMap.h>
 #import <wtf/text/StringToIntegerConversion.h>
-#import <pal/cocoa/AVFoundationSoftLink.h>
 
 #import "VideoToolboxSoftLink.h"
+#import <pal/cocoa/AVFoundationSoftLink.h>
 
 namespace WebCore {
 
@@ -150,11 +148,10 @@
     for (id value in array) {
         if (![value isKindOfClass:NSString.class])
             return WTF::nullopt;
-        bool isValidNumber = false;
-        auto numericValue = toIntegralType<uint16_t>(String((NSString *)value), &isValidNumber);
-        if (!isValidNumber)
+        auto numericValue = parseInteger<uint16_t>(String((NSString *)value));
+        if (!numericValue)
             return WTF::nullopt;
-        vector.uncheckedAppend(numericValue);
+        vector.uncheckedAppend(*numericValue);
     }
     return vector;
 }

Modified: trunk/Source/WebCore/platform/network/ParsedRequestRange.cpp (277245 => 277246)


--- trunk/Source/WebCore/platform/network/ParsedRequestRange.cpp	2021-05-09 18:22:23 UTC (rev 277245)
+++ trunk/Source/WebCore/platform/network/ParsedRequestRange.cpp	2021-05-09 18:31:34 UTC (rev 277246)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2021 Apple Inc.  All rights reserved.
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "ParsedRequestRange.h"
 
-#include <wtf/text/WTFString.h>
+#include <wtf/text/StringToIntegerConversion.h>
 
 namespace WebCore {
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to