Bug 59128

Summary: HTMLFormControlElement::labels should allow custom attributes.
Product: WebKit Reporter: Yael <yael>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, ap, commit-queue, eric, sam, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Attachments:
Description Flags
Patch.
sam: review-
Patch.
sam: review-
Patch.
none
Patch.
sam: review+, ap: commit-queue-
Patch. none

Description Yael 2011-04-21 12:20:34 PDT
This was introduced in http://trac.webkit.org/changeset/60232.
HTMLFormControlElement::labels() needlessly caches its labels list.
Comment 1 Yael 2011-04-21 12:23:16 PDT
Created attachment 90576 [details]
Patch.
Comment 2 Sam Weinig 2011-04-21 13:12:21 PDT
Comment on attachment 90576 [details]
Patch.

This leaves the node list cache in NodeRareData.  I am also not sure we don't want to cache this value.  Consider the following test.

inputElement.labels.customProperty = 1;
alert(inputElement.labels.customProperty);

That should probably work, but probably won't with this patch or the current code.
Comment 3 Yael 2011-04-21 14:36:08 PDT
(In reply to comment #2)
> (From update of attachment 90576 [details])
> This leaves the node list cache in NodeRareData.  I am also not sure we don't want to cache this value.  Consider the following test.
> 
> inputElement.labels.customProperty = 1;
> alert(inputElement.labels.customProperty);
> 
> That should probably work, but probably won't with this patch or the current code.

Right, I was a bit too quick :)
I'll rework this patch.
Comment 4 Yael 2011-04-21 15:37:55 PDT
Created attachment 90617 [details]
Patch.

Cache the node this time. We do want the test in comment #2 to pass :)
Sam, I did not quite understand your comment on irc about strong pointers and could not catch you afterwards.
If it is still a problem please let me know and I'll address that.
Comment 5 Alexey Proskuryakov 2011-04-21 15:47:21 PDT
Comment on attachment 90617 [details]
Patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=90617&action=review

I don't deeply understand what's going one like Sam does, but I've got a few comments.

> LayoutTests/fast/forms/script-tests/labels-custom-property.js:1
> +description('Test that we can set and get custom properties on the labels attribute. ');

Could you please merge these .js and .html files? Keeping them separate causes nothing but difficulties, as you need a second step to get from test to its content.

> LayoutTests/fast/forms/script-tests/labels-custom-property.js:11
> +labels.customProperty = 1;
> +shouldBe('labels.customProperty', '1');

Can you add a gc() call between these? I can't easily find any code marking the JS wrapper.
Comment 6 Sam Weinig 2011-04-21 17:04:46 PDT
Comment on attachment 90617 [details]
Patch.

I think you need to change m_labelsNodeListCache to be a weak pointer for this not leak.
Comment 7 Yael 2011-04-21 18:09:12 PDT
(In reply to comment #6)
> (From update of attachment 90617 [details])
> I think you need to change m_labelsNodeListCache to be a weak pointer for this not leak.

Thank you for the review. I am not sure I know what you mean by "weak pointer" ? I cannot find it in wtf. Do you mean DynamicNodeList* or something else?
Comment 8 Yael 2011-04-22 06:03:43 PDT
(In reply to comment #5)
> (From update of attachment 90617 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=90617&action=review
> 
Thank you for your comments.
> I don't deeply understand what's going one like Sam does, but I've got a few comments.
> 
> > LayoutTests/fast/forms/script-tests/labels-custom-property.js:1
> > +description('Test that we can set and get custom properties on the labels attribute. ');
> 
> Could you please merge these .js and .html files? Keeping them separate causes nothing but difficulties, as you need a second step to get from test to its content.
> 
Will do :)

> > LayoutTests/fast/forms/script-tests/labels-custom-property.js:11
> > +labels.customProperty = 1;
> > +shouldBe('labels.customProperty', '1');
> 
> Can you add a gc() call between these? I can't easily find any code marking the JS wrapper.
Will do :)
I'll submit a new patch once the pointer issue is resolved.
Going through the logs, I see that the way we cache the DynamicNodeList wrappers was changed this week.
Please look at r84309 and r83990.
Comment 9 Yael 2011-04-22 09:05:15 PDT
Created attachment 90710 [details]
Patch.

Address comment #5 and commnet #6.
Comment 10 Yael 2011-04-22 09:06:21 PDT
(In reply to comment #9)
> Created an attachment (id=90710) [details]
> Patch.
> 
> Address comment #5 and comment #6.

Verified that the LabelsNodeList is being garbage collected and the C++ object is being deleted.
Comment 11 Yael 2011-04-22 09:17:32 PDT
Created attachment 90711 [details]
Patch.

Resolved conflicts.
Comment 12 Alexey Proskuryakov 2011-04-22 10:32:47 PDT
Wait, it''s not a weak pointer, it's a potentially dangling pointer...

For those following along at home, could you please explain why this pointer will never point to released memory?
Comment 13 Alexey Proskuryakov 2011-04-22 11:02:11 PDT
Comment on attachment 90711 [details]
Patch.

Could you please answer that before committing? If the code is wrong in that respect, the patch would be introducing a security bug.
Comment 14 Yael 2011-04-22 11:32:00 PDT
Created attachment 90731 [details]
Patch.

Change LabelsNodeList::create() to take a pointer Node* instead of PassRefPtr.
Change m_labelsNodeListCache to be of type LabelsNodeList*.
Comment 15 Yael 2011-04-22 11:33:51 PDT
(In reply to comment #12)
> Wait, it''s not a weak pointer, it's a potentially dangling pointer...
> 
> For those following along at home, could you please explain why this pointer will never point to released memory?

The pointer is cleared in the destructor of LabelsListNode.
Comment 16 WebKit Commit Bot 2011-04-22 15:37:01 PDT
Comment on attachment 90731 [details]
Patch.

Clearing flags on attachment: 90731

Committed r84693: <http://trac.webkit.org/changeset/84693>
Comment 17 WebKit Commit Bot 2011-04-22 15:37:06 PDT
All reviewed patches have been landed.  Closing bug.
Comment 18 WebKit Review Bot 2011-04-22 16:04:26 PDT
http://trac.webkit.org/changeset/84693 might have broken SnowLeopard Intel Release (Build)