1
0
Fork 0
mirror of https://github.com/rubyjs/therubyrhino synced 2023-03-27 23:21:34 -04:00

properly map Time objects.

This commit is contained in:
Charles Lowell 2011-10-05 16:49:51 -05:00
parent 87f8aed5fa
commit 478d81831f

View file

@ -1,20 +1,21 @@
module Rhino module Rhino
module To module To
JS_UNDEF = [J::Scriptable::NOT_FOUND, J::Undefined] JS_UNDEF = [J::Scriptable::NOT_FOUND, J::Undefined]
def ruby(object) def ruby(object)
case object case object
when *JS_UNDEF then nil when *JS_UNDEF then nil
when J::Wrapper then object.unwrap when J::Wrapper then object.unwrap
when J::NativeArray then array(object) when J::NativeArray then array(object)
when J::NativeDate then Time.at(object.getJSTimeValue() / 1000)
when J::Regexp::NativeRegExp then object when J::Regexp::NativeRegExp then object
when J::Function then NativeFunction.new(object) when J::Function then NativeFunction.new(object)
when J::Scriptable then NativeObject.new(object) when J::Scriptable then NativeObject.new(object)
else object else object
end end
end end
def javascript(object) def javascript(object)
case object case object
when String,Numeric then object when String,Numeric then object
@ -22,12 +23,12 @@ module Rhino
when Array then J::NativeArray.new(object.to_java) when Array then J::NativeArray.new(object.to_java)
when Hash then ruby_hash_to_native(object) when Hash then ruby_hash_to_native(object)
when Proc,Method then RubyFunction.new(object) when Proc,Method then RubyFunction.new(object)
when NativeObject then object.j when NativeObject then object.j
when J::Scriptable then object when J::Scriptable then object
else RubyObject.new(object) else RubyObject.new(object)
end end
end end
def array(native) def array(native)
native.length.times.map {|i| ruby(native.get(i,native))} native.length.times.map {|i| ruby(native.get(i,native))}
end end
@ -41,7 +42,7 @@ module Rhino
native_object.j native_object.j
end end
module_function :ruby, :javascript, :array, :ruby_hash_to_native module_function :ruby, :javascript, :array, :ruby_hash_to_native
end end
end end