Permalink
Browse files

refactor memspecs to just test that proxies were removed.

  • Loading branch information...
1 parent 0740bd2 commit b0084c4c0c5f5fe1b103356786df871321072f46 @cowboyd cowboyd committed May 24, 2011
Showing with 26 additions and 55 deletions.
  1. +11 −0 lib/v8/portal/proxies.rb
  2. +1 −3 specmem/object_memspec.rb
  3. +14 −52 specmem/proxies_memspec.rb
View
@@ -73,6 +73,17 @@ def rb_proxy_2_js_object(proxy)
@rb_proxies_rb2js[proxy.object_id]
end
+ def js_empty?
+ @js_proxies_rb2js.empty? && @js_proxies_js2rb.empty?
+ end
+
+ def rb_empty?
+ @rb_proxies_rb2js.empty? && @rb_proxies_js2rb.empty?
+ end
+
+ def empty?
+ js_empty? && rb_empty?
+ end
DoubleProxyError = Class.new(StandardError)
class ClearJSProxy
@@ -5,10 +5,8 @@
include V8::MemSpec
it "will return a new peer and not barf if the old peer has been garbage collected" do
v8_eval('var o = {foo: "bar"}')
- o = v8_eval('o')
- old_id = o.object_id
+ old_id = v8_eval('o').object_id
ruby_gc do
- o = nil
v8_eval('o').Get(c::String::New("foo")).Utf8Value().should == "bar"
v8_eval('o').object_id.should_not be(old_id)
end
View
@@ -5,82 +5,44 @@
context "A Ruby object embedded into JavaScript" do
it "holds a hard reference to any ruby object which is linked to a javascript proxy" do
- rb_object = Object.new
- check_not_finalized(rb_object)
- subject.register_javascript_proxy c::Object::New(), :for => rb_object
- rb_object = nil
+ subject.register_javascript_proxy c::Object::New(), :for => Object.new
+ ruby_gc do
+ subject.should_not be_empty
+ end
end
it "releases the hard reference if its corresponding javascript object has been garbage collected" do
rb_object = Object.new
js_proxy = c::Object::New()
- check_finalized(rb_object)
subject.register_javascript_proxy js_proxy, :for => rb_object
rb_object = nil
ruby_gc do
+ subject.should_not be_empty
v8_gc()
end
+ subject.should be_empty
end
end
context "A JavaScript object embedded into Ruby" do
it "holds a hard reference to any JavaScript object which is linked to a Ruby proxy" do
- js_object = c::Object::New()
- check_not_finalized(js_object)
- subject.register_ruby_proxy Object.new, :for => js_object
- js_object = nil
+ proxy = Object.new
+ subject.register_ruby_proxy proxy, :for => c::Object::New()
+ ruby_gc do
+ subject.should_not be_empty
+ end
end
it "clears any strong references to the JavaScript object when it's Ruby proxy is garbage collected" do
- js_object = c::Object::New()
- rb_proxy = Object.new
- subject.register_ruby_proxy rb_proxy, :for => js_object
- check_finalized(js_object)
- js_object = rb_proxy = nil
+ subject.register_ruby_proxy Object.new, :for => c::Object::New()
+ subject.should_not be_empty
ruby_gc do
v8_gc
GC.start
v8_gc
end
- end
- end
- private
-
- def finalize(object_id)
- @finalized ||= {}
- @finalized[object_id] = true
- end
-
- def check_finalized(object)
- @finalized ||= {}
- ObjectSpace.define_finalizer(object, method(:finalize))
- id_to_check = object.object_id
- object = nil
- afterwards do
- @finalized[id_to_check].should be_true
- end
- end
-
- def check_not_finalized(object)
- @finalized ||= {}
- ObjectSpace.define_finalizer(object, method(:finalize))
- id_to_check = object.object_id
- object = nil
- afterwards do
- @finalized[id_to_check].should be_false
+ subject.should be_empty
end
end
- def afterwards(&block)
- @after ||= []
- @after << block if block_given?
- end
-
- after do
- ruby_gc do
- @after.each do |proc|
- proc.call
- end if @after
- end
- end
end

0 comments on commit b0084c4

Please sign in to comment.