Class: Minjs::ECMA262::ExpAdd

Inherits:
ExpArg2 show all
Includes:
BinaryOperation
Defined in:
lib/minjs/ecma262/exp.rb

Overview

11.6.1 The Addition operator ( + )

Instance Attribute Summary

Attributes inherited from ExpArg2

#val, #val2

Instance Method Summary collapse

Methods included from BinaryOperation

#==, #add_paren, #remove_paren

Methods inherited from ExpArg2

#deep_dup, #initialize, #replace, #to_js, #traverse

Methods inherited from Exp

#left_hand_side_exp?, #to_js, #traverse

Methods inherited from Base

#==, #add_remove_paren, #concat, #deep_dup, #replace, #to_js, #to_s

Constructor Details

This class inherits a constructor from Minjs::ECMA262::ExpArg2

Instance Method Details

#priorityObject



842
843
844
# File 'lib/minjs/ecma262/exp.rb', line 842

def priority
  PRIORITY_ADDITIVE
end

#reduce(parent) ⇒ Object



852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
# File 'lib/minjs/ecma262/exp.rb', line 852

def reduce(parent)
  #
  # String + String/
  # a + b = a.concat(b)
  if @val.kind_of? ECMA262String or @val2.kind_of? ECMA262String
    if @val.respond_to? :to_ecma262_string and @val2.respond_to? :to_ecma262_string
      v = @val.to_ecma262_string
      v2 = @val2.to_ecma262_string
      if !v.nil? and !v2.nil?
        new_str = ECMA262String.new(v + v2)
        parent.replace(self, new_str)
      end
    end
  #
  # Numeric + Numeric
  #
  elsif @val.respond_to? :to_ecma262_number and @val2.respond_to? :to_ecma262_number
    #
    #11.6.3 Applying the Additive Operators to Numbers(TODO)
    #
    # N + M => (N + M)
    v = @val.to_ecma262_number
    v2 = @val2.to_ecma262_number
    if !v.nil? and !v2.nil?
      parent.replace(self, ECMA262Numeric.new(v + v2))
    end
  end
end

#swapObject



846
847
848
849
850
# File 'lib/minjs/ecma262/exp.rb', line 846

def swap
  t = @val
  @val = @val2
  @val2 = t
end

#symObject



838
839
840
# File 'lib/minjs/ecma262/exp.rb', line 838

def sym
  "+"
end