Sha256: 1a2d0d6c12c9df63fe4a2abf5efabf3b558ffd8a7ac17115c7d2feffa9b3f7e1

Contents?: true

Size: 628 Bytes

Versions: 15

Compression:

Stored size: 628 Bytes

Contents

module V8
  module Util
    module Weakcell
      def weakcell(name, &block)
        unless storage = instance_variable_get("@#{name}")
          storage = instance_variable_set("@#{name}", Storage.new)
        end
        storage.access(&block)
      end
      class Storage
        def access(&block)
          if @ref
            @ref.object || populate(block)
          else
            populate(block)
          end
        end

        private

        def populate(block)
          occupant = block.call()
          @ref = Ref::WeakReference.new(occupant)
          return occupant
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
therubyracer-0.11.0beta7-x86_64-linux lib/v8/util/weakcell.rb
therubyracer-0.11.0beta7-x86-linux lib/v8/util/weakcell.rb
therubyracer-0.11.0beta7-x86_64-darwin-10 lib/v8/util/weakcell.rb
therubyracer-0.11.0beta7 lib/v8/util/weakcell.rb
therubyracer-0.11.0beta6-x86-linux lib/v8/util/weakcell.rb
therubyracer-0.11.0beta6-x86_64-linux lib/v8/util/weakcell.rb
therubyracer-0.11.0beta6 lib/v8/util/weakcell.rb
therubyracer-0.11.0beta5-x86-linux lib/v8/util/weakcell.rb
therubyracer-0.11.0beta5 lib/v8/util/weakcell.rb
therubyracer-0.11.0beta5-x86_64-linux lib/v8/util/weakcell.rb
therubyracer-0.11.0beta4 lib/v8/util/weakcell.rb
therubyracer-0.11.0beta3 lib/v8/util/weakcell.rb
therubyracer-0.11.0beta2-x86_64-linux lib/v8/util/weakcell.rb
therubyracer-0.11.0beta2 lib/v8/util/weakcell.rb
therubyracer-0.11.0beta1 lib/v8/util/weakcell.rb