OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ModuleMap_h | |
6 #define ModuleMap_h | |
7 | |
8 #include "platform/heap/Handle.h" | |
9 #include "platform/weborigin/KURL.h" | |
10 #include "platform/weborigin/KURLHash.h" | |
11 #include "wtf/HashMap.h" | |
12 #include "wtf/HashTableDeletedValueType.h" | |
13 | |
14 namespace blink { | |
15 | |
16 class ResourceFetcher; | |
17 | |
18 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.
| |
19 public: | |
20 static ModuleScript* create() { return new ModuleScript(); } | |
21 DEFINE_INLINE_TRACE() {} | |
22 | |
23 private: | |
24 ModuleScript() {} | |
25 }; | |
26 | |
27 class ModuleMap : public GarbageCollected<ModuleMap> { | |
28 WTF_MAKE_NONCOPYABLE(ModuleMap); | |
29 | |
30 public: | |
31 static ModuleMap* create(ResourceFetcher* fetcher) { return new ModuleMap(fetc her); } | |
32 DECLARE_TRACE(); | |
33 | |
34 // https://html.spec.whatwg.org/#fetch-a-single-module-script | |
35 void fetch( | |
36 const KURL& url | |
37 /*, a fetch client settings object, a destination, a cryptographic nonce, a parser state, a credentials mode, a module map settings object, a referrer, an d a top-level module fetch flag*/); // => ModuleScript* | |
38 | |
39 private: | |
40 ModuleMap(ResourceFetcher*); | |
41 ModuleMap() = delete; | |
42 | |
43 // either a module script, null (used to represent failed fetches), or a | |
44 // placeholder value "fetching". Module maps are used to ensure that imported | |
45 // JavaScript modules are only fetched, parsed, and evaluated once per | |
46 // Document or worker. | |
47 class Entry { | |
48 public: | |
49 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | |
50 | |
51 enum class State { | |
52 Fetching, | |
53 Fetched, | |
54 Failed, | |
55 Deleted, | |
56 }; | |
57 | |
58 Entry() : m_state(State::Fetching) {} | |
59 Entry(WTF::HashTableDeletedValueType) : m_state(State::Deleted) {} | |
60 | |
61 bool isFetching() const { return m_state == State::Fetching; } | |
62 | |
63 ModuleScript* moduleScript() { | |
64 if (!m_moduleScript) | |
65 return nullptr; | |
66 | |
67 DCHECK_EQ(m_state, State::Fetched); | |
68 return m_moduleScript; | |
69 } | |
70 | |
71 DEFINE_INLINE_TRACE() { visitor->trace(m_moduleScript); } | |
72 | |
73 private: | |
74 State m_state; | |
75 Member<ModuleScript> m_moduleScript; | |
76 }; | |
77 | |
78 using MapImpl = HeapHashMap<KURL, Entry>; | |
79 | |
80 // A module map is a map of absolute URLs to values | |
81 MapImpl m_map; | |
82 | |
83 Member<ResourceFetcher> m_fetcher; | |
84 }; | |
85 | |
86 } // namespace blink | |
87 | |
88 #endif | |
OLD | NEW |