| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/CustomElementMicrotaskDispatcher.h" | 5 #include "core/dom/custom/CustomElementMicrotaskDispatcher.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Microtask.h" | 7 #include "bindings/core/v8/Microtask.h" |
| 8 #include "core/dom/custom/CustomElementCallbackQueue.h" | 8 #include "core/dom/custom/CustomElementCallbackQueue.h" |
| 9 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" | 9 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" |
| 10 #include "core/dom/custom/CustomElementProcessingStack.h" | 10 #include "core/dom/custom/CustomElementProcessingStack.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue
) | 29 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue
) |
| 30 { | 30 { |
| 31 ensureMicrotaskScheduledForElementQueue(); | 31 ensureMicrotaskScheduledForElementQueue(); |
| 32 queue->setOwner(kMicrotaskQueueId); | 32 queue->setOwner(kMicrotaskQueueId); |
| 33 m_elements.append(queue); | 33 m_elements.append(queue); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void CustomElementMicrotaskDispatcher::ensureMicrotaskScheduledForElementQueue() | 36 void CustomElementMicrotaskDispatcher::ensureMicrotaskScheduledForElementQueue() |
| 37 { | 37 { |
| 38 ASSERT(m_phase == Quiescent || m_phase == Resolving); | 38 DCHECK(m_phase == Quiescent || m_phase == Resolving); |
| 39 ensureMicrotaskScheduled(); | 39 ensureMicrotaskScheduled(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void CustomElementMicrotaskDispatcher::ensureMicrotaskScheduled() | 42 void CustomElementMicrotaskDispatcher::ensureMicrotaskScheduled() |
| 43 { | 43 { |
| 44 if (!m_hasScheduledMicrotask) { | 44 if (!m_hasScheduledMicrotask) { |
| 45 Microtask::enqueueMicrotask(WTF::bind(&dispatch)); | 45 Microtask::enqueueMicrotask(WTF::bind(&dispatch)); |
| 46 m_hasScheduledMicrotask = true; | 46 m_hasScheduledMicrotask = true; |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 void CustomElementMicrotaskDispatcher::dispatch() | 50 void CustomElementMicrotaskDispatcher::dispatch() |
| 51 { | 51 { |
| 52 instance().doDispatch(); | 52 instance().doDispatch(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void CustomElementMicrotaskDispatcher::doDispatch() | 55 void CustomElementMicrotaskDispatcher::doDispatch() |
| 56 { | 56 { |
| 57 ASSERT(isMainThread()); | 57 DCHECK(isMainThread()); |
| 58 | 58 |
| 59 ASSERT(m_phase == Quiescent && m_hasScheduledMicrotask); | 59 DCHECK(m_phase == Quiescent); |
| 60 DCHECK(m_hasScheduledMicrotask); |
| 60 m_hasScheduledMicrotask = false; | 61 m_hasScheduledMicrotask = false; |
| 61 | 62 |
| 62 // Finishing microtask work deletes all | 63 // Finishing microtask work deletes all |
| 63 // CustomElementCallbackQueues. Being in a callback delivery scope | 64 // CustomElementCallbackQueues. Being in a callback delivery scope |
| 64 // implies those queues could still be in use. | 65 // implies those queues could still be in use. |
| 65 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementProcessingStack::inCallbackDe
liveryScope()); | 66 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementProcessingStack::inCallbackDe
liveryScope()); |
| 66 | 67 |
| 67 m_phase = Resolving; | 68 m_phase = Resolving; |
| 68 | 69 |
| 69 m_phase = DispatchingCallbacks; | 70 m_phase = DispatchingCallbacks; |
| 70 for (const auto& element : m_elements) { | 71 for (const auto& element : m_elements) { |
| 71 // Created callback may enqueue an attached callback. | 72 // Created callback may enqueue an attached callback. |
| 72 CustomElementProcessingStack::CallbackDeliveryScope scope; | 73 CustomElementProcessingStack::CallbackDeliveryScope scope; |
| 73 element->processInElementQueue(kMicrotaskQueueId); | 74 element->processInElementQueue(kMicrotaskQueueId); |
| 74 } | 75 } |
| 75 | 76 |
| 76 m_elements.clear(); | 77 m_elements.clear(); |
| 77 CustomElementScheduler::microtaskDispatcherDidFinish(); | 78 CustomElementScheduler::microtaskDispatcherDidFinish(); |
| 78 m_phase = Quiescent; | 79 m_phase = Quiescent; |
| 79 } | 80 } |
| 80 | 81 |
| 81 DEFINE_TRACE(CustomElementMicrotaskDispatcher) | 82 DEFINE_TRACE(CustomElementMicrotaskDispatcher) |
| 82 { | 83 { |
| 83 visitor->trace(m_elements); | 84 visitor->trace(m_elements); |
| 84 } | 85 } |
| 85 | 86 |
| 86 } // namespace blink | 87 } // namespace blink |
| OLD | NEW |