updated Makefile.common
[org.ibex.core.git] / src / org / ibex / js / JSDate.java
index 694122c..144e868 100644 (file)
@@ -55,19 +55,19 @@ public class JSDate extends JS {
         }
     }
 
-    public String toString() { return date_format(date, FORMATSPEC_FULL); }
+    String coerceToString() { return date_format(date, FORMATSPEC_FULL); }
 
-    public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+    public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
         switch(nargs) {
             case 0: {
-                //#switch(method)
-                case "toString": return date_format(date, FORMATSPEC_FULL);
-                case "toTimeString": return date_format(date, FORMATSPEC_TIME);
-                case "toDateString": return date_format(date, FORMATSPEC_DATE);
-                case "toLocaleString": return toLocaleString(date);
-                case "toLocaleTimeString": return toLocaleTimeString(date);
-                case "toLocaleDateString": return toLocaleDateString(date);
-                case "toUTCString": return toUTCString(date);
+                //#jswitch(method)
+                case "toString": return JS.S(date_format(date, FORMATSPEC_FULL));
+                case "toTimeString": return JS.S(date_format(date, FORMATSPEC_TIME));
+                case "toDateString": return JS.S(date_format(date, FORMATSPEC_DATE));
+                case "toLocaleString": return JS.S(toLocaleString(date));
+                case "toLocaleTimeString": return JS.S(toLocaleTimeString(date));
+                case "toLocaleDateString": return JS.S(toLocaleDateString(date));
+                case "toUTCString": return JS.S(toUTCString(date));
                 case "valueOf": return N(this.date);
                 case "getTime": return N(this.date);
                 case "getYear": return N(getYear(date));
@@ -92,16 +92,16 @@ public class JSDate extends JS {
                 return super.callMethod(method, a0, a1, a2, rest, nargs);
             }
             case 1: {
-                //#switch(method)
+                //#jswitch(method)
                 case "setTime": return N(this.setTime(toDouble(a0)));
                 case "setYear": return N(this.setYear(toDouble(a0)));
                 //#end
                 // fall through
             }
             default: {
-                Object[] args = new Object[nargs];
+                JS[] args = new JS[nargs];
                 for(int i=0; i<nargs; i++) args[i] = i==0 ? a0 : i==1 ? a1 : i==2 ? a2 : rest[i-3];
-                //#switch(method)
+                //#jswitch(method)
                 case "setMilliseconds": return N(this.makeTime(args, 1, true));
                 case "setUTCMilliseconds": return N(this.makeTime(args, 1, false));
                 case "setSeconds": return N(this.makeTime(args, 2, true));
@@ -122,8 +122,8 @@ public class JSDate extends JS {
         return super.callMethod(method, a0, a1, a2, rest, nargs);
     }
 
-    public Object get(Object key) throws JSExn {
-        //#switch(key)
+    public JS get(JS key) throws JSExn {
+        //#jswitch(key)
         case "toString": return METHOD;
         case "toTimeString": return METHOD;
         case "toDateString": return METHOD;
@@ -528,7 +528,7 @@ public class JSDate extends JS {
 
 
     private static final int MAXARGS = 7;
-    private static double jsStaticJSFunction_UTC(Object[] args) {
+    private static double jsStaticJSFunction_UTC(JS[] args) throws JSExn {
         double array[] = new double[MAXARGS];
         int loop;
         double d;
@@ -888,11 +888,11 @@ public class JSDate extends JS {
         return result.toString();
     }
 
-    private static double _toNumber(Object o) { return JS.toDouble(o); }
-    private static double _toNumber(Object[] o, int index) { return JS.toDouble(o[index]); }
+    private static double _toNumber(JS o) throws JSExn { return JS.toDouble(o); }
+    private static double _toNumber(JS[] o, int index) throws JSExn { return JS.toDouble(o[index]); }
     private static double toDouble(double d) { return d; }
 
-    public JSDate(Object a0, Object a1, Object a2, Object[] rest, int nargs) {
+    public JSDate(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
 
         JSDate obj = this;
         switch (nargs) {
@@ -902,16 +902,10 @@ public class JSDate extends JS {
             }
             case 1: {
                 double date;
-                if (a0 instanceof JS)
-                    a0 = ((JS) a0).toString();
-                if (!(a0 instanceof String)) {
-                    // if it's not a string, use it as a millisecond date
+                if(isString(a0))
+                    date = date_parseString(JS.toString(a0));
+                else
                     date = _toNumber(a0);
-                } else {
-                    // it's a string; parse it.
-                    String str = (String) a0;
-                    date = date_parseString(str);
-                }
                 obj.date = TimeClip(date);
                 return;
             }
@@ -1055,7 +1049,7 @@ public class JSDate extends JS {
         return this.date;
     }
 
-    private double makeTime(Object[] args, int maxargs, boolean local) {
+    private double makeTime(JS[] args, int maxargs, boolean local) throws JSExn {
         int i;
         double conv[] = new double[4];
         double hour, min, sec, msec;
@@ -1079,7 +1073,7 @@ public class JSDate extends JS {
          * d.setMilliseconds()" returns NaN.  Blech.
          */
         if (args.length == 0)
-            args = new Object[] { null };
+            args = new JS[] { null };
 
         for (i = 0; i < args.length && i < maxargs; i++) {
             conv[i] = _toNumber(args[i]);
@@ -1131,15 +1125,15 @@ public class JSDate extends JS {
         return date;
     }
 
-    private double setHours(Object[] args) {
+    private double setHours(JS[] args) throws JSExn {
         return makeTime(args, 4, true);
     }
 
-    private double setUTCHours(Object[] args) {
+    private double setUTCHours(JS[] args) throws JSExn {
         return makeTime(args, 4, false);
     }
 
-    private double makeDate(Object[] args, int maxargs, boolean local) {
+    private double makeDate(JS[] args, int maxargs, boolean local) throws JSExn {
         int i;
         double conv[] = new double[3];
         double year, month, day;
@@ -1150,7 +1144,7 @@ public class JSDate extends JS {
 
         /* See arg padding comment in makeTime.*/
         if (args.length == 0)
-            args = new Object[] { null };
+            args = new JS[] { null };
 
         for (i = 0; i < args.length && i < maxargs; i++) {
             conv[i] = _toNumber(args[i]);