Class: Minjs::ECMA262::ExpCall

Inherits:
Expression show all
Defined in:
lib/minjs/ecma262/expression.rb

Overview

Class of the Call expression element.

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Expression

#reduce, #side_effect?

Methods inherited from Base

#add_remove_paren, #concat

Constructor Details

#initialize(name, args) ⇒ ExpCall

Returns a new instance of ExpCall.



594
595
596
597
# File 'lib/minjs/ecma262/expression.rb', line 594

def initialize(name, args)
  @name = name
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



592
593
594
# File 'lib/minjs/ecma262/expression.rb', line 592

def args
  @args
end

#nameObject (readonly)

Returns the value of attribute name.



591
592
593
# File 'lib/minjs/ecma262/expression.rb', line 591

def name
  @name
end

Instance Method Details

#==(obj) ⇒ Object

compare object



637
638
639
# File 'lib/minjs/ecma262/expression.rb', line 637

def ==(obj)
  self.class == obj.class and @name == obj.name and @args == obj.args
end

#add_parenObject

add parenthesis if need



671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/minjs/ecma262/expression.rb', line 671

def add_paren
  if @name.priority > PRIORITY_LEFT_HAND_SIDE
    @name = ExpParen.new(@name)
  end
  if @args
    @args.map! do |arg|
      if arg.priority > PRIORITY_ASSIGNMENT
        ExpParen.new(arg)
      else
        arg
      end
    end
  end
  self
end

#deep_dupObject

duplicate object

See Also:



606
607
608
609
# File 'lib/minjs/ecma262/expression.rb', line 606

def deep_dup
  self.class.new(@name.deep_dup,
                 @args ? @args.collect{|x| x.deep_dup} : nil)
end

#left_hand_side_exp?Boolean

Returns true if expression is kind of LeftHandSideExpression.

Returns:

  • (Boolean)

    true if expression is kind of LeftHandSideExpression.



649
650
651
# File 'lib/minjs/ecma262/expression.rb', line 649

def left_hand_side_exp?
  true
end

#priorityFixnum

Returns expression priority.

Returns:

  • (Fixnum)

    expression priority



600
601
602
# File 'lib/minjs/ecma262/expression.rb', line 600

def priority
  PRIORITY_LEFT_HAND_SIDE
end

#remove_parenObject

remove parenthesis if possible



654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# File 'lib/minjs/ecma262/expression.rb', line 654

def remove_paren
  if @name.kind_of? ExpParen and @name.val.priority <= PRIORITY_LEFT_HAND_SIDE
    @name = @name.val if @name.remove_paren?
  end
  if @args
    @args.map! do |arg|
      if arg.kind_of? ExpParen and arg.val.priority <= PRIORITY_ASSIGNMENT #AssignmentOperators
        arg.val if arg.remove_paren?
      else
        arg
      end
    end
  end
  self
end

#replace(from, to) ⇒ Object

Replaces children object.

See Also:



613
614
615
616
617
618
619
620
621
622
623
624
625
# File 'lib/minjs/ecma262/expression.rb', line 613

def replace(from, to)
  if @name .eql? from
    @name = to
  else
    @args.each_index do |i|
      arg = @args[i]
      if arg .eql? from
        @args[i] = to
        break
      end
    end
  end
end

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



643
644
645
646
# File 'lib/minjs/ecma262/expression.rb', line 643

def to_js(options = {})
  args = @args.collect{|x| x.to_js(options)}.join(",")
  "#{@name.to_js(options)}(#{args})"
end

#traverse(parent) {|parent, _self| ... } ⇒ Object

Traverses this children and itself with given block.

Yields:

Yield Parameters:



628
629
630
631
632
633
634
# File 'lib/minjs/ecma262/expression.rb', line 628

def traverse(parent, &block)
  @name.traverse(self, &block)
  @args.each do |x|
    x.traverse(self, &block)
  end
  yield parent, self
end