Diff
Modified: trunk/Source/WTF/ChangeLog (277244 => 277245)
--- trunk/Source/WTF/ChangeLog 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WTF/ChangeLog 2021-05-09 18:22:23 UTC (rev 277245)
@@ -1,3 +1,14 @@
+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
+
+ Reviewed by Sam Weinig.
+
+ * wtf/text/StringBuilder.h: Added conversion operator to make a StringView, built on the exiting
+ is8Bit, characters8, characters16 and length functions. Removed now-uneeded equal function and
+ == and != operators since the StringView ones work for those same cases with the same syntax.
+
2021-05-08 Darin Adler <[email protected]>
Rename toIntegralType to parseInteger and prepare to use it to replace all our integer-parsing functions
Modified: trunk/Source/WTF/wtf/text/StringBuilder.h (277244 => 277245)
--- trunk/Source/WTF/wtf/text/StringBuilder.h 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WTF/wtf/text/StringBuilder.h 2021-05-09 18:22:23 UTC (rev 277245)
@@ -327,6 +327,8 @@
bool is8Bit() const { return m_is8Bit; }
WTF_EXPORT_PRIVATE bool isAllASCII() const;
+ operator StringView() const;
+
void clear()
{
m_length = 0;
@@ -376,6 +378,13 @@
#endif
};
+inline StringBuilder::operator StringView() const
+{
+ if (m_is8Bit)
+ return { characters8(), length() };
+ return { characters16(), length() };
+}
+
template<>
ALWAYS_INLINE LChar* StringBuilder::getBufferCharacters<LChar>()
{
@@ -417,6 +426,7 @@
appendFromAdapters(StringTypeAdapter<StringTypes>(strings)...);
}
+// FIXME: Move this to StringView and make it take a StringView instead of a StringBuilder?
template<typename CharacterType>
bool equal(const StringBuilder& s, const CharacterType* buffer, unsigned length)
{
@@ -429,33 +439,6 @@
return equal(s.characters16(), buffer, length);
}
-template<typename StringType>
-bool equal(const StringBuilder& a, const StringType& b)
-{
- if (a.length() != b.length())
- return false;
-
- if (!a.length())
- return true;
-
- if (a.is8Bit()) {
- if (b.is8Bit())
- return equal(a.characters8(), b.characters8(), a.length());
- return equal(a.characters8(), b.characters16(), a.length());
- }
-
- if (b.is8Bit())
- return equal(a.characters16(), b.characters8(), a.length());
- return equal(a.characters16(), b.characters16(), a.length());
-}
-
-inline bool operator==(const StringBuilder& a, const StringBuilder& b) { return equal(a, b); }
-inline bool operator!=(const StringBuilder& a, const StringBuilder& b) { return !equal(a, b); }
-inline bool operator==(const StringBuilder& a, const String& b) { return equal(a, b); }
-inline bool operator!=(const StringBuilder& a, const String& b) { return !equal(a, b); }
-inline bool operator==(const String& a, const StringBuilder& b) { return equal(b, a); }
-inline bool operator!=(const String& a, const StringBuilder& b) { return !equal(b, a); }
-
template<> struct IntegerToStringConversionTrait<StringBuilder> {
using ReturnType = void;
using AdditionalArgumentType = StringBuilder;
Modified: trunk/Source/WebCore/ChangeLog (277244 => 277245)
--- trunk/Source/WebCore/ChangeLog 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/ChangeLog 2021-05-09 18:22:23 UTC (rev 277245)
@@ -1,3 +1,141 @@
+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
+
+ Reviewed by Sam Weinig.
+
+ * dom/Document.cpp:
+ (WebCore::Document::createEvent): Fix spelling error.
+
+ * html/FTPDirectoryDocument.cpp:
+ (WebCore::processFilesizeString): Use parseIntegerAllowingTrailingJunk<uint64_t>
+ instead of String::toUInt64.
+
+ * html/FormController.cpp:
+ (WebCore::deserializeFormControlState): Use parseIntegerAllowingTrailingJunk<size_t>
+ instead of String::toUInt.
+ (WebCore::SavedFormState::deserialize): Ditto.
+
+ * html/HTMLFontElement.cpp:
+ (WebCore::parseFontSize): Use parseInteger<int> instead of
+ charactersToIntStrict.
+ * html/HTMLFrameElement.cpp:
+ (WebCore::HTMLFrameElement::parseAttribute): Use parseIntegerAllowingTrailingJunk<int>
+ instead of String::toInt.
+ * html/HTMLFrameSetElement.cpp:
+ (WebCore::HTMLFrameSetElement::parseAttribute): Ditto.
+ * html/HTMLHRElement.cpp:
+ (WebCore::HTMLHRElement::collectStyleForPresentationAttribute): Ditto.
+ * html/HTMLIFrameElement.cpp:
+ (WebCore::HTMLIFrameElement::collectStyleForPresentationAttribute): Ditto.
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::parseAttribute): Ditto.
+ * html/HTMLLIElement.cpp:
+ (WebCore::HTMLLIElement::parseValue): Ditto.
+ * html/HTMLMarqueeElement.cpp:
+ (WebCore::HTMLMarqueeElement::loop const): Ditto.
+ * html/HTMLTableCellElement.cpp:
+ (WebCore::HTMLTableCellElement::collectStyleForPresentationAttribute): Ditto.
+ * html/HTMLTableColElement.cpp:
+ (WebCore::HTMLTableColElement::parseAttribute): Ditto.
+ * html/HTMLTableElement.cpp:
+ (WebCore::HTMLTableElement::parseAttribute): Ditto.
+
+ * html/LinkIconCollector.cpp:
+ (WebCore::LinkIconCollector::iconsOfTypes): Use parseIntegerAllowingTrailingJunk<unsigned>
+ instead of String::toUInt. Also removed unneeded call to stripWhiteSpace since the
+ integer parsing function already skips leading and trailing spaces.
+
+ * html/MediaFragmentURIParser.cpp:
+ (WebCore::MediaFragmentURIParser::parseNPTTime): Use parseInteger<int> instead of
+ String::toInt. The strings passsed in are fixed size and all digits.
+
+ * html/TypeAhead.cpp:
+ (WebCore::TypeAhead::handleEvent): Use parseIntegerAllowingTrailingJunk<int>
+ instead of String::toInt.
+
+ * html/URLDecomposition.cpp:
+ (WebCore::URLDecomposition::setHost): Use parseInteger<uint16_t> instead of parseUInt16.
+ (WebCore::parsePort): Ditto.
+
+ * html/shadow/DateTimeNumericFieldElement.cpp:
+ (WebCore::DateTimeNumericFieldElement::handleKeyboardEvent): Use
+ parseIntegerAllowingTrailingJunk<int> instead of String::toInt.
+
+ * html/track/VTTScanner.cpp:
+ (WebCore::VTTScanner::scanDigits): Use parseInteger<int> instead of
+ charactersToIntStrict.
+
+ * mathml/MathMLSelectElement.cpp:
+ (WebCore::MathMLSelectElement::getSelectedActionChildAndIndex): Use
+ parseIntegerAllowingTrailingJunk<int> instead of AtomString::toInt.
+
+2021-05-08 Darin Adler <[email protected]>
+
+ Remove uses of the String::toInt family of functions from the WebCore/svg and WebCore/workers directories
+ https://bugs.webkit.org/show_bug.cgi?id=225573
+
+ Reviewed by Sam Weinig.
+
+ Both SVG and service workers had code that should be moved from headers
+ into implementation files. This allowed us to use the new parseInteger
+ function templates without including the header in headers, which may help
+ keep compile times from getting out of hand.
+
+ * Sources.txt: Added the new source files.
+ * WebCore.xcodeproj/project.pbxproj: Ditto.
+
+ * svg/SVGFEConvolveMatrixElement.cpp:
+ (WebCore::SVGFEConvolveMatrixElement::parseAttribute): Use parseInteger<unsigned>
+ instead of String::toUIntStrict.
+ * svg/SVGFETurbulenceElement.cpp:
+ (WebCore::SVGFETurbulenceElement::parseAttribute): Ditto.
+
+ * svg/SVGToOTFFontConversion.cpp:
+ (WebCore::SVGToOTFFontConverter::appendOS2Table): Use
+ parseIntegerAllowingTrailingJunk<int> instead of String::toInt. Use
+ parseIntegerAllowingTrailingJunk<uint8_t> instead of String::toInt,
+ allowing us to remove range checking to reject values that are out of range.
+ (WebCore::SVGToOTFFontConverter::appendVORGTable): Ditto.
+ (WebCore::SVGToOTFFontConverter::SVGToOTFFontConverter): Ditto.
+
+ * svg/animation/SVGSMILElement.cpp:
+ (WebCore::SVGSMILElement::parseClockValue): Use parseInteger<uint8_t>
+ instead of String::toUIntStrict. These are all 2-character numeric
+ strings. Also simplified the logic and used StringView so we don't have to
+ allocate memory for the substrings.
+ (WebCore::SVGSMILElement::parseCondition): Use parseInteger<unsigned>
+ instead of String::toUIntStrict. Also used StringView.
+ * svg/properties/SVGAnimationAdditiveValueFunctionImpl.cpp:
+ (WebCore::SVGAnimationIntegerFunction::calculateDistance const): Moved
+ this file here from the header, and used parseInteger<int> rather than
+ String::toIntStrict.
+
+ * svg/properties/SVGAnimationAdditiveValueFunctionImpl.h: Moved
+ SVGAnimationIntegerFunction::calculateDistance out of the header.
+ Also marked the class and member functions final. (Could do that for
+ a lot more of the classes in this file.)
+
+ * svg/properties/SVGPropertyTraits.cpp: Added.
+ (WebCore::SVGPropertyTraits<int>::fromString): Moved this here from the
+ header and use parseInteger<int> instead of String::toIntStrict.
+ * svg/properties/SVGPropertyTraits.h: Updated for the above.
+
+ * workers/service/ServiceWorkerClientIdentifier.cpp: Added.
+ (WebCore::ServiceWorkerClientIdentifier::fromString): Moved this here
+ from the header and use parseInteger<uint64_t> instead of
+ StringView::toUInt64Strict.
+ * workers/service/ServiceWorkerClientIdentifier.h: Updated for the above.
+ Also moved ServiceWorkerClientIdentifierHash from the WTF namespace
+ to the WebCore namespace.
+
+ * workers/service/ServiceWorkerRegistrationKey.cpp:
+ (WebCore::ServiceWorkerRegistrationKey::fromDatabaseKey): Use
+ parseInteger<uint16_t> instead of charactersToUIntStrict, allowing us
+ to remove range checking. Also use StringView::substring instead of
+ writing out special cases for 8-bit and 16-bit characters.
+
2021-05-09 Myles C. Maxfield <[email protected]>
[GPU Process] Simplify DisplayList::Iterator part 6: Migrate ItemBufferWritingClient from ItemHandle to a const Variant&
Modified: trunk/Source/WebCore/Sources.txt (277244 => 277245)
--- trunk/Source/WebCore/Sources.txt 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/Sources.txt 2021-05-09 18:22:23 UTC (rev 277245)
@@ -2651,6 +2651,7 @@
svg/properties/SVGAnimatedProperty.cpp
svg/properties/SVGAnimationAdditiveValueFunctionImpl.cpp
svg/properties/SVGAttributeAnimator.cpp
+svg/properties/SVGPropertyTraits.cpp
workers/AbstractWorker.cpp
workers/DedicatedWorkerGlobalScope.cpp
workers/DedicatedWorkerThread.cpp
@@ -2677,6 +2678,7 @@
workers/service/ServiceWorker.cpp
workers/service/ServiceWorkerClient.cpp
workers/service/ServiceWorkerClientData.cpp
+workers/service/ServiceWorkerClientIdentifier.cpp
workers/service/ServiceWorkerClients.cpp
workers/service/ServiceWorkerContainer.cpp
workers/service/ServiceWorkerContextData.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (277244 => 277245)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-05-09 18:22:23 UTC (rev 277245)
@@ -11798,6 +11798,8 @@
93F9B6DF0BA0FB7200854064 /* JSComment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSComment.h; sourceTree = "<group>"; };
93F9B79E0BA6032600854064 /* JSCDATASection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCDATASection.cpp; sourceTree = "<group>"; };
93F9B79F0BA6032600854064 /* JSCDATASection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCDATASection.h; sourceTree = "<group>"; };
+ 93FCDB49264455D60046DD7D /* ServiceWorkerClientIdentifier.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerClientIdentifier.cpp; sourceTree = "<group>"; };
+ 93FCDB4B26470DD10046DD7D /* SVGPropertyTraits.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPropertyTraits.cpp; sourceTree = "<group>"; };
93FDAFC90B11307400E2746F /* EditorInsertAction.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = EditorInsertAction.h; sourceTree = "<group>"; };
941827881D8B242200492764 /* StyleColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleColor.cpp; sourceTree = "<group>"; };
941827891D8B242200492764 /* StyleColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleColor.h; sourceTree = "<group>"; };
@@ -17857,6 +17859,7 @@
55EE5360223B2A2100FBA944 /* SVGPropertyOwner.h */,
55BE025C223B29C30032F08A /* SVGPropertyOwnerRegistry.h */,
55BE0257223B29C00032F08A /* SVGPropertyRegistry.h */,
+ 93FCDB4B26470DD10046DD7D /* SVGPropertyTraits.cpp */,
088A0E03126EF1DB00978F7A /* SVGPropertyTraits.h */,
550F664522CA89BD000A3417 /* SVGSharedPrimitiveProperty.h */,
721443462240CAD200F12FF7 /* SVGValueProperty.h */,
@@ -20941,6 +20944,7 @@
46EF14281F97B7BA00C2A524 /* ServiceWorkerClient.idl */,
8379363C1FBBB0A400C8023C /* ServiceWorkerClientData.cpp */,
8379363E1FBBB0A500C8023C /* ServiceWorkerClientData.h */,
+ 93FCDB49264455D60046DD7D /* ServiceWorkerClientIdentifier.cpp */,
837D46251FA2A8C50054E1FA /* ServiceWorkerClientIdentifier.h */,
413FC4CD1FD1DD8C00541C4B /* ServiceWorkerClientQueryOptions.h */,
46EF14211F97B7BA00C2A524 /* ServiceWorkerClients.cpp */,
Modified: trunk/Source/WebCore/dom/Document.cpp (277244 => 277245)
--- trunk/Source/WebCore/dom/Document.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/dom/Document.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -5207,7 +5207,7 @@
// Please do *not* add new event classes to this function unless they are required
// for compatibility with the DOM specification or some actual legacy web content.
- // This mechanism is superceded by use of event constructors.
+ // This mechanism is superseded by use of event constructors.
// That is what we should use for any new event classes.
// The following strings are the ones from the DOM specification
Modified: trunk/Source/WebCore/html/FTPDirectoryDocument.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/FTPDirectoryDocument.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/FTPDirectoryDocument.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -42,6 +42,7 @@
#include <wtf/IsoMallocInlines.h>
#include <wtf/StdLibExtras.h>
#include <wtf/text/StringConcatenateNumbers.h>
+#include <wtf/text/StringToIntegerConversion.h>
#include <wtf/unicode/CharacterNames.h>
namespace WebCore {
@@ -160,18 +161,15 @@
if (isDirectory)
return "--"_s;
- bool valid;
- int64_t bytes = size.toUInt64(&valid);
- if (!valid)
+ auto bytes = parseIntegerAllowingTrailingJunk<uint64_t>(size);
+ if (!bytes)
return unknownFileSizeText();
- if (bytes < 1000000)
- return makeString(FormattedNumber::fixedWidth(bytes / 1000., 2), " KB");
-
- if (bytes < 1000000000)
- return makeString(FormattedNumber::fixedWidth(bytes / 1000000., 2), " MB");
-
- return makeString(FormattedNumber::fixedWidth(bytes / 1000000000., 2), " GB");
+ if (*bytes < 1000000)
+ return makeString(FormattedNumber::fixedWidth(*bytes / 1000., 2), " KB");
+ if (*bytes < 1000000000)
+ return makeString(FormattedNumber::fixedWidth(*bytes / 1000000., 2), " MB");
+ return makeString(FormattedNumber::fixedWidth(*bytes / 1000000000., 2), " GB");
}
static bool wasLastDayOfMonth(int year, int month, int day)
Modified: trunk/Source/WebCore/html/FormController.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/FormController.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/FormController.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -27,6 +27,7 @@
#include <wtf/NeverDestroyed.h>
#include <wtf/text/StringBuilder.h>
#include <wtf/text/StringConcatenateNumbers.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -65,7 +66,7 @@
{
if (index >= stateVector.size())
return WTF::nullopt;
- size_t size = stateVector[index++].toUInt();
+ auto size = parseIntegerAllowingTrailingJunk<size_t>(stateVector[index++]).valueOr(0);
if (index + size > stateVector.size())
return WTF::nullopt;
Vector<String> subvector;
@@ -196,8 +197,7 @@
{
if (index >= stateVector.size())
return nullptr;
- // FIXME: We need String::toSizeT().
- size_t itemCount = stateVector[index++].toUInt();
+ auto itemCount = parseIntegerAllowingTrailingJunk<size_t>(stateVector[index++]).valueOr(0);
if (!itemCount)
return nullptr;
auto savedFormState = makeUnique<SavedFormState>();
Modified: trunk/Source/WebCore/html/HTMLFontElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/HTMLFontElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/HTMLFontElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -33,6 +33,7 @@
#include "StyleProperties.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/text/StringBuilder.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -108,13 +109,8 @@
return false;
// Step 8
- int value;
+ int value = parseInteger<int>(digits).valueOr(0);
- if (digits.is8Bit())
- value = charactersToIntStrict(digits.characters8(), digits.length());
- else
- value = charactersToIntStrict(digits.characters16(), digits.length());
-
// Step 9
if (mode == RelativePlus)
value += 3;
Modified: trunk/Source/WebCore/html/HTMLFrameElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/HTMLFrameElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/HTMLFrameElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -29,6 +29,7 @@
#include "HTMLNames.h"
#include "RenderFrame.h"
#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -82,7 +83,7 @@
void HTMLFrameElement::parseAttribute(const QualifiedName& name, const AtomString& value)
{
if (name == frameborderAttr) {
- m_frameBorder = value.toInt();
+ m_frameBorder = parseIntegerAllowingTrailingJunk<int>(value).valueOr(0);
m_frameBorderSet = !value.isNull();
// FIXME: If we are already attached, this has no effect.
} else if (name == noresizeAttr) {
Modified: trunk/Source/WebCore/html/HTMLFrameSetElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/HTMLFrameSetElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/HTMLFrameSetElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -41,6 +41,7 @@
#include "RenderFrameSet.h"
#include "Text.h"
#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -131,7 +132,7 @@
if (name == borderAttr) {
if (!value.isNull()) {
- m_border = value.toInt();
+ m_border = parseIntegerAllowingTrailingJunk<int>(value).valueOr(0);
m_borderSet = true;
} else
m_borderSet = false;
Modified: trunk/Source/WebCore/html/HTMLHRElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/HTMLHRElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/HTMLHRElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -29,6 +29,7 @@
#include "HTMLNames.h"
#include "StyleProperties.h"
#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -73,9 +74,7 @@
addPropertyToPresentationAttributeStyle(style, CSSPropertyMarginRight, CSSValueAuto);
}
} else if (name == widthAttr) {
- bool ok;
- int v = value.toInt(&ok);
- if (ok && !v)
+ if (auto valueInteger = parseIntegerAllowingTrailingJunk<int>(value); valueInteger && !*valueInteger)
addPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, 1, CSSUnitType::CSS_PX);
else
addHTMLLengthToStyle(style, CSSPropertyWidth, value);
@@ -92,8 +91,7 @@
style.setProperty(CSSPropertyBackgroundColor, darkGrayValue);
}
} else if (name == sizeAttr) {
- StringImpl* si = value.impl();
- int size = si->toInt();
+ int size = parseIntegerAllowingTrailingJunk<int>(value).valueOr(0);
if (size <= 1)
addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderBottomWidth, 0, CSSUnitType::CSS_PX);
else
Modified: trunk/Source/WebCore/html/HTMLIFrameElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/HTMLIFrameElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/HTMLIFrameElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -35,6 +35,7 @@
#include "ScriptableDocumentParser.h"
#include "Settings.h"
#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -86,7 +87,7 @@
else if (name == frameborderAttr) {
// Frame border doesn't really match the HTML4 spec definition for iframes. It simply adds
// a presentational hint that the border should be off if set to zero.
- if (!value.toInt()) {
+ if (!parseIntegerAllowingTrailingJunk<int>(value).valueOr(0)) {
// Add a rule that nulls out our border width.
addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderWidth, 0, CSSUnitType::CSS_PX);
}
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -71,6 +71,7 @@
#include <wtf/Language.h>
#include <wtf/MathExtras.h>
#include <wtf/Ref.h>
+#include <wtf/text/StringToIntegerConversion.h>
#if ENABLE(TOUCH_EVENTS)
#include "TouchEvent.h"
@@ -801,7 +802,7 @@
if (m_size != oldSize && renderer())
renderer()->setNeedsLayoutAndPrefWidthsRecalc();
} else if (name == resultsAttr)
- m_maxResults = !value.isNull() ? std::min(value.toInt(), maxSavedResults) : -1;
+ m_maxResults = value.isNull() ? -1 : std::min(parseIntegerAllowingTrailingJunk<int>(value).valueOr(0), maxSavedResults);
else if (name == autosaveAttr || name == incrementalAttr)
invalidateStyleForSubtree();
else if (name == maxAttr || name == minAttr || name == multipleAttr || name == patternAttr || name == precisionAttr || name == stepAttr)
Modified: trunk/Source/WebCore/html/HTMLLIElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/HTMLLIElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/HTMLLIElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -117,13 +117,7 @@
inline void HTMLLIElement::parseValue(const AtomString& value)
{
ASSERT(renderer());
-
- bool valueOK;
- int requestedValue = value.toInt(&valueOK);
- if (valueOK)
- downcast<RenderListItem>(*renderer()).setExplicitValue(requestedValue);
- else
- downcast<RenderListItem>(*renderer()).setExplicitValue(WTF::nullopt);
+ downcast<RenderListItem>(*renderer()).setExplicitValue(parseIntegerAllowingTrailingJunk<int>(value));
}
}
Modified: trunk/Source/WebCore/html/HTMLMarqueeElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/HTMLMarqueeElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/HTMLMarqueeElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -32,6 +32,7 @@
#include "RenderLayerScrollableArea.h"
#include "RenderMarquee.h"
#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -147,9 +148,8 @@
int HTMLMarqueeElement::loop() const
{
- bool ok;
- int loopValue = attributeWithoutSynchronization(loopAttr).toInt(&ok);
- return ok && loopValue > 0 ? loopValue : -1;
+ auto loopValue = parseIntegerAllowingTrailingJunk<int>(attributeWithoutSynchronization(loopAttr));
+ return loopValue && *loopValue > 0 ? *loopValue : -1;
}
ExceptionOr<void> HTMLMarqueeElement::setLoop(int loop)
Modified: trunk/Source/WebCore/html/HTMLTableCellElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/HTMLTableCellElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/HTMLTableCellElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -32,6 +32,7 @@
#include "HTMLTableElement.h"
#include "RenderTableCell.h"
#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -102,17 +103,11 @@
if (name == nowrapAttr)
addPropertyToPresentationAttributeStyle(style, CSSPropertyWhiteSpace, CSSValueWebkitNowrap);
else if (name == widthAttr) {
- if (!value.isEmpty()) {
- int widthInt = value.toInt();
- if (widthInt > 0) // width="0" is ignored for compatibility with WinIE.
- addHTMLLengthToStyle(style, CSSPropertyWidth, value);
- }
+ if (parseIntegerAllowingTrailingJunk<int>(value).valueOr(0) > 0) // width="0" is ignored for compatibility with WinIE.
+ addHTMLLengthToStyle(style, CSSPropertyWidth, value);
} else if (name == heightAttr) {
- if (!value.isEmpty()) {
- int heightInt = value.toInt();
- if (heightInt > 0) // height="0" is ignored for compatibility with WinIE.
- addHTMLLengthToStyle(style, CSSPropertyHeight, value);
- }
+ if (parseIntegerAllowingTrailingJunk<int>(value).valueOr(0) > 0) // height="0" is ignored for compatibility with WinIE.
+ addHTMLLengthToStyle(style, CSSPropertyHeight, value);
} else
HTMLTablePartElement::collectStyleForPresentationAttribute(name, value, style);
}
Modified: trunk/Source/WebCore/html/HTMLTableColElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/HTMLTableColElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/HTMLTableColElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -79,7 +79,7 @@
if (!value.isEmpty()) {
if (is<RenderTableCol>(renderer())) {
RenderTableCol& col = downcast<RenderTableCol>(*renderer());
- int newWidth = width().toInt();
+ int newWidth = parseIntegerAllowingTrailingJunk<int>(width()).valueOr(0);
if (newWidth != col.width())
col.setNeedsLayoutAndPrefWidthsRecalc();
}
Modified: trunk/Source/WebCore/html/HTMLTableElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/HTMLTableElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/HTMLTableElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -42,6 +42,7 @@
#include "StyleProperties.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/Ref.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -399,7 +400,7 @@
m_rulesAttr = AllRules;
} else if (name == cellpaddingAttr) {
if (!value.isEmpty())
- m_padding = std::max(0, value.toInt());
+ m_padding = std::max(0, parseIntegerAllowingTrailingJunk<int>(value).valueOr(0));
else
m_padding = 1;
} else if (name == colsAttr) {
Modified: trunk/Source/WebCore/html/LinkIconCollector.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/LinkIconCollector.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/LinkIconCollector.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -31,6 +31,7 @@
#include "HTMLHeadElement.h"
#include "HTMLLinkElement.h"
#include "LinkIconType.h"
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -96,14 +97,9 @@
// part of the size, "60x70" becomes "60". This is for compatibility reasons
// and is probably good enough for now.
Optional<unsigned> iconSize;
+ if (linkElement.sizes().length())
+ iconSize = parseIntegerAllowingTrailingJunk<unsigned>(linkElement.sizes().item(0));
- if (linkElement.sizes().length()) {
- bool ok;
- unsigned size = linkElement.sizes().item(0).string().stripWhiteSpace().toUInt(&ok);
- if (ok)
- iconSize = size;
- }
-
Vector<std::pair<String, String>> attributes;
if (linkElement.hasAttributes()) {
attributes.reserveCapacity(linkElement.attributeCount());
Modified: trunk/Source/WebCore/html/MediaFragmentURIParser.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/MediaFragmentURIParser.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/MediaFragmentURIParser.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -24,11 +24,10 @@
*/
#include "config.h"
+#include "MediaFragmentURIParser.h"
#if ENABLE(VIDEO)
-#include "MediaFragmentURIParser.h"
-
#include "HTMLElement.h"
#include "MediaPlayer.h"
#include "ProcessingInstruction.h"
@@ -36,13 +35,13 @@
#include "Text.h"
#include <wtf/text/CString.h>
#include <wtf/text/StringBuilder.h>
-#include <wtf/text/WTFString.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
-const int secondsPerHour = 3600;
-const int secondsPerMinute = 60;
-const unsigned nptIdentifierLength = 4; // "npt:"
+constexpr int secondsPerHour = 3600;
+constexpr int secondsPerMinute = 60;
+constexpr unsigned nptIdentifierLength = 4; // "npt:"
static String collectDigits(const LChar* input, unsigned length, unsigned& position)
{
@@ -260,7 +259,7 @@
// npt-ss = 2DIGIT ; 0-59
String digits1 = collectDigits(timeString, length, offset);
- int value1 = digits1.toInt();
+ int value1 = parseInteger<int>(digits1).valueOr(0);
if (offset >= length || timeString[offset] == ',') {
time = MediaTime::createWithDouble(value1);
return true;
@@ -287,9 +286,9 @@
if (offset >= length || !isASCIIDigit(timeString[(offset)]))
return false;
String digits2 = collectDigits(timeString, length, offset);
- int value2 = digits2.toInt();
if (digits2.length() != 2)
return false;
+ int value2 = parseInteger<int>(digits2).value();
// Detect whether this timestamp includes hours.
int value3;
@@ -301,7 +300,7 @@
String digits3 = collectDigits(timeString, length, offset);
if (digits3.length() != 2)
return false;
- value3 = digits3.toInt();
+ value3 = parseInteger<int>(digits3).value();
} else {
value3 = value2;
value2 = value1;
Modified: trunk/Source/WebCore/html/TypeAhead.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/TypeAhead.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/TypeAhead.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -29,11 +29,10 @@
#include "TypeAhead.h"
#include "KeyboardEvent.h"
+#include <wtf/text/StringToIntegerConversion.h>
#include <wtf/unicode/CharacterNames.h>
-
namespace WebCore {
-using namespace WTF::Unicode;
TypeAhead::TypeAhead(TypeAheadDataSource* dataSource)
: m_dataSource(dataSource)
@@ -103,8 +102,7 @@
}
if (matchMode & MatchIndex) {
- bool ok = false;
- int index = m_buffer.toString().toInt(&ok);
+ int index = parseIntegerAllowingTrailingJunk<int>(m_buffer).valueOr(0);
if (index > 0 && index <= optionCount)
return index - 1;
}
Modified: trunk/Source/WebCore/html/URLDecomposition.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/URLDecomposition.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/URLDecomposition.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -27,6 +27,7 @@
#include "URLDecomposition.h"
#include "SecurityOrigin.h"
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -118,7 +119,7 @@
if (!portLength) {
fullURL.setHost(value.substring(0, separator));
} else {
- auto portNumber = parseUInt16(value.substring(separator + 1, portLength));
+ auto portNumber = parseInteger<uint16_t>(value.substring(separator + 1, portLength));
if (portNumber && WTF::isDefaultPortForProtocol(*portNumber, fullURL.protocol()))
fullURL.setHostAndPort(value.substring(0, separator));
else
@@ -172,7 +173,7 @@
auto digitsOnly = string.left(countASCIIDigits(string));
if (digitsOnly.isEmpty())
return Optional<uint16_t> { WTF::nullopt };
- auto port = parseUInt16(digitsOnly);
+ auto port = parseInteger<uint16_t>(digitsOnly);
if (!port)
return WTF::nullopt;
if (WTF::isDefaultPortForProtocol(*port, protocol))
Modified: trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -36,6 +36,7 @@
#include "RenderBlock.h"
#include "RenderStyle.h"
#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -182,7 +183,7 @@
}
m_typeAheadBuffer.append(number);
- setValueAsInteger(m_typeAheadBuffer.toString().toInt(), DispatchInputAndChangeEvents);
+ setValueAsInteger(parseIntegerAllowingTrailingJunk<int>(m_typeAheadBuffer).valueOr(0), DispatchInputAndChangeEvents);
keyboardEvent.setDefaultHandled();
}
Modified: trunk/Source/WebCore/html/track/VTTScanner.cpp (277244 => 277245)
--- trunk/Source/WebCore/html/track/VTTScanner.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/html/track/VTTScanner.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -30,6 +30,8 @@
#include "config.h"
#include "VTTScanner.h"
+#include <wtf/text/StringToIntegerConversion.h>
+
namespace WebCore {
VTTScanner::VTTScanner(const String& line)
@@ -122,19 +124,17 @@
number = 0;
return 0;
}
- bool validNumber;
- size_t numDigits = runOfDigits.length();
+
+ StringView string;
+ unsigned numDigits = runOfDigits.length();
if (m_is8Bit)
- number = charactersToIntStrict(m_data.characters8, numDigits, &validNumber);
+ string = { m_data.characters8, numDigits };
else
- number = charactersToIntStrict(m_data.characters16, numDigits, &validNumber);
+ string = { m_data.characters16, numDigits };
- // Since we know that scanDigits only scanned valid (ASCII) digits (and
- // hence that's what got passed to charactersToInt()), the remaining
- // failure mode for charactersToInt() is overflow, so if |validNumber| is
- // not true, then set |number| to the maximum int value.
- if (!validNumber)
- number = std::numeric_limits<int>::max();
+ // Since these are ASCII digits, the only failure mode is overflow, so use the maximum int value.
+ number = parseInteger<int>(string).valueOr(std::numeric_limits<int>::max());
+
// Consume the digits.
seekTo(runOfDigits.end());
return numDigits;
Modified: trunk/Source/WebCore/mathml/MathMLSelectElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/mathml/MathMLSelectElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/mathml/MathMLSelectElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -37,6 +37,7 @@
#include "RenderTreeUpdater.h"
#include "SVGElement.h"
#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -117,7 +118,7 @@
if (!selectedChild)
return 1;
- int selection = attributeWithoutSynchronization(MathMLNames::selectionAttr).toInt();
+ int selection = parseIntegerAllowingTrailingJunk<int>(attributeWithoutSynchronization(MathMLNames::selectionAttr)).valueOr(0);
int i;
for (i = 1; i < selection; i++) {
auto* nextChild = selectedChild->nextElementSibling();
Modified: trunk/Source/WebCore/svg/SVGFEConvolveMatrixElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/svg/SVGFEConvolveMatrixElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/svg/SVGFEConvolveMatrixElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -29,6 +29,7 @@
#include "SVGNames.h"
#include "SVGParserUtilities.h"
#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -105,12 +106,12 @@
}
if (name == SVGNames::targetXAttr) {
- m_targetX->setBaseValInternal(value.string().toUIntStrict());
+ m_targetX->setBaseValInternal(parseInteger<unsigned>(value).valueOr(0));
return;
}
if (name == SVGNames::targetYAttr) {
- m_targetY->setBaseValInternal(value.string().toUIntStrict());
+ m_targetY->setBaseValInternal(parseInteger<unsigned>(value).valueOr(0));
return;
}
Modified: trunk/Source/WebCore/svg/SVGFETurbulenceElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/svg/SVGFETurbulenceElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/svg/SVGFETurbulenceElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -25,6 +25,7 @@
#include "SVGNames.h"
#include "SVGParserUtilities.h"
#include <wtf/IsoMallocInlines.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -80,7 +81,7 @@
}
if (name == SVGNames::numOctavesAttr) {
- m_numOctaves->setBaseValInternal(value.string().toUIntStrict());
+ m_numOctaves->setBaseValInternal(parseInteger<unsigned>(value).valueOr(0));
return;
}
Modified: trunk/Source/WebCore/svg/SVGToOTFFontConversion.cpp (277244 => 277245)
--- trunk/Source/WebCore/svg/SVGToOTFFontConversion.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/svg/SVGToOTFFontConversion.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -39,6 +39,7 @@
#include "SVGVKernElement.h"
#include <wtf/Optional.h>
#include <wtf/Vector.h>
+#include <wtf/text/StringToIntegerConversion.h>
#include <wtf/text/StringView.h>
namespace WebCore {
@@ -489,13 +490,11 @@
void SVGToOTFFontConverter::appendOS2Table()
{
int16_t averageAdvance = s_outputUnitsPerEm;
- bool ok;
- int value = m_fontElement.attributeWithoutSynchronization(SVGNames::horiz_adv_xAttr).toInt(&ok);
- if (!ok && m_missingGlyphElement)
- value = m_missingGlyphElement->attributeWithoutSynchronization(SVGNames::horiz_adv_xAttr).toInt(&ok);
- value = scaleUnitsPerEm(value);
- if (ok)
- averageAdvance = clampTo<int16_t>(value);
+ auto horizAdvX = parseIntegerAllowingTrailingJunk<int>(m_fontElement.attributeWithoutSynchronization(SVGNames::horiz_adv_xAttr));
+ if (!horizAdvX && m_missingGlyphElement)
+ horizAdvX = parseIntegerAllowingTrailingJunk<int>(m_missingGlyphElement->attributeWithoutSynchronization(SVGNames::horiz_adv_xAttr));
+ if (horizAdvX)
+ averageAdvance = clampTo<int16_t>(scaleUnitsPerEm(*horizAdvX));
append16(2); // Version
append16(clampTo<int16_t>(averageAdvance));
@@ -522,10 +521,8 @@
Vector<String> segments = m_fontFaceElement->attributeWithoutSynchronization(SVGNames::panose_1Attr).string().split(' ');
if (segments.size() == panoseSize) {
for (auto& segment : segments) {
- bool ok;
- int value = segment.toInt(&ok);
- if (ok && value >= std::numeric_limits<uint8_t>::min() && value <= std::numeric_limits<uint8_t>::max())
- panoseBytes[numPanoseBytes++] = value;
+ if (auto value = parseIntegerAllowingTrailingJunk<uint8_t>(segment))
+ panoseBytes[numPanoseBytes++] = *value;
}
}
}
@@ -947,20 +944,18 @@
append16(1); // Major version
append16(0); // Minor version
- bool ok;
- int defaultVerticalOriginY = m_fontElement.attributeWithoutSynchronization(SVGNames::vert_origin_yAttr).toInt(&ok);
- if (!ok && m_missingGlyphElement)
- defaultVerticalOriginY = m_missingGlyphElement->attributeWithoutSynchronization(SVGNames::vert_origin_yAttr).toInt();
- defaultVerticalOriginY = scaleUnitsPerEm(defaultVerticalOriginY);
- append16(clampTo<int16_t>(defaultVerticalOriginY));
+ auto vertOriginY = parseIntegerAllowingTrailingJunk<int>(m_fontElement.attributeWithoutSynchronization(SVGNames::vert_origin_yAttr));
+ if (!vertOriginY && m_missingGlyphElement)
+ vertOriginY = parseIntegerAllowingTrailingJunk<int>(m_missingGlyphElement->attributeWithoutSynchronization(SVGNames::vert_origin_yAttr));
+ append16(clampTo<int16_t>(scaleUnitsPerEm(vertOriginY.valueOr(0))));
auto tableSizeOffset = m_result.size();
append16(0); // Place to write table size.
for (Glyph i = 0; i < m_glyphs.size(); ++i) {
if (auto* glyph = m_glyphs[i].glyphElement) {
- if (int verticalOriginY = glyph->attributeWithoutSynchronization(SVGNames::vert_origin_yAttr).toInt()) {
+ if (auto verticalOriginY = parseIntegerAllowingTrailingJunk<int>(glyph->attributeWithoutSynchronization(SVGNames::vert_origin_yAttr))) {
append16(i);
- append16(clampTo<int16_t>(scaleUnitsPerEm(verticalOriginY)));
+ append16(clampTo<int16_t>(scaleUnitsPerEm(*verticalOriginY)));
}
}
}
@@ -1450,21 +1445,17 @@
// FIXME: Handle commas.
if (m_fontFaceElement) {
- auto& fontWeightAttribute = m_fontFaceElement->attributeWithoutSynchronization(SVGNames::font_weightAttr);
- for (auto segment : StringView(fontWeightAttribute).split(' ')) {
+ for (auto segment : StringView(m_fontFaceElement->attributeWithoutSynchronization(SVGNames::font_weightAttr)).split(' ')) {
if (equalLettersIgnoringASCIICase(segment, "bold")) {
m_weight = 7;
break;
}
- bool ok;
- int value = segment.toInt(ok);
- if (ok && value >= 0 && value < 1000) {
- m_weight = std::max(std::min((value + 50) / 100, static_cast<int>(std::numeric_limits<uint8_t>::max())), static_cast<int>(std::numeric_limits<uint8_t>::min()));
+ if (auto value = parseIntegerAllowingTrailingJunk<uint16_t>(segment); value && *value >= 0 && *value < 1000) {
+ m_weight = (*value + 50) / 100;
break;
}
}
- auto& fontStyleAttribute = m_fontFaceElement->attributeWithoutSynchronization(SVGNames::font_styleAttr);
- for (auto segment : StringView(fontStyleAttribute).split(' ')) {
+ for (auto segment : StringView(m_fontFaceElement->attributeWithoutSynchronization(SVGNames::font_styleAttr)).split(' ')) {
if (equalLettersIgnoringASCIICase(segment, "italic") || equalLettersIgnoringASCIICase(segment, "oblique")) {
m_italic = true;
break;
Modified: trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp (277244 => 277245)
--- trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -48,6 +48,7 @@
#include <wtf/RobinHoodHashSet.h>
#include <wtf/StdLibExtras.h>
#include <wtf/Vector.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -333,7 +334,7 @@
{
if (data.isNull())
return SMILTime::unresolved();
-
+
String parse = data.stripWhiteSpace();
static MainThreadNeverDestroyed<const AtomString> indefiniteValue("indefinite", AtomString::ConstructFromLiteral);
@@ -344,27 +345,24 @@
bool ok;
size_t doublePointOne = parse.find(':');
size_t doublePointTwo = parse.find(':', doublePointOne + 1);
- if (doublePointOne == 2 && doublePointTwo == 5 && parse.length() >= 8) {
- result += parse.substring(0, 2).toUIntStrict(&ok) * 60 * 60;
- if (!ok)
+ if (doublePointOne == 2 && doublePointTwo == 5 && parse.length() >= 8) {
+ auto hour = parseInteger<uint8_t>(StringView { parse }.substring(0, 2));
+ auto minute = parseInteger<uint8_t>(StringView { parse }.substring(3, 2));
+ if (!hour || !minute)
return SMILTime::unresolved();
- result += parse.substring(3, 2).toUIntStrict(&ok) * 60;
- if (!ok)
- return SMILTime::unresolved();
- result += parse.substring(6).toDouble(&ok);
+ result = *hour * 60 * 60 + *minute * 60 + parse.substring(6).toDouble(&ok);
} else if (doublePointOne == 2 && doublePointTwo == notFound && parse.length() >= 5) {
- result += parse.substring(0, 2).toUIntStrict(&ok) * 60;
- if (!ok)
+ auto minute = parseInteger<uint8_t>(StringView { parse }.substring(0, 2));
+ if (!minute)
return SMILTime::unresolved();
- result += parse.substring(3).toDouble(&ok);
+ result = *minute * 60 + parse.substring(3).toDouble(&ok);
} else
return parseOffsetValue(parse);
-
if (!ok || !SMILTime(result).isFinite())
return SMILTime::unresolved();
return result;
}
-
+
static void sortTimeList(Vector<SMILTimeWithOrigin>& timeList)
{
std::sort(timeList.begin(), timeList.end());
@@ -375,7 +373,6 @@
String parseString = value.stripWhiteSpace();
double sign = 1.;
- bool ok;
size_t pos = parseString.find('+');
if (pos == notFound) {
pos = parseString.find('-');
@@ -412,12 +409,13 @@
Condition::Type type;
int repeats = -1;
if (nameString.startsWith("repeat(") && nameString.endsWith(')')) {
- // FIXME: For repeat events we just need to add the data carrying TimeEvent class and
- // fire the events at appropiate times.
- repeats = nameString.substring(7, nameString.length() - 8).toUIntStrict(&ok);
- if (!ok)
+ // FIXME: For repeat events we just need to add the data carrying TimeEvent class and fire the events at appropiate times.
+ auto parsedRepeat = parseInteger<unsigned>(StringView { nameString }.substring(7, nameString.length() - 8));
+ if (!parsedRepeat)
return false;
- nameString = "repeat";
+ // FIXME: By assigning an unsigned to a signed, this can turn large integers into negative numbers.
+ repeats = *parsedRepeat;
+ nameString = "repeat"_s;
type = Condition::EventBase;
} else if (nameString == "begin" || nameString == "end") {
if (baseID.isEmpty())
Modified: trunk/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.cpp (277244 => 277245)
--- trunk/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -28,6 +28,7 @@
#include "RenderElement.h"
#include "SVGElement.h"
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -44,4 +45,9 @@
return { };
}
+Optional<float> SVGAnimationIntegerFunction::calculateDistance(SVGElement*, const String& from, const String& to) const
+{
+ return std::abs(parseInteger<int>(to).valueOr(0) - parseInteger<int>(from).valueOr(0));
}
+
+}
Modified: trunk/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.h (277244 => 277245)
--- trunk/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.h 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.h 2021-05-09 18:22:23 UTC (rev 277245)
@@ -126,7 +126,7 @@
static Color colorFromString(SVGElement*, const String&);
};
-class SVGAnimationIntegerFunction : public SVGAnimationAdditiveValueFunction<int> {
+class SVGAnimationIntegerFunction final : public SVGAnimationAdditiveValueFunction<int> {
friend class SVGAnimatedIntegerPairAnimator;
public:
@@ -139,7 +139,7 @@
m_to = SVGPropertyTraits<int>::fromString(to);
}
- void setToAtEndOfDurationValue(const String& toAtEndOfDuration) override
+ void setToAtEndOfDurationValue(const String& toAtEndOfDuration) final
{
m_toAtEndOfDuration = SVGPropertyTraits<int>::fromString(toAtEndOfDuration);
}
@@ -149,13 +149,10 @@
animated = static_cast<int>(roundf(Base::animate(progress, repeatCount, m_from, m_to, toAtEndOfDuration(), animated)));
}
- Optional<float> calculateDistance(SVGElement*, const String& from, const String& to) const override
- {
- return std::abs(to.toIntStrict() - from.toIntStrict());
- }
+ Optional<float> calculateDistance(SVGElement*, const String&, const String&) const final;
private:
- void addFromAndToValues(SVGElement*) override
+ void addFromAndToValues(SVGElement*) final
{
m_to += m_from;
}
Copied: trunk/Source/WebCore/svg/properties/SVGPropertyTraits.cpp (from rev 277244, trunk/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.cpp) (0 => 277245)
--- trunk/Source/WebCore/svg/properties/SVGPropertyTraits.cpp (rev 0)
+++ trunk/Source/WebCore/svg/properties/SVGPropertyTraits.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -0,0 +1,38 @@
+/*
+ * 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
+ * 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 "SVGPropertyTraits.h"
+
+#include <wtf/text/StringToIntegerConversion.h>
+
+namespace WebCore {
+
+int SVGPropertyTraits<int>::fromString(const String& string)
+{
+ return parseInteger<int>(string).valueOr(0);
+}
+
+}
Modified: trunk/Source/WebCore/svg/properties/SVGPropertyTraits.h (277244 => 277245)
--- trunk/Source/WebCore/svg/properties/SVGPropertyTraits.h 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/svg/properties/SVGPropertyTraits.h 2021-05-09 18:22:23 UTC (rev 277245)
@@ -66,7 +66,7 @@
template<>
struct SVGPropertyTraits<int> {
static int initialValue() { return 0; }
- static int fromString(const String&string) { return string.toIntStrict(); }
+ static int fromString(const String&);
static Optional<int> parse(const QualifiedName&, const String&) { ASSERT_NOT_REACHED(); return initialValue(); }
static String toString(int type) { return String::number(type); }
};
Added: trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.cpp (0 => 277245)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.cpp (rev 0)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -0,0 +1,54 @@
+/*
+ * 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
+ * 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 "ServiceWorkerClientIdentifier.h"
+
+#if ENABLE(SERVICE_WORKER)
+
+#include <wtf/text/StringConcatenateNumbers.h>
+#include <wtf/text/StringToIntegerConversion.h>
+
+namespace WebCore {
+
+Optional<ServiceWorkerClientIdentifier> ServiceWorkerClientIdentifier::fromString(StringView string)
+{
+ ServiceWorkerClientIdentifier clientIdentifier;
+ unsigned counter = 0;
+ for (auto item : string.split('-')) {
+ auto identifier = parseInteger<uint64_t>(item);
+ if (!identifier || !*identifier)
+ return WTF::nullopt;
+ if (!counter++)
+ clientIdentifier.serverConnectionIdentifier = makeObjectIdentifier<SWServerConnectionIdentifierType>(identifier.value());
+ else if (counter == 2)
+ clientIdentifier.contextIdentifier = makeObjectIdentifier<DocumentIdentifierType>(identifier.value());
+ }
+ return (counter == 2) ? makeOptional(WTFMove(clientIdentifier)) : WTF::nullopt;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h (277244 => 277245)
--- trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h 2021-05-09 18:22:23 UTC (rev 277245)
@@ -30,7 +30,6 @@
#include "DocumentIdentifier.h"
#include "ServiceWorkerTypes.h"
#include <wtf/Hasher.h>
-#include <wtf/text/StringConcatenateNumbers.h>
namespace WebCore {
@@ -49,26 +48,9 @@
inline bool operator==(const ServiceWorkerClientIdentifier& a, const ServiceWorkerClientIdentifier& b)
{
- return a.serverConnectionIdentifier == b.serverConnectionIdentifier && a.contextIdentifier == b.contextIdentifier;
+ return a.serverConnectionIdentifier == b.serverConnectionIdentifier && a.contextIdentifier == b.contextIdentifier;
}
-inline Optional<ServiceWorkerClientIdentifier> ServiceWorkerClientIdentifier::fromString(StringView string)
-{
- ServiceWorkerClientIdentifier clientIdentifier;
-
- unsigned counter = 0;
- for (auto item : string.split('-')) {
- auto identifier = item.toUInt64Strict();
- if (!identifier || !*identifier)
- return WTF::nullopt;
- if (!counter++)
- clientIdentifier.serverConnectionIdentifier = makeObjectIdentifier<SWServerConnectionIdentifierType>(identifier.value());
- else if (counter == 2)
- clientIdentifier.contextIdentifier = makeObjectIdentifier<DocumentIdentifierType>(identifier.value());
- }
- return (counter == 2) ? makeOptional(WTFMove(clientIdentifier)) : WTF::nullopt;
-}
-
template<class Encoder>
void ServiceWorkerClientIdentifier::encode(Encoder& encoder) const
{
@@ -96,10 +78,6 @@
return computeHash(serverConnectionIdentifier, contextIdentifier);
}
-} // namespace WebCore
-
-namespace WTF {
-
struct ServiceWorkerClientIdentifierHash {
static unsigned hash(const WebCore::ServiceWorkerClientIdentifier& key) { return key.hash(); }
static bool equal(const WebCore::ServiceWorkerClientIdentifier& a, const WebCore::ServiceWorkerClientIdentifier& b) { return a == b; }
@@ -106,15 +84,17 @@
static const bool safeToCompareToEmptyOrDeleted = true;
};
+} // namespace WebCore
+
+namespace WTF {
+
template<> struct HashTraits<WebCore::ServiceWorkerClientIdentifier> : GenericHashTraits<WebCore::ServiceWorkerClientIdentifier> {
static WebCore::ServiceWorkerClientIdentifier emptyValue() { return { }; }
-
static void constructDeletedValue(WebCore::ServiceWorkerClientIdentifier& slot) { new (NotNull, &slot.serverConnectionIdentifier) WebCore::SWServerConnectionIdentifier(HashTableDeletedValue); }
-
static bool isDeletedValue(const WebCore::ServiceWorkerClientIdentifier& slot) { return slot.serverConnectionIdentifier.isHashTableDeletedValue(); }
};
-template<> struct DefaultHash<WebCore::ServiceWorkerClientIdentifier> : ServiceWorkerClientIdentifierHash { };
+template<> struct DefaultHash<WebCore::ServiceWorkerClientIdentifier> : WebCore::ServiceWorkerClientIdentifierHash { };
}
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp (277244 => 277245)
--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp 2021-05-09 09:52:48 UTC (rev 277244)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp 2021-05-09 18:22:23 UTC (rev 277245)
@@ -30,6 +30,7 @@
#include "SecurityOrigin.h"
#include <wtf/URLHash.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebCore {
@@ -107,20 +108,9 @@
// If there's a gap between third and second, we expect to have a port to decode
if (third - second > 1) {
- bool ok;
- unsigned port;
- if (key.is8Bit())
- port = charactersToUIntStrict(key.characters8() + second + 1, third - second - 1 , &ok);
- else
- port = charactersToUIntStrict(key.characters16() + second + 1, third - second - 1, &ok);
-
- if (!ok)
+ shortPort = parseInteger<uint16_t>(StringView { key }.substring(second + 1, third - second - 1));
+ if (!shortPort)
return WTF::nullopt;
-
- if (port > std::numeric_limits<uint16_t>::max())
- return WTF::nullopt;
-
- shortPort = static_cast<uint16_t>(port);
}
auto scope = URL { URL(), key.substring(third + 1) };