Skip to content

Commit 4defb9e

Browse files
committed
* implement IHash for js Symbol
* add test cases
1 parent 4f400cb commit 4defb9e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,11 @@
14581458
(-hash [o]
14591459
(goog/getUid o)))
14601460

1461+
(extend-type symbol
1462+
IHash
1463+
(-hash [o]
1464+
(hash (.toString o))))
1465+
14611466
;;this is primitive because & emits call to array-seq
14621467
(defn inc
14631468
"Returns a number one greater than num."

src/test/cljs/cljs/hashing_test.cljs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@
102102
(is (= (hash 0.5) (hash 0.5)))
103103
(is (= (hash -0.32553251) (hash -0.32553251)))
104104
(is (= (hash -0.0000032553251) (hash -0.0000032553251)))))
105+
106+
(deftest test-cljs-3290
107+
(testing "JS Symbol hash"
108+
(let [s (.for js/Symbol "foo")]
109+
(is (number? (hash s)))
110+
(is (== (hash s) (hash s)))
111+
(let [m {s 2}]
112+
(is (== 2 (get m s)))))))

0 commit comments

Comments
 (0)