Changeset 50608 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Nov 6, 2009, 3:33:17 PM (16 years ago)
Author:
[email protected]
Message:

Rolled back in r50590 with Windows build hopefully fixed.

Location:
trunk/JavaScriptCore
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r50599 r50608  
     12009-11-06  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Oliver Hunt.
     4       
     5        https://bugs.webkit.org/show_bug.cgi?id=31197
     6        Implemented a timezone cache not based on Mac OS X's notify_check API.
     7       
     8        If the VM calculates the local timezone offset from UTC, it caches the
     9        result until the end of the current VM invocation. (We don't want to cache
     10        forever, because the user's timezone may change over time.)
     11       
     12        This removes notify_* overhead on Mac, and, more significantly, removes
     13        OS time and date call overhead on non-Mac platforms.
     14
     15        ~8% speedup on Date microbenchmark on Mac. SunSpider reports maybe a tiny
     16        speedup on Mac. (Speedup on non-Mac platforms should be even more noticeable.)
     17
     18        * JavaScriptCore.exp:
     19
     20        * interpreter/CachedCall.h:
     21        (JSC::CachedCall::CachedCall):
     22        * interpreter/Interpreter.cpp:
     23        (JSC::Interpreter::execute):
     24        * runtime/JSGlobalObject.h:
     25        (JSC::DynamicGlobalObjectScope::DynamicGlobalObjectScope): Made the
     26        DynamicGlobalObjectScope constructor responsible for checking whether a
     27        dynamicGlobalObject has already been set. This eliminated some duplicate
     28        client code, and allowed me to avoid adding even more duplicate client
     29        code. Made DynamicGlobalObjectScope responsible for resetting the
     30        local timezone cache upon first entry to the VM.
     31
     32        * runtime/DateConstructor.cpp:
     33        (JSC::constructDate):
     34        (JSC::callDate):
     35        (JSC::dateParse):
     36        (JSC::dateUTC):
     37        * runtime/DateConversion.cpp:
     38        (JSC::parseDate):
     39        * runtime/DateConversion.h:
     40        * runtime/DateInstance.cpp:
     41        (JSC::DateInstance::gregorianDateTime):
     42        * runtime/DateInstance.h:
     43        * runtime/DateInstanceCache.h:
     44        * runtime/DatePrototype.cpp:
     45        (JSC::setNewValueFromTimeArgs):
     46        (JSC::setNewValueFromDateArgs):
     47        (JSC::dateProtoFuncSetYear):
     48        * runtime/InitializeThreading.cpp:
     49        (JSC::initializeThreadingOnce):
     50        * runtime/JSGlobalData.cpp:
     51        (JSC::JSGlobalData::JSGlobalData):
     52        * runtime/JSGlobalData.h:
     53        * wtf/DateMath.cpp:
     54        (WTF::getCurrentUTCTime):
     55        (WTF::getCurrentUTCTimeWithMicroseconds):
     56        (WTF::getLocalTime):
     57        (JSC::getUTCOffset): Use the new cache. Also, see below.
     58        (JSC::gregorianDateTimeToMS):
     59        (JSC::msToGregorianDateTime):
     60        (JSC::initializeDates):
     61        (JSC::parseDateFromNullTerminatedCharacters): Simplified the way this function
     62        accounts for the local timezone offset, to accomodate our new caching API,
     63        and a (possibly misguided) caller in WebCore. Also, see below.
     64        * wtf/DateMath.h:
     65        (JSC::GregorianDateTime::GregorianDateTime): Moved most of the code in
     66        DateMath.* into the JSC namespace. The code needed to move so it could
     67        naturally interact with ExecState and JSGlobalData to support caching.
     68        Logically, it seemed right to move it, too, since this code is not really
     69        as low-level as the WTF namespace might imply -- it implements a set of
     70        date parsing and conversion quirks that are finely tuned to the JavaScript
     71        language. Also removed the Mac OS X notify_* infrastructure.
     72       
     73        * wtf/CurrentTime.h:
     74        (WTF::currentTimeMS):
     75        (WTF::getLocalTime): Moved the rest of the DateMath code here, and renamed
     76        it to make it consistent with WTF's currentTime function.
     77
    1782009-11-06  Gabor Loki  <[email protected]>
    279
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r50591 r50608  
    179179__ZN3JSC25evaluateInGlobalCallFrameERKNS_7UStringERNS_7JSValueEPNS_14JSGlobalObjectE
    180180__ZN3JSC35createInterruptedExecutionExceptionEPNS_12JSGlobalDataE
     181__ZN3JSC37parseDateFromNullTerminatedCharactersEPKcPNS_9ExecStateE
     182__ZN3JSC3NaNE
    181183__ZN3JSC4Heap11objectCountEv
    182184__ZN3JSC4Heap14primaryHeapEndEv
     
    331333__ZN3WTF28setMainThreadCallbacksPausedEb
    332334__ZN3WTF36lockAtomicallyInitializedStaticMutexEv
    333 __ZN3WTF37parseDateFromNullTerminatedCharactersEPKc
    334335__ZN3WTF38unlockAtomicallyInitializedStaticMutexEv
    335336__ZN3WTF5Mutex4lockEv
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj

    r50174 r50608  
    669669                                >
    670670                        </File>
     671                        <File
     672                                RelativePath="..\..\wtf\DateMath.cpp"
     673                                >
     674                        </File>
     675                        <File
     676                                RelativePath="..\..\wtf\DateMath.h"
     677                                >
     678                        </File>
    671679                        <File
    672680                                RelativePath="..\..\runtime\DatePrototype.cpp"
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj

    r49705 r50608  
    286286                </File>
    287287                <File
    288                         RelativePath="..\..\wtf\DateMath.cpp"
    289                         >
    290                 </File>
    291                 <File
    292                         RelativePath="..\..\wtf\DateMath.h"
    293                         >
    294                 </File>
    295                 <File
    296288                        RelativePath="..\..\wtf\Deque.h"
    297289                        >
  • trunk/JavaScriptCore/JavaScriptCoreSources.bkl

    r47781 r50608  
    9090        runtime/DateConversion.cpp
    9191        runtime/DateInstance.cpp
     92        wtf/DateMath.cpp
    9293        runtime/DatePrototype.cpp
    9394        runtime/Error.cpp
     
    174175        wtf/ByteArray.cpp
    175176        wtf/CurrentTime.cpp
    176         wtf/DateMath.cpp
    177177        wtf/FastMalloc.cpp
    178178        wtf/HashTable.cpp
  • trunk/JavaScriptCore/interpreter/CachedCall.h

    r50591 r50608  
    3939            , m_interpreter(callFrame->interpreter())
    4040            , m_exception(exception)
    41             , m_globalObjectScope(callFrame, callFrame->globalData().dynamicGlobalObject ? callFrame->globalData().dynamicGlobalObject : function->scope().globalObject())
     41            , m_globalObjectScope(callFrame, function->scope().globalObject())
    4242        {
    4343            ASSERT(!function->isHostFunction());
  • trunk/JavaScriptCore/interpreter/Interpreter.cpp

    r50591 r50608  
    648648    }
    649649
    650     DynamicGlobalObjectScope globalObjectScope(callFrame, callFrame->globalData().dynamicGlobalObject ? callFrame->globalData().dynamicGlobalObject : scopeChain->globalObject);
     650    DynamicGlobalObjectScope globalObjectScope(callFrame, scopeChain->globalObject);
    651651
    652652    CallFrame* newCallFrame = CallFrame::create(oldEnd);
     
    778778    }
    779779
    780     DynamicGlobalObjectScope globalObjectScope(callFrame, callFrame->globalData().dynamicGlobalObject ? callFrame->globalData().dynamicGlobalObject : scopeChain->globalObject);
     780    DynamicGlobalObjectScope globalObjectScope(callFrame, scopeChain->globalObject);
    781781
    782782    EvalCodeBlock* codeBlock = &eval->bytecode(callFrame, scopeChain);
  • trunk/JavaScriptCore/pcre/pcre_exec.cpp

    r46118 r50608  
    21652165HistogramTimeLogger::HistogramTimeLogger(const JSRegExp* re)
    21662166    : m_re(re)
    2167     , m_startTime(getCurrentUTCTimeWithMicroseconds())
     2167    , m_startTime(currentTimeMS())
    21682168{
    21692169}
     
    21722172{
    21732173    static Histogram histogram;
    2174     histogram.add(m_re, getCurrentUTCTimeWithMicroseconds() - m_startTime);
     2174    histogram.add(m_re, currentTimeMS() - m_startTime);
    21752175}
    21762176
  • trunk/JavaScriptCore/profiler/ProfileNode.cpp

    r44508 r50608  
    3838#endif
    3939
     40using namespace WTF;
     41
    4042namespace JSC {
    4143
     
    5052    return static_cast<double>(counter.QuadPart) / frequency.QuadPart;
    5153#else
    52     return WTF::getCurrentUTCTimeWithMicroseconds();
     54    return currentTimeMS();
    5355#endif
    5456}
  • trunk/JavaScriptCore/runtime/DateConstructor.cpp

    r50591 r50608  
    7878
    7979    if (numArgs == 0) // new Date() ECMA 15.9.3.3
    80         value = getCurrentUTCTime();
     80        value = jsCurrentTime();
    8181    else if (numArgs == 1) {
    8282        if (args.at(0).inherits(&DateInstance::info))
     
    8585            JSValue primitive = args.at(0).toPrimitive(exec);
    8686            if (primitive.isString())
    87                 value = parseDate(primitive.getString());
     87                value = parseDate(exec, primitive.getString());
    8888            else
    8989                value = primitive.toNumber(exec);
     
    109109            t.isDST = -1;
    110110            double ms = (numArgs >= 7) ? args.at(6).toNumber(exec) : 0;
    111             value = gregorianDateTimeToMS(t, ms, false);
     111            value = gregorianDateTimeToMS(exec, t, ms, false);
    112112        }
    113113    }
     
    133133    tm localTM;
    134134    getLocalTime(&localTime, &localTM);
    135     GregorianDateTime ts(localTM);
     135    GregorianDateTime ts(exec, localTM);
    136136    return jsNontrivialString(exec, formatDate(ts) + " " + formatTime(ts, false));
    137137}
     
    145145static JSValue JSC_HOST_CALL dateParse(ExecState* exec, JSObject*, JSValue, const ArgList& args)
    146146{
    147     return jsNumber(exec, parseDate(args.at(0).toString(exec)));
     147    return jsNumber(exec, parseDate(exec, args.at(0).toString(exec)));
    148148}
    149149
    150150static JSValue JSC_HOST_CALL dateNow(ExecState* exec, JSObject*, JSValue, const ArgList&)
    151151{
    152     return jsNumber(exec, getCurrentUTCTime());
     152    return jsNumber(exec, jsCurrentTime());
    153153}
    154154
     
    174174    t.second = args.at(5).toInt32(exec);
    175175    double ms = (n >= 7) ? args.at(6).toNumber(exec) : 0;
    176     return jsNumber(exec, gregorianDateTimeToMS(t, ms, true));
     176    return jsNumber(exec, gregorianDateTimeToMS(exec, t, ms, true));
    177177}
    178178
  • trunk/JavaScriptCore/runtime/DateConversion.cpp

    r50591 r50608  
    5252namespace JSC {
    5353
    54 double parseDate(const UString &date)
     54double parseDate(ExecState* exec, const UString &date)
    5555{
    56     return parseDateFromNullTerminatedCharacters(date.UTF8String().c_str());
     56    return parseDateFromNullTerminatedCharacters(date.UTF8String().c_str(), exec);
    5757}
    5858
  • trunk/JavaScriptCore/runtime/DateConversion.h

    r50591 r50608  
    4343#define DateConversion_h
    4444
    45 namespace WTF {
    46     struct GregorianDateTime;
    47 }
    48 
    4945namespace JSC {
    5046
     47class ExecState;
    5148class UString;
     49struct GregorianDateTime;
    5250
    53 double parseDate(const UString&);
    54 UString formatDate(const WTF::GregorianDateTime&);
    55 UString formatDateUTCVariant(const WTF::GregorianDateTime&);
    56 UString formatTime(const WTF::GregorianDateTime&, bool inputIsUTC);
     51double parseDate(ExecState* exec, const UString&);
     52UString formatDate(const GregorianDateTime&);
     53UString formatDateUTCVariant(const GregorianDateTime&);
     54UString formatTime(const GregorianDateTime&, bool inputIsUTC);
    5755
    5856} // namespace JSC
  • trunk/JavaScriptCore/runtime/DateInstance.cpp

    r50591 r50608  
    5858    if (outputIsUTC) {
    5959        if (m_data->m_gregorianDateTimeUTCCachedForMS != milli) {
    60             msToGregorianDateTime(internalNumber(), true, m_data->m_cachedGregorianDateTimeUTC);
     60            msToGregorianDateTime(exec, internalNumber(), true, m_data->m_cachedGregorianDateTimeUTC);
    6161            m_data->m_gregorianDateTimeUTCCachedForMS = milli;
    6262        }
     
    6565
    6666    if (m_data->m_gregorianDateTimeCachedForMS != milli) {
    67         msToGregorianDateTime(internalNumber(), false, m_data->m_cachedGregorianDateTime);
     67        msToGregorianDateTime(exec, internalNumber(), false, m_data->m_cachedGregorianDateTime);
    6868        m_data->m_gregorianDateTimeCachedForMS = milli;
    6969    }
  • trunk/JavaScriptCore/runtime/DateInstance.h

    r50591 r50608  
    3939        static JS_EXPORTDATA const ClassInfo info;
    4040
    41         const WTF::GregorianDateTime* gregorianDateTime(ExecState*, bool outputIsUTC) const;
     41        const GregorianDateTime* gregorianDateTime(ExecState*, bool outputIsUTC) const;
    4242
    4343        static PassRefPtr<Structure> createStructure(JSValue prototype)
  • trunk/JavaScriptCore/runtime/DateInstanceCache.h

    r50591 r50608  
    4141
    4242        double m_gregorianDateTimeCachedForMS;
    43         WTF::GregorianDateTime m_cachedGregorianDateTime;
     43        GregorianDateTime m_cachedGregorianDateTime;
    4444        double m_gregorianDateTimeUTCCachedForMS;
    45         WTF::GregorianDateTime m_cachedGregorianDateTimeUTC;
     45        GregorianDateTime m_cachedGregorianDateTimeUTC;
    4646
    4747    private:
  • trunk/JavaScriptCore/runtime/DatePrototype.cpp

    r50591 r50608  
    843843    }
    844844   
    845     JSValue result = jsNumber(exec, gregorianDateTimeToMS(gregorianDateTime, ms, inputIsUTC));
     845    JSValue result = jsNumber(exec, gregorianDateTimeToMS(exec, gregorianDateTime, ms, inputIsUTC));
    846846    thisDateObj->setInternalValue(result);
    847847    return result;
     
    865865    GregorianDateTime gregorianDateTime;
    866866    if (numArgsToUse == 3 && isnan(milli))
    867         WTF::msToGregorianDateTime(0, true, gregorianDateTime);
     867        msToGregorianDateTime(exec, 0, true, gregorianDateTime);
    868868    else {
    869869        ms = milli - floor(milli / msPerSecond) * msPerSecond;
     
    880880    }
    881881           
    882     JSValue result = jsNumber(exec, gregorianDateTimeToMS(gregorianDateTime, ms, inputIsUTC));
     882    JSValue result = jsNumber(exec, gregorianDateTimeToMS(exec, gregorianDateTime, ms, inputIsUTC));
    883883    thisDateObj->setInternalValue(result);
    884884    return result;
     
    990990        // Based on ECMA 262 B.2.5 (setYear)
    991991        // the time must be reset to +0 if it is NaN.
    992         msToGregorianDateTime(0, true, gregorianDateTime);
     992        msToGregorianDateTime(exec, 0, true, gregorianDateTime);
    993993    else {   
    994994        double secs = floor(milli / msPerSecond);
     
    10071007           
    10081008    gregorianDateTime.year = (year > 99 || year < 0) ? year - 1900 : year;
    1009     JSValue result = jsNumber(exec, gregorianDateTimeToMS(gregorianDateTime, ms, outputIsUTC));
     1009    JSValue result = jsNumber(exec, gregorianDateTimeToMS(exec, gregorianDateTime, ms, outputIsUTC));
    10101010    thisDateObj->setInternalValue(result);
    10111011    return result;
  • trunk/JavaScriptCore/runtime/InitializeThreading.cpp

    r50591 r50608  
    5252#if ENABLE(JSC_MULTIPLE_THREADS)
    5353    s_dtoaP5Mutex = new Mutex;
    54     WTF::initializeDates();
     54    initializeDates();
    5555#endif
    5656}
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r50591 r50608  
    148148    , firstStringifierToMark(0)
    149149    , markStack(vptrSet.jsArrayVPtr)
     150    , cachedUTCOffset(NaN)
    150151#ifndef NDEBUG
    151152    , mainThreadOnly(false)
  • trunk/JavaScriptCore/runtime/JSGlobalData.h

    r50591 r50608  
    154154        MarkStack markStack;
    155155
     156        double cachedUTCOffset;
     157
    156158#ifndef NDEBUG
    157159        bool mainThreadOnly;
  • trunk/JavaScriptCore/runtime/JSGlobalObject.h

    r50591 r50608  
    443443            , m_savedDynamicGlobalObject(m_dynamicGlobalObjectSlot)
    444444        {
    445             m_dynamicGlobalObjectSlot = dynamicGlobalObject;
     445            if (!m_dynamicGlobalObjectSlot) {
     446                m_dynamicGlobalObjectSlot = dynamicGlobalObject;
     447
     448                // Reset the UTC cache between JS invocations to force the VM
     449                // to observe time zone changes.
     450                callFrame->globalData().cachedUTCOffset = NaN;
     451            }
    446452        }
    447453
  • trunk/JavaScriptCore/wtf/CurrentTime.h

    r42851 r50608  
    3535namespace WTF {
    3636
    37     // Returns the current system (UTC) time in seconds, starting January 1, 1970.
    38     // Precision varies depending on a platform but usually is as good or better
     37    // Returns the current UTC time in seconds, counted from January 1, 1970.
     38    // Precision varies depending on platform but is usually as good or better
    3939    // than a millisecond.
    4040    double currentTime();
     41
     42    // Same thing, in milliseconds.
     43    inline double currentTimeMS()
     44    {
     45        return currentTime() * 1000.0;
     46    }
     47
     48    inline void getLocalTime(const time_t* localTime, struct tm* localTM)
     49    {
     50    #if COMPILER(MSVC7) || COMPILER(MINGW) || PLATFORM(WINCE)
     51        *localTM = *localtime(localTime);
     52    #elif COMPILER(MSVC)
     53        localtime_s(localTM, localTime);
     54    #else
     55        localtime_r(localTime, localTM);
     56    #endif
     57    }
    4158
    4259} // namespace WTF
  • trunk/JavaScriptCore/wtf/DateMath.cpp

    r50591 r50608  
    5151#include "StringExtras.h"
    5252
     53#include "CallFrame.h"
     54
    5355#include <algorithm>
    5456#include <limits.h>
     
    6264#endif
    6365
    64 #if PLATFORM(DARWIN)
    65 #include <notify.h>
    66 #endif
    67 
    6866#if PLATFORM(WINCE)
    6967extern "C" size_t strftime(char * const s, const size_t maxsize, const char * const format, const struct tm * const t);
     
    8179#define NaN std::numeric_limits<double>::quiet_NaN()
    8280
    83 namespace WTF {
     81using namespace WTF;
     82
     83namespace JSC {
    8484
    8585/* Constants */
     
    294294}
    295295
    296 double getCurrentUTCTime()
    297 {
    298     return floor(getCurrentUTCTimeWithMicroseconds());
    299 }
    300 
    301 // Returns current time in milliseconds since 1 Jan 1970.
    302 double getCurrentUTCTimeWithMicroseconds()
    303 {
    304     return currentTime() * 1000.0;
    305 }
    306 
    307 void getLocalTime(const time_t* localTime, struct tm* localTM)
    308 {
    309 #if COMPILER(MSVC7) || COMPILER(MINGW) || PLATFORM(WINCE)
    310     *localTM = *localtime(localTime);
    311 #elif COMPILER(MSVC)
    312     localtime_s(localTM, localTime);
    313 #else
    314     localtime_r(localTime, localTM);
    315 #endif
    316 }
    317 
    318296// There is a hard limit at 2038 that we currently do not have a workaround
    319297// for (rdar://problem/5052975).
     
    329307    // minus 27 instead, to ensure there is a range of 28 years that all years
    330308    // can map to.
    331     return std::min(msToYear(getCurrentUTCTime()), maximumYearForDST() - 27) ;
     309    return std::min(msToYear(jsCurrentTime()), maximumYearForDST() - 27) ;
    332310}
    333311
     
    400378}
    401379
    402 #if PLATFORM(DARWIN)
    403 static int32_t s_cachedUTCOffset; // In milliseconds. An assumption here is that access to an int32_t variable is atomic on platforms that take this code path.
    404 static bool s_haveCachedUTCOffset;
    405 static int s_notificationToken;
    406 #endif
    407 
    408380/*
    409381 * Get the difference in milliseconds between this time zone and UTC (GMT)
    410382 * NOT including DST.
    411383 */
    412 double getUTCOffset()
    413 {
    414 #if PLATFORM(DARWIN)
    415     if (s_haveCachedUTCOffset) {
    416         int notified;
    417         uint32_t status = notify_check(s_notificationToken, &notified);
    418         if (status == NOTIFY_STATUS_OK && !notified)
    419             return s_cachedUTCOffset;
    420     }
    421 #endif
    422 
    423     int32_t utcOffset = calculateUTCOffset();
    424 
    425 #if PLATFORM(DARWIN)
    426     // Theoretically, it is possible that several threads will be executing this code at once, in which case we will have a race condition,
    427     // and a newer value may be overwritten. In practice, time zones don't change that often.
    428     s_cachedUTCOffset = utcOffset;
    429 #endif
    430 
    431     return utcOffset;
     384double getUTCOffset(ExecState* exec)
     385{
     386    double utcOffset = exec->globalData().cachedUTCOffset;
     387    if (!isnan(utcOffset))
     388        return utcOffset;
     389    exec->globalData().cachedUTCOffset = calculateUTCOffset();
     390    return exec->globalData().cachedUTCOffset;
    432391}
    433392
     
    487446}
    488447
    489 double gregorianDateTimeToMS(const GregorianDateTime& t, double milliSeconds, bool inputIsUTC)
     448double gregorianDateTimeToMS(ExecState* exec, const GregorianDateTime& t, double milliSeconds, bool inputIsUTC)
    490449{
    491450    int day = dateToDayInYear(t.year + 1900, t.month, t.monthDay);
     
    494453
    495454    if (!inputIsUTC) { // convert to UTC
    496         double utcOffset = getUTCOffset();
     455        double utcOffset = getUTCOffset(exec);
    497456        result -= utcOffset;
    498457        result -= getDSTOffset(result, utcOffset);
     
    503462
    504463// input is UTC
    505 void msToGregorianDateTime(double ms, bool outputIsUTC, GregorianDateTime& tm)
     464void msToGregorianDateTime(ExecState* exec, double ms, bool outputIsUTC, GregorianDateTime& tm)
    506465{
    507466    double dstOff = 0.0;
    508467    double utcOff = 0.0;
    509468    if (!outputIsUTC) {
    510         utcOff = getUTCOffset();
     469        utcOff = getUTCOffset(exec);
    511470        dstOff = getDSTOffset(ms, utcOff);
    512471        ms += dstOff + utcOff;
     
    535494
    536495    equivalentYearForDST(2000); // Need to call once to initialize a static used in this function.
    537 #if PLATFORM(DARWIN)
    538     // Register for a notification whenever the time zone changes.
    539     uint32_t status = notify_register_check("com.apple.system.timezone", &s_notificationToken);
    540     if (status == NOTIFY_STATUS_OK) {
    541         s_cachedUTCOffset = calculateUTCOffset();
    542         s_haveCachedUTCOffset = true;
    543     }
    544 #endif
    545496}
    546497
     
    623574}
    624575
    625 double parseDateFromNullTerminatedCharacters(const char* dateString)
     576// Odd case where 'exec' is allowed to be 0, to accomodate a caller in WebCore.
     577double parseDateFromNullTerminatedCharacters(const char* dateString, ExecState* exec)
    626578{
    627579    // This parses a date in the form:
     
    890842            year += 1900;
    891843    }
    892 
     844   
     845    double ms = ymdhmsToSeconds(year, month + 1, day, hour, minute, second) * msPerSecond;
    893846    // fall back to local timezone
    894847    if (!haveTZ) {
    895         GregorianDateTime t;
    896         t.monthDay = day;
    897         t.month = month;
    898         t.year = year - 1900;
    899         t.isDST = -1;
    900         t.second = second;
    901         t.minute = minute;
    902         t.hour = hour;
    903 
    904         // Use our gregorianDateTimeToMS() rather than mktime() as the latter can't handle the full year range.
    905         return gregorianDateTimeToMS(t, 0, false);
    906     }
    907 
    908     return (ymdhmsToSeconds(year, month + 1, day, hour, minute, second) - (offset * 60.0)) * msPerSecond;
     848        if (exec) {
     849            double utcOffset = getUTCOffset(exec);
     850            double dstOffset = getDSTOffset(ms, utcOffset);
     851            offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute);
     852        } else {
     853            double utcOffset = calculateUTCOffset();
     854            double dstOffset = getDSTOffset(ms, utcOffset);
     855            offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute);
     856        }
     857    }
     858
     859    return ms - (offset * msPerMinute);
    909860}
    910861
     
    919870
    920871
    921 } // namespace WTF
     872} // namespace JSC
  • trunk/JavaScriptCore/wtf/DateMath.h

    r50591 r50608  
    4545#include <time.h>
    4646#include <string.h>
     47#include <wtf/CurrentTime.h>
    4748#include <wtf/Noncopyable.h>
     49#include <wtf/UnusedParam.h>
    4850
    49 namespace WTF {
     51namespace JSC {
    5052
     53class ExecState;
    5154struct GregorianDateTime;
    5255
    5356void initializeDates();
    54 void msToGregorianDateTime(double, bool outputIsUTC, GregorianDateTime&);
    55 double gregorianDateTimeToMS(const GregorianDateTime&, double, bool inputIsUTC);
    56 double getUTCOffset();
     57void msToGregorianDateTime(ExecState*, double, bool outputIsUTC, GregorianDateTime&);
     58double gregorianDateTimeToMS(ExecState*, const GregorianDateTime&, double, bool inputIsUTC);
     59double getUTCOffset(ExecState*);
    5760int equivalentYearForDST(int year);
    58 double getCurrentUTCTime();
    59 double getCurrentUTCTimeWithMicroseconds();
    60 void getLocalTime(const time_t*, tm*);
    6161
    6262// Not really math related, but this is currently the only shared place to put these. 
    63 double parseDateFromNullTerminatedCharacters(const char*);
     63double parseDateFromNullTerminatedCharacters(const char* dateString, ExecState* exec); // exec may be 0
    6464double timeClip(double);
     65
     66inline double jsCurrentTime()
     67{
     68    // JavaScript doesn't recognize fractions of a millisecond.
     69    return floor(WTF::currentTimeMS());
     70}
    6571
    6672const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
     
    99105    }
    100106
    101     GregorianDateTime(const tm& inTm)
     107    GregorianDateTime(ExecState* exec, const tm& inTm)
    102108        : second(inTm.tm_sec)
    103109        , minute(inTm.tm_min)
     
    110116        , isDST(inTm.tm_isdst)
    111117    {
     118        UNUSED_PARAM(exec);
    112119#if HAVE(TM_GMTOFF)
    113120        utcOffset = static_cast<int>(inTm.tm_gmtoff);
    114121#else
    115         utcOffset = static_cast<int>(getUTCOffset() / msPerSecond + (isDST ? secondsPerHour : 0));
     122        utcOffset = static_cast<int>(getUTCOffset(exec) / msPerSecond + (isDST ? secondsPerHour : 0));
    116123#endif
    117124
     
    188195}
    189196
    190 } // namespace WTF
     197} // namespace JSC
    191198
    192199#endif // DateMath_h
Note: See TracChangeset for help on using the changeset viewer.