Bug 42814

Summary: maxLength should not be applied to non-text types
Product: WebKit Reporter: Kent Tamura <tkent>
Component: FormsAssignee: Kent Tamura <tkent>
Status: RESOLVED FIXED    
Severity: Normal CC: adele, dglazkov
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch none

Description Kent Tamura 2010-07-22 03:38:57 PDT
maxLength should not be applied to non-text types
Comment 1 Kent Tamura 2010-07-22 03:40:49 PDT
According to http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary ,
maxLength should be applied only to text, search, url, tel, email, and password types.
Comment 2 Kent Tamura 2010-07-22 03:46:56 PDT
Created attachment 62283 [details]
Patch
Comment 3 Darin Adler 2010-07-22 07:31:20 PDT
Comment on attachment 62283 [details]
Patch

> +var input = document.createElement('input');
> +input.maxLength = 2;
> +input.type = 'number';
> +document.body.appendChild(input);
> +input.focus();
> +document.execCommand('insertText', false, '1234');
> +shouldBe('input.value', '"1234"');

Once you've set up the basics like this, it would be better to have the test cover many cases. It's good to go past the minimum and make sure you've covered all the code. Ideally you have a test that will fail if you change anything in your patch, rather than a test that covers just the most important thing you've changed.

It's unfortunate that HTMLInputElement itself calls a virtual function for supportsMaxLength. It's true that it needs to be virtual so that InputElement can call it, but when HTMLInputElement is calling itself the extra cost is not justified. There is a programming technique that eliminates this without any special care at call sites. See Node::localName, Node::virtualLocalName, Element::localName and Element::virtualLocalName, for an example of the technique. Using the technique would make our compiled code smaller and faster, but would make the code a bit more ugly.

Something from the existing code, not new: It seems a little bit unfortunate that when invoking the regular expression engine you can't tell it that you want to match against the entire string. It ends up doing work you don't need. We could consider adding a new operation to RegularExpression.

Otherwise things look good.
Comment 4 Kent Tamura 2010-07-22 19:32:43 PDT
(In reply to comment #3)
> Once you've set up the basics like this, it would be better to have the test cover many cases. It's good to go past the minimum and make sure you've covered all the code. Ideally you have a test that will fail if you change anything in your patch, rather than a test that covers just the most important thing you've changed.

I think the existing tests (not only the new one) cover this change well.

> It's unfortunate that HTMLInputElement itself calls a virtual function for supportsMaxLength. It's true that it needs to be virtual so that InputElement can call it, but when HTMLInputElement is calling itself the extra cost is not justified. There is a programming technique that eliminates this without any special care at call sites. See Node::localName, Node::virtualLocalName, Element::localName and Element::virtualLocalName, for an example of the technique. Using the technique would make our compiled code smaller and faster, but would make the code a bit more ugly.

Ok, I changed supportsMaxLength() call in HTMLInputElement to isTextType() and a comment.

Committed as r63942.