to-moz-dependencies.patch 7.0 KB

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