Bug 80060

Summary: hasOwnProperty works inconsistently between WebKit and Firefox
Product: WebKit Reporter: Marc Silverman <silverma>
Component: WebCore JavaScriptAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: ap, barraclough, silverma
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Mac (Intel)   
OS: OS X 10.7   

Description Marc Silverman 2012-03-01 15:26:21 PST
On WebKit nightly and the latest version of Chrome, the following shows two alerts.  On Firefox, it shows one alert.  Which is correct?
NOTE 1 in 15.2.4.5 Object.prototype.hasOwnProperty of the ECMAScript Language Spec says: "this method does not consider objects in the prototype chain", I couldn't figure out if that's relevant.

ECMAScript Language Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf

----

<p id="element">Sample Text</p>

<SCRIPT type="text/javascript">

var o = document.getElementById("element");

if(o.hasOwnProperty('style')) {
    alert(o.nodeName + ' has \'style\' as the direct property of the object.');
}
if('style' in o) {
    alert(o.nodeName + ' has \'style\' as a property in the object\'s prototype chain.');
}
</SCRIPT>
Comment 1 Gavin Barraclough 2012-03-01 16:57:09 PST
I believe this is actually a WebIDL related bug, and that Firefox's behavior is correct.

I believe hasOwnProperty is working correctly on both browsers, and that it is actually the DOM that is different (in Safari, 'style' is a property of the element, in Firefox it is presumably a property of the prototype).  If so, it is Firefox behaving correctly – I believe WebIDL specifies that such properties should be on the prototype.
Comment 2 Alexey Proskuryakov 2012-03-02 14:19:17 PST
> property of the element, in Firefox it is presumably a property of the prototype

Which is a of course a general issue that has been reported before. Not sure what the best original is.
Comment 3 Marc Silverman 2012-03-03 14:38:09 PST

*** This bug has been marked as a duplicate of bug 49739 ***