src/jdk/nashorn/internal/objects/NativeDate.java

Print this page

        

@@ -517,11 +517,11 @@
      * @return time zone offset or NaN if N/A
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
     public static Object getTimezoneOffset(final Object self) {
         final NativeDate nd = getNativeDate(self);
-        if (nd != null) {
+        if (nd != null && nd.isValidDate()) {
             final long msec = (long) nd.getTime();
             return - nd.getTimeZone().getOffset(msec) / msPerMinute;
         }
         return Double.NaN;
     }

@@ -533,12 +533,12 @@
      * @param time time
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
     public static Object setTime(final Object self, final Object time) {
-        final double     num = timeClip(JSType.toNumber(time));
         final NativeDate nd  = getNativeDate(self);
+        final double     num = timeClip(JSType.toNumber(time));
         nd.setTime(num);
         return num;
     }
 
     /**

@@ -549,13 +549,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
     public static Object setMilliseconds(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, MILLISECOND, args, true);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.29 Date.prototype.setUTCMilliseconds (ms)

@@ -565,13 +563,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
     public static Object setUTCMilliseconds(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, MILLISECOND, args, false);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.30 Date.prototype.setSeconds (sec [, ms ] )

@@ -581,13 +577,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
     public static Object setSeconds(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, SECOND, args, true);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.31 Date.prototype.setUTCSeconds (sec [, ms ] )

@@ -597,13 +591,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
     public static Object setUTCSeconds(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, SECOND, args, false);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.32 Date.prototype.setMinutes (min [, sec [, ms ] ] )

@@ -613,13 +605,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
     public static Object setMinutes(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, MINUTE, args, true);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.33 Date.prototype.setUTCMinutes (min [, sec [, ms ] ] )

@@ -629,13 +619,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
     public static Object setUTCMinutes(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, MINUTE, args, false);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.34 Date.prototype.setHours (hour [, min [, sec [, ms ] ] ] )

@@ -645,13 +633,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4)
     public static Object setHours(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, HOUR, args, true);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.35 Date.prototype.setUTCHours (hour [, min [, sec [, ms ] ] ] )

@@ -661,13 +647,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4)
     public static Object setUTCHours(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, HOUR, args, false);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.36 Date.prototype.setDate (date)

@@ -677,13 +661,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
     public static Object setDate(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, DAY, args, true);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.37 Date.prototype.setUTCDate (date)

@@ -693,13 +675,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
     public static Object setUTCDate(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, DAY, args, false);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.38 Date.prototype.setMonth (month [, date ] )

@@ -709,13 +689,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
     public static Object setMonth(final Object self, final Object... args) {
         final NativeDate nd = getNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, MONTH, args, true);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.39 Date.prototype.setUTCMonth (month [, date ] )

@@ -725,13 +703,11 @@
      * @return time
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
     public static Object setUTCMonth(final Object self, final Object... args) {
         final NativeDate nd = ensureNativeDate(self);
-        if (nd.isValidDate()) {
             setFields(nd, MONTH, args, false);
-        }
         return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.40 Date.prototype.setFullYear (year [, month [, date ] ] )

@@ -745,11 +721,15 @@
         final NativeDate nd   = ensureNativeDate(self);
         if (nd.isValidDate()) {
             setFields(nd, YEAR, args, true);
         } else {
             final double[] d = convertArgs(args, 0, YEAR, YEAR, 3);
+            if (d != null) {
             nd.setTime(timeClip(utc(makeDate(makeDay(d[0], d[1], d[2]), 0), nd.getTimeZone())));
+            } else {
+                nd.setTime(NaN);
+            }
         }
         return nd.getTime();
     }
 
     /**

@@ -780,25 +760,25 @@
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
     public static Object setYear(final Object self, final Object year) {
         final NativeDate nd = getNativeDate(self);
         if (isNaN(nd.getTime())) {
-            return null;
+            nd.setTime(utc(0, nd.getTimeZone()));
         }
 
         final double yearNum = JSType.toNumber(year);
         if (isNaN(yearNum)) {
             nd.setTime(NaN);
-            return nd;
+            return nd.getTime();
         }
         int yearInt = JSType.toInteger(yearNum);
         if (0 <= yearInt && yearInt <= 99) {
             yearInt += 1900;
         }
         setFields(nd, YEAR, new Object[] {yearInt}, true);
 
-        return nd;
+        return nd.getTime();
     }
 
     /**
      * ECMA 15.9.5.42 Date.prototype.toUTCString ( )
      *

@@ -1296,10 +1276,14 @@
             length = 4;
         }
         final double time = local ? nd.getLocalTime() : nd.getTime();
         final double d[] = convertArgs(args, time, fieldId, start, length);
 
+        if (! nd.isValidDate()) {
+            return;
+        }
+
         double newTime;
         if (d == null) {
             newTime = NaN;
         } else {
             if (start == YEAR) {