mirror of
https://github.com/rubyjs/therubyrhino
synced 2023-03-27 23:21:34 -04:00
map org.mozilla.javascript.Undefined to ruby nil
This commit is contained in:
parent
9276bb69a6
commit
f7d0f719b5
2 changed files with 10 additions and 4 deletions
|
@ -1,11 +1,13 @@
|
||||||
|
|
||||||
module Rhino
|
module Rhino
|
||||||
module To
|
module To
|
||||||
|
JS_UNDEF = [J::Scriptable::NOT_FOUND, J::Undefined]
|
||||||
|
|
||||||
def ruby(object)
|
def ruby(object)
|
||||||
case object
|
case object
|
||||||
when J::Scriptable::NOT_FOUND then nil
|
when *JS_UNDEF then nil
|
||||||
when J::Wrapper then object.unwrap
|
when J::Wrapper then object.unwrap
|
||||||
when J::Scriptable then NativeObject.new(object)
|
when J::Scriptable then NativeObject.new(object)
|
||||||
else object
|
else object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,10 @@ describe Rhino::To do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "converts javascript undefined into nil" do
|
||||||
|
To.ruby(J::Undefined.instance).should be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "javascript translation" do
|
describe "javascript translation" do
|
||||||
|
|
Loading…
Reference in a new issue