class Opal::Nodes::IterArityCheckNode

Public Instance Methods

compile() click to toggle source
# File lib/opal/nodes/args/arity_check.rb, line 121
def compile
  scope.arity = arity

  return unless compiler.arity_check?

  unless arity_checks.empty?
    parent_scope = scope
    until parent_scope.def? || parent_scope.class_scope? || parent_scope.top?
      parent_scope = parent_scope.parent
    end

    context =
      if parent_scope.top?
        "'<main>'"
      elsif parent_scope.def?
        "'#{parent_scope.mid}'"
      elsif parent_scope.class?
        "'<class:#{parent_scope.name}>'"
      elsif parent_scope.module?
        "'<module:#{parent_scope.name}>'"
      end

    identity = scope.identity

    line "if (#{identity}.$$is_lambda || #{identity}.$$define_meth) {"
    line '  var $arity = arguments.length;'
    line "  if (#{arity_checks.join(' || ')}) { Opal.block_ac($arity, #{arity}, #{context}); }"
    line '}'
  end
end