Skip to content

Commit

Permalink
Added coercions for nil
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Mar 4, 2012
1 parent 3adacf5 commit db6c5a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/evaljs/rhino.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
NativeArray
(as-clojure [x] (vec (map as-clojure x)))
Object
(as-clojure [x] x))
(as-clojure [x] x)
nil
(as-clojure [_] nil))

(defprotocol AsJavascript
(as-javascript [x]))
Expand Down Expand Up @@ -46,7 +48,9 @@
Map
(as-javascript [x] (native-object (for [[k v] x] [k (as-javascript v)])))
Object
(as-javascript [x] x))
(as-javascript [x] x)
nil
(as-javascript [_] nil))

(deftype RhinoContext [context scope]
JSContext
Expand Down
8 changes: 5 additions & 3 deletions test/evaljs/test/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
(is (= (evaljs "10") 10))
(is (= (evaljs "\"foo\"") "foo"))
(is (= (evaljs "[1, 2]") [1 2]))
(is (= (evaljs "x={a:2};x") {"a" 2}))))
(is (= (evaljs "x={a:2};x") {"a" 2}))
(is (= (evaljs "null") nil))))

(deftest import-vars
(with-context (rhino-context {:x 1, :s "foo", :k :a})
(with-context (rhino-context {:x 1, :s "foo", :k :a, :n nil})
(is (= (evaljs "x") 1))
(is (= (evaljs "s") "foo"))
(is (= (evaljs "k") "a")))
(is (= (evaljs "k") "a"))
(is (= (evaljs "n") nil)))
(with-context (rhino-context {:x [1 2]})
(is (= (evaljs "x") [1 2]))
(is (= (evaljs "x[0]") 1)))
Expand Down

0 comments on commit db6c5a8

Please sign in to comment.