diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h index 57ad824b47..e98f66ff04 100644 --- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h +++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h @@ -235,6 +235,7 @@ namespace JS { P(toString) \ P(toTimeString) \ P(toUpperCase) \ + P(toUTCString) \ P(trace) \ P(trim) \ P(trimEnd) \ diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index 36071284f1..2d98bf6adf 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -81,6 +81,7 @@ void DatePrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.getUTCSeconds, get_utc_seconds, 0, attr); define_native_function(vm.names.toDateString, to_date_string, 0, attr); define_native_function(vm.names.toGMTString, to_gmt_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); @@ -399,10 +400,19 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string) } JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_gmt_string) +{ + // toGMTString is deprecated but kept for compatibility. + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toGMTString + return to_utc_string(vm, global_object); +} + +JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_utc_string) { auto* this_object = typed_this(vm, global_object); if (!this_object) return {}; + + // HTTP dates are always expressed in GMT. auto string = this_object->gmt_date_string(); return js_string(vm, move(string)); } diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.h b/Userland/Libraries/LibJS/Runtime/DatePrototype.h index bf9bc49034..266e0c63ca 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.h +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.h @@ -63,6 +63,7 @@ private: 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);