| 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 20 matching lines...) Expand all Loading... |
| 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/CustomElementCallbackDispatcher.h" |
| 35 | 35 |
| 36 namespace WebCore { | 36 namespace WebCore { |
| 37 | 37 |
| 38 class MicrotaskQueueInvocationScope { | 38 class MicrotaskQueueInvocationScope { |
| 39 public: | 39 public: |
| 40 #if defined(NDEBUG) | 40 #if defined(NDEBUG) |
| 41 explicit MicrotaskQueueInvocationScope(CustomElementMicrotaskQueue*) { } | 41 explicit MicrotaskQueueInvocationScope(CustomElementMicrotaskQueueBase*) { } |
| 42 #else | 42 #else |
| 43 explicit MicrotaskQueueInvocationScope(CustomElementMicrotaskQueue* queue) | 43 explicit MicrotaskQueueInvocationScope(CustomElementMicrotaskQueueBase* queu
e) |
| 44 : m_parent(s_top) | 44 : m_parent(s_top) |
| 45 , m_queue(queue) | 45 , m_queue(queue) |
| 46 { | 46 { |
| 47 s_top = this; | 47 s_top = this; |
| 48 ASSERT(m_queue->isEmpty() || !hasReenter()); | 48 ASSERT(m_queue->isEmpty() || !hasReenter()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 ~MicrotaskQueueInvocationScope() | 51 ~MicrotaskQueueInvocationScope() |
| 52 { | 52 { |
| 53 s_top = m_parent; | 53 s_top = m_parent; |
| 54 } | 54 } |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 bool hasReenter() const | 57 bool hasReenter() const |
| 58 { | 58 { |
| 59 for (MicrotaskQueueInvocationScope* scope = this->m_parent; scope; scope
= scope->m_parent) { | 59 for (MicrotaskQueueInvocationScope* scope = this->m_parent; scope; scope
= scope->m_parent) { |
| 60 if (scope->m_queue == m_queue) | 60 if (scope->m_queue == m_queue) |
| 61 return true; | 61 return true; |
| 62 } | 62 } |
| 63 | 63 |
| 64 return false; | 64 return false; |
| 65 } | 65 } |
| 66 | 66 |
| 67 MicrotaskQueueInvocationScope* m_parent; | 67 MicrotaskQueueInvocationScope* m_parent; |
| 68 CustomElementMicrotaskQueue* m_queue; | 68 CustomElementMicrotaskQueueBase* m_queue; |
| 69 | 69 |
| 70 static MicrotaskQueueInvocationScope* s_top; | 70 static MicrotaskQueueInvocationScope* s_top; |
| 71 #endif | 71 #endif |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 #if !defined(NDEBUG) | 74 #if !defined(NDEBUG) |
| 75 MicrotaskQueueInvocationScope* MicrotaskQueueInvocationScope::s_top = 0; | 75 MicrotaskQueueInvocationScope* MicrotaskQueueInvocationScope::s_top = 0; |
| 76 #endif | 76 #endif |
| 77 | 77 |
| 78 void CustomElementMicrotaskQueue::enqueue(PassOwnPtrWillBeRawPtr<CustomElementMi
crotaskStep> step) | 78 void CustomElementMicrotaskQueueBase::dispatch() |
| 79 { | 79 { |
| 80 m_queue.append(step); | 80 MicrotaskQueueInvocationScope scope(this); |
| 81 doDispatch(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 CustomElementMicrotaskStep::Result CustomElementMicrotaskQueue::dispatch() | 84 void CustomElementMicrotaskQueueBase::trace(Visitor* visitor) |
| 84 { | |
| 85 MicrotaskQueueInvocationScope scope(this); | |
| 86 WillBeHeapVector<OwnPtrWillBeMember<CustomElementMicrotaskStep> > remaining; | |
| 87 Result accumulatedResult = CustomElementMicrotaskStep::ContinueWithRemoving; | |
| 88 | |
| 89 unsigned i; | |
| 90 for (i = 0; i < m_queue.size(); ++i) { | |
| 91 Result result = m_queue[i]->process(); | |
| 92 accumulatedResult = CustomElementMicrotaskStep::Result(result | accumula
tedResult); | |
| 93 if (result & CustomElementMicrotaskStep::ShouldRemain) | |
| 94 remaining.append(m_queue[i].release()); | |
| 95 if (result & CustomElementMicrotaskStep::ShouldStop) | |
| 96 break; | |
| 97 } | |
| 98 | |
| 99 for (++i; i < m_queue.size(); ++i) | |
| 100 remaining.append(m_queue[i].release()); | |
| 101 m_queue.swap(remaining); | |
| 102 | |
| 103 return accumulatedResult; | |
| 104 } | |
| 105 | |
| 106 bool CustomElementMicrotaskQueue::needsProcessOrStop() const | |
| 107 { | |
| 108 for (size_t i = 0; i < m_queue.size(); ++i) { | |
| 109 if (m_queue[i]->needsProcessOrStop()) | |
| 110 return true; | |
| 111 } | |
| 112 | |
| 113 return false; | |
| 114 } | |
| 115 | |
| 116 void CustomElementMicrotaskQueue::trace(Visitor* visitor) | |
| 117 { | 85 { |
| 118 visitor->trace(m_queue); | 86 visitor->trace(m_queue); |
| 119 } | 87 } |
| 120 | 88 |
| 121 #if !defined(NDEBUG) | 89 #if !defined(NDEBUG) |
| 122 void CustomElementMicrotaskQueue::show(unsigned indent) | 90 void CustomElementMicrotaskQueueBase::show(unsigned indent) |
| 123 { | 91 { |
| 124 for (unsigned q = 0; q < m_queue.size(); ++q) { | 92 for (unsigned q = 0; q < m_queue.size(); ++q) { |
| 125 if (m_queue[q]) | 93 if (m_queue[q]) |
| 126 m_queue[q]->show(indent); | 94 m_queue[q]->show(indent); |
| 127 else | 95 else |
| 128 fprintf(stderr, "%*snull\n", indent, ""); | 96 fprintf(stderr, "%*snull\n", indent, ""); |
| 129 } | 97 } |
| 130 } | 98 } |
| 131 #endif | 99 #endif |
| 132 | 100 |
| 101 void CustomElementMicrotaskQueue::enqueue(PassOwnPtr<CustomElementMicrotaskStep>
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 |
| 133 } // namespace WebCore | 118 } // namespace WebCore |
| OLD | NEW |