Class: Java::OrgMozillaJavascript::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/rhino/rhino_ext.rb

Constant Summary collapse

CACHE =
java.util.WeakHashMap.new

Instance Method Summary collapse

Instance Method Details

#cache(key) ⇒ Object

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 ...)


249
250
251
252
253
# File 'lib/rhino/rhino_ext.rb', line 249

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!Object



239
240
241
# File 'lib/rhino/rhino_ext.rb', line 239

def disable_cache!
  CACHE[self] = false
end

#enable_cache!Object



235
236
237
# File 'lib/rhino/rhino_ext.rb', line 235

def enable_cache!
  CACHE[self] = nil unless CACHE[self]
end

#reset_cache!Object



231
232
233
# File 'lib/rhino/rhino_ext.rb', line 231

def reset_cache!
  CACHE[self] = java.util.WeakHashMap.new
end