Changeset 10713 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Oct 3, 2005, 6:43:58 PM (20 years ago)
Author:
mjs
Message:

Patch from George Staikos <[email protected]>, reviewed and tweaked a bit by me.

http://bugzilla.opendarwin.org/show_bug.cgi?id=5174
Add support for compiling on Linux (likely to help for other POSIX systems too)

  • kjs/collector.cpp: (KJS::Collector::markCurrentThreadConservatively): (KJS::Collector::markOtherThreadConservatively):
  • kjs/config.h:
  • kjs/date_object.cpp: (KJS::formatDate): (KJS::formatDateUTCVariant): (KJS::formatTime): (KJS::timeZoneOffset): (KJS::DateProtoFuncImp::callAsFunction): (KJS::DateObjectImp::construct): (KJS::DateObjectImp::callAsFunction): (KJS::makeTime):
  • kjs/identifier.cpp:
  • kjs/internal.cpp: (KJS::initializeInterpreterLock): (KJS::lockInterpreter): (KJS::unlockInterpreter): (KJS::UndefinedImp::toPrimitive): (KJS::UndefinedImp::toBoolean): (KJS::UndefinedImp::toNumber): (KJS::UndefinedImp::toString): (KJS::NullImp::toPrimitive): (KJS::NullImp::toBoolean): (KJS::NullImp::toNumber): (KJS::NullImp::toString): (KJS::BooleanImp::toPrimitive): (KJS::BooleanImp::toBoolean): (KJS::BooleanImp::toNumber): (KJS::BooleanImp::toString): (KJS::StringImp::toPrimitive): (KJS::StringImp::toBoolean): (KJS::StringImp::toNumber): (KJS::StringImp::toString):
  • kjs/internal.h:
  • kjs/protected_values.cpp:
Location:
trunk/JavaScriptCore/kjs
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/collector.cpp

    r10701 r10713  
    3232#include <algorithm>
    3333
    34 #if !WIN32
     34#if __APPLE__
    3535
    3636#include <CoreFoundation/CoreFoundation.h>
     
    4040#include <mach/thread_act.h>
    4141
     42#elif WIN32
     43
     44#include <windows.h>
     45
    4246#else
    4347
    44 #include <windows.h>
     48#include <pthread.h>
    4549
    4650#endif
     
    292296    setjmp(registers);
    293297
    294 #if !WIN32
     298#if __APPLE__
    295299    pthread_t thread = pthread_self();
    296300    void *stackBase = pthread_get_stackaddr_np(thread);
    297 #else
     301#elif WIN32
    298302    NT_TIB *pTib;
    299303    __asm {
     
    302306    }
    303307    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);
    304317#endif
    305318
     
    318331  thread_suspend(thread->machThread);
    319332
    320 #if defined(__i386__)
     333#if __i386__
    321334  i386_thread_state_t regs;
    322335  unsigned user_count = sizeof(regs)/sizeof(int);
    323336  thread_state_flavor_t flavor = i386_THREAD_STATE;
    324 #elif defined(__ppc__)
     337#elif __ppc__
    325338  ppc_thread_state_t  regs;
    326339  unsigned user_count = PPC_THREAD_STATE_COUNT;
    327340  thread_state_flavor_t flavor = PPC_THREAD_STATE;
    328 #elif defined(__ppc64__)
     341#elif __ppc64__
    329342  ppc_thread_state64_t  regs;
    330343  unsigned user_count = PPC_THREAD_STATE64_COUNT;
     
    340353 
    341354  // scan the stack
    342 #if defined(__i386__)
     355#if __i386__
    343356  markStackObjectsConservatively((void *)regs.esp, pthread_get_stackaddr_np(thread->posixThread));
    344357#elif defined(__ppc__) || defined(__ppc64__)
  • trunk/JavaScriptCore/kjs/config.h

    r10701 r10713  
    1 #if !WIN32
     1#if __APPLE__
    22
    33#define HAVE_FUNC_ISINF 1
     
    88#define TIME_WITH_SYS_TIME 1
    99
    10 #else
     10#elif WIN32
    1111
    1212#define HAVE_FLOAT_H 1
    1313#define HAVE_FUNC__FINITE 1
    1414#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
    1525
    1626#endif
  • trunk/JavaScriptCore/kjs/date_object.cpp

    r10675 r10713  
    2121 */
    2222
    23 #ifdef HAVE_CONFIG_H
    24 #include <config.h>
    25 #endif
     23#include "config.h"
    2624#ifndef HAVE_SYS_TIMEB_H
    2725#define HAVE_SYS_TIMEB_H 0
     
    4240#endif
    4341
     42#ifdef HAVE_ERRNO_H
     43#include <errno.h>
     44#endif
     45
    4446#ifdef HAVE_SYS_PARAM_H
    4547#  include <sys/param.h>
     
    7678const double msPerHour = msPerMinute * minutesPerHour;
    7779const double msPerDay = msPerHour * hoursPerDay;
    78 
    79 #if APPLE_CHANGES
     80static const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
     81static const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
     82   
     83#ifdef APPLE_CHANGES
    8084
    8185// Originally, we wrote our own implementation that uses Core Foundation because of a performance problem in Mac OS X 10.2.
     
    97101#define strftime(a, b, c, d) NotAllowedToCallThis()
    98102
    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    
    102103static struct tm *tmUsingCF(time_t clock, CFTimeZoneRef timeZone)
    103104{
     
    223224    }
    224225    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);
    260226}
    261227
     
    327293namespace KJS {
    328294
     295static 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
     304static 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
     313static 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
    329330static int day(double t)
    330331{
     
    389390static long timeZoneOffset(const struct tm *t)
    390391{
    391 #if defined BSD || defined(__linux__) || defined(__APPLE__)
     392#if !defined(WIN32)
    392393  return -(t->tm_gmtoff / 60);
    393394#else
     
    583584  ValueImp *result = NULL;
    584585  UString s;
    585 #if !APPLE_CHANGES
     586#if !defined(APPLE_CHANGES) || !APPLE_CHANGES
    586587  const int bufsize=100;
    587588  char timebuffer[bufsize];
     
    592593  ValueImp *v = thisObj->internalValue();
    593594  double milli = v->toNumber(exec);
    594  
    595595  if (isNaN(milli)) {
    596596    switch (id) {
     
    638638  double ms = milli - tv * 1000.0;
    639639
     640  // FIXME: not threadsafe (either of these options)
    640641  struct tm *t = utc ? gmtime(&tv) : localtime(&tv);
    641642  // we had an out of range year. use that one (plus/minus offset
     
    650651    t->tm_wday = weekDay(m);
    651652  }
    652   
     653 
    653654  switch (id) {
    654 #if APPLE_CHANGES
    655655  case ToString:
    656656    result = String(formatDate(*t) + " " + formatTime(*t));
     
    666666    result = String(formatDateUTCVariant(*t) + " " + formatTime(*t));
    667667    break;
     668#if APPLE_CHANGES
    668669  case ToLocaleString:
    669670    result = String(formatLocaleDate(exec, secs, true, true, args));
     
    676677    break;
    677678#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 & toUTCString
    692       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;
    697679  case ToLocaleString:
    698680    strftime(timebuffer, bufsize, "%c", t);
     
    746728    break;
    747729  case GetTimezoneOffset:
    748 #if defined BSD || defined(__APPLE__)
    749     result = Number(-t->tm_gmtoff / 60);
    750 #else
     730#if WIN32
    751731#  if defined(__BORLANDC__)
    752732#error please add daylight savings offset here!
     
    757737    result = Number(( timezone / 60 - ( daylight ? 60 : 0 )));
    758738#  endif
     739#else
     740    result = Number(-t->tm_gmtoff / 60);
    759741#endif
    760742    break;
     
    848830#else
    849831    struct timeval tv;
     832    // FIXME: not threadsafe
    850833    gettimeofday(&tv, 0L);
    851834    double utc = floor((double)tv.tv_sec * 1000.0 + (double)tv.tv_usec / 1000.0);
     
    893876
    894877// ECMA 15.9.2
    895 ValueImp *DateObjectImp::callAsFunction(ExecState */*exec*/, ObjectImp */*thisObj*/, const List &/*args*/)
     878ValueImp *DateObjectImp::callAsFunction(ExecState * /*exec*/, ObjectImp * /*thisObj*/, const List &/*args*/)
    896879{
    897880  time_t t = time(0L);
    898 #if APPLE_CHANGES
     881  // FIXME: not threadsafe
    899882  struct tm *tm = localtime(&t);
    900883  return String(formatDate(*tm) + " " + formatTime(*tm));
    901 #else
    902   UString s(ctime(&t));
    903 
    904   // return formatted string minus trailing \n
    905   return String(s.substr(0, s.size() - 1));
    906 #endif
    907884}
    908885
     
    1011988    if (utc) {
    1012989        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
    1019992        (void)localtime(&zero);
    1020993#  if defined(__BORLANDC__) || defined(__CYGWIN__)
     
    1024997#  endif
    1025998        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;
    10261004#endif
    10271005    } else {
     
    10291007        t->tm_isdst = -1;
    10301008    }
    1031    
     1009
     1010#ifdef __APPLE__
    10321011    // t->tm_year must hold the bulk of the data to avoid overflow when converting
    10331012    // to a CFGregorianDate. (CFGregorianDate.month is an SInt8; CFGregorianDate.year is an SInt32.)
    10341013    t->tm_year += t->tm_mon / 12;
    10351014    t->tm_mon %= 12;
    1036    
     1015#endif   
    10371016
    10381017    double yearOffset = 0.0;
  • trunk/JavaScriptCore/kjs/identifier.cpp

    r10701 r10713  
    2626// runs at init time.
    2727
    28 #if !WIN32 // can't get this to compile on Visual C++ yet
     28#if !defined(WIN32) // can't get this to compile on Visual C++ yet
    2929#define AVOID_STATIC_CONSTRUCTORS 1
    3030#endif
  • trunk/JavaScriptCore/kjs/internal.cpp

    r10701 r10713  
    7575#endif // APPLE_CHANGES
    7676
    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
    8678
    8779static pthread_once_t interpreterLockOnce = PTHREAD_ONCE_INIT;
     
    113105}
    114106
     107#else
     108
     109static inline void initializeInterpreterLock() { }
     110static inline void lockInterpreter() { }
     111static inline void unlockInterpreter() { }
     112
     113const int interpreterLockCount = 1;
     114
    115115#endif
    116116
    117117// ------------------------------ UndefinedImp ---------------------------------
    118118
    119 ValueImp *UndefinedImp::toPrimitive(ExecState */*exec*/, Type) const
     119ValueImp *UndefinedImp::toPrimitive(ExecState *, Type) const
    120120{
    121121  return const_cast<UndefinedImp *>(this);
    122122}
    123123
    124 bool UndefinedImp::toBoolean(ExecState */*exec*/) const
     124bool UndefinedImp::toBoolean(ExecState *) const
    125125{
    126126  return false;
    127127}
    128128
    129 double UndefinedImp::toNumber(ExecState */*exec*/) const
     129double UndefinedImp::toNumber(ExecState *) const
    130130{
    131131  return NaN;
    132132}
    133133
    134 UString UndefinedImp::toString(ExecState */*exec*/) const
     134UString UndefinedImp::toString(ExecState *) const
    135135{
    136136  return "undefined";
     
    144144// ------------------------------ NullImp --------------------------------------
    145145
    146 ValueImp *NullImp::toPrimitive(ExecState */*exec*/, Type) const
     146ValueImp *NullImp::toPrimitive(ExecState *, Type) const
    147147{
    148148  return const_cast<NullImp *>(this);
    149149}
    150150
    151 bool NullImp::toBoolean(ExecState */*exec*/) const
     151bool NullImp::toBoolean(ExecState *) const
    152152{
    153153  return false;
    154154}
    155155
    156 double NullImp::toNumber(ExecState */*exec*/) const
     156double NullImp::toNumber(ExecState *) const
    157157{
    158158  return 0.0;
    159159}
    160160
    161 UString NullImp::toString(ExecState */*exec*/) const
     161UString NullImp::toString(ExecState *) const
    162162{
    163163  return "null";
     
    171171// ------------------------------ BooleanImp -----------------------------------
    172172
    173 ValueImp *BooleanImp::toPrimitive(ExecState */*exec*/, Type) const
     173ValueImp *BooleanImp::toPrimitive(ExecState *, Type) const
    174174{
    175175  return const_cast<BooleanImp *>(this);
    176176}
    177177
    178 bool BooleanImp::toBoolean(ExecState */*exec*/) const
     178bool BooleanImp::toBoolean(ExecState *) const
    179179{
    180180  return val;
    181181}
    182182
    183 double BooleanImp::toNumber(ExecState */*exec*/) const
     183double BooleanImp::toNumber(ExecState *) const
    184184{
    185185  return val ? 1.0 : 0.0;
    186186}
    187187
    188 UString BooleanImp::toString(ExecState */*exec*/) const
     188UString BooleanImp::toString(ExecState *) const
    189189{
    190190  return val ? "true" : "false";
     
    200200// ------------------------------ StringImp ------------------------------------
    201201
    202 ValueImp *StringImp::toPrimitive(ExecState */*exec*/, Type) const
     202ValueImp *StringImp::toPrimitive(ExecState *, Type) const
    203203{
    204204  return const_cast<StringImp *>(this);
    205205}
    206206
    207 bool StringImp::toBoolean(ExecState */*exec*/) const
     207bool StringImp::toBoolean(ExecState *) const
    208208{
    209209  return (val.size() > 0);
    210210}
    211211
    212 double StringImp::toNumber(ExecState */*exec*/) const
     212double StringImp::toNumber(ExecState *) const
    213213{
    214214  return val.toDouble();
    215215}
    216216
    217 UString StringImp::toString(ExecState */*exec*/) const
     217UString StringImp::toString(ExecState *) const
    218218{
    219219  return val;
  • trunk/JavaScriptCore/kjs/internal.h

    r10634 r10713  
    3535#include <kxmlcore/SharedPtr.h>
    3636
    37 #if !WIN32
     37#if __APPLE__
    3838#define KJS_MULTIPLE_THREADS 1
    3939#endif
  • trunk/JavaScriptCore/kjs/protected_values.cpp

    r10701 r10713  
    2828#include "internal.h"
    2929#include <stdint.h>
     30#include <stdlib.h>
    3031#include "value.h"
    3132
Note: See TracChangeset for help on using the changeset viewer.