Class: Minjs::ECMA262::ExpSub

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

Overview

Class of the Subtraction 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) ⇒ ExpSub

Returns a new instance of ExpSub.



1295
1296
1297
1298
# File 'lib/minjs/ecma262/expression.rb', line 1295

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

Instance Method Details

#ecma262_typeofSymbol

return results of ‘typeof’ operator.

Returns:

  • (Symbol)

    :number



1326
1327
1328
# File 'lib/minjs/ecma262/expression.rb', line 1326

def ecma262_typeof
  :number
end

#priorityFixnum

Returns expression priority.

Returns:

  • (Fixnum)

    expression priority



1306
1307
1308
# File 'lib/minjs/ecma262/expression.rb', line 1306

def priority
  PRIORITY_ADDITIVE
end

#reduce(parent) ⇒ Object

reduce expression if available

Parameters:

  • parent (Base)

    parent element



1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
# File 'lib/minjs/ecma262/expression.rb', line 1312

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



1301
1302
1303
# File 'lib/minjs/ecma262/expression.rb', line 1301

def sym
  "-"
end