|
35 | 35 | meths))))) |
36 | 36 |
|
37 | 37 | (defn invoke-instance-method |
38 | | - #?@(:cljs [[ctx bindings obj _target-class method-name args _arg-count] |
| 38 | + #?@(:cljs [[ctx bindings obj _target-class method-name args _arg-count _arg-types] |
39 | 39 | ;; gobject/get didn't work here |
40 | 40 | (if-some [method (aget obj method-name)] |
41 | 41 | ;; use Reflect rather than (.apply method ...), see https://github.com/babashka/nbb/issues/118 |
42 | 42 | (let [args (.map args #(sci.impl.types/eval % ctx bindings))] |
43 | 43 | (js/Reflect.apply method obj args)) |
44 | 44 | (throw (js/Error. (str "Could not find instance method: " method-name))))] |
45 | 45 | :clj |
46 | | - [[ctx bindings obj ^Class target-class method ^objects args arg-count] |
| 46 | + [[ctx bindings obj ^Class target-class method ^objects args arg-count arg-types] |
47 | 47 | (let [^java.util.List methods |
48 | 48 | (meth-cache ctx target-class method arg-count #(Reflector/getMethods target-class arg-count method false) :instance-methods) |
49 | 49 | zero-args? (zero? arg-count)] |
50 | 50 | (if (and zero-args? (.isEmpty ^java.util.List methods)) |
51 | 51 | (invoke-instance-field obj target-class method) |
52 | | - (do (let [args-array (object-array arg-count) |
53 | | - ;; TODO: this can all be done at analysis time |
54 | | - ^"[Ljava.lang.Class;" types-array (when (and (not zero-args?) |
55 | | - (> (.size methods) 1)) |
56 | | - (make-array Class arg-count))] |
| 52 | + (do (let [args-array (object-array arg-count)] |
57 | 53 | (areduce args idx _ret nil |
58 | | - (do (aset args-array idx (sci.impl.types/eval (aget args idx) ctx bindings)) |
59 | | - (when types-array |
60 | | - (when-let [t (:tag-class (meta (aget args idx)))] |
61 | | - (aset types-array idx t))))) |
| 54 | + (aset args-array idx (sci.impl.types/eval (aget args idx) ctx bindings))) |
62 | 55 | ;; Note: I also tried caching the method that invokeMatchingMethod looks up, but retrieving it from the cache was actually more expensive than just doing the invocation! |
63 | 56 | ;; See getMatchingMethod in Reflector |
64 | | - (Reflector/invokeMatchingMethod method methods target-class obj args-array types-array)))))])) |
| 57 | + (Reflector/invokeMatchingMethod method methods target-class obj args-array arg-types)))))])) |
65 | 58 |
|
66 | 59 | (defn get-static-field [^Class class field-name-sym] |
67 | 60 | #?(:clj (Reflector/getStaticField class (str field-name-sym)) |
|
0 commit comments