js-on-sx: Date.UTC and new Date propagate NaN/Infinity args
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 4m20s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 4m20s
This commit is contained in:
@@ -1111,8 +1111,10 @@
|
||||
(v)
|
||||
(cond
|
||||
((number? v) v)
|
||||
((= (type-of v) "rational") (exact->inexact v))
|
||||
((= (type-of v) "string") (js-date-parse-string v))
|
||||
(else 0))))
|
||||
((js-undefined? v) (js-nan-value))
|
||||
(else (js-to-number v)))))
|
||||
|
||||
(define
|
||||
js-date-parse-string
|
||||
@@ -1159,6 +1161,26 @@
|
||||
(* secs 1000)
|
||||
ms))))))
|
||||
|
||||
(define
|
||||
js-date-args-have-nan?
|
||||
(fn
|
||||
(args i)
|
||||
(cond
|
||||
((>= i (len args)) false)
|
||||
(else
|
||||
(let
|
||||
((n (js-to-number (nth args i))))
|
||||
(cond
|
||||
((or (number? n) (= (type-of n) "rational"))
|
||||
(let
|
||||
((nf (if (= (type-of n) "rational") (exact->inexact n) n)))
|
||||
(cond
|
||||
((js-number-is-nan nf) true)
|
||||
((= nf (js-infinity-value)) true)
|
||||
((= nf (- 0 (js-infinity-value))) true)
|
||||
(else (js-date-args-have-nan? args (+ i 1))))))
|
||||
(else (js-date-args-have-nan? args (+ i 1)))))))))
|
||||
|
||||
(define
|
||||
js-date-civil-to-days
|
||||
(fn
|
||||
@@ -1219,6 +1241,7 @@
|
||||
(cond
|
||||
((= (len args) 0) 0)
|
||||
((= (len args) 1) (js-date-from-one (nth args 0)))
|
||||
((js-date-args-have-nan? args 0) (js-nan-value))
|
||||
(else (js-date-from-parts args))))
|
||||
(dict-set! this "__js_is_date__" true)
|
||||
this)))))
|
||||
@@ -1228,8 +1251,15 @@
|
||||
(fn
|
||||
(&rest args)
|
||||
(cond
|
||||
((= (len args) 0) 0)
|
||||
(else (js-date-from-parts args))))
|
||||
((= (len args) 0) (js-nan-value))
|
||||
((js-date-args-have-nan? args 0) (js-nan-value))
|
||||
(else
|
||||
(let
|
||||
((ms (js-date-from-parts args)))
|
||||
(cond
|
||||
((or (> ms 8640000000000000) (< ms -8640000000000000))
|
||||
(js-nan-value))
|
||||
(else ms))))))
|
||||
:prototype
|
||||
{:getTime (fn () (js-date-time-value (js-this)))
|
||||
:valueOf (fn () (js-date-time-value (js-this)))
|
||||
|
||||
Reference in New Issue
Block a user