Class: Minjs::ECMA262::StTry

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

Overview

Base class of ECMA262 TryStatement 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, try, catch, finally) ⇒ StTry

Returns a new instance of StTry.



1443
1444
1445
1446
1447
1448
# File 'lib/minjs/ecma262/statement.rb', line 1443

def initialize(var_env, try, catch, finally)
  @var_env = var_env
  @try = try
  @catch = catch
  @finally = finally
end

Instance Attribute Details

#catchObject (readonly)

Returns the value of attribute catch.



1441
1442
1443
# File 'lib/minjs/ecma262/statement.rb', line 1441

def catch
  @catch
end

#finallyObject (readonly)

Returns the value of attribute finally.



1441
1442
1443
# File 'lib/minjs/ecma262/statement.rb', line 1441

def finally
  @finally
end

#tryObject (readonly)

Returns the value of attribute try.



1441
1442
1443
# File 'lib/minjs/ecma262/statement.rb', line 1441

def try
  @try
end

#var_envObject (readonly)

Returns the value of attribute var_env.



1440
1441
1442
# File 'lib/minjs/ecma262/statement.rb', line 1440

def var_env
  @var_env
end

Instance Method Details

#==(obj) ⇒ Object

compare object



1480
1481
1482
1483
1484
1485
# File 'lib/minjs/ecma262/statement.rb', line 1480

def ==(obj)
  self.class == obj.class and
    self.try == obj.try and
    self.catch == obj.catch and
    self.finally == obj.finally
end

#deep_dupObject

duplicate object

See Also:



1452
1453
1454
1455
1456
1457
# File 'lib/minjs/ecma262/statement.rb', line 1452

def deep_dup
  self.class.new(@var_env,
                 @try.deep_dup,
                 @catch ? @catch.deep_dup : nil,
                 @finally ? @finally.deep_dup : nil)
end

#replace(from, to) ⇒ Object

Replaces children object.

See Also:



1461
1462
1463
1464
1465
1466
1467
1468
1469
# File 'lib/minjs/ecma262/statement.rb', line 1461

def replace(from, to)
  if from .eql? @try
    @try = to
  elsif from .eql? @catch
    @catch = to
  elsif from .eql? @finally
    @finally = to
  end
end

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



1489
1490
1491
1492
1493
1494
1495
1496
1497
# File 'lib/minjs/ecma262/statement.rb', line 1489

def to_js(options = {})
  if @catch and @finally
    concat(options, :try, @try, @catch, :finally, @finally)
  elsif @catch
    concat(options, :try, @try, @catch)
  else
    concat(options, :try, @try, :finally, @finally)
  end
end

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

Traverses this children and itself with given block.

Yields:

Yield Parameters:



1472
1473
1474
1475
1476
1477
# File 'lib/minjs/ecma262/statement.rb', line 1472

def traverse(parent, &block)
  @try.traverse(self, &block)
  @catch.traverse(self, &block) if @catch
  @finally.traverse(self, &block) if @finally
  yield parent, self
end