Bug 1780545 - Part 3: Remove range checks from Intl.DateTimeFormat. r=dminor

Remove range check per <https://github.com/tc39/ecma402/pull/701>.

Differential Revision: https://phabricator.services.mozilla.com/D152391
This commit is contained in:
André Bargull 2022-07-27 13:58:24 +00:00
parent ce2f4684c8
commit 02a1007eb9
4 changed files with 16 additions and 27 deletions

View File

@ -585,7 +585,6 @@ MSG_DEF(JSMSG_UNDEFINED_UNIT, 0, JSEXN_TYPEERR, "undefined unit in Numb
MSG_DEF(JSMSG_UNDEFINED_DATE, 2, JSEXN_TYPEERR, "undefined {0}-date in DateTimeFormat.{1}()")
MSG_DEF(JSMSG_UNDEFINED_NUMBER, 3, JSEXN_TYPEERR, "undefined {0} number in {1}.{2}()")
MSG_DEF(JSMSG_UNDEFINED_TYPE, 0, JSEXN_TYPEERR, "missing \"type\" option in DisplayNames()")
MSG_DEF(JSMSG_START_AFTER_END_DATE, 1, JSEXN_RANGEERR, "start-date after end-date in DateTimeFormat.{0}()")
MSG_DEF(JSMSG_EXPONENT_TOO_LARGE, 0, JSEXN_RANGEERR, "exponent is too large")
MSG_DEF(JSMSG_NAN_NUMBER_RANGE, 3, JSEXN_RANGEERR, "range can't {0} with NaN in {1}.{2}()")
MSG_DEF(JSMSG_INVALID_NUMBER_OPTION, 2, JSEXN_TYPEERR, "can't set option {0} when {1} is used")

View File

@ -1407,7 +1407,6 @@ static bool PartitionDateTimeRangePattern(
ClippedTime y, bool* equal) {
MOZ_ASSERT(x.isValid());
MOZ_ASSERT(y.isValid());
MOZ_ASSERT(x.toDouble() <= y.toDouble());
// We can't access the calendar used by UDateIntervalFormat to change it to a
// proleptic Gregorian calendar. Instead we need to call a different formatter
@ -1424,7 +1423,8 @@ static bool PartitionDateTimeRangePattern(
GregorianChangeDate + msPerDay;
mozilla::intl::ICUResult result = Ok();
if (x.toDouble() < GregorianChangeDatePlusOneDay) {
if (x.toDouble() < GregorianChangeDatePlusOneDay ||
y.toDouble() < GregorianChangeDatePlusOneDay) {
// Create calendar objects for the start and end date by cloning the date
// formatter calendar. The date formatter calendar already has the correct
// time zone set and was changed to use a proleptic Gregorian calendar.
@ -1565,10 +1565,6 @@ bool js::intl_FormatDateTimeRange(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
// Self-hosted code should have checked this condition.
MOZ_ASSERT(x.toDouble() <= y.toDouble(),
"start date mustn't be after the end date");
mozilla::intl::DateTimeFormat* df =
GetOrCreateDateTimeFormat(cx, dateTimeFormat);
if (!df) {

View File

@ -667,33 +667,28 @@ function Intl_DateTimeFormat_formatRange(startDate, endDate) {
// Step 1.
var dtf = this;
// Steps 2-3.
// Step 2.
if (!IsObject(dtf) || (dtf = intl_GuardToDateTimeFormat(dtf)) === null) {
return callFunction(intl_CallDateTimeFormatMethodIfWrapped, this, startDate, endDate,
"Intl_DateTimeFormat_formatRange");
}
// Step 4.
// Step 3.
if (startDate === undefined || endDate === undefined) {
ThrowTypeError(JSMSG_UNDEFINED_DATE, startDate === undefined ? "start" : "end",
"formatRange");
}
// Step 5.
// Step 4.
var x = ToNumber(startDate);
// Step 6.
// Step 5.
var y = ToNumber(endDate);
// Step 7.
if (x > y) {
ThrowRangeError(JSMSG_START_AFTER_END_DATE, "formatRange");
}
// Ensure the DateTimeFormat internals are resolved.
getDateTimeFormatInternals(dtf);
// Step 8.
// Step 6.
return intl_FormatDateTimeRange(dtf, x, y, /* formatToParts = */ false);
}
@ -706,33 +701,28 @@ function Intl_DateTimeFormat_formatRangeToParts(startDate, endDate) {
// Step 1.
var dtf = this;
// Steps 2-3.
// Step 2.
if (!IsObject(dtf) || (dtf = intl_GuardToDateTimeFormat(dtf)) === null) {
return callFunction(intl_CallDateTimeFormatMethodIfWrapped, this, startDate, endDate,
"Intl_DateTimeFormat_formatRangeToParts");
}
// Step 4.
// Step 3.
if (startDate === undefined || endDate === undefined) {
ThrowTypeError(JSMSG_UNDEFINED_DATE, startDate === undefined ? "start" : "end",
"formatRangeToParts");
}
// Step 5.
// Step 4.
var x = ToNumber(startDate);
// Step 6.
// Step 5.
var y = ToNumber(endDate);
// Step 7.
if (x > y) {
ThrowRangeError(JSMSG_START_AFTER_END_DATE, "formatRangeToParts");
}
// Ensure the DateTimeFormat internals are resolved.
getDateTimeFormatInternals(dtf);
// Step 8.
// Step 6.
return intl_FormatDateTimeRange(dtf, x, y, /* formatToParts = */ true);
}

View File

@ -656,6 +656,10 @@ skip script test262/intl402/PluralRules/prototype/selectRange/x-greater-than-y-t
skip script test262/intl402/NumberFormat/prototype/formatRange/x-greater-than-y-throws.js
skip script test262/intl402/NumberFormat/prototype/formatRangeToParts/x-greater-than-y-throws.js
# https://github.com/tc39/test262/pull/3609
skip script test262/intl402/DateTimeFormat/prototype/formatRange/date-x-greater-than-y-throws.js
skip script test262/intl402/DateTimeFormat/prototype/formatRangeToParts/date-x-greater-than-y-throws.js
##############################################
# Enable Iterator Helpers tests in the shell #