Bug 148871

Summary: Indexing an object with an integer that is not a supported property index should not call the named property getter
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: FormsAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cdumez, commit-queue, darin, ggaren, rniwa, sam, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
URL: https://heycam.github.io/webidl/#idl-indexed-properties
See Also: https://bugs.webkit.org/show_bug.cgi?id=153599
Attachments:
Description Flags
Patch none

Description Ryosuke Niwa 2015-09-04 19:24:00 PDT
When an input element has a name which is an number, it should still be accessible via form.elements.
e.g. <input name="2"></input> should be accessible via form.elements[2].

See
https://html.spec.whatwg.org/multipage/forms.html#dom-form-elements
https://html.spec.whatwg.org/multipage/infrastructure.html#htmlformcontrolscollection

This bug was found by the newly added test:
LayoutTests/http/tests/w3c/html/semantics/forms/the-form-element/form-elements-matches.html
Comment 1 Radar WebKit Bug Importer 2015-09-04 19:24:27 PDT
<rdar://problem/22589952>
Comment 2 Ryosuke Niwa 2015-09-04 19:25:29 PDT
Both Firefox and Chrome pass this test.
Comment 3 Chris Dumez 2015-10-23 16:14:11 PDT
Note
Note that if an indexed property getter or setter is specified using an operation with an identifier, then indexing an object with an integer that is not a supported property index does not necessarily elicit the same behavior as invoking the operation with that index. The actual behavior in this case is language binding specific.

In the ECMAScript language binding, a regular property lookup is done. For example, take the following IDL:

IDL
interface A {
  getter DOMString toWord(unsigned long index);
};
Assume that an object implementing A has supported property indices in the range 0 ≤ index < 2. Also assume that toWord is defined to return its argument converted into an English word. The behavior when invoking the operation with an out of range index is different from indexing the object directly:

ECMAScript
var a = getA();

a.toWord(0);  // Evalautes to "zero".
a[0];         // Also evaluates to "zero".

a.toWord(5);  // Evaluates to "five".
a[5];         // Evaluates to undefined, since there is no property "5".
Comment 4 Chris Dumez 2015-10-23 16:16:58 PDT
Firefox and Chrome follow the Web IDL specification here.
Comment 5 Chris Dumez 2015-10-24 16:23:03 PDT
Created attachment 263986 [details]
Patch
Comment 7 WebKit Commit Bot 2015-10-26 11:09:36 PDT
Comment on attachment 263986 [details]
Patch

Clearing flags on attachment: 263986

Committed r191587: <http://trac.webkit.org/changeset/191587>
Comment 8 WebKit Commit Bot 2015-10-26 11:09:41 PDT
All reviewed patches have been landed.  Closing bug.