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

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: rebased 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 "bindings/core/v8/V8Binding.h"
7 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
8 #include "core/dom/ExecutionContext.h" 9 #include "core/dom/ExecutionContext.h"
9 #include "core/dom/ModuleMap.h" 10 #include "core/dom/ModuleMap.h"
10 #include "core/dom/ModuleScript.h" 11 #include "core/dom/ModuleScript.h"
11 #include "core/dom/ScriptModuleResolverImpl.h" 12 #include "core/dom/ScriptModuleResolverImpl.h"
12 #include "core/dom/TaskRunnerHelper.h" 13 #include "core/dom/TaskRunnerHelper.h"
13 #include "core/frame/LocalFrame.h" 14 #include "core/frame/LocalFrame.h"
14 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" 15 #include "core/loader/modulescript/ModuleScriptFetchRequest.h"
15 #include "core/loader/modulescript/ModuleScriptLoaderRegistry.h" 16 #include "core/loader/modulescript/ModuleScriptLoaderRegistry.h"
16 #include "core/loader/modulescript/ModuleTreeLinkerRegistry.h" 17 #include "core/loader/modulescript/ModuleTreeLinkerRegistry.h"
17 #include "platform/loader/fetch/ResourceFetcher.h" 18 #include "platform/loader/fetch/ResourceFetcher.h"
19 #include "v8/include/v8.h"
18 20
19 namespace blink { 21 namespace blink {
20 22
21 ModulatorImpl* ModulatorImpl::Create(RefPtr<ScriptState> script_state, 23 ModulatorImpl* ModulatorImpl::Create(RefPtr<ScriptState> script_state,
22 Document& document) { 24 Document& document) {
23 return new ModulatorImpl( 25 return new ModulatorImpl(
24 std::move(script_state), 26 std::move(script_state),
25 TaskRunnerHelper::Get(TaskType::kNetworking, &document), 27 TaskRunnerHelper::Get(TaskType::kNetworking, &document),
26 document.Fetcher()); 28 document.Fetcher());
27 } 29 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 ScriptState::Scope scope(script_state_.Get()); 129 ScriptState::Scope scope(script_state_.Get());
128 return script_module.Instantiate(script_state_.Get()); 130 return script_module.Instantiate(script_state_.Get());
129 } 131 }
130 132
131 Vector<String> ModulatorImpl::ModuleRequestsFromScriptModule( 133 Vector<String> ModulatorImpl::ModuleRequestsFromScriptModule(
132 ScriptModule script_module) { 134 ScriptModule script_module) {
133 ScriptState::Scope scope(script_state_.Get()); 135 ScriptState::Scope scope(script_state_.Get());
134 return script_module.ModuleRequests(script_state_.Get()); 136 return script_module.ModuleRequests(script_state_.Get());
135 } 137 }
136 138
139 void ModulatorImpl::ExecuteModule(const ModuleScript* module_script) {
140 // https://html.spec.whatwg.org/#run-a-module-script
141 ScriptState::Scope scope(script_state_.Get());
142
143 // 3. "If s's instantiation state is "errored", then report the exception
144 // given by s's instantiation error for s and abort these steps."
145 printf("Exec module %p\n", module_script);
146 ModuleInstantiationState instantiationState =
147 module_script->InstantiationState();
148 if (instantiationState == ModuleInstantiationState::kErrored) {
149 v8::Isolate* isolate = script_state_->GetIsolate();
150
151 v8::TryCatch try_catch(isolate);
152 try_catch.SetVerbose(true);
153
154 // TODO(hiroshige): fix below
155 AccessControlStatus access_control_status = kSharableCrossOrigin;
156 v8::ScriptOrigin origin(
157 V8String(isolate, "fixme_get_this_info_from_module_script.js"),
158 v8::Integer::New(isolate, 0), // line_offset
159 v8::Integer::New(isolate, 0), // col_offset
160 V8Boolean(access_control_status == kSharableCrossOrigin, isolate),
161 v8::Local<v8::Integer>(), // script id
162 V8String(isolate, ""), // source_map_url
163 V8Boolean(access_control_status == kOpaqueResource, isolate),
164 V8Boolean(false, isolate), // is_wasm
165 V8Boolean(false, isolate)); // is_module
166 // ^^^ is_module = false to compile a fragment that throws exception
167
168 V8ScriptRunner::ThrowException(
169 isolate, module_script->CreateInstantiationError(isolate), origin);
170 return;
171 }
172
173 // 4. "Assert: s's instantiation state is "instantiated" (and thus its
174 // module record is not null)."
175 CHECK_EQ(instantiationState, ModuleInstantiationState::kInstantiated);
176
177 // 5. "Let record be s's module record."
178 const ScriptModule& record = module_script->Record();
179 CHECK(!record.IsNull());
180
181 // 6.--9.?
182 record.Evaluate(script_state_.Get());
183 }
184
137 inline ExecutionContext* ModulatorImpl::GetExecutionContext() const { 185 inline ExecutionContext* ModulatorImpl::GetExecutionContext() const {
138 return ExecutionContext::From(script_state_.Get()); 186 return ExecutionContext::From(script_state_.Get());
139 } 187 }
140 188
141 DEFINE_TRACE(ModulatorImpl) { 189 DEFINE_TRACE(ModulatorImpl) {
142 Modulator::Trace(visitor); 190 Modulator::Trace(visitor);
143 visitor->Trace(fetcher_); 191 visitor->Trace(fetcher_);
144 visitor->Trace(map_); 192 visitor->Trace(map_);
145 visitor->Trace(loader_registry_); 193 visitor->Trace(loader_registry_);
146 visitor->Trace(tree_linker_registry_); 194 visitor->Trace(tree_linker_registry_);
147 visitor->Trace(script_module_resolver_); 195 visitor->Trace(script_module_resolver_);
148 } 196 }
149 197
150 DEFINE_TRACE_WRAPPERS(ModulatorImpl) { 198 DEFINE_TRACE_WRAPPERS(ModulatorImpl) {
151 visitor->TraceWrappers(map_); 199 visitor->TraceWrappers(map_);
152 } 200 }
153 201
154 } // namespace blink 202 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ModulatorImpl.h ('k') | third_party/WebKit/Source/core/dom/ModulePendingScript.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698