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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ SCI is used in [babashka](https://github.com/babashka/babashka),
- Add core dynamic vars like `*warn-on-reflection*` and bind them during
`load-string` etc. such that `set!`-ing then in a `future` works.
- Fix [#984](https://github.com/babashka/sci/issues/984): support alternative `set!` syntax in CLJS
- Fix [#987](https://github.com/babashka/sci/issues/987): method or property should be munged
- Fix [#986](https://github.com/babashka/sci/issues/986): preserve error location for js static method
- Fix [#990](https://github.com/babashka/sci/issues/990): fix `merge-opts` with `:bindings` + deprecate `:bindings` (replaced by `:namespaces {'user ...}`)

Expand Down
6 changes: 4 additions & 2 deletions src/sci/impl/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,8 @@
meth-name (if field-access
(subs method-name 1)
method-name)
meth-name* meth-name
meth-name (munge meth-name)
stack (assoc (meta expr)
:ns @utils/current-ns
:file @utils/current-file)]
Expand Down Expand Up @@ -1011,7 +1013,7 @@
(aset arg-types idx t))))))))
(with-meta (sci.impl.types/->Node
(eval/eval-instance-method-invocation
ctx bindings instance-expr meth-name field-access args arg-count
ctx bindings instance-expr meth-name meth-name* field-access args arg-count
#?(:cljs nil
:clj (when @has-types?
arg-types)))
Expand All @@ -1036,7 +1038,7 @@
;; default case
(sci.impl.types/->Node
(eval/eval-instance-method-invocation
ctx bindings instance-expr meth-name field-access args allowed? nil nil)
ctx bindings instance-expr meth-name meth-name* field-access args allowed? nil nil)
stack))
{::instance-expr instance-expr
::method-name method-name}))))]
Expand Down
8 changes: 4 additions & 4 deletions src/sci/impl/evaluator.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@

(def none-sentinel #?(:clj (Object.) :cljs (js/Object.)))

(defn get-from-type [instance method-str #?(: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) none-sentinel)
(get instance (keyword method-str-unmunged) none-sentinel)
(if (instance? sci.impl.deftype.SciType instance)
(get (types/getVal instance) (symbol method-str) none-sentinel)
none-sentinel))
none-sentinel))

(defn eval-instance-method-invocation
[ctx bindings instance-expr method-str field-access args #?(:cljs allowed) arg-count arg-types]
[ctx bindings instance-expr method-str method-str-unmunged field-access args #?(:cljs allowed) arg-count arg-types]
(let [instance-meta (meta instance-expr)
tag-class (:tag-class instance-meta)
instance-expr* (types/eval instance-expr ctx bindings)
v (get-from-type instance-expr* method-str #?(:clj arg-count :cljs args))]
v (get-from-type instance-expr* method-str method-str-unmunged #?(:clj arg-count :cljs args))]
(if-not (identical? none-sentinel v)
v
(let [instance-class (or tag-class (#?(:clj class :cljs type) instance-expr*))
Expand Down
5 changes: 5 additions & 0 deletions test/sci/interop_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,8 @@
{:bindings {'resource (io/resource "clojure/core.clj")}
:classes {'java.net.URL java.net.URL
'java.net.JarURLConnection java.net.JarURLConnection}}))))

#?(:cljs
(deftest issue-987-test
(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}})))))
Loading