Bug 1353650 - Part 9: Replace PluralRules::getKeywords in favour of uplrules_getKeywords. r=Waldo
authorAndré Bargull <andre.bargull@gmail.com>
Wed, 19 Apr 2017 07:07:08 -0700
changeset 601735 22d85759ecf8feb12ee81d1838a121121c423561
parent 601734 9fba9d8fc530f42623971c526936b86e4e9d6bea
child 601736 63c35f0dc789a33c644a3ab53de4efb15f372c5e
push id66200
push userhchang@mozilla.com
push dateThu, 29 Jun 2017 03:53:43 +0000
reviewersWaldo
bugs1353650
milestone56.0a1
Bug 1353650 - Part 9: Replace PluralRules::getKeywords in favour of uplrules_getKeywords. r=Waldo
js/src/builtin/Intl.cpp
--- a/js/src/builtin/Intl.cpp
+++ b/js/src/builtin/Intl.cpp
@@ -25,17 +25,16 @@
 #include "jsfriendapi.h"
 #include "jsobj.h"
 #include "jsstr.h"
 #include "jsutil.h"
 
 #include "builtin/IntlTimeZoneData.h"
 #include "ds/Sort.h"
 #if ENABLE_INTL_API
-#include "unicode/plurrule.h"
 #include "unicode/ucal.h"
 #include "unicode/ucol.h"
 #include "unicode/udat.h"
 #include "unicode/udatpg.h"
 #include "unicode/uenum.h"
 #include "unicode/uloc.h"
 #include "unicode/unum.h"
 #include "unicode/unumsys.h"
@@ -90,47 +89,16 @@ using mozilla::RangedPtr;
 
 namespace {
 
 enum UErrorCode {
     U_ZERO_ERROR,
     U_BUFFER_OVERFLOW_ERROR,
 };
 
-}
-
-namespace icu {
-
-class StringEnumeration {
-    public:
-        explicit StringEnumeration();
-};
-
-StringEnumeration::StringEnumeration()
-{
-    MOZ_CRASH("StringEnumeration::StringEnumeration: Intl API disabled");
-}
-
-class PluralRules {
-public:
-
-    StringEnumeration* getKeywords(UErrorCode& status) const;
-
-};
-
-StringEnumeration*
-PluralRules::getKeywords(UErrorCode& status) const
-{
-    MOZ_CRASH("PluralRules::getKeywords: Intl API disabled");
-}
-
-} // icu namespace
-
-namespace {
-
 typedef bool UBool;
 typedef char16_t UChar;
 typedef double UDate;
 
 inline UBool
 U_FAILURE(UErrorCode code)
 {
     MOZ_CRASH("U_FAILURE: Intl API disabled");
@@ -183,22 +151,16 @@ uenum_next(UEnumeration* en, int32_t* re
 }
 
 void
 uenum_close(UEnumeration* en)
 {
     MOZ_CRASH("uenum_close: Intl API disabled");
 }
 
-UEnumeration*
-uenum_openFromStringEnumeration(icu::StringEnumeration* adopted, UErrorCode* ec)
-{
-    MOZ_CRASH("uenum_openFromStringEnumeration: Intl API disabled");
-}
-
 struct UCollator;
 
 enum UColAttribute {
     UCOL_ALTERNATE_HANDLING,
     UCOL_CASE_FIRST,
     UCOL_CASE_LEVEL,
     UCOL_NORMALIZATION_MODE,
     UCOL_STRENGTH,
@@ -776,16 +738,22 @@ uplrules_openForType(const char *locale,
 
 int32_t
 uplrules_select(const UPluralRules *uplrules, double number, UChar *keyword, int32_t capacity,
                 UErrorCode *status)
 {
     MOZ_CRASH("uplrules_select: Intl API disabled");
 }
 
+UEnumeration*
+uplrules_getKeywords(const UPluralRules* uplrules, UErrorCode* status)
+{
+    MOZ_CRASH("uplrules_getKeywords: Intl API disabled");
+}
+
 int32_t
 u_strToLower(UChar* dest, int32_t destCapacity, const UChar* src, int32_t srcLength,
              const char* locale, UErrorCode* pErrorCode)
 {
     MOZ_CRASH("u_strToLower: Intl API disabled");
 }
 
 int32_t
@@ -3825,34 +3793,23 @@ js::intl_GetPluralCategories(JSContext* 
     }
 
     UErrorCode status = U_ZERO_ERROR;
     UPluralRules* pr = uplrules_openForType(icuLocale(locale.ptr()), category, &status);
     if (U_FAILURE(status)) {
         JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INTERNAL_INTL_ERROR);
         return false;
     }
-
     ScopedICUObject<UPluralRules, uplrules_close> closePluralRules(pr);
 
-    // We should get a C API for that in ICU 59 and switch to it.
-    // https://ssl.icu-project.org/trac/ticket/12772
-    icu::StringEnumeration* kwenum =
-        reinterpret_cast<icu::PluralRules*>(pr)->getKeywords(status);
+    UEnumeration* ue = uplrules_getKeywords(pr, &status);
     if (U_FAILURE(status)) {
         JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INTERNAL_INTL_ERROR);
         return false;
     }
-
-    UEnumeration* ue = uenum_openFromStringEnumeration(kwenum, &status);
-    if (U_FAILURE(status)) {
-        JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INTERNAL_INTL_ERROR);
-        return false;
-    }
-
     ScopedICUObject<UEnumeration, uenum_close> closeEnum(ue);
 
     RootedObject res(cx, NewDenseEmptyArray(cx));
     if (!res)
         return false;
 
     RootedValue element(cx);
     uint32_t i = 0;