mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	forwardable.rb: backtrace
* lib/forwardable.rb (_delegator_method): leave the backtrace untouched during accessor. forwardable.rb does not appear in the backtrace during delegated method because of tail-call optimization. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									8a8d3e2ed4
								
							
						
					
					
						commit
						e8700ab03d
					
				
					 3 changed files with 16 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,10 @@
 | 
			
		|||
Sat Jun 11 09:31:28 2016  Nobuyoshi Nakada  <nobu@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* lib/forwardable.rb (_delegator_method): leave the backtrace
 | 
			
		||||
	  untouched during accessor.  forwardable.rb does not appear in
 | 
			
		||||
	  the backtrace during delegated method because of tail-call
 | 
			
		||||
	  optimization.
 | 
			
		||||
 | 
			
		||||
Sat Jun 11 01:38:31 2016  Naohisa Goto  <ngotogenome@gmail.com>
 | 
			
		||||
 | 
			
		||||
	* include/ruby/defines.h (GCC_VERSION_SINCE): Fix logic error by
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -113,12 +113,9 @@ module Forwardable
 | 
			
		|||
  # Version of +forwardable.rb+
 | 
			
		||||
  FORWARDABLE_VERSION = "1.1.0"
 | 
			
		||||
 | 
			
		||||
  FILE_REGEXP = %r"#{Regexp.quote(__FILE__)}"
 | 
			
		||||
 | 
			
		||||
  @debug = nil
 | 
			
		||||
  class << self
 | 
			
		||||
    # If true, <tt>__FILE__</tt> will remain in the backtrace in the event an
 | 
			
		||||
    # Exception is raised.
 | 
			
		||||
    # ignored
 | 
			
		||||
    attr_accessor :debug
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -204,8 +201,6 @@ module Forwardable
 | 
			
		|||
        def #{ali}(*args, &block)
 | 
			
		||||
          begin
 | 
			
		||||
            #{accessor}
 | 
			
		||||
          ensure
 | 
			
		||||
            $@.delete_if {|s| ::Forwardable::FILE_REGEXP =~ s} if $@ and !::Forwardable::debug
 | 
			
		||||
          end.__send__ :#{method}, *args, &block
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -225,18 +225,21 @@ class TestForwardable < Test::Unit::TestCase
 | 
			
		|||
  class Foo
 | 
			
		||||
    extend Forwardable
 | 
			
		||||
 | 
			
		||||
    attr_accessor :bar
 | 
			
		||||
    def_delegator :bar, :baz
 | 
			
		||||
    def_delegator :caller, :itself, :c
 | 
			
		||||
 | 
			
		||||
    class Exception
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_backtrace_adjustment
 | 
			
		||||
    obj = Foo.new
 | 
			
		||||
    def (obj.bar = Object.new).baz
 | 
			
		||||
      foo
 | 
			
		||||
    end
 | 
			
		||||
    e = assert_raise(NameError) {
 | 
			
		||||
      Foo.new.baz
 | 
			
		||||
      obj.baz
 | 
			
		||||
    }
 | 
			
		||||
    assert_not_match(/\/forwardable\.rb/, e.backtrace[0])
 | 
			
		||||
    assert_not_match(/\/forwardable\.rb/, e.backtrace[0],
 | 
			
		||||
                     proc {RubyVM::InstructionSequence.of(obj.method(:baz)).disassemble})
 | 
			
		||||
    assert_equal(caller(0, 1)[0], Foo.new.c[0])
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue