Skip to content

Comparing object with "hasOwnProperty" keys fails #58

Closed
@foolip

Description

@foolip

I'm trying to use deep-object-diff to compare different copies of https://github.com/mdn/browser-compat-data, which is a dataset describing the web platform itself. As such, it has a key called "hasOwnProperty" to describe that method. deep-object-diff uses code like obj.hasOwnProperty(key) a lot, and obj.hasOwnProperty will in this case be an object in the BCD data, not Object.prototype.hasOwnProperty.

This causes deep-object-diff to throw an exception, the first place being here.

return r.hasOwnProperty(key) ? acc : { ...acc, [key]: undefined };

Simplified a bit, here's a subset of the data:

{
  "javascript": {
    "builtins": {
      "Object": {
        "hasOwnProperty": {
          "__compat": "an object with more stuff here"
        }
      }
    }
  }
}

Repro script showing the problem:

const { diff } = require("deep-object-diff");
diff({"hasOwnProperty": 1}, {"hasOwnProperty": 2});

This will throw "Uncaught TypeError: r.hasOwnProperty is not a function".

A possible fix for this would be to add a hasOwnProperty wrapper to https://github.com/mattphillips/deep-object-diff/blob/master/src/utils/index.js and always use that, but there may be other ways.

Activity

papb

papb commented on Oct 6, 2020

@papb
anko

anko commented on Oct 9, 2020

@anko
Contributor

@foolip Review #59?

(Posting this because I think you don't get a notification when a PR links to your issue.)

foolip

foolip commented on Oct 21, 2020

@foolip
Author

@anko thanks for posting the fix, I've tried it and can confirm it fixes my problem.

mattphillips

mattphillips commented on Jan 25, 2022

@mattphillips
Owner

Available in v1.1.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @foolip@anko@mattphillips@papb

      Issue actions

        Comparing object with "hasOwnProperty" keys fails · Issue #58 · mattphillips/deep-object-diff