OLD | NEW |
---|---|
(Empty) | |
1 // 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
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/dom/ModulatorImpl.h" | |
6 | |
7 #include "core/dom/Document.h" | |
8 #include "core/dom/ModuleMap.h" | |
9 #include "core/dom/ModuleScript.h" | |
10 #include "core/dom/ScriptModuleResolverImpl.h" | |
11 #include "core/dom/TaskRunnerHelper.h" | |
12 #include "core/fetch/ResourceFetcher.h" | |
13 #include "core/loader/modulescript/ModuleScriptLoaderRegistry.h" | |
14 #include "core/loader/modulescript/ModuleTreeLinkerRegistry.h" | |
15 | |
16 namespace blink { | |
17 | |
18 ModulatorImpl* ModulatorImpl::create(RefPtr<ScriptState> scriptState, | |
19 Document& document) { | |
20 return new ModulatorImpl( | |
21 std::move(scriptState), | |
22 TaskRunnerHelper::get(TaskType::Networking, &document), | |
23 document.fetcher()); | |
24 } | |
25 | |
26 ModulatorImpl::ModulatorImpl(RefPtr<ScriptState> scriptState, | |
27 WebTaskRunner* taskRunner, | |
28 ResourceFetcher* fetcher) | |
29 : m_scriptState(std::move(scriptState)), | |
30 m_taskRunner(taskRunner->clone()), | |
31 m_fetcher(fetcher), | |
32 m_map(ModuleMap::create(this)), | |
33 m_loaderRegistry(ModuleScriptLoaderRegistry::create()), | |
34 m_treeLinkerRegistry(ModuleTreeLinkerRegistry::create()), | |
35 m_scriptModuleResolver(ScriptModuleResolverImpl::create(this)) { | |
36 DCHECK(m_scriptState); | |
37 DCHECK(m_fetcher); | |
38 } | |
39 | |
40 ModulatorImpl::~ModulatorImpl() {} | |
41 | |
42 void ModulatorImpl::fetchTree(const KURL& url, | |
43 const KURL& baseURL, | |
44 ModuleTreeClient* client) { | |
45 // Step 1. Perform the internal module script graph fetching procedure given | |
46 // url, settings object, destination, cryptographic nonce, parser state, | |
47 // credentials mode, settings object, a new empty list, "client", and with the | |
48 // top-level module fetch flag set. If the caller of this algorithm specified | |
49 // custom perform the fetch steps, pass those along as well. | |
50 HashSet<KURL> emptyAncestorList; | |
51 m_treeLinkerRegistry->fetch(url, baseURL, emptyAncestorList, this, client); | |
52 | |
53 // Step 2. When the internal module script graph fetching procedure | |
54 // asynchronously completes with result, asynchronously complete this | |
55 // algorithm with result. | |
56 } | |
57 | |
58 void ModulatorImpl::fetchSingle(const KURL& url, | |
59 const KURL& baseURL, | |
60 SingleModuleClient* client) { | |
61 m_map->retrieveAndFetchIfNeeded(url, baseURL, client); | |
62 } | |
63 | |
64 void ModulatorImpl::fetchNewSingleModule(const KURL& url, | |
65 const KURL& baseURL, | |
66 ModuleScriptLoaderClient* client) { | |
67 m_loaderRegistry->fetch(url, baseURL, this, m_fetcher.get(), client); | |
68 } | |
69 | |
70 ModuleScript* ModulatorImpl::retrieveFetchedModuleScript(const KURL& url) { | |
71 return m_map->retrieveFetchedModuleScript(url); | |
72 } | |
73 | |
74 ScriptModule ModulatorImpl::compileModule(const String& script, | |
75 const String& urlStr) { | |
76 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | |
77 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.
| |
78 | |
79 ScriptState::Scope scope(m_scriptState.get()); | |
80 return ScriptModule::compile(isolate, script, urlStr); | |
81 } | |
82 | |
83 bool ModulatorImpl::instantiateModule(ScriptModule scriptModule) { | |
84 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | |
85 v8::HandleScope handleScope(isolate); | |
86 | |
87 ScriptState::Scope scope(m_scriptState.get()); | |
88 return scriptModule.instantiate(m_scriptState.get()); | |
89 } | |
90 | |
91 Vector<String> ModulatorImpl::moduleRequestsFromScriptModule( | |
92 ScriptModule scriptModule) { | |
93 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | |
94 v8::HandleScope handleScope(isolate); | |
95 | |
96 ScriptState::Scope scope(m_scriptState.get()); | |
97 return scriptModule.moduleRequests(m_scriptState.get()); | |
98 } | |
99 | |
100 void ModulatorImpl::executeModule(ScriptModule scriptModule) { | |
101 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | |
102 v8::HandleScope handleScope(isolate); | |
103 | |
104 ScriptState::Scope scope(m_scriptState.get()); | |
105 | |
106 v8::MicrotasksScope microtasksScope(isolate, | |
107 v8::MicrotasksScope::kRunMicrotasks); | |
108 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
| |
109 } | |
110 | |
111 DEFINE_TRACE(ModulatorImpl) { | |
112 visitor->trace(m_map); | |
113 visitor->trace(m_fetcher); | |
114 visitor->trace(m_loaderRegistry); | |
115 visitor->trace(m_treeLinkerRegistry); | |
116 visitor->trace(m_scriptModuleResolver); | |
117 } | |
118 | |
119 } // namespace blink | |
OLD | NEW |