Class: Minjs::ECMA262::StWith

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

Overview

Base class of ECMA262 WithStatement 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(var_env, exp, statement) ⇒ StWith

Returns a new instance of StWith.



1158
1159
1160
1161
1162
# File 'lib/minjs/ecma262/statement.rb', line 1158

def initialize(var_env, exp, statement)
  @var_env = var_env
  @exp = exp
  @statement = statement
end

Instance Attribute Details

#expObject (readonly)

Returns the value of attribute exp.



1156
1157
1158
# File 'lib/minjs/ecma262/statement.rb', line 1156

def exp
  @exp
end

#statementObject (readonly)

Returns the value of attribute statement.



1156
1157
1158
# File 'lib/minjs/ecma262/statement.rb', line 1156

def statement
  @statement
end

#var_envObject (readonly)

Returns the value of attribute var_env.



1156
1157
1158
# File 'lib/minjs/ecma262/statement.rb', line 1156

def var_env
  @var_env
end

Instance Method Details

#==(obj) ⇒ Object

compare object



1188
1189
1190
1191
1192
# File 'lib/minjs/ecma262/statement.rb', line 1188

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

#add_parenObject

add parenthesis if need



1209
1210
1211
# File 'lib/minjs/ecma262/statement.rb', line 1209

def add_paren
  self
end

#deep_dupObject

duplicate object

See Also:



1166
1167
1168
# File 'lib/minjs/ecma262/statement.rb', line 1166

def deep_dup
  self.class.new(@var_env, @exp.deep_dup, @statement.deep_dup)
end

#remove_parenObject

remove parenthesis if possible



1201
1202
1203
1204
1205
1206
# File 'lib/minjs/ecma262/statement.rb', line 1201

def remove_paren
  if @exp.kind_of? ExpParen
    @exp = @exp.val
  end
  self
end

#replace(from, to) ⇒ Object

Replaces children object.

See Also:



1172
1173
1174
1175
1176
1177
1178
# File 'lib/minjs/ecma262/statement.rb', line 1172

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

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



1196
1197
1198
# File 'lib/minjs/ecma262/statement.rb', line 1196

def to_js(options = {})
  concat options, :with, "(", @exp, ")", @statement
end

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

Traverses this children and itself with given block.

Yields:

Yield Parameters:



1181
1182
1183
1184
1185
# File 'lib/minjs/ecma262/statement.rb', line 1181

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