forked from rubyjs/therubyracer
/
proxies_memspec.rb
48 lines (42 loc) · 1.37 KB
/
proxies_memspec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'spec_helper'
describe V8::Portal::Proxies do
include V8::MemSpec
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
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()
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
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
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
subject.should be_empty
end
end
end