class Minjs::ECMA262::StForIn

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

@see www.ecma-international.org/ecma-262 ECMA262 12.6.4

Attributes

exp1[R]
exp2[R]
statement[R]

Public Class Methods

new(exp1, exp2, statement) click to toggle source
# File lib/minjs/ecma262/statement.rb, line 843
def initialize(exp1, exp2, statement)
  @exp1 = exp1
  @exp2 = exp2
  @statement = statement
end

Public Instance Methods

==(obj) click to toggle source

compare object

# 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_paren() click to toggle source

add parenthesis if need

# 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_dup() click to toggle source

duplicate object @see Base#deep_dup

# 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_paren() click to toggle source

remove parenthesis if possible

# 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) click to toggle source

Replaces children object. @see Base#replace

# File lib/minjs/ecma262/statement.rb, line 857
def replace(from, to)
  if from .eql? @statement
    @statement = to
  end
end
to_js(options = {}) click to toggle source

Returns a ECMAScript string containg the representation of element. @see Base#to_js

# 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| ... } click to toggle source

Traverses this children and itself with given block.

# 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