[njs] An invalid value of Date object has been fixed.

Igor Sysoev igor at sysoev.ru
Wed Aug 31 12:54:36 UTC 2016


details:   http://hg.nginx.org/njs/rev/c0aa3ecd2e83
branches:  
changeset: 163:c0aa3ecd2e83
user:      Igor Sysoev <igor at sysoev.ru>
date:      Wed Aug 31 15:53:13 2016 +0300
description:
An invalid value of Date object has been fixed.

diffstat:

 njs/njs_date.c           |  10 ++++++----
 njs/test/njs_unit_test.c |   3 +++
 2 files changed, 9 insertions(+), 4 deletions(-)

diffs (47 lines):

diff -r 47f4830c3d22 -r c0aa3ecd2e83 njs/njs_date.c
--- a/njs/njs_date.c	Tue Aug 30 12:11:24 2016 +0300
+++ b/njs/njs_date.c	Wed Aug 31 15:53:13 2016 +0300
@@ -81,8 +81,8 @@ njs_ret_t
 njs_date_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     njs_index_t unused)
 {
-    double      num;
-    int64_t     time, values[8];
+    double      num, time;
+    int64_t     values[8];
     nxt_uint_t  i, n;
     njs_date_t  *date;
     struct tm   tm;
@@ -110,8 +110,8 @@ njs_date_constructor(njs_vm_t *vm, njs_v
                 num = args[i].data.u.number;
 
                 if (njs_is_nan(num)) {
-                    nargs = 0;
-                    break;
+                    time = num;
+                    goto done;
                 }
 
                 values[i] = num;
@@ -138,6 +138,8 @@ njs_date_constructor(njs_vm_t *vm, njs_v
             }
         }
 
+    done:
+
         date = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_date_t));
         if (nxt_slow_path(date == NULL)) {
             return NXT_ERROR;
diff -r 47f4830c3d22 -r c0aa3ecd2e83 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Aug 30 12:11:24 2016 +0300
+++ b/njs/test/njs_unit_test.c	Wed Aug 31 15:53:13 2016 +0300
@@ -4465,6 +4465,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("var o = Object.create(null); '__proto__' in o"),
       nxt_string("false") },
 
+    { nxt_string("var d = new Date(''); d +' '+ d.getTime()"),
+      nxt_string("Invalid Date NaN") },
+
     { nxt_string("var d = new Date(1308895200000); d.getTime()"),
       nxt_string("1308895200000") },
 



More information about the nginx-devel mailing list