Skip to content

Commit 25b2f28

Browse files
committed
Disable date object related system calls by default.
JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
1 parent 3f37769 commit 25b2f28

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
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;
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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN
2828

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

3132
/**
@@ -37,6 +38,8 @@ struct timezone
3738
int tz_dsttime; /**< type of DST correction */
3839
};
3940

41+
#endif /* ECMA_ENABLE_DATE_SYS_CALLS */
42+
4043
/** \addtogroup ecma ECMA
4144
* @{
4245
*
@@ -456,15 +459,19 @@ ecma_date_week_day (ecma_number_t time) /**< time value */
456459
ecma_number_t __attr_always_inline___
457460
ecma_date_local_tza ()
458461
{
462+
#ifdef ECMA_ENABLE_DATE_SYS_CALLS
459463
struct timeval tv;
460464
struct timezone tz;
461465

462466
if (gettimeofday (&tv, &tz) != 0)
463467
{
464-
return ecma_raise_type_error ("gettimeofday failed");
468+
return ecma_number_make_nan ();
465469
}
466470

467471
return tz.tz_minuteswest * -ECMA_DATE_MS_PER_MINUTE;
472+
#else /* !ECMA_ENABLE_DATE_SYS_CALLS */
473+
return ECMA_NUMBER_ZERO;
474+
#endif /* ECMA_ENABLE_DATE_SYS_CALLS */
468475
} /* ecma_date_local_tza */
469476

470477
/**
@@ -483,15 +490,19 @@ ecma_date_daylight_saving_ta (ecma_number_t time) /**< time value */
483490
return time; /* time is NaN */
484491
}
485492

493+
#ifdef ECMA_ENABLE_DATE_SYS_CALLS
486494
struct timeval tv;
487495
struct timezone tz;
488496

489497
if (gettimeofday (&tv, &tz) != 0)
490498
{
491-
return ecma_raise_type_error ("gettimeofday failed");
499+
return ecma_number_make_nan ();
492500
}
493501

494502
return tz.tz_dsttime;
503+
#else /* !ECMA_ENABLE_DATE_SYS_CALLS */
504+
return ECMA_NUMBER_ZERO;
505+
#endif /* ECMA_ENABLE_DATE_SYS_CALLS */
495506
} /* ecma_date_daylight_saving_ta */
496507

497508
/**

0 commit comments

Comments
 (0)