class Minjs::ECMA262::ExpLogicalNot
Class of the Logical Not operator expression element.
@see www.ecma-international.org/ecma-262 ECMA262
11.4
Public Class Methods
new(val)
click to toggle source
# File lib/minjs/ecma262/expression.rb, line 1076 def initialize(val) @val = val end
Public Instance Methods
ecma262_typeof()
click to toggle source
return results of ‘typeof’ operator.
@return [Symbol] :boolean
# File lib/minjs/ecma262/expression.rb, line 1143 def ecma262_typeof :boolean end
priority()
click to toggle source
@return [Fixnum] expression priority
# File lib/minjs/ecma262/expression.rb, line 1086 def priority PRIORITY_UNARY end
reduce(parent)
click to toggle source
reduce expression if available @param parent [Base] parent element
# 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()
click to toggle source
symbol of expression
# File lib/minjs/ecma262/expression.rb, line 1081 def sym "!" end
to_ecma262_boolean()
click to toggle source
Returns results of ToBoolean()
Returns true or false if trivial, otherwise nil.
@return [Boolean]
@see www.ecma-international.org/ecma-262 ECMA262
9.2
# 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()
click to toggle source
Returns results of ToNumber()
Returns number if value is trivial, otherwise nil.
@return [Numeric]
@see www.ecma-international.org/ecma-262 ECMA262
9.3
# 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