binaryage / cljs-oops

ClojureScript macros for convenient native Javascript object access.
Other
350 stars 13 forks source link

`oget` fails if the JS object has `:constructor` set to `null` #31

Open p-himik opened 3 years ago

p-himik commented 3 years ago
=> (oget #js {:constructor nil, :a 1} :a)
TypeError: Cannot read properties of null (reading 'prototype')
    at Object.oops$helpers$is_prototype_QMARK_ [as is_prototype_QMARK_] (helpers.cljs:7)
    at Object.oops$helpers$cljs_type_QMARK_ [as cljs_type_QMARK_] (helpers.cljs:19)
    at Object.oops$core$validate_object_access_dynamically [as validate_object_access_dynamically] (core.cljs:39)
    at eval (views.cljs:308)

The culprit seems to be this function:

(defn is-prototype? [o]
  (identical? (.-prototype (.-constructor o)) o))

Perhaps it should check if (.-constructor o) is not null?