mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
LibJS: Convert PlainDateTime AOs to ThrowCompletionOr
This commit is contained in:
parent
35bba1c98d
commit
d764f1c699
8 changed files with 49 additions and 71 deletions
|
@ -238,8 +238,6 @@ BigInt* round_temporal_instant(GlobalObject& global_object, BigInt const& nanose
|
|||
// 8.5.9 TemporalInstantToString ( instant, timeZone, precision ), https://tc39.es/proposal-temporal/#sec-temporal-temporalinstanttostring
|
||||
ThrowCompletionOr<String> temporal_instant_to_string(GlobalObject& global_object, Instant& instant, Value time_zone, Variant<StringView, u8> const& precision)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Assert: Type(instant) is Object.
|
||||
// 2. Assert: instant has an [[InitializedTemporalInstant]] internal slot.
|
||||
|
||||
|
@ -260,11 +258,9 @@ ThrowCompletionOr<String> temporal_instant_to_string(GlobalObject& global_object
|
|||
auto* date_time = TRY(builtin_time_zone_get_plain_date_time_for(global_object, output_time_zone, instant, *iso_calendar));
|
||||
|
||||
// 7. Let dateTimeString be ? TemporalDateTimeToString(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], undefined, precision, "never").
|
||||
auto date_time_string = temporal_date_time_to_string(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), js_undefined(), precision, "never"sv);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto date_time_string = TRY(temporal_date_time_to_string(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), js_undefined(), precision, "never"sv));
|
||||
|
||||
Optional<String> time_zone_string;
|
||||
String time_zone_string;
|
||||
|
||||
// 8. If timeZone is undefined, then
|
||||
if (time_zone.is_undefined()) {
|
||||
|
@ -278,7 +274,7 @@ ThrowCompletionOr<String> temporal_instant_to_string(GlobalObject& global_object
|
|||
}
|
||||
|
||||
// 10. Return the string-concatenation of dateTimeString and timeZoneString.
|
||||
return String::formatted("{}{}", *date_time_string, *time_zone_string);
|
||||
return String::formatted("{}{}", date_time_string, time_zone_string);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -424,14 +424,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_date_time)
|
|||
// 3. If temporalTime is undefined, then
|
||||
if (vm.argument(0).is_undefined()) {
|
||||
// a. Return ? CreateTemporalDateTime(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], 0, 0, 0, 0, 0, 0, temporalDate.[[Calendar]]).
|
||||
return create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), 0, 0, 0, 0, 0, 0, temporal_date->calendar());
|
||||
return TRY_OR_DISCARD(create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), 0, 0, 0, 0, 0, 0, temporal_date->calendar()));
|
||||
}
|
||||
|
||||
// 4. Set temporalTime to ? ToTemporalTime(temporalTime).
|
||||
auto* temporal_time = TRY_OR_DISCARD(to_temporal_time(global_object, vm.argument(0)));
|
||||
|
||||
// 5. Return ? CreateTemporalDateTime(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], temporalDate.[[Calendar]]).
|
||||
return create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_date->calendar());
|
||||
return TRY_OR_DISCARD(create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_date->calendar()));
|
||||
}
|
||||
|
||||
// 3.3.28 Temporal.PlainDate.prototype.toString ( [ options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.tostring
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <LibJS/Runtime/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Date.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||
|
@ -99,19 +100,19 @@ bool iso_date_time_within_limits(GlobalObject& global_object, i32 year, u8 month
|
|||
}
|
||||
|
||||
// 5.5.3 InterpretTemporalDateTimeFields ( calendar, fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-interprettemporaldatetimefields
|
||||
Optional<ISODateTime> interpret_temporal_date_time_fields(GlobalObject& global_object, Object& calendar, Object& fields, Object& options)
|
||||
ThrowCompletionOr<ISODateTime> interpret_temporal_date_time_fields(GlobalObject& global_object, Object& calendar, Object& fields, Object& options)
|
||||
{
|
||||
// 1. Let timeResult be ? ToTemporalTimeRecord(fields).
|
||||
auto unregulated_time_result = TRY_OR_DISCARD(to_temporal_time_record(global_object, fields));
|
||||
auto unregulated_time_result = TRY(to_temporal_time_record(global_object, fields));
|
||||
|
||||
// 2. Let temporalDate be ? DateFromFields(calendar, fields, options).
|
||||
auto* temporal_date = TRY_OR_DISCARD(date_from_fields(global_object, calendar, fields, options));
|
||||
auto* temporal_date = TRY(date_from_fields(global_object, calendar, fields, options));
|
||||
|
||||
// 3. Let overflow be ? ToTemporalOverflow(options).
|
||||
auto overflow = TRY_OR_DISCARD(to_temporal_overflow(global_object, options));
|
||||
auto overflow = TRY(to_temporal_overflow(global_object, options));
|
||||
|
||||
// 4. Let timeResult be ? RegulateTime(timeResult.[[Hour]], timeResult.[[Minute]], timeResult.[[Second]], timeResult.[[Millisecond]], timeResult.[[Microsecond]], timeResult.[[Nanosecond]], overflow).
|
||||
auto time_result = TRY_OR_DISCARD(regulate_time(global_object, unregulated_time_result.hour, unregulated_time_result.minute, unregulated_time_result.second, unregulated_time_result.millisecond, unregulated_time_result.microsecond, unregulated_time_result.nanosecond, overflow));
|
||||
auto time_result = TRY(regulate_time(global_object, unregulated_time_result.hour, unregulated_time_result.minute, unregulated_time_result.second, unregulated_time_result.millisecond, unregulated_time_result.microsecond, unregulated_time_result.nanosecond, overflow));
|
||||
|
||||
// 5. Return the Record { [[Year]]: temporalDate.[[ISOYear]], [[Month]]: temporalDate.[[ISOMonth]], [[Day]]: temporalDate.[[ISODay]], [[Hour]]: timeResult.[[Hour]], [[Minute]]: timeResult.[[Minute]], [[Second]]: timeResult.[[Second]], [[Millisecond]]: timeResult.[[Millisecond]], [[Microsecond]]: timeResult.[[Microsecond]], [[Nanosecond]]: timeResult.[[Nanosecond]] }.
|
||||
return ISODateTime {
|
||||
|
@ -128,7 +129,7 @@ Optional<ISODateTime> interpret_temporal_date_time_fields(GlobalObject& global_o
|
|||
}
|
||||
|
||||
// 5.5.4 ToTemporalDateTime ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldatetime
|
||||
PlainDateTime* to_temporal_date_time(GlobalObject& global_object, Value item, Object* options)
|
||||
ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(GlobalObject& global_object, Value item, Object* options)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
|
@ -157,7 +158,7 @@ PlainDateTime* to_temporal_date_time(GlobalObject& global_object, Value item, Ob
|
|||
auto* instant = create_temporal_instant(global_object, zoned_date_time.nanoseconds()).release_value();
|
||||
|
||||
// ii. Return ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]).
|
||||
return TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar()));
|
||||
return builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar());
|
||||
}
|
||||
|
||||
// c. If item has an [[InitializedTemporalDate]] internal slot, then
|
||||
|
@ -169,32 +170,29 @@ PlainDateTime* to_temporal_date_time(GlobalObject& global_object, Value item, Ob
|
|||
}
|
||||
|
||||
// d. Let calendar be ? GetTemporalCalendarWithISODefault(item).
|
||||
calendar = TRY_OR_DISCARD(get_temporal_calendar_with_iso_default(global_object, item_object));
|
||||
calendar = TRY(get_temporal_calendar_with_iso_default(global_object, item_object));
|
||||
|
||||
// e. Let fieldNames be ? CalendarFields(calendar, « "day", "hour", "microsecond", "millisecond", "minute", "month", "monthCode", "nanosecond", "second", "year" »).
|
||||
auto field_names = TRY_OR_DISCARD(calendar_fields(global_object, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
|
||||
auto field_names = TRY(calendar_fields(global_object, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
|
||||
|
||||
// f. Let fields be ? PrepareTemporalFields(item, fieldNames, «»).
|
||||
auto* fields = TRY_OR_DISCARD(prepare_temporal_fields(global_object, item_object, field_names, {}));
|
||||
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, {}));
|
||||
|
||||
// g. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options).
|
||||
auto maybe_result = interpret_temporal_date_time_fields(global_object, *calendar, *fields, *options);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
result = move(*maybe_result);
|
||||
result = TRY(interpret_temporal_date_time_fields(global_object, *calendar, *fields, *options));
|
||||
}
|
||||
// 3. Else,
|
||||
else {
|
||||
// a. Perform ? ToTemporalOverflow(options).
|
||||
(void)TRY_OR_DISCARD(to_temporal_overflow(global_object, *options));
|
||||
(void)TRY(to_temporal_overflow(global_object, *options));
|
||||
|
||||
// b. Let string be ? ToString(item).
|
||||
auto string = item.to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
|
||||
// c. Let result be ? ParseTemporalDateTimeString(string).
|
||||
result = TRY_OR_DISCARD(parse_temporal_date_time_string(global_object, string));
|
||||
result = TRY(parse_temporal_date_time_string(global_object, string));
|
||||
|
||||
// d. Assert: ! IsValidISODate(result.[[Year]], result.[[Month]], result.[[Day]]) is true.
|
||||
VERIFY(is_valid_iso_date(result.year, result.month, result.day));
|
||||
|
@ -203,7 +201,7 @@ PlainDateTime* to_temporal_date_time(GlobalObject& global_object, Value item, Ob
|
|||
VERIFY(is_valid_time(result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
|
||||
|
||||
// f. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
|
||||
calendar = TRY_OR_DISCARD(to_temporal_calendar_with_iso_default(global_object, result.calendar.has_value() ? js_string(vm, *result.calendar) : js_undefined()));
|
||||
calendar = TRY(to_temporal_calendar_with_iso_default(global_object, result.calendar.has_value() ? js_string(vm, *result.calendar) : js_undefined()));
|
||||
}
|
||||
|
||||
// 4. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], calendar).
|
||||
|
@ -230,7 +228,7 @@ ISODateTime balance_iso_date_time(i32 year, u8 month, u8 day, u8 hour, u8 minute
|
|||
}
|
||||
|
||||
// 5.5.6 CreateTemporalDateTime ( isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond, calendar [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporaldatetime
|
||||
PlainDateTime* create_temporal_date_time(GlobalObject& global_object, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target)
|
||||
ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(GlobalObject& global_object, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
|
@ -238,22 +236,17 @@ PlainDateTime* create_temporal_date_time(GlobalObject& global_object, i32 iso_ye
|
|||
// 2. Assert: Type(calendar) is Object.
|
||||
|
||||
// 3. If ! IsValidISODate(isoYear, isoMonth, isoDay) is false, throw a RangeError exception.
|
||||
if (!is_valid_iso_date(iso_year, iso_month, iso_day)) {
|
||||
vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidPlainDateTime);
|
||||
return {};
|
||||
}
|
||||
if (!is_valid_iso_date(iso_year, iso_month, iso_day))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDateTime);
|
||||
|
||||
// 4. If ! IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception.
|
||||
if (!is_valid_time(hour, minute, second, millisecond, microsecond, nanosecond)) {
|
||||
vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidPlainDateTime);
|
||||
return {};
|
||||
}
|
||||
if (!is_valid_time(hour, minute, second, millisecond, microsecond, nanosecond))
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDateTime);
|
||||
|
||||
// 5. If ! ISODateTimeWithinLimits(isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond) is false, then
|
||||
if (!iso_date_time_within_limits(global_object, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond)) {
|
||||
// a. Throw a RangeError exception.
|
||||
vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidPlainDateTime);
|
||||
return {};
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDateTime);
|
||||
}
|
||||
|
||||
// 6. If newTarget is not present, set it to %Temporal.PlainDateTime%.
|
||||
|
@ -271,14 +264,14 @@ PlainDateTime* create_temporal_date_time(GlobalObject& global_object, i32 iso_ye
|
|||
// 15. Set object.[[ISOMicrosecond]] to microsecond.
|
||||
// 16. Set object.[[ISONanosecond]] to nanosecond.
|
||||
// 17. Set object.[[Calendar]] to calendar.
|
||||
auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<PlainDateTime>(global_object, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, calendar));
|
||||
auto* object = TRY(ordinary_create_from_constructor<PlainDateTime>(global_object, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, calendar));
|
||||
|
||||
// 18. Return object.
|
||||
return object;
|
||||
}
|
||||
|
||||
// 5.5.7 TemporalDateTimeToString ( isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond, calendar, precision, showCalendar ), , https://tc39.es/proposal-temporal/#sec-temporal-temporaldatetimetostring
|
||||
Optional<String> temporal_date_time_to_string(GlobalObject& global_object, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<StringView, u8> const& precision, StringView show_calendar)
|
||||
ThrowCompletionOr<String> temporal_date_time_to_string(GlobalObject& global_object, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<StringView, u8> const& precision, StringView show_calendar)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
|
@ -295,8 +288,8 @@ Optional<String> temporal_date_time_to_string(GlobalObject& global_object, i32 i
|
|||
|
||||
// 8. Let calendarID be ? ToString(calendar).
|
||||
auto calendar_id = calendar.to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
|
||||
// 9. Let calendarString be ! FormatCalendarAnnotation(calendarID, showCalendar).
|
||||
auto calendar_string = format_calendar_annotation(calendar_id, show_calendar);
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||
|
||||
|
@ -51,11 +51,11 @@ private:
|
|||
|
||||
BigInt* get_epoch_from_iso_parts(GlobalObject&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond);
|
||||
bool iso_date_time_within_limits(GlobalObject&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond);
|
||||
Optional<ISODateTime> interpret_temporal_date_time_fields(GlobalObject&, Object& calendar, Object& fields, Object& options);
|
||||
PlainDateTime* to_temporal_date_time(GlobalObject&, Value item, Object* options = nullptr);
|
||||
ThrowCompletionOr<ISODateTime> interpret_temporal_date_time_fields(GlobalObject&, Object& calendar, Object& fields, Object& options);
|
||||
ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(GlobalObject&, Value item, Object* options = nullptr);
|
||||
ISODateTime balance_iso_date_time(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, i64 nanosecond);
|
||||
PlainDateTime* create_temporal_date_time(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target = nullptr);
|
||||
Optional<String> temporal_date_time_to_string(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<StringView, u8> const& precision, StringView show_calendar);
|
||||
ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target = nullptr);
|
||||
ThrowCompletionOr<String> temporal_date_time_to_string(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<StringView, u8> const& precision, StringView show_calendar);
|
||||
i8 compare_iso_date_time(i32 year1, u8 month1, u8 day1, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, i32 year2, u8 month2, u8 day2, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2);
|
||||
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ Value PlainDateTimeConstructor::construct(FunctionObject& new_target)
|
|||
}
|
||||
|
||||
// 12. Return ? CreateTemporalDateTime(isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond, calendar, NewTarget).
|
||||
return create_temporal_date_time(global_object, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, *calendar, &new_target);
|
||||
return TRY_OR_DISCARD(create_temporal_date_time(global_object, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, *calendar, &new_target));
|
||||
}
|
||||
|
||||
// 5.2.2 Temporal.PlainDateTime.from ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.from
|
||||
|
@ -111,25 +111,21 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimeConstructor::from)
|
|||
(void)TRY_OR_DISCARD(to_temporal_overflow(global_object, *options));
|
||||
|
||||
// b. Return ? CreateTemporalDateTime(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], item.[[ISOHour]], item.[[ISOMinute]], item.[[ISOSecond]], item.[[ISOMillisecond]], item.[[ISOMicrosecond]], item.[[ISONanosecond]], item.[[Calendar]]).
|
||||
return create_temporal_date_time(global_object, plain_date_time.iso_year(), plain_date_time.iso_month(), plain_date_time.iso_day(), plain_date_time.iso_hour(), plain_date_time.iso_minute(), plain_date_time.iso_second(), plain_date_time.iso_millisecond(), plain_date_time.iso_microsecond(), plain_date_time.iso_nanosecond(), plain_date_time.calendar());
|
||||
return TRY_OR_DISCARD(create_temporal_date_time(global_object, plain_date_time.iso_year(), plain_date_time.iso_month(), plain_date_time.iso_day(), plain_date_time.iso_hour(), plain_date_time.iso_minute(), plain_date_time.iso_second(), plain_date_time.iso_millisecond(), plain_date_time.iso_microsecond(), plain_date_time.iso_nanosecond(), plain_date_time.calendar()));
|
||||
}
|
||||
|
||||
// 3. Return ? ToTemporalDateTime(item, options).
|
||||
return to_temporal_date_time(global_object, item, options);
|
||||
return TRY_OR_DISCARD(to_temporal_date_time(global_object, item, options));
|
||||
}
|
||||
|
||||
// 5.2.3 Temporal.PlainDateTime.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.compare
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimeConstructor::compare)
|
||||
{
|
||||
// 1. Set one to ? ToTemporalDateTime(one).
|
||||
auto* one = to_temporal_date_time(global_object, vm.argument(0));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto* one = TRY_OR_DISCARD(to_temporal_date_time(global_object, vm.argument(0)));
|
||||
|
||||
// 2. Set two to ? ToTemporalDateTime(two).
|
||||
auto two = to_temporal_date_time(global_object, vm.argument(1));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto two = TRY_OR_DISCARD(to_temporal_date_time(global_object, vm.argument(1)));
|
||||
|
||||
// 3. Return 𝔽(! CompareISODateTime(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], one.[[ISOHour]], one.[[ISOMinute]], one.[[ISOSecond]], one.[[ISOMillisecond]], one.[[ISOMicrosecond]], one.[[ISONanosecond]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]], two.[[ISOHour]], two.[[ISOMinute]], two.[[ISOSecond]], two.[[ISOMillisecond]], two.[[ISOMicrosecond]], two.[[ISONanosecond]])).
|
||||
return Value(compare_iso_date_time(one->iso_year(), one->iso_month(), one->iso_day(), one->iso_hour(), one->iso_minute(), one->iso_second(), one->iso_millisecond(), one->iso_microsecond(), one->iso_nanosecond(), two->iso_year(), two->iso_month(), two->iso_day(), two->iso_hour(), two->iso_minute(), two->iso_second(), two->iso_millisecond(), two->iso_microsecond(), two->iso_nanosecond()));
|
||||
|
|
|
@ -392,14 +392,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with_plain_time)
|
|||
// 3. If plainTimeLike is undefined, then
|
||||
if (vm.argument(0).is_undefined()) {
|
||||
// a. Return ? CreateTemporalDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], 0, 0, 0, 0, 0, 0, dateTime.[[Calendar]]).
|
||||
return create_temporal_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), 0, 0, 0, 0, 0, 0, date_time->calendar());
|
||||
return TRY_OR_DISCARD(create_temporal_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), 0, 0, 0, 0, 0, 0, date_time->calendar()));
|
||||
}
|
||||
|
||||
// 4. Let plainTime be ? ToTemporalTime(plainTimeLike).
|
||||
auto* plain_time = TRY_OR_DISCARD(to_temporal_time(global_object, vm.argument(0)));
|
||||
|
||||
// 5. Return ? CreateTemporalDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], plainTime.[[ISOHour]], plainTime.[[ISOMinute]], plainTime.[[ISOSecond]], plainTime.[[ISOMillisecond]], plainTime.[[ISOMicrosecond]], plainTime.[[ISONanosecond]], dateTime.[[Calendar]]).
|
||||
return create_temporal_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), plain_time->iso_hour(), plain_time->iso_minute(), plain_time->iso_second(), plain_time->iso_millisecond(), plain_time->iso_microsecond(), plain_time->iso_nanosecond(), date_time->calendar());
|
||||
return TRY_OR_DISCARD(create_temporal_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), plain_time->iso_hour(), plain_time->iso_minute(), plain_time->iso_second(), plain_time->iso_millisecond(), plain_time->iso_microsecond(), plain_time->iso_nanosecond(), date_time->calendar()));
|
||||
}
|
||||
|
||||
// 5.3.24 Temporal.PlainDateTime.prototype.withPlainDate ( plainDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.withplaindate
|
||||
|
@ -418,7 +418,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with_plain_date)
|
|||
auto* calendar = TRY_OR_DISCARD(consolidate_calendars(global_object, date_time->calendar(), plain_date->calendar()));
|
||||
|
||||
// 5. Return ? CreateTemporalDateTime(plainDate.[[ISOYear]], plainDate.[[ISOMonth]], plainDate.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], calendar).
|
||||
return create_temporal_date_time(global_object, plain_date->iso_year(), plain_date->iso_month(), plain_date->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), *calendar);
|
||||
return TRY_OR_DISCARD(create_temporal_date_time(global_object, plain_date->iso_year(), plain_date->iso_month(), plain_date->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), *calendar));
|
||||
}
|
||||
|
||||
// 5.3.25 Temporal.PlainDateTime.prototype.withCalendar ( calendar ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.withcalendar
|
||||
|
@ -436,7 +436,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with_calendar)
|
|||
return {};
|
||||
|
||||
// 4. Return ? CreateTemporalDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], calendar).
|
||||
return create_temporal_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), *calendar);
|
||||
return TRY_OR_DISCARD(create_temporal_date_time(global_object, date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), *calendar));
|
||||
}
|
||||
|
||||
// 5.3.31 Temporal.PlainDateTime.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.equals
|
||||
|
@ -449,9 +449,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::equals)
|
|||
return {};
|
||||
|
||||
// 3. Set other to ? ToTemporalDateTime(other).
|
||||
auto* other = to_temporal_date_time(global_object, vm.argument(0));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto* other = TRY_OR_DISCARD(to_temporal_date_time(global_object, vm.argument(0)));
|
||||
|
||||
// 4. Let result be ! CompareISODateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], other.[[ISOYear]], other.[[ISOMonth]], other.[[ISODay]], other.[[ISOHour]], other.[[ISOMinute]], other.[[ISOSecond]], other.[[ISOMillisecond]], other.[[ISOMicrosecond]], other.[[ISONanosecond]]).
|
||||
auto result = compare_iso_date_time(date_time->iso_year(), date_time->iso_month(), date_time->iso_day(), date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(), date_time->iso_millisecond(), date_time->iso_microsecond(), date_time->iso_nanosecond(), other->iso_year(), other->iso_month(), other->iso_day(), other->iso_hour(), other->iso_minute(), other->iso_second(), other->iso_millisecond(), other->iso_microsecond(), other->iso_nanosecond());
|
||||
|
|
|
@ -291,7 +291,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_plain_date_time)
|
|||
auto* temporal_date = TRY_OR_DISCARD(to_temporal_date(global_object, vm.argument(0)));
|
||||
|
||||
// 4. Return ? CreateTemporalDateTime(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], temporalDate.[[Calendar]]).
|
||||
return create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_date->calendar());
|
||||
return TRY_OR_DISCARD(create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_date->calendar()));
|
||||
}
|
||||
|
||||
// 4.3.19 Temporal.PlainTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.getisofields
|
||||
|
|
|
@ -410,8 +410,6 @@ ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(GlobalObject&
|
|||
// 11.6.13 BuiltinTimeZoneGetPlainDateTimeFor ( timeZone, instant, calendar ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetplaindatetimefor
|
||||
ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(GlobalObject& global_object, Value time_zone, Instant& instant, Object& calendar)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Let offsetNanoseconds be ? GetOffsetNanosecondsFor(timeZone, instant).
|
||||
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(global_object, time_zone, instant));
|
||||
|
||||
|
@ -422,10 +420,7 @@ ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(Glob
|
|||
result = balance_iso_date_time(result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond + offset_nanoseconds);
|
||||
|
||||
// 4. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], calendar).
|
||||
auto* date_time = create_temporal_date_time(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, calendar);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
return date_time;
|
||||
return create_temporal_date_time(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, calendar);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue