handle_memspec.rb 875 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. require 'spec_helper'
  2. describe V8::C::Handle do
  3. include V8::MemSpec
  4. context "A JavaScript Object reflected into Ruby" do
  5. before do
  6. @weakref_callback = WeakrefCallback.new
  7. end
  8. it "has a strong reference from the ruby side, which is not released until the Ruby reference goes away" do
  9. handle = c::Handle::New(object = c::Object::New())
  10. handle.MakeWeak(nil, @weakref_callback)
  11. ruby_gc do
  12. v8_gc
  13. @weakref_callback.should_not have_been_invoked
  14. handle.should_not be_dead
  15. end
  16. ruby_gc do
  17. object = nil
  18. v8_gc
  19. @weakref_callback.should have_been_invoked
  20. handle.should be_dead
  21. end
  22. end
  23. private
  24. class WeakrefCallback
  25. def call(value, parameters)
  26. @invoked = true
  27. end
  28. def has_been_invoked?
  29. @invoked
  30. end
  31. end
  32. end
  33. end