From 896567a22b8597303239ce35fe8c77dc662c9389 Mon Sep 17 00:00:00 2001 From: "sicking%bigfoot.com" Date: Thu, 16 Jan 2003 23:56:58 +0000 Subject: [PATCH] Bug 189201: Hold a reference to the document-node even for embedded stylesheets to make sure that the document doesn't go away. r=peterv sr=bz --- .../source/xslt/txMozillaXSLTProcessor.cpp | 30 +++++++++---------- .../source/xslt/txMozillaXSLTProcessor.h | 1 + 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp b/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp index 9dd386d72ebd..eba74b6e79c3 100644 --- a/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp +++ b/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.cpp @@ -397,11 +397,21 @@ txMozillaXSLTProcessor::ImportStylesheet(nsIDOMNode *aStyle) PRUint16 type = 0; aStyle->GetNodeType(&type); - NS_ENSURE_TRUE(type == nsIDOMNode::ELEMENT_NODE || - type == nsIDOMNode::DOCUMENT_NODE, - NS_ERROR_INVALID_ARG); + switch (type) { + case nsIDOMNode::ELEMENT_NODE: + aStyle->GetOwnerDocument(getter_AddRefs(mStylesheetDocument)); + break; + + case nsIDOMNode::DOCUMENT_NODE: + mStylesheetDocument = do_QueryInterface(aStyle); + break; + + default: + return NS_ERROR_INVALID_ARG; + } mStylesheet = aStyle; + return NS_OK; } @@ -429,12 +439,7 @@ txMozillaXSLTProcessor::TransformToDocument(nsIDOMNode *aSource, NS_ENSURE_TRUE(sourceNode, NS_ERROR_FAILURE); // Create wrapper for the style document. - nsCOMPtr styleDOMDocument; - mStylesheet->GetOwnerDocument(getter_AddRefs(styleDOMDocument)); - if (!styleDOMDocument) { - styleDOMDocument = do_QueryInterface(mStylesheet); - } - Document xslDocument(styleDOMDocument); + Document xslDocument(mStylesheetDocument); // Create a new ProcessorState. Must be done after creating the documents // so that C++ will ensure that it is destroyed before the documents. @@ -502,12 +507,7 @@ txMozillaXSLTProcessor::TransformToFragment(nsIDOMNode *aSource, NS_ENSURE_TRUE(sourceNode, NS_ERROR_FAILURE); // Create wrapper for the style document. - nsCOMPtr styleDOMDocument; - mStylesheet->GetOwnerDocument(getter_AddRefs(styleDOMDocument)); - if (!styleDOMDocument) { - styleDOMDocument = do_QueryInterface(mStylesheet); - } - Document xslDocument(styleDOMDocument); + Document xslDocument(mStylesheetDocument); // Create a new ProcessorState. Must be done after creating the documents // so that C++ will ensure that it is destroyed before the documents. diff --git a/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.h b/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.h index d839c216ce14..dd843ff8a6ed 100644 --- a/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.h +++ b/extensions/transformiix/source/xslt/txMozillaXSLTProcessor.h @@ -140,6 +140,7 @@ public: protected: nsCOMPtr mStylesheet; + nsCOMPtr mStylesheetDocument; txExpandedNameMap mVariables; };