[njs] Fixed Date.prototype.setTime().
Dmitry Volyntsev
xeioex at nginx.com
Fri Oct 11 12:34:51 UTC 2019
details: https://hg.nginx.org/njs/rev/a4e44e7e6f38
branches:
changeset: 1182:a4e44e7e6f38
user: Artem S. Povalyukhin <artem.povaluhin at gmail.com>
date: Fri Oct 11 06:50:33 2019 +0300
description:
Fixed Date.prototype.setTime().
This closes #236 issue on Github.
diffstat:
src/njs_date.c | 15 +++++----------
src/test/njs_unit_test.c | 15 +++++++++++++++
2 files changed, 20 insertions(+), 10 deletions(-)
diffs (50 lines):
diff -r 9944f6e9f33a -r a4e44e7e6f38 src/njs_date.c
--- a/src/njs_date.c Fri Oct 11 08:01:03 2019 +0300
+++ b/src/njs_date.c Fri Oct 11 06:50:33 2019 +0300
@@ -1520,16 +1520,11 @@ njs_date_prototype_set_time(njs_vm_t *vm
{
double time;
- time = njs_date(&args[0])->time;
-
- if (njs_fast_path(!isnan(time))) {
-
- if (nargs > 1) {
- time = njs_number(&args[1]);
-
- } else {
- time = NAN;
- }
+ if (nargs > 1) {
+ time = njs_timeclip(njs_number(&args[1]));
+
+ } else {
+ time = NAN;
}
njs_date(&args[0])->time = time;
diff -r 9944f6e9f33a -r a4e44e7e6f38 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Fri Oct 11 08:01:03 2019 +0300
+++ b/src/test/njs_unit_test.c Fri Oct 11 06:50:33 2019 +0300
@@ -11878,6 +11878,21 @@ static njs_unit_test_t njs_test[] =
{ njs_str("var d = new Date(); d.setTime(1308895200000); d.getTime()"),
njs_str("1308895200000") },
+ { njs_str("var d = new Date(); d.setTime(); d.getTime()"),
+ njs_str("NaN") },
+
+ { njs_str("var d = new Date(); d.setTime(Infinity); d.getTime()"),
+ njs_str("NaN") },
+
+ { njs_str("var d = new Date(); d.setTime(8.64e15 +1); d.getTime()"),
+ njs_str("NaN") },
+
+ { njs_str("var d = new Date(NaN); d.setTime(0); d.getTime()"),
+ njs_str("0") },
+
+ { njs_str("var d = new Date(); d.setTime(8.64e15); d.getTime()"),
+ njs_str("8640000000000000") },
+
{ njs_str("var d = new Date(1308895201625); d.setMilliseconds(5003);"
"d.getTime()"),
njs_str("1308895206003") },
More information about the nginx-devel
mailing list