1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/lib/v8/conversion/indentity.rb
Charles Lowell 1a93c34b07 remove WeakRef from the equation
It turns out that the Ruby stdlib WeakRef class is
completely broken. 

http://bugs.ruby-lang.org/issues/4168

While it is fixed in trunk, it is not useable, so
as a temporary measure, use the `ref` gem as a 
dependency. It appears to be both faster and more
correct.
2012-06-20 04:35:40 -05:00

30 lines
No EOL
642 B
Ruby

require 'ref'
class V8::Conversion
module Identity
def to_ruby(v8_object)
if v8_object.class <= V8::C::Object
v8_idmap[v8_object.GetIdentityHash()] || super(v8_object)
else
super(v8_object)
end
end
def to_v8(ruby_object)
rb_idmap[ruby_object.object_id] || super(ruby_object)
end
def equate(ruby_object, v8_object)
v8_idmap[v8_object.GetIdentityHash()] = ruby_object
rb_idmap[ruby_object.object_id] = v8_object
end
def v8_idmap
@v8_idmap ||= Ref::WeakValueMap.new
end
def rb_idmap
@ruby_idmap ||= Ref::WeakValueMap.new
end
end
end