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

Side by Side 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: snapshot Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 #include "core/dom/ModulatorImpl.h"
6
7 #include "core/dom/Document.h"
8 #include "core/dom/ExecutionContext.h"
9 #include "core/dom/ModuleMap.h"
10 #include "core/dom/ModuleScript.h"
11 #include "core/dom/ScriptModuleResolverImpl.h"
12 #include "core/dom/TaskRunnerHelper.h"
13 #include "core/frame/LocalFrame.h"
14 #include "core/loader/modulescript//ModuleScriptFetchRequest.h"
15 #include "core/loader/modulescript/ModuleScriptLoaderRegistry.h"
16 #include "core/loader/modulescript/ModuleTreeLinkerRegistry.h"
17 #include "platform/loader/fetch/ResourceFetcher.h"
18
19 namespace blink {
20
21 ModulatorImpl* ModulatorImpl::create(RefPtr<ScriptState> scriptState,
22 Document& document) {
23 return new ModulatorImpl(
24 std::move(scriptState),
25 TaskRunnerHelper::get(TaskType::Networking, &document), &document,
26 document.fetcher());
27 }
28
29 ModulatorImpl::ModulatorImpl(RefPtr<ScriptState> scriptState,
30 RefPtr<WebTaskRunner> taskRunner,
31 ExecutionContext* executionContext,
32 ResourceFetcher* fetcher)
33 : m_scriptState(std::move(scriptState)),
34 m_taskRunner(std::move(taskRunner)),
35 m_executionContext(executionContext),
36 m_fetcher(fetcher),
37 m_map(ModuleMap::create(this)),
38 m_loaderRegistry(ModuleScriptLoaderRegistry::create()),
39 m_treeLinkerRegistry(ModuleTreeLinkerRegistry::create()),
40 m_scriptModuleResolver(ScriptModuleResolverImpl::create(this)) {
41 DCHECK(m_scriptState);
42 DCHECK(m_taskRunner);
43 DCHECK(m_executionContext);
44 DCHECK(m_fetcher);
45 }
46
47 ModulatorImpl::~ModulatorImpl() {}
48
49 ReferrerPolicy ModulatorImpl::referrerPolicy() {
50 return m_executionContext->getReferrerPolicy();
51 }
52
53 void ModulatorImpl::fetchTree(const ModuleScriptFetchRequest& request,
54 ModuleTreeClient* client) {
55 // Step 1. Perform the internal module script graph fetching procedure given
56 // url, settings object, destination, cryptographic nonce, parser state,
57 // credentials mode, settings object, a new empty list, "client", and with the
58 // top-level module fetch flag set. If the caller of this algorithm specified
59 // custom perform the fetch steps, pass those along as well.
60
61 // Note: "Fetch a module script graph" algorithm doesn't have "referrer" as
62 // its argument.
63 DCHECK(request.referrer().isNull());
64
65 AncestorList emptyAncestorList;
66 fetchTreeInternal(request, emptyAncestorList,
67 ModuleGraphLevel::TopLevelModuleFetch, client);
68
69 // Step 2. When the internal module script graph fetching procedure
70 // asynchronously completes with result, asynchronously complete this
71 // algorithm with result.
72 // Note: We delegate to ModuleTreeLinker to notify ModuleTreeClient.
73 }
74
75 void ModulatorImpl::fetchTreeInternal(const ModuleScriptFetchRequest& request,
76 const AncestorList& ancestorList,
77 ModuleGraphLevel level,
78 ModuleTreeClient* client) {
79 m_treeLinkerRegistry->fetch(request, ancestorList, level, this, client);
80 }
81
82 void ModulatorImpl::fetchSingle(const ModuleScriptFetchRequest& request,
83 ModuleGraphLevel level,
84 SingleModuleClient* client) {
85 m_map->retrieveAndFetchIfNeeded(request, level, client);
86 }
87
88 void ModulatorImpl::fetchNewSingleModule(
89 const ModuleScriptFetchRequest& request,
90 ModuleGraphLevel level,
91 ModuleScriptLoaderClient* client) {
92 m_loaderRegistry->fetch(request, level, this, m_fetcher.get(), client);
93 }
94
95 ModuleScript* ModulatorImpl::retrieveFetchedModuleScript(const KURL& url) {
96 return m_map->retrieveFetchedModuleScript(url);
97 }
98
99 ScriptModule ModulatorImpl::compileModule(const String& script,
100 const String& urlStr) {
101 // Implements Steps 3-6 of
102 // https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-module-sc ript
103
104 // Step 3. Let realm be the provided environment settings object's Realm.
105 // Note: Realm is v8::Context.
106 // Step 4. If scripting is disabled for the given environment settings
107 // object's responsible browsing context, then let script source be the empty
108 // string. Otherwise, let script source be the provided script source.
109 // TODO(kouhei): if(m_executionContext->canExecuteScripts) after the CL
110 // landed.
111 // Step 5. Let result be ParseModule(script source, realm, script).
112 // Step 6. If result is a List of errors, report the exception given by the
113 // first element of result for script, return null, and abort these steps.
114 // Note: reporting is routed via V8Initializer::messageHandlerInMainThread.
115 ScriptState::Scope scope(m_scriptState.get());
116 return ScriptModule::compile(m_scriptState->isolate(), script, urlStr);
117 }
118
119 ScriptValue ModulatorImpl::instantiateModule(ScriptModule scriptModule) {
120 ScriptState::Scope scope(m_scriptState.get());
121 return scriptModule.instantiate(m_scriptState.get());
122 }
123
124 Vector<String> ModulatorImpl::moduleRequestsFromScriptModule(
125 ScriptModule scriptModule) {
126 ScriptState::Scope scope(m_scriptState.get());
127 return scriptModule.moduleRequests(m_scriptState.get());
128 }
129
130 void ModulatorImpl::executeModule(ScriptModule scriptModule) {
131 ScriptState::Scope scope(m_scriptState.get());
132 scriptModule.evaluate(m_scriptState.get());
133 }
134
135 DEFINE_TRACE(ModulatorImpl) {
136 visitor->trace(m_executionContext);
137 visitor->trace(m_fetcher);
138 visitor->trace(m_map);
139 visitor->trace(m_loaderRegistry);
140 visitor->trace(m_treeLinkerRegistry);
141 visitor->trace(m_scriptModuleResolver);
142 }
143
144 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ModulatorImpl.h ('k') | third_party/WebKit/Source/core/dom/ModuleMap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698