Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLJS-3290: implement IHash for js Symbol #225

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,11 @@
(-hash [o]
(goog/getUid o)))

(extend-type symbol
IHash
(-hash [o]
(hash (.toString o))))

;;this is primitive because & emits call to array-seq
(defn inc
"Returns a number one greater than num."
Expand Down
9 changes: 9 additions & 0 deletions src/test/cljs/cljs/hashing_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,12 @@
(is (= (hash 0.5) (hash 0.5)))
(is (= (hash -0.32553251) (hash -0.32553251)))
(is (= (hash -0.0000032553251) (hash -0.0000032553251)))))

(deftest test-cljs-3290
(testing "JS Symbol hash"
(let [s (.for js/Symbol "foo")]
(is (number? (hash s)))
(is (== (hash s) (hash s)))
(is (not (== (hash s) (hash (.for js/Symbol "bar")))))
(let [m {s 2}]
(is (== 2 (get m s)))))))
Loading