Add a frozenness check to Enumerator#initialize.

* enumerator.c (enumerator_init): Add a frozenness check to
  prevent a frozen Enumerator object from being reinitialized with
  a different enumerable object.  This is the least we should do,
  and more fixes will follow. [Fixes GH-368] Patch by Kenichi
  Kamiya.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2013-07-29 12:06:39 +00:00
parent ef01a5a649
commit 8cb0de91c4
3 changed files with 19 additions and 0 deletions

View file

@ -67,6 +67,16 @@ class TestEnumerator < Test::Unit::TestCase
assert_match 'Enumerator.new without a block is deprecated', err
assert_equal([1, 2, 3], Enumerator.new { |y| i = 0; loop { y << (i += 1) } }.take(3))
assert_raise(ArgumentError) { Enumerator.new }
enum = @obj.to_enum
assert_raise(NoMethodError) { enum.each {} }
enum.freeze
assert_raise(RuntimeError) {
capture_io do
# warning: Enumerator.new without a block is deprecated; use Object#to_enum
enum.__send__(:initialize, @obj, :foo)
end
}
end
def test_initialize_copy