mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
LibJS: Pass prototype to Date constructor
This commit is contained in:
parent
2a15323029
commit
0df4d2823a
3 changed files with 13 additions and 4 deletions
|
@ -25,16 +25,23 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibCore/DateTime.h>
|
#include <LibCore/DateTime.h>
|
||||||
|
#include <LibJS/Heap/Heap.h>
|
||||||
#include <LibJS/Interpreter.h>
|
#include <LibJS/Interpreter.h>
|
||||||
#include <LibJS/Runtime/Date.h>
|
#include <LibJS/Runtime/Date.h>
|
||||||
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
|
|
||||||
namespace JS {
|
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<Date>(datetime, milliseconds, *global_object.interpreter().date_prototype());
|
||||||
|
}
|
||||||
|
|
||||||
|
Date::Date(Core::DateTime datetime, u16 milliseconds, Object& prototype)
|
||||||
: m_datetime(datetime)
|
: m_datetime(datetime)
|
||||||
, m_milliseconds(milliseconds)
|
, m_milliseconds(milliseconds)
|
||||||
{
|
{
|
||||||
set_prototype(interpreter().date_prototype());
|
set_prototype(&prototype);
|
||||||
}
|
}
|
||||||
|
|
||||||
Date::~Date()
|
Date::~Date()
|
||||||
|
|
|
@ -31,7 +31,9 @@ namespace JS {
|
||||||
|
|
||||||
class Date final : public Object {
|
class Date final : public Object {
|
||||||
public:
|
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;
|
virtual ~Date() override;
|
||||||
|
|
||||||
Core::DateTime& datetime() { return m_datetime; }
|
Core::DateTime& datetime() { return m_datetime; }
|
||||||
|
|
|
@ -61,7 +61,7 @@ Value DateConstructor::construct(Interpreter& interpreter)
|
||||||
gettimeofday(&tv, nullptr);
|
gettimeofday(&tv, nullptr);
|
||||||
auto datetime = Core::DateTime::now();
|
auto datetime = Core::DateTime::now();
|
||||||
auto milliseconds = static_cast<u16>(tv.tv_usec / 1000);
|
auto milliseconds = static_cast<u16>(tv.tv_usec / 1000);
|
||||||
return interpreter.heap().allocate<Date>(datetime, milliseconds);
|
return Date::create(interpreter.global_object(), datetime, milliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value DateConstructor::now(Interpreter&)
|
Value DateConstructor::now(Interpreter&)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue