CLJS-177 js->clj should convert JavaScript null to Clojure nil

212 views
Skip to first unread message

Jason Rudolph

unread,
Apr 10, 2012, 7:57:22 PM4/10/12
to cloju...@googlegroups.com
I noticed a change in the behavior of js->clj in commit ebf45f5 [A], and I'm wondering if this change was intentional.

Prior to commit ebf45f5, js->clj converted JavaScript null to Clojure nil without any errors.

As of commit ebf45f5 (related to CLJS-175), js->clj throws a TypeError when it encounters JavaScript null:

      TypeError: Cannot read property 'constructor' of null
       b===c}function q(b,c){return gb.call(e,b,c)}function pb(b){return b.construct
                                                                          ^
      TypeError: Cannot read property 'constructor' of null

-----

I created CLJS-177 [B] to track this issue. I attached a patch [C] that adds a test to demonstrate the issue and provides a suggested fix.

Note: CLJS-175 [D] intentionally limited the types of objects it would attempt to convert to Clojure code. For example, CLJS-175 notes that conversion "doesn't make sense for something like Date or RegExp." I agree for those types of objects, but "null" seems straightforward enough that it should be converted.

Do you agree that js->clj should convert JavaScript null to Clojure nil?  If so, does this patch seem like a reasonable solution?



David Nolen

unread,
Apr 10, 2012, 8:39:05 PM4/10/12
to cloju...@googlegroups.com
I think it's actually better to fix type to return nil for types that don't have a constructor. This is in master now.

David

--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/clojure-dev/-/35ISWSLl4TwJ.
To post to this group, send email to cloju...@googlegroups.com.
To unsubscribe from this group, send email to clojure-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/clojure-dev?hl=en.

Reply all
Reply to author
Forward
0 new messages