hasOwnProperty() not working in Chrome for array hasOwnProperty() not working in Chrome for array google-chrome google-chrome

hasOwnProperty() not working in Chrome for array


There appears to be some sort of bug in Chrome that was introduced when we upgraded from Chrome version 54.0.2840.99 to 55.0.2883.75 on Dec. 2, 2016.

The solution to our particular issue was to change our hash function to only return positive numbers. While small tests using negative numbers appears to work fine (as per squint's example in the comments), in our application they no longer work in Chrome.

I don't have a lot of time to dig into it. I don't know if it has to do with the number of items (we only have about 170 or so items in our "bucket").

Update:

gre_gor, in a comment above produced a sample that demonstrates the bug:

obj = {  buckets: {},  comparer: {    getObjectHashCode: function(str) { // hardcoded magic hashing      return {        "SUPPLYINVENTORY/SUPTRANSENTRY": -1525029354,        "PROPANE/LOADPROPANETOGROWERAR": 115289505      }[str.toUpperCase()];    },    areEqual: function(a, b) {      return a.toUpperCase() == b.toUpperCase();    }  },  containsKey: function(key) {    var hash = this.comparer.getObjectHashCode(key);    if (!this.buckets.hasOwnProperty(hash))      return false;    var array = this.buckets[hash];    for (var i = 0; i < array.length; i++) {      if (this.comparer.areEqual(array[i].key, key))        return true;    }    return false;  }};obj.buckets[-1525029354] = [{  key: "SUPPLYINVENTORY/SUPTRANSENTRY",  value: "$SupTransEntry object"}];obj.buckets[115289505] = [{  key: "PROPANE/LOADPROPANETOGROWERAR",  value: "$LoadPropaneToGrowerAR object"}];console.log(obj.containsKey("SUPPLYINVENTORY/SUPTRANSENTRY"), obj.containsKey("PROPANE/LOADPROPANETOGROWERAR"));

The text "true true" should go to the console, but in Chrome 55, it produces "false true".

Thank you gre_gor for a test that reliably reproduces the issue. I've reported the bug to Google.

Update #2: A bug was submitted 3 days before my submission for it. The issue has been fixed and will be out soon enough that I'm not going to have to work around it. -- Chromium Bug #673008