2012-06-11 07:14:00 -05:00
|
|
|
class V8::Conversion
|
|
|
|
module Method
|
2012-06-16 04:54:31 -05:00
|
|
|
include V8::Conversion::Code
|
2012-06-11 07:14:00 -05:00
|
|
|
|
|
|
|
def to_v8
|
2012-06-16 04:54:31 -05:00
|
|
|
template = @@method_cache[self] ||= to_template
|
|
|
|
template.GetFunction()
|
2012-06-11 07:14:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class MethodCache
|
|
|
|
def initialize
|
|
|
|
@map = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](method)
|
|
|
|
weakref = @map[method.to_s]
|
2012-06-19 08:33:48 -05:00
|
|
|
weakref.__getobj__ if weakref
|
|
|
|
rescue WeakRef::RefError
|
|
|
|
nil #template was garbage collected, so no mapping
|
2012-06-11 07:14:00 -05:00
|
|
|
end
|
2012-06-19 08:33:48 -05:00
|
|
|
|
2012-06-11 07:14:00 -05:00
|
|
|
def []=(method, template)
|
|
|
|
@map[method.to_s] = WeakRef.new(template)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@@method_cache = MethodCache.new
|
|
|
|
end
|
|
|
|
end
|