lib/bindex/rubinius.rb in bindex-0.1.0 vs lib/bindex/rubinius.rb in bindex-0.1.1

- old
+ new

@@ -17,25 +17,32 @@ end end # Filters internal Rubinius locations. # - # The reason for this is that some methods, like ::Kernel.raise, are - # implemented in Ruby for Rubinius. Therefore, we will get a binding for - # them as well. + # There are a couple of reasons why we wanna filter out the locations. # - # To align the current_bindings implementation with the CRuby one, where - # the first binding will usually be binding of caller, we can use this - # object to clean bindings for internal Rubinius methods. + # * ::Kernel.raise, is implemented in Ruby for Rubinius. We don't wanna + # have the frame for it to align with the CRuby and JRuby implementations. + # + # * For internal methods location variables can be nil. We can't create a + # bindings for them. + # + # * Bindings from the current file are considered internal and ignored. + # + # We do that all that so we can align the bindings with the backtraces + # entries. class InternalLocationFilter def initialize(locations) @locations = locations end def filter @locations.reject do |location| - location.file.start_with?('kernel/') || location.file == __FILE__ + location.file.start_with?('kernel/delta/kernel.rb') || + location.file == __FILE__ || + location.variables.nil? end end end end end @@ -48,9 +55,12 @@ ::Rubinius.singleton_class.class_eval do raise_exception = instance_method(:raise_exception) define_method(:raise_exception) do |exc| - exc.instance_variable_set(:@bindings, Bindex::Rubinius.current_bindings) + if exc.bindings.empty? + exc.instance_variable_set(:@bindings, Bindex::Rubinius.current_bindings) + end + raise_exception.bind(self).call(exc) end end