class Java::OrgMozillaJavascript::Context

Constants

CACHE

Public Instance Methods

cache(key) { || ... } click to toggle source

Support for caching JS data per context. e.g. to get === comparison's working …

NOTE: the cache only works correctly for keys following Java identity !

(implementing #equals & #hashCode e.g. RubyStrings will work ...)
# File lib/rhino/rhino_ext.rb, line 305
def cache(key)
  return yield if (cache = CACHE[self]) == false
  cache = reset_cache! unless cache
  fetch(key, cache) || store(key, yield, cache)
end
disable_cache!() click to toggle source
# File lib/rhino/rhino_ext.rb, line 295
def disable_cache!
  CACHE[self] = false
end
enable_cache!() click to toggle source
# File lib/rhino/rhino_ext.rb, line 291
def enable_cache!
  CACHE[self] = nil unless CACHE[self]
end
reset_cache!() click to toggle source
# File lib/rhino/rhino_ext.rb, line 287
def reset_cache!
  CACHE[self] = java.util.WeakHashMap.new
end

Private Instance Methods

fetch(key, cache = CACHE[self]) click to toggle source
# File lib/rhino/rhino_ext.rb, line 313
def fetch(key, cache = CACHE[self])
  ref = cache.get(key)
  ref ? ref.get : nil
end
store(key, value, cache = CACHE[self]) click to toggle source
# File lib/rhino/rhino_ext.rb, line 318
def store(key, value, cache = CACHE[self])
  cache.put(key, java.lang.ref.WeakReference.new(value))
  value
end