Module: Rhino

Defined in:
lib/rhino.rb,
lib/rhino/ruby.rb,
lib/rhino/error.rb,
lib/rhino/context.rb,
lib/rhino/version.rb,
lib/rhino/wormhole.rb,
lib/rhino/ruby/access.rb,
lib/rhino/deprecations.rb,
lib/rhino/ruby/default_access.rb,
lib/rhino/ruby/attribute_access.rb

Defined Under Namespace

Modules: JS, Ruby, To Classes: Context, ContextError, IOReader, JSError, RestrictableContextFactory, RunawayScriptError, ScriptTimeoutError

Constant Summary collapse

RubyObject =
Ruby::Object
RubyFunction =
Ruby::Function
RubyConstructor =
Ruby::Constructor
ContextFactory =

:nodoc: backward compatibility

JS::ContextFactory
VERSION =
"2.0.1"
@@implementation_version =
nil
@@stub_class =
Class.new(Object)
@@warnings =
{}

Class Method Summary collapse

Class Method Details

.const_missing(name) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rhino/deprecations.rb', line 6

def self.const_missing(name)
  case name.to_s
  when 'J' then
    warn "[DEPRECATION] `Rhino::J` is deprecated, use `Rhino::JS` instead."
    return JS
  when 'JavascriptError' then
    warn "[DEPRECATION] `Rhino::JavascriptError` is deprecated, use `Rhino::JSError` instead."
    return JSError
  when 'NativeObject' then
    warn "[DEPRECATION] `Rhino::NativeObject` is no longer used, returning a stub."
    return @@stub_class
  when 'NativeFunction' then
    warn "[DEPRECATION] `Rhino::NativeFunction` is no longer used, returning a stub."
    return @@stub_class
  else super
  end
end

.implementation_versionObject

Helper to resolve what version of Rhino's .jar we're really using.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rhino.rb', line 21

def self.implementation_version
  @@implementation_version ||= begin
    urls = JS::Kit.java_class.to_java.getClassLoader.
      getResources('META-INF/MANIFEST.MF').to_a
    rhino_jar_urls = urls.select { |url| url.toString.index(JAR_PATH) }
    if rhino_jar_urls.empty?
      raise "could not find #{JAR_PATH} manifest among: #{urls.map(&:toString).join(', ')}"
    elsif rhino_jar_urls.size > 1
      raise "could not find #{JAR_PATH} manifest among: #{urls.map(&:toString).join(', ')}"
    end
    manifest = java.util.jar.Manifest.new rhino_jar_urls.first.openStream
    manifest.getMainAttributes.getValue 'Implementation-Version'
  end
end

.warn(msg) ⇒ Object


26
27
28
29
30
31
32
33
# File 'lib/rhino/deprecations.rb', line 26

def self.warn(msg)
  # only print out deprecation warnings once
  if msg[0, 13] == '[DEPRECATION]'
    return nil if @@warnings[msg]
    @@warnings[msg] = true
  end
  super # Kernel.warn
end