puleos / object-hash

Generate hashes from javascript objects in node and the browser.
MIT License
1.41k stars 145 forks source link

Not properly hashing `class` based objects getters #120

Open piranna opened 1 year ago

piranna commented 1 year ago

When hashing a (class based) object with a getter, object-hash try to get the actual property value, while in fact it's calculated. So when doing it with ws WebSocket class, it goes to its prototype and finally to the extensions getter, throwsing an exception because this._extensions is undefined since its initialized in its constructor. Here we have several alternatives:

I think the best option is the last one, since it's the most attached to the code. Since we are using Object.keys(), there would not be overlap with getters set at prototype or class level, and the place to check and serialize the getter with the getter: prefix and the serialized getter function object should be in place of fetching its value when accesing to the object attributes values.

I think this issue can be related to https://github.com/puleos/object-hash/issues/49, https://github.com/puleos/object-hash/issues/81, https://github.com/puleos/object-hash/issues/84, and https://github.com/puleos/object-hash/issues/72