Class: Minjs::ECMA262::ExpLogicalNot
- Inherits:
-
Expression
- Object
- Base
- Expression
- Minjs::ECMA262::ExpLogicalNot
- Includes:
- UnaryOperation
- Defined in:
- lib/minjs/ecma262/expression.rb
Overview
Class of the Logical Not operator expression element.
Instance Attribute Summary
Attributes included from UnaryOperation
Attributes inherited from Base
Instance Method Summary collapse
-
#ecma262_typeof ⇒ Symbol
return results of ‘typeof’ operator.
-
#initialize(val) ⇒ ExpLogicalNot
constructor
A new instance of ExpLogicalNot.
-
#priority ⇒ Fixnum
Expression priority.
-
#reduce(parent) ⇒ Object
reduce expression if available.
-
#sym ⇒ Object
symbol of expression.
-
#to_ecma262_boolean ⇒ Boolean
Returns results of ToBoolean().
-
#to_ecma262_number ⇒ Numeric
Returns results of ToNumber().
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_typeof ⇒ Symbol
return results of ‘typeof’ operator.
1143 1144 1145 |
# File 'lib/minjs/ecma262/expression.rb', line 1143 def ecma262_typeof :boolean end |
#priority ⇒ Fixnum
Returns 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
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 |
#sym ⇒ Object
symbol of expression
1081 1082 1083 |
# File 'lib/minjs/ecma262/expression.rb', line 1081 def sym "!" end |
#to_ecma262_boolean ⇒ Boolean
Returns results of ToBoolean()
Returns true or false if trivial, otherwise nil.
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_number ⇒ Numeric
Returns results of ToNumber()
Returns number if value is trivial, otherwise nil.
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 |