Bug 74468 - Incorrect behavior for HTMLCollection.prototype.item(someString)
Summary: Incorrect behavior for HTMLCollection.prototype.item(someString)
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
: 74546 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-12-13 17:29 PST by Boris Zbarsky
Modified: 2012-01-25 05:04 PST (History)
10 users (show)

See Also:


Attachments
Testcase (441 bytes, text/html)
2011-12-13 17:29 PST, Boris Zbarsky
no flags Details
Patch (11.72 KB, patch)
2012-01-25 01:29 PST, Pablo Flouret
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Zbarsky 2011-12-13 17:29:47 PST
Created attachment 119120 [details]
Testcase

Webkit apparently treats item() on form.elements and other HTMLCollections as an alias for namedItem if a string is passed or something.  This is wrong per the spec at http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#htmlformcontrolscollection as well as per the DOM 2 HTML spec.  See the attached testcase; it should say "PASS" twice.

BUILD: Current WebKit nightly.

STEPS TO REPRODUCE:
Load attached testcase.

EXPECTED RESULTS: 2 lines that say "PASS"

ACTUAL RESULTS: 2 lines that say "FAIL"

Gecko and Presto both get this right.
Comment 1 Alexey Proskuryakov 2011-12-14 10:54:06 PST
> Gecko and Presto both get this right.

This behavior was implemented in bug 11078 precisely to match Gecko and Presto (and document.all.item(someString) still works in Firefox 8.0.1). It might have gotten unintentionally extended to other versions of item() with code refactorings over the years.

We should investigate which versions of item() need to fall back to namedItem().
Comment 2 Boris Zbarsky 2011-12-14 11:06:24 PST
Yeah, document.all is not an HTMLCollection and has completely different item() behavior in Firefox.

Per HTML5 spec, it's an HTMLCollection, though.  The spec probably needs fixing.
Comment 3 Boris Zbarsky 2011-12-14 11:08:07 PST
I filed https://www.w3.org/Bugs/Public/show_bug.cgi?id=15184
Comment 4 Ryosuke Niwa 2011-12-14 16:00:57 PST
*** Bug 74546 has been marked as a duplicate of this bug. ***
Comment 5 Pablo Flouret 2012-01-25 01:29:33 PST
Created attachment 123898 [details]
Patch
Comment 6 Adam Barth 2012-01-25 01:35:22 PST
Comment on attachment 123898 [details]
Patch

This didn't cause any other tests to fail?  Do we know the history of this code?  Why does WebKit have this behavior?
Comment 7 Adam Barth 2012-01-25 01:36:04 PST
Comment on attachment 123898 [details]
Patch

Ah, I see that Alexey answered that question above.
Comment 8 WebKit Review Bot 2012-01-25 05:04:40 PST
Comment on attachment 123898 [details]
Patch

Clearing flags on attachment: 123898

Committed r105870: <http://trac.webkit.org/changeset/105870>
Comment 9 WebKit Review Bot 2012-01-25 05:04:49 PST
All reviewed patches have been landed.  Closing bug.