mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
1a93c34b07
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.
26 lines
No EOL
460 B
Ruby
26 lines
No EOL
460 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 = Ref::WeakValueMap.new
|
|
end
|
|
|
|
def [](method)
|
|
@map[method.to_s]
|
|
end
|
|
|
|
def []=(method, template)
|
|
@map[method.to_s] = template
|
|
end
|
|
end
|
|
|
|
@@method_cache = MethodCache.new
|
|
end
|
|
end |