Skip to content

Commit

Permalink
Merge pull request #112 from eregon/foreign_exception_fixes
Browse files Browse the repository at this point in the history
Adapt ExecJS::GraalJSRuntime to foreign exception changes in TruffleRuby
  • Loading branch information
byroot committed Mar 2, 2022
2 parents e6db400 + 4cb60fa commit 610e88a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/execjs/graaljs_runtime.rb
Expand Up @@ -46,16 +46,18 @@ def call(source, *args)

private

ForeignException = defined?(Polyglot::ForeignException) ? Polyglot::ForeignException : ::RuntimeError

def translate
convert_js_to_ruby yield
rescue ::RuntimeError => e
rescue ForeignException => e
if e.message.start_with?('SyntaxError:')
error_class = ExecJS::RuntimeError
else
error_class = ExecJS::ProgramError
end

backtrace = e.backtrace.map { |line| line.sub('(eval)', '(execjs)') }
backtrace = (e.backtrace || []).map { |line| line.sub('(eval)', '(execjs)') }
raise error_class, e.message, backtrace
end

Expand Down

0 comments on commit 610e88a

Please sign in to comment.