Issue #2135 - Bug 1393806/Part 2: Modify AdoptNodeIntoOwnerDoc to use the non-XPCOM version of document.AdoptNode

* Unlike the original patch, this does not remove the XPCOM version of Document.adoptNode/importNode to avoid breaking other applications that might be using those functions.
This commit is contained in:
FranklinDM 2023-03-04 17:15:04 +08:00 • committed by roytam1
commit 3062964d28

View file

@ -1563,20 +1563,16 @@ AdoptNodeIntoOwnerDoc(nsINode *aParent, nsINode *aNode)
nsIDocument *doc = aParent->OwnerDoc(); nsIDocument *doc = aParent->OwnerDoc();
nsresult rv; ErrorResult rv;
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(doc, &rv); nsINode* adoptedNode = doc->AdoptNode(*aNode, rv);
NS_ENSURE_SUCCESS(rv, rv); rv.WouldReportJSException();
if (NS_WARN_IF(rv.Failed())) {
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode, &rv); return rv.StealNSResult();
NS_ENSURE_SUCCESS(rv, rv); }
nsCOMPtr<nsIDOMNode> adoptedNode;
rv = domDoc->AdoptNode(node, getter_AddRefs(adoptedNode));
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(aParent->OwnerDoc() == doc, NS_ASSERTION(aParent->OwnerDoc() == doc,
"ownerDoc chainged while adopting"); "ownerDoc chainged while adopting");
NS_ASSERTION(adoptedNode == node, "Uh, adopt node changed nodes?"); NS_ASSERTION(adoptedNode == aNode, "Uh, adopt node changed nodes?");
NS_ASSERTION(aParent->OwnerDoc() == aNode->OwnerDoc(), NS_ASSERTION(aParent->OwnerDoc() == aNode->OwnerDoc(),
"ownerDocument changed again after adopting!"); "ownerDocument changed again after adopting!");