Class: Minjs::ECMA262::ExpMul

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

Overview

Class of the Multiprication operator expression element.

See Also:

Instance Attribute Summary

Attributes included from BinaryOperation

#val, #val2

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods included from BinaryOperation

#==, #add_paren, #deep_dup, #remove_paren, #replace, #to_js, #traverse

Methods inherited from Expression

#left_hand_side_exp?, #side_effect?

Methods inherited from Base

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

Constructor Details

#initialize(val, val2) ⇒ ExpMul

Returns a new instance of ExpMul.



1154
1155
1156
1157
# File 'lib/minjs/ecma262/expression.rb', line 1154

def initialize(val, val2)
  @val = val
  @val2 = val2
end

Instance Method Details

#ecma262_typeofSymbol

return results of ‘typeof’ operator.

Returns:

  • (Symbol)

    :number



1185
1186
1187
# File 'lib/minjs/ecma262/expression.rb', line 1185

def ecma262_typeof
  :number
end

#priorityFixnum

Returns expression priority.

Returns:

  • (Fixnum)

    expression priority



1165
1166
1167
# File 'lib/minjs/ecma262/expression.rb', line 1165

def priority
  PRIORITY_MULTIPLICATIVE
end

#reduce(parent) ⇒ Object

reduce expression if available

Parameters:

  • parent (Base)

    parent element



1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
# File 'lib/minjs/ecma262/expression.rb', line 1171

def reduce(parent)
  # A * B
  if @val.respond_to? :to_ecma262_number and @val2.respond_to? :to_ecma262_number
    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

#symObject

symbol of expression



1160
1161
1162
# File 'lib/minjs/ecma262/expression.rb', line 1160

def sym
  "*"
end