Bug 1421544 - Lazy push/pop CustomElementReactionsStack entry;

Tag UXP Issue #1344
This commit is contained in:
Gaming4JC 2020-01-25 08:59:17 -05:00 committed by Roy Tam
commit a6339bef90
2 changed files with 96 additions and 19 deletions

View file

@ -951,18 +951,24 @@ CustomElementRegistry::Upgrade(Element* aElement,
void
CustomElementReactionsStack::CreateAndPushElementQueue()
{
MOZ_ASSERT(mRecursionDepth);
MOZ_ASSERT(!mIsElementQueuePushedForCurrentRecursionDepth);
// Push a new element queue onto the custom element reactions stack.
mReactionsStack.AppendElement(MakeUnique<ElementQueue>());
mIsElementQueuePushedForCurrentRecursionDepth = true;
}
void
CustomElementReactionsStack::PopAndInvokeElementQueue()
{
// Pop the element queue from the custom element reactions stack,
// and invoke custom element reactions in that queue.
MOZ_ASSERT(mRecursionDepth);
MOZ_ASSERT(mIsElementQueuePushedForCurrentRecursionDepth);
MOZ_ASSERT(!mReactionsStack.IsEmpty(),
"Reaction stack shouldn't be empty");
// Pop the element queue from the custom element reactions stack,
// and invoke custom element reactions in that queue.
const uint32_t lastIndex = mReactionsStack.Length() - 1;
ElementQueue* elementQueue = mReactionsStack.ElementAt(lastIndex).get();
// Check element queue size in order to reduce function call overhead.
@ -986,6 +992,7 @@ CustomElementReactionsStack::PopAndInvokeElementQueue()
"reactions created by InvokeReactions() should be consumed and removed");
mReactionsStack.RemoveElementAt(lastIndex);
mIsElementQueuePushedForCurrentRecursionDepth = false;
}
void
@ -1009,8 +1016,15 @@ CustomElementReactionsStack::Enqueue(Element* aElement,
RefPtr<CustomElementData> elementData = aElement->GetCustomElementData();
MOZ_ASSERT(elementData, "CustomElementData should exist");
// Add element to the current element queue.
if (!mReactionsStack.IsEmpty()) {
if (mRecursionDepth) {
// If the element queue is not created for current recursion depth, create
// and push an element queue to reactions stack first.
if (!mIsElementQueuePushedForCurrentRecursionDepth) {
CreateAndPushElementQueue();
}
MOZ_ASSERT(!mReactionsStack.IsEmpty());
// Add element to the current element queue.
mReactionsStack.LastElement()->AppendElement(aElement);
elementData->mReactionQueue.AppendElement(aReaction);
return;
@ -1018,6 +1032,8 @@ CustomElementReactionsStack::Enqueue(Element* aElement,
// If the custom element reactions stack is empty, then:
// Add element to the backup element queue.
MOZ_ASSERT(mReactionsStack.IsEmpty(),
"custom element reactions stack should be empty");
MOZ_ASSERT(!aReaction->IsUpgradeReaction(),
"Upgrade reaction should not be scheduled to backup queue");
mBackupQueue.AppendElement(aElement);