Index: third_party/WebKit/Source/core/dom/ModuleMap.h |
diff --git a/third_party/WebKit/Source/core/dom/ModuleMap.h b/third_party/WebKit/Source/core/dom/ModuleMap.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..36b00fe017c57ac7db118b799710a4f13cb482a3 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/dom/ModuleMap.h |
@@ -0,0 +1,88 @@ |
+// 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. |
+ |
+#ifndef ModuleMap_h |
+#define ModuleMap_h |
+ |
+#include "platform/heap/Handle.h" |
+#include "platform/weborigin/KURL.h" |
+#include "platform/weborigin/KURLHash.h" |
+#include "wtf/HashMap.h" |
+#include "wtf/HashTableDeletedValueType.h" |
+ |
+namespace blink { |
+ |
+class ResourceFetcher; |
+ |
+class ModuleScript : public GarbageCollected<ModuleScript> { |
adamk
2016/12/06 21:19:00
Is this the same thing as the previously-discussed
kouhei (in TOK)
2016/12/08 03:20:38
Yes. Let's rename this to ScriptModule.
|
+ public: |
+ static ModuleScript* create() { return new ModuleScript(); } |
+ DEFINE_INLINE_TRACE() {} |
+ |
+ private: |
+ ModuleScript() {} |
+}; |
+ |
+class ModuleMap : public GarbageCollected<ModuleMap> { |
+ WTF_MAKE_NONCOPYABLE(ModuleMap); |
+ |
+ public: |
+ static ModuleMap* create(ResourceFetcher* fetcher) { return new ModuleMap(fetcher); } |
+ DECLARE_TRACE(); |
+ |
+ // https://html.spec.whatwg.org/#fetch-a-single-module-script |
+ void fetch( |
+ const KURL& url |
+ /*, a fetch client settings object, a destination, a cryptographic nonce, a parser state, a credentials mode, a module map settings object, a referrer, and a top-level module fetch flag*/); // => ModuleScript* |
+ |
+ private: |
+ ModuleMap(ResourceFetcher*); |
+ ModuleMap() = delete; |
+ |
+ // either a module script, null (used to represent failed fetches), or a |
+ // placeholder value "fetching". Module maps are used to ensure that imported |
+ // JavaScript modules are only fetched, parsed, and evaluated once per |
+ // Document or worker. |
+ class Entry { |
+ public: |
+ DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
+ |
+ enum class State { |
+ Fetching, |
+ Fetched, |
+ Failed, |
+ Deleted, |
+ }; |
+ |
+ Entry() : m_state(State::Fetching) {} |
+ Entry(WTF::HashTableDeletedValueType) : m_state(State::Deleted) {} |
+ |
+ bool isFetching() const { return m_state == State::Fetching; } |
+ |
+ ModuleScript* moduleScript() { |
+ if (!m_moduleScript) |
+ return nullptr; |
+ |
+ DCHECK_EQ(m_state, State::Fetched); |
+ return m_moduleScript; |
+ } |
+ |
+ DEFINE_INLINE_TRACE() { visitor->trace(m_moduleScript); } |
+ |
+ private: |
+ State m_state; |
+ Member<ModuleScript> m_moduleScript; |
+ }; |
+ |
+ using MapImpl = HeapHashMap<KURL, Entry>; |
+ |
+ // A module map is a map of absolute URLs to values |
+ MapImpl m_map; |
+ |
+ Member<ResourceFetcher> m_fetcher; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif |