Class: Opal::Nodes::CallNode

Inherits:
Base
  • Object
show all
Defined in:
opal/lib/opal/nodes/call.rb

Direct Known Subclasses

BaseSuperNode, JsCallNode

Defined Under Namespace

Classes: DependencyResolver

Constant Summary collapse

SPECIALS =
{}
OPERATORS =

Operators that get optimized by compiler

{ :+ => :plus, :- => :minus, :* => :times, :/ => :divide,
:< => :lt, :<= => :le, :> => :gt, :>= => :ge }.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#compiler, #sexp, #type

Attributes included from Opal::Nodes::Closure::NodeSupport

#closure

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_gvar, #add_ivar, #add_local, #add_temp, children, #children, #class_variable_owner, #class_variable_owner_nesting_level, #comments, #compile_to_fragments, #error, #expr, #expr?, #expr_or_empty, #expr_or_nil, #fragment, handle, handlers, #has_rescue_else?, #helper, #in_ensure, #in_ensure?, #in_resbody, #in_resbody?, #in_rescue, #in_while?, #process, #push, #recv, #recv?, #s, #scope, #source_location, #stmt, #stmt?, #top_scope, truthy_optimize?, #unshift, #while_loop, #with_temp, #wrap

Methods included from Opal::Nodes::Closure::NodeSupport

#closure_is?, #compile_catcher, #generate_thrower, #generate_thrower_without_catcher, #in_closure, #pop_closure, #push_closure, #select_closure, #thrower

Methods included from Helpers

#current_indent, #empty_line, #indent, #js_truthy, #js_truthy_optimize, #line, #mid_to_jsid, #property, #valid_name?

Constructor Details

#initializeCallNode

Returns a new instance of CallNode.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'opal/lib/opal/nodes/call.rb', line 25

def initialize(*)
  super
  @recvr, @meth, *args = *@sexp

  *rest, last_arg = *args

  if last_arg && %i[iter block_pass].include?(last_arg.type)
    @iter = last_arg
    args = rest
  else
    @iter = nil
  end

  @arglist = s(:arglist, *args)
end

Instance Attribute Details

#arglistObject (readonly)

Returns the value of attribute arglist.



12
13
14
# File 'opal/lib/opal/nodes/call.rb', line 12

def arglist
  @arglist
end

#iterObject (readonly)

Returns the value of attribute iter.



12
13
14
# File 'opal/lib/opal/nodes/call.rb', line 12

def iter
  @iter
end

#methObject (readonly)

Returns the value of attribute meth.



12
13
14
# File 'opal/lib/opal/nodes/call.rb', line 12

def meth
  @meth
end

#recvrObject (readonly)

Returns the value of attribute recvr.



12
13
14
# File 'opal/lib/opal/nodes/call.rb', line 12

def recvr
  @recvr
end

Class Method Details

.add_special(name, options = {}, &handler) ⇒ Object



20
21
22
23
# File 'opal/lib/opal/nodes/call.rb', line 20

def self.add_special(name, options = {}, &handler)
  SPECIALS[name] = options
  define_method("handle_#{name}", &handler)
end

Instance Method Details

#compileObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'opal/lib/opal/nodes/call.rb', line 41

def compile
  # handle some methods specially
  # some special methods need to skip compilation, so we pass the default as a block
  handle_special do
    compiler.record_method_call meth

    with_wrapper do
      if using_eval?
        # if trying to access an lvar in eval or irb mode
        compile_eval_var
      elsif using_irb?
        # if trying to access an lvar in irb mode
        compile_irb_var
      else
        default_compile
      end
    end
  end
end