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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions