Skip to content
Permalink
Browse files

CLJS-3093: Check subvec arguments

  • Loading branch information...
mfikes committed May 23, 2019
1 parent 2bbc6eb commit 570d066ecd0e5a3b45849a28b8b8238fa920a4ea
Showing with 12 additions and 6 deletions.
  1. +4 −6 src/main/cljs/cljs/core.cljs
  2. +8 −0 src/test/cljs/cljs/core_test.cljs
@@ -5963,12 +5963,10 @@ reduces them without incurring seq initialization"
(do
(when-not (vector? v)
(throw (js/Error. "v must satisfy IVector")))
(let [c (count v)]
(when (or (neg? start)
(neg? end)
(> start c)
(> end c))
(throw (js/Error. "Index out of bounds"))))
(when (or (neg? start)
(< end start)
(> end (count v)))
(throw (js/Error. "Index out of bounds")))
(Subvec. meta v start end __hash))))

(defn subvec
@@ -1781,3 +1781,11 @@
(is (nil? (peek (subvec [1 2] 0 0))))
(is (nil? (peek (subvec [1 2] 1 1))))
(is (nil? (peek (subvec [1 2] 2 2)))))

(deftest test-cljs-3093
(is (thrown-with-msg? js/Error #"Index out of bounds" (subvec [1 2 3 4] -1)))
(is (= [1 2 3 4] (subvec [1 2 3 4] -0.9)))
(is (thrown-with-msg? js/Error #"Index out of bounds" (subvec [1 2 3 4] 2 1)))
(is (= [] (subvec [1 2 3 4] 1.7 1.3)))
(is (thrown-with-msg? js/Error #"Index out of bounds" (subvec [1 2 3 4] 0 5)))
(is (= [1 2 3 4] (subvec [1 2 3 4] 0 4.9))))

0 comments on commit 570d066

Please sign in to comment.
You can’t perform that action at this time.