Changeset 50608 in webkit for trunk/JavaScriptCore
- Timestamp:
- Nov 6, 2009, 3:33:17 PM (16 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r50599 r50608 1 2009-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 1 78 2009-11-06 Gabor Loki <[email protected]> 2 79 -
trunk/JavaScriptCore/JavaScriptCore.exp
r50591 r50608 179 179 __ZN3JSC25evaluateInGlobalCallFrameERKNS_7UStringERNS_7JSValueEPNS_14JSGlobalObjectE 180 180 __ZN3JSC35createInterruptedExecutionExceptionEPNS_12JSGlobalDataE 181 __ZN3JSC37parseDateFromNullTerminatedCharactersEPKcPNS_9ExecStateE 182 __ZN3JSC3NaNE 181 183 __ZN3JSC4Heap11objectCountEv 182 184 __ZN3JSC4Heap14primaryHeapEndEv … … 331 333 __ZN3WTF28setMainThreadCallbacksPausedEb 332 334 __ZN3WTF36lockAtomicallyInitializedStaticMutexEv 333 __ZN3WTF37parseDateFromNullTerminatedCharactersEPKc334 335 __ZN3WTF38unlockAtomicallyInitializedStaticMutexEv 335 336 __ZN3WTF5Mutex4lockEv -
trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
r50174 r50608 669 669 > 670 670 </File> 671 <File 672 RelativePath="..\..\wtf\DateMath.cpp" 673 > 674 </File> 675 <File 676 RelativePath="..\..\wtf\DateMath.h" 677 > 678 </File> 671 679 <File 672 680 RelativePath="..\..\runtime\DatePrototype.cpp" -
trunk/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj
r49705 r50608 286 286 </File> 287 287 <File 288 RelativePath="..\..\wtf\DateMath.cpp"289 >290 </File>291 <File292 RelativePath="..\..\wtf\DateMath.h"293 >294 </File>295 <File296 288 RelativePath="..\..\wtf\Deque.h" 297 289 > -
trunk/JavaScriptCore/JavaScriptCoreSources.bkl
r47781 r50608 90 90 runtime/DateConversion.cpp 91 91 runtime/DateInstance.cpp 92 wtf/DateMath.cpp 92 93 runtime/DatePrototype.cpp 93 94 runtime/Error.cpp … … 174 175 wtf/ByteArray.cpp 175 176 wtf/CurrentTime.cpp 176 wtf/DateMath.cpp177 177 wtf/FastMalloc.cpp 178 178 wtf/HashTable.cpp -
trunk/JavaScriptCore/interpreter/CachedCall.h
r50591 r50608 39 39 , m_interpreter(callFrame->interpreter()) 40 40 , m_exception(exception) 41 , m_globalObjectScope(callFrame, callFrame->globalData().dynamicGlobalObject ? callFrame->globalData().dynamicGlobalObject :function->scope().globalObject())41 , m_globalObjectScope(callFrame, function->scope().globalObject()) 42 42 { 43 43 ASSERT(!function->isHostFunction()); -
trunk/JavaScriptCore/interpreter/Interpreter.cpp
r50591 r50608 648 648 } 649 649 650 DynamicGlobalObjectScope globalObjectScope(callFrame, callFrame->globalData().dynamicGlobalObject ? callFrame->globalData().dynamicGlobalObject :scopeChain->globalObject);650 DynamicGlobalObjectScope globalObjectScope(callFrame, scopeChain->globalObject); 651 651 652 652 CallFrame* newCallFrame = CallFrame::create(oldEnd); … … 778 778 } 779 779 780 DynamicGlobalObjectScope globalObjectScope(callFrame, callFrame->globalData().dynamicGlobalObject ? callFrame->globalData().dynamicGlobalObject :scopeChain->globalObject);780 DynamicGlobalObjectScope globalObjectScope(callFrame, scopeChain->globalObject); 781 781 782 782 EvalCodeBlock* codeBlock = &eval->bytecode(callFrame, scopeChain); -
trunk/JavaScriptCore/pcre/pcre_exec.cpp
r46118 r50608 2165 2165 HistogramTimeLogger::HistogramTimeLogger(const JSRegExp* re) 2166 2166 : m_re(re) 2167 , m_startTime( getCurrentUTCTimeWithMicroseconds())2167 , m_startTime(currentTimeMS()) 2168 2168 { 2169 2169 } … … 2172 2172 { 2173 2173 static Histogram histogram; 2174 histogram.add(m_re, getCurrentUTCTimeWithMicroseconds() - m_startTime);2174 histogram.add(m_re, currentTimeMS() - m_startTime); 2175 2175 } 2176 2176 -
trunk/JavaScriptCore/profiler/ProfileNode.cpp
r44508 r50608 38 38 #endif 39 39 40 using namespace WTF; 41 40 42 namespace JSC { 41 43 … … 50 52 return static_cast<double>(counter.QuadPart) / frequency.QuadPart; 51 53 #else 52 return WTF::getCurrentUTCTimeWithMicroseconds();54 return currentTimeMS(); 53 55 #endif 54 56 } -
trunk/JavaScriptCore/runtime/DateConstructor.cpp
r50591 r50608 78 78 79 79 if (numArgs == 0) // new Date() ECMA 15.9.3.3 80 value = getCurrentUTCTime();80 value = jsCurrentTime(); 81 81 else if (numArgs == 1) { 82 82 if (args.at(0).inherits(&DateInstance::info)) … … 85 85 JSValue primitive = args.at(0).toPrimitive(exec); 86 86 if (primitive.isString()) 87 value = parseDate( primitive.getString());87 value = parseDate(exec, primitive.getString()); 88 88 else 89 89 value = primitive.toNumber(exec); … … 109 109 t.isDST = -1; 110 110 double ms = (numArgs >= 7) ? args.at(6).toNumber(exec) : 0; 111 value = gregorianDateTimeToMS( t, ms, false);111 value = gregorianDateTimeToMS(exec, t, ms, false); 112 112 } 113 113 } … … 133 133 tm localTM; 134 134 getLocalTime(&localTime, &localTM); 135 GregorianDateTime ts( localTM);135 GregorianDateTime ts(exec, localTM); 136 136 return jsNontrivialString(exec, formatDate(ts) + " " + formatTime(ts, false)); 137 137 } … … 145 145 static JSValue JSC_HOST_CALL dateParse(ExecState* exec, JSObject*, JSValue, const ArgList& args) 146 146 { 147 return jsNumber(exec, parseDate( args.at(0).toString(exec)));147 return jsNumber(exec, parseDate(exec, args.at(0).toString(exec))); 148 148 } 149 149 150 150 static JSValue JSC_HOST_CALL dateNow(ExecState* exec, JSObject*, JSValue, const ArgList&) 151 151 { 152 return jsNumber(exec, getCurrentUTCTime());152 return jsNumber(exec, jsCurrentTime()); 153 153 } 154 154 … … 174 174 t.second = args.at(5).toInt32(exec); 175 175 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)); 177 177 } 178 178 -
trunk/JavaScriptCore/runtime/DateConversion.cpp
r50591 r50608 52 52 namespace JSC { 53 53 54 double parseDate( const UString &date)54 double parseDate(ExecState* exec, const UString &date) 55 55 { 56 return parseDateFromNullTerminatedCharacters(date.UTF8String().c_str() );56 return parseDateFromNullTerminatedCharacters(date.UTF8String().c_str(), exec); 57 57 } 58 58 -
trunk/JavaScriptCore/runtime/DateConversion.h
r50591 r50608 43 43 #define DateConversion_h 44 44 45 namespace WTF {46 struct GregorianDateTime;47 }48 49 45 namespace JSC { 50 46 47 class ExecState; 51 48 class UString; 49 struct GregorianDateTime; 52 50 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);51 double parseDate(ExecState* exec, const UString&); 52 UString formatDate(const GregorianDateTime&); 53 UString formatDateUTCVariant(const GregorianDateTime&); 54 UString formatTime(const GregorianDateTime&, bool inputIsUTC); 57 55 58 56 } // namespace JSC -
trunk/JavaScriptCore/runtime/DateInstance.cpp
r50591 r50608 58 58 if (outputIsUTC) { 59 59 if (m_data->m_gregorianDateTimeUTCCachedForMS != milli) { 60 msToGregorianDateTime( internalNumber(), true, m_data->m_cachedGregorianDateTimeUTC);60 msToGregorianDateTime(exec, internalNumber(), true, m_data->m_cachedGregorianDateTimeUTC); 61 61 m_data->m_gregorianDateTimeUTCCachedForMS = milli; 62 62 } … … 65 65 66 66 if (m_data->m_gregorianDateTimeCachedForMS != milli) { 67 msToGregorianDateTime( internalNumber(), false, m_data->m_cachedGregorianDateTime);67 msToGregorianDateTime(exec, internalNumber(), false, m_data->m_cachedGregorianDateTime); 68 68 m_data->m_gregorianDateTimeCachedForMS = milli; 69 69 } -
trunk/JavaScriptCore/runtime/DateInstance.h
r50591 r50608 39 39 static JS_EXPORTDATA const ClassInfo info; 40 40 41 const WTF::GregorianDateTime* gregorianDateTime(ExecState*, bool outputIsUTC) const;41 const GregorianDateTime* gregorianDateTime(ExecState*, bool outputIsUTC) const; 42 42 43 43 static PassRefPtr<Structure> createStructure(JSValue prototype) -
trunk/JavaScriptCore/runtime/DateInstanceCache.h
r50591 r50608 41 41 42 42 double m_gregorianDateTimeCachedForMS; 43 WTF::GregorianDateTime m_cachedGregorianDateTime;43 GregorianDateTime m_cachedGregorianDateTime; 44 44 double m_gregorianDateTimeUTCCachedForMS; 45 WTF::GregorianDateTime m_cachedGregorianDateTimeUTC;45 GregorianDateTime m_cachedGregorianDateTimeUTC; 46 46 47 47 private: -
trunk/JavaScriptCore/runtime/DatePrototype.cpp
r50591 r50608 843 843 } 844 844 845 JSValue result = jsNumber(exec, gregorianDateTimeToMS( gregorianDateTime, ms, inputIsUTC));845 JSValue result = jsNumber(exec, gregorianDateTimeToMS(exec, gregorianDateTime, ms, inputIsUTC)); 846 846 thisDateObj->setInternalValue(result); 847 847 return result; … … 865 865 GregorianDateTime gregorianDateTime; 866 866 if (numArgsToUse == 3 && isnan(milli)) 867 WTF::msToGregorianDateTime(0, true, gregorianDateTime);867 msToGregorianDateTime(exec, 0, true, gregorianDateTime); 868 868 else { 869 869 ms = milli - floor(milli / msPerSecond) * msPerSecond; … … 880 880 } 881 881 882 JSValue result = jsNumber(exec, gregorianDateTimeToMS( gregorianDateTime, ms, inputIsUTC));882 JSValue result = jsNumber(exec, gregorianDateTimeToMS(exec, gregorianDateTime, ms, inputIsUTC)); 883 883 thisDateObj->setInternalValue(result); 884 884 return result; … … 990 990 // Based on ECMA 262 B.2.5 (setYear) 991 991 // the time must be reset to +0 if it is NaN. 992 msToGregorianDateTime( 0, true, gregorianDateTime);992 msToGregorianDateTime(exec, 0, true, gregorianDateTime); 993 993 else { 994 994 double secs = floor(milli / msPerSecond); … … 1007 1007 1008 1008 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)); 1010 1010 thisDateObj->setInternalValue(result); 1011 1011 return result; -
trunk/JavaScriptCore/runtime/InitializeThreading.cpp
r50591 r50608 52 52 #if ENABLE(JSC_MULTIPLE_THREADS) 53 53 s_dtoaP5Mutex = new Mutex; 54 WTF::initializeDates();54 initializeDates(); 55 55 #endif 56 56 } -
trunk/JavaScriptCore/runtime/JSGlobalData.cpp
r50591 r50608 148 148 , firstStringifierToMark(0) 149 149 , markStack(vptrSet.jsArrayVPtr) 150 , cachedUTCOffset(NaN) 150 151 #ifndef NDEBUG 151 152 , mainThreadOnly(false) -
trunk/JavaScriptCore/runtime/JSGlobalData.h
r50591 r50608 154 154 MarkStack markStack; 155 155 156 double cachedUTCOffset; 157 156 158 #ifndef NDEBUG 157 159 bool mainThreadOnly; -
trunk/JavaScriptCore/runtime/JSGlobalObject.h
r50591 r50608 443 443 , m_savedDynamicGlobalObject(m_dynamicGlobalObjectSlot) 444 444 { 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 } 446 452 } 447 453 -
trunk/JavaScriptCore/wtf/CurrentTime.h
r42851 r50608 35 35 namespace WTF { 36 36 37 // Returns the current system (UTC) time in seconds, startingJanuary 1, 1970.38 // Precision varies depending on a platform but usually isas good or better37 // 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 39 39 // than a millisecond. 40 40 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 } 41 58 42 59 } // namespace WTF -
trunk/JavaScriptCore/wtf/DateMath.cpp
r50591 r50608 51 51 #include "StringExtras.h" 52 52 53 #include "CallFrame.h" 54 53 55 #include <algorithm> 54 56 #include <limits.h> … … 62 64 #endif 63 65 64 #if PLATFORM(DARWIN)65 #include <notify.h>66 #endif67 68 66 #if PLATFORM(WINCE) 69 67 extern "C" size_t strftime(char * const s, const size_t maxsize, const char * const format, const struct tm * const t); … … 81 79 #define NaN std::numeric_limits<double>::quiet_NaN() 82 80 83 namespace WTF { 81 using namespace WTF; 82 83 namespace JSC { 84 84 85 85 /* Constants */ … … 294 294 } 295 295 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 #else314 localtime_r(localTime, localTM);315 #endif316 }317 318 296 // There is a hard limit at 2038 that we currently do not have a workaround 319 297 // for (rdar://problem/5052975). … … 329 307 // minus 27 instead, to ensure there is a range of 28 years that all years 330 308 // can map to. 331 return std::min(msToYear( getCurrentUTCTime()), maximumYearForDST() - 27) ;309 return std::min(msToYear(jsCurrentTime()), maximumYearForDST() - 27) ; 332 310 } 333 311 … … 400 378 } 401 379 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 #endif407 408 380 /* 409 381 * Get the difference in milliseconds between this time zone and UTC (GMT) 410 382 * NOT including DST. 411 383 */ 412 double getUTCOffset() 413 { 414 #if PLATFORM(DARWIN) 415 if (s_haveCachedUTCOffset) { 416 int notified; 417 uint32_t status = notify_check(s_notificationToken, ¬ified); 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; 384 double 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; 432 391 } 433 392 … … 487 446 } 488 447 489 double gregorianDateTimeToMS( const GregorianDateTime& t, double milliSeconds, bool inputIsUTC)448 double gregorianDateTimeToMS(ExecState* exec, const GregorianDateTime& t, double milliSeconds, bool inputIsUTC) 490 449 { 491 450 int day = dateToDayInYear(t.year + 1900, t.month, t.monthDay); … … 494 453 495 454 if (!inputIsUTC) { // convert to UTC 496 double utcOffset = getUTCOffset( );455 double utcOffset = getUTCOffset(exec); 497 456 result -= utcOffset; 498 457 result -= getDSTOffset(result, utcOffset); … … 503 462 504 463 // input is UTC 505 void msToGregorianDateTime( double ms, bool outputIsUTC, GregorianDateTime& tm)464 void msToGregorianDateTime(ExecState* exec, double ms, bool outputIsUTC, GregorianDateTime& tm) 506 465 { 507 466 double dstOff = 0.0; 508 467 double utcOff = 0.0; 509 468 if (!outputIsUTC) { 510 utcOff = getUTCOffset( );469 utcOff = getUTCOffset(exec); 511 470 dstOff = getDSTOffset(ms, utcOff); 512 471 ms += dstOff + utcOff; … … 535 494 536 495 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 #endif545 496 } 546 497 … … 623 574 } 624 575 625 double parseDateFromNullTerminatedCharacters(const char* dateString) 576 // Odd case where 'exec' is allowed to be 0, to accomodate a caller in WebCore. 577 double parseDateFromNullTerminatedCharacters(const char* dateString, ExecState* exec) 626 578 { 627 579 // This parses a date in the form: … … 890 842 year += 1900; 891 843 } 892 844 845 double ms = ymdhmsToSeconds(year, month + 1, day, hour, minute, second) * msPerSecond; 893 846 // fall back to local timezone 894 847 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); 909 860 } 910 861 … … 919 870 920 871 921 } // namespace WTF872 } // namespace JSC -
trunk/JavaScriptCore/wtf/DateMath.h
r50591 r50608 45 45 #include <time.h> 46 46 #include <string.h> 47 #include <wtf/CurrentTime.h> 47 48 #include <wtf/Noncopyable.h> 49 #include <wtf/UnusedParam.h> 48 50 49 namespace WTF{51 namespace JSC { 50 52 53 class ExecState; 51 54 struct GregorianDateTime; 52 55 53 56 void initializeDates(); 54 void msToGregorianDateTime( double, bool outputIsUTC, GregorianDateTime&);55 double gregorianDateTimeToMS( const GregorianDateTime&, double, bool inputIsUTC);56 double getUTCOffset( );57 void msToGregorianDateTime(ExecState*, double, bool outputIsUTC, GregorianDateTime&); 58 double gregorianDateTimeToMS(ExecState*, const GregorianDateTime&, double, bool inputIsUTC); 59 double getUTCOffset(ExecState*); 57 60 int equivalentYearForDST(int year); 58 double getCurrentUTCTime();59 double getCurrentUTCTimeWithMicroseconds();60 void getLocalTime(const time_t*, tm*);61 61 62 62 // Not really math related, but this is currently the only shared place to put these. 63 double parseDateFromNullTerminatedCharacters(const char* );63 double parseDateFromNullTerminatedCharacters(const char* dateString, ExecState* exec); // exec may be 0 64 64 double timeClip(double); 65 66 inline double jsCurrentTime() 67 { 68 // JavaScript doesn't recognize fractions of a millisecond. 69 return floor(WTF::currentTimeMS()); 70 } 65 71 66 72 const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; … … 99 105 } 100 106 101 GregorianDateTime( const tm& inTm)107 GregorianDateTime(ExecState* exec, const tm& inTm) 102 108 : second(inTm.tm_sec) 103 109 , minute(inTm.tm_min) … … 110 116 , isDST(inTm.tm_isdst) 111 117 { 118 UNUSED_PARAM(exec); 112 119 #if HAVE(TM_GMTOFF) 113 120 utcOffset = static_cast<int>(inTm.tm_gmtoff); 114 121 #else 115 utcOffset = static_cast<int>(getUTCOffset( ) / msPerSecond + (isDST ? secondsPerHour : 0));122 utcOffset = static_cast<int>(getUTCOffset(exec) / msPerSecond + (isDST ? secondsPerHour : 0)); 116 123 #endif 117 124 … … 188 195 } 189 196 190 } // namespace WTF197 } // namespace JSC 191 198 192 199 #endif // DateMath_h
Note:
See TracChangeset
for help on using the changeset viewer.