From 4cb60fa26649a917b40eeae29e8139e2dd269ab2 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 2 Mar 2022 17:14:12 +0100 Subject: [PATCH] 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. --- lib/execjs/graaljs_runtime.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/execjs/graaljs_runtime.rb b/lib/execjs/graaljs_runtime.rb index 01d652d..d3cab2a 100644 --- a/lib/execjs/graaljs_runtime.rb +++ b/lib/execjs/graaljs_runtime.rb @@ -46,16 +46,18 @@ module ExecJS 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