Skip to content

Commit 610e88a

Browse files
authored
Merge pull request #112 from eregon/foreign_exception_fixes
Adapt ExecJS::GraalJSRuntime to foreign exception changes in TruffleRuby
2 parents e6db400 + 4cb60fa commit 610e88a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/execjs/graaljs_runtime.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ def call(source, *args)
4646

4747
private
4848

49+
ForeignException = defined?(Polyglot::ForeignException) ? Polyglot::ForeignException : ::RuntimeError
50+
4951
def translate
5052
convert_js_to_ruby yield
51-
rescue ::RuntimeError => e
53+
rescue ForeignException => e
5254
if e.message.start_with?('SyntaxError:')
5355
error_class = ExecJS::RuntimeError
5456
else
5557
error_class = ExecJS::ProgramError
5658
end
5759

58-
backtrace = e.backtrace.map { |line| line.sub('(eval)', '(execjs)') }
60+
backtrace = (e.backtrace || []).map { |line| line.sub('(eval)', '(execjs)') }
5961
raise error_class, e.message, backtrace
6062
end
6163

0 commit comments

Comments
 (0)