Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(803)

Unified Diff: Source/core/dom/Microtask.cpp

Issue 167683003: use v8 Microtask Queue (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: sync Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/v8/V8PerIsolateData.cpp ('k') | Source/web/WebKit.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Microtask.cpp
diff --git a/Source/core/dom/Microtask.cpp b/Source/core/dom/Microtask.cpp
index a70aed8750b311b5d5d0b2637b65ae94d766596d..bbfb00df0df387155ff21d0dc56ec1f724c3547b 100644
--- a/Source/core/dom/Microtask.cpp
+++ b/Source/core/dom/Microtask.cpp
@@ -33,39 +33,48 @@
#include "bindings/v8/V8PerIsolateData.h"
#include "wtf/Vector.h"
+#include <v8.h>
namespace WebCore {
-typedef Vector<MicrotaskCallback> MicrotaskQueue;
-
-static MicrotaskQueue& microtaskQueue()
-{
- DEFINE_STATIC_LOCAL(MicrotaskQueue, microtaskQueue, ());
- return microtaskQueue;
-}
-
void Microtask::performCheckpoint()
{
- V8PerIsolateData* isolateData = V8PerIsolateData::current();
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate);
ASSERT(isolateData);
if (isolateData->recursionLevel() || isolateData->performingMicrotaskCheckpoint())
return;
isolateData->setPerformingMicrotaskCheckpoint(true);
- while (!microtaskQueue().isEmpty()) {
- Vector<MicrotaskCallback> microtasks;
- microtasks.swap(microtaskQueue());
- for (size_t i = 0; i < microtasks.size(); ++i) {
- microtasks[i]();
- }
- }
+ v8::HandleScope handleScope(isolate);
+ v8::Local<v8::Context> context = isolateData->ensureDomInJSContext();
+ v8::Context::Scope scope(context);
+ v8::V8::RunMicrotasks(isolate);
isolateData->setPerformingMicrotaskCheckpoint(false);
}
+COMPILE_ASSERT(sizeof(void*) == sizeof(MicrotaskCallback), VoidPtrAndFunctionPtrAreSameSize);
+
+static void microtaskFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ MicrotaskCallback callback =
+ reinterpret_cast<MicrotaskCallback>(reinterpret_cast<intptr_t>(
+ info.Data().As<v8::External>()->Value()));
+ (*callback)();
+}
+
void Microtask::enqueueMicrotask(MicrotaskCallback callback)
{
- microtaskQueue().append(callback);
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate);
+ v8::HandleScope handleScope(isolate);
+ v8::Local<v8::Context> context = isolateData->ensureDomInJSContext();
+ v8::Context::Scope scope(context);
+ v8::Local<v8::External> handler =
+ v8::External::New(isolate,
+ reinterpret_cast<void*>(reinterpret_cast<intptr_t>(callback)));
+ v8::V8::EnqueueMicrotask(isolate, v8::Function::New(isolate, &microtaskFunctionCallback, handler));
}
} // namespace WebCore
« no previous file with comments | « Source/bindings/v8/V8PerIsolateData.cpp ('k') | Source/web/WebKit.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698