Class: Opal::Nodes::EnsureNode
- Inherits:
-
Base
- Object
- Base
- Opal::Nodes::EnsureNode
show all
- Defined in:
- lib/opal/nodes/rescue.rb
Instance Attribute Summary
Attributes inherited from Base
#compiler, #sexp, #type
#closure
Instance Method Summary
collapse
Methods inherited from Base
#add_gvar, #add_ivar, #add_local, #add_temp, children, #children, #class_variable_owner, #class_variable_owner_nesting_level, #comments, #compile_to_fragments, #error, #expr, #expr?, #expr_or_empty, #expr_or_nil, #fragment, handle, handlers, #helper, #in_ensure, #in_ensure?, #in_resbody, #in_resbody?, #in_rescue, #in_while?, #initialize, #process, #push, #recv, #recv?, #s, #scope, #source_location, #stmt, #stmt?, #top_scope, truthy_optimize?, #unshift, #while_loop, #with_temp, #wrap
#closure_is?, #compile_catcher, #generate_thrower, #generate_thrower_without_catcher, #in_closure, #pop_closure, #push_closure, #select_closure, #thrower
Methods included from Helpers
#current_indent, #empty_line, #indent, #js_truthy, #js_truthy_optimize, #line, #mid_to_jsid, #property, #valid_name?
Instance Method Details
#body_sexp ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/opal/nodes/rescue.rb', line 65
def body_sexp
if wrap_in_closure?
compiler.returns(begn)
else
begn
end
end
|
#compile ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/opal/nodes/rescue.rb', line 12
def compile
push_closure if wrap_in_closure?
push 'try {'
in_ensure do
line stmt(body_sexp)
end
line '} finally {'
indent do
if has_rescue_else?
unshift 'var $no_errors = true; '
line 'var $rescue_else_result;'
line 'if ($no_errors) { '
indent do
line '$rescue_else_result = (function() {'
indent do
line stmt(rescue_else_code)
end
line '})();'
end
line '}'
line compiler.process(ensr_sexp, @level)
line 'if ($no_errors) { return $rescue_else_result; }'
else
line compiler.process(ensr_sexp, @level)
end
end
line '}'
pop_closure if wrap_in_closure?
if wrap_in_closure?
if scope.await_encountered
wrap '(await (async function() { ', '; })())'
else
wrap '(function() { ', '; })()'
end
end
end
|
#ensr_sexp ⇒ Object
73
74
75
|
# File 'lib/opal/nodes/rescue.rb', line 73
def ensr_sexp
ensr || s(:nil)
end
|
#has_rescue_else? ⇒ Boolean
87
88
89
|
# File 'lib/opal/nodes/rescue.rb', line 87
def has_rescue_else?
@sexp.meta[:has_rescue_else]
end
|
#rescue_else_code ⇒ Object
81
82
83
84
85
|
# File 'lib/opal/nodes/rescue.rb', line 81
def rescue_else_code
rescue_else_code = scope.rescue_else_sexp
rescue_else_code = compiler.returns(rescue_else_code) unless stmt?
rescue_else_code
end
|
#wrap_in_closure? ⇒ Boolean
77
78
79
|
# File 'lib/opal/nodes/rescue.rb', line 77
def wrap_in_closure?
recv? || expr? || has_rescue_else?
end
|