proxies_memspec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. require 'spec_helper'
  2. describe V8::Portal::Proxies do
  3. include V8::MemSpec
  4. context "A Ruby object embedded into JavaScript" do
  5. it "holds a hard reference to any ruby object which is linked to a javascript proxy" do
  6. subject.register_javascript_proxy c::Object::New(), :for => Object.new
  7. ruby_gc do
  8. subject.should_not be_empty
  9. end
  10. end
  11. it "releases the hard reference if its corresponding javascript object has been garbage collected" do
  12. ruby_gc do
  13. rb_object = Object.new
  14. js_proxy = c::Object::New()
  15. subject.should be_empty
  16. subject.register_javascript_proxy js_proxy, :for => rb_object
  17. rb_object = nil
  18. subject.should_not be_empty
  19. v8_gc()
  20. end
  21. subject.should be_empty
  22. end
  23. end
  24. context "A JavaScript object embedded into Ruby" do
  25. it "holds a hard reference to any JavaScript object which is linked to a Ruby proxy" do
  26. proxy = Object.new
  27. subject.register_ruby_proxy proxy, :for => c::Object::New()
  28. ruby_gc do
  29. subject.should_not be_empty
  30. end
  31. end
  32. it "clears any strong references to the JavaScript object when it's Ruby proxy is garbage collected" do
  33. subject.register_ruby_proxy Object.new, :for => c::Object::New()
  34. subject.should_not be_empty
  35. ruby_gc do
  36. v8_gc
  37. GC.start
  38. v8_gc
  39. end
  40. subject.should be_empty
  41. end
  42. end
  43. end