Bug 1458646 - Replace JS_NewStringCopyZ with NewStringCopyZ in Intl code. r=Waldo
authorAndré Bargull <andre.bargull@gmail.com>
Wed, 02 May 2018 11:37:28 -0700
changeset 471680 5f691b58a680400323d78bebeb22dff9b0f954b2
parent 471679 e8b373cf0de6992e00db7e2489496848f33b64ff
child 471681 ce4fdee191230038af2188d9c9ed1ee126fa551f
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1458646
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1458646 - Replace JS_NewStringCopyZ with NewStringCopyZ in Intl code. r=Waldo
js/src/builtin/intl/Collator.cpp
js/src/builtin/intl/DateTimeFormat.cpp
js/src/builtin/intl/NumberFormat.cpp
js/src/vm/SelfHosting.cpp
--- a/js/src/builtin/intl/Collator.cpp
+++ b/js/src/builtin/intl/Collator.cpp
@@ -235,17 +235,23 @@ js::intl_availableCollations(JSContext* 
         // Per ECMA-402, 10.2.3, we don't include standard and search:
         // "The values 'standard' and 'search' must not be used as elements in
         // any [[sortLocaleData]][locale].co and [[searchLocaleData]][locale].co
         // array."
         if (StringsAreEqual(collation, "standard") || StringsAreEqual(collation, "search"))
             continue;
 
         // ICU returns old-style keyword values; map them to BCP 47 equivalents.
-        JSString* jscollation = JS_NewStringCopyZ(cx, uloc_toUnicodeLocaleType("co", collation));
+        collation = uloc_toUnicodeLocaleType("co", collation);
+        if (!collation) {
+            ReportInternalError(cx);
+            return false;
+        }
+
+        JSString* jscollation = NewStringCopyZ<CanGC>(cx, collation);
         if (!jscollation)
             return false;
         element = StringValue(jscollation);
         if (!DefineDataElement(cx, collations, index++, element))
             return false;
     }
 
     args.rval().setObject(*collations);
--- a/js/src/builtin/intl/DateTimeFormat.cpp
+++ b/js/src/builtin/intl/DateTimeFormat.cpp
@@ -242,17 +242,23 @@ DefaultCalendar(JSContext* cx, const JSA
 
     const char* calendar = ucal_getType(cal, &status);
     if (U_FAILURE(status)) {
         intl::ReportInternalError(cx);
         return false;
     }
 
     // ICU returns old-style keyword values; map them to BCP 47 equivalents
-    JSString* str = JS_NewStringCopyZ(cx, uloc_toUnicodeLocaleType("ca", calendar));
+    calendar = uloc_toUnicodeLocaleType("ca", calendar);
+    if (!calendar) {
+        intl::ReportInternalError(cx);
+        return false;
+    }
+
+    JSString* str = NewStringCopyZ<CanGC>(cx, calendar);
     if (!str)
         return false;
 
     rval.setString(str);
     return true;
 }
 
 struct CalendarAlias
@@ -309,28 +315,32 @@ js::intl_availableCalendars(JSContext* c
         const char* calendar = uenum_next(values, nullptr, &status);
         if (U_FAILURE(status)) {
             intl::ReportInternalError(cx);
             return false;
         }
 
         // ICU returns old-style keyword values; map them to BCP 47 equivalents
         calendar = uloc_toUnicodeLocaleType("ca", calendar);
+        if (!calendar) {
+            intl::ReportInternalError(cx);
+            return false;
+        }
 
-        JSString* jscalendar = JS_NewStringCopyZ(cx, calendar);
+        JSString* jscalendar = NewStringCopyZ<CanGC>(cx, calendar);
         if (!jscalendar)
             return false;
         element = StringValue(jscalendar);
         if (!DefineDataElement(cx, calendars, index++, element))
             return false;
 
         // ICU doesn't return calendar aliases, append them here.
         for (const auto& calendarAlias : calendarAliases) {
             if (StringsAreEqual(calendar, calendarAlias.calendar)) {
-                JSString* jscalendar = JS_NewStringCopyZ(cx, calendarAlias.alias);
+                JSString* jscalendar = NewStringCopyZ<CanGC>(cx, calendarAlias.alias);
                 if (!jscalendar)
                     return false;
                 element = StringValue(jscalendar);
                 if (!DefineDataElement(cx, calendars, index++, element))
                     return false;
             }
         }
     }
--- a/js/src/builtin/intl/NumberFormat.cpp
+++ b/js/src/builtin/intl/NumberFormat.cpp
@@ -218,17 +218,22 @@ js::intl_numberingSystem(JSContext* cx, 
     if (U_FAILURE(status)) {
         intl::ReportInternalError(cx);
         return false;
     }
 
     ScopedICUObject<UNumberingSystem, unumsys_close> toClose(numbers);
 
     const char* name = unumsys_getName(numbers);
-    JSString* jsname = JS_NewStringCopyZ(cx, name);
+    if (!name) {
+        intl::ReportInternalError(cx);
+        return false;
+    }
+
+    JSString* jsname = NewStringCopyZ<CanGC>(cx, name);
     if (!jsname)
         return false;
 
     args.rval().setString(jsname);
     return true;
 }
 
 /**
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -1920,17 +1920,17 @@ intrinsic_RuntimeDefaultLocale(JSContext
     MOZ_ASSERT(args.length() == 0);
 
     const char* locale = cx->runtime()->getDefaultLocale();
     if (!locale) {
         JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_DEFAULT_LOCALE_ERROR);
         return false;
     }
 
-    JSString* jslocale = JS_NewStringCopyZ(cx, locale);
+    JSString* jslocale = NewStringCopyZ<CanGC>(cx, locale);
     if (!jslocale)
         return false;
 
     args.rval().setString(jslocale);
     return true;
 }
 
 static bool