cljs-oops icon indicating copy to clipboard operation
cljs-oops copied to clipboard

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

Open p-himik opened this issue 4 years ago • 0 comments

=> (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?

p-himik avatar Sep 10 '21 18:09 p-himik