diff options
author | Linus Groh <mail@linusgroh.de> | 2021-11-06 17:38:51 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-11-07 15:31:28 +0100 |
commit | 36b51276d5c0eafeedd1082d08d98663f763170c (patch) | |
tree | 5fed4f1c099d9582de721d634701d2318a514809 | |
parent | 706296374b781225814529e0c3a07b4a5f0eb371 (diff) | |
download | serenity-36b51276d5c0eafeedd1082d08d98663f763170c.zip |
LibJS: Change calendar_date_add() date parameter from PlainDate to Value
Turns out use of this AO is a bit more flexible than I anticipated.
5 files changed, 8 insertions, 7 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index 6e2e3bbcd2..1a86899b31 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -137,8 +137,9 @@ ThrowCompletionOr<Object*> calendar_merge_fields(GlobalObject& global_object, Ob } // 12.1.7 CalendarDateAdd ( calendar, date, duration, options [ , dateAdd ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateadd -ThrowCompletionOr<PlainDate*> calendar_date_add(GlobalObject& global_object, Object& calendar, PlainDate& date, Duration& duration, Object* options, FunctionObject* date_add) +ThrowCompletionOr<PlainDate*> calendar_date_add(GlobalObject& global_object, Object& calendar, Value date, Duration& duration, Object* options, FunctionObject* date_add) { + // NOTE: `date` is a `Value` because we sometimes need to pass a PlainDate, sometimes a PlainDateTime, and sometimes undefined. auto& vm = global_object.vm(); // 1. Assert: Type(calendar) is Object. @@ -148,7 +149,7 @@ ThrowCompletionOr<PlainDate*> calendar_date_add(GlobalObject& global_object, Obj date_add = TRY(Value(&calendar).get_method(global_object, vm.names.dateAdd)); // 3. Let addedDate be ? Call(dateAdd, calendar, ยซ date, duration, options ยป). - auto added_date = TRY(call(global_object, date_add ?: js_undefined(), &calendar, &date, &duration, options ?: js_undefined())); + auto added_date = TRY(call(global_object, date_add ?: js_undefined(), &calendar, date, &duration, options ?: js_undefined())); // 4. Perform ? RequireInternalSlot(addedDate, [[InitializedTemporalDate]]). auto* added_date_object = TRY(added_date.to_object(global_object)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h index a330fb807b..5b2da3de5c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h @@ -36,7 +36,7 @@ ThrowCompletionOr<Calendar*> get_builtin_calendar(GlobalObject&, String const& i Calendar* get_iso8601_calendar(GlobalObject&); ThrowCompletionOr<Vector<String>> calendar_fields(GlobalObject&, Object& calendar, Vector<StringView> const& field_names); ThrowCompletionOr<Object*> calendar_merge_fields(GlobalObject&, Object& calendar, Object& fields, Object& additional_fields); -ThrowCompletionOr<PlainDate*> calendar_date_add(GlobalObject&, Object& calendar, PlainDate&, Duration&, Object* options, FunctionObject* date_add = nullptr); +ThrowCompletionOr<PlainDate*> calendar_date_add(GlobalObject&, Object& calendar, Value date, Duration&, Object* options, FunctionObject* date_add = nullptr); ThrowCompletionOr<Duration*> calendar_date_until(GlobalObject&, Object& calendar, PlainDate& one, PlainDate& two, Object& options, FunctionObject* date_until = nullptr); ThrowCompletionOr<double> calendar_year(GlobalObject&, Object& calendar, Object& date_like); ThrowCompletionOr<double> calendar_month(GlobalObject&, Object& calendar, Object& date_like); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp index 854f599c21..9118fd3287 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp @@ -355,7 +355,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::add) auto* options = TRY(get_options_object(global_object, vm.argument(1))); // 5. Return ? CalendarDateAdd(temporalDate.[[Calendar]], temporalDate, duration, options). - return TRY(calendar_date_add(global_object, temporal_date->calendar(), *temporal_date, *duration, options)); + return TRY(calendar_date_add(global_object, temporal_date->calendar(), temporal_date, *duration, options)); } // 3.3.20 Temporal.PlainDate.prototype.subtract ( temporalDurationLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.subtract @@ -375,7 +375,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::subtract) auto* negated_duration = create_negated_temporal_duration(global_object, *duration); // 6. Return ? CalendarDateAdd(temporalDate.[[Calendar]], temporalDate, negatedDuration, options). - return TRY(calendar_date_add(global_object, temporal_date->calendar(), *temporal_date, *negated_duration, options)); + return TRY(calendar_date_add(global_object, temporal_date->calendar(), temporal_date, *negated_duration, options)); } // 3.3.22 Temporal.PlainDate.prototype.withCalendar ( calendar ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.withcalendar diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp index 11f62fdbca..cacdd6cf02 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp @@ -327,7 +327,7 @@ ThrowCompletionOr<TemporalPlainDateTime> add_date_time(GlobalObject& global_obje auto* date_duration = TRY(create_temporal_duration(global_object, years, months, weeks, days + time_result.days, 0, 0, 0, 0, 0, 0)); // 5. Let addedDate be ? CalendarDateAdd(calendar, datePart, dateDuration, options). - auto* added_date = TRY(calendar_date_add(global_object, calendar, *date_part, *date_duration, options)); + auto* added_date = TRY(calendar_date_add(global_object, calendar, date_part, *date_duration, options)); // 6. Return the Record { [[Year]]: addedDate.[[ISOYear]], [[Month]]: addedDate.[[ISOMonth]], [[Day]]: addedDate.[[ISODay]], [[Hour]]: timeResult.[[Hour]], [[Minute]]: timeResult.[[Minute]], [[Second]]: timeResult.[[Second]], [[Millisecond]]: timeResult.[[Millisecond]], [[Microsecond]]: timeResult.[[Microsecond]], [[Nanosecond]]: timeResult.[[Nanosecond]] }. return TemporalPlainDateTime { .year = added_date->iso_year(), .month = added_date->iso_month(), .day = added_date->iso_day(), .hour = time_result.hour, .minute = time_result.minute, .second = time_result.second, .millisecond = time_result.millisecond, .microsecond = time_result.microsecond, .nanosecond = time_result.nanosecond }; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp index c317789a19..5de69bed16 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp @@ -300,7 +300,7 @@ ThrowCompletionOr<BigInt*> add_zoned_date_time(GlobalObject& global_object, BigI auto* date_duration = TRY(create_temporal_duration(global_object, years, months, weeks, days, 0, 0, 0, 0, 0, 0)); // 7. Let addedDate be ? CalendarDateAdd(calendar, datePart, dateDuration, options). - auto* added_date = TRY(calendar_date_add(global_object, calendar, *date_part, *date_duration, options)); + auto* added_date = TRY(calendar_date_add(global_object, calendar, date_part, *date_duration, options)); // 8. Let intermediateDateTime be ? CreateTemporalDateTime(addedDate.[[ISOYear]], addedDate.[[ISOMonth]], addedDate.[[ISODay]], temporalDateTime.[[ISOHour]], temporalDateTime.[[ISOMinute]], temporalDateTime.[[ISOSecond]], temporalDateTime.[[ISOMillisecond]], temporalDateTime.[[ISOMicrosecond]], temporalDateTime.[[ISONanosecond]], calendar). auto* intermediate_date_time = TRY(create_temporal_date_time(global_object, added_date->iso_year(), added_date->iso_month(), added_date->iso_day(), temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond(), calendar)); |