1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

LibJS: Convert Date.prototype to be a PrototypeObject

This commit is contained in:
Timothy Flynn 2021-09-11 16:14:34 -04:00 committed by Andreas Kling
parent 8bfb665b72
commit 94f076a774
2 changed files with 42 additions and 54 deletions

View file

@ -12,7 +12,6 @@
#include <LibCore/DateTime.h> #include <LibCore/DateTime.h>
#include <LibCrypto/BigInt/UnsignedBigInteger.h> #include <LibCrypto/BigInt/UnsignedBigInteger.h>
#include <LibJS/Runtime/BigInt.h> #include <LibJS/Runtime/BigInt.h>
#include <LibJS/Runtime/Date.h>
#include <LibJS/Runtime/DatePrototype.h> #include <LibJS/Runtime/DatePrototype.h>
#include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
@ -21,20 +20,8 @@
namespace JS { namespace JS {
static Date* typed_this(VM& vm, GlobalObject& global_object)
{
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return nullptr;
if (!is<Date>(this_object)) {
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Date");
return nullptr;
}
return static_cast<Date*>(this_object);
}
DatePrototype::DatePrototype(GlobalObject& global_object) DatePrototype::DatePrototype(GlobalObject& global_object)
: Object(*global_object.object_prototype()) : PrototypeObject(*global_object.object_prototype())
{ {
} }
@ -108,7 +95,7 @@ DatePrototype::~DatePrototype()
// 21.4.4.2 Date.prototype.getDate ( ), https://tc39.es/ecma262/#sec-date.prototype.getdate // 21.4.4.2 Date.prototype.getDate ( ), https://tc39.es/ecma262/#sec-date.prototype.getdate
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_date) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_date)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -121,7 +108,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_date)
// 21.4.4.20 Date.prototype.setDate ( date ), https://tc39.es/ecma262/#sec-date.prototype.setdate // 21.4.4.20 Date.prototype.setDate ( date ), https://tc39.es/ecma262/#sec-date.prototype.setdate
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_date) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_date)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -149,7 +136,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_date)
// 21.4.4.3 Date.prototype.getDay ( ), https://tc39.es/ecma262/#sec-date.prototype.getday // 21.4.4.3 Date.prototype.getDay ( ), https://tc39.es/ecma262/#sec-date.prototype.getday
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_day) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_day)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -162,7 +149,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_day)
// 21.4.4.4 Date.prototype.getFullYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getfullyear // 21.4.4.4 Date.prototype.getFullYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getfullyear
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_full_year) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_full_year)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -175,7 +162,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_full_year)
// 21.4.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] ), https://tc39.es/ecma262/#sec-date.prototype.setfullyear // 21.4.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] ), https://tc39.es/ecma262/#sec-date.prototype.setfullyear
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_full_year) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_full_year)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -224,7 +211,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_full_year)
// B.2.4.1 Date.prototype.getYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getyear // B.2.4.1 Date.prototype.getYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getyear
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_year) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_year)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -237,7 +224,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_year)
// B.2.4.2 Date.prototype.setYear ( year ), https://tc39.es/ecma262/#sec-date.prototype.setyear // B.2.4.2 Date.prototype.setYear ( year ), https://tc39.es/ecma262/#sec-date.prototype.setyear
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_year) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_year)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -268,7 +255,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_year)
// 21.4.4.5 Date.prototype.getHours ( ), https://tc39.es/ecma262/#sec-date.prototype.gethours // 21.4.4.5 Date.prototype.getHours ( ), https://tc39.es/ecma262/#sec-date.prototype.gethours
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_hours) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_hours)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -281,7 +268,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_hours)
// 21.4.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] ), https://tc39.es/ecma262/#sec-date.prototype.sethours // 21.4.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] ), https://tc39.es/ecma262/#sec-date.prototype.sethours
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_hours) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_hours)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -341,7 +328,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_hours)
// 21.4.4.23 Date.prototype.setMilliseconds ( ms ), https://tc39.es/ecma262/#sec-date.prototype.setmilliseconds // 21.4.4.23 Date.prototype.setMilliseconds ( ms ), https://tc39.es/ecma262/#sec-date.prototype.setmilliseconds
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_milliseconds) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_milliseconds)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -354,7 +341,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_milliseconds)
// 21.4.4.23 Date.prototype.setMilliseconds ( ms ), https://tc39.es/ecma262/#sec-date.prototype.setmilliseconds // 21.4.4.23 Date.prototype.setMilliseconds ( ms ), https://tc39.es/ecma262/#sec-date.prototype.setmilliseconds
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_milliseconds) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_milliseconds)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -390,7 +377,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_milliseconds)
// 21.4.4.7 Date.prototype.getMinutes ( ), https://tc39.es/ecma262/#sec-date.prototype.getminutes // 21.4.4.7 Date.prototype.getMinutes ( ), https://tc39.es/ecma262/#sec-date.prototype.getminutes
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_minutes) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_minutes)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -403,7 +390,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_minutes)
// 21.4.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] ), https://tc39.es/ecma262/#sec-date.prototype.setminutes // 21.4.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] ), https://tc39.es/ecma262/#sec-date.prototype.setminutes
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_minutes) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_minutes)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -454,7 +441,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_minutes)
// 21.4.4.8 Date.prototype.getMonth ( ), https://tc39.es/ecma262/#sec-date.prototype.getmonth // 21.4.4.8 Date.prototype.getMonth ( ), https://tc39.es/ecma262/#sec-date.prototype.getmonth
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_month) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_month)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -467,7 +454,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_month)
// 21.4.4.25 Date.prototype.setMonth ( month [ , date ] ), https://tc39.es/ecma262/#sec-date.prototype.setmonth // 21.4.4.25 Date.prototype.setMonth ( month [ , date ] ), https://tc39.es/ecma262/#sec-date.prototype.setmonth
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_month) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_month)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -506,7 +493,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_month)
// 21.4.4.9 Date.prototype.getSeconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getseconds // 21.4.4.9 Date.prototype.getSeconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getseconds
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_seconds) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_seconds)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -519,7 +506,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_seconds)
// 21.4.4.26 Date.prototype.setSeconds ( sec [ , ms ] ), https://tc39.es/ecma262/#sec-date.prototype.setseconds // 21.4.4.26 Date.prototype.setSeconds ( sec [ , ms ] ), https://tc39.es/ecma262/#sec-date.prototype.setseconds
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_seconds) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_seconds)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -561,7 +548,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_seconds)
// 21.4.4.10 Date.prototype.getTime ( ), https://tc39.es/ecma262/#sec-date.prototype.gettime // 21.4.4.10 Date.prototype.getTime ( ), https://tc39.es/ecma262/#sec-date.prototype.gettime
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_time) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_time)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -574,7 +561,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_time)
// 21.4.4.27 Date.prototype.setTime ( time ), https://tc39.es/ecma262/#sec-date.prototype.settime // 21.4.4.27 Date.prototype.setTime ( time ), https://tc39.es/ecma262/#sec-date.prototype.settime
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_time) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_time)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -603,7 +590,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_time)
// 21.4.4.11 Date.prototype.getTimezoneOffset ( ), https://tc39.es/ecma262/#sec-date.prototype.gettimezoneoffset // 21.4.4.11 Date.prototype.getTimezoneOffset ( ), https://tc39.es/ecma262/#sec-date.prototype.gettimezoneoffset
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_timezone_offset) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_timezone_offset)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -617,7 +604,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_timezone_offset)
// 21.4.4.12 Date.prototype.getUTCDate ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcdate // 21.4.4.12 Date.prototype.getUTCDate ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcdate
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_date) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_date)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -630,7 +617,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_date)
// 21.4.4.13 Date.prototype.getUTCDay ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcday // 21.4.4.13 Date.prototype.getUTCDay ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcday
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_day) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_day)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -643,7 +630,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_day)
// 21.4.4.14 Date.prototype.getUTCFullYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcfullyear // 21.4.4.14 Date.prototype.getUTCFullYear ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcfullyear
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_full_year) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_full_year)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -656,7 +643,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_full_year)
// 21.4.4.15 Date.prototype.getUTCHours ( ), https://tc39.es/ecma262/#sec-date.prototype.getutchours // 21.4.4.15 Date.prototype.getUTCHours ( ), https://tc39.es/ecma262/#sec-date.prototype.getutchours
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_hours) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_hours)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -669,7 +656,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_hours)
// 21.4.4.16 Date.prototype.getUTCMilliseconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcmilliseconds // 21.4.4.16 Date.prototype.getUTCMilliseconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcmilliseconds
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_milliseconds) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_milliseconds)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -682,7 +669,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_milliseconds)
// 21.4.4.18 Date.prototype.getUTCMonth ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcmonth // 21.4.4.18 Date.prototype.getUTCMonth ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcmonth
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_month) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_month)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -695,7 +682,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_month)
// 21.4.4.17 Date.prototype.getUTCMinutes ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcminutes // 21.4.4.17 Date.prototype.getUTCMinutes ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcminutes
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_minutes) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_minutes)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -708,7 +695,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_minutes)
// 21.4.4.19 Date.prototype.getUTCSeconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcseconds // 21.4.4.19 Date.prototype.getUTCSeconds ( ), https://tc39.es/ecma262/#sec-date.prototype.getutcseconds
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_seconds) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_seconds)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -721,7 +708,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::get_utc_seconds)
// 21.4.4.35 Date.prototype.toDateString ( ), https://tc39.es/ecma262/#sec-date.prototype.todatestring // 21.4.4.35 Date.prototype.toDateString ( ), https://tc39.es/ecma262/#sec-date.prototype.todatestring
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -742,7 +729,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_gmt_string)
// 21.4.4.43 Date.prototype.toUTCString ( ), https://tc39.es/ecma262/#sec-date.prototype.toutcstring // 21.4.4.43 Date.prototype.toUTCString ( ), https://tc39.es/ecma262/#sec-date.prototype.toutcstring
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_utc_string) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_utc_string)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -757,7 +744,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_utc_string)
// 21.4.4.36 Date.prototype.toISOString ( ), https://tc39.es/ecma262/#sec-date.prototype.toisostring // 21.4.4.36 Date.prototype.toISOString ( ), https://tc39.es/ecma262/#sec-date.prototype.toisostring
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_iso_string) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_iso_string)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -773,7 +760,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_iso_string)
// 21.4.4.38 Date.prototype.toLocaleDateString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocaledatestring // 21.4.4.38 Date.prototype.toLocaleDateString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocaledatestring
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_date_string) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_date_string)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -788,7 +775,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_date_string)
// 21.4.4.39 Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocalestring // 21.4.4.39 Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocalestring
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_string) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_string)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -803,7 +790,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_string)
// 21.4.4.40 Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocaletimestring // 21.4.4.40 Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocaletimestring
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_time_string) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_time_string)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -818,7 +805,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_time_string)
// 21.4.4.42 Date.prototype.toTimeString ( ), https://tc39.es/ecma262/#sec-date.prototype.totimestring // 21.4.4.42 Date.prototype.toTimeString ( ), https://tc39.es/ecma262/#sec-date.prototype.totimestring
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_time_string) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_time_string)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -832,7 +819,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_time_string)
// 21.4.4.41 Date.prototype.toString ( ), https://tc39.es/ecma262/#sec-date.prototype.tostring // 21.4.4.41 Date.prototype.toString ( ), https://tc39.es/ecma262/#sec-date.prototype.tostring
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_string) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_string)
{ {
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (!this_object) if (!this_object)
return {}; return {};
@ -862,7 +849,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json)
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_temporal_instant) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_temporal_instant)
{ {
// 1. Let t be ? thisTimeValue(this value). // 1. Let t be ? thisTimeValue(this value).
auto* this_object = typed_this(vm, global_object); auto* this_object = typed_this_object(global_object);
if (vm.exception()) if (vm.exception())
return {}; return {};
auto t = this_object->value_of(); auto t = this_object->value_of();

View file

@ -6,12 +6,13 @@
#pragma once #pragma once
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Date.h>
#include <LibJS/Runtime/PrototypeObject.h>
namespace JS { namespace JS {
class DatePrototype final : public Object { class DatePrototype final : public PrototypeObject<DatePrototype, Date> {
JS_OBJECT(DatePrototype, Object); JS_PROTOTYPE_OBJECT(DatePrototype, Date, Date);
public: public:
explicit DatePrototype(GlobalObject&); explicit DatePrototype(GlobalObject&);