diff options
author | Linus Groh <mail@linusgroh.de> | 2022-07-05 19:25:01 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-05 23:15:52 +0200 |
commit | fec5d8d5310000fc95cfffa7d1ef20ecd0d29c01 (patch) | |
tree | 88502d2be9e3eb96ab6fc4296b28181a1dc58476 | |
parent | c3567faa8c2ca2918ee103bb817c930c0f0b2b7c (diff) | |
download | serenity-fec5d8d5310000fc95cfffa7d1ef20ecd0d29c01.zip |
LibJS: Consistently check Temporal overflow options
This is a normative change in the Temporal spec.
See: https://github.com/tc39/proposal-temporal/commit/c8ee2bd
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp | 12 |
2 files changed, 20 insertions, 7 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp index aee6ff126d..602f6e03eb 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp @@ -100,20 +100,27 @@ ThrowCompletionOr<PlainDate*> to_temporal_date(GlobalObject& global_object, Valu if (is<ZonedDateTime>(item_object)) { auto& zoned_date_time = static_cast<ZonedDateTime&>(item_object); - // i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]). + // i. Perform ? ToTemporalOverflow(options). + (void)TRY(to_temporal_overflow(global_object, options)); + + // ii. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]). auto* instant = create_temporal_instant(global_object, zoned_date_time.nanoseconds()).release_value(); - // ii. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]). + // iii. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]). auto* plain_date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar())); - // iii. Return ! CreateTemporalDate(plainDateTime.[[ISOYear]], plainDateTime.[[ISOMonth]], plainDateTime.[[ISODay]], plainDateTime.[[Calendar]]). + // iv. Return ! CreateTemporalDate(plainDateTime.[[ISOYear]], plainDateTime.[[ISOMonth]], plainDateTime.[[ISODay]], plainDateTime.[[Calendar]]). return create_temporal_date(global_object, plain_date_time->iso_year(), plain_date_time->iso_month(), plain_date_time->iso_day(), plain_date_time->calendar()); } // c. If item has an [[InitializedTemporalDateTime]] internal slot, then if (is<PlainDateTime>(item_object)) { auto& date_time_item = static_cast<PlainDateTime&>(item_object); - // i. Return ! CreateTemporalDate(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], item.[[Calendar]]). + + // i. Perform ? ToTemporalOverflow(options). + (void)TRY(to_temporal_overflow(global_object, options)); + + // ii. Return ! CreateTemporalDate(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], item.[[Calendar]]). return create_temporal_date(global_object, date_time_item.iso_year(), date_time_item.iso_month(), date_time_item.iso_day(), date_time_item.calendar()); } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp index 0be5940c51..69e4a7e5e4 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp @@ -148,10 +148,13 @@ ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(GlobalObject& global_obj if (is<ZonedDateTime>(item_object)) { auto& zoned_date_time = static_cast<ZonedDateTime&>(item_object); - // i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]). + // i. Perform ? ToTemporalOverflow(options). + (void)TRY(to_temporal_overflow(global_object, options)); + + // ii. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]). auto* instant = create_temporal_instant(global_object, zoned_date_time.nanoseconds()).release_value(); - // ii. Return ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]). + // iii. Return ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]). return builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar()); } @@ -159,7 +162,10 @@ ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(GlobalObject& global_obj if (is<PlainDate>(item_object)) { auto& plain_date = static_cast<PlainDate&>(item_object); - // i. Return ? CreateTemporalDateTime(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], 0, 0, 0, 0, 0, 0, item.[[Calendar]]). + // i. Perform ? ToTemporalOverflow(options). + (void)TRY(to_temporal_overflow(global_object, options)); + + // ii. Return ? CreateTemporalDateTime(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], 0, 0, 0, 0, 0, 0, item.[[Calendar]]). return create_temporal_date_time(global_object, plain_date.iso_year(), plain_date.iso_month(), plain_date.iso_day(), 0, 0, 0, 0, 0, 0, plain_date.calendar()); } |