Bug 5926 - Assertion failure in HTMLGenericFormElementImpl::removedFromTree
Summary: Assertion failure in HTMLGenericFormElementImpl::removedFromTree
Status: VERIFIED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Nobody
URL: https://tychousa7.umuc.edu/sys/login....
Keywords: HasReduction
Depends on:
Blocks:
 
Reported: 2005-12-03 09:55 PST by Alexey Proskuryakov
Modified: 2006-01-17 09:47 PST (History)
2 users (show)

See Also:


Attachments
Minimal testcase (141 bytes, text/html)
2005-12-23 12:40 PST, Joost de Valk (AlthA)
no flags Details
Proposed patch (6.91 KB, patch)
2005-12-24 11:34 PST, mitz
no flags Details | Formatted Diff | Diff
Reduced testcase that triggers the assert even with the patch (221 bytes, text/html)
2005-12-27 13:34 PST, mitz
no flags Details
Don't assert (1.33 KB, patch)
2005-12-30 08:05 PST, mitz
no flags Details | Formatted Diff | Diff
Corrected patch (1.34 KB, patch)
2005-12-30 14:33 PST, mitz
mjs: review-
Details | Formatted Diff | Diff
Ignore ancestor forms that aren't our form (4.93 KB, patch)
2006-01-16 08:57 PST, mitz
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Proskuryakov 2005-12-03 09:55:59 PST
WebKit/WebCore/khtml/html/html_formimpl.cpp:864: failed assertion `form == m_form'

Steps to reproduce (debug build of ToT):
1. open the bug URL;
2. after it finishes loading, close the window.
Comment 1 Joost de Valk (AlthA) 2005-12-23 12:40:54 PST
Created attachment 5251 [details]
Minimal testcase

This is a minimal testcase for the bug, reload or close the page, and any debug
build wil crash.
Comment 2 Joost de Valk (AlthA) 2005-12-23 12:41:45 PST
changed keyword NeedsReduction to HasReduction :)
Comment 3 mitz 2005-12-24 11:34:47 PST
Created attachment 5271 [details]
Proposed patch
Comment 4 Maciej Stachowiak 2005-12-24 14:24:57 PST
Comment on attachment 5271 [details]
Proposed patch

It's a little ugly for the parser to know about this HTMLGenericFormElementImpl
detail directly. Is it possible for the GenericFormElement itself to detect
that it changed forms? Perhaps it can do something on
removedFromDocument/insertedIntoDocument or something?
Comment 5 mitz 2005-12-24 14:39:57 PST
(In reply to comment #4)
> (From update of attachment 5271 [details] [edit])
> Is it possible for the GenericFormElement itself to detect
> that it changed forms? Perhaps it can do something on
> removedFromDocument/insertedIntoDocument or something?

I tried such an approach, but I couldn't differentiate between "inserted in the right place" and "inserted 
not where it was expected to be inserted" (in both cases insertedIntoDocument is called only once), so I 
ended up calling getForm() every time, which kind of defeats the presumed purpose of passing the 
form to the constructor. Perhaps I didn't try hard enough.
Comment 6 Maciej Stachowiak 2005-12-24 14:42:35 PST
Comment on attachment 5271 [details]
Proposed patch

r=me
Comment 7 mitz 2005-12-27 12:32:44 PST
Comment on attachment 5271 [details]
Proposed patch

The patch fixes the minimal testcase but not the given URL.
Comment 8 Joost de Valk (AlthA) 2005-12-27 12:38:27 PST
I would say, commit the patch, cause it solves a problem, and do not close the bug yet, removing the 
review+ seems a bit harsh.
Comment 9 mitz 2005-12-27 13:34:03 PST
Created attachment 5307 [details]
Reduced testcase that triggers the assert even with the patch

This is different from the previous reduction, in that in this case, the input
element ends up belonging to form B, even though it isn't a descendant of form
B. That's also what Firefox thinks should happen.

However, if the input element were programatically inserted at the same place,
then getForm() would be used and it would end up belonging to its ancestor,
form A. Firefox says so too.

I see four options:
1) Decide that the above (Firefox-compatible) behavior is correct, and remove
the assert.
2) Decide that the above (Firefox-compatible) behavior is correct, add have the
parser set some flag(s) on the inputElement to bypass the assert in this
special case.
3) Decide that the above logic is incorrect, and change getForm() to answer
"which form would the parser associate this input element with if it were here
in the first place" (if the question has meaning, and if it's even possible to
answer, it probably involves traversing the entire DOM tree).
4) Decide that the above logic is incorrect, and an input element's form should
always be its ancestor.
Comment 10 mitz 2005-12-27 13:45:46 PST
Hmm... I checked what Firefox has to say about the original testcase, and even though it gives the same 
DOM tree as WebKit, where the input element is a direct descendant of form A, its form is form B. So I 
guess the Firefox logic when parsing is like WebKit's w/o the "proposed patch", which means that option 
1) above should say "...remove the assert and don't apply the 'proposed patch'" and that the only other 
option that makes sense is option 4).
Comment 11 mitz 2005-12-30 08:05:59 PST
Created attachment 5385 [details]
Don't assert

According to Dave Hyatt on IRC, the assert should be yanked.
Comment 12 mitz 2005-12-30 14:31:55 PST
Comment on attachment 5385 [details]
Don't assert

I mistakenly deleted the } before the else too. That doesn't even compile!
Comment 13 mitz 2005-12-30 14:33:53 PST
Created attachment 5388 [details]
Corrected patch
Comment 14 mitz 2005-12-30 14:34:18 PST
Comment on attachment 5388 [details]
Corrected patch

Added missing curly brace
Comment 15 Geoffrey Garen 2005-12-30 15:09:44 PST
Comment on attachment 5388 [details]
Corrected patch

Dave?
Comment 16 Darin Adler 2005-12-30 16:17:24 PST
Comment on attachment 5388 [details]
Corrected patch

I don't think it's right to just remove this assert. It's possible that a form
element is being removed from the DOM tree along with a form that it's nested
inside. The form the element is attached to is still in the main document's DOM
tree. This code will discover the form that's being removed along with the
node, but will leave the form element attached to the form still in the main
document. This is not a good state -- the form from the main document has an
element attached to it that's no longer in the document at all.
Comment 17 Maciej Stachowiak 2006-01-02 20:35:16 PST
Moving to r- until Darin's comment is addressed.
Comment 18 mitz 2006-01-16 08:57:17 PST
Created attachment 5719 [details]
Ignore ancestor forms that aren't our form
Comment 19 Darin Adler 2006-01-17 00:28:30 PST
Comment on attachment 5719 [details]
Ignore ancestor forms that aren't our form

Looks fine, r=me.