Class: Minjs::ECMA262::ExpLogicalNot

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

Overview

Class of the Logical Not 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) ⇒ ExpLogicalNot

Returns a new instance of ExpLogicalNot.



1076
1077
1078
# File 'lib/minjs/ecma262/expression.rb', line 1076

def initialize(val)
  @val = val
end

Instance Method Details

#ecma262_typeofSymbol

return results of ‘typeof’ operator.

Returns:

  • (Symbol)

    :boolean



1143
1144
1145
# File 'lib/minjs/ecma262/expression.rb', line 1143

def ecma262_typeof
  :boolean
end

#priorityFixnum

Returns expression priority.

Returns:

  • (Fixnum)

    expression priority



1086
1087
1088
# File 'lib/minjs/ecma262/expression.rb', line 1086

def priority
  PRIORITY_UNARY
end

#reduce(parent) ⇒ Object

reduce expression if available

Parameters:

  • parent (Base)

    parent element



1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
# File 'lib/minjs/ecma262/expression.rb', line 1092

def reduce(parent)
  if @val.kind_of? ECMA262Numeric and (@val.to_js == "0" || @val.to_js == "1")
    return
  end

  if (e = to_ecma262_boolean) != nil and @val.side_effect? == false
    if e
      parent.replace(self, ExpLogicalNot.new(ECMA262Numeric.new(0)))
    else
      parent.replace(self, ExpLogicalNot.new(ECMA262Numeric.new(1)))
    end
  elsif @val.kind_of? ExpLogicalNot and
     @val.val.respond_to?(:ecma262_typeof) and
     @val.val.ecma262_typeof == :boolean
      parent.replace(self, @val.val)
  end
end

#symObject

symbol of expression



1081
1082
1083
# File 'lib/minjs/ecma262/expression.rb', line 1081

def sym
  "!"
end

#to_ecma262_booleanBoolean

Returns results of ToBoolean()

Returns true or false if trivial, otherwise nil.

Returns:

See Also:



1118
1119
1120
1121
1122
# File 'lib/minjs/ecma262/expression.rb', line 1118

def to_ecma262_boolean
  return nil unless @val.respond_to? :to_ecma262_boolean
  return nil if @val.to_ecma262_boolean.nil?
  !@val.to_ecma262_boolean
end

#to_ecma262_numberNumeric

Returns results of ToNumber()

Returns number if value is trivial, otherwise nil.

Returns:

  • (Numeric)

See Also:



1132
1133
1134
1135
1136
1137
1138
# File 'lib/minjs/ecma262/expression.rb', line 1132

def to_ecma262_number
  if @val.respond_to? :to_ecma262_number
    v = @val.to_ecma262_number
    return nil if v.nil?
    v == 0 ? 1 : 0
  end
end