Bug 69877

Summary: Make CachedResourceClientWalker templated and have it do checked casts.
Product: WebKit Reporter: Nate Chapin <japhet>
Component: WebCore Misc.Assignee: Nate Chapin <japhet>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, ap, koivisto, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
patch none

Description Nate Chapin 2011-10-11 15:54:35 PDT
Followup to https://bugs.webkit.org/show_bug.cgi?id=69790, which introduced a bunch of unchecked casts that rely on CachedResource subtypes and CachedResourceClient subtypes matching each other correctly.  As written, it will fail dangerously in the event of a programmer error.
Comment 1 Nate Chapin 2011-10-11 15:56:51 PDT
Created attachment 110597 [details]
patch
Comment 2 WebKit Review Bot 2011-10-11 17:11:37 PDT
Comment on attachment 110597 [details]
patch

Clearing flags on attachment: 110597

Committed r97199: <http://trac.webkit.org/changeset/97199>
Comment 3 WebKit Review Bot 2011-10-11 17:11:42 PDT
All reviewed patches have been landed.  Closing bug.
Comment 4 Antti Koivisto 2011-10-12 01:03:51 PDT
Comment on attachment 110597 [details]
patch

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

> Source/WebCore/loader/cache/CachedResourceClientWalker.h:54
> +            if (m_clientSet.contains(next) && (T::expectedType() == CachedResourceClient::expectedType() || next->type() == T::expectedType()))
> +                return static_cast<T*>(next);

What is the purpose of T::expectedType() == CachedResourceClient::expectedType()?

Could this assert the correct type instead?
Comment 5 Nate Chapin 2011-10-12 08:52:44 PDT
(In reply to comment #4)
> (From update of attachment 110597 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=110597&action=review
> 
> > Source/WebCore/loader/cache/CachedResourceClientWalker.h:54
> > +            if (m_clientSet.contains(next) && (T::expectedType() == CachedResourceClient::expectedType() || next->type() == T::expectedType()))
> > +                return static_cast<T*>(next);
> 
> What is the purpose of T::expectedType() == CachedResourceClient::expectedType()?
> 
> Could this assert the correct type instead?

The purpose is to handle the notifyFinished() callback correctly.  notifyFinished() is called for all CachedResourceClient types, and is templated with the base class rather than a subclass.

I suppose we could assert instead of just skipping clients of the wrong type.  I don't have a strong opinion.
Comment 6 Antti Koivisto 2011-10-12 10:50:02 PDT
I suspect that all cases where there are unexpected types on the list are bugs so assert would be the right choice.