1
0
Fork 0
mirror of https://github.com/rails/execjs synced 2023-03-27 23:21:20 -04:00

Adapt ExecJS::GraalJSRuntime to foreign exception changes in TruffleRuby

* 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.
This commit is contained in:
Benoit Daloze 2022-03-02 17:14:12 +01:00
parent e6db400607
commit 4cb60fa266

View file

@ -46,16 +46,18 @@ module ExecJS
private private
ForeignException = defined?(Polyglot::ForeignException) ? Polyglot::ForeignException : ::RuntimeError
def translate def translate
convert_js_to_ruby yield convert_js_to_ruby yield
rescue ::RuntimeError => e rescue ForeignException => e
if e.message.start_with?('SyntaxError:') if e.message.start_with?('SyntaxError:')
error_class = ExecJS::RuntimeError error_class = ExecJS::RuntimeError
else else
error_class = ExecJS::ProgramError error_class = ExecJS::ProgramError
end 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 raise error_class, e.message, backtrace
end end