OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/dom/custom/CustomElementMicrotaskQueue.h" | 32 #include "core/dom/custom/CustomElementMicrotaskQueue.h" |
33 | 33 |
34 #include "core/dom/custom/CustomElementCallbackDispatcher.h" | 34 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" |
| 35 #include "core/html/imports/HTMLImportLoader.h" |
35 | 36 |
36 namespace WebCore { | 37 namespace WebCore { |
37 | 38 |
38 class MicrotaskQueueInvocationScope { | 39 CustomElementMicrotaskQueue::CustomElementMicrotaskQueue() |
39 public: | 40 : m_syncQueue(CustomElementSyncMicrotaskQueue::create()) |
40 #if defined(NDEBUG) | 41 , m_asyncQueue(CustomElementAsyncImportMicrotaskQueue::create()) |
41 explicit MicrotaskQueueInvocationScope(CustomElementMicrotaskQueueBase*) { } | |
42 #else | |
43 explicit MicrotaskQueueInvocationScope(CustomElementMicrotaskQueueBase* queu
e) | |
44 : m_parent(s_top) | |
45 , m_queue(queue) | |
46 { | |
47 s_top = this; | |
48 ASSERT(m_queue->isEmpty() || !hasReenter()); | |
49 } | |
50 | |
51 ~MicrotaskQueueInvocationScope() | |
52 { | |
53 s_top = m_parent; | |
54 } | |
55 | |
56 private: | |
57 bool hasReenter() const | |
58 { | |
59 for (MicrotaskQueueInvocationScope* scope = this->m_parent; scope; scope
= scope->m_parent) { | |
60 if (scope->m_queue == m_queue) | |
61 return true; | |
62 } | |
63 | |
64 return false; | |
65 } | |
66 | |
67 MicrotaskQueueInvocationScope* m_parent; | |
68 CustomElementMicrotaskQueueBase* m_queue; | |
69 | |
70 static MicrotaskQueueInvocationScope* s_top; | |
71 #endif | |
72 }; | |
73 | |
74 #if !defined(NDEBUG) | |
75 MicrotaskQueueInvocationScope* MicrotaskQueueInvocationScope::s_top = 0; | |
76 #endif | |
77 | |
78 void CustomElementMicrotaskQueueBase::dispatch() | |
79 { | 42 { |
80 MicrotaskQueueInvocationScope scope(this); | |
81 doDispatch(); | |
82 } | 43 } |
83 | 44 |
84 void CustomElementMicrotaskQueueBase::trace(Visitor* visitor) | 45 void CustomElementMicrotaskQueue::enqueue(HTMLImportLoader* parentLoader, PassOw
nPtrWillBeRawPtr<CustomElementMicrotaskStep> step) |
85 { | 46 { |
86 visitor->trace(m_queue); | 47 if (parentLoader) |
| 48 parentLoader->microtaskQueue()->enqueue(step); |
| 49 else |
| 50 m_syncQueue->enqueue(step); |
| 51 } |
| 52 |
| 53 void CustomElementMicrotaskQueue::enqueue(HTMLImportLoader* parentLoader, PassOw
nPtrWillBeRawPtr<CustomElementMicrotaskImportStep> step, bool importIsSync) |
| 54 { |
| 55 if (importIsSync) |
| 56 enqueue(parentLoader, PassOwnPtrWillBeRawPtr<CustomElementMicrotaskStep>
(step)); |
| 57 else |
| 58 m_asyncQueue->enqueue(step); |
| 59 } |
| 60 |
| 61 void CustomElementMicrotaskQueue::dispatch() |
| 62 { |
| 63 m_syncQueue->dispatch(); |
| 64 if (m_syncQueue->isEmpty()) |
| 65 m_asyncQueue->dispatch(); |
| 66 } |
| 67 |
| 68 void CustomElementMicrotaskQueue::trace(Visitor* visitor) |
| 69 { |
| 70 visitor->trace(m_syncQueue); |
| 71 visitor->trace(m_asyncQueue); |
87 } | 72 } |
88 | 73 |
89 #if !defined(NDEBUG) | 74 #if !defined(NDEBUG) |
90 void CustomElementMicrotaskQueueBase::show(unsigned indent) | 75 void CustomElementMicrotaskQueue::show(unsigned indent) |
91 { | 76 { |
92 for (unsigned q = 0; q < m_queue.size(); ++q) { | 77 fprintf(stderr, "%*sSync:\n", indent, ""); |
93 if (m_queue[q]) | 78 m_syncQueue->show(indent + 1); |
94 m_queue[q]->show(indent); | 79 fprintf(stderr, "%*sAsync:\n", indent, ""); |
95 else | 80 m_asyncQueue->show(indent + 1); |
96 fprintf(stderr, "%*snull\n", indent, ""); | |
97 } | |
98 } | 81 } |
99 #endif | 82 #endif |
100 | 83 |
101 void CustomElementMicrotaskQueue::enqueue(PassOwnPtrWillBeRawPtr<CustomElementMi
crotaskStep> step) | |
102 { | |
103 m_queue.append(step); | |
104 } | |
105 | |
106 void CustomElementMicrotaskQueue::doDispatch() | |
107 { | |
108 unsigned i; | |
109 | |
110 for (i = 0; i < m_queue.size(); ++i) { | |
111 if (CustomElementMicrotaskStep::Processing == m_queue[i]->process()) | |
112 break; | |
113 } | |
114 | |
115 m_queue.remove(0, i); | |
116 } | |
117 | |
118 } // namespace WebCore | 84 } // namespace WebCore |
OLD | NEW |