mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 07:17:35 +00:00
LibJS: Remove redundant TemporalDateString production
This is an editorial change in the Temporal spec.
See: 41a8a5c
This commit is contained in:
parent
33f53041e7
commit
51e01b5a80
5 changed files with 8 additions and 38 deletions
|
@ -226,8 +226,6 @@
|
||||||
M(TemporalInvalidCalendarFunctionResult, "Invalid calendar, {}() function returned {}") \
|
M(TemporalInvalidCalendarFunctionResult, "Invalid calendar, {}() function returned {}") \
|
||||||
M(TemporalInvalidCalendarIdentifier, "Invalid calendar identifier '{}'") \
|
M(TemporalInvalidCalendarIdentifier, "Invalid calendar identifier '{}'") \
|
||||||
M(TemporalInvalidCalendarString, "Invalid calendar string '{}'") \
|
M(TemporalInvalidCalendarString, "Invalid calendar string '{}'") \
|
||||||
M(TemporalInvalidDateString, "Invalid date string '{}'") \
|
|
||||||
M(TemporalInvalidDateStringUTCDesignator, "Invalid date string '{}': must not contain a UTC designator") \
|
|
||||||
M(TemporalInvalidDateTimeString, "Invalid date time string '{}'") \
|
M(TemporalInvalidDateTimeString, "Invalid date time string '{}'") \
|
||||||
M(TemporalInvalidDateTimeStringUTCDesignator, "Invalid date time string '{}': must not contain a UTC designator") \
|
M(TemporalInvalidDateTimeStringUTCDesignator, "Invalid date time string '{}': must not contain a UTC designator") \
|
||||||
M(TemporalInvalidDuration, "Invalid duration") \
|
M(TemporalInvalidDuration, "Invalid duration") \
|
||||||
|
|
|
@ -1291,28 +1291,11 @@ ThrowCompletionOr<String> parse_temporal_calendar_string(GlobalObject& global_ob
|
||||||
// 13.35 ParseTemporalDateString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldatestring
|
// 13.35 ParseTemporalDateString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldatestring
|
||||||
ThrowCompletionOr<TemporalDate> parse_temporal_date_string(GlobalObject& global_object, String const& iso_string)
|
ThrowCompletionOr<TemporalDate> parse_temporal_date_string(GlobalObject& global_object, String const& iso_string)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
// 1. Let parts be ? ParseTemporalDateTimeString(isoString).
|
||||||
|
auto parts = TRY(parse_temporal_date_time_string(global_object, iso_string));
|
||||||
|
|
||||||
// 1. Assert: Type(isoString) is String.
|
// 2. Return the Record { [[Year]]: parts.[[Year]], [[Month]]: parts.[[Month]], [[Day]]: parts.[[Day]], [[Calendar]]: parts.[[Calendar]] }.
|
||||||
|
return TemporalDate { .year = parts.year, .month = parts.month, .day = parts.day, .calendar = move(parts.calendar) };
|
||||||
// 2. If isoString does not satisfy the syntax of a TemporalDateString (see 13.33), then
|
|
||||||
auto parse_result = parse_iso8601(Production::TemporalDateString, iso_string);
|
|
||||||
if (!parse_result.has_value()) {
|
|
||||||
// a. Throw a RangeError exception.
|
|
||||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidDateString, iso_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. If isoString contains a UTCDesignator, then
|
|
||||||
if (parse_result->utc_designator.has_value()) {
|
|
||||||
// a. Throw a RangeError exception.
|
|
||||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidDateStringUTCDesignator, iso_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Let result be ? ParseISODateTime(isoString).
|
|
||||||
auto result = TRY(parse_iso_date_time(global_object, *parse_result));
|
|
||||||
|
|
||||||
// 5. Return the Record { [[Year]]: result.[[Year]], [[Month]]: result.[[Month]], [[Day]]: result.[[Day]], [[Calendar]]: result.[[Calendar]] }.
|
|
||||||
return TemporalDate { .year = result.year, .month = result.month, .day = result.day, .calendar = move(result.calendar) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13.36 ParseTemporalDateTimeString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldatetimestring
|
// 13.36 ParseTemporalDateTimeString ( isoString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaldatetimestring
|
||||||
|
|
|
@ -1610,14 +1610,6 @@ bool ISO8601Parser::parse_temporal_instant_string()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://tc39.es/proposal-temporal/#prod-TemporalDateString
|
|
||||||
bool ISO8601Parser::parse_temporal_date_string()
|
|
||||||
{
|
|
||||||
// TemporalDateString :
|
|
||||||
// CalendarDateTime
|
|
||||||
return parse_calendar_date_time();
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://tc39.es/proposal-temporal/#prod-TemporalDateTimeString
|
// https://tc39.es/proposal-temporal/#prod-TemporalDateTimeString
|
||||||
bool ISO8601Parser::parse_temporal_date_time_string()
|
bool ISO8601Parser::parse_temporal_date_time_string()
|
||||||
{
|
{
|
||||||
|
@ -1745,7 +1737,6 @@ bool ISO8601Parser::parse_temporal_relative_to_string()
|
||||||
|
|
||||||
#define JS_ENUMERATE_ISO8601_PRODUCTION_PARSERS \
|
#define JS_ENUMERATE_ISO8601_PRODUCTION_PARSERS \
|
||||||
__JS_ENUMERATE(TemporalInstantString, parse_temporal_instant_string) \
|
__JS_ENUMERATE(TemporalInstantString, parse_temporal_instant_string) \
|
||||||
__JS_ENUMERATE(TemporalDateString, parse_temporal_date_string) \
|
|
||||||
__JS_ENUMERATE(TemporalDateTimeString, parse_temporal_date_time_string) \
|
__JS_ENUMERATE(TemporalDateTimeString, parse_temporal_date_time_string) \
|
||||||
__JS_ENUMERATE(TemporalDurationString, parse_temporal_duration_string) \
|
__JS_ENUMERATE(TemporalDurationString, parse_temporal_duration_string) \
|
||||||
__JS_ENUMERATE(TemporalMonthDayString, parse_temporal_month_day_string) \
|
__JS_ENUMERATE(TemporalMonthDayString, parse_temporal_month_day_string) \
|
||||||
|
|
|
@ -52,7 +52,6 @@ struct ParseResult {
|
||||||
|
|
||||||
enum class Production {
|
enum class Production {
|
||||||
TemporalInstantString,
|
TemporalInstantString,
|
||||||
TemporalDateString,
|
|
||||||
TemporalDateTimeString,
|
TemporalDateTimeString,
|
||||||
TemporalDurationString,
|
TemporalDurationString,
|
||||||
TemporalMonthDayString,
|
TemporalMonthDayString,
|
||||||
|
@ -174,7 +173,6 @@ public:
|
||||||
[[nodiscard]] bool parse_duration_date();
|
[[nodiscard]] bool parse_duration_date();
|
||||||
[[nodiscard]] bool parse_duration();
|
[[nodiscard]] bool parse_duration();
|
||||||
[[nodiscard]] bool parse_temporal_instant_string();
|
[[nodiscard]] bool parse_temporal_instant_string();
|
||||||
[[nodiscard]] bool parse_temporal_date_string();
|
|
||||||
[[nodiscard]] bool parse_temporal_date_time_string();
|
[[nodiscard]] bool parse_temporal_date_time_string();
|
||||||
[[nodiscard]] bool parse_temporal_duration_string();
|
[[nodiscard]] bool parse_temporal_duration_string();
|
||||||
[[nodiscard]] bool parse_temporal_month_day_string();
|
[[nodiscard]] bool parse_temporal_month_day_string();
|
||||||
|
|
|
@ -44,18 +44,18 @@ describe("errors", () => {
|
||||||
}).toThrowWithMessage(TypeError, "null is not a function");
|
}).toThrowWithMessage(TypeError, "null is not a function");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("invalid date string", () => {
|
test("invalid date time string", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
Temporal.PlainDate.from("foo");
|
Temporal.PlainDate.from("foo");
|
||||||
}).toThrowWithMessage(RangeError, "Invalid date string 'foo'");
|
}).toThrowWithMessage(RangeError, "Invalid date time string 'foo'");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("extended year must not be negative zero", () => {
|
test("extended year must not be negative zero", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
Temporal.PlainDate.from("-000000-01-01");
|
Temporal.PlainDate.from("-000000-01-01");
|
||||||
}).toThrowWithMessage(RangeError, "Invalid date string '-000000-01-01'");
|
}).toThrowWithMessage(RangeError, "Invalid date time string '-000000-01-01'");
|
||||||
expect(() => {
|
expect(() => {
|
||||||
Temporal.PlainDate.from("−000000-01-01"); // U+2212
|
Temporal.PlainDate.from("−000000-01-01"); // U+2212
|
||||||
}).toThrowWithMessage(RangeError, "Invalid date string '−000000-01-01'");
|
}).toThrowWithMessage(RangeError, "Invalid date time string '−000000-01-01'");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue