mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:37:35 +00:00
LibJS: Convert DatePrototype functions to ThrowCompletionOr
This commit is contained in:
parent
ba39a54bb8
commit
2b87f77578
2 changed files with 196 additions and 204 deletions
|
@ -30,57 +30,57 @@ void DatePrototype::initialize(GlobalObject& global_object)
|
|||
auto& vm = this->vm();
|
||||
Object::initialize(global_object);
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_old_native_function(vm.names.getDate, get_date, 0, attr);
|
||||
define_old_native_function(vm.names.setDate, set_date, 1, attr);
|
||||
define_old_native_function(vm.names.getDay, get_day, 0, attr);
|
||||
define_old_native_function(vm.names.getFullYear, get_full_year, 0, attr);
|
||||
define_old_native_function(vm.names.setFullYear, set_full_year, 3, attr);
|
||||
define_old_native_function(vm.names.getYear, get_year, 0, attr);
|
||||
define_old_native_function(vm.names.setYear, set_year, 1, attr);
|
||||
define_old_native_function(vm.names.getHours, get_hours, 0, attr);
|
||||
define_old_native_function(vm.names.setHours, set_hours, 4, attr);
|
||||
define_old_native_function(vm.names.getMilliseconds, get_milliseconds, 0, attr);
|
||||
define_old_native_function(vm.names.setMilliseconds, set_milliseconds, 1, attr);
|
||||
define_old_native_function(vm.names.getMinutes, get_minutes, 0, attr);
|
||||
define_old_native_function(vm.names.setMinutes, set_minutes, 3, attr);
|
||||
define_old_native_function(vm.names.getMonth, get_month, 0, attr);
|
||||
define_old_native_function(vm.names.setMonth, set_month, 2, attr);
|
||||
define_old_native_function(vm.names.getSeconds, get_seconds, 0, attr);
|
||||
define_old_native_function(vm.names.setSeconds, set_seconds, 2, attr);
|
||||
define_old_native_function(vm.names.getTime, get_time, 0, attr);
|
||||
define_old_native_function(vm.names.setTime, set_time, 1, attr);
|
||||
define_old_native_function(vm.names.getTimezoneOffset, get_timezone_offset, 0, attr);
|
||||
define_old_native_function(vm.names.getUTCDate, get_utc_date, 0, attr);
|
||||
define_old_native_function(vm.names.setUTCDate, set_date, 1, attr); // FIXME: This is a hack, Serenity doesn't currently support timezones other than UTC.
|
||||
define_old_native_function(vm.names.getUTCDay, get_utc_day, 0, attr);
|
||||
define_old_native_function(vm.names.getUTCFullYear, get_utc_full_year, 0, attr);
|
||||
define_old_native_function(vm.names.setUTCFullYear, set_full_year, 3, attr); // FIXME: see above
|
||||
define_old_native_function(vm.names.getUTCHours, get_utc_hours, 0, attr);
|
||||
define_old_native_function(vm.names.setUTCHours, set_hours, 4, attr); // FIXME: see above
|
||||
define_old_native_function(vm.names.getUTCMilliseconds, get_utc_milliseconds, 0, attr);
|
||||
define_old_native_function(vm.names.setUTCMilliseconds, set_milliseconds, 1, attr); // FIXME: see above
|
||||
define_old_native_function(vm.names.getUTCMinutes, get_utc_minutes, 0, attr);
|
||||
define_old_native_function(vm.names.setUTCMinutes, set_minutes, 3, attr); // FIXME: see above
|
||||
define_old_native_function(vm.names.getUTCMonth, get_utc_month, 0, attr);
|
||||
define_old_native_function(vm.names.setUTCMonth, set_month, 2, attr); // FIXME: see above
|
||||
define_old_native_function(vm.names.getUTCSeconds, get_utc_seconds, 0, attr);
|
||||
define_old_native_function(vm.names.setUTCSeconds, set_seconds, 2, attr); // FIXME: see above
|
||||
define_old_native_function(vm.names.toDateString, to_date_string, 0, attr);
|
||||
define_old_native_function(vm.names.toUTCString, to_utc_string, 0, attr);
|
||||
define_old_native_function(vm.names.toISOString, to_iso_string, 0, attr);
|
||||
define_old_native_function(vm.names.toLocaleDateString, to_locale_date_string, 0, attr);
|
||||
define_old_native_function(vm.names.toLocaleString, to_locale_string, 0, attr);
|
||||
define_old_native_function(vm.names.toLocaleTimeString, to_locale_time_string, 0, attr);
|
||||
define_old_native_function(vm.names.toTimeString, to_time_string, 0, attr);
|
||||
define_old_native_function(vm.names.toString, to_string, 0, attr);
|
||||
define_old_native_function(vm.names.toJSON, to_json, 1, attr);
|
||||
define_old_native_function(vm.names.toTemporalInstant, to_temporal_instant, 0, attr);
|
||||
define_native_function(vm.names.getDate, get_date, 0, attr);
|
||||
define_native_function(vm.names.setDate, set_date, 1, attr);
|
||||
define_native_function(vm.names.getDay, get_day, 0, attr);
|
||||
define_native_function(vm.names.getFullYear, get_full_year, 0, attr);
|
||||
define_native_function(vm.names.setFullYear, set_full_year, 3, attr);
|
||||
define_native_function(vm.names.getYear, get_year, 0, attr);
|
||||
define_native_function(vm.names.setYear, set_year, 1, attr);
|
||||
define_native_function(vm.names.getHours, get_hours, 0, attr);
|
||||
define_native_function(vm.names.setHours, set_hours, 4, attr);
|
||||
define_native_function(vm.names.getMilliseconds, get_milliseconds, 0, attr);
|
||||
define_native_function(vm.names.setMilliseconds, set_milliseconds, 1, attr);
|
||||
define_native_function(vm.names.getMinutes, get_minutes, 0, attr);
|
||||
define_native_function(vm.names.setMinutes, set_minutes, 3, attr);
|
||||
define_native_function(vm.names.getMonth, get_month, 0, attr);
|
||||
define_native_function(vm.names.setMonth, set_month, 2, attr);
|
||||
define_native_function(vm.names.getSeconds, get_seconds, 0, attr);
|
||||
define_native_function(vm.names.setSeconds, set_seconds, 2, attr);
|
||||
define_native_function(vm.names.getTime, get_time, 0, attr);
|
||||
define_native_function(vm.names.setTime, set_time, 1, attr);
|
||||
define_native_function(vm.names.getTimezoneOffset, get_timezone_offset, 0, attr);
|
||||
define_native_function(vm.names.getUTCDate, get_utc_date, 0, attr);
|
||||
define_native_function(vm.names.setUTCDate, set_date, 1, attr); // FIXME: This is a hack, Serenity doesn't currently support timezones other than UTC.
|
||||
define_native_function(vm.names.getUTCDay, get_utc_day, 0, attr);
|
||||
define_native_function(vm.names.getUTCFullYear, get_utc_full_year, 0, attr);
|
||||
define_native_function(vm.names.setUTCFullYear, set_full_year, 3, attr); // FIXME: see above
|
||||
define_native_function(vm.names.getUTCHours, get_utc_hours, 0, attr);
|
||||
define_native_function(vm.names.setUTCHours, set_hours, 4, attr); // FIXME: see above
|
||||
define_native_function(vm.names.getUTCMilliseconds, get_utc_milliseconds, 0, attr);
|
||||
define_native_function(vm.names.setUTCMilliseconds, set_milliseconds, 1, attr); // FIXME: see above
|
||||
define_native_function(vm.names.getUTCMinutes, get_utc_minutes, 0, attr);
|
||||
define_native_function(vm.names.setUTCMinutes, set_minutes, 3, attr); // FIXME: see above
|
||||
define_native_function(vm.names.getUTCMonth, get_utc_month, 0, attr);
|
||||
define_native_function(vm.names.setUTCMonth, set_month, 2, attr); // FIXME: see above
|
||||
define_native_function(vm.names.getUTCSeconds, get_utc_seconds, 0, attr);
|
||||
define_native_function(vm.names.setUTCSeconds, set_seconds, 2, attr); // FIXME: see above
|
||||
define_native_function(vm.names.toDateString, to_date_string, 0, attr);
|
||||
define_native_function(vm.names.toUTCString, to_utc_string, 0, attr);
|
||||
define_native_function(vm.names.toISOString, to_iso_string, 0, attr);
|
||||
define_native_function(vm.names.toLocaleDateString, to_locale_date_string, 0, attr);
|
||||
define_native_function(vm.names.toLocaleString, to_locale_string, 0, attr);
|
||||
define_native_function(vm.names.toLocaleTimeString, to_locale_time_string, 0, attr);
|
||||
define_native_function(vm.names.toTimeString, to_time_string, 0, attr);
|
||||
define_native_function(vm.names.toString, to_string, 0, attr);
|
||||
define_native_function(vm.names.toJSON, to_json, 1, attr);
|
||||
define_native_function(vm.names.toTemporalInstant, to_temporal_instant, 0, attr);
|
||||
|
||||
// 21.4.4.45 Date.prototype [ @@toPrimitive ] ( hint ), https://tc39.es/ecma262/#sec-date.prototype-@@toprimitive
|
||||
define_old_native_function(*vm.well_known_symbol_to_primitive(), symbol_to_primitive, 1, Attribute::Configurable);
|
||||
define_native_function(*vm.well_known_symbol_to_primitive(), symbol_to_primitive, 1, Attribute::Configurable);
|
||||
|
||||
// Aliases.
|
||||
define_old_native_function(vm.names.valueOf, get_time, 0, attr);
|
||||
define_native_function(vm.names.valueOf, get_time, 0, attr);
|
||||
|
||||
// B.2.4.3 Date.prototype.toGMTString ( ), https://tc39.es/ecma262/#sec-date.prototype.togmtstring
|
||||
// The function object that is the initial value of Date.prototype.toGMTString
|
||||
|
@ -93,9 +93,9 @@ DatePrototype::~DatePrototype()
|
|||
}
|
||||
|
||||
// 21.4.4.2 Date.prototype.getDate ( ), https://tc39.es/ecma262/#sec-date.prototype.getdate
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_date)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_date)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -104,13 +104,13 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_date)
|
|||
}
|
||||
|
||||
// 21.4.4.20 Date.prototype.setDate ( date ), https://tc39.es/ecma262/#sec-date.prototype.setdate
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_date)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_date)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
auto& datetime = this_object->datetime();
|
||||
|
||||
auto new_date_value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
|
||||
auto new_date_value = TRY(vm.argument(0).to_number(global_object));
|
||||
if (!new_date_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
|
@ -128,9 +128,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_date)
|
|||
}
|
||||
|
||||
// 21.4.4.3 Date.prototype.getDay ( ), https://tc39.es/ecma262/#sec-date.prototype.getday
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_day)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_day)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -139,9 +139,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_day)
|
|||
}
|
||||
|
||||
// 21.4.4.4 Date.prototype.getFullYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getfullyear
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_full_year)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_full_year)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -150,9 +150,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_full_year)
|
|||
}
|
||||
|
||||
// 21.4.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] ), https://tc39.es/ecma262/#sec-date.prototype.setfullyear
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_full_year)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_full_year)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
auto& datetime = this_object->datetime();
|
||||
|
||||
|
@ -160,21 +160,21 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_full_year)
|
|||
return vm.argument_count() > i ? vm.argument(i).to_number(global_object) : Value(fallback);
|
||||
};
|
||||
|
||||
auto new_year_value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
|
||||
auto new_year_value = TRY(vm.argument(0).to_number(global_object));
|
||||
if (!new_year_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
}
|
||||
auto new_year = new_year_value.as_i32();
|
||||
|
||||
auto new_month_value = TRY_OR_DISCARD(arg_or(1, datetime.month() - 1));
|
||||
auto new_month_value = TRY(arg_or(1, datetime.month() - 1));
|
||||
if (!new_month_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
}
|
||||
auto new_month = new_month_value.as_i32() + 1; // JS Months: 0 - 11, DateTime months: 1-12
|
||||
|
||||
auto new_day_value = TRY_OR_DISCARD(arg_or(2, datetime.day()));
|
||||
auto new_day_value = TRY(arg_or(2, datetime.day()));
|
||||
if (!new_day_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
|
@ -193,9 +193,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_full_year)
|
|||
}
|
||||
|
||||
// B.2.4.1 Date.prototype.getYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getyear
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_year)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_year)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -204,13 +204,13 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_year)
|
|||
}
|
||||
|
||||
// B.2.4.2 Date.prototype.setYear ( year ), https://tc39.es/ecma262/#sec-date.prototype.setyear
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_year)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_year)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
auto& datetime = this_object->datetime();
|
||||
|
||||
auto new_year_value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
|
||||
auto new_year_value = TRY(vm.argument(0).to_number(global_object));
|
||||
if (!new_year_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
|
@ -231,9 +231,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_year)
|
|||
}
|
||||
|
||||
// 21.4.4.5 Date.prototype.getHours ( ), https://tc39.es/ecma262/#sec-date.prototype.gethours
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_hours)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_hours)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -242,9 +242,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_hours)
|
|||
}
|
||||
|
||||
// 21.4.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] ), https://tc39.es/ecma262/#sec-date.prototype.sethours
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_hours)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_hours)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
auto arg_or = [&vm, &global_object](size_t i, i32 fallback) -> ThrowCompletionOr<Value> {
|
||||
return vm.argument_count() > i ? vm.argument(i).to_number(global_object) : Value(fallback);
|
||||
|
@ -252,28 +252,28 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_hours)
|
|||
|
||||
auto& datetime = this_object->datetime();
|
||||
|
||||
auto new_hours_value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
|
||||
auto new_hours_value = TRY(vm.argument(0).to_number(global_object));
|
||||
if (!new_hours_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
}
|
||||
auto new_hours = new_hours_value.as_i32();
|
||||
|
||||
auto new_minutes_value = TRY_OR_DISCARD(arg_or(1, datetime.minute()));
|
||||
auto new_minutes_value = TRY(arg_or(1, datetime.minute()));
|
||||
if (!new_minutes_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
}
|
||||
auto new_minutes = new_minutes_value.as_i32();
|
||||
|
||||
auto new_seconds_value = TRY_OR_DISCARD(arg_or(2, datetime.second()));
|
||||
auto new_seconds_value = TRY(arg_or(2, datetime.second()));
|
||||
if (!new_seconds_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
}
|
||||
auto new_seconds = new_seconds_value.as_i32();
|
||||
|
||||
auto new_milliseconds_value = TRY_OR_DISCARD(arg_or(3, this_object->milliseconds()));
|
||||
auto new_milliseconds_value = TRY(arg_or(3, this_object->milliseconds()));
|
||||
if (!new_milliseconds_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
|
@ -294,9 +294,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_hours)
|
|||
}
|
||||
|
||||
// 21.4.4.23 Date.prototype.setMilliseconds ( ms ), https://tc39.es/ecma262/#sec-date.prototype.setmilliseconds
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_milliseconds)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_milliseconds)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -305,11 +305,11 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_milliseconds)
|
|||
}
|
||||
|
||||
// 21.4.4.23 Date.prototype.setMilliseconds ( ms ), https://tc39.es/ecma262/#sec-date.prototype.setmilliseconds
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_milliseconds)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_milliseconds)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
auto new_milliseconds_value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
|
||||
auto new_milliseconds_value = TRY(vm.argument(0).to_number(global_object));
|
||||
|
||||
if (!new_milliseconds_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
|
@ -337,9 +337,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_milliseconds)
|
|||
}
|
||||
|
||||
// 21.4.4.7 Date.prototype.getMinutes ( ), https://tc39.es/ecma262/#sec-date.prototype.getminutes
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_minutes)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_minutes)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -348,9 +348,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_minutes)
|
|||
}
|
||||
|
||||
// 21.4.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] ), https://tc39.es/ecma262/#sec-date.prototype.setminutes
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_minutes)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_minutes)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
auto arg_or = [&vm, &global_object](size_t i, i32 fallback) -> ThrowCompletionOr<Value> {
|
||||
return vm.argument_count() > i ? vm.argument(i).to_number(global_object) : Value(fallback);
|
||||
|
@ -358,21 +358,21 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_minutes)
|
|||
|
||||
auto& datetime = this_object->datetime();
|
||||
|
||||
auto new_minutes_value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
|
||||
auto new_minutes_value = TRY(vm.argument(0).to_number(global_object));
|
||||
if (!new_minutes_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
}
|
||||
auto new_minutes = new_minutes_value.as_i32();
|
||||
|
||||
auto new_seconds_value = TRY_OR_DISCARD(arg_or(1, datetime.second()));
|
||||
auto new_seconds_value = TRY(arg_or(1, datetime.second()));
|
||||
if (!new_seconds_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
}
|
||||
auto new_seconds = new_seconds_value.as_i32();
|
||||
|
||||
auto new_milliseconds_value = TRY_OR_DISCARD(arg_or(2, this_object->milliseconds()));
|
||||
auto new_milliseconds_value = TRY(arg_or(2, this_object->milliseconds()));
|
||||
if (!new_milliseconds_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
|
@ -393,9 +393,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_minutes)
|
|||
}
|
||||
|
||||
// 21.4.4.8 Date.prototype.getMonth ( ), https://tc39.es/ecma262/#sec-date.prototype.getmonth
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_month)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_month)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -404,9 +404,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_month)
|
|||
}
|
||||
|
||||
// 21.4.4.25 Date.prototype.setMonth ( month [ , date ] ), https://tc39.es/ecma262/#sec-date.prototype.setmonth
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_month)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_month)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
auto arg_or = [&vm, &global_object](size_t i, i32 fallback) -> ThrowCompletionOr<Value> {
|
||||
return vm.argument_count() > i ? vm.argument(i).to_number(global_object) : Value(fallback);
|
||||
|
@ -414,14 +414,14 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_month)
|
|||
|
||||
auto& datetime = this_object->datetime();
|
||||
|
||||
auto new_month_value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
|
||||
auto new_month_value = TRY(vm.argument(0).to_number(global_object));
|
||||
if (!new_month_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
}
|
||||
auto new_month = new_month_value.as_i32() + 1; // JS Months: 0 - 11, DateTime months: 1-12
|
||||
|
||||
auto new_date_value = TRY_OR_DISCARD(arg_or(1, this_object->date()));
|
||||
auto new_date_value = TRY(arg_or(1, this_object->date()));
|
||||
if (!new_date_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
|
@ -439,9 +439,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_month)
|
|||
}
|
||||
|
||||
// 21.4.4.9 Date.prototype.getSeconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getseconds
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_seconds)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_seconds)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -450,9 +450,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_seconds)
|
|||
}
|
||||
|
||||
// 21.4.4.26 Date.prototype.setSeconds ( sec [ , ms ] ), https://tc39.es/ecma262/#sec-date.prototype.setseconds
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_seconds)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_seconds)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
auto arg_or = [&vm, &global_object](size_t i, i32 fallback) -> ThrowCompletionOr<Value> {
|
||||
return vm.argument_count() > i ? vm.argument(i).to_number(global_object) : Value(fallback);
|
||||
|
@ -460,14 +460,14 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_seconds)
|
|||
|
||||
auto& datetime = this_object->datetime();
|
||||
|
||||
auto new_seconds_value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
|
||||
auto new_seconds_value = TRY(vm.argument(0).to_number(global_object));
|
||||
if (!new_seconds_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
}
|
||||
auto new_seconds = new_seconds_value.as_i32();
|
||||
|
||||
auto new_milliseconds_value = TRY_OR_DISCARD(arg_or(1, this_object->milliseconds()));
|
||||
auto new_milliseconds_value = TRY(arg_or(1, this_object->milliseconds()));
|
||||
if (!new_milliseconds_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
|
@ -488,9 +488,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_seconds)
|
|||
}
|
||||
|
||||
// 21.4.4.10 Date.prototype.getTime ( ), https://tc39.es/ecma262/#sec-date.prototype.gettime
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_time)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_time)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -499,11 +499,11 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_time)
|
|||
}
|
||||
|
||||
// 21.4.4.27 Date.prototype.setTime ( time ), https://tc39.es/ecma262/#sec-date.prototype.settime
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_time)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_time)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
auto new_time_value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
|
||||
auto new_time_value = TRY(vm.argument(0).to_number(global_object));
|
||||
if (!new_time_value.is_finite_number()) {
|
||||
this_object->set_is_invalid(true);
|
||||
return js_nan();
|
||||
|
@ -524,9 +524,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::set_time)
|
|||
}
|
||||
|
||||
// 21.4.4.11 Date.prototype.getTimezoneOffset ( ), https://tc39.es/ecma262/#sec-date.prototype.gettimezoneoffset
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_timezone_offset)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_timezone_offset)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -536,9 +536,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_timezone_offset)
|
|||
}
|
||||
|
||||
// 21.4.4.12 Date.prototype.getUTCDate ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcdate
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_date)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_date)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -547,9 +547,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_date)
|
|||
}
|
||||
|
||||
// 21.4.4.13 Date.prototype.getUTCDay ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcday
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_day)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_day)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -558,9 +558,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_day)
|
|||
}
|
||||
|
||||
// 21.4.4.14 Date.prototype.getUTCFullYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcfullyear
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_full_year)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_full_year)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -569,9 +569,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_full_year)
|
|||
}
|
||||
|
||||
// 21.4.4.15 Date.prototype.getUTCHours ( ), https://tc39.es/ecma262/#sec-date.prototype.getutchours
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_hours)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_hours)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -580,9 +580,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_hours)
|
|||
}
|
||||
|
||||
// 21.4.4.16 Date.prototype.getUTCMilliseconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcmilliseconds
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_milliseconds)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_milliseconds)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -591,9 +591,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_milliseconds)
|
|||
}
|
||||
|
||||
// 21.4.4.18 Date.prototype.getUTCMonth ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcmonth
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_month)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_month)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -602,9 +602,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_month)
|
|||
}
|
||||
|
||||
// 21.4.4.17 Date.prototype.getUTCMinutes ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcminutes
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_minutes)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_minutes)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -613,9 +613,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_minutes)
|
|||
}
|
||||
|
||||
// 21.4.4.19 Date.prototype.getUTCSeconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcseconds
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_seconds)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_seconds)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_nan();
|
||||
|
@ -624,9 +624,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::get_utc_seconds)
|
|||
}
|
||||
|
||||
// 21.4.4.35 Date.prototype.toDateString ( ), https://tc39.es/ecma262/#sec-date.prototype.todatestring
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_date_string)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_string(vm, "Invalid Date");
|
||||
|
@ -636,16 +636,16 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_date_string)
|
|||
}
|
||||
|
||||
// B.2.4.3 Date.prototype.toGMTString ( ), https://tc39.es/ecma262/#sec-date.prototype.togmtstring
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_gmt_string)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_gmt_string)
|
||||
{
|
||||
// NOTE: The toUTCString method is preferred. The toGMTString method is provided principally for compatibility with old code.
|
||||
return to_utc_string(vm, global_object);
|
||||
}
|
||||
|
||||
// 21.4.4.43 Date.prototype.toUTCString ( ), https://tc39.es/ecma262/#sec-date.prototype.toutcstring
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_utc_string)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_utc_string)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_string(vm, "Invalid Date");
|
||||
|
@ -656,23 +656,21 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_utc_string)
|
|||
}
|
||||
|
||||
// 21.4.4.36 Date.prototype.toISOString ( ), https://tc39.es/ecma262/#sec-date.prototype.toisostring
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_iso_string)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_iso_string)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid()) {
|
||||
vm.throw_exception<RangeError>(global_object, ErrorType::InvalidTimeValue);
|
||||
return {};
|
||||
}
|
||||
if (this_object->is_invalid())
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::InvalidTimeValue);
|
||||
|
||||
auto string = this_object->iso_date_string();
|
||||
return js_string(vm, move(string));
|
||||
}
|
||||
|
||||
// 21.4.4.38 Date.prototype.toLocaleDateString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocaledatestring
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_locale_date_string)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_date_string)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_string(vm, "Invalid Date");
|
||||
|
@ -683,9 +681,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_locale_date_string)
|
|||
}
|
||||
|
||||
// 21.4.4.39 Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocalestring
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_locale_string)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_string)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_string(vm, "Invalid Date");
|
||||
|
@ -696,9 +694,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_locale_string)
|
|||
}
|
||||
|
||||
// 21.4.4.40 Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocaletimestring
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_locale_time_string)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_time_string)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_string(vm, "Invalid Date");
|
||||
|
@ -709,9 +707,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_locale_time_string)
|
|||
}
|
||||
|
||||
// 21.4.4.42 Date.prototype.toTimeString ( ), https://tc39.es/ecma262/#sec-date.prototype.totimestring
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_time_string)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_time_string)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_string(vm, "Invalid Date");
|
||||
|
@ -721,9 +719,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_time_string)
|
|||
}
|
||||
|
||||
// 21.4.4.41 Date.prototype.toString ( ), https://tc39.es/ecma262/#sec-date.prototype.tostring
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_string)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_string)
|
||||
{
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
|
||||
if (this_object->is_invalid())
|
||||
return js_string(vm, "Invalid Date");
|
||||
|
@ -733,27 +731,27 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_string)
|
|||
}
|
||||
|
||||
// 21.4.4.37 Date.prototype.toJSON ( key ), https://tc39.es/ecma262/#sec-date.prototype.tojson
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_json)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json)
|
||||
{
|
||||
auto this_value = vm.this_value(global_object);
|
||||
|
||||
auto time_value = TRY_OR_DISCARD(this_value.to_primitive(global_object, Value::PreferredType::Number));
|
||||
auto time_value = TRY(this_value.to_primitive(global_object, Value::PreferredType::Number));
|
||||
|
||||
if (time_value.is_number() && !time_value.is_finite_number())
|
||||
return js_null();
|
||||
|
||||
return TRY_OR_DISCARD(this_value.invoke(global_object, vm.names.toISOString));
|
||||
return TRY(this_value.invoke(global_object, vm.names.toISOString));
|
||||
}
|
||||
|
||||
// 14.1.1 Date.prototype.toTemporalInstant ( ), https://tc39.es/proposal-temporal/#sec-date.prototype.totemporalinstant
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_temporal_instant)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_temporal_instant)
|
||||
{
|
||||
// 1. Let t be ? thisTimeValue(this value).
|
||||
auto* this_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* this_object = TRY(typed_this_object(global_object));
|
||||
auto t = this_object->value_of();
|
||||
|
||||
// 2. Let ns be ? NumberToBigInt(t) × 10^6.
|
||||
auto* ns = TRY_OR_DISCARD(number_to_bigint(global_object, t));
|
||||
auto* ns = TRY(number_to_bigint(global_object, t));
|
||||
ns = js_bigint(vm, ns->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000 }));
|
||||
|
||||
// 3. Return ! CreateTemporalInstant(ns).
|
||||
|
@ -761,29 +759,23 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::to_temporal_instant)
|
|||
}
|
||||
|
||||
// 21.4.4.45 Date.prototype [ @@toPrimitive ] ( hint ), https://tc39.es/ecma262/#sec-date.prototype-@@toprimitive
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(DatePrototype::symbol_to_primitive)
|
||||
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::symbol_to_primitive)
|
||||
{
|
||||
auto this_value = vm.this_value(global_object);
|
||||
if (!this_value.is_object()) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, this_value.to_string_without_side_effects());
|
||||
return {};
|
||||
}
|
||||
if (!this_value.is_object())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, this_value.to_string_without_side_effects());
|
||||
auto hint_value = vm.argument(0);
|
||||
if (!hint_value.is_string()) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::InvalidHint, hint_value.to_string_without_side_effects());
|
||||
return {};
|
||||
}
|
||||
if (!hint_value.is_string())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::InvalidHint, hint_value.to_string_without_side_effects());
|
||||
auto& hint = hint_value.as_string().string();
|
||||
Value::PreferredType try_first;
|
||||
if (hint == "string" || hint == "default") {
|
||||
if (hint == "string" || hint == "default")
|
||||
try_first = Value::PreferredType::String;
|
||||
} else if (hint == "number") {
|
||||
else if (hint == "number")
|
||||
try_first = Value::PreferredType::Number;
|
||||
} else {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::InvalidHint, hint);
|
||||
return {};
|
||||
}
|
||||
return TRY_OR_DISCARD(this_value.as_object().ordinary_to_primitive(try_first));
|
||||
else
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::InvalidHint, hint);
|
||||
return TRY(this_value.as_object().ordinary_to_primitive(try_first));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,46 +20,46 @@ public:
|
|||
virtual ~DatePrototype() override;
|
||||
|
||||
private:
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_date);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(set_date);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_day);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_full_year);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(set_full_year);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_year);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(set_year);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_hours);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(set_hours);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_milliseconds);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(set_milliseconds);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_minutes);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(set_minutes);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_month);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(set_month);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_seconds);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(set_seconds);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_time);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(set_time);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_timezone_offset);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_utc_date);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_utc_day);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_utc_full_year);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_utc_hours);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_utc_milliseconds);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_utc_minutes);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_utc_month);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get_utc_seconds);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_date_string);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_gmt_string);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_utc_string);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_iso_string);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_locale_date_string);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_locale_string);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_locale_time_string);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_time_string);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_string);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_json);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_temporal_instant);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(symbol_to_primitive);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_date);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_date);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_day);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_full_year);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_full_year);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_year);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_year);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_hours);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_hours);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_milliseconds);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_milliseconds);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_minutes);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_minutes);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_month);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_month);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_seconds);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_seconds);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_time);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_time);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_timezone_offset);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_utc_date);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_utc_day);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_utc_full_year);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_utc_hours);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_utc_milliseconds);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_utc_minutes);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_utc_month);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_utc_seconds);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_date_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_gmt_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_utc_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_iso_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_locale_date_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_locale_time_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_time_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_json);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_temporal_instant);
|
||||
JS_DECLARE_NATIVE_FUNCTION(symbol_to_primitive);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue