Skip to content

Commit

Permalink
Bug 1920955 - Part 1: Ensure date-time separators are consistent. r=s…
Browse files Browse the repository at this point in the history
…fink

Request for test262 coverage: tc39/test262#4237

Differential Revision: https://phabricator.services.mozilla.com/D223506

UltraBlame original commit: 75430ad783acfc49e5aaca4178f7359695cf47e5
  • Loading branch information
marco-c committed Oct 9, 2024
1 parent 44c463b commit 66b4eef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
2 changes: 2 additions & 0 deletions js/public/friend/ErrorNumbers.msg
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,8 @@ MSG_DEF(JSMSG_TEMPORAL_PARSER_INVALID_UTC_DESIGNATOR_WITHOUT_NAME, 0, JSEXN_RANG
MSG_DEF(JSMSG_TEMPORAL_PARSER_MONTH_DAY_CALENDAR_NOT_ISO8601, 0, JSEXN_RANGEERR, "Month-Day formats only support the \"iso8601\" calendar")
MSG_DEF(JSMSG_TEMPORAL_PARSER_YEAR_MONTH_CALENDAR_NOT_ISO8601, 0, JSEXN_RANGEERR, "Year-Month formats only support the \"iso8601\" calendar")
MSG_DEF(JSMSG_TEMPORAL_PARSER_INVALID_SUBMINUTE_TIMEZONE, 0, JSEXN_RANGEERR, "time zone offset must not contain seconds precision")
MSG_DEF(JSMSG_TEMPORAL_PARSER_INCONSISTENT_DATE_SEPARATOR, 0, JSEXN_RANGEERR, "date separator '-' must be consistent")
MSG_DEF(JSMSG_TEMPORAL_PARSER_INCONSISTENT_TIME_SEPARATOR, 0, JSEXN_RANGEERR, "time separator ':' must be consistent")



Expand Down
35 changes: 25 additions & 10 deletions js/src/builtin/temporal/TemporalParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ mozilla::Result<PlainDate, ParserError> TemporalParser<CharT>::date() {
}


character('-');
bool hasMonthSeparator = character('-');



Expand All @@ -1003,7 +1003,12 @@ mozilla::Result<PlainDate, ParserError> TemporalParser<CharT>::date() {
}


character('-');
bool hasDaySeparator = character('-');


if (hasMonthSeparator != hasDaySeparator) {
return mozilla::Err(JSMSG_TEMPORAL_PARSER_INCONSISTENT_DATE_SEPARATOR);
}



Expand Down Expand Up @@ -1053,7 +1058,7 @@ mozilla::Result<PlainTime, ParserError> TemporalParser<CharT>::timeSpec() {
}


bool needsMinutes = character(':');
bool hasMinuteSeparator = character(':');



Expand All @@ -1072,7 +1077,7 @@ mozilla::Result<PlainTime, ParserError> TemporalParser<CharT>::timeSpec() {
}


bool needsSeconds = needsMinutes && character(':');
bool hasSecondSeparator = character(':');



Expand All @@ -1084,17 +1089,22 @@ mozilla::Result<PlainTime, ParserError> TemporalParser<CharT>::timeSpec() {
}


if (hasMinuteSeparator != hasSecondSeparator) {
return mozilla::Err(JSMSG_TEMPORAL_PARSER_INCONSISTENT_TIME_SEPARATOR);
}



if (auto f = fraction()) {
int32_t fractionalPart = f.value();
result.millisecond = fractionalPart / 1'000'000;
result.microsecond = (fractionalPart % 1'000'000) / 1'000;
result.nanosecond = fractionalPart % 1'000;
}
} else if (needsSeconds) {
} else if (hasSecondSeparator) {
return mozilla::Err(JSMSG_TEMPORAL_PARSER_MISSING_SECOND);
}
} else if (needsMinutes) {
} else if (hasMinuteSeparator) {
return mozilla::Err(JSMSG_TEMPORAL_PARSER_MISSING_MINUTE);
}

Expand Down Expand Up @@ -1231,7 +1241,7 @@ TemporalParser<CharT>::utcOffsetSubMinutePrecision() {



bool needsMinutes = character(':');
bool hasMinuteSeparator = character(':');



Expand All @@ -1249,7 +1259,7 @@ TemporalParser<CharT>::utcOffsetSubMinutePrecision() {



bool needsSeconds = needsMinutes && character(':');
bool hasSecondSeparator = character(':');



Expand All @@ -1264,15 +1274,20 @@ TemporalParser<CharT>::utcOffsetSubMinutePrecision() {
return mozilla::Err(JSMSG_TEMPORAL_PARSER_INVALID_SECOND);
}


if (hasMinuteSeparator != hasSecondSeparator) {
return mozilla::Err(JSMSG_TEMPORAL_PARSER_INCONSISTENT_TIME_SEPARATOR);
}

if (auto fractionalPart = fraction()) {
result.fractionalPart = fractionalPart.value();
}

result.subMinutePrecision = true;
} else if (needsSeconds) {
} else if (hasSecondSeparator) {
return mozilla::Err(JSMSG_TEMPORAL_PARSER_MISSING_SECOND);
}
} else if (needsMinutes) {
} else if (hasMinuteSeparator) {
return mozilla::Err(JSMSG_TEMPORAL_PARSER_MISSING_MINUTE);
}

Expand Down

0 comments on commit 66b4eef

Please sign in to comment.