mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
42 lines
No EOL
992 B
Ruby
42 lines
No EOL
992 B
Ruby
|
|
require 'spec_helper'
|
|
|
|
describe "Memory:" do
|
|
include V8::ExtSpec
|
|
context "A JavaScript Object reflected into Ruby" do
|
|
|
|
before do
|
|
@weakref_callback = WeakrefCallback.new
|
|
end
|
|
|
|
it "has a strong reference from the ruby side, which is not released until the Ruby reference goes away" do
|
|
handle = c::Handle::New(object = c::Object::New())
|
|
handle.MakeWeak(nil, @weakref_callback)
|
|
ruby_gc do
|
|
v8_gc
|
|
@weakref_callback.should_not have_been_invoked
|
|
handle.should_not be_dead
|
|
end
|
|
ruby_gc do
|
|
object = nil
|
|
v8_gc
|
|
@weakref_callback.should have_been_invoked
|
|
handle.should be_dead
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
class WeakrefCallback
|
|
|
|
def call(value, parameters)
|
|
@invoked = true
|
|
end
|
|
|
|
def has_been_invoked?
|
|
@invoked
|
|
end
|
|
end
|
|
end
|
|
#These don't work in 1.8.7. Can't determine why not. I'll probably have to come back to this.
|
|
end if RUBY_VERSION >= '1.9.2' |