| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/dom/custom/CustomElementReactionStack.h" | 5 #include "core/dom/custom/CustomElementReactionStack.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Microtask.h" | 7 #include "bindings/core/v8/Microtask.h" |
| 8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
| 9 #include "core/dom/custom/CEReactionsScope.h" | 9 #include "core/dom/custom/CEReactionsScope.h" |
| 10 #include "core/dom/custom/CustomElementReactionQueue.h" | 10 #include "core/dom/custom/CustomElementReactionQueue.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 void CustomElementReactionStack::popInvokingReactions() { | 47 void CustomElementReactionStack::popInvokingReactions() { |
| 48 ElementQueue* queue = m_stack.back(); | 48 ElementQueue* queue = m_stack.back(); |
| 49 if (queue) | 49 if (queue) |
| 50 invokeReactions(*queue); | 50 invokeReactions(*queue); |
| 51 m_stack.pop_back(); | 51 m_stack.pop_back(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void CustomElementReactionStack::invokeReactions(ElementQueue& queue) { | 54 void CustomElementReactionStack::invokeReactions(ElementQueue& queue) { |
| 55 for (size_t i = 0; i < queue.size(); ++i) { | 55 for (size_t i = 0; i < queue.size(); ++i) { |
| 56 Element* element = queue[i]; | 56 Element* element = queue[i]; |
| 57 if (CustomElementReactionQueue* reactions = m_map.get(element)) { | 57 if (CustomElementReactionQueue* reactions = m_map.at(element)) { |
| 58 reactions->invokeReactions(element); | 58 reactions->invokeReactions(element); |
| 59 CHECK(reactions->isEmpty()); | 59 CHECK(reactions->isEmpty()); |
| 60 m_map.erase(element); | 60 m_map.erase(element); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 void CustomElementReactionStack::enqueueToCurrentQueue( | 65 void CustomElementReactionStack::enqueueToCurrentQueue( |
| 66 Element* element, | 66 Element* element, |
| 67 CustomElementReaction* reaction) { | 67 CustomElementReaction* reaction) { |
| 68 enqueue(m_stack.back(), element, reaction); | 68 enqueue(m_stack.back(), element, reaction); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void CustomElementReactionStack::enqueue(Member<ElementQueue>& queue, | 71 void CustomElementReactionStack::enqueue(Member<ElementQueue>& queue, |
| 72 Element* element, | 72 Element* element, |
| 73 CustomElementReaction* reaction) { | 73 CustomElementReaction* reaction) { |
| 74 if (!queue) | 74 if (!queue) |
| 75 queue = new ElementQueue(); | 75 queue = new ElementQueue(); |
| 76 queue->push_back(element); | 76 queue->push_back(element); |
| 77 | 77 |
| 78 CustomElementReactionQueue* reactions = m_map.get(element); | 78 CustomElementReactionQueue* reactions = m_map.at(element); |
| 79 if (!reactions) { | 79 if (!reactions) { |
| 80 reactions = new CustomElementReactionQueue(); | 80 reactions = new CustomElementReactionQueue(); |
| 81 m_map.insert(TraceWrapperMember<Element>(this, element), reactions); | 81 m_map.insert(TraceWrapperMember<Element>(this, element), reactions); |
| 82 } | 82 } |
| 83 | 83 |
| 84 reactions->add(reaction); | 84 reactions->add(reaction); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void CustomElementReactionStack::enqueueToBackupQueue( | 87 void CustomElementReactionStack::enqueueToBackupQueue( |
| 88 Element* element, | 88 Element* element, |
| 89 CustomElementReaction* reaction) { | 89 CustomElementReaction* reaction) { |
| 90 // https://html.spec.whatwg.org/multipage/scripting.html#backup-element-queue | 90 // https://html.spec.whatwg.org/multipage/scripting.html#backup-element-queue |
| 91 | 91 |
| 92 DCHECK(!CEReactionsScope::current()); | 92 DCHECK(!CEReactionsScope::current()); |
| 93 DCHECK(m_stack.isEmpty()); | 93 DCHECK(m_stack.isEmpty()); |
| 94 DCHECK(isMainThread()); | 94 DCHECK(isMainThread()); |
| 95 | 95 |
| 96 // If the processing the backup element queue is not set: | 96 // If the processing the backup element queue is not set: |
| 97 if (!m_backupQueue || m_backupQueue->isEmpty()) { | 97 if (!m_backupQueue || m_backupQueue->isEmpty()) { |
| 98 Microtask::enqueueMicrotask( | 98 Microtask::enqueueMicrotask( |
| 99 WTF::bind(&CustomElementReactionStack::invokeBackupQueue, | 99 WTF::bind(&CustomElementReactionStack::invokeBackupQueue, |
| 100 Persistent<CustomElementReactionStack>(this))); | 100 Persistent<CustomElementReactionStack>(this))); |
| 101 } | 101 } |
| 102 | 102 |
| 103 enqueue(m_backupQueue, element, reaction); | 103 enqueue(m_backupQueue, element, reaction); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void CustomElementReactionStack::clearQueue(Element* element) { | 106 void CustomElementReactionStack::clearQueue(Element* element) { |
| 107 if (CustomElementReactionQueue* reactions = m_map.get(element)) | 107 if (CustomElementReactionQueue* reactions = m_map.at(element)) |
| 108 reactions->clear(); | 108 reactions->clear(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void CustomElementReactionStack::invokeBackupQueue() { | 111 void CustomElementReactionStack::invokeBackupQueue() { |
| 112 DCHECK(isMainThread()); | 112 DCHECK(isMainThread()); |
| 113 invokeReactions(*m_backupQueue); | 113 invokeReactions(*m_backupQueue); |
| 114 m_backupQueue->clear(); | 114 m_backupQueue->clear(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 CustomElementReactionStack& CustomElementReactionStack::current() { | 117 CustomElementReactionStack& CustomElementReactionStack::current() { |
| 118 return *customElementReactionStack(); | 118 return *customElementReactionStack(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 CustomElementReactionStack* | 121 CustomElementReactionStack* |
| 122 CustomElementReactionStackTestSupport::setCurrentForTest( | 122 CustomElementReactionStackTestSupport::setCurrentForTest( |
| 123 CustomElementReactionStack* newStack) { | 123 CustomElementReactionStack* newStack) { |
| 124 Persistent<CustomElementReactionStack>& stack = customElementReactionStack(); | 124 Persistent<CustomElementReactionStack>& stack = customElementReactionStack(); |
| 125 CustomElementReactionStack* oldStack = stack.get(); | 125 CustomElementReactionStack* oldStack = stack.get(); |
| 126 stack = newStack; | 126 stack = newStack; |
| 127 return oldStack; | 127 return oldStack; |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace blink | 130 } // namespace blink |
| OLD | NEW |