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

Side by Side Diff: third_party/WebKit/Source/core/dom/ModulatorImpl.cpp

Issue 2838933003: [not-for-commit] kitsune changes + pending kouhei changes (Closed)
Patch Set: Created 3 years, 8 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/ModulatorImpl.h" 5 #include "core/dom/ModulatorImpl.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/ExecutionContext.h" 8 #include "core/dom/ExecutionContext.h"
9 #include "core/dom/ModuleMap.h" 9 #include "core/dom/ModuleMap.h"
10 #include "core/dom/ModuleScript.h" 10 #include "core/dom/ModuleScript.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 ScriptState::Scope scope(script_state_.Get()); 121 ScriptState::Scope scope(script_state_.Get());
122 return ScriptModule::Compile(script_state_->GetIsolate(), script_source, 122 return ScriptModule::Compile(script_state_->GetIsolate(), script_source,
123 url_str, access_control_status); 123 url_str, access_control_status);
124 } 124 }
125 125
126 ScriptValue ModulatorImpl::InstantiateModule(ScriptModule script_module) { 126 ScriptValue ModulatorImpl::InstantiateModule(ScriptModule script_module) {
127 ScriptState::Scope scope(script_state_.Get()); 127 ScriptState::Scope scope(script_state_.Get());
128 return script_module.Instantiate(script_state_.Get()); 128 return script_module.Instantiate(script_state_.Get());
129 } 129 }
130 130
131 ScriptValue ModulatorImpl::GetInstantiationError(
132 const ModuleScript* module_script) {
133 ScriptState::Scope scope(script_state_.Get());
134 return ScriptValue(
135 script_state_.Get(),
136 module_script->CreateInstantiationError(script_state_->GetIsolate()));
137 }
138
131 Vector<String> ModulatorImpl::ModuleRequestsFromScriptModule( 139 Vector<String> ModulatorImpl::ModuleRequestsFromScriptModule(
132 ScriptModule script_module) { 140 ScriptModule script_module) {
133 ScriptState::Scope scope(script_state_.Get()); 141 ScriptState::Scope scope(script_state_.Get());
134 return script_module.ModuleRequests(script_state_.Get()); 142 return script_module.ModuleRequests(script_state_.Get());
135 } 143 }
136 144
137 inline ExecutionContext* ModulatorImpl::GetExecutionContext() const { 145 inline ExecutionContext* ModulatorImpl::GetExecutionContext() const {
138 return ExecutionContext::From(script_state_.Get()); 146 return ExecutionContext::From(script_state_.Get());
139 } 147 }
140 148
149 void ModulatorImpl::ExecuteModule(const ModuleScript* module_script) {
150 // https://html.spec.whatwg.org/#run-a-module-script
151
152 // 1. "Let settings be the settings object of s."
153 // The settings object is |this|.
154
155 // 2. "Check if we can run script with settings.
156 // If this returns "do not run" then abort these steps."
157 if (!GetExecutionContext()->CanExecuteScripts(kAboutToExecuteScript))
158 return;
159
160 ScriptState::Scope scope(script_state_.Get());
161
162 // 3. "If s's instantiation state is "errored", then report the exception
163 // given by s's instantiation error for s and abort these steps."
164 ModuleInstantiationState instantiationState =
165 module_script->InstantiationState();
166 if (instantiationState == ModuleInstantiationState::kErrored) {
167 v8::Isolate* isolate = script_state_->GetIsolate();
168 ScriptModule::ReportException(
169 script_state_.Get(), module_script->CreateInstantiationError(isolate),
170 module_script->BaseURL().GetString());
171 return;
172 }
173
174 // 4. "Assert: s's instantiation state is "instantiated" (and thus its
175 // module record is not null)."
176 CHECK_EQ(instantiationState, ModuleInstantiationState::kInstantiated);
177
178 // 5. "Let record be s's module record."
179 const ScriptModule& record = module_script->Record();
180 CHECK(!record.IsNull());
181
182 // 6.--9.?
183 record.Evaluate(script_state_.Get());
184 }
185
141 DEFINE_TRACE(ModulatorImpl) { 186 DEFINE_TRACE(ModulatorImpl) {
142 Modulator::Trace(visitor); 187 Modulator::Trace(visitor);
143 visitor->Trace(fetcher_); 188 visitor->Trace(fetcher_);
144 visitor->Trace(map_); 189 visitor->Trace(map_);
145 visitor->Trace(loader_registry_); 190 visitor->Trace(loader_registry_);
146 visitor->Trace(tree_linker_registry_); 191 visitor->Trace(tree_linker_registry_);
147 visitor->Trace(script_module_resolver_); 192 visitor->Trace(script_module_resolver_);
148 } 193 }
149 194
150 DEFINE_TRACE_WRAPPERS(ModulatorImpl) { 195 DEFINE_TRACE_WRAPPERS(ModulatorImpl) {
151 visitor->TraceWrappers(map_); 196 visitor->TraceWrappers(map_);
152 } 197 }
153 198
154 } // namespace blink 199 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698