Chromium Code Reviews| Index: Source/core/dom/Microtask.cpp |
| diff --git a/Source/core/dom/Microtask.cpp b/Source/core/dom/Microtask.cpp |
| index 67e71a79ecea31afa62e1c1b9a51f7d5f6360278..269357963404a3721d565fdee79e03ed6753479e 100644 |
| --- a/Source/core/dom/Microtask.cpp |
| +++ b/Source/core/dom/Microtask.cpp |
| @@ -31,26 +31,46 @@ |
| #include "config.h" |
| #include "core/dom/Microtask.h" |
| +#include "bindings/v8/V8PerIsolateData.h" |
| #include "core/dom/MutationObserver.h" |
| #include "core/dom/custom/CustomElementScheduler.h" |
| #include "wtf/Vector.h" |
| namespace WebCore { |
| +typedef Vector<MicrotaskCallback> MicrotaskQueue; |
| + |
| +static MicrotaskQueue& microtaskQueue() |
| +{ |
| + DEFINE_STATIC_LOCAL(MicrotaskQueue, microtaskQueue, ()); |
| + return microtaskQueue; |
| +} |
| + |
| void Microtask::performCheckpoint() |
|
adamk
2014/01/29 22:58:24
Will this one day take a v8::Isolate* argument? If
rafaelw
2014/01/29 23:18:52
We'll soon need a threadlocal get in order to retr
|
| { |
| - static bool performingCheckpoint = false; |
| - if (performingCheckpoint) |
| + V8PerIsolateData* isolateData = V8PerIsolateData::current(); |
| + ASSERT(isolateData); |
| + if (isolateData->performingCheckpoint()) |
| return; |
| - performingCheckpoint = true; |
| + isolateData->setPerformingCheckpoint(true); |
| - bool anyWorkDone; |
| - do { |
| - MutationObserver::deliverAllMutations(); |
| - anyWorkDone = CustomElementScheduler::dispatchMicrotaskProcessingSteps(); |
| - } while (anyWorkDone); |
| + // FIXME: Custom element's callbacks need to be refactored to enqueueMicrotask() |
| + while (CustomElementScheduler::dispatchMicrotaskProcessingSteps() || !microtaskQueue().isEmpty()) { |
| + if (microtaskQueue().isEmpty()) |
| + continue; |
| + Vector<MicrotaskCallback> microtasks; |
| + microtasks.swap(microtaskQueue()); |
| + for (size_t i = 0; i < microtasks.size(); ++i) { |
| + microtasks[i](); |
| + } |
| + } |
| - performingCheckpoint = false; |
| + isolateData->setPerformingCheckpoint(false); |
| +} |
| + |
| +void Microtask::enqueueMicrotask(MicrotaskCallback callback) |
| +{ |
| + microtaskQueue().append(callback); |
| } |
| } // namespace WebCore |