From 4defb9e23eca4ff57376767f90da50655dfde81f Mon Sep 17 00:00:00 2001 From: David Nolen Date: Wed, 21 Feb 2024 12:30:37 -0500 Subject: [PATCH 1/2] * implement IHash for js Symbol * add test cases --- src/main/cljs/cljs/core.cljs | 5 +++++ src/test/cljs/cljs/hashing_test.cljs | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/cljs/cljs/core.cljs b/src/main/cljs/cljs/core.cljs index ac7dbfc45..e384f1560 100644 --- a/src/main/cljs/cljs/core.cljs +++ b/src/main/cljs/cljs/core.cljs @@ -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." diff --git a/src/test/cljs/cljs/hashing_test.cljs b/src/test/cljs/cljs/hashing_test.cljs index 2a2ffcf18..66fd39aef 100644 --- a/src/test/cljs/cljs/hashing_test.cljs +++ b/src/test/cljs/cljs/hashing_test.cljs @@ -102,3 +102,11 @@ (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))) + (let [m {s 2}] + (is (== 2 (get m s))))))) From 3b9056391060315695d600f2a1fa728bcb21e415 Mon Sep 17 00:00:00 2001 From: David Nolen Date: Wed, 21 Feb 2024 14:00:01 -0500 Subject: [PATCH 2/2] * assertion --- src/test/cljs/cljs/hashing_test.cljs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/cljs/cljs/hashing_test.cljs b/src/test/cljs/cljs/hashing_test.cljs index 66fd39aef..7bad7169e 100644 --- a/src/test/cljs/cljs/hashing_test.cljs +++ b/src/test/cljs/cljs/hashing_test.cljs @@ -108,5 +108,6 @@ (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)))))))