Class: Red::ControlNode::RescueNode

Inherits:
Object
  • Object
show all
Defined in:
lib/red/control_nodes.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(attempted, rescue_body) ⇒ RescueNode

Returns a new instance of RescueNode.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/red/control_nodes.rb', line 52

def initialize(attempted, rescue_body)
  raise(BuildError::NoArbitraryRescue, "JavaScript does not support arbitrary placement of rescue/try blocks") unless @@rescue_is_safe
  raise(BuildError::NoSpecificRescue, "JavaScript does not support rescuing of specific exception classes") unless !rescue_body[1]
  @@rescue_is_safe == false
  @attempted = attempted.build_node
  if (block = (rescue_body.assoc(:block) || [])[1..-1]) && block.first.last == [:gvar, %s($!)]
    exception_node = block.shift
    @exception_variable = exception_node[1].build_node
    @rescued = block.unshift(:block).build_node
  else
    @exception_variable = :e.build_node
    @rescued = rescue_body[2].build_node
  end
end

Instance Method Details

#compile_internals(options = {}) ⇒ Object



71
72
73
# File 'lib/red/control_nodes.rb', line 71

def compile_internals(options = {})
  return [@attempted, @exception_variable, @rescued].compile_nodes
end

#compile_node(options = {}) ⇒ Object



67
68
69
# File 'lib/red/control_nodes.rb', line 67

def compile_node(options = {})
  return "try { %s; } catch(%s) { %s; }" % self.compile_internals
end