summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatoshi Tagomori <s-tagomori@sakura.ad.jp>2025-11-26 00:21:40 +0900
committerSatoshi Tagomori <tagomoris@gmail.com>2025-11-26 10:10:47 +0900
commit0654bcd4f809e97bca4a099fa78db9990fa5a4ae (patch)
tree0a9533ba97a0f58f784007eb272b18b4d65e9912
parent8bf333a199b5c099c2e3d3efeb2ba06f265db324 (diff)
Box: Add a test to drop the reference to a box
-rw-r--r--test/ruby/test_box.rb17
1 files changed, 17 insertions, 0 deletions
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