summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-03-14 16:23:46 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-15 21:20:33 +0100
commit3596c42deb247b2eb71a4e17543e55d7ce3cd034 (patch)
tree74be7dda9fe6a865889d5c49427a3da3f9a65dcc /Userland
parent4da3e5d91fd10424ffe791ecdc93b982daa0cc16 (diff)
downloadserenity-3596c42deb247b2eb71a4e17543e55d7ce3cd034.zip
LibJS: Partial support for Date.prototype.setFullYear()
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h1
-rw-r--r--Userland/Libraries/LibJS/Runtime/DatePrototype.cpp17
-rw-r--r--Userland/Libraries/LibJS/Runtime/DatePrototype.h1
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);