Skip to content

Commit 7cbbff5

Browse files
ProjectFrankswannodette
authored andcommitted
CLJS-2021: subvec throws when passed non-vector
1 parent 0bb257c commit 7cbbff5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/main/cljs/cljs/core.cljs

+9-6
Original file line numberDiff line numberDiff line change
@@ -5476,12 +5476,15 @@ reduces them without incurring seq initialization"
54765476
(defn- build-subvec [meta v start end __hash]
54775477
(if (instance? Subvec v)
54785478
(recur meta (.-v v) (+ (.-start v) start) (+ (.-start v) end) __hash)
5479-
(let [c (count v)]
5480-
(when (or (neg? start)
5481-
(neg? end)
5482-
(> start c)
5483-
(> end c))
5484-
(throw (js/Error. "Index out of bounds")))
5479+
(do
5480+
(when-not (vector? v)
5481+
(throw (js/Error. "v must satisfy IVector")))
5482+
(let [c (count v)]
5483+
(when (or (neg? start)
5484+
(neg? end)
5485+
(> start c)
5486+
(> end c))
5487+
(throw (js/Error. "Index out of bounds"))))
54855488
(Subvec. meta v start end __hash))))
54865489

54875490
(defn subvec

src/test/cljs/cljs/core_test.cljs

+7
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,13 @@
12621262
(case (swap! x m) :a 0 :default)
12631263
(is (= :b @x)))))
12641264

1265+
(deftest test-cljs-2021
1266+
(let [check-if-throws #(try (%) (catch js/Error e :fail))]
1267+
(is (= :fail (check-if-throws #(subvec nil 0 0))))
1268+
(is (= :fail (check-if-throws #(subvec {:foo :bar} 0 1))))
1269+
(is (= :fail (check-if-throws #(subvec '(:foo) 0 1))))
1270+
(is (= :fail (check-if-throws #(subvec #{:foo} 0 1))))))
1271+
12651272
(comment
12661273
;; ObjMap
12671274
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)