question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Objects with null prototype cause fast-deep-equal to throw an error

See original GitHub issue

Example code:

fastDeepEqual(Object.create(null, {a:true}), {a:true})

This will throw an error, the line below calls .valueOf() which is not a method for objects with a null prototype.

https://github.com/epoberezkin/fast-deep-equal/blob/master/src/index.jst#L51

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:18
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
epoberezkincommented, Jan 30, 2020

Thank you - I commented there.

The design decision here is to consider instances of different classes (i.e. with different prototypes in JS) as not equal, even if they have the same properties. So if null prototype support is added (which I am considering), objects in your example would not throw an exception, but would return false - I believe it is different from what you expect.

I am also considering to introduce a version of this function that ignores classes/prototypes and only checks properties, with some specific exceptions (e.g. Date and RegExp).

To address it now, any possible workaround should be used in the application code.

2reactions
thomas-jeepecommented, Jan 18, 2020

I don’t use null prototype directly, but graphql-js uses them for return values and I want to make assertions on those return values.

Some quick issue searching shows some reasoning for using null prototype.

https://github.com/graphql/graphql-js/pull/504#issuecomment-250343574

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to fix [Object: null prototype] { title: 'product' }
I'm wondering if this actually is an error with express or just a propriety that its been added to express recently , because...
Read more >
JavaScript and object with null prototype - LinkedIn
Object with null prototype and its purpose​​ If you create an object in JavaScript - it has some methods by default, such as...
Read more >
core-helpers - Remirror
Throw an error if the referenced property is undefined . Signature: ... A deep merge which only merges plain objects and Arrays. It...
Read more >
johnrom/formik - UNPKG
isArray;\nvar keyList = Object.keys;\nvar hasProp = Object.prototype. ... some other error. we should definitely know about these\n throw error;\n }\n};\n" ...
Read more >
jest typeerror: class extends value - You.com | The AI Search ...
I get the following error: FAIL e2e/firstTest.e2e.jsrun... ○ Test suite failed to run TypeError: Class extends value #<Object> is not a constructor or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found