diff --git a/lib/v8.rb b/lib/v8.rb index cff7787..39e7328 100644 --- a/lib/v8.rb +++ b/lib/v8.rb @@ -1,6 +1,7 @@ require "v8/version" require 'v8/init' +require 'v8/util/weakcell' require 'v8/conversion/fundamental' require 'v8/conversion/indentity' require 'v8/conversion/primitive' @@ -19,5 +20,4 @@ require 'v8/access/indices' require 'v8/access' require 'v8/context' require 'v8/object' -require 'v8/array' -require 'v8/util/weakcell' \ No newline at end of file +require 'v8/array' \ No newline at end of file diff --git a/lib/v8/conversion/method.rb b/lib/v8/conversion/method.rb index f2ef39e..e41ab5c 100644 --- a/lib/v8/conversion/method.rb +++ b/lib/v8/conversion/method.rb @@ -3,7 +3,7 @@ class V8::Conversion include V8::Conversion::Proc def to_v8 - (@@method_cache[self] ||= v8_template).GetFunction() + (@@method_cache[self] ||= to_v8_template).GetFunction() end diff --git a/lib/v8/conversion/proc.rb b/lib/v8/conversion/proc.rb index 9946b38..cdc6993 100644 --- a/lib/v8/conversion/proc.rb +++ b/lib/v8/conversion/proc.rb @@ -1,17 +1,17 @@ class V8::Conversion module Proc + include V8::Util::Weakcell def to_v8 - return v8_template.GetFunction() + return to_v8_template.GetFunction() end - def v8_template - unless @v8_template && @v8_template.weakref_alive? + def to_v8_template + weakcell(:v8_template) do template = V8::C::FunctionTemplate::New() template.SetCallHandler(InvocationHandler.new, V8::C::External::New(self)) - @v8_template = WeakRef.new(template) + template end - return @v8_template.__getobj__ end class InvocationHandler