Skip to content

Commit

Permalink
CLJS-2133: Invalid variadic IFn implementations now fail
Browse files Browse the repository at this point in the history
revert self__ hoisting, need to emit self__ ref in variadic delegate
  • Loading branch information
swannodette committed Jun 27, 2017
1 parent 3417d46 commit 809f23a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/clojure/cljs/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -744,13 +744,13 @@
mname (munge name)
delegate-name (str mname "__delegate")]
(emitln "(function() { ")
(when type
(emitln "var self__ = this;"))
(emits "var " delegate-name " = function (")
(doseq [param params]
(emit param)
(when-not (= param (last params)) (emits ",")))
(emitln "){")
(when type
(emitln "var self__ = this;"))
(when recurs (emitln "while(true){"))
(emits expr)
(when recurs
Expand All @@ -762,6 +762,8 @@
(if variadic
(concat (butlast params) ['var_args])
params)) "){")
(when type
(emitln "var self__ = this;"))
(when variadic
(emits "var ")
(emit (last params))
Expand Down
10 changes: 10 additions & 0 deletions src/test/cljs/cljs/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,16 @@
(testing "Syntax quoted dotted symbol without namespace should resolve to itself"
(is (= 'clojure.core `clojure.core))))

(deftype Partial [f args]
IFn
(-invoke [_ & a]
(apply (apply partial f args) a)))

(deftest test-cljs-2133
(testing "Invalid variadic IFn implementation should work"
(let [p (Partial. + [1])]
(p 2))))

(comment
;; ObjMap
;; (let [ks (map (partial str "foo") (range 500))
Expand Down

0 comments on commit 809f23a

Please sign in to comment.