From ad40c5f9a92adfc486ae224cf75565b9465e4914 Mon Sep 17 00:00:00 2001 From: tuqqu Date: Fri, 19 Mar 2021 13:10:55 +0300 Subject: [PATCH] LibJS: Support month and day arguments of Date.setFullYear --- .../Libraries/LibJS/Runtime/DatePrototype.cpp | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index ff262fcf44..9250907204 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -128,10 +128,27 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_full_year) 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(); + + i32 new_month; + if (vm.argument_count() >= 2) { + new_month = vm.argument(1).to_i32(global_object); + if (vm.exception()) + return {}; + } else { + new_month = datetime.month(); + } + + i32 new_day; + if (vm.argument_count() >= 3) { + new_day = vm.argument(2).to_i32(global_object); + if (vm.exception()) + return {}; + } else { + new_day = datetime.day(); + } + datetime.set_time(new_year, new_month, new_day, datetime.hour(), datetime.minute(), datetime.second()); return Value { this_object->time() }; }