mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:37:35 +00:00
LibJS: Adjust grammar for DateExtendedYear to exclude -000000
This is an editorial change in the Temporal spec.
See: fb3e656
We lose the custom error message, but it's not the end of the world.
This commit is contained in:
parent
68af8649fb
commit
54af3a5396
8 changed files with 28 additions and 30 deletions
|
@ -236,7 +236,6 @@
|
|||
M(TemporalInvalidDurationString, "Invalid duration string '{}'") \
|
||||
M(TemporalInvalidDurationStringFractionNotLast, "Invalid duration string '{}': fractional {} must not be proceeded by {}") \
|
||||
M(TemporalInvalidEpochNanoseconds, "Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17") \
|
||||
M(TemporalInvalidExtendedYearNegativeZero, "Invalid extended year, must not be negative zero") \
|
||||
M(TemporalInvalidInstantString, "Invalid instant string '{}'") \
|
||||
M(TemporalInvalidISODate, "Invalid ISO date") \
|
||||
M(TemporalInvalidMonthCode, "Invalid month code") \
|
||||
|
|
|
@ -1113,47 +1113,43 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject& global_object,
|
|||
else
|
||||
normalized_year = year_part.value_or("0");
|
||||
|
||||
// 7. If SameValue(year, "-000000") is true, throw a RangeError exception.
|
||||
if (normalized_year == "-000000"sv)
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidExtendedYearNegativeZero);
|
||||
|
||||
// 8. Set year to ! ToIntegerOrInfinity(year).
|
||||
// 7. Set year to ! ToIntegerOrInfinity(year).
|
||||
auto year = *normalized_year.to_int<i32>();
|
||||
|
||||
u8 month;
|
||||
// 9. If month is undefined, then
|
||||
// 8. If month is undefined, then
|
||||
if (!month_part.has_value()) {
|
||||
// a. Set month to 1.
|
||||
month = 1;
|
||||
}
|
||||
// 10. Else,
|
||||
// 9. Else,
|
||||
else {
|
||||
// a. Set month to ! ToIntegerOrInfinity(month).
|
||||
month = *month_part->to_uint<u8>();
|
||||
}
|
||||
|
||||
u8 day;
|
||||
// 11. If day is undefined, then
|
||||
// 10. If day is undefined, then
|
||||
if (!day_part.has_value()) {
|
||||
// a. Set day to 1.
|
||||
day = 1;
|
||||
}
|
||||
// 12. Else,
|
||||
// 11. Else,
|
||||
else {
|
||||
// a. Set day to ! ToIntegerOrInfinity(day).
|
||||
day = *day_part->to_uint<u8>();
|
||||
}
|
||||
|
||||
// 13. Set hour to ! ToIntegerOrInfinity(hour).
|
||||
// 12. Set hour to ! ToIntegerOrInfinity(hour).
|
||||
u8 hour = *hour_part.value_or("0"sv).to_uint<u8>();
|
||||
|
||||
// 14. Set minute to ! ToIntegerOrInfinity(minute).
|
||||
// 13. Set minute to ! ToIntegerOrInfinity(minute).
|
||||
u8 minute = *minute_part.value_or("0"sv).to_uint<u8>();
|
||||
|
||||
// 15. Set second to ! ToIntegerOrInfinity(second).
|
||||
// 14. Set second to ! ToIntegerOrInfinity(second).
|
||||
u8 second = *second_part.value_or("0"sv).to_uint<u8>();
|
||||
|
||||
// 16. If second is 60, then
|
||||
// 15. If second is 60, then
|
||||
if (second == 60) {
|
||||
// a. Set second to 59.
|
||||
second = 59;
|
||||
|
@ -1162,7 +1158,7 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject& global_object,
|
|||
u16 millisecond;
|
||||
u16 microsecond;
|
||||
u16 nanosecond;
|
||||
// 17. If fraction is not undefined, then
|
||||
// 16. If fraction is not undefined, then
|
||||
if (fraction_part.has_value()) {
|
||||
// a. Set fraction to the string-concatenation of the previous value of fraction and the string "000000000".
|
||||
auto fraction = String::formatted("{}000000000", *fraction_part);
|
||||
|
@ -1176,7 +1172,7 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject& global_object,
|
|||
// g. Set nanosecond to ! ToIntegerOrInfinity(nanosecond).
|
||||
nanosecond = *fraction.substring(7, 3).to_uint<u16>();
|
||||
}
|
||||
// 18. Else,
|
||||
// 17. Else,
|
||||
else {
|
||||
// a. Let millisecond be 0.
|
||||
millisecond = 0;
|
||||
|
@ -1186,15 +1182,15 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(GlobalObject& global_object,
|
|||
nanosecond = 0;
|
||||
}
|
||||
|
||||
// 19. If ! IsValidISODate(year, month, day) is false, throw a RangeError exception.
|
||||
// 18. If ! IsValidISODate(year, month, day) is false, throw a RangeError exception.
|
||||
if (!is_valid_iso_date(year, month, day))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidISODate);
|
||||
|
||||
// 20. If ! IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
|
||||
// 19. If ! IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
|
||||
if (!is_valid_time(hour, minute, second, millisecond, microsecond, nanosecond))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidTime);
|
||||
|
||||
// 21. Return the Record { [[Year]]: year, [[Month]]: month, [[Day]]: day, [[Hour]]: hour, [[Minute]]: minute, [[Second]]: second, [[Millisecond]]: millisecond, [[Microsecond]]: microsecond, [[Nanosecond]]: nanosecond, [[Calendar]]: calendar }.
|
||||
// 20. Return the Record { [[Year]]: year, [[Month]]: month, [[Day]]: day, [[Hour]]: hour, [[Minute]]: minute, [[Second]]: second, [[Millisecond]]: millisecond, [[Microsecond]]: microsecond, [[Nanosecond]]: nanosecond, [[Calendar]]: calendar }.
|
||||
return ISODateTime { .year = year, .month = month, .day = day, .hour = hour, .minute = minute, .second = second, .millisecond = millisecond, .microsecond = microsecond, .nanosecond = nanosecond, .calendar = Optional<String>(move(calendar_part)) };
|
||||
}
|
||||
|
||||
|
|
|
@ -265,6 +265,9 @@ bool ISO8601Parser::parse_date_year()
|
|||
return false;
|
||||
}
|
||||
}
|
||||
// It is a Syntax Error if DateExtendedYear is "-000000" or "−000000" (U+2212 MINUS SIGN followed by 000000).
|
||||
if (transaction.parsed_string_view().is_one_of("-000000"sv, "−000000"sv))
|
||||
return false;
|
||||
m_state.parse_result.date_year = transaction.parsed_string_view();
|
||||
transaction.commit();
|
||||
return true;
|
||||
|
|
|
@ -53,9 +53,9 @@ describe("errors", () => {
|
|||
test("extended year must not be negative zero", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainDate.from("-000000-01-01");
|
||||
}).toThrowWithMessage(RangeError, "Invalid extended year, must not be negative zero");
|
||||
}).toThrowWithMessage(RangeError, "Invalid date string '-000000-01-01'");
|
||||
expect(() => {
|
||||
Temporal.PlainDate.from("−000000-01-01"); // U+2212
|
||||
}).toThrowWithMessage(RangeError, "Invalid extended year, must not be negative zero");
|
||||
}).toThrowWithMessage(RangeError, "Invalid date string '−000000-01-01'");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -190,9 +190,9 @@ describe("errors", () => {
|
|||
test("extended year must not be negative zero", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainDateTime.from("-000000-01-01");
|
||||
}).toThrowWithMessage(RangeError, "Invalid extended year, must not be negative zero");
|
||||
}).toThrowWithMessage(RangeError, "Invalid date time string '-000000-01-01'");
|
||||
expect(() => {
|
||||
Temporal.PlainDateTime.from("−000000-01-01"); // U+2212
|
||||
}).toThrowWithMessage(RangeError, "Invalid extended year, must not be negative zero");
|
||||
}).toThrowWithMessage(RangeError, "Invalid date time string '−000000-01-01'");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -79,9 +79,9 @@ describe("errors", () => {
|
|||
test("extended year must not be negative zero", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainMonthDay.from("-000000-01-01");
|
||||
}).toThrowWithMessage(RangeError, "Invalid extended year, must not be negative zero");
|
||||
}).toThrowWithMessage(RangeError, "Invalid month day string '-000000-01-01'");
|
||||
expect(() => {
|
||||
Temporal.PlainMonthDay.from("−000000-01-01"); // U+2212
|
||||
}).toThrowWithMessage(RangeError, "Invalid extended year, must not be negative zero");
|
||||
}).toThrowWithMessage(RangeError, "Invalid month day string '−000000-01-01'");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -68,10 +68,10 @@ describe("errors", () => {
|
|||
test("extended year must not be negative zero", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainTime.from("-000000-01-01T00:00:00");
|
||||
}).toThrowWithMessage(RangeError, "Invalid extended year, must not be negative zero");
|
||||
}).toThrowWithMessage(RangeError, "Invalid time string '-000000-01-01T00:00:00'");
|
||||
expect(() => {
|
||||
Temporal.PlainTime.from("−000000-01-01T00:00:00"); // U+2212
|
||||
}).toThrowWithMessage(RangeError, "Invalid extended year, must not be negative zero");
|
||||
}).toThrowWithMessage(RangeError, "Invalid time string '−000000-01-01T00:00:00'");
|
||||
});
|
||||
|
||||
test("ambiguous string must contain a time designator", () => {
|
||||
|
|
|
@ -105,9 +105,9 @@ describe("errors", () => {
|
|||
test("extended year must not be negative zero", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainYearMonth.from("-000000-01");
|
||||
}).toThrowWithMessage(RangeError, "Invalid extended year, must not be negative zero");
|
||||
}).toThrowWithMessage(RangeError, "Invalid year month string '-000000-01'");
|
||||
expect(() => {
|
||||
Temporal.PlainYearMonth.from("−000000-01-01"); // U+2212
|
||||
}).toThrowWithMessage(RangeError, "Invalid extended year, must not be negative zero");
|
||||
Temporal.PlainYearMonth.from("−000000-01"); // U+2212
|
||||
}).toThrowWithMessage(RangeError, "Invalid year month string '−000000-01'");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue