mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:27:45 +00:00
LibJS: Check PlainMonthDay is in the ISO date time limits in creation
This is a normative change in the Temporal spec.
See: 374305c
This commit is contained in:
parent
61847b3cef
commit
1e829c4ea8
2 changed files with 17 additions and 7 deletions
|
@ -155,18 +155,22 @@ ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(GlobalObject& global
|
|||
if (!is_valid_iso_date(reference_iso_year, iso_month, iso_day))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainMonthDay);
|
||||
|
||||
// 4. If newTarget is not present, set newTarget to %Temporal.PlainMonthDay%.
|
||||
// 4. If ISODateTimeWithinLimits(referenceISOYear, isoMonth, isoDay, 12, 0, 0, 0, 0, 0) is false, throw a RangeError exception.
|
||||
if (!iso_date_time_within_limits(global_object, reference_iso_year, iso_month, iso_day, 12, 0, 0, 0, 0, 0))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainMonthDay);
|
||||
|
||||
// 5. If newTarget is not present, set newTarget to %Temporal.PlainMonthDay%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_plain_month_day_constructor();
|
||||
|
||||
// 5. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainMonthDay.prototype%", « [[InitializedTemporalMonthDay]], [[ISOMonth]], [[ISODay]], [[ISOYear]], [[Calendar]] »).
|
||||
// 6. Set object.[[ISOMonth]] to isoMonth.
|
||||
// 7. Set object.[[ISODay]] to isoDay.
|
||||
// 8. Set object.[[Calendar]] to calendar.
|
||||
// 9. Set object.[[ISOYear]] to referenceISOYear.
|
||||
// 6. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainMonthDay.prototype%", « [[InitializedTemporalMonthDay]], [[ISOMonth]], [[ISODay]], [[ISOYear]], [[Calendar]] »).
|
||||
// 7. Set object.[[ISOMonth]] to isoMonth.
|
||||
// 8. Set object.[[ISODay]] to isoDay.
|
||||
// 9. Set object.[[Calendar]] to calendar.
|
||||
// 10. Set object.[[ISOYear]] to referenceISOYear.
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainMonthDay>(global_object, *new_target, &GlobalObject::temporal_plain_month_day_prototype, iso_month, iso_day, reference_iso_year, calendar));
|
||||
|
||||
// 10. Return object.
|
||||
// 11. Return object.
|
||||
return object;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,12 @@ describe("errors", () => {
|
|||
new Temporal.PlainMonthDay(1, 0);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain month day");
|
||||
});
|
||||
|
||||
test("not within iso date time limit", () => {
|
||||
expect(() => {
|
||||
new Temporal.PlainMonthDay(9, 30, "iso8601", 999_999_999_999_999);
|
||||
}).toThrowWithMessage(RangeError, "Invalid plain month day");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue