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

Unified Diff: third_party/WebKit/Source/core/dom/ModulatorImpl.cpp

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: address haraken/yhirano comments Created 3 years, 11 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
Index: third_party/WebKit/Source/core/dom/ModulatorImpl.cpp
diff --git a/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp b/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..eca2fdba4ade948bbfc4193012b1b836cbb0c497
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp
@@ -0,0 +1,119 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
dominicc (has gone to gerrit) 2017/01/11 03:23:48 I like how straightforward the implementation of t
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/dom/ModulatorImpl.h"
+
+#include "core/dom/Document.h"
+#include "core/dom/ModuleMap.h"
+#include "core/dom/ModuleScript.h"
+#include "core/dom/ScriptModuleResolverImpl.h"
+#include "core/dom/TaskRunnerHelper.h"
+#include "core/fetch/ResourceFetcher.h"
+#include "core/loader/modulescript/ModuleScriptLoaderRegistry.h"
+#include "core/loader/modulescript/ModuleTreeLinkerRegistry.h"
+
+namespace blink {
+
+ModulatorImpl* ModulatorImpl::create(RefPtr<ScriptState> scriptState,
+ Document& document) {
+ return new ModulatorImpl(
+ std::move(scriptState),
+ TaskRunnerHelper::get(TaskType::Networking, &document),
+ document.fetcher());
+}
+
+ModulatorImpl::ModulatorImpl(RefPtr<ScriptState> scriptState,
+ WebTaskRunner* taskRunner,
+ ResourceFetcher* fetcher)
+ : m_scriptState(std::move(scriptState)),
+ m_taskRunner(taskRunner->clone()),
+ m_fetcher(fetcher),
+ m_map(ModuleMap::create(this)),
+ m_loaderRegistry(ModuleScriptLoaderRegistry::create()),
+ m_treeLinkerRegistry(ModuleTreeLinkerRegistry::create()),
+ m_scriptModuleResolver(ScriptModuleResolverImpl::create(this)) {
+ DCHECK(m_scriptState);
+ DCHECK(m_fetcher);
+}
+
+ModulatorImpl::~ModulatorImpl() {}
+
+void ModulatorImpl::fetchTree(const KURL& url,
+ const KURL& baseURL,
+ ModuleTreeClient* client) {
+ // Step 1. Perform the internal module script graph fetching procedure given
+ // url, settings object, destination, cryptographic nonce, parser state,
+ // credentials mode, settings object, a new empty list, "client", and with the
+ // top-level module fetch flag set. If the caller of this algorithm specified
+ // custom perform the fetch steps, pass those along as well.
+ HashSet<KURL> emptyAncestorList;
+ m_treeLinkerRegistry->fetch(url, baseURL, emptyAncestorList, this, client);
+
+ // Step 2. When the internal module script graph fetching procedure
+ // asynchronously completes with result, asynchronously complete this
+ // algorithm with result.
+}
+
+void ModulatorImpl::fetchSingle(const KURL& url,
+ const KURL& baseURL,
+ SingleModuleClient* client) {
+ m_map->retrieveAndFetchIfNeeded(url, baseURL, client);
+}
+
+void ModulatorImpl::fetchNewSingleModule(const KURL& url,
+ const KURL& baseURL,
+ ModuleScriptLoaderClient* client) {
+ m_loaderRegistry->fetch(url, baseURL, this, m_fetcher.get(), client);
+}
+
+ModuleScript* ModulatorImpl::retrieveFetchedModuleScript(const KURL& url) {
+ return m_map->retrieveFetchedModuleScript(url);
+}
+
+ScriptModule ModulatorImpl::compileModule(const String& script,
+ const String& urlStr) {
+ v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
+ v8::HandleScope handleScope(isolate);
dominicc (has gone to gerrit) 2017/01/11 06:57:15 ScriptState::Scope has a handle scope; do you need
kouhei (in TOK) 2017/01/17 05:26:13 Done.
+
+ ScriptState::Scope scope(m_scriptState.get());
+ return ScriptModule::compile(isolate, script, urlStr);
+}
+
+bool ModulatorImpl::instantiateModule(ScriptModule scriptModule) {
+ v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
+ v8::HandleScope handleScope(isolate);
+
+ ScriptState::Scope scope(m_scriptState.get());
+ return scriptModule.instantiate(m_scriptState.get());
+}
+
+Vector<String> ModulatorImpl::moduleRequestsFromScriptModule(
+ ScriptModule scriptModule) {
+ v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
+ v8::HandleScope handleScope(isolate);
+
+ ScriptState::Scope scope(m_scriptState.get());
+ return scriptModule.moduleRequests(m_scriptState.get());
+}
+
+void ModulatorImpl::executeModule(ScriptModule scriptModule) {
+ v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
+ v8::HandleScope handleScope(isolate);
+
+ ScriptState::Scope scope(m_scriptState.get());
+
+ v8::MicrotasksScope microtasksScope(isolate,
+ v8::MicrotasksScope::kRunMicrotasks);
+ scriptModule.evaluate(m_scriptState.get());
dominicc (has gone to gerrit) 2017/01/11 06:57:15 Wonder if this API should take ExceptionState?
kouhei (in TOK) 2017/01/17 05:26:13 I'm not aware of the case when it can throw except
+}
+
+DEFINE_TRACE(ModulatorImpl) {
+ visitor->trace(m_map);
+ visitor->trace(m_fetcher);
+ visitor->trace(m_loaderRegistry);
+ visitor->trace(m_treeLinkerRegistry);
+ visitor->trace(m_scriptModuleResolver);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698