OLD | NEW |
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 Vector<String> ModulatorImpl::ModuleRequestsFromScriptModule( | 131 Vector<String> ModulatorImpl::ModuleRequestsFromScriptModule( |
132 ScriptModule script_module) { | 132 ScriptModule script_module) { |
133 ScriptState::Scope scope(script_state_.Get()); | 133 ScriptState::Scope scope(script_state_.Get()); |
134 return script_module.ModuleRequests(script_state_.Get()); | 134 return script_module.ModuleRequests(script_state_.Get()); |
135 } | 135 } |
136 | 136 |
137 inline ExecutionContext* ModulatorImpl::GetExecutionContext() const { | 137 inline ExecutionContext* ModulatorImpl::GetExecutionContext() const { |
138 return ExecutionContext::From(script_state_.Get()); | 138 return ExecutionContext::From(script_state_.Get()); |
139 } | 139 } |
140 | 140 |
| 141 void ModulatorImpl::ExecuteModule(const ModuleScript* module_script) { |
| 142 // https://html.spec.whatwg.org/#run-a-module-script |
| 143 |
| 144 // 1. "Let settings be the settings object of s." |
| 145 // The settings object is |this|. |
| 146 |
| 147 // 2. "Check if we can run script with settings. |
| 148 // If this returns "do not run" then abort these steps." |
| 149 if (!GetExecutionContext()->CanExecuteScripts(kAboutToExecuteScript)) |
| 150 return; |
| 151 |
| 152 // 6. "Prepare to run script given settings." |
| 153 // This is placed here to also cover ScriptModule::ReportException(). |
| 154 ScriptState::Scope scope(script_state_.Get()); |
| 155 |
| 156 // 3. "If s's instantiation state is "errored", then report the exception |
| 157 // given by s's instantiation error for s and abort these steps." |
| 158 ModuleInstantiationState instantiationState = |
| 159 module_script->InstantiationState(); |
| 160 if (instantiationState == ModuleInstantiationState::kErrored) { |
| 161 v8::Isolate* isolate = script_state_->GetIsolate(); |
| 162 ScriptModule::ReportException( |
| 163 script_state_.Get(), module_script->CreateInstantiationError(isolate), |
| 164 module_script->BaseURL().GetString()); |
| 165 return; |
| 166 } |
| 167 |
| 168 // 4. "Assert: s's instantiation state is "instantiated" (and thus its |
| 169 // module record is not null)." |
| 170 CHECK_EQ(instantiationState, ModuleInstantiationState::kInstantiated); |
| 171 |
| 172 // 5. "Let record be s's module record." |
| 173 const ScriptModule& record = module_script->Record(); |
| 174 CHECK(!record.IsNull()); |
| 175 |
| 176 // Steps 7 and 8. |
| 177 record.Evaluate(script_state_.Get()); |
| 178 |
| 179 // 9. "Clean up after running script with settings." |
| 180 // Implemented as the ScriptState::Scope destructor. |
| 181 } |
| 182 |
141 DEFINE_TRACE(ModulatorImpl) { | 183 DEFINE_TRACE(ModulatorImpl) { |
142 Modulator::Trace(visitor); | 184 Modulator::Trace(visitor); |
143 visitor->Trace(fetcher_); | 185 visitor->Trace(fetcher_); |
144 visitor->Trace(map_); | 186 visitor->Trace(map_); |
145 visitor->Trace(loader_registry_); | 187 visitor->Trace(loader_registry_); |
146 visitor->Trace(tree_linker_registry_); | 188 visitor->Trace(tree_linker_registry_); |
147 visitor->Trace(script_module_resolver_); | 189 visitor->Trace(script_module_resolver_); |
148 } | 190 } |
149 | 191 |
150 DEFINE_TRACE_WRAPPERS(ModulatorImpl) { | 192 DEFINE_TRACE_WRAPPERS(ModulatorImpl) { |
151 visitor->TraceWrappers(map_); | 193 visitor->TraceWrappers(map_); |
152 } | 194 } |
153 | 195 |
154 } // namespace blink | 196 } // namespace blink |
OLD | NEW |