From 97e47b3d6c2f47b57e2db388059f9ed505a072fb Mon Sep 17 00:00:00 2001 From: Sean Mann Date: Wed, 21 Sep 2022 15:59:29 -0600 Subject: [PATCH 1/2] pass exception text into javascript --- ext/mini_racer_extension/mini_racer_extension.cc | 3 ++- test/mini_racer_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ext/mini_racer_extension/mini_racer_extension.cc b/ext/mini_racer_extension/mini_racer_extension.cc index acb8fb8e..72f17761 100644 --- a/ext/mini_racer_extension/mini_racer_extension.cc +++ b/ext/mini_racer_extension/mini_racer_extension.cc @@ -1281,7 +1281,8 @@ gvl_ruby_callback(void* data) { if(callback_data.failed) { rb_iv_set(parent, "@current_exception", result); - args->GetIsolate()->ThrowException(String::NewFromUtf8Literal(args->GetIsolate(), "Ruby exception")); + VALUE message = rb_funcall(result, rb_intern("message"), 0); + args->GetIsolate()->ThrowException(String::NewFromUtf8(args->GetIsolate(), RSTRING_PTR(message), NewStringType::kNormal, RSTRING_LENINT(message)).ToLocalChecked()); } else { HandleScope scope(args->GetIsolate()); diff --git a/test/mini_racer_test.rb b/test/mini_racer_test.rb index 0f698eee..1e88b391 100644 --- a/test/mini_racer_test.rb +++ b/test/mini_racer_test.rb @@ -872,6 +872,14 @@ def test_pipe_leak end end + def test_capture_ruby_exception_message + context = MiniRacer::Context.new() + error_message = "Actual Error Message" + context.attach("a", proc{|a| raise error_message}) + + assert_equal error_message, context.eval("try { a(); \'no throw\' } catch (e) { e }") + end + def test_symbol_support context = MiniRacer::Context.new() assert_equal :foo, context.eval("Symbol('foo')") From fd3c62abfe7c9782dfd242c57cca8033b914a196 Mon Sep 17 00:00:00 2001 From: Sean Mann Date: Wed, 21 Sep 2022 16:00:21 -0600 Subject: [PATCH 2/2] rem debug --- test/mini_racer_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mini_racer_test.rb b/test/mini_racer_test.rb index 1e88b391..02efa6ba 100644 --- a/test/mini_racer_test.rb +++ b/test/mini_racer_test.rb @@ -877,7 +877,7 @@ def test_capture_ruby_exception_message error_message = "Actual Error Message" context.attach("a", proc{|a| raise error_message}) - assert_equal error_message, context.eval("try { a(); \'no throw\' } catch (e) { e }") + assert_equal error_message, context.eval("try { a(); } catch (e) { e }") end def test_symbol_support