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

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

Issue 2878833002: Worklet: Move common code of addModule from Main/ThreadedWorklet to Worklet (Closed)
Patch Set: fix crashes 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/Worklet.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/Worklet.cpp
diff --git a/third_party/WebKit/Source/core/workers/Worklet.cpp b/third_party/WebKit/Source/core/workers/Worklet.cpp
index dfa704f07e1d6a00388a22978e724ba8a6a7e6a3..58dc60b66a0d64bc26b78743d55e28baeed6858a 100644
--- a/third_party/WebKit/Source/core/workers/Worklet.cpp
+++ b/third_party/WebKit/Source/core/workers/Worklet.cpp
@@ -4,25 +4,63 @@
#include "core/workers/Worklet.h"
+#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "core/dom/DOMException.h"
#include "core/dom/Document.h"
+#include "core/dom/TaskRunnerHelper.h"
#include "core/frame/LocalFrame.h"
#include "core/workers/WorkletGlobalScopeProxy.h"
namespace blink {
Worklet::Worklet(LocalFrame* frame)
- : ContextLifecycleObserver(frame->GetDocument()), frame_(frame) {
+ : ContextLifecycleObserver(frame->GetDocument()) {
DCHECK(IsMainThread());
}
-void Worklet::ContextDestroyed(ExecutionContext*) {
+// Implementation of the first half of the "addModule(moduleURL, options)"
+// algorithm:
+// https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule
+ScriptPromise Worklet::addModule(ScriptState* script_state,
+ const String& module_url) {
DCHECK(IsMainThread());
- frame_ = nullptr;
+ if (!GetExecutionContext()) {
+ return ScriptPromise::RejectWithDOMException(
+ script_state, DOMException::Create(kInvalidStateError,
+ "This frame is already detached"));
+ }
+
+ // Step 1: "Let promise be a new promise."
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
+ ScriptPromise promise = resolver->Promise();
+
+ // Step 2: "Let worklet be the current Worklet."
+ // |this| is the current Worklet.
+
+ // Step 3: "Let moduleURLRecord be the result of parsing the moduleURL
+ // argument relative to the relevant settings object of this."
+ KURL module_url_record = GetExecutionContext()->CompleteURL(module_url);
+
+ // Step 4: "If moduleURLRecord is failure, then reject promise with a
+ // "SyntaxError" DOMException and return promise."
+ if (!module_url_record.IsValid()) {
+ resolver->Reject(DOMException::Create(
+ kSyntaxError, "'" + module_url + "' is not a valid URL."));
+ return promise;
+ }
+
+ // Step 5: "Return promise, and then continue running this algorithm in
+ // parallel."
+ // |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(&Worklet::FetchAndInvokeScript, WrapPersistent(this),
+ module_url_record, WrapPersistent(resolver)));
+ return promise;
}
DEFINE_TRACE(Worklet) {
- visitor->Trace(frame_);
ContextLifecycleObserver::Trace(visitor);
}
« no previous file with comments | « third_party/WebKit/Source/core/workers/Worklet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698