Module: Rhino::To

Defined in:
lib/rhino/wormhole.rb

Constant Summary collapse

JS_UNDEF =
[J::Scriptable::NOT_FOUND, J::Undefined]

Class Method Summary collapse

Class Method Details

.array(native) ⇒ Object



30
31
32
# File 'lib/rhino/wormhole.rb', line 30

def array(native)
  native.length.times.map {|i| ruby(native.get(i,native))}
end

.javascript(object) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rhino/wormhole.rb', line 18

def javascript(object)
  case object
  when String,Numeric       then object
  when TrueClass,FalseClass then object
  when Array                then J::NativeArray.new(object.to_java)
  when Proc,Method          then RubyFunction.new(object)
  when NativeObject         then object.j      
  when J::Scriptable        then object
  else RubyObject.new(object)
  end
end

.ruby(object) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rhino/wormhole.rb', line 6

def ruby(object)
  case object
  when *JS_UNDEF                then nil
  when J::Wrapper               then object.unwrap
  when J::NativeArray           then array(object)
  when J::Regexp::NativeRegExp  then object
  when J::Function              then NativeFunction.new(object)
  when J::Scriptable            then NativeObject.new(object)
  else  object
  end        
end