Skip to content

Commit

Permalink
CLJS-477: Vararg fns break when first vararg is undefined.
Browse files Browse the repository at this point in the history
Examine arguments.length to determine the presence of varargs instead of
checking the argument in the first vararg position with goog.isDef(arg).
  • Loading branch information
mtyaka authored and swannodette committed Feb 26, 2013
1 parent cb04704 commit 17f9c53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/clj/cljs/compiler.clj
Expand Up @@ -422,7 +422,7 @@
(emitln "var self__ = this;"))
(when variadic
(emitln "var " (last params) " = null;")
(emitln "if (goog.isDef(var_args)) {")
(emitln "if (arguments.length > " (dec (count params)) ") {")
(emitln " " (last params) " = cljs.core.array_seq(Array.prototype.slice.call(arguments, " (dec (count params)) "),0);")
(emitln "} "))
(emitln "return " delegate-name ".call(" (string/join ", " (cons "this" params)) ");")
Expand Down
5 changes: 5 additions & 0 deletions test/cljs/cljs/core_test.cljs
Expand Up @@ -1828,5 +1828,10 @@
(assert (= (reduce-kv + 0 (apply hash-map (range 1000)))
(reduce + (range 1000))))

;; CLJS-477

(assert (= [js/undefined 1 2] ((fn [& more] more) js/undefined 1 2)))
(assert (= [js/undefined 4 5] ((fn [a b & more] more) 1 2 js/undefined 4 5)))

:ok
)

0 comments on commit 17f9c53

Please sign in to comment.