| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * 3. Neither the name of Google Inc. nor the names of its contributors | |
| 15 * may be used to endorse or promote products derived from this | |
| 16 * software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "core/dom/custom/CustomElementMicrotaskQueue.h" | |
| 33 | |
| 34 #include "core/dom/custom/CustomElementCallbackDispatcher.h" | |
| 35 | |
| 36 namespace WebCore { | |
| 37 | |
| 38 class MicrotaskQueueInvocationScope { | |
| 39 public: | |
| 40 #if defined(NDEBUG) | |
| 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 { | |
| 80 MicrotaskQueueInvocationScope scope(this); | |
| 81 doDispatch(); | |
| 82 } | |
| 83 | |
| 84 void CustomElementMicrotaskQueueBase::trace(Visitor* visitor) | |
| 85 { | |
| 86 visitor->trace(m_queue); | |
| 87 } | |
| 88 | |
| 89 #if !defined(NDEBUG) | |
| 90 void CustomElementMicrotaskQueueBase::show(unsigned indent) | |
| 91 { | |
| 92 for (unsigned q = 0; q < m_queue.size(); ++q) { | |
| 93 if (m_queue[q]) | |
| 94 m_queue[q]->show(indent); | |
| 95 else | |
| 96 fprintf(stderr, "%*snull\n", indent, ""); | |
| 97 } | |
| 98 } | |
| 99 #endif | |
| 100 | |
| 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 | |
| OLD | NEW |