Skip to content
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
4 changes: 2 additions & 2 deletions src/sci/impl/evaluator.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
8 changes: 8 additions & 0 deletions test/sci/interop_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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}})))))
Loading