Skip to content

Commit e5cf0c8

Browse files
committed
Iron out the remaining issues with exception handling
1 parent 9f47f92 commit e5cf0c8

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

app/ruby_engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def run(source)
1212
def run_with_writer(source, writer, &block)
1313
@writer = writer
1414
@dots = 0
15-
run(source, &block)
15+
run(source, &block).__await__
1616
end
1717

1818
# Display a message while a block is being executed

app/ruby_engine/opal_webworker.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def initialize(version)
8181
super()
8282
end
8383

84+
attr_writer :writer
85+
8486
def upload_opal_await(engine)
8587
engine.loading("downloading ruby") { upload_script_await("opal") }
8688
engine.loading("downloading ruby extras") { upload_script_await("opal/full") }
@@ -93,7 +95,7 @@ def upload_script_await(name)
9395
end
9496

9597
def eval_ruby_await(ruby)
96-
send_await(:eval, "var out = eval(Opal.compile(#{ruby.to_json})); out === Opal.nil ? '' : out.$to_s();")
98+
send_await(:eval, "var out = eval(Opal.compile(#{ruby.to_json})); (out == null || out === Opal.nil) ? '' : out.$to_s();")
9799
end
98100

99101
def prepare_stdio_await
@@ -126,7 +128,7 @@ def prepare_error_handler_await
126128
end
127129

128130
def handle_error(err)
129-
# @writer.log_error err
131+
@writer.log_error err
130132
end
131133
end
132134

@@ -144,6 +146,7 @@ def engine_id
144146

145147
def run(source)
146148
worker = OpalWorker.new(@version)
149+
worker.writer = @writer
147150

148151
worker.upload_opal_await(self)
149152

@@ -152,12 +155,14 @@ def run(source)
152155
worker.prepare_stdio_await
153156
end
154157

155-
yield(worker.eval_ruby_await(source))
158+
retval = worker.eval_ruby_await(source)
156159

157160
# Ensure the errors arrive
158161
worker.send_await(:nop)
159162

160163
worker.close
164+
165+
yield(retval)
161166
end
162167
end
163168
end

app/try_ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def eval_code(source)
392392
end
393393

394394
def show_result(retval)
395-
print_to_output(retval) if @output_buffer.length == 0 && !retval.empty?
395+
print_to_output(retval) if @output_buffer.length == 0 && retval && !retval.empty?
396396

397397
# Do not check the answer if there is no regexp matcher
398398
if @current_item && @current_item.answer

0 commit comments

Comments
 (0)