In the GHCJS section, how does getCurrentTime work? In the time library itself, this is implemented using FFI , invoking functions provided by the operating system. However, in time there are no lines starting with:
foreign import javascript ...
I checked the shims repository that GHCJS uses to fix libraries. It fixes the time zone get function , but does not mention getCurrentTime . The only thing I found that it was remotely closed was in ghcjs-boot , where old-time fixed:
#ifdef ghcjs_HOST_OS type CTimeVal = () type CTimeZone = () ... foreign import ccall unsafe "HsTime.h __hscore_gettimeofday" gettimeofday :: Ptr CTimeVal -> Ptr CTimeZone -> IO CInt ...
But there are two problems with this. Firstly, this is not a valid library ( old-time instead of time ). Another is that it still uses C FFI. I do not understand how using C FFI can work when you compile GHCJS.
So where getCurrentTime get fit for GHCJS?
In response to a comment about the grepping ghcjs source, if I search for getTime (which I believe will be the javascript function used) in the GHCJS source, I get basically nothing. However, grepping the all.js file created by GHCJS for a project that uses getCurrentTime , I get the following:
ag '\bgetTime\b' all.js 20948: h$log((("elapsed time: " + (h$RTS_597.getTime() - h$RTS_595.getTime())) + "ms")); 22863: var atime = goog.math.Long.fromNumber(fs.atime.getTime()); 22864: var mtime = goog.math.Long.fromNumber(fs.mtime.getTime()); 22865: var ctime = goog.math.Long.fromNumber(fs.ctime.getTime());
The last three are from some kind of file system.
I found this in generated javascript:
function h$gettimeofday(tv_v,tv_o,tz_v,tz_o) { var now = Date.now(); tv_v.dv.setInt32(tv_o, (now / 1000)|0, true); tv_v.dv.setInt32(tv_o + 4, ((now % 1000) * 1000)|0, true); if(tv_v.len >= tv_o + 12) { tv_v.dv.setInt32(tv_o + 8, ((now % 1000) * 1000)|0, true); } return 0; }
But the question of how this is connected remains.