Avoid obj.hasOwnProperty in favor of Object.prototype.hasOwnPrototype

Reimplement #1818, with replacing all hasOwnPrototype and adding a test.