mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
87efe139e9
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.
29 lines
No EOL
592 B
Ruby
29 lines
No EOL
592 B
Ruby
class V8::Conversion
|
|
module Method
|
|
include V8::Conversion::Code
|
|
|
|
def to_v8
|
|
template = @@method_cache[self] ||= to_template
|
|
template.GetFunction()
|
|
end
|
|
|
|
class MethodCache
|
|
def initialize
|
|
@map = {}
|
|
end
|
|
|
|
def [](method)
|
|
weakref = @map[method.to_s]
|
|
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
|
|
end
|
|
|
|
@@method_cache = MethodCache.new
|
|
end
|
|
end |