Class: Minjs::ECMA262::StForIn

Inherits:
Statement show all
Defined in:
lib/minjs/ecma262/statement.rb

Overview

Base class of ECMA262 ‘for(in)’ IterationStatement element.

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Statement

#empty?, #priority, #to_exp?, #to_return?

Methods inherited from Base

#add_remove_paren, #concat

Constructor Details

#initialize(exp1, exp2, statement) ⇒ StForIn

Returns a new instance of StForIn.



843
844
845
846
847
# File 'lib/minjs/ecma262/statement.rb', line 843

def initialize(exp1, exp2, statement)
  @exp1 = exp1
  @exp2 = exp2
  @statement = statement
end

Instance Attribute Details

#exp1Object (readonly)

Returns the value of attribute exp1.



841
842
843
# File 'lib/minjs/ecma262/statement.rb', line 841

def exp1
  @exp1
end

#exp2Object (readonly)

Returns the value of attribute exp2.



841
842
843
# File 'lib/minjs/ecma262/statement.rb', line 841

def exp2
  @exp2
end

#statementObject (readonly)

Returns the value of attribute statement.



841
842
843
# File 'lib/minjs/ecma262/statement.rb', line 841

def statement
  @statement
end

Instance Method Details

#==(obj) ⇒ Object

compare object



872
873
874
875
876
877
# File 'lib/minjs/ecma262/statement.rb', line 872

def ==(obj)
  self.class == obj.class and
    @exp1 == obj.exp1 and
    @exp2 == obj.exp2 and
    @statement == obj.statement
end

#add_parenObject

add parenthesis if need



903
904
905
906
907
908
# File 'lib/minjs/ecma262/statement.rb', line 903

def add_paren
  if @exp1.priority > PRIORITY_LEFT_HAND_SIDE
    @exp1 = ExpParen.new(@exp1)
  end
  self
end

#deep_dupObject

duplicate object

See Also:



851
852
853
# File 'lib/minjs/ecma262/statement.rb', line 851

def deep_dup
  self.class.new(@exp1.deep_dup, @exp2.deep_dup, @statement.deep_dup)
end

#remove_parenObject

remove parenthesis if possible



892
893
894
895
896
897
898
899
900
# File 'lib/minjs/ecma262/statement.rb', line 892

def remove_paren
  if @exp1.kind_of? ExpParen and @exp1.val.priority <= PRIORITY_LEFT_HAND_SIDE
    @exp1 = @exp1.val
  end
  if @exp2.kind_of? ExpParen
    @exp2 = @exp2.val
  end
  self
end

#replace(from, to) ⇒ Object

Replaces children object.

See Also:



857
858
859
860
861
# File 'lib/minjs/ecma262/statement.rb', line 857

def replace(from, to)
  if from .eql? @statement
    @statement = to
  end
end

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



881
882
883
884
885
886
887
888
889
# File 'lib/minjs/ecma262/statement.rb', line 881

def to_js(options = {})
  if @statement.kind_of? StBlock and @statement.statement_list.length == 1
    statement = @statement.statement_list.statement_list[0]
  else
    statement = @statement
  end

  concat options, :for, '(', @exp1, :in, @exp2, ')', statement
end

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

Traverses this children and itself with given block.

Yields:

Yield Parameters:



864
865
866
867
868
869
# File 'lib/minjs/ecma262/statement.rb', line 864

def traverse(parent, &block)
  @exp1.traverse(self, &block)
  @exp2.traverse(self, &block)
  @statement.traverse(self, &block)
  yield parent, self
end