Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp b/third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp |
| index 1ec77952d5ed56cb36c22416618391f4e158ec23..734bdf458d46bb7d35cbffd53c8e6c1acb2284eb 100644 |
| --- a/third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp |
| +++ b/third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp |
| @@ -4,8 +4,11 @@ |
| #include "core/dom/custom/CustomElementReactionStack.h" |
| +#include "bindings/core/v8/Microtask.h" |
| #include "core/dom/Element.h" |
| +#include "core/dom/custom/CEReactionsScope.h" |
| #include "core/dom/custom/CustomElementReactionQueue.h" |
| +#include "core/frame/FrameHost.h" |
| namespace blink { |
| @@ -20,6 +23,7 @@ DEFINE_TRACE(CustomElementReactionStack) |
| { |
| visitor->trace(m_map); |
| visitor->trace(m_stack); |
| + visitor->trace(m_backupQueue); |
| } |
| void CustomElementReactionStack::push() |
| @@ -30,30 +34,37 @@ void CustomElementReactionStack::push() |
| void CustomElementReactionStack::popInvokingReactions() |
| { |
| ElementQueue* queue = m_stack.last(); |
| - if (!queue) { |
| - m_stack.removeLast(); |
| - return; |
| - } |
| + if (queue) |
| + invokeReactions(*queue); |
| + m_stack.removeLast(); |
| +} |
| - for (size_t i = 0; i < queue->size(); ++i) { |
| - Element* element = (*queue)[i]; |
| +void CustomElementReactionStack::invokeReactions(ElementQueue& queue) |
| +{ |
| + for (size_t i = 0; i < queue.size(); ++i) { |
| + Element* element = queue[i]; |
| if (CustomElementReactionQueue* reactions = m_map.get(element)) { |
| reactions->invokeReactions(element); |
| CHECK(reactions->isEmpty()); |
| m_map.remove(element); |
| } |
| } |
| +} |
| - m_stack.removeLast(); |
| +void CustomElementReactionStack::enqueueToCurrentQueue( |
| + Element* element, |
| + CustomElementReaction* reaction) |
| +{ |
| + enqueue(m_stack.last(), element, reaction); |
| } |
| void CustomElementReactionStack::enqueue( |
| + Member<ElementQueue>& queue, |
| Element* element, |
| CustomElementReaction* reaction) |
| { |
| - ElementQueue* queue = m_stack.last(); |
| if (!queue) |
| - m_stack.last() = queue = new ElementQueue(); |
| + queue = new ElementQueue(); |
| queue->append(element); |
| CustomElementReactionQueue* reactions = m_map.get(element); |
| @@ -65,4 +76,30 @@ void CustomElementReactionStack::enqueue( |
| reactions->add(reaction); |
| } |
| +void CustomElementReactionStack::enqueueToBackupQueue( |
| + Element* element, |
| + CustomElementReaction* reaction) |
| +{ |
| + // https://html.spec.whatwg.org/multipage/scripting.html#backup-element-queue |
| + |
| + DCHECK(m_stack.isEmpty()); |
|
dominicc (has gone to gerrit)
2016/06/29 07:19:54
Maybe we can also DCHECK CEReactionsScope::current
|
| + DCHECK(isMainThread()); |
| + |
| + // If the processing the backup element queue is not set: |
| + if (!m_backupQueue || m_backupQueue->isEmpty()) { |
| + Microtask::enqueueMicrotask(WTF::bind( |
| + &CustomElementReactionStack::invokeBackupQueue, |
| + Persistent<CustomElementReactionStack>(this))); |
| + } |
| + |
| + enqueue(m_backupQueue, element, reaction); |
| +} |
| + |
| +void CustomElementReactionStack::invokeBackupQueue() |
| +{ |
| + DCHECK(isMainThread()); |
| + invokeReactions(*m_backupQueue); |
| + m_backupQueue->clear(); |
| +} |
| + |
| } // namespace blink |