@@ -391,25 +391,9 @@ LibraryManager.library = {
391
391
// time.h
392
392
// ==========================================================================
393
393
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 ( ) ;
413
397
} ,
414
398
415
399
_mktime_js__sig : 'ii ',
@@ -549,11 +533,6 @@ LibraryManager.library = {
549
533
return ret ;
550
534
} ,
551
535
552
- dysize : function ( year ) {
553
- var leap = ( ( year % 4 == 0 ) && ( ( year % 100 != 0 ) || ( year % 400 == 0 ) ) ) ;
554
- return leap ? 366 : 365 ;
555
- } ,
556
-
557
536
// TODO: Initialize these to defaults on startup from system settings.
558
537
// Note: glibc has one fewer underscore for all of these. Also used in other related functions (timegm)
559
538
_tzset_js__deps : [ 'tzset_impl' ] ,
@@ -1246,66 +1225,6 @@ LibraryManager.library = {
1246
1225
return _strptime ( buf , format , tm ) ; // no locale support yet
1247
1226
} ,
1248
1227
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
-
1309
1228
// ==========================================================================
1310
1229
// sys/timeb.h
1311
1230
// ==========================================================================
@@ -2463,8 +2382,9 @@ LibraryManager.library = {
2463
2382
2464
2383
// Represents whether emscripten_get_now is guaranteed monotonic; the Date.now
2465
2384
// implementation is not :(
2385
+ $nowIsMonotonic__internal : true ,
2466
2386
#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 : `
2468
2388
((typeof performance == 'object' && performance && typeof performance['now'] == 'function')
2469
2389
#if ENVIRONMENT_MAY_BE_NODE
2470
2390
|| ENVIRONMENT_IS_NODE
@@ -2475,9 +2395,15 @@ LibraryManager.library = {
2475
2395
);` ,
2476
2396
#else
2477
2397
// 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 ; ',
2479
2399
#endif
2480
2400
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
+
2481
2407
#if MINIMAL_RUNTIME
2482
2408
$warnOnce : function ( text ) {
2483
2409
if ( ! warnOnce . shown ) warnOnce . shown = { } ;
0 commit comments