Skip to content

Commit

Permalink
disable arity check for now
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Feb 12, 2016
1 parent 1b9033e commit 06394ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
52 changes: 26 additions & 26 deletions lib/opal/nodes/def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,32 +260,32 @@ def compile_keyword_args

# Returns code used in debug mode to check arity of method call
def arity_check(args, opt, splat, kwargs, block_name, mid)
meth = mid.to_s.inspect

arity = args.size - 1
arity -= (opt.size)

arity -= 1 if splat

arity -= (kwargs.size)

arity -= 1 if block_name
arity = -arity - 1 if !opt.empty? or !kwargs.empty? or splat

# $arity will point to our received arguments count
aritycode = "var $arity = arguments.length;"

if arity < 0 # splat or opt args
min_arity = -(arity + 1)
max_arity = args.size - 1
max_arity -= 1 if block_name
checks = []
checks << "$arity < #{min_arity}" if min_arity > 0
checks << "$arity > #{max_arity}" if max_arity and not(splat)
aritycode + "if (#{checks.join(' || ')}) { Opal.ac($arity, #{arity}, this, #{meth}); }" if checks.size > 0
else
aritycode + "if ($arity !== #{arity}) { Opal.ac($arity, #{arity}, this, #{meth}); }"
end
# meth = mid.to_s.inspect
#
# arity = args.size - 1
# arity -= (opt.size)
#
# arity -= 1 if splat
#
# arity -= (kwargs.size)
#
# arity -= 1 if block_name
# arity = -arity - 1 if !opt.empty? or !kwargs.empty? or splat
#
# # $arity will point to our received arguments count
# aritycode = "var $arity = arguments.length;"
#
# if arity < 0 # splat or opt args
# min_arity = -(arity + 1)
# max_arity = args.size - 1
# max_arity -= 1 if block_name
# checks = []
# checks << "$arity < #{min_arity}" if min_arity > 0
# checks << "$arity > #{max_arity}" if max_arity and not(splat)
# aritycode + "if (#{checks.join(' || ')}) { Opal.ac($arity, #{arity}, this, #{meth}); }" if checks.size > 0
# else
# aritycode + "if ($arity !== #{arity}) { Opal.ac($arity, #{arity}, this, #{meth}); }"
# end
end
end

Expand Down
5 changes: 3 additions & 2 deletions opal/corelib/basic_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def instance_eval(*args, &block)
})(self)
}
end
elsif args.size > 0
Kernel.raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
# elsif args.size > 0
# `console.log("instance_eval>>>asdf", args, args.length)`
# Kernel.raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
end

%x{
Expand Down

0 comments on commit 06394ae

Please sign in to comment.