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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/ModulatorImpl.cpp
diff --git a/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp b/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp
index b41d3a4038568b5a5c0940a95339b1d9484e49ce..0de68c9d76a278de233bc2435d7a2d5e549c8fe8 100644
--- a/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp
+++ b/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp
@@ -4,6 +4,7 @@
#include "core/dom/ModulatorImpl.h"
+#include "bindings/core/v8/V8Binding.h"
#include "core/dom/Document.h"
#include "core/dom/ExecutionContext.h"
#include "core/dom/ModuleMap.h"
@@ -15,6 +16,7 @@
#include "core/loader/modulescript/ModuleScriptLoaderRegistry.h"
#include "core/loader/modulescript/ModuleTreeLinkerRegistry.h"
#include "platform/loader/fetch/ResourceFetcher.h"
+#include "v8/include/v8.h"
namespace blink {
@@ -134,6 +136,52 @@ Vector<String> ModulatorImpl::ModuleRequestsFromScriptModule(
return script_module.ModuleRequests(script_state_.Get());
}
+void ModulatorImpl::ExecuteModule(const ModuleScript* module_script) {
+ // https://html.spec.whatwg.org/#run-a-module-script
+ ScriptState::Scope scope(script_state_.Get());
+
+ // 3. "If s's instantiation state is "errored", then report the exception
+ // given by s's instantiation error for s and abort these steps."
+ printf("Exec module %p\n", module_script);
+ ModuleInstantiationState instantiationState =
+ module_script->InstantiationState();
+ if (instantiationState == ModuleInstantiationState::kErrored) {
+ v8::Isolate* isolate = script_state_->GetIsolate();
+
+ v8::TryCatch try_catch(isolate);
+ try_catch.SetVerbose(true);
+
+ // TODO(hiroshige): fix below
+ AccessControlStatus access_control_status = kSharableCrossOrigin;
+ v8::ScriptOrigin origin(
+ V8String(isolate, "fixme_get_this_info_from_module_script.js"),
+ v8::Integer::New(isolate, 0), // line_offset
+ v8::Integer::New(isolate, 0), // col_offset
+ V8Boolean(access_control_status == kSharableCrossOrigin, isolate),
+ v8::Local<v8::Integer>(), // script id
+ V8String(isolate, ""), // source_map_url
+ V8Boolean(access_control_status == kOpaqueResource, isolate),
+ V8Boolean(false, isolate), // is_wasm
+ V8Boolean(false, isolate)); // is_module
+ // ^^^ is_module = false to compile a fragment that throws exception
+
+ V8ScriptRunner::ThrowException(
+ isolate, module_script->CreateInstantiationError(isolate), origin);
+ return;
+ }
+
+ // 4. "Assert: s's instantiation state is "instantiated" (and thus its
+ // module record is not null)."
+ CHECK_EQ(instantiationState, ModuleInstantiationState::kInstantiated);
+
+ // 5. "Let record be s's module record."
+ const ScriptModule& record = module_script->Record();
+ CHECK(!record.IsNull());
+
+ // 6.--9.?
+ record.Evaluate(script_state_.Get());
+}
+
inline ExecutionContext* ModulatorImpl::GetExecutionContext() const {
return ExecutionContext::From(script_state_.Get());
}
« 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