Specify fixed precision explicitly to prepare to change String::number and StringBuil...
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Mar 2019 17:11:13 +0000 (17:11 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Mar 2019 17:11:13 +0000 (17:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195533

Reviewed by Brent Fulgham.

Source/JavaScriptCore:

* API/tests/ExecutionTimeLimitTest.cpp:
(testExecutionTimeLimit): Use appendFixedPrecisionNumber.
* runtime/NumberPrototype.cpp:
(JSC::numberProtoFuncToPrecision): Use numberToStringFixedPrecision.
* runtime/Options.cpp:
(JSC::Option::dump const): Use appendFixedPrecisionNumber.

Source/WebCore:

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::changeValueByStep): Use numberToStringFixedPrecision.
(WebCore::AccessibilityNodeObject::changeValueByPercent): Ditto.
* accessibility/AccessibilityScrollbar.cpp:
(WebCore::AccessibilityScrollbar::setValue): Ditto.
* css/CSSFontVariationValue.cpp:
(WebCore::CSSFontVariationValue::customCSSText const): Use appendFixedPrecisionNumber.
* css/CSSGradientValue.cpp:
(WebCore::CSSLinearGradientValue::customCSSText const): Ditto.
(WebCore::CSSRadialGradientValue::customCSSText const): Ditto.
* css/CSSKeyframeRule.cpp:
(WebCore::StyleRuleKeyframe::keyText const): Ditto.
* css/CSSTimingFunctionValue.cpp:
(WebCore::CSSCubicBezierTimingFunctionValue::customCSSText const): Ditto.
(WebCore::CSSSpringTimingFunctionValue::customCSSText const): Ditto.
* css/parser/CSSParserToken.cpp:
(WebCore::CSSParserToken::serialize const): Ditto.
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::completeURLsInAttributeValue const): Ditto.
* inspector/InspectorOverlay.cpp:
(WebCore::InspectorOverlay::drawRulers): Use numberToStringFixedPrecision.
* loader/ResourceLoadStatistics.cpp:
(WebCore::ResourceLoadStatistics::toString const): Use appendFixedPrecisionNumber.
* page/PrintContext.cpp:
(WebCore::PrintContext::pageProperty): Use numberToStringFixedPrecision.
* page/cocoa/ResourceUsageOverlayCocoa.mm:
(WebCore::gcTimerString): Use numberToStringFixedPrecision.
* platform/LayoutUnit.h:
(WTF::ValueToString<WebCore::LayoutUnit>::string): Ditto.
* platform/graphics/Color.cpp:
(WebCore::Color::cssText const): Use appendFixedPrecisionNumber.
* platform/graphics/ExtendedColor.cpp:
(WebCore::ExtendedColor::cssText const): Ditto.
* svg/SVGAngleValue.cpp:
(WebCore::SVGAngleValue::valueAsString const): Use numberToStringFixedPrecision.
* svg/SVGNumberListValues.cpp:
(WebCore::SVGNumberListValues::valueAsString const): Use appendFixedPrecisionNumber.
* svg/SVGPathStringBuilder.cpp:
(WebCore::appendNumber): Ditto.
(WebCore::appendPoint): Ditto.
* svg/SVGPointListValues.cpp:
(WebCore::SVGPointListValues::valueAsString const): Ditto.
* svg/SVGTransformValue.cpp:
(WebCore::SVGTransformValue::valueAsString const): Ditto.
* svg/properties/SVGPropertyTraits.h:
(WebCore::SVGPropertyTraits<float>::toString): Use numberToStringFixedPrecision.
(WebCore::SVGPropertyTraits<FloatPoint>::toString): Use appendFixedPrecisionNumber.
(WebCore::SVGPropertyTraits<FloatRect>::toString): Ditto.
* testing/Internals.cpp:
(WebCore::Internals::dumpMarkerRects): Use appendFixedPrecisionNumber.
(WebCore::Internals::getCurrentCursorInfo): Ditto.
* xml/XPathValue.cpp:
(WebCore::XPath::Value::toString const): Use numberToStringFixedPrecision.

Source/WebKit:

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::dumpContentsToFile): Use appendFixedPrecisionNumber.
* NetworkProcess/cache/NetworkCacheEntry.cpp:
(WebKit::NetworkCache::Entry::asJSON const): Ditto.
* Shared/Gamepad/GamepadData.cpp:
(WebKit::GamepadData::loggingString const): Ditto.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::logDiagnosticMessageWithValue): Use numberToStringFixedPrecision.

Source/WTF:

Soon, we will change String::number and StringBuilder::appendNumber for floating
point to use "shortest form" serialization instead of the current default, which is
"6-digit fixed precision stripping trailing zeros". To prepare to do this safely
without accidentally changing any behavior, changing callers to call the explicit
versions. Later, we may want to return and change many of them to use shortest form
instead, but that may require rebaselining tests, and in some extreme cases, getting
rid of flawed logic that converts between different single and double precision
floating point; such problems may be hidden by fixed precision serialization.

Since "shortest form" is already the behavior for AtomicString::number and
for makeString, no changes required for clients of either of those.

* wtf/Logger.h:
(WTF::LogArgument::toString): Use numberToStringFixedPrecision.
* wtf/MediaTime.cpp:
(WTF::MediaTime::toString const): Use appendFixedPrecisionNumber.
* wtf/text/ValueToString.h:
(WTF::ValueToString<float>::string): Use numberToStringFixedPrecision.
(WTF::ValueToString<double>::string): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242713 268f45cc-cd09-0410-ab3c-d52691b4dbfc

37 files changed:
Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.cpp
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/NumberPrototype.cpp
Source/JavaScriptCore/runtime/Options.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/Logger.h
Source/WTF/wtf/MediaTime.cpp
Source/WTF/wtf/text/ValueToString.h
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Source/WebCore/accessibility/AccessibilityScrollbar.cpp
Source/WebCore/css/CSSFontVariationValue.cpp
Source/WebCore/css/CSSGradientValue.cpp
Source/WebCore/css/CSSKeyframeRule.cpp
Source/WebCore/css/CSSTimingFunctionValue.cpp
Source/WebCore/css/parser/CSSParserToken.cpp
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/inspector/InspectorOverlay.cpp
Source/WebCore/loader/ResourceLoadStatistics.cpp
Source/WebCore/page/PrintContext.cpp
Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm
Source/WebCore/platform/LayoutUnit.h
Source/WebCore/platform/graphics/Color.cpp
Source/WebCore/platform/graphics/ExtendedColor.cpp
Source/WebCore/svg/SVGAngleValue.cpp
Source/WebCore/svg/SVGNumberListValues.cpp
Source/WebCore/svg/SVGPathStringBuilder.cpp
Source/WebCore/svg/SVGPointListValues.cpp
Source/WebCore/svg/SVGTransformValue.cpp
Source/WebCore/svg/properties/SVGPropertyTraits.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/xml/XPathValue.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/NetworkCache.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheEntry.cpp
Source/WebKit/Shared/Gamepad/GamepadData.cpp
Source/WebKit/UIProcess/WebPageProxy.cpp

index ac8010a..9c86700 100644 (file)
@@ -194,7 +194,7 @@ int testExecutionTimeLimit()
 
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
+            scriptBuilder.appendFixedPrecisionNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral(") break; } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
@@ -235,7 +235,7 @@ int testExecutionTimeLimit()
                                      "'use strict';"
                                      "if (i % 1000 === 0) {"
                                         "if (currentCPUTime() - startTime >");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
+            scriptBuilder.appendFixedPrecisionNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral("       ) { return; }");
             scriptBuilder.appendLiteral("    }");
             scriptBuilder.appendLiteral("    return recurse(i + 1); }");
@@ -275,7 +275,7 @@ int testExecutionTimeLimit()
             
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); try { while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
+            scriptBuilder.appendFixedPrecisionNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral(") break; } } catch(e) { } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
@@ -314,7 +314,7 @@ int testExecutionTimeLimit()
             
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
+            scriptBuilder.appendFixedPrecisionNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral(") break; } } foo();");
             
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
@@ -353,7 +353,7 @@ int testExecutionTimeLimit()
             
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
+            scriptBuilder.appendFixedPrecisionNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral(") break; } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
@@ -392,7 +392,7 @@ int testExecutionTimeLimit()
 
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(maxBusyLoopTime.seconds()); // in seconds.
+            scriptBuilder.appendFixedPrecisionNumber(maxBusyLoopTime.seconds()); // in seconds.
             scriptBuilder.appendLiteral(") break; } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
@@ -435,7 +435,7 @@ int testExecutionTimeLimit()
 
             StringBuilder scriptBuilder;
             scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
-            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired.seconds());
+            scriptBuilder.appendFixedPrecisionNumber(timeAfterWatchdogShouldHaveFired.seconds());
             scriptBuilder.appendLiteral(") break; } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
index 142fa4b..de331db 100644 (file)
@@ -1,3 +1,17 @@
+2019-03-11  Darin Adler  <darin@apple.com>
+
+        Specify fixed precision explicitly to prepare to change String::number and StringBuilder::appendNumber floating point behavior
+        https://bugs.webkit.org/show_bug.cgi?id=195533
+
+        Reviewed by Brent Fulgham.
+
+        * API/tests/ExecutionTimeLimitTest.cpp:
+        (testExecutionTimeLimit): Use appendFixedPrecisionNumber.
+        * runtime/NumberPrototype.cpp:
+        (JSC::numberProtoFuncToPrecision): Use numberToStringFixedPrecision.
+        * runtime/Options.cpp:
+        (JSC::Option::dump const): Use appendFixedPrecisionNumber.
+
 2019-03-10  Ross Kirsling  <ross.kirsling@sony.com>
 
         Invalid flags in a RegExp literal should be an early SyntaxError
index 04d98e6..ab3afd0 100644 (file)
@@ -505,7 +505,7 @@ EncodedJSValue JSC_HOST_CALL numberProtoFuncToPrecision(ExecState* exec)
     if (!inRange)
         return throwVMError(exec, scope, createRangeError(exec, "toPrecision() argument must be between 1 and 21"_s));
 
-    return JSValue::encode(jsString(exec, String::number(x, significantFigures, KeepTrailingZeros)));
+    return JSValue::encode(jsString(exec, String::numberToStringFixedPrecision(x, significantFigures, KeepTrailingZeros)));
 }
 
 static ALWAYS_INLINE JSString* int32ToStringInternal(VM& vm, int32_t value, int32_t radix)
index b9e972d..3c31deb 100644 (file)
@@ -906,7 +906,7 @@ void Option::dump(StringBuilder& builder) const
         builder.appendNumber(m_entry.sizeVal);
         break;
     case Options::Type::doubleType:
-        builder.appendNumber(m_entry.doubleVal);
+        builder.appendFixedPrecisionNumber(m_entry.doubleVal);
         break;
     case Options::Type::int32Type:
         builder.appendNumber(m_entry.int32Val);
index 2247b2d..b46a186 100644 (file)
@@ -1,3 +1,30 @@
+2019-03-11  Darin Adler  <darin@apple.com>
+
+        Specify fixed precision explicitly to prepare to change String::number and StringBuilder::appendNumber floating point behavior
+        https://bugs.webkit.org/show_bug.cgi?id=195533
+
+        Reviewed by Brent Fulgham.
+
+        Soon, we will change String::number and StringBuilder::appendNumber for floating
+        point to use "shortest form" serialization instead of the current default, which is
+        "6-digit fixed precision stripping trailing zeros". To prepare to do this safely
+        without accidentally changing any behavior, changing callers to call the explicit
+        versions. Later, we may want to return and change many of them to use shortest form
+        instead, but that may require rebaselining tests, and in some extreme cases, getting
+        rid of flawed logic that converts between different single and double precision
+        floating point; such problems may be hidden by fixed precision serialization.
+
+        Since "shortest form" is already the behavior for AtomicString::number and
+        for makeString, no changes required for clients of either of those.
+
+        * wtf/Logger.h:
+        (WTF::LogArgument::toString): Use numberToStringFixedPrecision.
+        * wtf/MediaTime.cpp:
+        (WTF::MediaTime::toString const): Use appendFixedPrecisionNumber.
+        * wtf/text/ValueToString.h:
+        (WTF::ValueToString<float>::string): Use numberToStringFixedPrecision.
+        (WTF::ValueToString<double>::string): Ditto.
+
 2019-03-11  Truitt Savell  <tsavell@apple.com>
 
         Unreviewed, rolling out r242702.
index b0cdbf8..436e9e6 100644 (file)
@@ -36,8 +36,8 @@ struct LogArgument {
     template<typename U = T> static typename std::enable_if<std::is_same<U, unsigned>::value, String>::type toString(unsigned argument) { return String::number(argument); }
     template<typename U = T> static typename std::enable_if<std::is_same<U, unsigned long>::value, String>::type toString(unsigned long argument) { return String::number(argument); }
     template<typename U = T> static typename std::enable_if<std::is_same<U, long>::value, String>::type toString(long argument) { return String::number(argument); }
-    template<typename U = T> static typename std::enable_if<std::is_same<U, float>::value, String>::type toString(float argument) { return String::number(argument); }
-    template<typename U = T> static typename std::enable_if<std::is_same<U, double>::value, String>::type toString(double argument) { return String::number(argument); }
+    template<typename U = T> static typename std::enable_if<std::is_same<U, float>::value, String>::type toString(float argument) { return String::numberToStringFixedPrecision(argument); }
+    template<typename U = T> static typename std::enable_if<std::is_same<U, double>::value, String>::type toString(double argument) { return String::numberToStringFixedPrecision(argument); }
     template<typename U = T> static typename std::enable_if<std::is_same<typename std::remove_reference<U>::type, AtomicString>::value, String>::type toString(const AtomicString& argument) { return argument.string(); }
     template<typename U = T> static typename std::enable_if<std::is_same<typename std::remove_reference<U>::type, String>::value, String>::type toString(String argument) { return argument; }
     template<typename U = T> static typename std::enable_if<std::is_same<typename std::remove_reference<U>::type, StringBuilder*>::value, String>::type toString(StringBuilder* argument) { return argument->toString(); }
index 87c7fbd..b72cec7 100644 (file)
@@ -593,7 +593,7 @@ String MediaTime::toString() const
         builder.appendNumber(m_timeScale);
         builder.appendLiteral(" = ");
     }
-    builder.appendNumber(toDouble());
+    builder.appendFixedPrecisionNumber(toDouble());
     builder.append('}');
     return builder.toString();
 }
index 7a396a6..c1ef993 100644 (file)
 
 namespace WTF {
 
-template<class T>
-struct ValueToString;
+template<typename> struct ValueToString;
 
-template <>
-struct ValueToString<int> {
-    static String string(const int value) { return String::number(value); }
+template<> struct ValueToString<int> {
+    static String string(int value) { return String::number(value); }
 };
 
-template <>
-struct ValueToString<float> {
-    static String string(const float value) { return String::number(value); }
+template<> struct ValueToString<float> {
+    static String string(float value) { return String::numberToStringFixedPrecision(value); }
 };
 
-template <>
-struct ValueToString<double> {
-    static String string(const double value) { return String::number(value); }
+template<> struct ValueToString<double> {
+    static String string(double value) { return String::numberToStringFixedPrecision(value); }
 };
 
 } // namespace WTF
index 043c9d6..e09f8e7 100644 (file)
@@ -1,3 +1,64 @@
+2019-03-11  Darin Adler  <darin@apple.com>
+
+        Specify fixed precision explicitly to prepare to change String::number and StringBuilder::appendNumber floating point behavior
+        https://bugs.webkit.org/show_bug.cgi?id=195533
+
+        Reviewed by Brent Fulgham.
+
+        * accessibility/AccessibilityNodeObject.cpp:
+        (WebCore::AccessibilityNodeObject::changeValueByStep): Use numberToStringFixedPrecision.
+        (WebCore::AccessibilityNodeObject::changeValueByPercent): Ditto.
+        * accessibility/AccessibilityScrollbar.cpp:
+        (WebCore::AccessibilityScrollbar::setValue): Ditto.
+        * css/CSSFontVariationValue.cpp:
+        (WebCore::CSSFontVariationValue::customCSSText const): Use appendFixedPrecisionNumber.
+        * css/CSSGradientValue.cpp:
+        (WebCore::CSSLinearGradientValue::customCSSText const): Ditto.
+        (WebCore::CSSRadialGradientValue::customCSSText const): Ditto.
+        * css/CSSKeyframeRule.cpp:
+        (WebCore::StyleRuleKeyframe::keyText const): Ditto.
+        * css/CSSTimingFunctionValue.cpp:
+        (WebCore::CSSCubicBezierTimingFunctionValue::customCSSText const): Ditto.
+        (WebCore::CSSSpringTimingFunctionValue::customCSSText const): Ditto.
+        * css/parser/CSSParserToken.cpp:
+        (WebCore::CSSParserToken::serialize const): Ditto.
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::completeURLsInAttributeValue const): Ditto.
+        * inspector/InspectorOverlay.cpp:
+        (WebCore::InspectorOverlay::drawRulers): Use numberToStringFixedPrecision.
+        * loader/ResourceLoadStatistics.cpp:
+        (WebCore::ResourceLoadStatistics::toString const): Use appendFixedPrecisionNumber.
+        * page/PrintContext.cpp:
+        (WebCore::PrintContext::pageProperty): Use numberToStringFixedPrecision.
+        * page/cocoa/ResourceUsageOverlayCocoa.mm:
+        (WebCore::gcTimerString): Use numberToStringFixedPrecision.
+        * platform/LayoutUnit.h:
+        (WTF::ValueToString<WebCore::LayoutUnit>::string): Ditto.
+        * platform/graphics/Color.cpp:
+        (WebCore::Color::cssText const): Use appendFixedPrecisionNumber.
+        * platform/graphics/ExtendedColor.cpp:
+        (WebCore::ExtendedColor::cssText const): Ditto.
+        * svg/SVGAngleValue.cpp:
+        (WebCore::SVGAngleValue::valueAsString const): Use numberToStringFixedPrecision.
+        * svg/SVGNumberListValues.cpp:
+        (WebCore::SVGNumberListValues::valueAsString const): Use appendFixedPrecisionNumber.
+        * svg/SVGPathStringBuilder.cpp:
+        (WebCore::appendNumber): Ditto.
+        (WebCore::appendPoint): Ditto.
+        * svg/SVGPointListValues.cpp:
+        (WebCore::SVGPointListValues::valueAsString const): Ditto.
+        * svg/SVGTransformValue.cpp:
+        (WebCore::SVGTransformValue::valueAsString const): Ditto.
+        * svg/properties/SVGPropertyTraits.h:
+        (WebCore::SVGPropertyTraits<float>::toString): Use numberToStringFixedPrecision.
+        (WebCore::SVGPropertyTraits<FloatPoint>::toString): Use appendFixedPrecisionNumber.
+        (WebCore::SVGPropertyTraits<FloatRect>::toString): Ditto.
+        * testing/Internals.cpp:
+        (WebCore::Internals::dumpMarkerRects): Use appendFixedPrecisionNumber.
+        (WebCore::Internals::getCurrentCursorInfo): Ditto.
+        * xml/XPathValue.cpp:
+        (WebCore::XPath::Value::toString const): Use numberToStringFixedPrecision.
+
 2019-03-11  Philippe Normand  <pnormand@igalia.com>
 
         Unreviewed, Non-GStreamer-GL build fix after r242701.
index d6ff0a5..c76c77e 100644 (file)
@@ -1098,7 +1098,7 @@ void AccessibilityNodeObject::changeValueByStep(bool increase)
 
     value += increase ? step : -step;
 
-    setValue(String::number(value));
+    setValue(String::numberToStringFixedPrecision(value));
 
     axObjectCache()->postNotification(node(), AXObjectCache::AXValueChanged);
 }
@@ -1110,11 +1110,11 @@ void AccessibilityNodeObject::changeValueByPercent(float percentChange)
     float value = valueForRange();
 
     // Make sure the specified percent will cause a change of one integer step or larger.
-    if (fabs(step) < 1)
-        step = fabs(percentChange) * (1 / percentChange);
+    if (std::abs(step) < 1)
+        step = std::abs(percentChange) * (1 / percentChange);
 
     value += step;
-    setValue(String::number(value));
+    setValue(String::numberToStringFixedPrecision(value));
 
     axObjectCache()->postNotification(node(), AXObjectCache::AXValueChanged);
 }
index 1919c5f..32eea2c 100644 (file)
@@ -98,7 +98,7 @@ void AccessibilityScrollbar::setValue(float value)
         return;
     
     float newValue = value * m_scrollbar->maximum();
-    if (dispatchAccessibleSetValueEvent(String::number(newValue)))
+    if (dispatchAccessibleSetValueEvent(String::numberToStringFixedPrecision(newValue)))
         return;
     m_scrollbar->scrollableArea().scrollToOffsetWithoutAnimation(m_scrollbar->orientation(), newValue);
 }
index 72ddc1a..9fcd0b1 100644 (file)
@@ -47,7 +47,7 @@ String CSSFontVariationValue::customCSSText() const
     for (char c : m_tag)
         builder.append(c);
     builder.appendLiteral("\" ");
-    builder.appendNumber(m_value);
+    builder.appendFixedPrecisionNumber(m_value);
     return builder.toString();
 }
 
index 898b1e2..6b0f91d 100644 (file)
@@ -693,7 +693,7 @@ String CSSLinearGradientValue::customCSSText() const
                 result.append(')');
             } else {
                 result.appendLiteral("color-stop(");
-                result.appendNumber(position);
+                result.appendFixedPrecisionNumber(position);
                 result.appendLiteral(", ");
                 result.append(stop.m_color->cssText());
                 result.append(')');
@@ -974,7 +974,7 @@ String CSSRadialGradientValue::customCSSText() const
                 result.append(')');
             } else {
                 result.appendLiteral("color-stop(");
-                result.appendNumber(position);
+                result.appendFixedPrecisionNumber(position);
                 result.appendLiteral(", ");
                 result.append(stop.m_color->cssText());
                 result.append(')');
index 81e9958..9dd5938 100644 (file)
@@ -63,7 +63,7 @@ String StyleRuleKeyframe::keyText() const
     for (size_t i = 0; i < m_keys.size(); ++i) {
         if (i)
             keyText.append(',');
-        keyText.appendNumber(m_keys.at(i) * 100);
+        keyText.appendFixedPrecisionNumber(m_keys.at(i) * 100);
         keyText.append('%');
     }
 
index 2dd6195..65bae81 100644 (file)
@@ -34,13 +34,13 @@ String CSSCubicBezierTimingFunctionValue::customCSSText() const
 {
     StringBuilder builder;
     builder.appendLiteral("cubic-bezier(");
-    builder.appendNumber(m_x1);
+    builder.appendFixedPrecisionNumber(m_x1);
     builder.appendLiteral(", ");
-    builder.appendNumber(m_y1);
+    builder.appendFixedPrecisionNumber(m_y1);
     builder.appendLiteral(", ");
-    builder.appendNumber(m_x2);
+    builder.appendFixedPrecisionNumber(m_x2);
     builder.appendLiteral(", ");
-    builder.appendNumber(m_y2);
+    builder.appendFixedPrecisionNumber(m_y2);
     builder.append(')');    
     return builder.toString();
 }
@@ -71,13 +71,13 @@ String CSSSpringTimingFunctionValue::customCSSText() const
 {
     StringBuilder builder;
     builder.appendLiteral("spring(");
-    builder.appendNumber(m_mass);
+    builder.appendFixedPrecisionNumber(m_mass);
     builder.append(' ');
-    builder.appendNumber(m_stiffness);
+    builder.appendFixedPrecisionNumber(m_stiffness);
     builder.append(' ');
-    builder.appendNumber(m_damping);
+    builder.appendFixedPrecisionNumber(m_damping);
     builder.append(' ');
-    builder.appendNumber(m_initialVelocity);
+    builder.appendFixedPrecisionNumber(m_initialVelocity);
     builder.append(')');
     return builder.toString();
 }
index a1135aa..bf69cd4 100644 (file)
@@ -419,15 +419,15 @@ void CSSParserToken::serialize(StringBuilder& builder) const
         // These won't properly preserve the NumericValueType flag
         if (m_numericSign == PlusSign)
             builder.append('+');
-        builder.appendNumber(numericValue());
+        builder.appendFixedPrecisionNumber(numericValue());
         break;
     case PercentageToken:
-        builder.appendNumber(numericValue());
+        builder.appendFixedPrecisionNumber(numericValue());
         builder.append('%');
         break;
     case DimensionToken:
         // This will incorrectly serialize e.g. 4e3e2 as 4000e2
-        builder.appendNumber(numericValue());
+        builder.appendFixedPrecisionNumber(numericValue());
         serializeIdentifier(value().toString(), builder);
         break;
     case UnicodeRangeToken:
index 5cc8b39..81a92e5 100644 (file)
@@ -551,7 +551,7 @@ String HTMLImageElement::completeURLsInAttributeValue(const URL& base, const Att
             result.append(URL(base, candidate.string.toString()).string());
             if (candidate.density != UninitializedDescriptor) {
                 result.append(' ');
-                result.appendNumber(candidate.density);
+                result.appendFixedPrecisionNumber(candidate.density);
                 result.append('x');
             }
             if (candidate.resourceWidth != UninitializedDescriptor) {
index 9bad9c3..c1bb55a 100644 (file)
@@ -782,7 +782,7 @@ void InspectorOverlay::drawRulers(GraphicsContext& context)
 
                 GraphicsContextStateSaver verticalLabelStateSaver(context);
                 context.translate(zoom(x) + 0.5f, scrollY);
-                context.drawText(font, TextRun(String::number(x)), { 2, rulerLabelSize });
+                context.drawText(font, TextRun(String::numberToStringFixedPrecision(x)), { 2, rulerLabelSize });
             }
 
             for (float y = multipleBelow(minY, rulerStepIncrement * 2); y < maxY; y += rulerStepIncrement * 2) {
@@ -792,7 +792,7 @@ void InspectorOverlay::drawRulers(GraphicsContext& context)
                 GraphicsContextStateSaver horizontalLabelStateSaver(context);
                 context.translate(scrollX, zoom(y) + 0.5f);
                 context.rotate(-piOverTwoFloat);
-                context.drawText(font, TextRun(String::number(y)), { 2, rulerLabelSize });
+                context.drawText(font, TextRun(String::numberToStringFixedPrecision(y)), { 2, rulerLabelSize });
             }
         }
     }
index 8fe5dd0..9459776 100644 (file)
@@ -412,14 +412,14 @@ String ResourceLoadStatistics::toString() const
     builder.append(registrableDomain.string());
     builder.append('\n');
     builder.appendLiteral("    lastSeen: ");
-    builder.appendNumber(lastSeen.secondsSinceEpoch().value());
+    builder.appendFixedPrecisionNumber(lastSeen.secondsSinceEpoch().value());
     builder.append('\n');
     
     // User interaction
     appendBoolean(builder, "hadUserInteraction", hadUserInteraction);
     builder.append('\n');
     builder.appendLiteral("    mostRecentUserInteraction: ");
-    builder.appendNumber(mostRecentUserInteractionTime.secondsSinceEpoch().value());
+    builder.appendFixedPrecisionNumber(mostRecentUserInteractionTime.secondsSinceEpoch().value());
     builder.append('\n');
     appendBoolean(builder, "grandfathered", grandfathered);
     builder.append('\n');
index 2c0be46..a3f900f 100644 (file)
@@ -326,10 +326,10 @@ String PrintContext::pageProperty(Frame* frame, const char* propertyName, int pa
     if (!strcmp(propertyName, "margin-left")) {
         if (style->marginLeft().isAuto())
             return "auto"_s;
-        return String::number(style->marginLeft().value());
+        return String::numberToStringFixedPrecision(style->marginLeft().value());
     }
     if (!strcmp(propertyName, "line-height"))
-        return String::number(style->lineHeight().value());
+        return String::numberToStringFixedPrecision(style->lineHeight().value());
     if (!strcmp(propertyName, "font-size"))
         return String::number(style->fontDescription().computedPixelSize());
     if (!strcmp(propertyName, "font-family"))
index 56b65d6..0c8d293 100644 (file)
@@ -439,7 +439,7 @@ static String gcTimerString(MonotonicTime timerFireDate, MonotonicTime now)
 {
     if (std::isnan(timerFireDate))
         return "[not scheduled]"_s;
-    return String::number((timerFireDate - now).seconds());
+    return String::numberToStringFixedPrecision((timerFireDate - now).seconds());
 }
 
 void ResourceUsageOverlay::platformDraw(CGContextRef context)
index c569d85..8e605ed 100644 (file)
@@ -833,12 +833,14 @@ inline LayoutUnit operator"" _lu(unsigned long long value)
 } // namespace WebCore
 
 #ifndef NDEBUG
+
 namespace WTF {
+
 // This structure is used by PODIntervalTree for debugging.
-template <>
-struct ValueToString<WebCore::LayoutUnit> {
-    static String string(const WebCore::LayoutUnit value) { return String::number(value.toFloat()); }
+template<> struct ValueToString<WebCore::LayoutUnit> {
+    static String string(WebCore::LayoutUnit value) { return String::numberToStringFixedPrecision(value.toFloat()); }
 };
 
 } // namespace WTF
+
 #endif
index 93a489e..680a9cb 100644 (file)
@@ -377,7 +377,7 @@ String Color::cssText() const
     builder.appendNumber(static_cast<unsigned char>(blue()));
     if (colorHasAlpha) {
         builder.appendLiteral(", ");
-        builder.appendNumber(alpha() / 255.0f);
+        builder.appendFixedPrecisionNumber(alpha() / 255.0f);
     }
         
     builder.append(')');
index fc27c08..2a3c83e 100644 (file)
@@ -56,16 +56,16 @@ String ExtendedColor::cssText() const
         return WTF::emptyString();
     }
 
-    builder.appendNumber(red());
+    builder.appendFixedPrecisionNumber(red());
     builder.append(' ');
 
-    builder.appendNumber(green());
+    builder.appendFixedPrecisionNumber(green());
     builder.append(' ');
 
-    builder.appendNumber(blue());
+    builder.appendFixedPrecisionNumber(blue());
     if (!WTF::areEssentiallyEqual(alpha(), 1.0f)) {
         builder.appendLiteral(" / ");
-        builder.appendNumber(alpha());
+        builder.appendFixedPrecisionNumber(alpha());
     }
     builder.append(')');
 
index 91f15f6..1ea285f 100644 (file)
@@ -73,7 +73,7 @@ String SVGAngleValue::valueAsString() const
         return makeString(FormattedNumber::fixedPrecision(m_valueInSpecifiedUnits), "grad");
     case SVG_ANGLETYPE_UNSPECIFIED:
     case SVG_ANGLETYPE_UNKNOWN:
-        return String::number(m_valueInSpecifiedUnits);
+        return String::numberToStringFixedPrecision(m_valueInSpecifiedUnits);
     }
 
     ASSERT_NOT_REACHED();
index 6dfd993..c97368b 100644 (file)
@@ -52,7 +52,7 @@ String SVGNumberListValues::valueAsString() const
         if (i > 0)
             builder.append(' ');
 
-        builder.appendNumber(at(i));
+        builder.appendFixedPrecisionNumber(at(i));
     }
 
     return builder.toString();
index 105391c..a832b9f 100644 (file)
@@ -57,15 +57,15 @@ static void appendFlag(StringBuilder& stringBuilder, bool flag)
 
 static void appendNumber(StringBuilder& stringBuilder, float number)
 {
-    stringBuilder.appendNumber(number);
+    stringBuilder.appendFixedPrecisionNumber(number);
     stringBuilder.append(' ');
 }
 
 static void appendPoint(StringBuilder& stringBuilder, const FloatPoint& point)
 {
-    stringBuilder.appendNumber(point.x());
+    stringBuilder.appendFixedPrecisionNumber(point.x());
     stringBuilder.append(' ');
-    stringBuilder.appendNumber(point.y());
+    stringBuilder.appendFixedPrecisionNumber(point.y());
     stringBuilder.append(' ');
 }
 
index d81e6a2..ae66a27 100644 (file)
@@ -36,9 +36,9 @@ String SVGPointListValues::valueAsString() const
             builder.append(' '); // FIXME: Shouldn't we use commas to seperate?
 
         const auto& point = at(i);
-        builder.appendNumber(point.x());
+        builder.appendFixedPrecisionNumber(point.x());
         builder.append(' ');
-        builder.appendNumber(point.y());
+        builder.appendFixedPrecisionNumber(point.y());
     }
 
     return builder.toString();
index 63d45a5..a614ac2 100644 (file)
@@ -167,35 +167,35 @@ String SVGTransformValue::valueAsString() const
     case SVG_TRANSFORM_MATRIX: {
         StringBuilder builder;
         builder.append(prefix);
-        builder.appendNumber(m_matrix.a());
+        builder.appendFixedPrecisionNumber(m_matrix.a());
         builder.append(' ');
-        builder.appendNumber(m_matrix.b());
+        builder.appendFixedPrecisionNumber(m_matrix.b());
         builder.append(' ');
-        builder.appendNumber(m_matrix.c());
+        builder.appendFixedPrecisionNumber(m_matrix.c());
         builder.append(' ');
-        builder.appendNumber(m_matrix.d());
+        builder.appendFixedPrecisionNumber(m_matrix.d());
         builder.append(' ');
-        builder.appendNumber(m_matrix.e());
+        builder.appendFixedPrecisionNumber(m_matrix.e());
         builder.append(' ');
-        builder.appendNumber(m_matrix.f());
+        builder.appendFixedPrecisionNumber(m_matrix.f());
         builder.append(')');
         return builder.toString();
     }
     case SVG_TRANSFORM_TRANSLATE: {
         StringBuilder builder;
         builder.append(prefix);
-        builder.appendNumber(m_matrix.e());
+        builder.appendFixedPrecisionNumber(m_matrix.e());
         builder.append(' ');
-        builder.appendNumber(m_matrix.f());
+        builder.appendFixedPrecisionNumber(m_matrix.f());
         builder.append(')');
         return builder.toString();
     }
     case SVG_TRANSFORM_SCALE: {
         StringBuilder builder;
         builder.append(prefix);
-        builder.appendNumber(m_matrix.xScale());
+        builder.appendFixedPrecisionNumber(m_matrix.xScale());
         builder.append(' ');
-        builder.appendNumber(m_matrix.yScale());
+        builder.appendFixedPrecisionNumber(m_matrix.yScale());
         builder.append(')');
         return builder.toString();
     }
@@ -207,12 +207,12 @@ String SVGTransformValue::valueAsString() const
         float cy = narrowPrecisionToFloat(cosAngle != 1 ? (m_matrix.e() * sinAngle / (1 - cosAngle) + m_matrix.f()) / 2 : 0);
         StringBuilder builder;
         builder.append(prefix);
-        builder.appendNumber(m_angle);
+        builder.appendFixedPrecisionNumber(m_angle);
         if (cx || cy) {
             builder.append(' ');
-            builder.appendNumber(cx);
+            builder.appendFixedPrecisionNumber(cx);
             builder.append(' ');
-            builder.appendNumber(cy);
+            builder.appendFixedPrecisionNumber(cy);
         }
         builder.append(')');
         return builder.toString();
@@ -221,7 +221,7 @@ String SVGTransformValue::valueAsString() const
     case SVG_TRANSFORM_SKEWY: {
         StringBuilder builder;
         builder.append(prefix);
-        builder.appendNumber(m_angle);
+        builder.appendFixedPrecisionNumber(m_angle);
         builder.append(')');
         return builder.toString();
     }
index dfff942..bb83e77 100644 (file)
@@ -103,7 +103,7 @@ struct SVGPropertyTraits<float> {
             return WTF::nullopt;
         return number;
     }
-    static String toString(float type) { return String::number(type); }
+    static String toString(float type) { return String::numberToStringFixedPrecision(type); }
 };
 
 template<>
@@ -140,9 +140,9 @@ struct SVGPropertyTraits<FloatPoint> {
     static String toString(const FloatPoint& type)
     {
         StringBuilder builder;
-        builder.appendNumber(type.x());
+        builder.appendFixedPrecisionNumber(type.x());
         builder.append(' ');
-        builder.appendNumber(type.y());
+        builder.appendFixedPrecisionNumber(type.y());
         return builder.toString();
     }
 };
@@ -167,13 +167,13 @@ struct SVGPropertyTraits<FloatRect> {
     static String toString(const FloatRect& type)
     {
         StringBuilder builder;
-        builder.appendNumber(type.x());
+        builder.appendFixedPrecisionNumber(type.x());
         builder.append(' ');
-        builder.appendNumber(type.y());
+        builder.appendFixedPrecisionNumber(type.y());
         builder.append(' ');
-        builder.appendNumber(type.width());
+        builder.appendFixedPrecisionNumber(type.width());
         builder.append(' ');
-        builder.appendNumber(type.height());
+        builder.appendFixedPrecisionNumber(type.height());
         return builder.toString();
     }
 };
index 730c61f..d39f541 100644 (file)
@@ -1606,13 +1606,13 @@ ExceptionOr<String> Internals::dumpMarkerRects(const String& markerTypeString)
     rectString.appendLiteral("marker rects: ");
     for (const auto& rect : rects) {
         rectString.append('(');
-        rectString.appendNumber(rect.x());
+        rectString.appendFixedPrecisionNumber(rect.x());
         rectString.appendLiteral(", ");
-        rectString.appendNumber(rect.y());
+        rectString.appendFixedPrecisionNumber(rect.y());
         rectString.appendLiteral(", ");
-        rectString.appendNumber(rect.width());
+        rectString.appendFixedPrecisionNumber(rect.width());
         rectString.appendLiteral(", ");
-        rectString.appendNumber(rect.height());
+        rectString.appendFixedPrecisionNumber(rect.height());
         rectString.appendLiteral(") ");
     }
     return rectString.toString();
@@ -3328,14 +3328,14 @@ ExceptionOr<String> Internals::getCurrentCursorInfo()
     if (cursor.image()) {
         FloatSize size = cursor.image()->size();
         result.appendLiteral(" image=");
-        result.appendNumber(size.width());
+        result.appendFixedPrecisionNumber(size.width());
         result.append('x');
-        result.appendNumber(size.height());
+        result.appendFixedPrecisionNumber(size.height());
     }
 #if ENABLE(MOUSE_CURSOR_SCALE)
     if (cursor.imageScaleFactor() != 1) {
         result.appendLiteral(" scale=");
-        result.appendNumber(cursor.imageScaleFactor(), 8);
+        result.appendFixedPrecisionNumber(cursor.imageScaleFactor(), 8);
     }
 #endif
     return result.toString();
index 0605121..a9c9bd3 100644 (file)
@@ -126,7 +126,7 @@ String Value::toString() const
                 return "0"_s;
             if (std::isinf(m_number))
                 return std::signbit(m_number) ? "-Infinity"_s : "Infinity"_s;
-            return String::number(m_number);
+            return String::numberToStringFixedPrecision(m_number);
         case BooleanValue:
             return m_bool ? "true"_s : "false"_s;
     }
index 1473c2a..ccda61a 100644 (file)
@@ -1,3 +1,19 @@
+2019-03-11  Darin Adler  <darin@apple.com>
+
+        Specify fixed precision explicitly to prepare to change String::number and StringBuilder::appendNumber floating point behavior
+        https://bugs.webkit.org/show_bug.cgi?id=195533
+
+        Reviewed by Brent Fulgham.
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::Cache::dumpContentsToFile): Use appendFixedPrecisionNumber.
+        * NetworkProcess/cache/NetworkCacheEntry.cpp:
+        (WebKit::NetworkCache::Entry::asJSON const): Ditto.
+        * Shared/Gamepad/GamepadData.cpp:
+        (WebKit::GamepadData::loggingString const): Ditto.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::logDiagnosticMessageWithValue): Use numberToStringFixedPrecision.
+
 2019-03-11  John Wilander  <wilander@apple.com>
 
         Resource Load Statistics: Make it possible exclude localhost from classification
index ba5c8b2..a6ba2b2 100644 (file)
@@ -549,7 +549,7 @@ void Cache::dumpContentsToFile()
             epilogue.appendNumber(totals.bodySize);
             epilogue.appendLiteral(",\n");
             epilogue.appendLiteral("\"averageWorth\": ");
-            epilogue.appendNumber(totals.count ? totals.worth / totals.count : 0);
+            epilogue.appendFixedPrecisionNumber(totals.count ? totals.worth / totals.count : 0);
             epilogue.appendLiteral("\n");
             epilogue.appendLiteral("}\n}\n");
             auto writeData = epilogue.toString().utf8();
index ea7b3f8..7ae1c2f 100644 (file)
@@ -219,13 +219,13 @@ void Entry::asJSON(StringBuilder& json, const Storage::RecordInfo& info) const
     json.appendNumber(info.bodySize);
     json.appendLiteral(",\n");
     json.appendLiteral("\"worth\": ");
-    json.appendNumber(info.worth);
+    json.appendFixedPrecisionNumber(info.worth);
     json.appendLiteral(",\n");
     json.appendLiteral("\"partition\": ");
     json.appendQuotedJSONString(m_key.partition());
     json.appendLiteral(",\n");
     json.appendLiteral("\"timestamp\": ");
-    json.appendNumber(m_timeStamp.secondsSinceEpoch().milliseconds());
+    json.appendFixedPrecisionNumber(m_timeStamp.secondsSinceEpoch().milliseconds());
     json.appendLiteral(",\n");
     json.appendLiteral("\"URL\": ");
     json.appendQuotedJSONString(m_response.url().string());
index fd0a953..365c102 100644 (file)
@@ -100,7 +100,7 @@ String GamepadData::loggingString() const
         builder.appendLiteral(" Axis ");
         builder.appendNumber(i);
         builder.appendLiteral(": ");
-        builder.appendNumber(m_axisValues[i]);
+        builder.appendFixedPrecisionNumber(m_axisValues[i]);
     }
 
     builder.append('\n');
@@ -108,7 +108,7 @@ String GamepadData::loggingString() const
         builder.appendLiteral(" Button ");
         builder.appendNumber(i);
         builder.appendLiteral(": ");
-        builder.appendNumber(m_buttonValues[i]);
+        builder.appendFixedPrecisionNumber(m_buttonValues[i]);
     }
 
     return builder.toString();
index b369809..92ea590 100644 (file)
@@ -6442,7 +6442,7 @@ void WebPageProxy::logDiagnosticMessageWithValue(const String& message, const St
     if (!effectiveClient)
         return;
 
-    effectiveClient->logDiagnosticMessageWithValue(this, message, description, String::number(value, significantFigures));
+    effectiveClient->logDiagnosticMessageWithValue(this, message, description, String::numberToStringFixedPrecision(value, significantFigures));
 }
 
 void WebPageProxy::logDiagnosticMessageWithEnhancedPrivacy(const String& message, const String& description, ShouldSample shouldSample)