Last Comment Bug 57048 - propertyIsEnumerable(): Ecmascript compliance bug
: propertyIsEnumerable(): Ecmascript compliance bug
Status: RESOLVED FIXED
: js1.5
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: All All
: P3 normal (vote)
: ---
Assigned To: rogerl (gone)
: Phil Schwartau
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2000-10-17 13:02 PDT by David Flanagan
Modified: 2008-04-17 10:09 PDT (History)
5 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Make propertyIsEnumerable do a hasOwnProeprty check (834 bytes, patch)
2000-11-21 18:17 PST, Mike McCabe
no flags Details | Diff | Splinter Review

Description David Flanagan 2000-10-17 13:02:16 PDT
Section 15.2.4.7 of the ECMA3 spec says that propertyIsEnumerable 
"does not consider objects in the prototype chain".

Personally, I think this is a mistake in the specification, because
the function isn't as useful if it ignores that prototype chain.

However, spidermonkey does not conform to the spec as it is written.
Note that Rhino does conform.  Here is an illustration:

js> String.prototype.foo = "bar";
bar
js> s = "test"
test
js> s.propertyIsEnumerable("foo")
true
js> function Foo() { this.x = 1; }
js> Foo.prototype.y = 2;
2
js> var f = new Foo();
js> f.propertyIsEnumerable("x");
true
js> f.propertyIsEnumerable("y");
true
Comment 1 Phil Schwartau 2000-10-17 17:32:45 PDT
From the ECMA3 spec:

15.2.4.7 Object.prototype.propertyIsEnumerable (V)

When the propertyIsEnumerable method is called with argument V, the following 
steps are taken:

1. Let O be this object.
2. Call ToString(V).
3. If O doesn’t have a property with the name given by Result(2), return false .
4. If the property has the DontEnum attribute, return false .
5. Return true.

NOTE This method does not consider objects in the prototype chain.
Comment 2 Brendan Eich [:brendan] 2000-10-26 19:04:32 PDT
We believe the spec suffered a draft error that no one caught, and that the 
intention was for propertyIsEnumerable to match the for..in loop, and check the 
prototype chain as well as the object at hand.  I think we should WONTFIX this 
bug and fix the spec, but I'll confirm and reassign to waldemar for ultimate 
disposition.

/be
Comment 3 David Flanagan 2000-10-26 19:24:01 PDT
A quick check of a newly downloaded copy of IE 5.5 makes it
look like MS implements the spec as written, rather than
as intended.

javascript:String.prototype.foo = 'bar';s='foo';s.propertyIsEnumerable('foo')

evaluates to false in IE5.5
Comment 4 Waldemar Horwat 2000-11-20 16:36:57 PST
I discussed this at the last ECMA meeting and the decision was to implement the 
spec as written, even if it's flawed in this case.  Spidermonkey is correct; 
Rhino should be updated.
Comment 5 Phil Schwartau 2000-11-20 17:00:29 PST
Reassigning to Rhino per Waldemar's comment above -
Comment 6 Norris Boyd 2000-11-20 17:22:49 PST
Reassigning back--

Rhino's matches the spec as written, SpiderMonkey does not.

Here's Rhino's output: 
js> String.prototype.foo = "bar";
bar
js> s = "test"
test
js> s.propertyIsEnumerable("foo")
false
js> function Foo() { this.x = 1; }
js> Foo.prototype.y = 2;
2
js> var f = new Foo();
js> f.propertyIsEnumerable("x");
true
js> f.propertyIsEnumerable("y");
false
js>
Comment 7 Phil Schwartau 2000-11-20 17:38:12 PST
[MID-AIR COLLISION] 

Norris is correct. As David reported, it's SpiderMonkey that goes up 
the prototype chain for propertyIsEnumerable(), against spec. 


Confirmed with Waldemar -
Comment 8 Mike McCabe 2000-11-21 18:17:07 PST
Created attachment 19598 [details] [diff] [review]
Make propertyIsEnumerable do a hasOwnProeprty check
Comment 9 rogerl (gone) 2000-11-28 11:00:17 PST
r=rogerl
Comment 10 Mike McCabe 2000-11-28 18:06:03 PST
Fix checked in.
Comment 11 Brendan Eich [:brendan] 2000-12-01 01:32:45 PST
Who sr='d this change?

I still think ECMA is wrong, and should be fixed -- it's not as if anyone uses
this feature yet.

/be

Note You need to log in before you can comment on or make changes to this bug.