/[jscoverage]/trunk/js/jsdate.cpp
ViewVC logotype

Diff of /trunk/js/jsdate.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 459 by siliconforks, Tue Dec 9 03:37:47 2008 UTC revision 460 by siliconforks, Sat Sep 26 23:15:22 2009 UTC
# Line 416  Line 416 
416      return result;      return result;
417  }  }
418    
419    static jsdouble
420  #define AdjustTime(t)   fmod(LocalTZA + DaylightSavingTA(t), msPerDay)  AdjustTime(jsdouble date)
421    {
422        jsdouble t = DaylightSavingTA(date) + LocalTZA;
423        t = (LocalTZA >= 0) ? fmod(t, msPerDay) : -fmod(msPerDay - t, msPerDay);
424        return t;
425    }
426    
427  #define LocalTime(t)    ((t) + AdjustTime(t))  #define LocalTime(t)    ((t) + AdjustTime(t))
428    
# Line 913  Line 918 
918      return js_NewNumberInRootedValue(cx, result, vp);      return js_NewNumberInRootedValue(cx, result, vp);
919  }  }
920    
921    static inline jsdouble
922    NowAsMillis()
923    {
924        return (jsdouble) (PRMJ_Now() / PRMJ_USEC_PER_MSEC);
925    }
926    
927  static JSBool  static JSBool
928  date_now(JSContext *cx, uintN argc, jsval *vp)  date_now(JSContext *cx, uintN argc, jsval *vp)
929  {  {
930      return js_NewDoubleInRootedValue(cx, PRMJ_Now() / PRMJ_USEC_PER_MSEC, vp);      return js_NewDoubleInRootedValue(cx, NowAsMillis(), vp);
931  }  }
932    
933  #ifdef JS_TRACER  #ifdef JS_TRACER
934  static jsdouble FASTCALL  static jsdouble FASTCALL
935  date_now_tn(JSContext*)  date_now_tn(JSContext*)
936  {  {
937      return PRMJ_Now() / PRMJ_USEC_PER_MSEC;      return NowAsMillis();
938  }  }
939  #endif  #endif
940    
# Line 2012  Line 2023 
2023      return date_toString(cx, argc, vp);      return date_toString(cx, argc, vp);
2024  }  }
2025    
 JS_DEFINE_CALLINFO_2(extern, OBJECT, js_FastNewDate, CONTEXT, OBJECT, 0, 0)  
   
2026  // Don't really need an argument here, but we don't support arg-less builtins  // Don't really need an argument here, but we don't support arg-less builtins
2027  JS_DEFINE_TRCINFO_1(date_now,  JS_DEFINE_TRCINFO_1(date_now,
2028      (1, (static, DOUBLE, date_now_tn, CONTEXT, 0, 0)))      (1, (static, DOUBLE, date_now_tn, CONTEXT, 0, 0)))
# Line 2026  Line 2035 
2035  };  };
2036    
2037  JS_DEFINE_TRCINFO_1(date_valueOf,  JS_DEFINE_TRCINFO_1(date_valueOf,
2038      (3, (static, JSVAL_FAIL, date_valueOf_tn, CONTEXT, THIS, STRING, 0, 0)))      (3, (static, JSVAL_RETRY, date_valueOf_tn, CONTEXT, THIS, STRING, 0, 0)))
2039    
2040  static JSFunctionSpec date_methods[] = {  static JSFunctionSpec date_methods[] = {
2041      JS_FN("getTime",             date_getTime,            0,0),      JS_FN("getTime",             date_getTime,            0,0),
# Line 2104  Line 2113 
2113      jsdouble d;      jsdouble d;
2114    
2115      /* Date called as function. */      /* Date called as function. */
2116      if (!(cx->fp->flags & JSFRAME_CONSTRUCTING)) {      if (!JS_IsConstructing(cx))
2117          return date_format(cx, PRMJ_Now() / PRMJ_USEC_PER_MSEC,          return date_format(cx, NowAsMillis(), FORMATSPEC_FULL, rval);
                            FORMATSPEC_FULL, rval);  
     }  
2118    
2119      /* Date called as constructor. */      /* Date called as constructor. */
2120      if (argc == 0) {      if (argc == 0) {
2121          date = date_constructor(cx, obj);          date = date_constructor(cx, obj);
2122          if (!date)          if (!date)
2123              return JS_FALSE;              return JS_FALSE;
2124          *date = PRMJ_Now() / PRMJ_USEC_PER_MSEC;          *date = NowAsMillis();
2125      } else if (argc == 1) {      } else if (argc == 1) {
2126          if (!JSVAL_IS_STRING(argv[0])) {          if (!JSVAL_IS_STRING(argv[0])) {
2127              /* the argument is a millisecond number */              /* the argument is a millisecond number */
# Line 2160  Line 2167 
2167      return JS_TRUE;      return JS_TRUE;
2168  }  }
2169    
 JS_STATIC_ASSERT(JSSLOT_PRIVATE == JSSLOT_UTC_TIME);  
 JS_STATIC_ASSERT(JSSLOT_UTC_TIME + 1 == JSSLOT_LOCAL_TIME);  
   
 #ifdef JS_TRACER  
 JSObject* FASTCALL  
 js_FastNewDate(JSContext* cx, JSObject* proto)  
 {  
     JS_ASSERT(JS_ON_TRACE(cx));  
     JSObject* obj = (JSObject*) js_NewGCThing(cx, GCX_OBJECT, sizeof(JSObject));  
     if (!obj)  
         return NULL;  
   
     JSClass* clasp = &js_DateClass;  
     obj->classword = jsuword(clasp);  
   
     obj->fslots[JSSLOT_PROTO] = OBJECT_TO_JSVAL(proto);  
     obj->fslots[JSSLOT_PARENT] = proto->fslots[JSSLOT_PARENT];  
   
     jsdouble* date = js_NewWeaklyRootedDouble(cx, 0.0);  
     if (!date)  
         return NULL;  
     *date = date_now_tn(cx);  
     obj->fslots[JSSLOT_UTC_TIME] = DOUBLE_TO_JSVAL(date);  
     obj->fslots[JSSLOT_LOCAL_TIME] = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);  
     for (unsigned i = JSSLOT_LOCAL_TIME + 1; i != JS_INITIAL_NSLOTS; ++i)  
         obj->fslots[i] = JSVAL_VOID;  
       
     JS_ASSERT(!clasp->getObjectOps);  
     JS_ASSERT(proto->map->ops == &js_ObjectOps);  
     obj->map = js_HoldObjectMap(cx, proto->map);  
     obj->dslots = NULL;  
     return obj;      
 }  
 #endif  
   
2170  JSObject *  JSObject *
2171  js_InitDateClass(JSContext *cx, JSObject *obj)  js_InitDateClass(JSContext *cx, JSObject *obj)
2172  {  {
# Line 2203  Line 2175 
2175    
2176      /* set static LocalTZA */      /* set static LocalTZA */
2177      LocalTZA = -(PRMJ_LocalGMTDifference() * msPerSecond);      LocalTZA = -(PRMJ_LocalGMTDifference() * msPerSecond);
2178      proto = JS_InitClass(cx, obj, NULL, &js_DateClass, js_Date, MAXARGS,      proto = js_InitClass(cx, obj, NULL, &js_DateClass, js_Date, MAXARGS,
2179                           NULL, date_methods, NULL, date_static_methods);                           NULL, date_methods, NULL, date_static_methods);
2180      if (!proto)      if (!proto)
2181          return NULL;          return NULL;
# Line 2473  Line 2445 
2445          return 0;          return 0;
2446      return utctime;      return utctime;
2447  }  }
2448    
2449    #ifdef JS_THREADSAFE
2450    #include "prinrval.h"
2451    
2452    uint32
2453    js_IntervalNow()
2454    {
2455        return uint32(PR_IntervalToMilliseconds(PR_IntervalNow()));
2456    }
2457    
2458    #else /* !JS_THREADSAFE */
2459    
2460    uint32
2461    js_IntervalNow()
2462    {
2463        return uint32(PRMJ_Now() / PRMJ_USEC_PER_MSEC);
2464    }
2465    #endif

Legend:
Removed from v.459  
changed lines
  Added in v.460

  ViewVC Help
Powered by ViewVC 1.1.24