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

Unified Diff: third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp

Issue 2854003002: Worklet: Make the latter half of addModule() async (Closed)
Patch Set: WrapWeakPersistent -> WrapPersistent Created 3 years, 7 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 | « third_party/WebKit/Source/core/workers/MainThreadWorklet.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp
diff --git a/third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp b/third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp
index 4d2c6f10b6428927b613355010abc027c280d6a6..2c24ab8124d9529f8242cbbe431ac03de9836152 100644
--- a/third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp
+++ b/third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp
@@ -4,11 +4,13 @@
#include "core/workers/MainThreadWorklet.h"
+#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/ScriptSourceCode.h"
#include "bindings/core/v8/V8BindingForCore.h"
#include "core/dom/DOMException.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
+#include "core/dom/TaskRunnerHelper.h"
#include "core/frame/LocalFrame.h"
#include "core/workers/WorkletGlobalScopeProxy.h"
#include "core/workers/WorkletPendingTasks.h"
@@ -18,7 +20,8 @@ namespace blink {
MainThreadWorklet::MainThreadWorklet(LocalFrame* frame) : Worklet(frame) {}
-// Implementation of the "addModule(moduleURL, options)" algorithm:
+// Implementation of the first half of the "addModule(moduleURL, options)"
+// algorithm:
// https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule
ScriptPromise MainThreadWorklet::addModule(ScriptState* script_state,
const String& module_url) {
@@ -50,7 +53,24 @@ ScriptPromise MainThreadWorklet::addModule(ScriptState* script_state,
// Step 5: "Return promise, and then continue running this algorithm in
// parallel."
- // TODO(nhiroki): Make the following sequence async.
+ // |kUnspecedLoading| is used here because this is a part of script module
+ // loading.
+ TaskRunnerHelper::Get(TaskType::kUnspecedLoading, script_state)
+ ->PostTask(BLINK_FROM_HERE,
+ WTF::Bind(&MainThreadWorklet::FetchAndInvokeScript,
+ WrapPersistent(this), module_url_record,
+ WrapPersistent(resolver)));
+ return promise;
+}
+
+// Implementation of the second half of the "addModule(moduleURL, options)"
+// algorithm:
+// https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule
+void MainThreadWorklet::FetchAndInvokeScript(const KURL& module_url_record,
+ ScriptPromiseResolver* resolver) {
+ DCHECK(IsMainThread());
+ if (!GetExecutionContext())
+ return;
// Step 6: "Let credentialOptions be the credentials member of options."
// TODO(nhiroki): Implement credentialOptions (https://crbug.com/710837).
@@ -93,7 +113,6 @@ ScriptPromise MainThreadWorklet::addModule(ScriptState* script_state,
// TODO(nhiroki): Queue a task instead of executing this here.
GetWorkletGlobalScopeProxy()->FetchAndInvokeScript(module_url_record,
pending_tasks);
- return promise;
}
void MainThreadWorklet::ContextDestroyed(ExecutionContext* execution_context) {
« no previous file with comments | « third_party/WebKit/Source/core/workers/MainThreadWorklet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698