Source code

Revision control

Copy as Markdown

Other Tools

diff --git a/Decimal.cpp b/Decimal.cpp
--- a/Decimal.cpp
+++ b/Decimal.cpp
@@ -28,12 +28,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "platform/Decimal.h"
+#include "Decimal.h"
+#include "moz-decimal-utils.h"
-#include "wtf/Allocator.h"
-#include "wtf/MathExtras.h"
-#include "wtf/Noncopyable.h"
-#include "wtf/text/StringBuilder.h"
+using namespace moz_decimal_utils;
#include <algorithm>
#include <float.h>
@@ -695,7 +693,7 @@ Decimal Decimal::floor() const
Decimal Decimal::fromDouble(double doubleValue)
{
if (std::isfinite(doubleValue))
- return fromString(String::numberToStringECMAScript(doubleValue));
+ return fromString(mozToString(doubleValue));
if (std::isinf(doubleValue))
return infinity(doubleValue < 0 ? Negative : Positive);
@@ -936,7 +934,7 @@ double Decimal::toDouble() const
{
if (isFinite()) {
bool valid;
- const double doubleValue = toString().toDouble(&valid);
+ const double doubleValue = mozToDouble(toString(), &valid);
return valid ? doubleValue : std::numeric_limits<double>::quiet_NaN();
}
@@ -989,7 +987,7 @@ String Decimal::toString() const
}
}
- const String digits = String::number(coefficient);
+ const String digits = mozToString(coefficient);
int coefficientLength = static_cast<int>(digits.length());
const int adjustedExponent = originalExponent + coefficientLength - 1;
if (originalExponent <= 0 && adjustedExponent >= -6) {
diff --git a/Decimal.h b/Decimal.h
index f97da8c113e1..bc8264d1d5f5 100644
--- a/Decimal.h
+++ b/Decimal.h
@@ -28,16 +28,39 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ * Imported from:
+ * Check UPSTREAM-GIT-SHA for the commit ID of the last update from Blink core.
+ */
+
#ifndef Decimal_h
#define Decimal_h
+#include "mozilla/Assertions.h"
+#include <stdint.h>
#include "mozilla/Types.h"
-#include "platform/PlatformExport.h"
-#include "wtf/Allocator.h"
-#include "wtf/Assertions.h"
-#include "wtf/text/WTFString.h"
-#include <stdint.h>
+#include <string>
+
+#ifndef ASSERT
+#define DEFINED_ASSERT_FOR_DECIMAL_H 1
+#define ASSERT MOZ_ASSERT
+#endif
+
+#define PLATFORM_EXPORT
+
+// To use USING_FAST_MALLOC we'd need:
+// Since we don't allocate Decimal objects, no need.
+#define USING_FAST_MALLOC(type) \
+ void ignore_this_dummy_method() = delete
+
+#define DISALLOW_NEW() \
+ private: \
+ void* operator new(size_t) = delete; \
+ void* operator new(size_t, void*) = delete; \
+ public:
namespace blink {
@@ -144,7 +167,7 @@ public:
MFBT_API double toDouble() const;
// Note: toString method supports infinity and nan but fromString not.
- MFBT_API String toString() const;
+ MFBT_API std::string toString() const;
static MFBT_API Decimal fromDouble(double);
// fromString supports following syntax EBNF:
@@ -154,7 +177,7 @@ public:
// exponent-marker ::= 'e' | 'E'
// digit ::= '0' | '1' | ... | '9'
// Note: fromString doesn't support "infinity" and "nan".
- static MFBT_API Decimal fromString(const String&);
+ static MFBT_API Decimal fromString(const std::string& aValue);
static MFBT_API Decimal infinity(Sign);
static MFBT_API Decimal nan();
static MFBT_API Decimal zero(Sign);
@@ -183,4 +206,15 @@ private:
} // namespace blink
+namespace mozilla {
+typedef blink::Decimal Decimal;
+} // namespace mozilla
+
+#undef USING_FAST_MALLOC
+
+#ifdef DEFINED_ASSERT_FOR_DECIMAL_H
+#undef DEFINED_ASSERT_FOR_DECIMAL_H
+#undef ASSERT
+#endif
+
#endif // Decimal_h