diff --git a/dom/html/HTMLImageElement.cpp b/dom/html/HTMLImageElement.cpp index 4dd46f5a0e..05bfa01e43 100644 --- a/dom/html/HTMLImageElement.cpp +++ b/dom/html/HTMLImageElement.cpp @@ -876,20 +876,12 @@ HTMLImageElement::WrapNode(JSContext* aCx, JS::Handle aGivenProto) return HTMLImageElementBinding::Wrap(aCx, this, aGivenProto); } -#ifdef DEBUG -nsIDOMHTMLFormElement* -HTMLImageElement::GetForm() const -{ - return mForm; -} -#endif - void HTMLImageElement::SetForm(nsIDOMHTMLFormElement* aForm) { NS_PRECONDITION(aForm, "Don't pass null here"); - NS_ASSERTION(!mForm, - "We don't support switching from one non-null form to another."); + MOZ_ASSERT(!mForm && !HasFlag(ADDED_TO_FORM), + "We don't support switching from one non-null form to another."); mForm = static_cast(aForm); } diff --git a/dom/html/HTMLImageElement.h b/dom/html/HTMLImageElement.h index 2c184d26d9..d85f7cfb03 100644 --- a/dom/html/HTMLImageElement.h +++ b/dom/html/HTMLImageElement.h @@ -216,9 +216,8 @@ public: SetHTMLAttr(nsGkAtoms::lowsrc, aLowsrc, aError); } -#ifdef DEBUG - nsIDOMHTMLFormElement* GetForm() const; -#endif + HTMLFormElement* GetForm() const { return mForm; }; + void SetForm(nsIDOMHTMLFormElement* aForm); void ClearForm(bool aRemoveFromForm); diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index ba9db1febd..03b0da8265 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -1824,8 +1824,8 @@ void nsGenericHTMLFormElement::SetForm(nsIDOMHTMLFormElement* aForm) { NS_PRECONDITION(aForm, "Don't pass null here"); - NS_ASSERTION(!mForm, - "We don't support switching from one non-null form to another."); + MOZ_ASSERT(!mForm && !HasFlag(ADDED_TO_FORM), + "We don't support switching from one non-null form to another."); // keep a *weak* ref to the form here mForm = static_cast(aForm); diff --git a/parser/html/nsHtml5TreeOperation.cpp b/parser/html/nsHtml5TreeOperation.cpp index 634c0b0a18..b399210aaf 100644 --- a/parser/html/nsHtml5TreeOperation.cpp +++ b/parser/html/nsHtml5TreeOperation.cpp @@ -704,7 +704,9 @@ nsHtml5TreeOperation::SetFormElement(nsIContent* aNode, nsIContent* aParent) RefPtr imageElement = static_cast(domImageElement.get()); MOZ_ASSERT(imageElement); - imageElement->SetForm(formElement); + if (!imageElement->GetForm()) { + imageElement->SetForm(formElement); + } } }