From 0654bcd4f809e97bca4a099fa78db9990fa5a4ae Mon Sep 17 00:00:00 2001 From: Satoshi Tagomori Date: Wed, 26 Nov 2025 00:21:40 +0900 Subject: Box: Add a test to drop the reference to a box --- test/ruby/test_box.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/ruby/test_box.rb b/test/ruby/test_box.rb index 9b87f9b5bc..7023ecab16 100644 --- a/test/ruby/test_box.rb +++ b/test/ruby/test_box.rb @@ -810,4 +810,21 @@ class TestBox < Test::Unit::TestCase assert_equal expected, 1 end; end + + def test_mark_box_object_referred_only_from_binding + assert_separately([ENV_ENABLE_BOX], __FILE__, __LINE__, "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true) + begin; + box = Ruby::Box.new + box.eval('class Integer; def +(*)=42; end') + b = box.eval('binding') + box = nil # remove direct reference to the box + + assert_equal 42, b.eval('1+2') + + GC.stress = true + GC.start + + assert_equal 42, b.eval('1+2') + end; + end end -- cgit v1.2.3