mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 12:34:21 +00:00
Box: Add a test to drop the reference to a box
This commit is contained in:
parent
8bf333a199
commit
0654bcd4f8
Notes:
git
2025-11-26 01:11:19 +00:00
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user