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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp

Issue 2843873002: Insert CHECK()s to ensure module-related code are not executed without the flag (Closed)
Patch Set: Rebase Created 3 years, 7 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 "bindings/core/v8/ScriptModule.h" 5 #include "bindings/core/v8/ScriptModule.h"
6 6
7 #include "bindings/core/v8/V8BindingForCore.h" 7 #include "bindings/core/v8/V8BindingForCore.h"
8 #include "core/dom/Modulator.h" 8 #include "core/dom/Modulator.h"
9 #include "core/dom/ScriptModuleResolver.h" 9 #include "core/dom/ScriptModuleResolver.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 ScriptModule::ScriptModule() {
14 // We ensure module-related code is not executed without the flag.
15 // https://crbug.com/715376
16 CHECK(RuntimeEnabledFeatures::moduleScriptsEnabled());
17 }
18
19 ScriptModule::ScriptModule(WTF::HashTableDeletedValueType)
20 : module_(WTF::kHashTableDeletedValue) {
21 // We ensure module-related code is not executed without the flag.
22 // https://crbug.com/715376
23 CHECK(RuntimeEnabledFeatures::moduleScriptsEnabled());
24 }
25
13 ScriptModule::ScriptModule(v8::Isolate* isolate, v8::Local<v8::Module> module) 26 ScriptModule::ScriptModule(v8::Isolate* isolate, v8::Local<v8::Module> module)
14 : module_(SharedPersistent<v8::Module>::Create(module, isolate)), 27 : module_(SharedPersistent<v8::Module>::Create(module, isolate)),
15 identity_hash_(static_cast<unsigned>(module->GetIdentityHash())) { 28 identity_hash_(static_cast<unsigned>(module->GetIdentityHash())) {
29 // We ensure module-related code is not executed without the flag.
30 // https://crbug.com/715376
31 CHECK(RuntimeEnabledFeatures::moduleScriptsEnabled());
32
16 DCHECK(!module_->IsEmpty()); 33 DCHECK(!module_->IsEmpty());
17 } 34 }
18 35
19 ScriptModule::~ScriptModule() {} 36 ScriptModule::~ScriptModule() {}
20 37
21 ScriptModule ScriptModule::Compile(v8::Isolate* isolate, 38 ScriptModule ScriptModule::Compile(v8::Isolate* isolate,
22 const String& source, 39 const String& source,
23 const String& file_name, 40 const String& file_name,
24 AccessControlStatus access_control_status) { 41 AccessControlStatus access_control_status) {
42 // We ensure module-related code is not executed without the flag.
43 // https://crbug.com/715376
44 CHECK(RuntimeEnabledFeatures::moduleScriptsEnabled());
45
25 v8::TryCatch try_catch(isolate); 46 v8::TryCatch try_catch(isolate);
26 try_catch.SetVerbose(true); 47 try_catch.SetVerbose(true);
27 v8::Local<v8::Module> module; 48 v8::Local<v8::Module> module;
28 if (!V8ScriptRunner::CompileModule(isolate, source, file_name, 49 if (!V8ScriptRunner::CompileModule(isolate, source, file_name,
29 access_control_status) 50 access_control_status)
30 .ToLocal(&module)) { 51 .ToLocal(&module)) {
31 // Compilation error is not used in Blink implementaion logic. 52 // Compilation error is not used in Blink implementaion logic.
32 // Note: Error message is delivered to user (e.g. console) by message 53 // Note: Error message is delivered to user (e.g. console) by message
33 // listeners set on v8::Isolate. See V8Initializer::initalizeMainThread(). 54 // listeners set on v8::Isolate. See V8Initializer::initalizeMainThread().
34 // TODO(nhiroki): Revisit this when supporting modules on worker threads. 55 // TODO(nhiroki): Revisit this when supporting modules on worker threads.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (!V8ScriptRunner::EvaluateModule(module_->NewLocal(isolate), 92 if (!V8ScriptRunner::EvaluateModule(module_->NewLocal(isolate),
72 script_state->GetContext(), isolate) 93 script_state->GetContext(), isolate)
73 .ToLocal(&result)) { 94 .ToLocal(&result)) {
74 return; 95 return;
75 } 96 }
76 } 97 }
77 98
78 void ScriptModule::ReportException(ScriptState* script_state, 99 void ScriptModule::ReportException(ScriptState* script_state,
79 v8::Local<v8::Value> exception, 100 v8::Local<v8::Value> exception,
80 const String& file_name) { 101 const String& file_name) {
102 // We ensure module-related code is not executed without the flag.
103 // https://crbug.com/715376
104 CHECK(RuntimeEnabledFeatures::moduleScriptsEnabled());
105
81 v8::Isolate* isolate = script_state->GetIsolate(); 106 v8::Isolate* isolate = script_state->GetIsolate();
82 107
83 v8::TryCatch try_catch(isolate); 108 v8::TryCatch try_catch(isolate);
84 try_catch.SetVerbose(true); 109 try_catch.SetVerbose(true);
85 110
86 V8ScriptRunner::ReportExceptionForModule(isolate, exception, file_name); 111 V8ScriptRunner::ReportExceptionForModule(isolate, exception, file_name);
87 } 112 }
88 113
89 Vector<String> ScriptModule::ModuleRequests(ScriptState* script_state) { 114 Vector<String> ScriptModule::ModuleRequests(ScriptState* script_state) {
90 if (IsNull()) 115 if (IsNull())
91 return Vector<String>(); 116 return Vector<String>();
92 117
93 v8::Local<v8::Module> module = module_->NewLocal(script_state->GetIsolate()); 118 v8::Local<v8::Module> module = module_->NewLocal(script_state->GetIsolate());
94 119
95 Vector<String> ret; 120 Vector<String> ret;
96 121
97 int length = module->GetModuleRequestsLength(); 122 int length = module->GetModuleRequestsLength();
98 ret.ReserveInitialCapacity(length); 123 ret.ReserveInitialCapacity(length);
99 for (int i = 0; i < length; ++i) { 124 for (int i = 0; i < length; ++i) {
100 v8::Local<v8::String> v8_name = module->GetModuleRequest(i); 125 v8::Local<v8::String> v8_name = module->GetModuleRequest(i);
101 ret.push_back(ToCoreString(v8_name)); 126 ret.push_back(ToCoreString(v8_name));
102 } 127 }
103 return ret; 128 return ret;
104 } 129 }
105 130
106 v8::MaybeLocal<v8::Module> ScriptModule::ResolveModuleCallback( 131 v8::MaybeLocal<v8::Module> ScriptModule::ResolveModuleCallback(
107 v8::Local<v8::Context> context, 132 v8::Local<v8::Context> context,
108 v8::Local<v8::String> specifier, 133 v8::Local<v8::String> specifier,
109 v8::Local<v8::Module> referrer) { 134 v8::Local<v8::Module> referrer) {
135 // We ensure module-related code is not executed without the flag.
136 // https://crbug.com/715376
137 CHECK(RuntimeEnabledFeatures::moduleScriptsEnabled());
138
110 v8::Isolate* isolate = context->GetIsolate(); 139 v8::Isolate* isolate = context->GetIsolate();
111 Modulator* modulator = Modulator::From(ScriptState::From(context)); 140 Modulator* modulator = Modulator::From(ScriptState::From(context));
112 DCHECK(modulator); 141 DCHECK(modulator);
113 142
114 ScriptModule referrer_record(isolate, referrer); 143 ScriptModule referrer_record(isolate, referrer);
115 ExceptionState exception_state(isolate, ExceptionState::kExecutionContext, 144 ExceptionState exception_state(isolate, ExceptionState::kExecutionContext,
116 "ScriptModule", "resolveModuleCallback"); 145 "ScriptModule", "resolveModuleCallback");
117 ScriptModule resolved = modulator->GetScriptModuleResolver()->Resolve( 146 ScriptModule resolved = modulator->GetScriptModuleResolver()->Resolve(
118 ToCoreStringWithNullCheck(specifier), referrer_record, exception_state); 147 ToCoreStringWithNullCheck(specifier), referrer_record, exception_state);
119 if (resolved.IsNull()) { 148 if (resolved.IsNull()) {
120 DCHECK(exception_state.HadException()); 149 DCHECK(exception_state.HadException());
121 return v8::MaybeLocal<v8::Module>(); 150 return v8::MaybeLocal<v8::Module>();
122 } 151 }
123 152
124 DCHECK(!exception_state.HadException()); 153 DCHECK(!exception_state.HadException());
125 return v8::MaybeLocal<v8::Module>(resolved.module_->NewLocal(isolate)); 154 return v8::MaybeLocal<v8::Module>(resolved.module_->NewLocal(isolate));
126 } 155 }
127 156
128 } // namespace blink 157 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ScriptModule.h ('k') | third_party/WebKit/Source/core/dom/ModulatorImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698