Bug 45358 - DatasetDOMStringMap does not have the right memory model
Summary: DatasetDOMStringMap does not have the right memory model
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Erik Arvidsson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-07 19:25 PDT by Erik Arvidsson
Modified: 2010-12-14 01:58 PST (History)
4 users (show)

See Also:


Attachments
Patch (5.38 KB, patch)
2010-09-07 22:46 PDT, Sam Weinig
mitz: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Arvidsson 2010-09-07 19:25:04 PDT
This came up in irc today when we talked about classList DOMTokenList which has the same behavior/issue:

The dataset needs to not fail when the element goes away.

othermaciej: I think the following would work:
[7:06pm] othermaciej: - DOMTokenList is a normal RefCounted
[7:06pm] othermaciej: - Element keeps a ref to it via rare data struct
[7:06pm] othermaciej: - Element destructor presumably already cleans up any rare data that may exist, so rare data can clear out DOMTokenList's backpointer to its element
[7:07pm] othermaciej: - At JS/GC level, Element wrapper keeps DOMTokenList wrapper alive
[7:15pm] arv: jamesr, othermaciej: DatasetDOMStringMap uses the same pattern. I assume that needs to be updated too?
[7:15pm] othermaciej: arv: ask and/or yell at weinig
Comment 1 Sam Weinig 2010-09-07 22:46:03 PDT
Created attachment 66843 [details]
Patch
Comment 2 Sam Weinig 2010-09-07 22:47:48 PDT
I disagree with Maciej that we need to completely alter the memory management of DOMStringMap. The model I used is idiomatic in WebCore. For instance, It is used by CanvasRenderingContext and ValidityState.  That said, I was forgetting to mark the dataset, so I have attached a patch to fix it.
Comment 3 mitz 2010-09-07 22:52:18 PDT
Comment on attachment 66843 [details]
Patch

> +    DOMStringMap* optionalDataset() const;

That’s an awful use of “optional”. r+ only because it’s already being used like this.
Comment 4 Sam Weinig 2010-09-07 22:59:57 PDT
Fixed in r66954. 

Filed https://bugs.webkit.org/show_bug.cgi?id=45367 for a better name.
Comment 5 Erik Arvidsson 2010-09-08 11:32:05 PDT
Comment on attachment 66843 [details]
Patch

This test does not seem correct to me.

Your test seems to test that we get back the same wrapper object?

Don't you want to GC the element and ensure that the dataset does not blow up when the element goes away? (and that the element can be GC'd when there are only references to the dataset)

Is there a reason why you use __proto__ here. Could you have used any property name?
Comment 6 Sam Weinig 2010-09-08 14:29:16 PDT
(In reply to comment #5)
> (From update of attachment 66843 [details])
> This test does not seem correct to me.
> 

Can you elaborate on what is incorrect about it?

> Your test seems to test that we get back the same wrapper object?

Yes.

> 
> Don't you want to GC the element and ensure that the dataset does not blow up when the element goes away? (and that the element can be GC'd when there are only references to the dataset)

I am not entirely sure what you are getting at. Can you provide a test case?

> Is there a reason why you use __proto__ here. Could you have used any property name?

Yeah, I was being sneaky due to the fact that dataset intercepts all property sets except for a few built in properties and puts them in the DOM as attributes, so it wouldn't be testing the right thing?
Comment 7 Erik Arvidsson 2010-09-17 15:42:49 PDT
Would it not be better to tie the lifetime of the dataset to the lifetime of the element it came from?

Also see Bug 45426
Comment 8 Sam Weinig 2010-09-18 16:55:55 PDT
(In reply to comment #7)
> Would it not be better to tie the lifetime of the dataset to the lifetime of the element it came from?
> 
> Also see Bug 45426

That is what is done.
Comment 9 Erik Arvidsson 2010-09-20 10:29:49 PDT
Forgive my ignorance.

I think what is confusing is that markDOMObjectWrapper takes an argument called globalData.
Comment 10 Eric Seidel (no email) 2010-12-14 01:58:52 PST
Looks like this was landed but just not closed.