From 1ce52b3501062d7902193b3cf6b99c06ecd18b28 Mon Sep 17 00:00:00 2001 From: kares Date: Mon, 9 Jan 2023 18:51:29 +0100 Subject: [PATCH 1/2] [jruby] avoid Thread#to_java internals JRuby.runtime.current_context is more future proof --- lib/method_source/source_location.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/method_source/source_location.rb b/lib/method_source/source_location.rb index 7629869..6aa6842 100644 --- a/lib/method_source/source_location.rb +++ b/lib/method_source/source_location.rb @@ -13,12 +13,12 @@ module MethodExtensions include ReeSourceLocation elsif defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ - require 'java' + require 'jruby' # JRuby version source_location hack # @return [Array] A two element array containing the source location of the method def source_location - to_java.source_location(Thread.current.to_java.getContext()) + to_java.source_location(JRuby.runtime.current_context) end else @@ -83,12 +83,12 @@ module UnboundMethodExtensions include ReeSourceLocation elsif defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ - require 'java' + require 'jruby' # JRuby version source_location hack # @return [Array] A two element array containing the source location of the method def source_location - to_java.source_location(Thread.current.to_java.getContext()) + to_java.source_location(JRuby.runtime.current_context) end else From 78d0b6e32f1131046102aeadb4c1903cabd4c4c6 Mon Sep 17 00:00:00 2001 From: kares Date: Mon, 9 Jan 2023 18:56:02 +0100 Subject: [PATCH 2/2] [jruby] refactor - simply calling native impls the Method/UnboundMethod#source_location replacements on JRuby made no sense - they simply delegated to what was already available. this might date back to JRuby 1.7 where these hacks would provide source_location for Ruby 1.8(.7) mode --- lib/method_source/source_location.rb | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/lib/method_source/source_location.rb b/lib/method_source/source_location.rb index 6aa6842..3d3686e 100644 --- a/lib/method_source/source_location.rb +++ b/lib/method_source/source_location.rb @@ -13,16 +13,9 @@ module MethodExtensions include ReeSourceLocation elsif defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ - require 'jruby' - - # JRuby version source_location hack - # @return [Array] A two element array containing the source location of the method - def source_location - to_java.source_location(JRuby.runtime.current_context) - end + # noop - source_location provided natively else - def trace_func(event, file, line, id, binding, classname) return unless event == 'call' set_trace_func nil @@ -83,17 +76,9 @@ module UnboundMethodExtensions include ReeSourceLocation elsif defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ - require 'jruby' - - # JRuby version source_location hack - # @return [Array] A two element array containing the source location of the method - def source_location - to_java.source_location(JRuby.runtime.current_context) - end - + # noop - source_location provided natively else - # Return the source location of an instance method for Ruby 1.8. # @return [Array] A two element array. First element is the # file, second element is the line in the file where the