From a0014ac6e9e751f9f9bf68c1a345394bbcfd096f Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 19 Jan 2020 21:22:39 -0500 Subject: Bug 1378079 - Part 3: Complete the steps related to custom elements in "create an element for a token". With fixup for missing header due to unified builds. Tag UXP Issue #1344 --- dom/html/nsHTMLContentSink.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'dom/html/nsHTMLContentSink.cpp') diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index 2827f5ff6..518a3675e 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -255,7 +255,8 @@ DoCustomElementCreate(Element** aElement, nsIDocument* aDoc, nsIAtom* aLocalName nsresult NS_NewHTMLElement(Element** aResult, already_AddRefed&& aNodeInfo, - FromParser aFromParser, const nsAString* aIs) + FromParser aFromParser, const nsAString* aIs, + mozilla::dom::CustomElementDefinition* aDefinition) { *aResult = nullptr; @@ -276,8 +277,8 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& // We only handle the "synchronous custom elements flag is set" now. // For the unset case (e.g. cloning a node), see bug 1319342 for that. // Step 4. - CustomElementDefinition* definition = nullptr; - if (CustomElementRegistry::IsCustomElementEnabled()) { + CustomElementDefinition* definition = aDefinition; + if (!definition && CustomElementRegistry::IsCustomElementEnabled()) { definition = nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(), nodeInfo->LocalName(), @@ -302,9 +303,20 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& bool synchronousCustomElements = aFromParser != dom::FROM_PARSER_FRAGMENT || aFromParser == dom::NOT_FROM_PARSER; // Per discussion in https://github.com/w3c/webcomponents/issues/635, - // use entry global in those places that are called from JS APIs. - nsIGlobalObject* global = GetEntryGlobal(); - MOZ_ASSERT(global); + // use entry global in those places that are called from JS APIs and use the + // node document's global object if it is called from parser. + nsIGlobalObject* global; + if (aFromParser == dom::NOT_FROM_PARSER) { + global = GetEntryGlobal(); + } else { + global = nodeInfo->GetDocument()->GetScopeObject(); + } + if (!global) { + // In browser chrome code, one may have access to a document which doesn't + // have scope object anymore. + return NS_ERROR_FAILURE; + } + AutoEntryScript aes(global, "create custom elements"); JSContext* cx = aes.cx(); ErrorResult rv; @@ -344,6 +356,7 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& // Step 6.2. NS_IF_ADDREF(*aResult = NS_NewHTMLElement(nodeInfo.forget(), aFromParser)); + (*aResult)->SetCustomElementData(new CustomElementData(definition->mType)); nsContentUtils::EnqueueUpgradeReaction(*aResult, definition); return NS_OK; } -- cgit v1.2.3