Using doubles where ints couldn't hold large values for FD.fstat()
authorMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 7 Jul 2005 05:12:51 +0000 (05:12 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 7 Jul 2005 05:12:51 +0000 (05:12 +0000)
tests/js-test/src/classes/js_fd.c

index eab9813..e04bb95 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: js_fd.c,v 1.32 2005/07/07 00:11:17 mmondor Exp $ */
+/* $Id: js_fd.c,v 1.33 2005/07/07 05:12:51 mmondor Exp $ */
 
 /*
  * Copyright (c) 2005, Matthew Mondor
@@ -1969,6 +1969,16 @@ fd_m_fstat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
        }                                                               \
 } while (/* CONSTCOND */0)
 
+#define DEFINE_DOUBLE_PROP(n, d) do {                                  \
+       if (!JS_NewDoubleValue(cx, (jsdouble)(d), &val))                \
+               goto err;                                               \
+       if (!JS_DefineProperty(cx, array, (n), val, NULL, NULL,         \
+           JSPROP_ENUMERATE)) {                                        \
+               QUEUE_EXCEPTION("Internal error!");                     \
+               goto err;                                               \
+       }                                                               \
+} while (/* CONSTCOND */0)
+
        DEFINE_INT_PROP("st_dev", st.st_dev);
        DEFINE_INT_PROP("st_ino", st.st_ino);
        DEFINE_INT_PROP("st_mode", st.st_mode);
@@ -1976,36 +1986,11 @@ fd_m_fstat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
        DEFINE_INT_PROP("st_uid", st.st_uid);
        DEFINE_INT_PROP("st_gid", st.st_gid);
        DEFINE_INT_PROP("st_rdev", st.st_rdev);
-       /*
-        * XXX
-        * The three times in struct stat are struct timespec (seconds since
-        * epoch, and nanoseconds in current second.  I should probably
-        * provide exactly the same, making sure that it be in GMT, possibly.
-        * Or, I could leave the application convert it to GMT.  However, I
-        * then need a new object for storage of the two values, unless I
-        * converted them into a string with some field separator character.
-        * For now, I'll just care about the seconds and return those, and
-        * will return them in GMT.  This is currently used by httpd.js to
-        * verify if a file was modified before sending it again, or before
-        * needing to read and parse scripts again.
-        */
-       /*
-        * XXX Seems that I am exceeding the JavaScript maximum integer size!
-        * Will I need to create my own arithmetic types!?
-        * This seems to be related to the way jsval are stored.
-        * jsval probably should be a structure or union, at the expense
-        * of some performance loss perhaps.
-        * I now return time in minutes instead!
-        */
-       DEFINE_INT_PROP("st_atime", st.st_atime / 60);
-       DEFINE_INT_PROP("st_mtime", st.st_mtime / 60);
-       DEFINE_INT_PROP("st_ctime", st.st_ctime / 60);
-       /*
-        * XXX Note: there are off_t and int64_t fields which won't properly
-        * be converted.
-        */
-       DEFINE_INT_PROP("st_size", st.st_size);
-       DEFINE_INT_PROP("st_blocks", st.st_blocks);
+       DEFINE_DOUBLE_PROP("st_atime", st.st_atime);
+       DEFINE_DOUBLE_PROP("st_mtime", st.st_mtime);
+       DEFINE_DOUBLE_PROP("st_ctime", st.st_ctime);
+       DEFINE_DOUBLE_PROP("st_size", st.st_size);
+       DEFINE_DOUBLE_PROP("st_blocks", st.st_blocks);
        DEFINE_INT_PROP("st_blksize", st.st_blksize);
        DEFINE_INT_PROP("st_flags", st.st_flags);
        DEFINE_INT_PROP("st_gen", st.st_gen);