Skip to content

Commit e05176a

Browse files
committed
Disable date object related system calls by default
Also fix some minor issues. Related issue: #923 JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
1 parent b8b587f commit e05176a

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

jerry-core/config.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,12 @@
180180
*/
181181
#define CONFIG_PARSER_ENABLE_PARSE_TIME_BYTE_CODE_OPTIMIZER
182182

183+
/**
184+
* Enable timezone and daylightsaving system calls for date object
185+
*
186+
* Note:
187+
* Experimental. Works on Ubuntu 14.04.
188+
*/
189+
// #define ECMA_ENABLE_DATE_SYS_CALLS
190+
183191
#endif /* !CONFIG_H */

jerry-core/ecma/builtin-objects/ecma-builtin-date.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
#define BUILTIN_UNDERSCORED_ID date
3434
#include "ecma-builtin-internal-routines-template.inc.h"
3535

36+
#ifdef ECMA_ENABLE_DATE_SYS_CALLS
3637
#include <sys/time.h>
38+
#endif /* ECMA_ENABLE_DATE_SYS_CALLS */
3739

3840
/** \addtogroup ecma ECMA
3941
* @{
@@ -451,16 +453,19 @@ ecma_builtin_date_utc (ecma_value_t this_arg __attr_unused___, /**< this argumen
451453
static ecma_value_t
452454
ecma_builtin_date_now (ecma_value_t this_arg __attr_unused___) /**< this argument */
453455
{
454-
struct timeval tv;
455456
ecma_number_t *now_num_p = ecma_alloc_number ();
456457
*now_num_p = ECMA_NUMBER_ZERO;
457458

459+
#ifdef ECMA_ENABLE_DATE_SYS_CALLS
460+
struct timeval tv = { 0, 0 };
461+
458462
if (gettimeofday (&tv, NULL) != 0)
459463
{
460464
return ecma_raise_type_error ("gettimeofday failed");
461465
}
462466

463467
*now_num_p = ((ecma_number_t) tv.tv_sec) * 1000.0 + ((ecma_number_t) (tv.tv_usec / 1000));
468+
#endif /* ECMA_ENABLE_DATE_SYS_CALLS */
464469

465470
return ecma_make_number_value (now_num_p);
466471
} /* ecma_builtin_date_now */

jerry-core/ecma/builtin-objects/ecma-builtin-helpers-date.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,10 @@
2626

2727
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN
2828

29+
#ifdef ECMA_ENABLE_DATE_SYS_CALLS
2930
#include <sys/time.h>
3031

31-
/**
32-
* Timezone structure
33-
*/
34-
struct timezone
35-
{
36-
int tz_minuteswest; /**< minutes west of Greenwich */
37-
int tz_dsttime; /**< type of DST correction */
38-
};
32+
#endif /* ECMA_ENABLE_DATE_SYS_CALLS */
3933

4034
/** \addtogroup ecma ECMA
4135
* @{
@@ -456,15 +450,19 @@ ecma_date_week_day (ecma_number_t time) /**< time value */
456450
ecma_number_t __attr_always_inline___
457451
ecma_date_local_tza ()
458452
{
459-
struct timeval tv;
460-
struct timezone tz;
453+
#ifdef ECMA_ENABLE_DATE_SYS_CALLS
454+
struct timeval tv = { 0, 0 }; /* gettimeofday may not fill tv, so zero-initializing */
455+
struct timezone tz = { 0, 0 }; /* gettimeofday may not fill tz, so zero-initializing */
461456

462457
if (gettimeofday (&tv, &tz) != 0)
463458
{
464-
return ecma_raise_type_error ("gettimeofday failed");
459+
return ecma_number_make_nan ();
465460
}
466461

467462
return tz.tz_minuteswest * -ECMA_DATE_MS_PER_MINUTE;
463+
#else /* !ECMA_ENABLE_DATE_SYS_CALLS */
464+
return ECMA_NUMBER_ZERO;
465+
#endif /* ECMA_ENABLE_DATE_SYS_CALLS */
468466
} /* ecma_date_local_tza */
469467

470468
/**
@@ -483,15 +481,19 @@ ecma_date_daylight_saving_ta (ecma_number_t time) /**< time value */
483481
return time; /* time is NaN */
484482
}
485483

486-
struct timeval tv;
487-
struct timezone tz;
484+
#ifdef ECMA_ENABLE_DATE_SYS_CALLS
485+
struct timeval tv = { 0, 0 }; /* gettimeofday may not fill tv, so zero-initializing */
486+
struct timezone tz = { 0, 0 }; /* gettimeofday may not fill tz, so zero-initializing */
488487

489488
if (gettimeofday (&tv, &tz) != 0)
490489
{
491-
return ecma_raise_type_error ("gettimeofday failed");
490+
return ecma_number_make_nan ();
492491
}
493492

494493
return tz.tz_dsttime;
494+
#else /* !ECMA_ENABLE_DATE_SYS_CALLS */
495+
return ECMA_NUMBER_ZERO;
496+
#endif /* ECMA_ENABLE_DATE_SYS_CALLS */
495497
} /* ecma_date_daylight_saving_ta */
496498

497499
/**

jerry-libc/include/sys/time.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ struct timeval
3131
unsigned long tv_usec; /**< microseconds */
3232
};
3333

34+
/**
35+
* Timezone structure
36+
*/
37+
struct timezone
38+
{
39+
int tz_minuteswest; /**< minutes west of Greenwich */
40+
int tz_dsttime; /**< type of DST correction */
41+
};
42+
3443
int gettimeofday (void *tp, void *tzp);
3544

3645
#ifdef __cplusplus

0 commit comments

Comments
 (0)