Bug 1632434 - Part 5: Remove guards around previous ICU draft APIs. r=jwalden

These APIs were stabilised in ICU 67.

Depends on D72912

Differential Revision: https://phabricator.services.mozilla.com/D72913
This commit is contained in:
André Bargull 2020-04-29 23:47:56 +00:00
Родитель 7e69806ed2
Коммит c4a1e03db6
4 изменённых файлов: 4 добавлений и 106 удалений

Просмотреть файл

@ -80,9 +80,7 @@ static const JSFunctionSpec listFormat_methods[] = {
JS_SELF_HOSTED_FN("resolvedOptions", "Intl_ListFormat_resolvedOptions", 0,
0),
JS_SELF_HOSTED_FN("format", "Intl_ListFormat_format", 1, 0),
#ifndef U_HIDE_DRAFT_API
JS_SELF_HOSTED_FN("formatToParts", "Intl_ListFormat_formatToParts", 1, 0),
#endif
JS_FN(js_toSource_str, listFormat_toSource, 0, 0), JS_FS_END};
static const JSPropertySpec listFormat_properties[] = {
@ -274,7 +272,6 @@ static bool FormatList(JSContext* cx, UListFormatter* lf,
return true;
}
#ifndef U_HIDE_DRAFT_API
static JSString* FormattedValueToString(JSContext* cx,
const UFormattedValue* formattedValue) {
UErrorCode status = U_ZERO_ERROR;
@ -434,7 +431,6 @@ static bool FormatListToParts(JSContext* cx, UListFormatter* lf,
result.setObject(*partsArray);
return true;
}
#endif // U_HIDE_DRAFT_API
bool js::intl_FormatList(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
@ -505,13 +501,8 @@ bool js::intl_FormatList(JSContext* cx, unsigned argc, Value* vp) {
}
// Use the UListFormatter to actually format the strings.
#ifndef U_HIDE_DRAFT_API
if (formatToParts) {
return FormatListToParts(cx, lf, strings, stringLengths, args.rval());
}
#else
MOZ_ASSERT(!formatToParts);
#endif
return FormatList(cx, lf, strings, stringLengths, args.rval());
}

Просмотреть файл

@ -895,16 +895,7 @@ static UFormattedNumber* NewUFormattedNumber(JSContext* cx) {
return formatted;
}
// We also support UFormattedNumber in addition to UFormattedValue, in case
// we're compiling against a system ICU which doesn't expose draft APIs.
#ifndef U_HIDE_DRAFT_API
using PartitionNumberPatternResult = const UFormattedValue*;
#else
using PartitionNumberPatternResult = const UFormattedNumber*;
#endif
static PartitionNumberPatternResult PartitionNumberPattern(
static const UFormattedValue* PartitionNumberPattern(
JSContext* cx, const UNumberFormatter* nf, UFormattedNumber* formatted,
HandleValue x) {
UErrorCode status = U_ZERO_ERROR;
@ -944,7 +935,6 @@ static PartitionNumberPatternResult PartitionNumberPattern(
return nullptr;
}
#ifndef U_HIDE_DRAFT_API
const UFormattedValue* formattedValue =
unumf_resultAsValue(formatted, &status);
if (U_FAILURE(status)) {
@ -952,18 +942,10 @@ static PartitionNumberPatternResult PartitionNumberPattern(
return nullptr;
}
return formattedValue;
#else
return formatted;
#endif
}
static JSString* FormattedNumberToString(
JSContext* cx, PartitionNumberPatternResult formattedValue) {
#ifndef U_HIDE_DRAFT_API
static_assert(
std::is_same_v<PartitionNumberPatternResult, const UFormattedValue*>,
"UFormattedValue arm");
JSContext* cx, const UFormattedValue* formattedValue) {
UErrorCode status = U_ZERO_ERROR;
int32_t strLength;
const char16_t* str = ufmtval_getString(formattedValue, &strLength, &status);
@ -973,22 +955,12 @@ static JSString* FormattedNumberToString(
}
return NewStringCopyN<CanGC>(cx, str, AssertedCast<uint32_t>(strLength));
#else
static_assert(
std::is_same_v<PartitionNumberPatternResult, const UFormattedNumber*>,
"UFormattedNumber arm");
return CallICU(cx,
[formatted](UChar* chars, int32_t size, UErrorCode* status) {
return unumf_resultToString(formatted, chars, size, status);
});
#endif
}
static bool FormatNumeric(JSContext* cx, const UNumberFormatter* nf,
UFormattedNumber* formatted, HandleValue x,
MutableHandleValue result) {
PartitionNumberPatternResult formattedValue =
const UFormattedValue* formattedValue =
PartitionNumberPattern(cx, nf, formatted, x);
if (!formattedValue) {
return false;
@ -1071,13 +1043,11 @@ static FieldType GetFieldTypeForNumberField(UNumberFormatFields fieldName,
case UNUM_EXPONENT_FIELD:
return &JSAtomState::exponentInteger;
#ifndef U_HIDE_DRAFT_API
case UNUM_MEASURE_UNIT_FIELD:
return &JSAtomState::unit;
case UNUM_COMPACT_FIELD:
return &JSAtomState::compact;
#endif
#ifndef U_HIDE_DEPRECATED_API
case UNUM_FIELD_COUNT:
@ -1419,7 +1389,6 @@ ArrayObject* NumberFormatFields::toArray(JSContext* cx,
return partsArray;
}
#ifndef U_HIDE_DRAFT_API
static bool FormattedNumberToParts(JSContext* cx,
const UFormattedValue* formattedValue,
HandleValue number,
@ -1500,69 +1469,19 @@ bool js::intl::FormattedRelativeTimeToParts(
cx, formattedValue, HandleValue::fromMarkedLocation(&tval),
relativeTimeUnit, FormattingType::NotForUnit, result);
}
#else
static ArrayObject* LegacyFormattedNumberToParts(
JSContext* cx, const UFormattedNumber* formatted, HandleValue x,
MutableHandleValue result) {
RootedString overallResult(cx, FormattedNumberToString(cx, formatted));
if (!overallResult) {
return false;
}
UErrorCode status = U_ZERO_ERROR;
UFieldPositionIterator* fpositer = ufieldpositer_open(&status);
if (U_FAILURE(status)) {
intl::ReportInternalError(cx);
return false;
}
MOZ_ASSERT(fpositer);
ScopedICUObject<UFieldPositionIterator, ufieldpositer_close> toClose(
fpositer);
unumf_resultGetAllFieldPositions(formatted, fpositer, &status);
if (U_FAILURE(status)) {
intl::ReportInternalError(cx);
return false;
}
// Vacuum up fields in the overall formatted string.
NumberFormatFields fields(cx, x);
int32_t field, beginIndex, endIndex;
while ((field = ufieldpositer_next(fpositer, &beginIndex, &endIndex)) >= 0) {
if (!fields.append(field, beginIndex, endIndex)) {
return false;
}
}
ArrayObject* array = fields.toArray(cx, overallResult, nullptr);
if (!array) {
return false;
}
result.setObject(*array);
return true;
}
#endif
static bool FormatNumericToParts(JSContext* cx, const UNumberFormatter* nf,
UFormattedNumber* formatted, HandleValue x,
FormattingType formattingType,
MutableHandleValue result) {
PartitionNumberPatternResult formattedValue =
const UFormattedValue* formattedValue =
PartitionNumberPattern(cx, nf, formatted, x);
if (!formattedValue) {
return false;
}
#ifndef U_HIDE_DRAFT_API
return FormattedNumberToParts(cx, formattedValue, x, nullptr, formattingType,
result);
#else
return LegacyFormattedNumberToParts(cx, formattedValue, x, result);
#endif
}
bool js::intl_FormatNumber(JSContext* cx, unsigned argc, Value* vp) {

Просмотреть файл

@ -76,10 +76,8 @@ static const JSFunctionSpec relativeTimeFormat_methods[] = {
JS_SELF_HOSTED_FN("resolvedOptions",
"Intl_RelativeTimeFormat_resolvedOptions", 0, 0),
JS_SELF_HOSTED_FN("format", "Intl_RelativeTimeFormat_format", 2, 0),
#ifndef U_HIDE_DRAFT_API
JS_SELF_HOSTED_FN("formatToParts", "Intl_RelativeTimeFormat_formatToParts",
2, 0),
#endif
JS_FN(js_toSource_str, relativeTimeFormat_toSource, 0, 0), JS_FS_END};
static const JSPropertySpec relativeTimeFormat_properties[] = {
@ -277,7 +275,6 @@ static bool intl_FormatRelativeTime(JSContext* cx,
return true;
}
#ifndef U_HIDE_DRAFT_API
static bool intl_FormatToPartsRelativeTime(JSContext* cx,
URelativeDateTimeFormatter* rtf,
double t, URelativeDateTimeUnit unit,
@ -342,7 +339,6 @@ static bool intl_FormatToPartsRelativeTime(JSContext* cx,
return intl::FormattedRelativeTimeToParts(cx, formattedValue, t, unitType,
result);
}
#endif
bool js::intl_FormatRelativeTime(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
@ -433,15 +429,9 @@ bool js::intl_FormatRelativeTime(JSContext* cx, unsigned argc, Value* vp) {
}
}
#ifndef U_HIDE_DRAFT_API
return formatToParts
? intl_FormatToPartsRelativeTime(cx, rtf, t, relDateTimeUnit,
relDateTimeNumeric, args.rval())
: intl_FormatRelativeTime(cx, rtf, t, relDateTimeUnit,
relDateTimeNumeric, args.rval());
#else
MOZ_ASSERT(!formatToParts);
return intl_FormatRelativeTime(cx, rtf, t, relDateTimeUnit,
relDateTimeNumeric, args.rval());
#endif
}

Просмотреть файл

@ -76,11 +76,9 @@ namespace intl {
using FieldType = js::ImmutablePropertyNamePtr JSAtomState::*;
#ifndef U_HIDE_DRAFT_API
MOZ_MUST_USE bool FormattedRelativeTimeToParts(
JSContext* cx, const UFormattedValue* formattedValue, double timeValue,
FieldType relativeTimeUnit, MutableHandleValue result);
#endif
} // namespace intl
} // namespace js