Class: Minjs::ECMA262::ExpNegative

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

Overview

Class of the Negative operator expression element.

See Also:

Instance Attribute Summary

Attributes included from UnaryOperation

#val

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods included from UnaryOperation

#==, #add_paren, #deep_dup, #remove_paren, #replace, #side_effect?, #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) ⇒ ExpNegative

Returns a new instance of ExpNegative.



1008
1009
1010
# File 'lib/minjs/ecma262/expression.rb', line 1008

def initialize(val)
  @val = val
end

Instance Method Details

#ecma262_typeofSymbol

return results of ‘typeof’ operator.

Returns:

  • (Symbol)

    :number



1039
1040
1041
# File 'lib/minjs/ecma262/expression.rb', line 1039

def ecma262_typeof
  :number
end

#priorityFixnum

Returns expression priority.

Returns:

  • (Fixnum)

    expression priority



1018
1019
1020
# File 'lib/minjs/ecma262/expression.rb', line 1018

def priority
  PRIORITY_UNARY
end

#reduce(parent) ⇒ Object

reduce expression if available

Parameters:

  • parent (Base)

    parent element



1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
# File 'lib/minjs/ecma262/expression.rb', line 1024

def reduce(parent)
  if @val.kind_of? ECMA262Numeric
    if @val.integer.match(/^\-/)
      integer = $'
    else
      integer = "-#{@val.integer}"
    end
    val = ECMA262Numeric.new(integer, @val.decimal, @val.exp)
    parent.replace(self, val)
  end
end

#symObject

symbol of expression



1013
1014
1015
# File 'lib/minjs/ecma262/expression.rb', line 1013

def sym
  "-"
end