Skip to content

Commit

Permalink
Adapt ExecJS::GraalJSRuntime to foreign exception changes in TruffleRuby
Browse files Browse the repository at this point in the history
* Foreign exceptions are no longer translated to ::RuntimeError but
  remain as foreign exceptions and are given the class Polyglot::ForeignException.
* The backtrace can be nil, notably when throwing a JS string.
  • Loading branch information
eregon committed Mar 2, 2022
1 parent e6db400 commit 4cb60fa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/execjs/graaljs_runtime.rb
Original file line number Diff line number Diff line change
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 4cb60fa

Please sign in to comment.