Skip to content

Commit 7ffaff6

Browse files
committed
Disable date object related system calls by default
Use DATE_SYS_CALLS=ON for make target to enable the date related system calls. Also fix some minor issues. Related issue: #923 JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
1 parent d4650bc commit 7ffaff6

File tree

5 files changed

+41
-11
lines changed

5 files changed

+41
-11
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ BUILD_NAME:=
7575
CMAKE_DEFINES:=$(CMAKE_DEFINES) -DENABLE_LOG=$(LOG)
7676
endif
7777

78+
# Date system calls
79+
ifneq ($(DATE_SYS_CALLS),)
80+
CMAKE_DEFINES:=$(CMAKE_DEFINES) -DENABLE_DATE_SYS_CALLS=$(DATE_SYS_CALLS)
81+
endif
82+
7883
# All-in-one build
7984
ifneq ($(ALL_IN_ONE),)
8085
CMAKE_DEFINES:=$(CMAKE_DEFINES) -DENABLE_ALL_IN_ONE=$(ALL_IN_ONE)

jerry-core/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ project (JerryCore C ASM)
185185
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ENABLE_LOG)
186186
endif()
187187

188+
# Date system calls
189+
if("${ENABLE_DATE_SYS_CALLS}" STREQUAL "ON")
190+
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ENABLE_DATE_SYS_CALLS)
191+
endif()
192+
188193
# Platform-specific configuration
189194
set(DEFINES_JERRY ${DEFINES_JERRY} ${DEFINES_JERRY_${PLATFORM_EXT}})
190195

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 JERRY_ENABLE_DATE_SYS_CALLS
3637
#include <sys/time.h>
38+
#endif /* JERRY_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 JERRY_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 /* JERRY_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 & 10 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 JERRY_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 /* JERRY_ENABLE_DATE_SYS_CALLS */
3933

4034
/** \addtogroup ecma ECMA
4135
* @{
@@ -456,15 +450,21 @@ ecma_date_week_day (ecma_number_t time) /**< time value */
456450
ecma_number_t __attr_always_inline___
457451
ecma_date_local_tza ()
458452
{
453+
#ifdef JERRY_ENABLE_DATE_SYS_CALLS
459454
struct timeval tv;
460455
struct timezone tz;
461456

457+
tz.tz_minuteswest = 0; /* gettimeofday may not fill tz, so zero-initializing */
458+
462459
if (gettimeofday (&tv, &tz) != 0)
463460
{
464-
return ecma_raise_type_error ("gettimeofday failed");
461+
return ecma_number_make_nan ();
465462
}
466463

467464
return tz.tz_minuteswest * -ECMA_DATE_MS_PER_MINUTE;
465+
#else /* !JERRY_ENABLE_DATE_SYS_CALLS */
466+
return ECMA_NUMBER_ZERO;
467+
#endif /* JERRY_ENABLE_DATE_SYS_CALLS */
468468
} /* ecma_date_local_tza */
469469

470470
/**
@@ -483,15 +483,21 @@ ecma_date_daylight_saving_ta (ecma_number_t time) /**< time value */
483483
return time; /* time is NaN */
484484
}
485485

486+
#ifdef JERRY_ENABLE_DATE_SYS_CALLS
486487
struct timeval tv;
487488
struct timezone tz;
488489

490+
tz.tz_dsttime = 0; /* gettimeofday may not fill tz, so zero-initializing */
491+
489492
if (gettimeofday (&tv, &tz) != 0)
490493
{
491-
return ecma_raise_type_error ("gettimeofday failed");
494+
return ecma_number_make_nan ();
492495
}
493496

494497
return tz.tz_dsttime;
498+
#else /* !JERRY_ENABLE_DATE_SYS_CALLS */
499+
return ECMA_NUMBER_ZERO;
500+
#endif /* JERRY_ENABLE_DATE_SYS_CALLS */
495501
} /* ecma_date_daylight_saving_ta */
496502

497503
/**

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)