diff --git a/lib/rhino/wormhole.rb b/lib/rhino/wormhole.rb index fdf9845..94b4540 100644 --- a/lib/rhino/wormhole.rb +++ b/lib/rhino/wormhole.rb @@ -1,11 +1,13 @@ module Rhino - module To + module To + JS_UNDEF = [J::Scriptable::NOT_FOUND, J::Undefined] + def ruby(object) case object - when J::Scriptable::NOT_FOUND then nil - when J::Wrapper then object.unwrap - when J::Scriptable then NativeObject.new(object) + when *JS_UNDEF then nil + when J::Wrapper then object.unwrap + when J::Scriptable then NativeObject.new(object) else object end end diff --git a/spec/rhino/wormhole_spec.rb b/spec/rhino/wormhole_spec.rb index db14034..29d1ce5 100644 --- a/spec/rhino/wormhole_spec.rb +++ b/spec/rhino/wormhole_spec.rb @@ -33,6 +33,10 @@ describe Rhino::To do end end end + + it "converts javascript undefined into nil" do + To.ruby(J::Undefined.instance).should be_nil + end end describe "javascript translation" do