class Minjs::ECMA262::ExpAdd

Class of the Additionr operator expression element.

@see www.ecma-international.org/ecma-262 ECMA262 11.6

Public Class Methods

new(val, val2) click to toggle source
# File lib/minjs/ecma262/expression.rb, line 1244
def initialize(val, val2)
  @val = val
  @val2 = val2
end

Public Instance Methods

priority() click to toggle source

@return [Fixnum] expression priority

# File lib/minjs/ecma262/expression.rb, line 1255
def priority
  PRIORITY_ADDITIVE
end
reduce(parent) click to toggle source

reduce expression if available @param parent [Base] parent element

# File lib/minjs/ecma262/expression.rb, line 1261
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
sym() click to toggle source

symbol of expression

# File lib/minjs/ecma262/expression.rb, line 1250
def sym
  "+"
end