Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | diff --git a/mfbt/decimal/Decimal.cpp b/mfbt/decimal/Decimal.cpp |
michael@0 | 2 | --- a/mfbt/decimal/Decimal.cpp |
michael@0 | 3 | +++ b/mfbt/decimal/Decimal.cpp |
michael@0 | 4 | @@ -23,26 +23,23 @@ |
michael@0 | 5 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 6 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 7 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 8 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 9 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 10 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 11 | */ |
michael@0 | 12 | |
michael@0 | 13 | -#include "config.h" |
michael@0 | 14 | #include "Decimal.h" |
michael@0 | 15 | +#include "moz-decimal-utils.h" |
michael@0 | 16 | |
michael@0 | 17 | #include <algorithm> |
michael@0 | 18 | #include <float.h> |
michael@0 | 19 | |
michael@0 | 20 | -#include <wtf/Assertions.h> |
michael@0 | 21 | -#include <wtf/MathExtras.h> |
michael@0 | 22 | -#include <wtf/Noncopyable.h> |
michael@0 | 23 | -#include <wtf/text/StringBuilder.h> |
michael@0 | 24 | +using namespace moz_decimal_utils; |
michael@0 | 25 | |
michael@0 | 26 | namespace WebCore { |
michael@0 | 27 | |
michael@0 | 28 | namespace DecimalPrivate { |
michael@0 | 29 | |
michael@0 | 30 | static int const ExponentMax = 1023; |
michael@0 | 31 | static int const ExponentMin = -1023; |
michael@0 | 32 | static int const Precision = 18; |
michael@0 | 33 | @@ -685,17 +682,17 @@ Decimal Decimal::floor() const |
michael@0 | 34 | result += 1; |
michael@0 | 35 | } |
michael@0 | 36 | return Decimal(sign(), 0, result); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | Decimal Decimal::fromDouble(double doubleValue) |
michael@0 | 40 | { |
michael@0 | 41 | if (std::isfinite(doubleValue)) |
michael@0 | 42 | - return fromString(String::numberToStringECMAScript(doubleValue)); |
michael@0 | 43 | + return fromString(mozToString(doubleValue)); |
michael@0 | 44 | |
michael@0 | 45 | if (std::isinf(doubleValue)) |
michael@0 | 46 | return infinity(doubleValue < 0 ? Negative : Positive); |
michael@0 | 47 | |
michael@0 | 48 | return nan(); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | Decimal Decimal::fromString(const String& str) |
michael@0 | 52 | @@ -937,17 +934,17 @@ Decimal Decimal::round() const |
michael@0 | 53 | result /= 10; |
michael@0 | 54 | return Decimal(sign(), 0, result); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | double Decimal::toDouble() const |
michael@0 | 58 | { |
michael@0 | 59 | if (isFinite()) { |
michael@0 | 60 | bool valid; |
michael@0 | 61 | - const double doubleValue = toString().toDouble(&valid); |
michael@0 | 62 | + const double doubleValue = mozToDouble(toString(), &valid); |
michael@0 | 63 | return valid ? doubleValue : std::numeric_limits<double>::quiet_NaN(); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | if (isInfinity()) |
michael@0 | 67 | return isNegative() ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity(); |
michael@0 | 68 | |
michael@0 | 69 | return std::numeric_limits<double>::quiet_NaN(); |
michael@0 | 70 | } |
michael@0 | 71 | @@ -990,17 +987,17 @@ String Decimal::toString() const |
michael@0 | 72 | ++coefficient; |
michael@0 | 73 | |
michael@0 | 74 | while (originalExponent < 0 && coefficient && !(coefficient % 10)) { |
michael@0 | 75 | coefficient /= 10; |
michael@0 | 76 | ++originalExponent; |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | - const String digits = String::number(coefficient); |
michael@0 | 81 | + const String digits = mozToString(coefficient); |
michael@0 | 82 | int coefficientLength = static_cast<int>(digits.length()); |
michael@0 | 83 | const int adjustedExponent = originalExponent + coefficientLength - 1; |
michael@0 | 84 | if (originalExponent <= 0 && adjustedExponent >= -6) { |
michael@0 | 85 | if (!originalExponent) { |
michael@0 | 86 | builder.append(digits); |
michael@0 | 87 | return builder.toString(); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | @@ -1032,15 +1029,28 @@ String Decimal::toString() const |
michael@0 | 91 | if (adjustedExponent) { |
michael@0 | 92 | builder.append(adjustedExponent < 0 ? "e" : "e+"); |
michael@0 | 93 | builder.appendNumber(adjustedExponent); |
michael@0 | 94 | } |
michael@0 | 95 | } |
michael@0 | 96 | return builder.toString(); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | +bool Decimal::toString(char* strBuf, size_t bufLength) const |
michael@0 | 100 | +{ |
michael@0 | 101 | + ASSERT(bufLength > 0); |
michael@0 | 102 | + String str = toString(); |
michael@0 | 103 | + size_t length = str.copy(strBuf, bufLength); |
michael@0 | 104 | + if (length < bufLength) { |
michael@0 | 105 | + strBuf[length] = '\0'; |
michael@0 | 106 | + return true; |
michael@0 | 107 | + } |
michael@0 | 108 | + strBuf[bufLength - 1] = '\0'; |
michael@0 | 109 | + return false; |
michael@0 | 110 | +} |
michael@0 | 111 | + |
michael@0 | 112 | Decimal Decimal::zero(Sign sign) |
michael@0 | 113 | { |
michael@0 | 114 | return Decimal(EncodedData(sign, EncodedData::ClassZero)); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | } // namespace WebCore |
michael@0 | 118 | |
michael@0 | 119 | diff --git a/mfbt/decimal/Decimal.h b/mfbt/decimal/Decimal.h |
michael@0 | 120 | --- a/mfbt/decimal/Decimal.h |
michael@0 | 121 | +++ b/mfbt/decimal/Decimal.h |
michael@0 | 122 | @@ -23,24 +23,41 @@ |
michael@0 | 123 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 124 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 125 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 126 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 127 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 128 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 129 | */ |
michael@0 | 130 | |
michael@0 | 131 | +/** |
michael@0 | 132 | + * Imported from: |
michael@0 | 133 | + * http://src.chromium.org/viewvc/blink/trunk/Source/core/platform/Decimal.h |
michael@0 | 134 | + * Check hg log for the svn rev of the last update from Blink core. |
michael@0 | 135 | + */ |
michael@0 | 136 | + |
michael@0 | 137 | #ifndef Decimal_h |
michael@0 | 138 | #define Decimal_h |
michael@0 | 139 | |
michael@0 | 140 | +#include "mozilla/Assertions.h" |
michael@0 | 141 | +#include <stdint.h> |
michael@0 | 142 | #include "mozilla/Types.h" |
michael@0 | 143 | |
michael@0 | 144 | -#include <stdint.h> |
michael@0 | 145 | -#include <wtf/Assertions.h> |
michael@0 | 146 | -#include <wtf/text/WTFString.h> |
michael@0 | 147 | +#include <string> |
michael@0 | 148 | + |
michael@0 | 149 | +#ifndef ASSERT |
michael@0 | 150 | +#define DEFINED_ASSERT_FOR_DECIMAL_H 1 |
michael@0 | 151 | +#define ASSERT MOZ_ASSERT |
michael@0 | 152 | +#endif |
michael@0 | 153 | + |
michael@0 | 154 | +// To use WTF_MAKE_FAST_ALLOCATED we'd need: |
michael@0 | 155 | +// http://src.chromium.org/viewvc/blink/trunk/Source/wtf/FastMalloc.h |
michael@0 | 156 | +// Since we don't allocate Decimal objects, no need. |
michael@0 | 157 | +#define WTF_MAKE_FAST_ALLOCATED \ |
michael@0 | 158 | + void ignore_this_dummy_method() MOZ_DELETE |
michael@0 | 159 | |
michael@0 | 160 | namespace WebCore { |
michael@0 | 161 | |
michael@0 | 162 | namespace DecimalPrivate { |
michael@0 | 163 | class SpecialValueHandler; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | // This class represents decimal base floating point number. |
michael@0 | 167 | @@ -136,27 +153,28 @@ public: |
michael@0 | 168 | MFBT_API Decimal abs() const; |
michael@0 | 169 | MFBT_API Decimal ceiling() const; |
michael@0 | 170 | MFBT_API Decimal floor() const; |
michael@0 | 171 | MFBT_API Decimal remainder(const Decimal&) const; |
michael@0 | 172 | MFBT_API Decimal round() const; |
michael@0 | 173 | |
michael@0 | 174 | MFBT_API double toDouble() const; |
michael@0 | 175 | // Note: toString method supports infinity and nan but fromString not. |
michael@0 | 176 | - MFBT_API String toString() const; |
michael@0 | 177 | + MFBT_API std::string toString() const; |
michael@0 | 178 | + MFBT_API bool toString(char* strBuf, size_t bufLength) const; |
michael@0 | 179 | |
michael@0 | 180 | static MFBT_API Decimal fromDouble(double); |
michael@0 | 181 | // fromString supports following syntax EBNF: |
michael@0 | 182 | // number ::= sign? digit+ ('.' digit*) (exponent-marker sign? digit+)? |
michael@0 | 183 | // | sign? '.' digit+ (exponent-marker sign? digit+)? |
michael@0 | 184 | // sign ::= '+' | '-' |
michael@0 | 185 | // exponent-marker ::= 'e' | 'E' |
michael@0 | 186 | // digit ::= '0' | '1' | ... | '9' |
michael@0 | 187 | // Note: fromString doesn't support "infinity" and "nan". |
michael@0 | 188 | - static MFBT_API Decimal fromString(const String&); |
michael@0 | 189 | + static MFBT_API Decimal fromString(const std::string& aValue); |
michael@0 | 190 | static MFBT_API Decimal infinity(Sign); |
michael@0 | 191 | static MFBT_API Decimal nan(); |
michael@0 | 192 | static MFBT_API Decimal zero(Sign); |
michael@0 | 193 | |
michael@0 | 194 | // You should not use below methods. We expose them for unit testing. |
michael@0 | 195 | MFBT_API explicit Decimal(const EncodedData&); |
michael@0 | 196 | const EncodedData& value() const { return m_data; } |
michael@0 | 197 | |
michael@0 | 198 | @@ -175,10 +193,21 @@ private: |
michael@0 | 199 | |
michael@0 | 200 | Sign sign() const { return m_data.sign(); } |
michael@0 | 201 | |
michael@0 | 202 | EncodedData m_data; |
michael@0 | 203 | }; |
michael@0 | 204 | |
michael@0 | 205 | } // namespace WebCore |
michael@0 | 206 | |
michael@0 | 207 | +namespace mozilla { |
michael@0 | 208 | + typedef WebCore::Decimal Decimal; |
michael@0 | 209 | +} |
michael@0 | 210 | + |
michael@0 | 211 | +#undef WTF_MAKE_FAST_ALLOCATED |
michael@0 | 212 | + |
michael@0 | 213 | +#ifdef DEFINED_ASSERT_FOR_DECIMAL_H |
michael@0 | 214 | +#undef DEFINED_ASSERT_FOR_DECIMAL_H |
michael@0 | 215 | +#undef ASSERT |
michael@0 | 216 | +#endif |
michael@0 | 217 | + |
michael@0 | 218 | #endif // Decimal_h |
michael@0 | 219 |