Bug 80060 - hasOwnProperty works inconsistently between WebKit and Firefox
Summary: hasOwnProperty works inconsistently between WebKit and Firefox
Status: RESOLVED DUPLICATE of bug 49739
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac (Intel) OS X 10.7
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2012-03-01 15:26 PST by Marc Silverman
Modified: 2012-03-03 14:38 PST (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
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 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.');
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 ***