diff --git a/src/sci/impl/evaluator.cljc b/src/sci/impl/evaluator.cljc index 2112b314..60d3b3c4 100644 --- a/src/sci/impl/evaluator.cljc +++ b/src/sci/impl/evaluator.cljc @@ -118,12 +118,12 @@ (def none-sentinel #?(:clj (Object.) :cljs (js/Object.))) -(defn get-from-type [instance method-str method-str-unmunged #?(:clj arg-count :cljs args)] +(defn get-from-type [instance _method-str method-str-unmunged #?(:clj arg-count :cljs args)] (if (zero? #?(:clj arg-count :cljs (alength args))) (if (instance? sci.impl.records.SciRecord instance) (get instance (keyword method-str-unmunged) none-sentinel) (if (instance? sci.impl.deftype.SciType instance) - (get (types/getVal instance) (symbol method-str) none-sentinel) + (get (types/getVal instance) (symbol method-str-unmunged) none-sentinel) none-sentinel)) none-sentinel)) diff --git a/test/sci/interop_test.cljc b/test/sci/interop_test.cljc index bbbc6000..e7bf2064 100644 --- a/test/sci/interop_test.cljc +++ b/test/sci/interop_test.cljc @@ -379,3 +379,11 @@ (is (= 1 (sci/eval-string "(def x #js {:foo_bar 1}) (.-foo-bar x)" {:classes {:allow :all}}))) (is (= 1 (sci/eval-string "(def x #js {:foo_bar (fn [] 1)}) (.foo-bar x)" {:classes {:allow :all}}))) (is (= {:foo_bar 1} (sci/eval-string "(js->clj (doto #js {} (set! -foo-bar 1)) :keywordize-keys true)" {:classes {:allow :all}}))))) + +#?(:clj + (deftest issue-987-deftype-munged-fields-test + ;; these cases don't work in CLJS yet because {:classes {:allow :all}} takes the fast path + ;; perhaps we can fix this by exposing the deftype as an Object in CLJS with mutated fields + (is (= 1 (sci/eval-string "(deftype Foo [foo-bar]) (.-foo-bar (->Foo 1))" {:classes {:allow :all}}))) + ;; this doesn't work yet either, but not common in Clojure + #_(is (= 1 (sci/eval-string "(deftype Foo [foo-bar]) (.-foo_bar (->Foo 1))" {:classes {:allow :all}})))))