Bug 37130 - Add the const modififier to HTMLLabelElement::correspondingControl
Summary: Add the const modififier to HTMLLabelElement::correspondingControl
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-05 18:21 PDT by James Hawkins
Modified: 2010-04-06 10:58 PDT (History)
2 users (show)

See Also:


Attachments
Patch (2.32 KB, patch)
2010-04-05 18:23 PDT, James Hawkins
abarth: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Hawkins 2010-04-05 18:21:16 PDT
Add the const modififier to HTMLLabelElement::correspondingControl
Comment 1 James Hawkins 2010-04-05 18:23:34 PDT
Created attachment 52594 [details]
Patch
Comment 2 Darin Adler 2010-04-05 18:34:41 PDT
Comment on attachment 52594 [details]
Patch

Generally speaking, it's not all that helpful to have const in the DOM tree. You can't traverse the tree without losing the const modifier anyway, so it's not normally a useful distinction, although we do have const here and there on DOM objects. Similarly, the notion of a const pointer to a DOM element doesn't exist in JavaScript or even in Objective-C.

Is it really important to be able to do this operation on a const HTMLLabelElement*? When would one of those even arise?
Comment 3 James Hawkins 2010-04-05 18:42:01 PDT
(In reply to comment #2)
> (From update of attachment 52594 [details])
> Generally speaking, it's not all that helpful to have const in the DOM tree.
> You can't traverse the tree without losing the const modifier anyway, so it's
> not normally a useful distinction, although we do have const here and there on
> DOM objects. Similarly, the notion of a const pointer to a DOM element doesn't
> exist in JavaScript or even in Objective-C.
> 
> Is it really important to be able to do this operation on a const
> HTMLLabelElement*? When would one of those even arise?

As a matter of style, it's best to use const objects when possible.  In Chrome AutoFill, we have label parsing code that traverses the DOM in an HTMLFormElement, pulling out the labels.  In the case where a form has HTMLLabelElements, we just need to read the innerText() from the HTMLLabelElement objects.  Since the parsing is a read-only operation, there's really no reason not to have const objects.
Comment 4 Adam Barth 2010-04-06 10:41:51 PDT
Comment on attachment 52594 [details]
Patch

Marking r- for now.  We can probably do this if there's a more compelling reason than style though.
Comment 5 James Hawkins 2010-04-06 10:44:54 PDT
Closing.
Comment 6 Darin Adler 2010-04-06 10:45:53 PDT
(In reply to comment #3)
> As a matter of style, it's best to use const objects when possible.

I believe this greatly overstates the matter.

I think const is a quite-useful concept to make code clearer and prevent certain classes of programming mistakes, but in this case I don't agree.

Calling innerText has many side effects, so it's not necessarily a classic example of a "const" operation. It can trigger a lot of work, including network loading.
Comment 7 James Hawkins 2010-04-06 10:58:20 PDT
(In reply to comment #6)
> (In reply to comment #3)
> > As a matter of style, it's best to use const objects when possible.
> 
> I believe this greatly overstates the matter.
> 
> I think const is a quite-useful concept to make code clearer and prevent
> certain classes of programming mistakes, but in this case I don't agree.
> 
> Calling innerText has many side effects, so it's not necessarily a classic
> example of a "const" operation. It can trigger a lot of work, including network
> loading.

Ok, thanks for the insights Darin.  I'm going to re-close this bug.