@@ -391,25 +391,9 @@ LibraryManager.library = {
391391 // time.h
392392 // ==========================================================================
393393
394- clock__sig : 'i ',
395- clock : function ( ) {
396- if ( _clock . start === undefined ) _clock . start = Date . now ( ) ;
397- return ( ( Date . now ( ) - _clock . start ) * ( { { { cDefine ( 'CLOCKS_PER_SEC' ) } } } / 1000 ) ) | 0 ;
398- } ,
399-
400- time__sig : 'ii ',
401- time : function ( ptr ) {
402- { { { from64 ( 'ptr' ) } } } ;
403- var ret = ( Date . now ( ) / 1000 ) | 0 ;
404- if ( ptr ) {
405- { { { makeSetValue ( 'ptr' , 0 , 'ret' , 'i32' ) } } } ;
406- }
407- return ret ;
408- } ,
409-
410- difftime__sig : 'dii ',
411- difftime : function ( time1 , time0 ) {
412- return time1 - time0 ;
394+ _emscripten_date_now__sig : 'j ',
395+ _emscripten_date_now : function ( ) {
396+ return Date . now ( ) ;
413397 } ,
414398
415399 _mktime_js__sig : 'ii ',
@@ -549,11 +533,6 @@ LibraryManager.library = {
549533 return ret ;
550534 } ,
551535
552- dysize : function ( year ) {
553- var leap = ( ( year % 4 == 0 ) && ( ( year % 100 != 0 ) || ( year % 400 == 0 ) ) ) ;
554- return leap ? 366 : 365 ;
555- } ,
556-
557536 // TODO: Initialize these to defaults on startup from system settings.
558537 // Note: glibc has one fewer underscore for all of these. Also used in other related functions (timegm)
559538 _tzset_js__deps : [ 'tzset_impl' ] ,
@@ -1246,66 +1225,6 @@ LibraryManager.library = {
12461225 return _strptime ( buf , format , tm ) ; // no locale support yet
12471226 } ,
12481227
1249- timespec_get__deps : [ 'clock_gettime' , '$setErrNo' ] ,
1250- timespec_get : function ( ts , base ) {
1251- //int timespec_get(struct timespec *ts, int base);
1252- if ( base !== { { { cDefine ( 'TIME_UTC' ) } } } ) {
1253- // There is no other implemented value than TIME_UTC; all other values are considered erroneous.
1254- setErrNo ( { { { cDefine ( 'EINVAL' ) } } } ) ;
1255- return 0 ;
1256- }
1257- var ret = _clock_gettime ( { { { cDefine ( 'CLOCK_REALTIME' ) } } } , ts ) ;
1258- return ret < 0 ? 0 : base ;
1259- } ,
1260-
1261- // ==========================================================================
1262- // sys/time.h
1263- // ==========================================================================
1264-
1265- clock_gettime__sig : 'iii' ,
1266- clock_gettime__deps : [ 'emscripten_get_now' , 'emscripten_get_now_is_monotonic' , '$setErrNo' ] ,
1267- clock_gettime : function ( clk_id , tp ) {
1268- // int clock_gettime(clockid_t clk_id, struct timespec *tp);
1269- var now ;
1270- if ( clk_id === { { { cDefine ( 'CLOCK_REALTIME' ) } } } ) {
1271- now = Date . now ( ) ;
1272- } else if ( ( clk_id === { { { cDefine ( 'CLOCK_MONOTONIC' ) } } } || clk_id === { { { cDefine ( 'CLOCK_MONOTONIC_RAW' ) } } } ) && _emscripten_get_now_is_monotonic ) {
1273- now = _emscripten_get_now ( ) ;
1274- } else {
1275- setErrNo ( { { { cDefine ( 'EINVAL' ) } } } ) ;
1276- return - 1 ;
1277- }
1278- { { { makeSetValue ( 'tp' , C_STRUCTS . timespec . tv_sec , '(now/1000)|0' , 'i32' ) } } } ; // seconds
1279- { { { makeSetValue ( 'tp' , C_STRUCTS . timespec . tv_nsec , '((now % 1000)*1000*1000)|0' , 'i32' ) } } } ; // nanoseconds
1280- return 0 ;
1281- } ,
1282- __clock_gettime__sig : 'iii ',
1283- __clock_gettime : 'clock_gettime ', // musl internal alias
1284- clock_getres__deps : [ 'emscripten_get_now_res' , 'emscripten_get_now_is_monotonic' , '$setErrNo' ] ,
1285- clock_getres : function ( clk_id , res ) {
1286- // int clock_getres(clockid_t clk_id, struct timespec *res);
1287- var nsec ;
1288- if ( clk_id === { { { cDefine ( 'CLOCK_REALTIME' ) } } } ) {
1289- nsec = 1000 * 1000 ; // educated guess that it's milliseconds
1290- } else if ( clk_id === { { { cDefine ( 'CLOCK_MONOTONIC' ) } } } && _emscripten_get_now_is_monotonic ) {
1291- nsec = _emscripten_get_now_res ( ) ;
1292- } else {
1293- setErrNo ( { { { cDefine ( 'EINVAL' ) } } } ) ;
1294- return - 1 ;
1295- }
1296- { { { makeSetValue ( 'res' , C_STRUCTS . timespec . tv_sec , '(nsec/1000000000)|0' , 'i32' ) } } } ;
1297- { { { makeSetValue ( 'res' , C_STRUCTS . timespec . tv_nsec , 'nsec' , 'i32' ) } } } // resolution is nanoseconds
1298- return 0 ;
1299- } ,
1300- gettimeofday__sig : 'iii ',
1301- // http://pubs.opengroup.org/onlinepubs/000095399/basedefs/sys/time.h.html
1302- gettimeofday : function ( ptr ) {
1303- var now = Date . now ( ) ;
1304- { { { makeSetValue ( 'ptr' , C_STRUCTS . timeval . tv_sec , '(now/1000)|0' , 'i32' ) } } } ; // seconds
1305- { { { makeSetValue ( 'ptr' , C_STRUCTS . timeval . tv_usec , '((now % 1000)*1000)|0' , 'i32' ) } } } ; // microseconds
1306- return 0 ;
1307- } ,
1308-
13091228 // ==========================================================================
13101229 // sys/timeb.h
13111230 // ==========================================================================
@@ -2463,8 +2382,9 @@ LibraryManager.library = {
24632382
24642383 // Represents whether emscripten_get_now is guaranteed monotonic; the Date.now
24652384 // implementation is not :(
2385+ $nowIsMonotonic__internal : true ,
24662386#if MIN_IE_VERSION <= 9 || MIN_FIREFOX_VERSION <= 14 || MIN_CHROME_VERSION <= 23 || MIN_SAFARI_VERSION <= 80400 // https://caniuse.com/#feat=high-resolution-time
2467- emscripten_get_now_is_monotonic : `
2387+ $nowIsMonotonic : `
24682388 ((typeof performance == 'object' && performance && typeof performance['now'] == 'function')
24692389#if ENVIRONMENT_MAY_BE_NODE
24702390 || ENVIRONMENT_IS_NODE
@@ -2475,9 +2395,15 @@ LibraryManager.library = {
24752395 );` ,
24762396#else
24772397 // Modern environment where performance.now() is supported: (rely on minifier to return true unconditionally from this function)
2478- emscripten_get_now_is_monotonic : 'true ; ',
2398+ $nowIsMonotonic : 'true ; ',
24792399#endif
24802400
2401+ _emscripten_get_now_is_monotonic__internal : true ,
2402+ _emscripten_get_now_is_monotonic__deps : [ '$nowIsMonotonic' ] ,
2403+ _emscripten_get_now_is_monotonic : function ( ) {
2404+ return nowIsMonotonic ;
2405+ } ,
2406+
24812407#if MINIMAL_RUNTIME
24822408 $warnOnce : function ( text ) {
24832409 if ( ! warnOnce . shown ) warnOnce . shown = { } ;
0 commit comments