зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1325279 - Put the reaction queue in CustomElementData structure instead of using a map; r=wchen
Bug 1347446 makes accessing ElementReactionQueue becomes a bit non-trival (have to get it via DocGroup). Since bug 1359346 already refactors the creation time of CustomElementData, ReactionQueue can also be put into CustomElementData, then we can just get ReactionQueue from Element. MozReview-Commit-ID: D6PouDu8hkL
This commit is contained in:
Родитель
e1cd972927
Коммит
bc065e9897
|
@ -947,23 +947,20 @@ void
|
|||
CustomElementReactionsStack::Enqueue(Element* aElement,
|
||||
CustomElementReaction* aReaction)
|
||||
{
|
||||
RefPtr<CustomElementData> elementData = aElement->GetCustomElementData();
|
||||
MOZ_ASSERT(elementData, "CustomElementData should exist");
|
||||
|
||||
// Add element to the current element queue.
|
||||
if (!mReactionsStack.IsEmpty()) {
|
||||
mReactionsStack.LastElement().AppendElement(do_GetWeakReference(aElement));
|
||||
ReactionQueue* reactionQueue =
|
||||
mElementReactionQueueMap.LookupOrAdd(aElement);
|
||||
reactionQueue->AppendElement(aReaction);
|
||||
|
||||
elementData->mReactionQueue.AppendElement(aReaction);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the custom element reactions stack is empty, then:
|
||||
// Add element to the backup element queue.
|
||||
mBackupQueue.AppendElement(do_GetWeakReference(aElement));
|
||||
|
||||
ReactionQueue* reactionQueue =
|
||||
mElementReactionQueueMap.LookupOrAdd(aElement);
|
||||
reactionQueue->AppendElement(aReaction);
|
||||
elementData->mReactionQueue.AppendElement(aReaction);
|
||||
|
||||
if (mIsBackupQueueProcessing) {
|
||||
return;
|
||||
|
@ -994,16 +991,15 @@ CustomElementReactionsStack::InvokeReactions(ElementQueue& aElementQueue)
|
|||
continue;
|
||||
}
|
||||
|
||||
nsAutoPtr<ReactionQueue> reactions;
|
||||
mElementReactionQueueMap.RemoveAndForget(element, reactions);
|
||||
RefPtr<CustomElementData> elementData = element->GetCustomElementData();
|
||||
MOZ_ASSERT(elementData, "CustomElementData should exist");
|
||||
|
||||
MOZ_ASSERT(reactions,
|
||||
"Associated ReactionQueue must be found in mElementReactionQueueMap");
|
||||
|
||||
for (uint32_t j = 0; j < reactions->Length(); ++j) {
|
||||
nsAutoPtr<CustomElementReaction>& reaction = reactions->ElementAt(j);
|
||||
reaction->Invoke(element);
|
||||
nsTArray<nsAutoPtr<CustomElementReaction>>& reactions =
|
||||
elementData->mReactionQueue;
|
||||
for (uint32_t j = 0; j < reactions.Length(); ++j) {
|
||||
reactions.ElementAt(j)->Invoke(element);
|
||||
}
|
||||
reactions.Clear();
|
||||
}
|
||||
aElementQueue.Clear();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ struct CustomElementData;
|
|||
struct ElementDefinitionOptions;
|
||||
struct LifecycleCallbacks;
|
||||
class CallbackFunction;
|
||||
class CustomElementReaction;
|
||||
class Function;
|
||||
class Promise;
|
||||
|
||||
|
@ -103,6 +104,13 @@ struct CustomElementData
|
|||
int32_t mAssociatedMicroTask;
|
||||
// Custom element state as described in the custom element spec.
|
||||
State mState;
|
||||
// custom element reaction queue as described in the custom element spec.
|
||||
// There is 1 reaction in reaction queue, when 1) it becomes disconnected,
|
||||
// 2) it’s adopted into a new document, 3) its attributes are changed,
|
||||
// appended, removed, or replaced.
|
||||
// There are 3 reactions in reaction queue when doing upgrade operation,
|
||||
// e.g., create an element, insert a node.
|
||||
AutoTArray<nsAutoPtr<CustomElementReaction>, 3> mReactionQueue;
|
||||
|
||||
// Empties the callback queue.
|
||||
void RunCallbackQueue();
|
||||
|
@ -191,7 +199,7 @@ public:
|
|||
}
|
||||
|
||||
// nsWeakPtr is a weak pointer of Element
|
||||
// The element reaction queues are stored in ElementReactionQueueMap.
|
||||
// The element reaction queues are stored in CustomElementData.
|
||||
// We need to lookup ElementReactionQueueMap again to get relevant reaction queue.
|
||||
// The choice of 1 for the auto size here is based on gut feeling.
|
||||
typedef AutoTArray<nsWeakPtr, 1> ElementQueue;
|
||||
|
@ -216,17 +224,6 @@ public:
|
|||
private:
|
||||
~CustomElementReactionsStack() {};
|
||||
|
||||
// There is 1 reaction in reaction queue, when 1) it becomes disconnected,
|
||||
// 2) it’s adopted into a new document, 3) its attributes are changed,
|
||||
// appended, removed, or replaced.
|
||||
// There are 3 reactions in reaction queue when doing upgrade operation,
|
||||
// e.g., create an element, insert a node.
|
||||
typedef AutoTArray<nsAutoPtr<CustomElementReaction>, 3> ReactionQueue;
|
||||
typedef nsClassHashtable<nsISupportsHashKey, ReactionQueue>
|
||||
ElementReactionQueueMap;
|
||||
|
||||
ElementReactionQueueMap mElementReactionQueueMap;
|
||||
|
||||
// The choice of 8 for the auto size here is based on gut feeling.
|
||||
AutoTArray<ElementQueue, 8> mReactionsStack;
|
||||
ElementQueue mBackupQueue;
|
||||
|
|
Загрузка…
Ссылка в новой задаче