X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/ba379fdc102753d6be2c4d937058fe40257329fe..12899fa232562c774004a3a9d7d3149944dec712:/runtime/DateInstance.cpp diff --git a/runtime/DateInstance.cpp b/runtime/DateInstance.cpp index 62791ae..db7b846 100644 --- a/runtime/DateInstance.cpp +++ b/runtime/DateInstance.cpp @@ -22,97 +22,72 @@ #include "config.h" #include "DateInstance.h" +#include "JSDateMath.h" +#include "JSGlobalObject.h" +#include "Operations.h" #include -#include #include using namespace WTF; namespace JSC { -struct DateInstance::Cache { - double m_gregorianDateTimeCachedForMS; - GregorianDateTime m_cachedGregorianDateTime; - double m_gregorianDateTimeUTCCachedForMS; - GregorianDateTime m_cachedGregorianDateTimeUTC; -}; +const ClassInfo DateInstance::s_info = {"Date", &JSWrapperObject::s_info, 0, 0, CREATE_METHOD_TABLE(DateInstance)}; -const ClassInfo DateInstance::info = {"Date", 0, 0, 0}; - -DateInstance::DateInstance(PassRefPtr structure) - : JSWrapperObject(structure) - , m_cache(0) +DateInstance::DateInstance(ExecState* exec, Structure* structure) + : JSWrapperObject(exec->vm(), structure) { } -DateInstance::~DateInstance() +void DateInstance::finishCreation(VM& vm) { - delete m_cache; + Base::finishCreation(vm); + ASSERT(inherits(&s_info)); + setInternalValue(vm, jsNaN()); } -void DateInstance::msToGregorianDateTime(double milli, bool outputIsUTC, GregorianDateTime& t) const +void DateInstance::finishCreation(VM& vm, double time) { - if (!m_cache) { - m_cache = new Cache; - m_cache->m_gregorianDateTimeCachedForMS = NaN; - m_cache->m_gregorianDateTimeUTCCachedForMS = NaN; - } - - if (outputIsUTC) { - if (m_cache->m_gregorianDateTimeUTCCachedForMS != milli) { - WTF::msToGregorianDateTime(milli, true, m_cache->m_cachedGregorianDateTimeUTC); - m_cache->m_gregorianDateTimeUTCCachedForMS = milli; - } - t.copyFrom(m_cache->m_cachedGregorianDateTimeUTC); - } else { - if (m_cache->m_gregorianDateTimeCachedForMS != milli) { - WTF::msToGregorianDateTime(milli, false, m_cache->m_cachedGregorianDateTime); - m_cache->m_gregorianDateTimeCachedForMS = milli; - } - t.copyFrom(m_cache->m_cachedGregorianDateTime); - } + Base::finishCreation(vm); + ASSERT(inherits(&s_info)); + setInternalValue(vm, jsNumber(timeClip(time))); } -bool DateInstance::getTime(GregorianDateTime& t, int& offset) const +void DateInstance::destroy(JSCell* cell) { - double milli = internalNumber(); - if (isnan(milli)) - return false; - - msToGregorianDateTime(milli, false, t); - offset = gmtoffset(t); - return true; + static_cast(cell)->DateInstance::~DateInstance(); } -bool DateInstance::getUTCTime(GregorianDateTime& t) const +const GregorianDateTime* DateInstance::calculateGregorianDateTime(ExecState* exec) const { double milli = internalNumber(); - if (isnan(milli)) - return false; - - msToGregorianDateTime(milli, true, t); - return true; -} + if (std::isnan(milli)) + return 0; -bool DateInstance::getTime(double& milli, int& offset) const -{ - milli = internalNumber(); - if (isnan(milli)) - return false; - - GregorianDateTime t; - msToGregorianDateTime(milli, false, t); - offset = gmtoffset(t); - return true; + if (!m_data) + m_data = exec->vm().dateInstanceCache.add(milli); + + if (m_data->m_gregorianDateTimeCachedForMS != milli) { + msToGregorianDateTime(exec, milli, false, m_data->m_cachedGregorianDateTime); + m_data->m_gregorianDateTimeCachedForMS = milli; + } + return &m_data->m_cachedGregorianDateTime; } -bool DateInstance::getUTCTime(double& milli) const +const GregorianDateTime* DateInstance::calculateGregorianDateTimeUTC(ExecState* exec) const { - milli = internalNumber(); - if (isnan(milli)) - return false; - - return true; + double milli = internalNumber(); + if (std::isnan(milli)) + return 0; + + if (!m_data) + m_data = exec->vm().dateInstanceCache.add(milli); + + if (m_data->m_gregorianDateTimeUTCCachedForMS != milli) { + msToGregorianDateTime(exec, milli, true, m_data->m_cachedGregorianDateTimeUTC); + m_data->m_gregorianDateTimeUTCCachedForMS = milli; + } + return &m_data->m_cachedGregorianDateTimeUTC; } } // namespace JSC