diff --git a/Libraries/LibJS/Runtime/Date.cpp b/Libraries/LibJS/Runtime/Date.cpp index faa3942075d..5ebf3a77a56 100644 --- a/Libraries/LibJS/Runtime/Date.cpp +++ b/Libraries/LibJS/Runtime/Date.cpp @@ -25,16 +25,23 @@ */ #include +#include #include #include +#include namespace JS { -Date::Date(Core::DateTime datetime, u16 milliseconds) +Date* Date::create(GlobalObject& global_object, Core::DateTime datetime, u16 milliseconds) +{ + return global_object.heap().allocate(datetime, milliseconds, *global_object.interpreter().date_prototype()); +} + +Date::Date(Core::DateTime datetime, u16 milliseconds, Object& prototype) : m_datetime(datetime) , m_milliseconds(milliseconds) { - set_prototype(interpreter().date_prototype()); + set_prototype(&prototype); } Date::~Date() diff --git a/Libraries/LibJS/Runtime/Date.h b/Libraries/LibJS/Runtime/Date.h index 557af7ce2cd..432ed1b4d23 100644 --- a/Libraries/LibJS/Runtime/Date.h +++ b/Libraries/LibJS/Runtime/Date.h @@ -31,7 +31,9 @@ namespace JS { class Date final : public Object { public: - Date(Core::DateTime datetime, u16 milliseconds); + static Date* create(GlobalObject&, Core::DateTime, u16 milliseconds); + + Date(Core::DateTime datetime, u16 milliseconds, Object& prototype); virtual ~Date() override; Core::DateTime& datetime() { return m_datetime; } diff --git a/Libraries/LibJS/Runtime/DateConstructor.cpp b/Libraries/LibJS/Runtime/DateConstructor.cpp index 9f825a6b96b..87eefc4de7c 100644 --- a/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -61,7 +61,7 @@ Value DateConstructor::construct(Interpreter& interpreter) gettimeofday(&tv, nullptr); auto datetime = Core::DateTime::now(); auto milliseconds = static_cast(tv.tv_usec / 1000); - return interpreter.heap().allocate(datetime, milliseconds); + return Date::create(interpreter.global_object(), datetime, milliseconds); } Value DateConstructor::now(Interpreter&)