Skip to content

Commit 0654bcd

Browse files
committed
Box: Add a test to drop the reference to a box
1 parent 8bf333a commit 0654bcd

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

test/ruby/test_box.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,4 +810,21 @@ def test_loading_extension_libs_in_main_box
810810
assert_equal expected, 1
811811
end;
812812
end
813+
814+
def test_mark_box_object_referred_only_from_binding
815+
assert_separately([ENV_ENABLE_BOX], __FILE__, __LINE__, "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true)
816+
begin;
817+
box = Ruby::Box.new
818+
box.eval('class Integer; def +(*)=42; end')
819+
b = box.eval('binding')
820+
box = nil # remove direct reference to the box
821+
822+
assert_equal 42, b.eval('1+2')
823+
824+
GC.stress = true
825+
GC.start
826+
827+
assert_equal 42, b.eval('1+2')
828+
end;
829+
end
813830
end

0 commit comments

Comments
 (0)