Bug 99241 - StyleSheetList should be a ContextDestructionObserver
Summary: StyleSheetList should be a ContextDestructionObserver
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Adam Barth
URL:
Keywords: EasyFix
Depends on:
Blocks:
 
Reported: 2012-10-13 00:22 PDT by WebKit Review Bot
Modified: 2024-01-30 10:29 PST (History)
12 users (show)

See Also:


Attachments
Patch (5.27 KB, patch)
2013-02-07 21:36 PST, Hanyee Kim
no flags Details | Formatted Diff | Diff
Patch (4.64 KB, patch)
2013-02-14 17:27 PST, Hanyee Kim
darin: review-
buildbot: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description WebKit Review Bot 2012-10-13 00:22:25 PDT
StyleSheetList should be a ContextDestructionObserver
Requested by abarth on #webkit.
Comment 1 Hanyee Kim 2013-02-07 21:36:03 PST
Created attachment 187234 [details]
Patch
Comment 2 Adam Barth 2013-02-08 08:47:50 PST
Comment on attachment 187234 [details]
Patch

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

> Source/WebCore/css/StyleSheetList.cpp:61
> +void StyleSheetList::contextDestroyed()
> +{
> +    m_detachedStyleSheets = document()->styleSheetCollection()->styleSheetsForStyleSheetList();
>  }

You need to call the base class here otherwise ContextDestructionObserver's pointer won't be cleared.

Also, is it ok to call document()->styleSheetCollection()->styleSheetsForStyleSheetList() at this point in the Document's destructor?  Your patch might have moved when this happens slightly.
Comment 3 Hanyee Kim 2013-02-14 17:26:11 PST
Thanks for your comment.

I think that it is not ok to call document()->styleSheetCollection()->styleSheetsForStyleSheetList() at this point in the Document's destructor.
So, I don't remove detachFromDoucment() for store m_detachedStyleSheets.

I will upload a new patch.
Comment 4 Hanyee Kim 2013-02-14 17:27:19 PST
Created attachment 188457 [details]
Patch
Comment 5 Build Bot 2013-02-15 05:42:36 PST
Comment on attachment 188457 [details]
Patch

Attachment 188457 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/16598048

New failing tests:
media/video-controls-captions-trackmenu.html
Comment 6 Adam Barth 2013-02-15 10:09:12 PST
> I think that it is not ok to call document()->styleSheetCollection()->styleSheetsForStyleSheetList() at this point in the Document's destructor.

Can you explain why?
Comment 7 Hanyee Kim 2013-02-21 23:35:47 PST
(In reply to comment #6)
Sorry. I am writing in the wrong.
It is ok to call document()->styleSheetCollection()->styleSheetsForStyleSheetList() in the Document's destructor. But it is not ok to document()->styleSheetCollection()->styleSheetsForStyleSheetList() in StyleSheetList::contextDestroyed().

Because StyleSheetList::contextDestroyed() is called by the ScriptExecutionContext's destructor. after the Document's destructor. Calling document() in contextDestroyed(). So, StyleSheetList::detachFromDocument() is needed  for store m_detachedStyleSheets.
Comment 8 Darin Adler 2014-08-19 09:35:11 PDT
Comment on attachment 188457 [details]
Patch

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

Seems OK, but I’m not sure this refactoring is sufficient improvement to be worth taking the change. If we wanted to take the full benefit from this, I think we’d want to remove the detachFromDocument function too. Also, I think we’d probably want to inline the document() function.

> Source/WebCore/ChangeLog:11
> +        This patch removes the raw pointer of Document in StyleSheetList. It
> +        could be replaced with ContextDestructionObserver.
> +        ContextDestructionObserver has the pointer and clears the pointer
> +        automatically when the document is destroyed.

Why? If this is a cleanup we should do more to actually clean up.

> Source/WebCore/css/StyleSheetList.cpp:53
> +    ScriptExecutionContext* context = ContextDestructionObserver::scriptExecutionContext();

We should call just scriptExecutionContext here, not explicitly ContextDestructionObserver::scriptExecutionContext.

> Source/WebCore/css/StyleSheetList.h:36
> +class StyleSheetList : public RefCounted<StyleSheetList>, public ContextDestructionObserver {

I think we’d want to use private inheritance here, not public.

> Source/WebCore/css/StyleSheetList.h:39
>      ~StyleSheetList();

We’d want to mark this virtual since it now will be implicitly virtual.