mfbt/decimal/to-moz-dependencies.patch

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mfbt/decimal/to-moz-dependencies.patch	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,219 @@
     1.4 +diff --git a/mfbt/decimal/Decimal.cpp b/mfbt/decimal/Decimal.cpp
     1.5 +--- a/mfbt/decimal/Decimal.cpp
     1.6 ++++ b/mfbt/decimal/Decimal.cpp
     1.7 +@@ -23,26 +23,23 @@
     1.8 +  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     1.9 +  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.10 +  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.11 +  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.12 +  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.13 +  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.14 +  */
    1.15 + 
    1.16 +-#include "config.h"
    1.17 + #include "Decimal.h"
    1.18 ++#include "moz-decimal-utils.h"
    1.19 + 
    1.20 + #include <algorithm>
    1.21 + #include <float.h>
    1.22 + 
    1.23 +-#include <wtf/Assertions.h>
    1.24 +-#include <wtf/MathExtras.h>
    1.25 +-#include <wtf/Noncopyable.h>
    1.26 +-#include <wtf/text/StringBuilder.h>
    1.27 ++using namespace moz_decimal_utils;
    1.28 + 
    1.29 + namespace WebCore {
    1.30 + 
    1.31 + namespace DecimalPrivate {
    1.32 + 
    1.33 + static int const ExponentMax = 1023;
    1.34 + static int const ExponentMin = -1023;
    1.35 + static int const Precision = 18;
    1.36 +@@ -685,17 +682,17 @@ Decimal Decimal::floor() const
    1.37 +         result += 1;
    1.38 +     }
    1.39 +     return Decimal(sign(), 0, result);
    1.40 + }
    1.41 + 
    1.42 + Decimal Decimal::fromDouble(double doubleValue)
    1.43 + {
    1.44 +     if (std::isfinite(doubleValue))
    1.45 +-        return fromString(String::numberToStringECMAScript(doubleValue));
    1.46 ++        return fromString(mozToString(doubleValue));
    1.47 + 
    1.48 +     if (std::isinf(doubleValue))
    1.49 +         return infinity(doubleValue < 0 ? Negative : Positive);
    1.50 + 
    1.51 +     return nan();
    1.52 + }
    1.53 + 
    1.54 + Decimal Decimal::fromString(const String& str)
    1.55 +@@ -937,17 +934,17 @@ Decimal Decimal::round() const
    1.56 +     result /= 10;
    1.57 +     return Decimal(sign(), 0, result);
    1.58 + }
    1.59 + 
    1.60 + double Decimal::toDouble() const
    1.61 + {
    1.62 +     if (isFinite()) {
    1.63 +         bool valid;
    1.64 +-        const double doubleValue = toString().toDouble(&valid);
    1.65 ++        const double doubleValue = mozToDouble(toString(), &valid);
    1.66 +         return valid ? doubleValue : std::numeric_limits<double>::quiet_NaN();
    1.67 +     }
    1.68 + 
    1.69 +     if (isInfinity())
    1.70 +         return isNegative() ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity();
    1.71 + 
    1.72 +     return std::numeric_limits<double>::quiet_NaN();
    1.73 + }
    1.74 +@@ -990,17 +987,17 @@ String Decimal::toString() const
    1.75 +             ++coefficient;
    1.76 + 
    1.77 +         while (originalExponent < 0 && coefficient && !(coefficient % 10)) {
    1.78 +             coefficient /= 10;
    1.79 +             ++originalExponent;
    1.80 +         }
    1.81 +     }
    1.82 + 
    1.83 +-    const String digits = String::number(coefficient);
    1.84 ++    const String digits = mozToString(coefficient);
    1.85 +     int coefficientLength = static_cast<int>(digits.length());
    1.86 +     const int adjustedExponent = originalExponent + coefficientLength - 1;
    1.87 +     if (originalExponent <= 0 && adjustedExponent >= -6) {
    1.88 +         if (!originalExponent) {
    1.89 +             builder.append(digits);
    1.90 +             return builder.toString();
    1.91 +         }
    1.92 + 
    1.93 +@@ -1032,15 +1029,28 @@ String Decimal::toString() const
    1.94 +         if (adjustedExponent) {
    1.95 +             builder.append(adjustedExponent < 0 ? "e" : "e+");
    1.96 +             builder.appendNumber(adjustedExponent);
    1.97 +         }
    1.98 +     }
    1.99 +     return builder.toString();
   1.100 + }
   1.101 + 
   1.102 ++bool Decimal::toString(char* strBuf, size_t bufLength) const
   1.103 ++{
   1.104 ++  ASSERT(bufLength > 0);
   1.105 ++  String str = toString();
   1.106 ++  size_t length = str.copy(strBuf, bufLength);
   1.107 ++  if (length < bufLength) {
   1.108 ++    strBuf[length] = '\0';
   1.109 ++    return true;
   1.110 ++  }
   1.111 ++  strBuf[bufLength - 1] = '\0';
   1.112 ++  return false;
   1.113 ++}
   1.114 ++
   1.115 + Decimal Decimal::zero(Sign sign)
   1.116 + {
   1.117 +     return Decimal(EncodedData(sign, EncodedData::ClassZero));
   1.118 + }
   1.119 + 
   1.120 + } // namespace WebCore
   1.121 + 
   1.122 +diff --git a/mfbt/decimal/Decimal.h b/mfbt/decimal/Decimal.h
   1.123 +--- a/mfbt/decimal/Decimal.h
   1.124 ++++ b/mfbt/decimal/Decimal.h
   1.125 +@@ -23,24 +23,41 @@
   1.126 +  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   1.127 +  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   1.128 +  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   1.129 +  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   1.130 +  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   1.131 +  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   1.132 +  */
   1.133 + 
   1.134 ++/**
   1.135 ++ * Imported from:
   1.136 ++ * http://src.chromium.org/viewvc/blink/trunk/Source/core/platform/Decimal.h
   1.137 ++ * Check hg log for the svn rev of the last update from Blink core.
   1.138 ++ */
   1.139 ++
   1.140 + #ifndef Decimal_h
   1.141 + #define Decimal_h
   1.142 + 
   1.143 ++#include "mozilla/Assertions.h"
   1.144 ++#include <stdint.h>
   1.145 + #include "mozilla/Types.h"
   1.146 + 
   1.147 +-#include <stdint.h>
   1.148 +-#include <wtf/Assertions.h>
   1.149 +-#include <wtf/text/WTFString.h>
   1.150 ++#include <string>
   1.151 ++
   1.152 ++#ifndef ASSERT
   1.153 ++#define DEFINED_ASSERT_FOR_DECIMAL_H 1
   1.154 ++#define ASSERT MOZ_ASSERT
   1.155 ++#endif
   1.156 ++
   1.157 ++// To use WTF_MAKE_FAST_ALLOCATED we'd need:
   1.158 ++// http://src.chromium.org/viewvc/blink/trunk/Source/wtf/FastMalloc.h
   1.159 ++// Since we don't allocate Decimal objects, no need.
   1.160 ++#define WTF_MAKE_FAST_ALLOCATED \
   1.161 ++  void ignore_this_dummy_method() MOZ_DELETE
   1.162 + 
   1.163 + namespace WebCore {
   1.164 + 
   1.165 + namespace DecimalPrivate {
   1.166 + class SpecialValueHandler;
   1.167 + }
   1.168 + 
   1.169 + // This class represents decimal base floating point number.
   1.170 +@@ -136,27 +153,28 @@ public:
   1.171 +     MFBT_API Decimal abs() const;
   1.172 +     MFBT_API Decimal ceiling() const;
   1.173 +     MFBT_API Decimal floor() const;
   1.174 +     MFBT_API Decimal remainder(const Decimal&) const;
   1.175 +     MFBT_API Decimal round() const;
   1.176 + 
   1.177 +     MFBT_API double toDouble() const;
   1.178 +     // Note: toString method supports infinity and nan but fromString not.
   1.179 +-    MFBT_API String toString() const;
   1.180 ++    MFBT_API std::string toString() const;
   1.181 ++    MFBT_API bool toString(char* strBuf, size_t bufLength) const;
   1.182 + 
   1.183 +     static MFBT_API Decimal fromDouble(double);
   1.184 +     // fromString supports following syntax EBNF:
   1.185 +     //  number ::= sign? digit+ ('.' digit*) (exponent-marker sign? digit+)?
   1.186 +     //          | sign? '.' digit+ (exponent-marker sign? digit+)?
   1.187 +     //  sign ::= '+' | '-'
   1.188 +     //  exponent-marker ::= 'e' | 'E'
   1.189 +     //  digit ::= '0' | '1' | ... | '9'
   1.190 +     // Note: fromString doesn't support "infinity" and "nan".
   1.191 +-    static MFBT_API Decimal fromString(const String&);
   1.192 ++    static MFBT_API Decimal fromString(const std::string& aValue);
   1.193 +     static MFBT_API Decimal infinity(Sign);
   1.194 +     static MFBT_API Decimal nan();
   1.195 +     static MFBT_API Decimal zero(Sign);
   1.196 + 
   1.197 +     // You should not use below methods. We expose them for unit testing.
   1.198 +     MFBT_API explicit Decimal(const EncodedData&);
   1.199 +     const EncodedData& value() const { return m_data; }
   1.200 + 
   1.201 +@@ -175,10 +193,21 @@ private:
   1.202 + 
   1.203 +     Sign sign() const { return m_data.sign(); }
   1.204 + 
   1.205 +     EncodedData m_data;
   1.206 + };
   1.207 + 
   1.208 + } // namespace WebCore
   1.209 + 
   1.210 ++namespace mozilla {
   1.211 ++  typedef WebCore::Decimal Decimal;
   1.212 ++}
   1.213 ++
   1.214 ++#undef WTF_MAKE_FAST_ALLOCATED
   1.215 ++
   1.216 ++#ifdef DEFINED_ASSERT_FOR_DECIMAL_H
   1.217 ++#undef DEFINED_ASSERT_FOR_DECIMAL_H
   1.218 ++#undef ASSERT
   1.219 ++#endif
   1.220 ++
   1.221 + #endif // Decimal_h
   1.222 + 

mercurial