Bug 1353650 - Part 8: Remove conditional code to check for presence of unum_formatDoubleForFields. r=Waldo
authorAndré Bargull <andre.bargull@gmail.com>
Wed, 05 Apr 2017 13:44:46 +0200
changeset 601734 9fba9d8fc530f42623971c526936b86e4e9d6bea
parent 601733 14fbfaa855fe8c5788e9e81736f9d137e960d858
child 601735 22d85759ecf8feb12ee81d1838a121121c423561
push id66200
push userhchang@mozilla.com
push dateThu, 29 Jun 2017 03:53:43 +0000
reviewersWaldo
bugs1353650
milestone56.0a1
Bug 1353650 - Part 8: Remove conditional code to check for presence of unum_formatDoubleForFields. r=Waldo
js/src/builtin/Intl.cpp
--- a/js/src/builtin/Intl.cpp
+++ b/js/src/builtin/Intl.cpp
@@ -331,18 +331,16 @@ unum_open(UNumberFormatStyle style, cons
 }
 
 void
 unum_setAttribute(UNumberFormat* fmt, UNumberFormatAttribute  attr, int32_t newValue)
 {
     MOZ_CRASH("unum_setAttribute: Intl API disabled");
 }
 
-#if defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
-
 int32_t
 unum_formatDoubleForFields(const UNumberFormat* fmt, double number, UChar* result,
                            int32_t resultLength, UFieldPositionIterator* fpositer,
                            UErrorCode* status)
 {
     MOZ_CRASH("unum_formatDoubleForFields: Intl API disabled");
 }
 
@@ -356,27 +354,16 @@ enum UNumberFormatFields {
     UNUM_CURRENCY_FIELD,
     UNUM_PERMILL_FIELD,
     UNUM_EXPONENT_SYMBOL_FIELD,
     UNUM_EXPONENT_SIGN_FIELD,
     UNUM_EXPONENT_FIELD,
     UNUM_FIELD_COUNT,
 };
 
-#else
-
-int32_t
-unum_formatDouble(const UNumberFormat* fmt, double number, UChar* result,
-                  int32_t resultLength, UFieldPosition* pos, UErrorCode* status)
-{
-    MOZ_CRASH("unum_formatDouble: Intl API disabled");
-}
-
-#endif // defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
-
 void
 unum_close(UNumberFormat* fmt)
 {
     MOZ_CRASH("unum_close: Intl API disabled");
 }
 
 void
 unum_setTextAttribute(UNumberFormat* fmt, UNumberFormatTextAttribute tag, const UChar* newValue,
@@ -1706,33 +1693,31 @@ CreateNumberFormatPrototype(JSContext* c
     // 11.4.4
     if (!JS_DefineFunctions(cx, proto, numberFormat_methods))
         return nullptr;
 
     // 11.4.2 and 11.4.3
     if (!JS_DefineProperties(cx, proto, numberFormat_properties))
         return nullptr;
 
-#if defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
     // If the still-experimental NumberFormat.prototype.formatToParts method is
     // enabled, also add it.
     if (cx->compartment()->creationOptions().experimentalNumberFormatFormatToPartsEnabled()) {
         RootedValue ftp(cx);
         HandlePropertyName name = cx->names().formatToParts;
         if (!GlobalObject::getSelfHostedFunction(cx, cx->global(),
                                                  cx->names().NumberFormatFormatToParts,
                                                  name, 1, &ftp))
         {
             return nullptr;
         }
 
         if (!DefineProperty(cx, proto, cx->names().formatToParts, ftp, nullptr, nullptr, 0))
             return nullptr;
     }
-#endif // defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
 
     // 8.1
     RootedValue ctorValue(cx, ObjectValue(*ctor));
     if (!DefineProperty(cx, Intl, cx->names().NumberFormat, ctorValue, nullptr, nullptr, 0))
         return nullptr;
 
     constructor.set(ctor);
     return proto;
@@ -1994,28 +1979,18 @@ NewUNumberFormat(JSContext* cx, Handle<N
 static JSString*
 PartitionNumberPattern(JSContext* cx, UNumberFormat* nf, double* x,
                        UFieldPositionIterator* fpositer)
 {
     // PartitionNumberPattern doesn't consider -0.0 to be negative.
     if (IsNegativeZero(*x))
         *x = 0.0;
 
-#if !defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
-    MOZ_ASSERT(fpositer == nullptr,
-               "shouldn't be requesting field information from an ICU that "
-               "can't provide it");
-#endif
-
     return Call(cx, [nf, x, fpositer](UChar* chars, int32_t size, UErrorCode* status) {
-#if defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
         return unum_formatDoubleForFields(nf, *x, chars, size, fpositer, status);
-#else
-        return unum_formatDouble(nf, *x, chars, size, nullptr, status);
-#endif
     });
 }
 
 static bool
 intl_FormatNumber(JSContext* cx, UNumberFormat* nf, double x, MutableHandleValue result)
 {
     // Passing null for |fpositer| will just not compute partition information,
     // letting us common up all ICU number-formatting code.
@@ -2024,18 +1999,16 @@ intl_FormatNumber(JSContext* cx, UNumber
         return false;
 
     result.setString(str);
     return true;
 }
 
 using FieldType = ImmutablePropertyNamePtr JSAtomState::*;
 
-#if defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
-
 static FieldType
 GetFieldTypeForNumberField(UNumberFormatFields fieldName, double d)
 {
     // See intl/icu/source/i18n/unicode/unum.h for a detailed field list.  This
     // list is deliberately exhaustive: cases might have to be added/removed if
     // this code is compiled with a different ICU with more UNumberFormatFields
     // enum initializers.  Please guard such cases with appropriate ICU
     // version-testing #ifdefs, should cross-version divergence occur.
@@ -2416,18 +2389,16 @@ intl_FormatNumberToParts(JSContext* cx, 
 
     MOZ_ASSERT(lastEndIndex == overallResult->length(),
                "result array must partition the entire string");
 
     result.setObject(*partsArray);
     return true;
 }
 
-#endif // defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
-
 bool
 js::intl_FormatNumber(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     MOZ_ASSERT(args.length() == 3);
     MOZ_ASSERT(args[0].isObject());
     MOZ_ASSERT(args[1].isNumber());
     MOZ_ASSERT(args[2].isBoolean());
@@ -2441,25 +2412,19 @@ js::intl_FormatNumber(JSContext* cx, uns
     if (!nf) {
         nf = NewUNumberFormat(cx, numberFormat);
         if (!nf)
             return false;
         numberFormat->setReservedSlot(NumberFormatObject::UNUMBER_FORMAT_SLOT, PrivateValue(nf));
     }
 
     // Use the UNumberFormat to actually format the number.
-#if defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
     if (args[2].toBoolean()) {
         return intl_FormatNumberToParts(cx, nf, args[1].toNumber(), args.rval());
     }
-#else
-    MOZ_ASSERT(!args[2].toBoolean(),
-               "shouldn't be doing formatToParts without an ICU that "
-               "supports it");
-#endif // defined(ICU_UNUM_HAS_FORMATDOUBLEFORFIELDS)
     return intl_FormatNumber(cx, nf, args[1].toNumber(), args.rval());
 }
 
 
 /******************** DateTimeFormat ********************/
 
 const ClassOps DateTimeFormatObject::classOps_ = {
     nullptr, /* addProperty */