summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-07-22 15:07:39 +0100
committerLinus Groh <mail@linusgroh.de>2022-07-22 17:10:03 +0100
commit1e829c4ea8e19ee9c1420563057846f3fff1efc6 (patch)
treedb1e498ed4b76989e7e6295bef4f25c3a9aa35e3 /Userland/Libraries/LibJS
parent61847b3cef76b99603467b7b540675cda0b8c9a4 (diff)
downloadserenity-1e829c4ea8e19ee9c1420563057846f3fff1efc6.zip
LibJS: Check PlainMonthDay is in the ISO date time limits in creation
This is a normative change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/374305c
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp18
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.js6
2 files changed, 17 insertions, 7 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp
index 85d21549e9..fbf8d44b25 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp
@@ -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;
}
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.js
index fc5b315382..109d01e28f 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainMonthDay/PlainMonthDay.js
@@ -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", () => {