mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
![Charles Lowell](/assets/img/avatar_default.png)
It appears that `Ref::WeakValueMap` is not 100% correct. There are cases where entries are temporarily corrupted; probably while attached finalizers run. This is a slight decrease in flexibility in that strings and primitives cannot maintain referential integrity when passed by reference to v8, but the default is to pass them by value anyway, and it greatly reduces the number of object_ids that the idmap sees and therefore reduces the chances of a recycled object id causing a bad lookup. While this is not a perfect fix, it does make a collision very unlikely, and it prevents the crashes being seen in #169 If this pops up again, we'll have to look at getting a perfectly reliable weakmap implementation.
31 lines
No EOL
735 B
Ruby
31 lines
No EOL
735 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)
|
|
return super(ruby_object) if ruby_object.is_a?(String) || ruby_object.is_a?(Primitive)
|
|
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 |