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

Open
#31 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
javascript
Domain
tooling

Research direction

Start with is-prototype? in helpers.cljs, at the stack trace location, and reproduce the oget example with a JavaScript object whose constructor is null. Verify that accessing :a no longer throws when the constructor is absent, while normal prototype checks still work.

Written by the indexing model from the issue text.

Description

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

Dominant language
Clojure
Stars
350
Forks
13
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from binaryage/cljs-oops

All issues in binaryage/cljs-oops

Similar issues

More Clojure issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.