mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +00:00
LibJS: Convert Temporal.PlainDate functions to ThrowCompletionOr
This commit is contained in:
parent
df67f4978e
commit
2093128b24
4 changed files with 144 additions and 145 deletions
|
@ -30,8 +30,8 @@ void PlainDateConstructor::initialize(GlobalObject& global_object)
|
|||
define_direct_property(vm.names.prototype, global_object.temporal_plain_date_prototype(), 0);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_old_native_function(vm.names.from, from, 1, attr);
|
||||
define_old_native_function(vm.names.compare, compare, 2, attr);
|
||||
define_native_function(vm.names.from, from, 1, attr);
|
||||
define_native_function(vm.names.compare, compare, 2, attr);
|
||||
|
||||
define_direct_property(vm.names.length, Value(3), Attribute::Configurable);
|
||||
}
|
||||
|
@ -74,34 +74,34 @@ ThrowCompletionOr<Object*> PlainDateConstructor::construct(FunctionObject& new_t
|
|||
}
|
||||
|
||||
// 3.2.2 Temporal.PlainDate.from ( item [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.from
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(PlainDateConstructor::from)
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateConstructor::from)
|
||||
{
|
||||
// 1. Set options to ? GetOptionsObject(options).
|
||||
auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(1)));
|
||||
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
|
||||
|
||||
auto item = vm.argument(0);
|
||||
// 2. If Type(item) is Object and item has an [[InitializedTemporalDate]] internal slot, then
|
||||
if (item.is_object() && is<PlainDate>(item.as_object())) {
|
||||
auto& plain_date_item = static_cast<PlainDate&>(item.as_object());
|
||||
// a. Perform ? ToTemporalOverflow(options).
|
||||
(void)TRY_OR_DISCARD(to_temporal_overflow(global_object, *options));
|
||||
(void)TRY(to_temporal_overflow(global_object, *options));
|
||||
|
||||
// b. Return ? CreateTemporalDate(item.[[ISOYear]], item.[[ISOMonth]], item.[[ISODay]], item.[[Calendar]]).
|
||||
return TRY_OR_DISCARD(create_temporal_date(global_object, plain_date_item.iso_year(), plain_date_item.iso_month(), plain_date_item.iso_day(), plain_date_item.calendar()));
|
||||
return TRY(create_temporal_date(global_object, plain_date_item.iso_year(), plain_date_item.iso_month(), plain_date_item.iso_day(), plain_date_item.calendar()));
|
||||
}
|
||||
|
||||
// 3. Return ? ToTemporalDate(item, options).
|
||||
return TRY_OR_DISCARD(to_temporal_date(global_object, item, options));
|
||||
return TRY(to_temporal_date(global_object, item, options));
|
||||
}
|
||||
|
||||
// 3.2.3 Temporal.PlainDate.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaindate-constructor
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(PlainDateConstructor::compare)
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateConstructor::compare)
|
||||
{
|
||||
// 1. Set one to ? ToTemporalDate(one).
|
||||
auto* one = TRY_OR_DISCARD(to_temporal_date(global_object, vm.argument(0)));
|
||||
auto* one = TRY(to_temporal_date(global_object, vm.argument(0)));
|
||||
|
||||
// 2. Set two to ? ToTemporalDate(two).
|
||||
auto* two = TRY_OR_DISCARD(to_temporal_date(global_object, vm.argument(1)));
|
||||
auto* two = TRY(to_temporal_date(global_object, vm.argument(1)));
|
||||
|
||||
// 3. Return 𝔽(! CompareISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]])).
|
||||
return Value(compare_iso_date(one->iso_year(), one->iso_month(), one->iso_day(), two->iso_year(), two->iso_month(), two->iso_day()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue