Module: Rhino

Extended by:
To
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,
lib/rhino/rhino_ext.rb

Defined Under Namespace

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

Constant Summary collapse

RubyObject =

:nodoc

Ruby::Object
RubyFunction =

:nodoc

Ruby::Function
RubyConstructor =

:nodoc

Ruby::Constructor
ContextFactory =

:nodoc: backward compatibility

JS::ContextFactory
VERSION =
"2.1.2"
@@implementation_version =

:nodoc

nil
@@silence =

:nodoc

java.lang.Boolean.getBoolean('rhino.silence')
@@warnings =

:nodoc

{}
@@stub_class =

:nodoc

Class.new(Object)

Class Method Summary collapse

Methods included from To

args_to_javascript, args_to_ruby, javascript, ruby, to_javascript, to_ruby

Class Method Details

.const_missing(name) ⇒ Object

:nodoc



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) # :nodoc
  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

.silence!Object

Silence ! (… or I kill you)



40
# File 'lib/rhino.rb', line 40

def self.silence!; @@silence = true; end

.silence?Boolean

Should we be silent - no warnings will be printed.

Returns:

  • (Boolean)


38
# File 'lib/rhino.rb', line 38

def self.silence?; @@silence; end

.warn(msg) ⇒ Object

:nodoc



44
45
46
47
48
49
50
51
52
# File 'lib/rhino.rb', line 44

def self.warn(msg) # :nodoc
  return if silence?
  # only print out deprecations once (even when non-silent)
  if msg[0, 13] == '[DEPRECATION]'
    return nil if @@warnings[msg]
    @@warnings[msg] = true
  end
  super # Kernel.warn
end