Welcome! Log In Create A New Profile

Advanced

[njs] Fixed Date.prototype.setTime().

Dmitry Volyntsev
October 11, 2019 08:36AM
details: https://hg.nginx.org/njs/rev/a4e44e7e6f38
branches:
changeset: 1182:a4e44e7e6f38
user: Artem S. Povalyukhin <artem.povaluhin@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") },
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed Date.prototype.setTime().

Dmitry Volyntsev 55 October 11, 2019 08:36AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 78
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready