Bug 1321771: Replace uses of JSAutoByteString in comparisons with js::StringEqualsAscii. r=arai
authorAndré Bargull <andre.bargull@gmail.com>
Sat, 03 Dec 2016 12:15:54 -0800
changeset 325263 c7beb88235a105fdd854945688ded42e043da8d4
parent 325250 12637ae351d64ecbf6b74cdbf26d7eb24ac0f659
child 325264 2f51065d18691e3bab09abf3224b0f4e134d451f
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersarai
bugs1321771
milestone53.0a1
Bug 1321771: Replace uses of JSAutoByteString in comparisons with js::StringEqualsAscii. r=arai
js/src/builtin/Intl.cpp
--- a/js/src/builtin/Intl.cpp
+++ b/js/src/builtin/Intl.cpp
@@ -16,16 +16,17 @@
 #include "mozilla/ScopeExit.h"
 
 #include <string.h>
 
 #include "jsapi.h"
 #include "jsatom.h"
 #include "jscntxt.h"
 #include "jsobj.h"
+#include "jsstr.h"
 
 #include "builtin/IntlTimeZoneData.h"
 #if ENABLE_INTL_API
 #include "unicode/ucal.h"
 #include "unicode/ucol.h"
 #include "unicode/udat.h"
 #include "unicode/udatpg.h"
 #include "unicode/uenum.h"
@@ -1112,20 +1113,20 @@ NewUCollator(JSContext* cx, HandleObject
     UColAttributeValue uAlternate = UCOL_DEFAULT;
     UColAttributeValue uNumeric = UCOL_OFF;
     // Normalization is always on to meet the canonical equivalence requirement.
     UColAttributeValue uNormalization = UCOL_ON;
     UColAttributeValue uCaseFirst = UCOL_DEFAULT;
 
     if (!GetProperty(cx, internals, internals, cx->names().usage, &value))
         return nullptr;
-    JSAutoByteString usage(cx, value.toString());
+    JSLinearString* usage = value.toString()->ensureLinear(cx);
     if (!usage)
         return nullptr;
-    if (equal(usage, "search")) {
+    if (StringEqualsAscii(usage, "search")) {
         // ICU expects search as a Unicode locale extension on locale.
         // Unicode locale extensions must occur before private use extensions.
         const char* oldLocale = locale.ptr();
         const char* p;
         size_t index;
         size_t localeLen = strlen(oldLocale);
         if ((p = strstr(oldLocale, "-x-")))
             index = p - oldLocale;
@@ -1143,36 +1144,38 @@ NewUCollator(JSContext* cx, HandleObject
         char* newLocale = cx->pod_malloc<char>(localeLen + insertLen + 1);
         if (!newLocale)
             return nullptr;
         memcpy(newLocale, oldLocale, index);
         memcpy(newLocale + index, insert, insertLen);
         memcpy(newLocale + index + insertLen, oldLocale + index, localeLen - index + 1); // '\0'
         locale.clear();
         locale.initBytes(newLocale);
+    } else {
+        MOZ_ASSERT(StringEqualsAscii(usage, "sort"));
     }
 
     // We don't need to look at the collation property - it can only be set
     // via the Unicode locale extension and is therefore already set on
     // locale.
 
     if (!GetProperty(cx, internals, internals, cx->names().sensitivity, &value))
         return nullptr;
-    JSAutoByteString sensitivity(cx, value.toString());
+    JSLinearString* sensitivity = value.toString()->ensureLinear(cx);
     if (!sensitivity)
         return nullptr;
-    if (equal(sensitivity, "base")) {
+    if (StringEqualsAscii(sensitivity, "base")) {
         uStrength = UCOL_PRIMARY;
-    } else if (equal(sensitivity, "accent")) {
+    } else if (StringEqualsAscii(sensitivity, "accent")) {
         uStrength = UCOL_SECONDARY;
-    } else if (equal(sensitivity, "case")) {
+    } else if (StringEqualsAscii(sensitivity, "case")) {
         uStrength = UCOL_PRIMARY;
         uCaseLevel = UCOL_ON;
     } else {
-        MOZ_ASSERT(equal(sensitivity, "variant"));
+        MOZ_ASSERT(StringEqualsAscii(sensitivity, "variant"));
         uStrength = UCOL_TERTIARY;
     }
 
     if (!GetProperty(cx, internals, internals, cx->names().ignorePunctuation, &value))
         return nullptr;
     // According to the ICU team, UCOL_SHIFTED causes punctuation to be
     // ignored. Looking at Unicode Technical Report 35, Unicode Locale Data
     // Markup Language, "shifted" causes whitespace and punctuation to be
@@ -1184,25 +1187,25 @@ NewUCollator(JSContext* cx, HandleObject
     if (!GetProperty(cx, internals, internals, cx->names().numeric, &value))
         return nullptr;
     if (!value.isUndefined() && value.toBoolean())
         uNumeric = UCOL_ON;
 
     if (!GetProperty(cx, internals, internals, cx->names().caseFirst, &value))
         return nullptr;
     if (!value.isUndefined()) {
-        JSAutoByteString caseFirst(cx, value.toString());
+        JSLinearString* caseFirst = value.toString()->ensureLinear(cx);
         if (!caseFirst)
             return nullptr;
-        if (equal(caseFirst, "upper"))
+        if (StringEqualsAscii(caseFirst, "upper"))
             uCaseFirst = UCOL_UPPER_FIRST;
-        else if (equal(caseFirst, "lower"))
+        else if (StringEqualsAscii(caseFirst, "lower"))
             uCaseFirst = UCOL_LOWER_FIRST;
         else
-            MOZ_ASSERT(equal(caseFirst, "false"));
+            MOZ_ASSERT(StringEqualsAscii(caseFirst, "false"));
     }
 
     UErrorCode status = U_ZERO_ERROR;
     UCollator* coll = ucol_open(icuLocale(locale.ptr()), &status);
     if (U_FAILURE(status)) {
         JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INTERNAL_INTL_ERROR);
         return nullptr;
     }
@@ -1594,48 +1597,48 @@ NewUNumberFormat(JSContext* cx, HandleOb
     RootedString currency(cx);
     AutoStableStringChars stableChars(cx);
 
     // We don't need to look at numberingSystem - it can only be set via
     // the Unicode locale extension and is therefore already set on locale.
 
     if (!GetProperty(cx, internals, internals, cx->names().style, &value))
         return nullptr;
-    JSAutoByteString style(cx, value.toString());
+    JSLinearString* style = value.toString()->ensureLinear(cx);
     if (!style)
         return nullptr;
 
-    if (equal(style, "currency")) {
+    if (StringEqualsAscii(style, "currency")) {
         if (!GetProperty(cx, internals, internals, cx->names().currency, &value))
             return nullptr;
         currency = value.toString();
         MOZ_ASSERT(currency->length() == 3,
                    "IsWellFormedCurrencyCode permits only length-3 strings");
         if (!stableChars.initTwoByte(cx, currency))
             return nullptr;
         // uCurrency remains owned by stableChars.
         uCurrency = Char16ToUChar(stableChars.twoByteRange().begin().get());
 
         if (!GetProperty(cx, internals, internals, cx->names().currencyDisplay, &value))
             return nullptr;
-        JSAutoByteString currencyDisplay(cx, value.toString());
+        JSLinearString* currencyDisplay = value.toString()->ensureLinear(cx);
         if (!currencyDisplay)
             return nullptr;
-        if (equal(currencyDisplay, "code")) {
+        if (StringEqualsAscii(currencyDisplay, "code")) {
             uStyle = UNUM_CURRENCY_ISO;
-        } else if (equal(currencyDisplay, "symbol")) {
+        } else if (StringEqualsAscii(currencyDisplay, "symbol")) {
             uStyle = UNUM_CURRENCY;
         } else {
-            MOZ_ASSERT(equal(currencyDisplay, "name"));
+            MOZ_ASSERT(StringEqualsAscii(currencyDisplay, "name"));
             uStyle = UNUM_CURRENCY_PLURAL;
         }
-    } else if (equal(style, "percent")) {
+    } else if (StringEqualsAscii(style, "percent")) {
         uStyle = UNUM_PERCENT;
     } else {
-        MOZ_ASSERT(equal(style, "decimal"));
+        MOZ_ASSERT(StringEqualsAscii(style, "decimal"));
         uStyle = UNUM_DECIMAL;
     }
 
     RootedId id(cx, NameToId(cx->names().minimumSignificantDigits));
     bool hasP;
     if (!HasProperty(cx, internals, id, &hasP))
         return nullptr;
     if (hasP) {