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

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

Issue 2903813002: [ES6 modules] Fix context leak. ModuleScript should use TraceWrapperV8Reference to hold onto v8::Mo… (Closed)
Patch Set: expected.txt Created 3 years, 6 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/ModuleScript.h" 5 #include "core/dom/ModuleScript.h"
6 6
7 #include "bindings/core/v8/ScriptValue.h" 7 #include "bindings/core/v8/ScriptValue.h"
8 #include "core/dom/ScriptModuleResolver.h" 8 #include "core/dom/ScriptModuleResolver.h"
9 #include "platform/bindings/ScriptState.h" 9 #include "platform/bindings/ScriptState.h"
10 #include "v8/include/v8.h" 10 #include "v8/include/v8.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 ScriptModule record, 71 ScriptModule record,
72 const KURL& base_url, 72 const KURL& base_url,
73 const String& nonce, 73 const String& nonce,
74 ParserDisposition parser_state, 74 ParserDisposition parser_state,
75 WebURLRequest::FetchCredentialsMode credentials_mode) { 75 WebURLRequest::FetchCredentialsMode credentials_mode) {
76 String dummy_source_text = ""; 76 String dummy_source_text = "";
77 return CreateInternal(dummy_source_text, modulator, record, base_url, nonce, 77 return CreateInternal(dummy_source_text, modulator, record, base_url, nonce,
78 parser_state, credentials_mode); 78 parser_state, credentials_mode);
79 } 79 }
80 80
81 ModuleScript::ModuleScript(Modulator* settings_object,
82 ScriptModule record,
83 const KURL& base_url,
84 const String& nonce,
85 ParserDisposition parser_state,
86 WebURLRequest::FetchCredentialsMode credentials_mode,
87 const String& source_text)
88 : settings_object_(settings_object),
89 record_(this),
90 base_url_(base_url),
91 instantiation_error_(this),
92 nonce_(nonce),
93 parser_state_(parser_state),
94 credentials_mode_(credentials_mode),
95 source_text_(source_text) {
96 DCHECK(settings_object);
97 v8::Isolate* isolate = settings_object_->GetScriptState()->GetIsolate();
98 v8::HandleScope scope(isolate);
99 record_.Set(isolate, record.NewLocal(isolate));
100 }
101
102 ScriptModule ModuleScript::Record() const {
103 v8::Isolate* isolate = settings_object_->GetScriptState()->GetIsolate();
104 v8::HandleScope scope(isolate);
105 return ScriptModule(isolate, record_.NewLocal(isolate));
106 }
107
81 void ModuleScript::SetInstantiationErrorAndClearRecord(ScriptValue error) { 108 void ModuleScript::SetInstantiationErrorAndClearRecord(ScriptValue error) {
82 // Implements Step 7.1 of: 109 // Implements Step 7.1 of:
83 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri pt-graph-fetching-procedure 110 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri pt-graph-fetching-procedure
84 111
85 // "set script's instantiation state to "errored", ..." 112 // "set script's instantiation state to "errored", ..."
86 DCHECK_EQ(instantiation_state_, ModuleInstantiationState::kUninstantiated); 113 DCHECK_EQ(instantiation_state_, ModuleInstantiationState::kUninstantiated);
87 instantiation_state_ = ModuleInstantiationState::kErrored; 114 instantiation_state_ = ModuleInstantiationState::kErrored;
88 115
89 // "its instantiation error to instantiationStatus.[[Value]], and ..." 116 // "its instantiation error to instantiationStatus.[[Value]], and ..."
90 DCHECK(!error.IsEmpty()); 117 DCHECK(!error.IsEmpty());
91 { 118 {
92 ScriptState::Scope scope(error.GetScriptState()); 119 ScriptState::Scope scope(error.GetScriptState());
93 instantiation_error_.Set(error.GetIsolate(), error.V8Value()); 120 instantiation_error_.Set(error.GetIsolate(), error.V8Value());
94 } 121 }
95 122
96 // "its module record to null." 123 // "its module record to null."
97 record_ = ScriptModule(); 124 record_.Clear();
98 } 125 }
99 126
100 void ModuleScript::SetInstantiationSuccess() { 127 void ModuleScript::SetInstantiationSuccess() {
101 // Implements Step 7.2 of: 128 // Implements Step 7.2 of:
102 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri pt-graph-fetching-procedure 129 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri pt-graph-fetching-procedure
103 130
104 // "set script's instantiation state to "instantiated"." 131 // "set script's instantiation state to "instantiated"."
105 DCHECK_EQ(instantiation_state_, ModuleInstantiationState::kUninstantiated); 132 DCHECK_EQ(instantiation_state_, ModuleInstantiationState::kUninstantiated);
106 instantiation_state_ = ModuleInstantiationState::kInstantiated; 133 instantiation_state_ = ModuleInstantiationState::kInstantiated;
107 } 134 }
108 135
109 DEFINE_TRACE(ModuleScript) { 136 DEFINE_TRACE(ModuleScript) {
110 visitor->Trace(settings_object_); 137 visitor->Trace(settings_object_);
111 Script::Trace(visitor); 138 Script::Trace(visitor);
112 } 139 }
113 DEFINE_TRACE_WRAPPERS(ModuleScript) { 140 DEFINE_TRACE_WRAPPERS(ModuleScript) {
141 // TODO(mlippautz): Support TraceWrappers(const
142 // TraceWrapperV8Reference<v8::Module>&) to remove the cast.
143 visitor->TraceWrappers(record_.Cast<v8::Value>());
114 visitor->TraceWrappers(instantiation_error_); 144 visitor->TraceWrappers(instantiation_error_);
115 } 145 }
116 146
117 bool ModuleScript::IsEmpty() const { 147 bool ModuleScript::IsEmpty() const {
118 return false; 148 return false;
119 } 149 }
120 150
121 bool ModuleScript::CheckMIMETypeBeforeRunScript(Document* context_document, 151 bool ModuleScript::CheckMIMETypeBeforeRunScript(Document* context_document,
122 const SecurityOrigin*) const { 152 const SecurityOrigin*) const {
123 // We don't check MIME type here because we check the MIME type in 153 // We don't check MIME type here because we check the MIME type in
124 // ModuleScriptLoader::WasModuleLoadSuccessful(). 154 // ModuleScriptLoader::WasModuleLoadSuccessful().
125 return true; 155 return true;
126 } 156 }
127 157
128 void ModuleScript::RunScript(LocalFrame* frame, const SecurityOrigin*) const { 158 void ModuleScript::RunScript(LocalFrame* frame, const SecurityOrigin*) const {
129 settings_object_->ExecuteModule(this); 159 settings_object_->ExecuteModule(this);
130 } 160 }
131 161
132 String ModuleScript::InlineSourceTextForCSP() const { 162 String ModuleScript::InlineSourceTextForCSP() const {
133 return source_text_; 163 return source_text_;
134 } 164 }
135 165
136 } // namespace blink 166 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698