Bug 1017932. Don't expose the XMLDocument bits on the return value of new Document(). r=peterv

This commit is contained in:
Boris Zbarsky 2014-06-03 11:38:37 -04:00
parent da05bf53a8
commit 8b3fd69b49
6 changed files with 56 additions and 4 deletions

View File

@ -138,7 +138,8 @@ typedef CallbackObjectHolder<NodeFilter, nsIDOMNodeFilter> NodeFilterHolder;
enum DocumentFlavor {
DocumentFlavorLegacyGuess, // compat with old code until made HTML5-compliant
DocumentFlavorHTML, // HTMLDocument with HTMLness bit set to true
DocumentFlavorSVG // SVGDocument
DocumentFlavorSVG, // SVGDocument
DocumentFlavorPlain, // Just a Document
};
// Document states
@ -2685,7 +2686,8 @@ nsresult
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false);
nsresult
NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false);
NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false,
bool aIsPlainDocument = false);
nsresult
NS_NewSVGDocument(nsIDocument** aInstancePtrResult);

View File

@ -12067,7 +12067,7 @@ nsIDocument::Constructor(const GlobalObject& aGlobal,
prin->GetPrincipal(),
true,
global,
DocumentFlavorLegacyGuess);
DocumentFlavorPlain);
if (NS_FAILED(res)) {
rv.Throw(res);
return nullptr;

View File

@ -566,6 +566,7 @@ skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s #bug 904183 # b2g(cl
skip-if = buildapp == 'b2g' || toolkit == 'android' #bug 904183 # b2g(bug 904183) b2g-debug(bug 904183) b2g-desktop(bug 904183)
[test_createHTMLDocument.html]
[test_declare_stylesheet_obsolete.html]
[test_document_constructor.html]
[test_domparser_null_char.html]
[test_domparsing.html]
[test_elementTraversal.html]

View File

@ -0,0 +1,31 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1017932
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1017932</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1017932 **/
var doc = new Document;
ok(doc instanceof Document, "Should have a document");
ok(!(doc instanceof XMLDocument), "Should not be an XMLDocument");
ok(!("load" in doc), "Should not have a load() method");
is(Object.getPrototypeOf(doc), Document.prototype,
"Should have the right proto");
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1017932">Mozilla Bug 1017932</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

View File

@ -50,6 +50,7 @@
#include "mozilla/EventDispatcher.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/XMLDocumentBinding.h"
#include "mozilla/dom/DocumentBinding.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -87,7 +88,10 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
} else if (aFlavor == DocumentFlavorHTML) {
rv = NS_NewHTMLDocument(getter_AddRefs(d));
isHTML = true;
} else if (aFlavor == DocumentFlavorPlain) {
rv = NS_NewXMLDocument(getter_AddRefs(d), aLoadedAsData, true);
} else if (aDoctype) {
MOZ_ASSERT(aFlavor == DocumentFlavorLegacyGuess);
nsAutoString publicId, name;
aDoctype->GetPublicId(publicId);
if (publicId.IsEmpty()) {
@ -117,6 +121,7 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
rv = NS_NewXMLDocument(getter_AddRefs(d));
}
} else {
MOZ_ASSERT(aFlavor == DocumentFlavorLegacyGuess);
rv = NS_NewXMLDocument(getter_AddRefs(d));
}
@ -172,7 +177,8 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
}
nsresult
NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData)
NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData,
bool aIsPlainDocument)
{
nsRefPtr<XMLDocument> doc = new XMLDocument();
@ -184,6 +190,7 @@ NS_NewXMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData)
}
doc->SetLoadedAsData(aLoadedAsData);
doc->mIsPlainDocument = aIsPlainDocument;
doc.forget(aInstancePtrResult);
return NS_OK;
@ -597,6 +604,7 @@ XMLDocument::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
// State from XMLDocument
clone->mAsync = mAsync;
clone->mIsPlainDocument = mIsPlainDocument;
return CallQueryInterface(clone.get(), aResult);
}
@ -604,6 +612,10 @@ XMLDocument::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
JSObject*
XMLDocument::WrapNode(JSContext *aCx)
{
if (mIsPlainDocument) {
return DocumentBinding::Wrap(aCx, this);
}
return XMLDocumentBinding::Wrap(aCx, this);
}

View File

@ -70,6 +70,9 @@ public:
protected:
virtual JSObject* WrapNode(JSContext *aCx) MOZ_OVERRIDE;
friend nsresult (::NS_NewXMLDocument)(nsIDocument**, bool, bool);
// mChannelIsPending indicates whether we're currently asynchronously loading
// data from mChannel (via document.load() or normal load). It's set to true
// when we first find out about the channel (StartDocumentLoad) and set to
@ -79,6 +82,9 @@ protected:
bool mChannelIsPending;
bool mAsync;
bool mLoopingForSyncLoad;
// If true. we're really a Document, not an XMLDocument
bool mIsPlainDocument;
};
} // namespace dom