Skip to content

Commit 6a9e706

Browse files
committed
Fixed arguments object is altered when contract put on a function
1 parent 833c657 commit 6a9e706

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/contracts.coffee

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,17 @@ fun = (dom, rng, options) ->
321321

322322
# check all the arguments
323323
i = 0
324-
while i < dom.length
324+
max_i = Math.max dom?.length, arguments.length
325+
while i < max_i
325326
# might pass through undefined which is fine (opt will take
326327
# care of it if the argument is actually optional)
327328
#
328329
# blame is reversed
329-
args[i] = dom[i].check(arguments[i], neg, pos, parents, stack)
330+
checked = if dom[i]
331+
dom[i].check arguments[i], neg, pos, parents, stack
332+
else arguments[i]
333+
if i < arguments.length
334+
args[i] = checked
330335
# assigning back to args since we might be wrapping functions/objects
331336
# in delayed contracts
332337
i++

0 commit comments

Comments
 (0)