Skip to content

Commit 7af8c42

Browse files
swannodettetonsky
andauthored
CLJS-3382: Fix regression in .apply after CLJS-3024 (#182)
Co-authored-by: Nikita Prokopov <[email protected]>
1 parent e4ff22f commit 7af8c42

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Diff for: src/main/clojure/cljs/core.cljc

+7-6
Original file line numberDiff line numberDiff line change
@@ -1507,12 +1507,13 @@
15071507
~(with-meta
15081508
`(fn ~[this-sym argsym]
15091509
(this-as ~this-sym
1510-
(.apply (.-call ~this-sym) ~this-sym
1511-
(.concat (array ~this-sym)
1512-
(if (> (.-length ~argsym) ~max-ifn-arity)
1513-
(doto (.slice ~argsym 0 ~max-ifn-arity)
1514-
(.push (.slice ~argsym ~max-ifn-arity)))
1515-
~argsym)))))
1510+
(let [args# (cljs.core/aclone ~argsym)]
1511+
(.apply (.-call ~this-sym) ~this-sym
1512+
(.concat (array ~this-sym)
1513+
(if (> (.-length args#) ~max-ifn-arity)
1514+
(doto (.slice args# 0 ~max-ifn-arity)
1515+
(.push (.slice args# ~max-ifn-arity)))
1516+
args#))))))
15161517
(meta form)))]
15171518
(ifn-invoke-methods type type-sym form))))
15181519

Diff for: src/test/cljs/cljs/apply_test.cljs

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
(is (= (range 22) (apply meta-f (range 22)))
4848
"Should properly call the last IFn arity with 20 args with last being a seq")
4949
(is (= (range 22) (.apply meta-f nil (to-array (range 22))))
50-
".apply should also handle >20 arguments"))
50+
".apply should also handle >20 arguments")
51+
(let [ctor #(.apply meta-f nil (js-arguments))] ; CLJS-3382
52+
(is (= '(1 2 3) (.apply ctor nil #js [1 2 3])))
53+
(is (= (range 30) (.apply ctor nil (to-array (range 30)))))))
5154

5255
(deftest multi-arity-test
5356
(is (= 2 (apply (fn ([a] a) ([a b] b)) 1 [2])))

0 commit comments

Comments
 (0)