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

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

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: Created 4 years 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/ModuleMap.cpp
diff --git a/third_party/WebKit/Source/core/dom/ModuleMap.cpp b/third_party/WebKit/Source/core/dom/ModuleMap.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8bd17f64f30b695b60c68d05728707f8a9a1ba60
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ModuleMap.cpp
@@ -0,0 +1,83 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/dom/ModuleMap.h"
+#include "core/fetch/ResourceFetcher.h"
+#include "core/loader/resource/ScriptResource.h"
+
+namespace blink {
+
+ModuleMap::ModuleMap(ResourceFetcher* fetcher)
+ : m_fetcher(fetcher)
+{
+ DCHECK(m_fetcher);
+}
+
+void ModuleMap::fetch(const KURL& url) {
+ printf("ModuleMap::fetch(%s)\n", url.getString().utf8().data());
+
+ MapImpl::AddResult result = m_map.set(url, Entry());
+ Entry& entry = result.storedValue->value;
+ if (!result.isNewEntry) {
+ printf("not new entry\n");
+ // FIXME: If moduleMap[url] is "fetching", wait (in parallel) until that
+ // entry's value changes, then proceed to the next step.
+ if (entry.isFetching()) {
+ // return promise?
+ }
+ // FIXME: If moduleMap[url] exists, asynchronously complete this algorithm
+ // with moduleMap[url], and abort these steps.
+ return;
+ }
+
+ // Step 4. Set moduleMap[url] to "fetching". => Initial entry state is
+ // fetching
+
+ // Step 5. Let request be a new request whose url is url, destination is
+ // destination, type is "script", mode is "cors", credentials mode is
+ // credentials mode, cryptographic nonce metadata is cryptographic nonce,
+ // parser metadata is parser state, referrer is referrer, and client is fetch
+ // client settings object.
+ FetchRequest request(ResourceRequest(url), "module");
+ // request.setDefer(FetchRequest::LazyLoad); //? always async -> defer?
+ Member<ScriptResource> resource = ScriptResource::fetch(request, m_fetcher.get());
+ resource->script();
+
+ // Step 6. If the caller specified custom steps to perform the fetch, perform
+ // them on request, setting the is top-level flag if the top-level module
+ // fetch flag is set. Return from this algorithm, and when the custom perform
+ // the fetch steps complete with response response, run the remaining steps.
+ // Otherwise, fetch request. Return from this algorithm, and run the remaining
+ // steps as part of the fetch's process response for the response response.
+ // Note: response is always CORS-same-origin.
+
+ // TODO(kouhei): yokuwakaran
+
+ // Step 7. If any of the following conditions are met, set moduleMap[url] to
+ // null, asynchronously complete this algorithm with null, and abort these
+ // steps:
+ // - response's type is "error"
+ // - response's status is not an ok status
+ // The result of extracting a MIME type from response's header list (ignoring
+ // parameters) is not a JavaScript MIME type
+ // Note: For historical reasons, fetching a classic script does not include
+ // MIME type checking. In contrast, module scripts will fail to load if they
+ // are not of a correct MIME type.
+
+ // Step 8. Let source text be the result of UTF-8 decoding response's body.
+
+ // Step 9. Let module script be the result of creating a module script given
+ // source text, module map settings object, response's url, cryptographic
+ // nonce, parser state, and credentials mode.
+
+ // Step 10. Set moduleMap[url] to module script, and asynchronously complete
+ // this algorithm with module script.
+}
+
+DEFINE_TRACE(ModuleMap) {
+ visitor->trace(m_map);
+ visitor->trace(m_fetcher);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698