1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

avoid potential race condition.

in between the weakref_alive? check and the actual
dereference via `__getobj__` the weak reference
could have been collected. It's better to just go
ahead and do the deref. If it throws an error,
then we know it didn't work.
This commit is contained in:
Charles Lowell 2012-06-19 08:33:48 -05:00
parent 9bc5c2b510
commit 87efe139e9
2 changed files with 7 additions and 6 deletions

View file

@ -28,9 +28,9 @@ class V8::Conversion
def [](object)
weakref = @map[to_key(object)]
if weakref && weakref.weakref_alive?
weakref.__getobj__
end
weakref.__getobj__ if weakref
rescue WeakRef::RefError
nil #peer was garbage collected, so no current mapping.
end
def equate(key_object, value_object)

View file

@ -14,10 +14,11 @@ class V8::Conversion
def [](method)
weakref = @map[method.to_s]
if weakref && weakref.weakref_alive?
weakref.__getobj__
end
weakref.__getobj__ if weakref
rescue WeakRef::RefError
nil #template was garbage collected, so no mapping
end
def []=(method, template)
@map[method.to_s] = WeakRef.new(template)
end