From 928d89c77b81b7ef560c0f40b0119dfcd31f3605 Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 21 May 2015 08:45:57 +0000 Subject: * proc.c: fix issues caused by binding created from Method#to_proc. [Bug #11163] * vm.c (vm_cref_new_toplevel): export as rb_vm_cref_new_toplevel(). * test/ruby/test_method.rb: add some assersions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_method.rb | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 960c4270d1..d1cde99ab4 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -887,17 +887,25 @@ class TestMethod < Test::Unit::TestCase end end + class C + D = "Const_D" + def foo + a = b = c = 12345 + end + end + def test_to_proc_binding bug11012 = '[ruby-core:68673] [Bug #11012]' - class << (obj = Object.new) - src = 1000.times.map {|i|"v#{i} = nil"}.join("\n") - eval("def foo()\n""#{src}\n""end") - end - b = obj.method(:foo).to_proc.binding - b.local_variables.each_with_index {|n, i| - b.local_variable_set(n, i) - } - assert_equal([998, 999], %w[v998 v999].map {|n| b.local_variable_get(n)}, bug11012) + b = C.new.method(:foo).to_proc.binding + assert_equal([], b.local_variables) + assert_equal("Const_D", b.eval("D")) # Check CREF + + assert_raise(NameError){ b.local_variable_get(:foo) } + assert_equal(123, b.local_variable_set(:foo, 123)) + assert_equal(123, b.local_variable_get(:foo)) + assert_equal(456, b.local_variable_set(:bar, 456)) + assert_equal(123, b.local_variable_get(:foo)) + assert_equal(456, b.local_variable_get(:bar)) end end -- cgit v1.2.3