Sha256: 5243f4f0ebca8bffcc74ac7dbefcb5bcf87a2c9a1678ac3a720292bce66a09bf

Contents?: true

Size: 1.76 KB

Versions: 77

Compression:

Stored size: 1.76 KB

Contents

module V8
  class Portal
    class Templates

      attr_reader :portal

      def initialize(portal)
        @portal = portal
        @constructors = {}
        @methods = {}
        @procs = {}
        @releases = {}
      end

      def to_constructor(ruby_class)
        class_id = ruby_class.object_id
        if constructor = @constructors[class_id]
          return constructor
        else
          constructor = @constructors[class_id] = ConstructorAdapter.new(self, class_id)
          ObjectSpace.define_finalizer(ruby_class, release(@constructors, class_id))
          return constructor
        end
      end

      def to_function(code)
        case code
        when Method, UnboundMethod
          if fn = @methods[code.to_s]
            return fn
          else
            function = @methods[code.to_s] = FunctionAdapter.new(@portal, code)
            #TODO: test this weak behavior
            function.template.MakeWeak(0, release(@methods, code.to_s))
            return function
          end
        else
          if fn = @procs[code]
            return fn
          else
            function = @procs[code] = FunctionAdapter.new(@portal, code)
            #TODO: test this weak behavior
            function.template.MakeWeak(0, release(@procs, code))
            return function
          end
        end
      end

      def proxies
        @portal.proxies
      end

      def release(refs, id)
        release = Release.new(@releases, refs, id)
        @releases[release] = true
        return release
      end

      class Release
        def initialize(releases, refs, id)
          @releases, @refs, @id = releases, refs, id
        end

        def call(*args)
          @refs.delete(@id)
          @releases.delete(self)
        end

      end
    end
  end
end

Version data entries

77 entries across 77 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.7.4 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.7.3 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.7.2 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.7.1 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.7.0 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.6.9 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.6.8 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.6.7 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.6.6 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.6.5 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.6.4 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.6.3 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.6.2 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.6.1 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.6.0 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.5.17 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.5.16 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.5.15 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb
classiccms-0.5.14 vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal/templates.rb