Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #5552 from lest/patch-3

deprecate Proc#bind that can cause symbol memory leak
  • Loading branch information...
commit fad83d8cbbbd0862a758a1c09c7dcc6f74a25d60 2 parents 6424922 + 9c857db
@tenderlove tenderlove authored
View
3  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}"
View
2  activesupport/lib/active_support/rescuable.rb
@@ -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
View
12 activesupport/test/core_ext/proc_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.