Module: Minjs::ECMA262::BinaryOperation

Overview

Module of typically binary operation expression.

Typically binary operation expression has two values(val, val2) and operation symbol.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valObject (readonly)

Returns the value of attribute val.



65
66
67
# File 'lib/minjs/ecma262/expression.rb', line 65

def val
  @val
end

#val2Object (readonly)

Returns the value of attribute val2.



65
66
67
# File 'lib/minjs/ecma262/expression.rb', line 65

def val2
  @val2
end

Instance Method Details

#==(obj) ⇒ Object

compare object



91
92
93
# File 'lib/minjs/ecma262/expression.rb', line 91

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

#add_parenObject

add parenthesis if need



79
80
81
82
83
84
85
86
87
88
# File 'lib/minjs/ecma262/expression.rb', line 79

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

  self
end

#deep_dupObject

duplicate object



97
98
99
# File 'lib/minjs/ecma262/expression.rb', line 97

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

#remove_parenObject

remove parenthesis if possible



68
69
70
71
72
73
74
75
76
# File 'lib/minjs/ecma262/expression.rb', line 68

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

#replace(from, to) ⇒ Object

Replaces children object.



103
104
105
106
107
108
109
# File 'lib/minjs/ecma262/expression.rb', line 103

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

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.



121
122
123
# File 'lib/minjs/ecma262/expression.rb', line 121

def to_js(options = {})
  concat options, @val, sym, @val2
end

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

Traverses this children and itself with given block.

Yields:

  • (parent, _self)

Yield Parameters:

See Also:



113
114
115
116
117
# File 'lib/minjs/ecma262/expression.rb', line 113

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