Bug 51586

Summary: CSSParser: m_implicitShorthand should probably be RAII
Product: WebKit Reporter: Alexander Pavlov (apavlov) <apavlov>
Component: CSSAssignee: Alexander Pavlov (apavlov) <apavlov>
Status: RESOLVED FIXED    
Severity: Normal CC: dglazkov, hyatt, levin, simon.fraser
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: All   
Attachments:
Description Flags
[PATCH] Suggested fix
none
[PATCH] Removed unused field
none
[PATCH] Comments addressed
levin: review-
[PATCH] levin's comments addressed
levin: review-
[PATCH] Enum instead of bool
darin: review-
[PATCH] darin@'s comments addressed (parameter retained for reuse by a subsequent patch) levin: review+

Alexander Pavlov (apavlov)
Reported 2010-12-24 01:46:34 PST
m_implicitShorthand is switched to true then false manually across the code, which is highly error-prone. Most probably this switching should either go into ShorthandScope or a standalone RAII implementation.
Attachments
[PATCH] Suggested fix (5.16 KB, patch)
2011-05-04 08:54 PDT, Alexander Pavlov (apavlov)
no flags
[PATCH] Removed unused field (5.12 KB, patch)
2011-05-04 10:28 PDT, Alexander Pavlov (apavlov)
no flags
[PATCH] Comments addressed (4.85 KB, patch)
2011-05-16 04:05 PDT, Alexander Pavlov (apavlov)
levin: review-
[PATCH] levin's comments addressed (4.88 KB, patch)
2011-05-17 02:08 PDT, Alexander Pavlov (apavlov)
levin: review-
[PATCH] Enum instead of bool (5.13 KB, patch)
2011-05-24 09:48 PDT, Alexander Pavlov (apavlov)
darin: review-
[PATCH] darin@'s comments addressed (parameter retained for reuse by a subsequent patch) (5.04 KB, patch)
2011-05-24 10:11 PDT, Alexander Pavlov (apavlov)
levin: review+
Alexander Pavlov (apavlov)
Comment 1 2011-05-04 08:54:30 PDT
Created attachment 92251 [details] [PATCH] Suggested fix
Luiz Agostini
Comment 2 2011-05-04 10:11:17 PDT
Comment on attachment 92251 [details] [PATCH] Suggested fix View in context: https://bugs.webkit.org/attachment.cgi?id=92251&action=review > Source/WebCore/css/CSSParser.h:397 > + bool m_oldImplicitShorthand; is m_oldImplicitShorthand used?
Alexander Pavlov (apavlov)
Comment 3 2011-05-04 10:17:58 PDT
(In reply to comment #2) > (From update of attachment 92251 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=92251&action=review > > > Source/WebCore/css/CSSParser.h:397 > > + bool m_oldImplicitShorthand; > > is m_oldImplicitShorthand used? Yikes, it was intended to be, but then I decided to retain the original behavior. Attaching a fixed patch now.
Alexander Pavlov (apavlov)
Comment 4 2011-05-04 10:28:18 PDT
Created attachment 92272 [details] [PATCH] Removed unused field
Hajime Morrita
Comment 5 2011-05-15 22:23:04 PDT
Comment on attachment 92272 [details] [PATCH] Removed unused field View in context: https://bugs.webkit.org/attachment.cgi?id=92272&action=review > Source/WebCore/css/CSSParser.cpp:2411 > + ImplicitScope implicitScope(this, true); Can we move this before the switch statement and remove duplication? > Source/WebCore/css/CSSParser.h:386 > + ImplicitScope(CSSParser* parser, bool isImplicit = true) : m_parser(parser) Please make it explicit or it looks we don't need the default value for the second parameter. Also, We don't need to put the header file. This can be local to CSSparser.cpp.
Alexander Pavlov (apavlov)
Comment 6 2011-05-16 04:05:23 PDT
Created attachment 93633 [details] [PATCH] Comments addressed
Alexander Pavlov (apavlov)
Comment 7 2011-05-16 04:06:14 PDT
Comment on attachment 92272 [details] [PATCH] Removed unused field View in context: https://bugs.webkit.org/attachment.cgi?id=92272&action=review >> Source/WebCore/css/CSSParser.cpp:2411 >> + ImplicitScope implicitScope(this, true); > > Can we move this before the switch statement and remove duplication? No, the rule-specified "longhand" properties in a 4-value shorthand (e.g. top right bottom left) are not implicit. >> Source/WebCore/css/CSSParser.h:386 >> + ImplicitScope(CSSParser* parser, bool isImplicit = true) : m_parser(parser) > > Please make it explicit or it looks we don't need the default value for the second parameter. > Also, We don't need to put the header file. This can be local to CSSparser.cpp. Done.
David Levin
Comment 8 2011-05-16 19:36:40 PDT
Comment on attachment 93633 [details] [PATCH] Comments addressed View in context: https://bugs.webkit.org/attachment.cgi?id=93633&action=review > Source/WebCore/css/CSSParser.cpp:98 > + WTF_MAKE_FAST_ALLOCATED; Why are you adding this here? What about non-copyable? > Source/WebCore/css/CSSParser.cpp:100 > + ImplicitScope(WebCore::CSSParser* parser, bool isImplicit) : m_parser(parser) Put initialization for m_parser on a new line. Why pass in isImplicit when it is always true? > Source/WebCore/css/CSSParser.cpp:102 > + m_parser->m_implicitShorthand = isImplicit; It looks like you have a 3 space indent instead of 4 spaces. > Source/WebCore/css/CSSParser.cpp:103 > + } add blank line here.
Alexander Pavlov (apavlov)
Comment 9 2011-05-17 02:05:34 PDT
(In reply to comment #8) > (From update of attachment 93633 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=93633&action=review > > > Source/WebCore/css/CSSParser.cpp:98 > > + WTF_MAKE_FAST_ALLOCATED; > > Why are you adding this here? This class is a replica of ShorthandScope which has this macro. Removed. > What about non-copyable? Added. I'm not sure about the guidelines for both of these macros (are they articulated anywhere?) > > Source/WebCore/css/CSSParser.cpp:100 > > + ImplicitScope(WebCore::CSSParser* parser, bool isImplicit) : m_parser(parser) > > Put initialization for m_parser on a new line. Done. > Why pass in isImplicit when it is always true? I have a followup change that may win a little something with this in place. > > Source/WebCore/css/CSSParser.cpp:102 > > + m_parser->m_implicitShorthand = isImplicit; > > It looks like you have a 3 space indent instead of 4 spaces. Done. > > Source/WebCore/css/CSSParser.cpp:103 > > + } > > add blank line here. Done.
Alexander Pavlov (apavlov)
Comment 10 2011-05-17 02:08:23 PDT
Created attachment 93751 [details] [PATCH] levin's comments addressed
Alexander Pavlov (apavlov)
Comment 11 2011-05-24 03:14:25 PDT
@reviewers: ping?
Alexander Pavlov (apavlov)
Comment 12 2011-05-24 03:16:17 PDT
Reviewers: ping
David Levin
Comment 13 2011-05-24 07:24:05 PDT
Comment on attachment 93751 [details] [PATCH] levin's comments addressed View in context: https://bugs.webkit.org/attachment.cgi?id=93751&action=review > Source/WebCore/css/CSSParser.cpp:100 > + ImplicitScope(WebCore::CSSParser* parser, bool isImplicit) bool isImplicit should be an enum (instead of a bool) because one can't tell at the calling site what it means. For example, when one sees ImplicitScope implicitScope(this, true); It isn't clear what "true" means.
David Levin
Comment 14 2011-05-24 07:27:05 PDT
(In reply to comment #9) > (In reply to comment #8) > > (From update of attachment 93633 [details] [details]) > > View in context: https://bugs.webkit.org/attachment.cgi?id=93633&action=review > > What about non-copyable? > > Added. I'm not sure about the guidelines for both of these macros (are they articulated anywhere?) No idea about WTF_MAKE_FAST_ALLOCATE so I never include it. I leave it up to the people who put it in but i'm pretty sure it is meaningless in this case since it has to do with how the class is allocated (when using new) and this class is only used on the stack. For non-copyable, always add it whenever you can. (Think of it like the equivalent in the Google style guide.)
Alexander Pavlov (apavlov)
Comment 15 2011-05-24 09:48:02 PDT
Created attachment 94630 [details] [PATCH] Enum instead of bool
Darin Adler
Comment 16 2011-05-24 09:51:50 PDT
Comment on attachment 94630 [details] [PATCH] Enum instead of bool View in context: https://bugs.webkit.org/attachment.cgi?id=94630&action=review > Source/WebCore/css/CSSParser.cpp:100 > + enum PropertyType { Making this enum a class member makes the call sites ugly with extra qualification needed. How about just making this a namespace-level enum instead? > Source/WebCore/css/CSSParser.cpp:101 > + PropertyExplicit = 0, Do we really need the "= 0" here? Please omit it. > Source/WebCore/css/CSSParser.cpp:105 > + ImplicitScope(WebCore::CSSParser* parser, PropertyType propertyType) I don’t think we need an argument at all. This class is already named ImplicitScope. I suggest removing the argument completely and just having this set to true. > Source/WebCore/css/CSSParser.cpp:108 > + m_parser->m_implicitShorthand = static_cast<bool>(propertyType); I don’t think the static_cast here is good style. Is it required by some compiler? Actually, I would suggest writing this: m_parser->m_implicitShorthand = propertyType == PropertyImplicit; I think that’s clearer.
Alexander Pavlov (apavlov)
Comment 17 2011-05-24 09:57:25 PDT
Thanks for the review, Darin (In reply to comment #16) > (From update of attachment 94630 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=94630&action=review > > > Source/WebCore/css/CSSParser.cpp:100 > > + enum PropertyType { > > Making this enum a class member makes the call sites ugly with extra qualification needed. How about just making this a namespace-level enum instead? OK > > Source/WebCore/css/CSSParser.cpp:101 > > + PropertyExplicit = 0, > > Do we really need the "= 0" here? Please omit it. This was necessary to clarify the static_cast validity below. > > Source/WebCore/css/CSSParser.cpp:105 > > + ImplicitScope(WebCore::CSSParser* parser, PropertyType propertyType) > > I don’t think we need an argument at all. This class is already named ImplicitScope. I suggest removing the argument completely and just having this set to true. As I mentioned in the #9 comment, I've got a pending patch (https://bugs.webkit.org/attachment.cgi?id=92972) for bug 15598 that will make a good use of this argument (now it uses an ugly solution instead). > > Source/WebCore/css/CSSParser.cpp:108 > > + m_parser->m_implicitShorthand = static_cast<bool>(propertyType); > > I don’t think the static_cast here is good style. Is it required by some compiler? Actually, I would suggest writing this: > > m_parser->m_implicitShorthand = propertyType == PropertyImplicit; > > I think that’s clearer. Makes sense. The sole reason I wrote it this way is that I seem to have seen a similar cast once in the WebKit code (but not sure).
Alexander Pavlov (apavlov)
Comment 18 2011-05-24 10:11:12 PDT
Created attachment 94635 [details] [PATCH] darin@'s comments addressed (parameter retained for reuse by a subsequent patch) The class name "ImplicitScope" denotes the fact that it affects the state of the "implicit" flag used by CSSParser when constructing property instances. Once a property has been determined to be implicit or explicit, the corresponding value can be passed into the ImplicitScope constructor (this is handy for constructing the "font" property longhands).
Alexander Pavlov (apavlov)
Comment 19 2011-05-25 02:37:39 PDT
Note You need to log in before you can comment on or make changes to this bug.