Bug 102765 - Remove unneeded null check in NodeRendererFactory::createRendererIfNeeded
Summary: Remove unneeded null check in NodeRendererFactory::createRendererIfNeeded
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Elliott Sprehn
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-19 21:29 PST by Elliott Sprehn
Modified: 2012-11-19 22:29 PST (History)
6 users (show)

See Also:


Attachments
Patch (2.03 KB, patch)
2012-11-19 21:36 PST, Elliott Sprehn
no flags Details | Formatted Diff | Diff
Patch for landing (2.09 KB, patch)
2012-11-19 22:06 PST, Elliott Sprehn
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Elliott Sprehn 2012-11-19 21:29:38 PST
Remove unneeded null check in NodeRendererFactory::createRendererIfNeeded
Comment 1 Elliott Sprehn 2012-11-19 21:36:03 PST
Created attachment 175136 [details]
Patch
Comment 2 Ojan Vafai 2012-11-19 21:49:55 PST
Comment on attachment 175136 [details]
Patch

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

> Source/WebCore/dom/NodeRenderingContext.cpp:255
> +    ASSERT(m_context.parentRenderer());

Can you move this line to be above the if/else. It makes more sense to me to assert before the line that depends on the assert.
Comment 3 Ojan Vafai 2012-11-19 21:50:11 PST
Actually, even better, but it directly in the else statement.
Comment 4 Brent Fulgham 2012-11-19 21:53:07 PST
I was about to r- because I think the ASSERTs should be positioned higher in the code flow, but Ojan beat me to it.

If m_context.parentRenderer() might ever ASSERT, then it's possible the new code will blow up before having a chance to assert.

I also had a question about the behavior of parentRenderer(), which I think is probably NOT a problem, but I'd feel better if you confirmed it.

> Source/WebCore/ChangeLog:10
> +        so there's no reason to check for it again.

Is it possible for parentRenderer() to return null, but parentFlowRenderer to be non-null?  From a brief look it seems like the answer is no.  But if I'm wrong, this change would modify the behavior.  Can you please confirm that this is not a problem?
Comment 5 Elliott Sprehn 2012-11-19 21:57:15 PST
(In reply to comment #3)
> Actually, even better, but it directly in the else statement.

I'm not actually asserting about the line in the else, I'm asserting about the rendererIsNeeded() on the following line after the assert. Calling that method on a context that doesn't have a style or a parentRenderer is always a mistake.

Also if I put it in the else it makes it look like if  isElementNode() is true and we don't go down the else that we may not have a renderer (which is never true). Also if we do go through that else we'll crash on the null dereference so there's no reason to ASSERT about it.
Comment 6 Elliott Sprehn 2012-11-19 22:01:41 PST
(In reply to comment #4)
> I was about to r- because I think the ASSERTs should be positioned higher in the code flow, but Ojan beat me to it.
> 
> If m_context.parentRenderer() might ever ASSERT, then it's possible the new code will blow up before having a chance to assert.

Yes, that was intended. We do this all over webkit, and it's even been requested by Apple on my patches before that I NOT assert about nulls and instead just let the program crash the null dereference.

> 
> I also had a question about the behavior of parentRenderer(), which I think is probably NOT a problem, but I'd feel better if you confirmed it.
> 
> > Source/WebCore/ChangeLog:10
> > +        so there's no reason to check for it again.
> 
> Is it possible for parentRenderer() to return null, but parentFlowRenderer to be non-null?  From a brief look it seems like the answer is no.  But if I'm wrong, this change would modify the behavior.  Can you please confirm that this is not a problem?

I don't understand what you're asking. parentRenderer never returns null in this code path because shouldCreateRenderer would have returned before we got here. There's no behavior change.
Comment 7 Elliott Sprehn 2012-11-19 22:06:19 PST
Created attachment 175138 [details]
Patch for landing
Comment 8 Elliott Sprehn 2012-11-19 22:06:45 PST
(In reply to comment #7)
> Created an attachment (id=175138) [details]
> Patch for landing

I moved the assert bove the if/else.
Comment 9 Brent Fulgham 2012-11-19 22:11:46 PST
(In reply to comment #6)
> (In reply to comment #4)
> > Is it possible for parentRenderer() to return null, but parentFlowRenderer to be non-null?  From a brief look it seems like the answer is no.  But if I'm wrong, this change would modify the behavior.  Can you please confirm that this is not a problem?
> 
> I don't understand what you're asking. parentRenderer never returns null in this code path because shouldCreateRenderer would have returned before we got here. There's no behavior change.

I actually went and looked at the routine, and see that you are correct.  Thanks!
Comment 10 WebKit Review Bot 2012-11-19 22:29:35 PST
Comment on attachment 175138 [details]
Patch for landing

Clearing flags on attachment: 175138

Committed r135252: <http://trac.webkit.org/changeset/135252>
Comment 11 WebKit Review Bot 2012-11-19 22:29:39 PST
All reviewed patches have been landed.  Closing bug.