X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9dae56ea45a0f5f8136a5c93d6f3a7f99399ca73..b80e619319b1def83d1e8b4f84042b661be1be7f:/runtime/DateInstance.cpp?ds=sidebyside diff --git a/runtime/DateInstance.cpp b/runtime/DateInstance.cpp index 8806dec..b43b183 100644 --- a/runtime/DateInstance.cpp +++ b/runtime/DateInstance.cpp @@ -22,95 +22,66 @@ #include "config.h" #include "DateInstance.h" -#include "DateMath.h" +#include "JSGlobalObject.h" + #include +#include #include -namespace JSC { +using namespace WTF; -struct DateInstance::Cache { - double m_gregorianDateTimeCachedForMS; - GregorianDateTime m_cachedGregorianDateTime; - double m_gregorianDateTimeUTCCachedForMS; - GregorianDateTime m_cachedGregorianDateTimeUTC; -}; +namespace JSC { const ClassInfo DateInstance::info = {"Date", 0, 0, 0}; -DateInstance::DateInstance(PassRefPtr structure) +DateInstance::DateInstance(ExecState* exec, NonNullPassRefPtr structure) : JSWrapperObject(structure) - , m_cache(0) { + setInternalValue(jsNaN(exec)); } -DateInstance::~DateInstance() +DateInstance::DateInstance(ExecState* exec, NonNullPassRefPtr structure, double time) + : JSWrapperObject(structure) { - delete m_cache; + setInternalValue(jsNumber(exec, timeClip(time))); } -void DateInstance::msToGregorianDateTime(double milli, bool outputIsUTC, GregorianDateTime& t) const +DateInstance::DateInstance(ExecState* exec, double time) + : JSWrapperObject(exec->lexicalGlobalObject()->dateStructure()) { - 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) { - JSC::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) { - JSC::msToGregorianDateTime(milli, false, m_cache->m_cachedGregorianDateTime); - m_cache->m_gregorianDateTimeCachedForMS = milli; - } - t.copyFrom(m_cache->m_cachedGregorianDateTime); - } + setInternalValue(jsNumber(exec, timeClip(time))); } -bool DateInstance::getTime(GregorianDateTime& t, int& offset) const +const GregorianDateTime* DateInstance::calculateGregorianDateTime(ExecState* exec) const { double milli = internalNumber(); if (isnan(milli)) - return false; - - msToGregorianDateTime(milli, false, t); - offset = gmtoffset(t); - return true; + return 0; + + if (!m_data) + m_data = exec->globalData().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(GregorianDateTime& t) const +const GregorianDateTime* DateInstance::calculateGregorianDateTimeUTC(ExecState* exec) const { double milli = internalNumber(); if (isnan(milli)) - return false; - - msToGregorianDateTime(milli, true, t); - return true; -} + 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->globalData().dateInstanceCache.add(milli); -bool DateInstance::getUTCTime(double& milli) const -{ - milli = internalNumber(); - if (isnan(milli)) - return false; - - return true; + 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