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

Merge pull request #112 from eregon/foreign_exception_fixes

Adapt ExecJS::GraalJSRuntime to foreign exception changes in TruffleRuby
This commit is contained in:
Jean Boussier 2022-03-02 17:44:33 +01:00 committed by GitHub
commit 610e88a9ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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