diff options
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/DatePrototype.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/DatePrototype.h | 1 |
3 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h index 18fb2ec114..07e577d1f4 100644 --- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h +++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h @@ -199,6 +199,7 @@ namespace JS { P(reverse) \ P(round) \ P(set) \ + P(setFullYear) \ P(setPrototypeOf) \ P(shift) \ P(sign) \ diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index 72fea9ca25..a1002ce90e 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -60,6 +60,7 @@ void DatePrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.getDate, get_date, 0, 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.getHours, get_hours, 0, attr); define_native_function(vm.names.getMilliseconds, get_milliseconds, 0, attr); define_native_function(vm.names.getMinutes, get_minutes, 0, attr); @@ -118,6 +119,22 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_full_year) return Value(static_cast<double>(this_object->full_year())); } +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_full_year) +{ + auto* this_object = typed_this(vm, global_object); + if (!this_object) + return {}; + auto new_year = vm.argument(0).to_i32(global_object); + if (vm.exception()) + return {}; + // FIXME: Support specifying new month and new day as well. + auto& datetime = this_object->datetime(); + auto new_month = datetime.month(); + auto new_day = datetime.day(); + datetime.set_time(new_year, new_month, new_day, datetime.hour(), datetime.minute(), datetime.second()); + return Value { this_object->time() }; +} + JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_hours) { auto* this_object = typed_this(vm, global_object); diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.h b/Userland/Libraries/LibJS/Runtime/DatePrototype.h index 5c8c8bebd4..b0891367f1 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.h +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.h @@ -42,6 +42,7 @@ private: JS_DECLARE_NATIVE_FUNCTION(get_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_hours); JS_DECLARE_NATIVE_FUNCTION(get_milliseconds); JS_DECLARE_NATIVE_FUNCTION(get_minutes); |