Class: Minjs::ECMA262::ExpCond

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

Overview

Class of the Conditional operator expression element.

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Expression

#left_hand_side_exp?, #reduce, #side_effect?

Methods inherited from Base

#add_remove_paren, #concat

Constructor Details

#initialize(val, val2, val3) ⇒ ExpCond

Returns a new instance of ExpCond.



1893
1894
1895
1896
1897
# File 'lib/minjs/ecma262/expression.rb', line 1893

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

Instance Attribute Details

#valObject (readonly) Also known as: cond

Returns the value of attribute val.



1890
1891
1892
# File 'lib/minjs/ecma262/expression.rb', line 1890

def val
  @val
end

#val2Object (readonly)

Returns the value of attribute val2.



1890
1891
1892
# File 'lib/minjs/ecma262/expression.rb', line 1890

def val2
  @val2
end

#val3Object (readonly)

Returns the value of attribute val3.



1890
1891
1892
# File 'lib/minjs/ecma262/expression.rb', line 1890

def val3
  @val3
end

Instance Method Details

#==(obj) ⇒ Object

compare object



1960
1961
1962
1963
1964
1965
# File 'lib/minjs/ecma262/expression.rb', line 1960

def ==(obj)
  self.class == obj.class and
    @val == obj.val and
    @val2 == obj.val2 and
    @val3 == obj.val3
end

#add_parenObject

add parenthesis if need



1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
# File 'lib/minjs/ecma262/expression.rb', line 1919

def add_paren
  if @val.priority > PRIORITY_CONDITIONAL
    @val = ExpParen.new(@val)
  end
  if @val2.priority > PRIORITY_ASSIGNMENT
    @val2 = ExpParen.new(@val2)
  end
  if @val3.priority > PRIORITY_ASSIGNMENT
    @val3 = ExpParen.new(@val3)
  end
  self
end

#deep_dupObject

duplicate object

See Also:



1934
1935
1936
# File 'lib/minjs/ecma262/expression.rb', line 1934

def deep_dup
  self.class.new(@val.deep_dup, @val2.deep_dup, @val3.deep_dup)
end

#ecma262_typeofSymbol

return results of ‘typeof’ operator.

Returns:

  • (Symbol)

    typeof val2 if typeof val2 equals to val3



1976
1977
1978
1979
1980
1981
1982
1983
# File 'lib/minjs/ecma262/expression.rb', line 1976

def ecma262_typeof
  if @val2.respond_to? :ecma262_typeof and @val3.respond_to? :ecma262_typeof
    if @val2.ecma262_typeof == @val3.ecma262_typeof
      return @val2.ecma262_typeof
    end
  end
  nil
end

#priorityFixnum

Returns expression priority.

Returns:

  • (Fixnum)

    expression priority



1900
1901
1902
# File 'lib/minjs/ecma262/expression.rb', line 1900

def priority
  PRIORITY_CONDITIONAL
end

#remove_parenObject

remove parenthesis if possible



1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
# File 'lib/minjs/ecma262/expression.rb', line 1905

def remove_paren
  if @val.kind_of? ExpParen and @val.val.priority < PRIORITY_CONDITIONAL
    @val = @val.val if @val.remove_paren?
  end
  if @val2.kind_of? ExpParen and @val2.val.priority <= PRIORITY_ASSIGNMENT
    @val2 = @val2.val
  end
  if @val3.kind_of? ExpParen and @val3.val.priority <= PRIORITY_ASSIGNMENT
    @val3 = @val3.val
  end
  self
end

#replace(from, to) ⇒ Object

Replaces children object.

See Also:



1940
1941
1942
1943
1944
1945
1946
1947
1948
# File 'lib/minjs/ecma262/expression.rb', line 1940

def replace(from, to)
  if from .eql? @val
    @val = to
  elsif from .eql? @val2
    @val2 = to
  elsif from .eql? @val3
    @val3 = to
  end
end

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



1969
1970
1971
# File 'lib/minjs/ecma262/expression.rb', line 1969

def to_js(options = {})
  "#{@val.to_js(options)}?#{@val2.to_js(options)}:#{@val3.to_js(options)}"
end

#traverse(parent) {|parent, _self| ... } ⇒ Object

Traverses this children and itself with given block.

Yields:

Yield Parameters:

See Also:



1952
1953
1954
1955
1956
1957
# File 'lib/minjs/ecma262/expression.rb', line 1952

def traverse(parent, &block)
  @val.traverse(self, &block)
  @val2.traverse(self, &block)
  @val3.traverse(self, &block)
  yield parent, self
end