From 4dda3f6039c4432a3545986ebc698a725c6c057c Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 5 Jan 2020 18:38:55 -0500 Subject: Bug 1406297 - Fix Document.createElement must report an exception. Tag UXP Issue #1344 --- dom/base/CustomElementRegistry.cpp | 4 +--- dom/html/nsHTMLContentSink.cpp | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'dom') diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index bad100cf5..7fd295201 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -111,13 +111,11 @@ CustomElementConstructor::Construct(const char* aExecutionReason, JS::Rooted result(cx); JS::Rooted constructor(cx, JS::ObjectValue(*mCallback)); if (!JS::Construct(cx, constructor, JS::HandleValueArray::empty(), &result)) { - aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return nullptr; } RefPtr element; if (NS_FAILED(UNWRAP_OBJECT(Element, &result, element))) { - aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return nullptr; } @@ -894,7 +892,7 @@ DoUpgrade(Element* aElement, return; } - if (constructResult.get() != aElement) { + if (!constructResult || constructResult.get() != aElement) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index ef160cf21..87ae2a4ac 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -233,18 +233,23 @@ public: }; static void -DoCustomElementCreate(Element** aElement, nsIDocument* aDoc, +DoCustomElementCreate(Element** aElement, nsIDocument* aDoc, nsIAtom* aLocalName, CustomElementConstructor* aConstructor, ErrorResult& aRv) { RefPtr element = aConstructor->Construct("Custom Element Create", aRv); - if (aRv.Failed() || !element->IsHTMLElement()) { + if (aRv.Failed()) { + return; + } + + if (!element || !element->IsHTMLElement()) { aRv.ThrowTypeError(NS_LITERAL_STRING("HTMLElement")); return; } if (aDoc != element->OwnerDoc() || element->GetParentNode() || - element->HasChildren() || element->GetAttrCount()) { + element->HasChildren() || element->GetAttrCount() || + element->NodeInfo()->NameAtom() != aLocalName) { aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return; } @@ -320,19 +325,20 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& (*aResult)->SetCustomElementData(new CustomElementData(typeAtom)); if (synchronousCustomElements) { CustomElementRegistry::Upgrade(*aResult, definition, rv); + if (rv.MaybeSetPendingException(cx)) { + aes.ReportException(); + } } else { nsContentUtils::EnqueueUpgradeReaction(*aResult, definition); } - if (rv.MaybeSetPendingException(cx)) { - aes.ReportException(); - } return NS_OK; } // Step 6.1. if (synchronousCustomElements) { DoCustomElementCreate(aResult, nodeInfo->GetDocument(), + nodeInfo->NameAtom(), definition->mConstructor, rv); if (rv.MaybeSetPendingException(cx)) { NS_IF_ADDREF(*aResult = NS_NewHTMLUnknownElement(nodeInfo.forget(), aFromParser)); -- cgit v1.2.3