LibJS: Stub out Date.prototype.getTimezoneOffset()

We only support UTC currently, so this always returns 0 as long as the
date is not invalid.
This commit is contained in:
Idan Horowitz 2021-06-06 15:53:52 +03:00 committed by Linus Groh
parent 44926b3f80
commit 3eb05d9413
Notes: sideshowbarker 2024-07-18 12:44:54 +09:00
3 changed files with 16 additions and 0 deletions

View File

@ -135,6 +135,7 @@ namespace JS {
P(getPrototypeOf) \
P(getSeconds) \
P(getTime) \
P(getTimezoneOffset) \
P(getUTCDate) \
P(getUTCDay) \
P(getUTCFullYear) \

View File

@ -54,6 +54,7 @@ void DatePrototype::initialize(GlobalObject& global_object)
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.getTimezoneOffset, get_timezone_offset, 0, attr);
define_native_function(vm.names.getUTCDate, get_utc_date, 0, attr);
define_native_function(vm.names.getUTCDay, get_utc_day, 0, attr);
define_native_function(vm.names.getUTCFullYear, get_utc_full_year, 0, attr);
@ -445,6 +446,19 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_time)
return Value(this_object->time());
}
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_timezone_offset)
{
auto* this_object = typed_this(vm, global_object);
if (!this_object)
return {};
if (this_object->is_invalid())
return js_nan();
// FIXME: Make this actually do something once we support timezones instead of just UTC
return Value(0);
}
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_date)
{
auto* this_object = typed_this(vm, global_object);

View File

@ -35,6 +35,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(get_seconds);
JS_DECLARE_NATIVE_FUNCTION(set_seconds);
JS_DECLARE_NATIVE_FUNCTION(get_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);