Skip to content

Commit

Permalink
Merge pull request rails#5552 from lest/patch-3
Browse files Browse the repository at this point in the history
deprecate Proc#bind that can cause symbol memory leak
  • Loading branch information
tenderlove committed Mar 22, 2012
2 parents 6424922 + 9c857db commit fad83d8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions activesupport/lib/active_support/core_ext/proc.rb
@@ -1,7 +1,10 @@
require "active_support/core_ext/kernel/singleton_class"
require "active_support/deprecation"

class Proc #:nodoc:
def bind(object)
ActiveSupport::Deprecation.warn 'Proc#bind is deprecated and will be removed in future versions', caller

block, time = self, Time.now
object.class_eval do
method_name = "__bind_#{time.to_i}_#{time.usec}"
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/rescuable.rb
Expand Up @@ -108,7 +108,7 @@ def handler_for_rescue(exception)
when Symbol
method(rescuer)
when Proc
rescuer.bind(self)
Proc.new { |*args| instance_exec(*args, &rescuer) }
end
end
end
Expand Down
12 changes: 7 additions & 5 deletions activesupport/test/core_ext/proc_test.rb
Expand Up @@ -3,10 +3,12 @@

class ProcTests < ActiveSupport::TestCase
def test_bind_returns_method_with_changed_self
block = Proc.new { self }
assert_equal self, block.call
bound_block = block.bind("hello")
assert_not_equal block, bound_block
assert_equal "hello", bound_block.call
assert_deprecated do
block = Proc.new { self }
assert_equal self, block.call
bound_block = block.bind("hello")
assert_not_equal block, bound_block
assert_equal "hello", bound_block.call
end
end
end

0 comments on commit fad83d8

Please sign in to comment.