Bug 1338889 - Part 2: Support DOMString as Argument 3 of Document.createElementNS. r=bz, a=jcristau
From b8b1ffc85a0b13ca873b07069affcc39489ff99d Mon Sep 17 00:00:00 2001
Document.createElementNS. r=bz
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -5530,45 +5530,50 @@ nsDocument::CreateElement(const nsAStrin
}
NS_IMETHODIMP
nsDocument::CreateElementNS(const nsAString& aNamespaceURI,
const nsAString& aQualifiedName,
nsIDOMElement** aReturn)
{
*aReturn = nullptr;
- ElementCreationOptions options;
+ ElementCreationOptionsOrString options;
+
+ options.SetAsString();
ErrorResult rv;
nsCOMPtr<Element> element =
CreateElementNS(aNamespaceURI, aQualifiedName, options, rv);
NS_ENSURE_FALSE(rv.Failed(), rv.StealNSResult());
return CallQueryInterface(element, aReturn);
}
already_AddRefed<Element>
nsDocument::CreateElementNS(const nsAString& aNamespaceURI,
const nsAString& aQualifiedName,
- const ElementCreationOptions& aOptions,
+ const ElementCreationOptionsOrString& aOptions,
ErrorResult& rv)
{
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
rv = nsContentUtils::GetNodeInfoFromQName(aNamespaceURI,
aQualifiedName,
mNodeInfoManager,
nsIDOMNode::ELEMENT_NODE,
getter_AddRefs(nodeInfo));
if (rv.Failed()) {
return nullptr;
}
- // Throw NotFoundError if 'is' is not-null and definition is null
- const nsString* is = CheckCustomElementName(
- aOptions, aQualifiedName, nodeInfo->NamespaceID(), rv);
- if (rv.Failed()) {
- return nullptr;
+ const nsString* is = nullptr;
+ if (aOptions.IsElementCreationOptions()) {
+ // Throw NotFoundError if 'is' is not-null and definition is null
+ is = CheckCustomElementName(aOptions.GetAsElementCreationOptions(),
+ aQualifiedName, nodeInfo->NamespaceID(), rv);
+ if (rv.Failed()) {
+ return nullptr;
+ }
}
nsCOMPtr<Element> element;
rv = NS_NewElement(getter_AddRefs(element), nodeInfo.forget(),
NOT_FROM_PARSER, is);
if (rv.Failed()) {
return nullptr;
}
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -1135,17 +1135,17 @@ public:
virtual void GetLastStyleSheetSet(nsString& aSheetSet) override;
virtual mozilla::dom::DOMStringList* StyleSheetSets() override;
virtual void EnableStyleSheetsForSet(const nsAString& aSheetSet) override;
virtual already_AddRefed<Element> CreateElement(const nsAString& aTagName,
const mozilla::dom::ElementCreationOptionsOrString& aOptions,
ErrorResult& rv) override;
virtual already_AddRefed<Element> CreateElementNS(const nsAString& aNamespaceURI,
const nsAString& aQualifiedName,
- const mozilla::dom::ElementCreationOptions& aOptions,
+ const mozilla::dom::ElementCreationOptionsOrString& aOptions,
mozilla::ErrorResult& rv) override;
virtual nsIDocument* MasterDocument() override
{
return mMasterDocument ? mMasterDocument.get()
: this;
}
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -2607,17 +2607,17 @@ public:
// GetElementById defined above
virtual already_AddRefed<Element>
CreateElement(const nsAString& aTagName,
const mozilla::dom::ElementCreationOptionsOrString& aOptions,
mozilla::ErrorResult& rv) = 0;
virtual already_AddRefed<Element>
CreateElementNS(const nsAString& aNamespaceURI,
const nsAString& aQualifiedName,
- const mozilla::dom::ElementCreationOptions& aOptions,
+ const mozilla::dom::ElementCreationOptionsOrString& aOptions,
mozilla::ErrorResult& rv) = 0;
already_AddRefed<mozilla::dom::DocumentFragment>
CreateDocumentFragment() const;
already_AddRefed<nsTextNode> CreateTextNode(const nsAString& aData) const;
already_AddRefed<mozilla::dom::Comment>
CreateComment(const nsAString& aData) const;
already_AddRefed<mozilla::dom::ProcessingInstruction>
CreateProcessingInstruction(const nsAString& target, const nsAString& data,
--- a/dom/webidl/Document.webidl
+++ b/dom/webidl/Document.webidl
@@ -50,17 +50,17 @@ interface Document : Node {
[Pure]
HTMLCollection getElementsByClassName(DOMString classNames);
[Pure]
Element? getElementById(DOMString elementId);
[NewObject, Throws]
Element createElement(DOMString localName, optional (ElementCreationOptions or DOMString) options);
[NewObject, Throws]
- Element createElementNS(DOMString? namespace, DOMString qualifiedName, optional ElementCreationOptions options);
+ Element createElementNS(DOMString? namespace, DOMString qualifiedName, optional (ElementCreationOptions or DOMString) options);
[NewObject]
DocumentFragment createDocumentFragment();
[NewObject]
Text createTextNode(DOMString data);
[NewObject]
Comment createComment(DOMString data);
[NewObject, Throws]
ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data);
--- a/dom/xml/XMLDocument.cpp
+++ b/dom/xml/XMLDocument.cpp
@@ -159,19 +159,21 @@ NS_NewDOMDocument(nsIDOMDocument** aInst
d->AppendChild(*doctypeAsNode, result);
if (NS_WARN_IF(result.Failed())) {
return result.StealNSResult();
}
}
if (!aQualifiedName.IsEmpty()) {
ErrorResult result;
+ ElementCreationOptionsOrString options;
+ options.SetAsString();
+
nsCOMPtr<Element> root =
- doc->CreateElementNS(aNamespaceURI, aQualifiedName,
- ElementCreationOptions(), result);
+ doc->CreateElementNS(aNamespaceURI, aQualifiedName, options, result);
if (NS_WARN_IF(result.Failed())) {
return result.StealNSResult();
}
d->AppendChild(*root, result);
if (NS_WARN_IF(result.Failed())) {
return result.StealNSResult();
}
--- a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
+++ b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
@@ -1131,19 +1131,22 @@ txMozillaXSLTProcessor::notifyError()
MOZ_ASSERT(document->GetReadyStateEnum() ==
nsIDocument::READYSTATE_UNINITIALIZED,
"Bad readyState.");
document->SetReadyStateInternal(nsIDocument::READYSTATE_LOADING);
NS_NAMED_LITERAL_STRING(ns, "http://www.mozilla.org/newlayout/xml/parsererror.xml");
IgnoredErrorResult rv;
+ ElementCreationOptionsOrString options;
+ options.SetAsString();
+
nsCOMPtr<Element> element =
document->CreateElementNS(ns, NS_LITERAL_STRING("parsererror"),
- ElementCreationOptions(), rv);
+ options, rv);
if (rv.Failed()) {
return;
}
document->AppendChild(*element, rv);
if (rv.Failed()) {
return;
}
@@ -1151,19 +1154,22 @@ txMozillaXSLTProcessor::notifyError()
RefPtr<nsTextNode> text = document->CreateTextNode(mErrorText);
element->AppendChild(*text, rv);
if (rv.Failed()) {
return;
}
if (!mSourceText.IsEmpty()) {
+ ElementCreationOptionsOrString options;
+ options.SetAsString();
+
nsCOMPtr<Element> sourceElement =
document->CreateElementNS(ns, NS_LITERAL_STRING("sourcetext"),
- ElementCreationOptions(), rv);
+ options, rv);
if (rv.Failed()) {
return;
}
element->AppendChild(*sourceElement, rv);
if (rv.Failed()) {
return;
}