diff options
author | Gaming4JC <g4jc@hyperbola.info> | 2020-01-03 22:18:55 -0500 |
---|---|---|
committer | Gaming4JC <g4jc@hyperbola.info> | 2020-01-26 15:50:12 -0500 |
commit | 25a33c7123d457a59ecb4b15a2466cfc8507406b (patch) | |
tree | 63a7ed7795fd48dfbe59cdc23738846646e7ce93 /dom/base/CustomElementRegistry.cpp | |
parent | 5cf46e2f87f4f6294d02d96c7905b069c9975eee (diff) | |
download | UXP-25a33c7123d457a59ecb4b15a2466cfc8507406b.tar UXP-25a33c7123d457a59ecb4b15a2466cfc8507406b.tar.gz UXP-25a33c7123d457a59ecb4b15a2466cfc8507406b.tar.lz UXP-25a33c7123d457a59ecb4b15a2466cfc8507406b.tar.xz UXP-25a33c7123d457a59ecb4b15a2466cfc8507406b.zip |
Bug 1347446 - Move custom element reactions stack to DocGroup.
Tag UXP Issue #1344
Diffstat (limited to 'dom/base/CustomElementRegistry.cpp')
-rw-r--r-- | dom/base/CustomElementRegistry.cpp | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index 25267f5d3..1ab566e1d 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -9,6 +9,7 @@ #include "mozilla/dom/CustomElementRegistryBinding.h" #include "mozilla/dom/HTMLElementBinding.h" #include "mozilla/dom/WebComponentsBinding.h" +#include "mozilla/dom/DocGroup.h" #include "nsIParserService.h" #include "jsapi.h" @@ -214,7 +215,6 @@ CustomElementRegistry::sProcessingStack; CustomElementRegistry::CustomElementRegistry(nsPIDOMWindowInner* aWindow) : mWindow(aWindow) , mIsCustomDefinitionRunning(false) - , mIsBackupQueueProcessing(false) { MOZ_ASSERT(aWindow); MOZ_ASSERT(aWindow->IsInnerWindow()); @@ -467,18 +467,27 @@ CustomElementRegistry::GetCustomPrototype(nsIAtom* aAtom, void CustomElementRegistry::UpgradeCandidates(JSContext* aCx, nsIAtom* aKey, - CustomElementDefinition* aDefinition) + CustomElementDefinition* aDefinition, + ErrorResult& aRv) { + DocGroup* docGroup = mWindow->GetDocGroup(); + if (!docGroup) { + aRv.Throw(NS_ERROR_UNEXPECTED); + return; + } + nsAutoPtr<nsTArray<nsWeakPtr>> candidates; mCandidatesMap.RemoveAndForget(aKey, candidates); if (candidates) { + CustomElementReactionsStack* reactionsStack = + docGroup->CustomElementReactionsStack(); for (size_t i = 0; i < candidates->Length(); ++i) { nsCOMPtr<Element> elem = do_QueryReferent(candidates->ElementAt(i)); if (!elem) { continue; } - EnqueueUpgradeReaction(elem, aDefinition); + reactionsStack->EnqueueUpgradeReaction(this, elem, aDefinition); } } } @@ -540,7 +549,13 @@ CustomElementRegistry::Define(const nsAString& aName, { // We do this for [CEReaction] temporarily and it will be removed // after webidl supports [CEReaction] annotation in bug 1309147. - AutoCEReaction ceReaction(this); + DocGroup* docGroup = mWindow->GetDocGroup(); + if (!docGroup) { + aRv.Throw(NS_ERROR_UNEXPECTED); + return; + } + + AutoCEReaction ceReaction(docGroup->CustomElementReactionsStack()); aRv.MightThrowJSException(); AutoJSAPI jsapi; @@ -770,7 +785,7 @@ CustomElementRegistry::Define(const nsAString& aName, * 13. 14. 15. Upgrade candidates */ // TODO: Bug 1299363 - Implement custom element v1 upgrade algorithm - UpgradeCandidates(cx, nameAtom, definition); + UpgradeCandidates(cx, nameAtom, definition, aRv); /** * 16. If this CustomElementRegistry's when-defined promise map contains an @@ -835,13 +850,6 @@ CustomElementRegistry::WhenDefined(const nsAString& aName, ErrorResult& aRv) } void -CustomElementRegistry::EnqueueUpgradeReaction(Element* aElement, - CustomElementDefinition* aDefinition) -{ - Enqueue(aElement, new CustomElementUpgradeReaction(this, aDefinition)); -} - -void CustomElementRegistry::Upgrade(Element* aElement, CustomElementDefinition* aDefinition) { @@ -887,16 +895,18 @@ CustomElementRegistry::Upgrade(Element* aElement, EnqueueLifecycleCallback(nsIDocument::eCreated, aElement, nullptr, aDefinition); } +//----------------------------------------------------- +// CustomElementReactionsStack void -CustomElementRegistry::CreateAndPushElementQueue() +CustomElementReactionsStack::CreateAndPushElementQueue() { // Push a new element queue onto the custom element reactions stack. mReactionsStack.AppendElement(); } void -CustomElementRegistry::PopAndInvokeElementQueue() +CustomElementReactionsStack::PopAndInvokeElementQueue() { // Pop the element queue from the custom element reactions stack, // and invoke custom element reactions in that queue. @@ -904,15 +914,23 @@ CustomElementRegistry::PopAndInvokeElementQueue() "Reaction stack shouldn't be empty"); ElementQueue& elementQueue = mReactionsStack.LastElement(); - CustomElementRegistry::InvokeReactions(elementQueue); + InvokeReactions(elementQueue); DebugOnly<bool> isRemovedElement = mReactionsStack.RemoveElement(elementQueue); MOZ_ASSERT(isRemovedElement, "Reaction stack should have an element queue to remove"); } void -CustomElementRegistry::Enqueue(Element* aElement, - CustomElementReaction* aReaction) +CustomElementReactionsStack::EnqueueUpgradeReaction(CustomElementRegistry* aRegistry, + Element* aElement, + CustomElementDefinition* aDefinition) +{ + Enqueue(aElement, new CustomElementUpgradeReaction(aRegistry, aDefinition)); +} + +void +CustomElementReactionsStack::Enqueue(Element* aElement, + CustomElementReaction* aReaction) { // Add element to the current element queue. if (!mReactionsStack.IsEmpty()) { @@ -943,13 +961,13 @@ CustomElementRegistry::Enqueue(Element* aElement, } void -CustomElementRegistry::InvokeBackupQueue() +CustomElementReactionsStack::InvokeBackupQueue() { - CustomElementRegistry::InvokeReactions(mBackupQueue); + InvokeReactions(mBackupQueue); } void -CustomElementRegistry::InvokeReactions(ElementQueue& aElementQueue) +CustomElementReactionsStack::InvokeReactions(ElementQueue& aElementQueue) { for (uint32_t i = 0; i < aElementQueue.Length(); ++i) { nsCOMPtr<Element> element = do_QueryReferent(aElementQueue[i]); |