forked from mirrors/gecko-dev
Bug 1941002 - Clone source. r=smaug a=pascalc
Differential Revision: https://phabricator.services.mozilla.com/D235577
This commit is contained in:
parent
b4bc1a7836
commit
c876e3e97c
4 changed files with 26 additions and 9 deletions
|
|
@ -80,7 +80,7 @@ nsresult nsXMLPrettyPrinter::PrettyPrint(Document* aDocument,
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<DocumentFragment> resultFragment =
|
RefPtr<DocumentFragment> resultFragment =
|
||||||
transformer->TransformToFragment(*aDocument, *aDocument, err);
|
transformer->TransformToFragment(*aDocument, false, *aDocument, err);
|
||||||
if (NS_WARN_IF(err.Failed())) {
|
if (NS_WARN_IF(err.Failed())) {
|
||||||
return err.StealNSResult();
|
return err.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -479,7 +479,7 @@ static nsresult handleNode(nsINode* aNode, txStylesheetCompiler* aCompiler) {
|
||||||
// explicitly destroy the attrs here since we no longer need it
|
// explicitly destroy the attrs here since we no longer need it
|
||||||
atts = nullptr;
|
atts = nullptr;
|
||||||
|
|
||||||
for (nsIContent* child = element->GetFirstChild(); child;
|
for (nsCOMPtr<nsIContent> child = element->GetFirstChild(); child;
|
||||||
child = child->GetNextSibling()) {
|
child = child->GetNextSibling()) {
|
||||||
rv = handleNode(child, aCompiler);
|
rv = handleNode(child, aCompiler);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
@ -493,7 +493,7 @@ static nsresult handleNode(nsINode* aNode, txStylesheetCompiler* aCompiler) {
|
||||||
rv = aCompiler->characters(chars);
|
rv = aCompiler->characters(chars);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
} else if (aNode->IsDocument()) {
|
} else if (aNode->IsDocument()) {
|
||||||
for (nsIContent* child = aNode->GetFirstChild(); child;
|
for (nsCOMPtr<nsIContent> child = aNode->GetFirstChild(); child;
|
||||||
child = child->GetNextSibling()) {
|
child = child->GetNextSibling()) {
|
||||||
rv = handleNode(child, aCompiler);
|
rv = handleNode(child, aCompiler);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
|
||||||
|
|
@ -553,7 +553,10 @@ already_AddRefed<Document> txMozillaXSLTProcessor::TransformToDocument(
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
mSource = &aSource;
|
mSource = aSource.CloneNode(true, aRv);
|
||||||
|
if (aRv.Failed()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<Document> doc;
|
nsCOMPtr<Document> doc;
|
||||||
rv = TransformToDoc(getter_AddRefs(doc), true);
|
rv = TransformToDoc(getter_AddRefs(doc), true);
|
||||||
|
|
@ -721,7 +724,7 @@ nsresult txMozillaXSLTProcessor::TransformToDoc(Document** aResult,
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<DocumentFragment> txMozillaXSLTProcessor::TransformToFragment(
|
already_AddRefed<DocumentFragment> txMozillaXSLTProcessor::TransformToFragment(
|
||||||
nsINode& aSource, Document& aOutput, ErrorResult& aRv) {
|
nsINode& aSource, bool aCloneSource, Document& aOutput, ErrorResult& aRv) {
|
||||||
if (NS_WARN_IF(NS_FAILED(mCompileResult))) {
|
if (NS_WARN_IF(NS_FAILED(mCompileResult))) {
|
||||||
aRv.Throw(mCompileResult);
|
aRv.Throw(mCompileResult);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -741,8 +744,17 @@ already_AddRefed<DocumentFragment> txMozillaXSLTProcessor::TransformToFragment(
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
UniquePtr<txXPathNode> sourceNode(
|
nsCOMPtr<nsINode> source;
|
||||||
txXPathNativeNode::createXPathNode(&aSource));
|
if (aCloneSource) {
|
||||||
|
source = aSource.CloneNode(true, aRv);
|
||||||
|
if (aRv.Failed()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
source = &aSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
UniquePtr<txXPathNode> sourceNode(txXPathNativeNode::createXPathNode(source));
|
||||||
if (!sourceNode) {
|
if (!sourceNode) {
|
||||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -1049,7 +1061,7 @@ nsresult txMozillaXSLTProcessor::ensureStylesheet() {
|
||||||
|
|
||||||
NS_ENSURE_TRUE(mStylesheetDocument, NS_ERROR_NOT_INITIALIZED);
|
NS_ENSURE_TRUE(mStylesheetDocument, NS_ERROR_NOT_INITIALIZED);
|
||||||
|
|
||||||
nsINode* style = mEmbeddedStylesheetRoot;
|
nsCOMPtr<nsINode> style = mEmbeddedStylesheetRoot;
|
||||||
if (!style) {
|
if (!style) {
|
||||||
style = mStylesheetDocument;
|
style = mStylesheetDocument;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,12 @@ class txMozillaXSLTProcessor final : public nsIDocumentTransformer,
|
||||||
|
|
||||||
void ImportStylesheet(nsINode& stylesheet, mozilla::ErrorResult& aRv);
|
void ImportStylesheet(nsINode& stylesheet, mozilla::ErrorResult& aRv);
|
||||||
already_AddRefed<mozilla::dom::DocumentFragment> TransformToFragment(
|
already_AddRefed<mozilla::dom::DocumentFragment> TransformToFragment(
|
||||||
nsINode& source, mozilla::dom::Document& docVal,
|
nsINode& aSource, mozilla::dom::Document& aDocument,
|
||||||
|
mozilla::ErrorResult& aRv) {
|
||||||
|
return TransformToFragment(aSource, true, aDocument, aRv);
|
||||||
|
}
|
||||||
|
already_AddRefed<mozilla::dom::DocumentFragment> TransformToFragment(
|
||||||
|
nsINode& aSource, bool aCloneSource, mozilla::dom::Document& aOutput,
|
||||||
mozilla::ErrorResult& aRv);
|
mozilla::ErrorResult& aRv);
|
||||||
already_AddRefed<mozilla::dom::Document> TransformToDocument(
|
already_AddRefed<mozilla::dom::Document> TransformToDocument(
|
||||||
nsINode& source, mozilla::ErrorResult& aRv);
|
nsINode& source, mozilla::ErrorResult& aRv);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue