Bug 793076 (part 8) - Make GetCachedLocalTime() infallible. r=jwalden.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 07 Oct 2012 18:03:20 -0700
changeset 109601 396196c97862cea92e9ff5ad53a70d178fedadc0
parent 109600 99229a1bf7eab4a9da02a4b2292d8cad17cfaea0
child 109602 2ec21afa445bfde8e432a15fcfab11efa2d4a768
push id23636
push usergsharp@mozilla.com
push dateMon, 08 Oct 2012 08:08:19 +0000
treeherdermozilla-central@24cf40690042 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs793076
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 793076 (part 8) - Make GetCachedLocalTime() infallible. r=jwalden.
js/src/jsdate.cpp
--- a/js/src/jsdate.cpp
+++ b/js/src/jsdate.cpp
@@ -1415,25 +1415,22 @@ FillLocalTimeSlots(DSTOffsetCache *dstOf
 
     int minutes = (yearSeconds / 60) % 60;
     obj->setSlot(JSObject::JSSLOT_DATE_LOCAL_MINUTES, Int32Value(minutes));
 
     int hours = (yearSeconds / (60 * 60)) % 24;
     obj->setSlot(JSObject::JSSLOT_DATE_LOCAL_HOURS, Int32Value(hours));
 }
 
-inline bool
-GetCachedLocalTime(DSTOffsetCache *dstOffsetCache, RawObject obj, double *time)
+inline double
+GetCachedLocalTime(DSTOffsetCache *dstOffsetCache, RawObject obj)
 {
-    if (!obj)
-        return false;
-
+    JS_ASSERT(obj);
     FillLocalTimeSlots(dstOffsetCache, obj);
-    *time = obj->getSlot(JSObject::JSSLOT_DATE_LOCAL_TIME).toDouble();
-    return true;
+    return obj->getSlot(JSObject::JSSLOT_DATE_LOCAL_TIME).toDouble();
 }
 
 JS_ALWAYS_INLINE bool
 IsDate(const Value &v)
 {
     return v.isObject() && v.toObject().hasClass(&DateClass);
 }
 
@@ -1758,20 +1755,17 @@ date_getUTCMilliseconds(JSContext *cx, u
 
 JS_ALWAYS_INLINE bool
 date_getTimezoneOffset_impl(JSContext *cx, CallArgs args)
 {
     JS_ASSERT(IsDate(args.thisv()));
 
     RootedObject thisObj(cx, &args.thisv().toObject());
     double utctime = thisObj->getDateUTCTime().toNumber();
-
-    double localtime;
-    if (!GetCachedLocalTime(&cx->dstOffsetCache, thisObj, &localtime))
-        return false;
+    double localtime = GetCachedLocalTime(&cx->dstOffsetCache, thisObj);
 
     /*
      * Return the time zone offset in minutes for the current locale that is
      * appropriate for this time. This value would be a constant except for
      * daylight savings time.
      */
     double result = (utctime - localtime) / msPerMinute;
     args.rval().setNumber(result);
@@ -3222,64 +3216,64 @@ JS_FRIEND_API(JSBool)
 js_DateIsValid(RawObject obj)
 {
     return obj->isDate() && !MOZ_DOUBLE_IS_NaN(obj->getDateUTCTime().toNumber());
 }
 
 JS_FRIEND_API(int)
 js_DateGetYear(JSContext *cx, RawObject obj)
 {
-    double localtime;
-
     /* Preserve legacy API behavior of returning 0 for invalid dates. */
-    if (!GetCachedLocalTime(&cx->dstOffsetCache, obj, &localtime) || MOZ_DOUBLE_IS_NaN(localtime))
+    JS_ASSERT(obj);
+    double localtime = GetCachedLocalTime(&cx->dstOffsetCache, obj);
+    if (MOZ_DOUBLE_IS_NaN(localtime))
         return 0;
 
     return (int) YearFromTime(localtime);
 }
 
 JS_FRIEND_API(int)
 js_DateGetMonth(JSContext *cx, RawObject obj)
 {
-    double localtime;
-
-    if (!GetCachedLocalTime(&cx->dstOffsetCache, obj, &localtime) || MOZ_DOUBLE_IS_NaN(localtime))
+    JS_ASSERT(obj);
+    double localtime = GetCachedLocalTime(&cx->dstOffsetCache, obj);
+    if (MOZ_DOUBLE_IS_NaN(localtime))
         return 0;
 
     return (int) MonthFromTime(localtime);
 }
 
 JS_FRIEND_API(int)
 js_DateGetDate(JSContext *cx, RawObject obj)
 {
-    double localtime;
-
-    if (!GetCachedLocalTime(&cx->dstOffsetCache, obj, &localtime) || MOZ_DOUBLE_IS_NaN(localtime))
+    JS_ASSERT(obj);
+    double localtime = GetCachedLocalTime(&cx->dstOffsetCache, obj);
+    if (MOZ_DOUBLE_IS_NaN(localtime))
         return 0;
 
     return (int) DateFromTime(localtime);
 }
 
 JS_FRIEND_API(int)
 js_DateGetHours(JSContext *cx, RawObject obj)
 {
-    double localtime;
-
-    if (!GetCachedLocalTime(&cx->dstOffsetCache, obj, &localtime) || MOZ_DOUBLE_IS_NaN(localtime))
+    JS_ASSERT(obj);
+    double localtime = GetCachedLocalTime(&cx->dstOffsetCache, obj);
+    if (MOZ_DOUBLE_IS_NaN(localtime))
         return 0;
 
     return (int) HourFromTime(localtime);
 }
 
 JS_FRIEND_API(int)
 js_DateGetMinutes(JSContext *cx, RawObject obj)
 {
-    double localtime;
-
-    if (!GetCachedLocalTime(&cx->dstOffsetCache, obj, &localtime) || MOZ_DOUBLE_IS_NaN(localtime))
+    JS_ASSERT(obj);
+    double localtime = GetCachedLocalTime(&cx->dstOffsetCache, obj);
+    if (MOZ_DOUBLE_IS_NaN(localtime))
         return 0;
 
     return (int) MinFromTime(localtime);
 }
 
 JS_FRIEND_API(int)
 js_DateGetSeconds(RawObject obj)
 {