Changeset 10713 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Oct 3, 2005, 6:43:58 PM (20 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r10701 r10713 32 32 #include <algorithm> 33 33 34 #if !WIN3234 #if __APPLE__ 35 35 36 36 #include <CoreFoundation/CoreFoundation.h> … … 40 40 #include <mach/thread_act.h> 41 41 42 #elif WIN32 43 44 #include <windows.h> 45 42 46 #else 43 47 44 #include < windows.h>48 #include <pthread.h> 45 49 46 50 #endif … … 292 296 setjmp(registers); 293 297 294 #if !WIN32298 #if __APPLE__ 295 299 pthread_t thread = pthread_self(); 296 300 void *stackBase = pthread_get_stackaddr_np(thread); 297 #el se301 #elif WIN32 298 302 NT_TIB *pTib; 299 303 __asm { … … 302 306 } 303 307 void *stackBase = (void *)pTib->StackBase; 308 #else 309 void *stackBase = 0; 310 pthread_attr_t sattr; 311 // FIXME: this function is non-portable; other POSIX systems may have different np alternatives 312 pthread_getattr_np(pthread_self(), &sattr); 313 // Should work but fails on Linux (?) 314 // pthread_attr_getstack(&sattr, &stackBase, &stackSize); 315 pthread_attr_getstackaddr(&sattr, &stackBase); 316 assert(stackBase); 304 317 #endif 305 318 … … 318 331 thread_suspend(thread->machThread); 319 332 320 #if defined(__i386__)333 #if __i386__ 321 334 i386_thread_state_t regs; 322 335 unsigned user_count = sizeof(regs)/sizeof(int); 323 336 thread_state_flavor_t flavor = i386_THREAD_STATE; 324 #elif defined(__ppc__)337 #elif __ppc__ 325 338 ppc_thread_state_t regs; 326 339 unsigned user_count = PPC_THREAD_STATE_COUNT; 327 340 thread_state_flavor_t flavor = PPC_THREAD_STATE; 328 #elif defined(__ppc64__)341 #elif __ppc64__ 329 342 ppc_thread_state64_t regs; 330 343 unsigned user_count = PPC_THREAD_STATE64_COUNT; … … 340 353 341 354 // scan the stack 342 #if defined(__i386__)355 #if __i386__ 343 356 markStackObjectsConservatively((void *)regs.esp, pthread_get_stackaddr_np(thread->posixThread)); 344 357 #elif defined(__ppc__) || defined(__ppc64__) -
trunk/JavaScriptCore/kjs/config.h
r10701 r10713 1 #if !WIN321 #if __APPLE__ 2 2 3 3 #define HAVE_FUNC_ISINF 1 … … 8 8 #define TIME_WITH_SYS_TIME 1 9 9 10 #el se10 #elif WIN32 11 11 12 12 #define HAVE_FLOAT_H 1 13 13 #define HAVE_FUNC__FINITE 1 14 14 #define HAVE_SYS_TIMEB_H 1 15 16 #else 17 18 #define HAVE_FUNC_ISINF 1 19 #define HAVE_FUNC_ISNAN 1 20 #define HAVE_STRINGS_H 1 21 #define HAVE_SYS_PARAM_H 1 22 #define HAVE_SYS_TIME_H 1 23 #define TIME_WITH_SYS_TIME 1 24 #define HAVE_ERRNO_H 1 15 25 16 26 #endif -
trunk/JavaScriptCore/kjs/date_object.cpp
r10675 r10713 21 21 */ 22 22 23 #ifdef HAVE_CONFIG_H 24 #include <config.h> 25 #endif 23 #include "config.h" 26 24 #ifndef HAVE_SYS_TIMEB_H 27 25 #define HAVE_SYS_TIMEB_H 0 … … 42 40 #endif 43 41 42 #ifdef HAVE_ERRNO_H 43 #include <errno.h> 44 #endif 45 44 46 #ifdef HAVE_SYS_PARAM_H 45 47 # include <sys/param.h> … … 76 78 const double msPerHour = msPerMinute * minutesPerHour; 77 79 const double msPerDay = msPerHour * hoursPerDay; 78 79 #if APPLE_CHANGES 80 static const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; 81 static const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; 82 83 #ifdef APPLE_CHANGES 80 84 81 85 // Originally, we wrote our own implementation that uses Core Foundation because of a performance problem in Mac OS X 10.2. … … 97 101 #define strftime(a, b, c, d) NotAllowedToCallThis() 98 102 99 static const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };100 static const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };101 102 103 static struct tm *tmUsingCF(time_t clock, CFTimeZoneRef timeZone) 103 104 { … … 223 224 } 224 225 return result; 225 }226 227 static UString formatDate(struct tm &tm)228 {229 char buffer[100];230 snprintf(buffer, sizeof(buffer), "%s %s %02d %04d",231 weekdayName[(tm.tm_wday + 6) % 7],232 monthName[tm.tm_mon], tm.tm_mday, tm.tm_year + 1900);233 return buffer;234 }235 236 static UString formatDateUTCVariant(struct tm &tm)237 {238 char buffer[100];239 snprintf(buffer, sizeof(buffer), "%s, %02d %s %04d",240 weekdayName[(tm.tm_wday + 6) % 7],241 tm.tm_mday, monthName[tm.tm_mon], tm.tm_year + 1900);242 return buffer;243 }244 245 static UString formatTime(struct tm &tm)246 {247 char buffer[100];248 if (tm.tm_gmtoff == 0) {249 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT", tm.tm_hour, tm.tm_min, tm.tm_sec);250 } else {251 int offset = tm.tm_gmtoff;252 if (offset < 0) {253 offset = -offset;254 }255 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d",256 tm.tm_hour, tm.tm_min, tm.tm_sec,257 tm.tm_gmtoff < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60);258 }259 return UString(buffer);260 226 } 261 227 … … 327 293 namespace KJS { 328 294 295 static UString formatDate(struct tm &tm) 296 { 297 char buffer[100]; 298 snprintf(buffer, sizeof(buffer), "%s %s %02d %04d", 299 weekdayName[(tm.tm_wday + 6) % 7], 300 monthName[tm.tm_mon], tm.tm_mday, tm.tm_year + 1900); 301 return buffer; 302 } 303 304 static UString formatDateUTCVariant(struct tm &tm) 305 { 306 char buffer[100]; 307 snprintf(buffer, sizeof(buffer), "%s, %02d %s %04d", 308 weekdayName[(tm.tm_wday + 6) % 7], 309 tm.tm_mday, monthName[tm.tm_mon], tm.tm_year + 1900); 310 return buffer; 311 } 312 313 static UString formatTime(struct tm &tm) 314 { 315 char buffer[100]; 316 if (tm.tm_gmtoff == 0) { 317 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT", tm.tm_hour, tm.tm_min, tm.tm_sec); 318 } else { 319 int offset = tm.tm_gmtoff; 320 if (offset < 0) { 321 offset = -offset; 322 } 323 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d", 324 tm.tm_hour, tm.tm_min, tm.tm_sec, 325 tm.tm_gmtoff < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60); 326 } 327 return UString(buffer); 328 } 329 329 330 static int day(double t) 330 331 { … … 389 390 static long timeZoneOffset(const struct tm *t) 390 391 { 391 #if defined BSD || defined(__linux__) || defined(__APPLE__)392 #if !defined(WIN32) 392 393 return -(t->tm_gmtoff / 60); 393 394 #else … … 583 584 ValueImp *result = NULL; 584 585 UString s; 585 #if ! APPLE_CHANGES586 #if !defined(APPLE_CHANGES) || !APPLE_CHANGES 586 587 const int bufsize=100; 587 588 char timebuffer[bufsize]; … … 592 593 ValueImp *v = thisObj->internalValue(); 593 594 double milli = v->toNumber(exec); 594 595 595 if (isNaN(milli)) { 596 596 switch (id) { … … 638 638 double ms = milli - tv * 1000.0; 639 639 640 // FIXME: not threadsafe (either of these options) 640 641 struct tm *t = utc ? gmtime(&tv) : localtime(&tv); 641 642 // we had an out of range year. use that one (plus/minus offset … … 650 651 t->tm_wday = weekDay(m); 651 652 } 652 653 653 654 switch (id) { 654 #if APPLE_CHANGES655 655 case ToString: 656 656 result = String(formatDate(*t) + " " + formatTime(*t)); … … 666 666 result = String(formatDateUTCVariant(*t) + " " + formatTime(*t)); 667 667 break; 668 #if APPLE_CHANGES 668 669 case ToLocaleString: 669 670 result = String(formatLocaleDate(exec, secs, true, true, args)); … … 676 677 break; 677 678 #else 678 case ToString:679 s = ctime(&tv);680 result = String(s.substr(0, s.size() - 1));681 break;682 case ToDateString:683 case ToTimeString:684 case ToGMTString:685 case ToUTCString:686 setlocale(LC_TIME,"C");687 if (id == DateProtoFuncImp::ToDateString) {688 strftime(timebuffer, bufsize, "%x",t);689 } else if (id == DateProtoFuncImp::ToTimeString) {690 strftime(timebuffer, bufsize, "%X",t);691 } else { // toGMTString & toUTCString692 strftime(timebuffer, bufsize, "%a, %d %b %Y %H:%M:%S %Z", t);693 }694 setlocale(LC_TIME,oldlocale.c_str());695 result = String(timebuffer);696 break;697 679 case ToLocaleString: 698 680 strftime(timebuffer, bufsize, "%c", t); … … 746 728 break; 747 729 case GetTimezoneOffset: 748 #if defined BSD || defined(__APPLE__) 749 result = Number(-t->tm_gmtoff / 60); 750 #else 730 #if WIN32 751 731 # if defined(__BORLANDC__) 752 732 #error please add daylight savings offset here! … … 757 737 result = Number(( timezone / 60 - ( daylight ? 60 : 0 ))); 758 738 # endif 739 #else 740 result = Number(-t->tm_gmtoff / 60); 759 741 #endif 760 742 break; … … 848 830 #else 849 831 struct timeval tv; 832 // FIXME: not threadsafe 850 833 gettimeofday(&tv, 0L); 851 834 double utc = floor((double)tv.tv_sec * 1000.0 + (double)tv.tv_usec / 1000.0); … … 893 876 894 877 // ECMA 15.9.2 895 ValueImp *DateObjectImp::callAsFunction(ExecState * /*exec*/, ObjectImp */*thisObj*/, const List &/*args*/)878 ValueImp *DateObjectImp::callAsFunction(ExecState * /*exec*/, ObjectImp * /*thisObj*/, const List &/*args*/) 896 879 { 897 880 time_t t = time(0L); 898 #if APPLE_CHANGES 881 // FIXME: not threadsafe 899 882 struct tm *tm = localtime(&t); 900 883 return String(formatDate(*tm) + " " + formatTime(*tm)); 901 #else902 UString s(ctime(&t));903 904 // return formatted string minus trailing \n905 return String(s.substr(0, s.size() - 1));906 #endif907 884 } 908 885 … … 1011 988 if (utc) { 1012 989 time_t zero = 0; 1013 #if defined BSD || defined(__linux__) || defined(__APPLE__) 1014 struct tm t3; 1015 localtime_r(&zero, &t3); 1016 utcOffset = t3.tm_gmtoff; 1017 t->tm_isdst = t3.tm_isdst; 1018 #else 990 #if defined(WIN32) 991 // FIXME: not threadsafe 1019 992 (void)localtime(&zero); 1020 993 # if defined(__BORLANDC__) || defined(__CYGWIN__) … … 1024 997 # endif 1025 998 t->tm_isdst = 0; 999 #else 1000 struct tm t3; 1001 localtime_r(&zero, &t3); 1002 utcOffset = t3.tm_gmtoff; 1003 t->tm_isdst = t3.tm_isdst; 1026 1004 #endif 1027 1005 } else { … … 1029 1007 t->tm_isdst = -1; 1030 1008 } 1031 1009 1010 #ifdef __APPLE__ 1032 1011 // t->tm_year must hold the bulk of the data to avoid overflow when converting 1033 1012 // to a CFGregorianDate. (CFGregorianDate.month is an SInt8; CFGregorianDate.year is an SInt32.) 1034 1013 t->tm_year += t->tm_mon / 12; 1035 1014 t->tm_mon %= 12; 1036 1015 #endif 1037 1016 1038 1017 double yearOffset = 0.0; -
trunk/JavaScriptCore/kjs/identifier.cpp
r10701 r10713 26 26 // runs at init time. 27 27 28 #if ! WIN32// can't get this to compile on Visual C++ yet28 #if !defined(WIN32) // can't get this to compile on Visual C++ yet 29 29 #define AVOID_STATIC_CONSTRUCTORS 1 30 30 #endif -
trunk/JavaScriptCore/kjs/internal.cpp
r10701 r10713 75 75 #endif // APPLE_CHANGES 76 76 77 #if !KJS_MULTIPLE_THREADS 78 79 static inline void initializeInterpreterLock() { } 80 static inline void lockInterpreter() { } 81 static inline void unlockInterpreter() { } 82 83 const int interpreterLockCount = 1; 84 85 #else 77 #if defined(KJS_MULTIPLE_THREADS) && KJS_MULTIPLE_THREADS 86 78 87 79 static pthread_once_t interpreterLockOnce = PTHREAD_ONCE_INIT; … … 113 105 } 114 106 107 #else 108 109 static inline void initializeInterpreterLock() { } 110 static inline void lockInterpreter() { } 111 static inline void unlockInterpreter() { } 112 113 const int interpreterLockCount = 1; 114 115 115 #endif 116 116 117 117 // ------------------------------ UndefinedImp --------------------------------- 118 118 119 ValueImp *UndefinedImp::toPrimitive(ExecState * /*exec*/, Type) const119 ValueImp *UndefinedImp::toPrimitive(ExecState *, Type) const 120 120 { 121 121 return const_cast<UndefinedImp *>(this); 122 122 } 123 123 124 bool UndefinedImp::toBoolean(ExecState * /*exec*/) const124 bool UndefinedImp::toBoolean(ExecState *) const 125 125 { 126 126 return false; 127 127 } 128 128 129 double UndefinedImp::toNumber(ExecState * /*exec*/) const129 double UndefinedImp::toNumber(ExecState *) const 130 130 { 131 131 return NaN; 132 132 } 133 133 134 UString UndefinedImp::toString(ExecState * /*exec*/) const134 UString UndefinedImp::toString(ExecState *) const 135 135 { 136 136 return "undefined"; … … 144 144 // ------------------------------ NullImp -------------------------------------- 145 145 146 ValueImp *NullImp::toPrimitive(ExecState * /*exec*/, Type) const146 ValueImp *NullImp::toPrimitive(ExecState *, Type) const 147 147 { 148 148 return const_cast<NullImp *>(this); 149 149 } 150 150 151 bool NullImp::toBoolean(ExecState * /*exec*/) const151 bool NullImp::toBoolean(ExecState *) const 152 152 { 153 153 return false; 154 154 } 155 155 156 double NullImp::toNumber(ExecState * /*exec*/) const156 double NullImp::toNumber(ExecState *) const 157 157 { 158 158 return 0.0; 159 159 } 160 160 161 UString NullImp::toString(ExecState * /*exec*/) const161 UString NullImp::toString(ExecState *) const 162 162 { 163 163 return "null"; … … 171 171 // ------------------------------ BooleanImp ----------------------------------- 172 172 173 ValueImp *BooleanImp::toPrimitive(ExecState * /*exec*/, Type) const173 ValueImp *BooleanImp::toPrimitive(ExecState *, Type) const 174 174 { 175 175 return const_cast<BooleanImp *>(this); 176 176 } 177 177 178 bool BooleanImp::toBoolean(ExecState * /*exec*/) const178 bool BooleanImp::toBoolean(ExecState *) const 179 179 { 180 180 return val; 181 181 } 182 182 183 double BooleanImp::toNumber(ExecState * /*exec*/) const183 double BooleanImp::toNumber(ExecState *) const 184 184 { 185 185 return val ? 1.0 : 0.0; 186 186 } 187 187 188 UString BooleanImp::toString(ExecState * /*exec*/) const188 UString BooleanImp::toString(ExecState *) const 189 189 { 190 190 return val ? "true" : "false"; … … 200 200 // ------------------------------ StringImp ------------------------------------ 201 201 202 ValueImp *StringImp::toPrimitive(ExecState * /*exec*/, Type) const202 ValueImp *StringImp::toPrimitive(ExecState *, Type) const 203 203 { 204 204 return const_cast<StringImp *>(this); 205 205 } 206 206 207 bool StringImp::toBoolean(ExecState * /*exec*/) const207 bool StringImp::toBoolean(ExecState *) const 208 208 { 209 209 return (val.size() > 0); 210 210 } 211 211 212 double StringImp::toNumber(ExecState * /*exec*/) const212 double StringImp::toNumber(ExecState *) const 213 213 { 214 214 return val.toDouble(); 215 215 } 216 216 217 UString StringImp::toString(ExecState * /*exec*/) const217 UString StringImp::toString(ExecState *) const 218 218 { 219 219 return val; -
trunk/JavaScriptCore/kjs/internal.h
r10634 r10713 35 35 #include <kxmlcore/SharedPtr.h> 36 36 37 #if !WIN3237 #if __APPLE__ 38 38 #define KJS_MULTIPLE_THREADS 1 39 39 #endif -
trunk/JavaScriptCore/kjs/protected_values.cpp
r10701 r10713 28 28 #include "internal.h" 29 29 #include <stdint.h> 30 #include <stdlib.h> 30 31 #include "value.h" 31 32
Note:
See TracChangeset
for help on using the changeset viewer.