Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Arguments object is altered when contract put on a function #9

Merged
merged 1 commit into from over 2 years ago

2 participants

Tobiasz Cudnik Tim Disney
Tobiasz Cudnik

Arguments object is altered when contract put on a function, particularly the arguments.length is changes.

Test case:

a :: (Any) -> Any
a = (b) ->
    console.log arguments.length
    console.log arguments
a 'b', 'c', 'd'
Tim Disney disnet merged commit a99109d into from
Tim Disney disnet closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 11, 2012
Tobiasz Cudnik TobiaszCudnik Fixed arguments object is altered when contract put on a function (ch…
…erry picked from commit 6a9e706)
a99109d
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 7 additions and 2 deletions. Show diff stats Hide diff stats

  1. +7 2 src/contracts.coffee
9 src/contracts.coffee
@@ -320,12 +320,17 @@ fun = (dom, rng, options) ->
320 320
321 321 # check all the arguments
322 322 i = 0
323   - while i < dom.length
  323 + max_i = Math.max dom?.length, arguments.length
  324 + while i < max_i
324 325 # might pass through undefined which is fine (opt will take
325 326 # care of it if the argument is actually optional)
326 327 #
327 328 # blame is reversed
328   - args[i] = dom[i].check(arguments[i], neg, pos, parents, stack)
  329 + checked = if dom[i]
  330 + dom[i].check arguments[i], neg, pos, parents, stack
  331 + else arguments[i]
  332 + if i < arguments.length
  333 + args[i] = checked
329 334 # assigning back to args since we might be wrapping functions/objects
330 335 # in delayed contracts
331 336 i++

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.