diff options
author | Gaming4JC <g4jc@hyperbola.info> | 2020-01-05 10:26:29 -0500 |
---|---|---|
committer | Gaming4JC <g4jc@hyperbola.info> | 2020-01-26 15:50:22 -0500 |
commit | 32f1ff0f8d3bf009f4e7b57dc75e86b5220f86ed (patch) | |
tree | 97eb8652cf43caa495e8999e2876a1745f1b30ea | |
parent | 53c9b77ed41aebb157012eff5e57cad3a962d18e (diff) | |
download | uxp-32f1ff0f8d3bf009f4e7b57dc75e86b5220f86ed.tar.gz |
Bug 1299363 - Part 1: Implement construction stack.
Tag UXP Issue #1344
-rw-r--r-- | dom/base/CustomElementRegistry.h | 6 | ||||
-rw-r--r-- | dom/bindings/BindingUtils.cpp | 37 |
2 files changed, 30 insertions, 13 deletions
diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h index 33f2a95ff6..84a7fe3acb 100644 --- a/dom/base/CustomElementRegistry.h +++ b/dom/base/CustomElementRegistry.h @@ -106,6 +106,8 @@ private: virtual ~CustomElementData() {} }; +#define ALEADY_CONSTRUCTED_MARKER nullptr + // The required information for a custom element as defined in: // https://html.spec.whatwg.org/multipage/scripting.html#custom-element-definition struct CustomElementDefinition @@ -132,8 +134,8 @@ struct CustomElementDefinition // The lifecycle callbacks to call for this custom element. UniquePtr<mozilla::dom::LifecycleCallbacks> mCallbacks; - // A construction stack. - // TODO: Bug 1287348 - Implement construction stack for upgrading an element + // A construction stack. Use nullptr to represent an "already constructed marker". + nsTArray<RefPtr<nsGenericHTMLElement>> mConstructionStack; // The document custom element order. uint32_t mDocOrder; diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 6c35da05ea..4d20a95f70 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -3539,20 +3539,35 @@ CreateHTMLElement(const GlobalObject& aGlobal, const JS::CallArgs& aCallArgs, // Step 6 and Step 7 are in the code output by CGClassConstructor. // Step 8. - // Construction stack will be implemented in bug 1287348. So we always run - // "construction stack is empty" case for now. - RefPtr<nsGenericHTMLElement> element; - if (tag == eHTMLTag_userdefined) { - // Autonomous custom element. - element = NS_NewHTMLElement(nodeInfo.forget()); - } else { - // Customized built-in element. - element = CreateHTMLElement(tag, nodeInfo.forget(), NOT_FROM_PARSER); + nsTArray<RefPtr<nsGenericHTMLElement>>& constructionStack = + definition->mConstructionStack; + if (constructionStack.IsEmpty()) { + RefPtr<nsGenericHTMLElement> newElement; + if (tag == eHTMLTag_userdefined) { + // Autonomous custom element. + newElement = NS_NewHTMLElement(nodeInfo.forget()); + } else { + // Customized built-in element. + newElement = CreateHTMLElement(tag, nodeInfo.forget(), NOT_FROM_PARSER); + } + + newElement->SetCustomElementData( + new CustomElementData(definition->mType, CustomElementData::State::eCustom)); + + return newElement.forget(); } - element->SetCustomElementData( - new CustomElementData(definition->mType, CustomElementData::State::eCustom)); + // Step 9. + RefPtr<nsGenericHTMLElement>& element = constructionStack.LastElement(); + + // Step 10. + if (element == ALEADY_CONSTRUCTED_MARKER) { + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return nullptr; + } + // Step 11 is in the code output by CGClassConstructor. + // Step 12 and Step 13. return element.forget(); } |