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

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

Issue 2706243006: Check that PendingScript::m_streamer is always null when resource() is null (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/PendingScript.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 ScriptResource* resource, 51 ScriptResource* resource,
52 const TextPosition& startingPosition, 52 const TextPosition& startingPosition,
53 bool isForTesting) 53 bool isForTesting)
54 : m_watchingForLoad(false), 54 : m_watchingForLoad(false),
55 m_element(element), 55 m_element(element),
56 m_startingPosition(startingPosition), 56 m_startingPosition(startingPosition),
57 m_integrityFailure(false), 57 m_integrityFailure(false),
58 m_parserBlockingLoadStartTime(0), 58 m_parserBlockingLoadStartTime(0),
59 m_client(nullptr), 59 m_client(nullptr),
60 m_isForTesting(isForTesting) { 60 m_isForTesting(isForTesting) {
61 CHECK(m_isForTesting || m_element); 61 checkState();
62 setResource(resource); 62 setResource(resource);
63 MemoryCoordinator::instance().registerClient(this); 63 MemoryCoordinator::instance().registerClient(this);
64 } 64 }
65 65
66 PendingScript::~PendingScript() {} 66 PendingScript::~PendingScript() {}
67 67
68 NOINLINE void PendingScript::checkState() const {
69 // TODO(hiroshige): Turn these CHECK()s into DCHECK() before going to beta.
70 CHECK(m_isForTesting || m_element);
71 CHECK(resource() || !m_streamer);
72 CHECK(!m_streamer || m_streamer->resource() == resource());
73 }
74
68 void PendingScript::dispose() { 75 void PendingScript::dispose() {
76 checkState();
kouhei (in TOK) 2017/02/23 01:54:17 Doesn't have to be this CL, but calling dispose()
hiroshige 2017/02/23 01:58:51 dispose() is the prefinalizer of PendingScript, so
sof 2017/02/23 07:26:23 Yes, promptly disposing of this object is worthwhi
77
69 stopWatchingForLoad(); 78 stopWatchingForLoad();
70 DCHECK(!m_client); 79 DCHECK(!m_client);
71 DCHECK(!m_watchingForLoad); 80 DCHECK(!m_watchingForLoad);
72 81
73 setResource(nullptr); 82 setResource(nullptr);
74 m_startingPosition = TextPosition::belowRangePosition(); 83 m_startingPosition = TextPosition::belowRangePosition();
75 m_integrityFailure = false; 84 m_integrityFailure = false;
76 m_parserBlockingLoadStartTime = 0; 85 m_parserBlockingLoadStartTime = 0;
77 if (m_streamer) 86 if (m_streamer)
78 m_streamer->cancel(); 87 m_streamer->cancel();
79 m_streamer = nullptr; 88 m_streamer = nullptr;
80 m_element = nullptr; 89 m_element = nullptr;
81 } 90 }
82 91
83 void PendingScript::watchForLoad(PendingScriptClient* client) { 92 void PendingScript::watchForLoad(PendingScriptClient* client) {
93 checkState();
94
84 DCHECK(!m_watchingForLoad); 95 DCHECK(!m_watchingForLoad);
85 // addClient() will call streamingFinished() if the load is complete. Callers 96 // addClient() will call streamingFinished() if the load is complete. Callers
86 // who do not expect to be re-entered from this call should not call 97 // who do not expect to be re-entered from this call should not call
87 // watchForLoad for a PendingScript which isReady. We also need to set 98 // watchForLoad for a PendingScript which isReady. We also need to set
88 // m_watchingForLoad early, since addClient() can result in calling 99 // m_watchingForLoad early, since addClient() can result in calling
89 // notifyFinished and further stopWatchingForLoad(). 100 // notifyFinished and further stopWatchingForLoad().
90 m_watchingForLoad = true; 101 m_watchingForLoad = true;
91 m_client = client; 102 m_client = client;
92 if (isReady()) 103 if (isReady())
93 m_client->pendingScriptFinished(this); 104 m_client->pendingScriptFinished(this);
94 } 105 }
95 106
96 void PendingScript::stopWatchingForLoad() { 107 void PendingScript::stopWatchingForLoad() {
108 checkState();
109
97 if (!m_watchingForLoad) 110 if (!m_watchingForLoad)
98 return; 111 return;
99 DCHECK(resource()); 112 DCHECK(resource());
100 m_client = nullptr; 113 m_client = nullptr;
101 m_watchingForLoad = false; 114 m_watchingForLoad = false;
102 } 115 }
103 116
104 Element* PendingScript::element() const { 117 Element* PendingScript::element() const {
105 // As mentioned in the comment at |m_element| declaration, |m_element| 118 // As mentioned in the comment at |m_element| declaration, |m_element|
106 // must points to the corresponding ScriptLoader's element. 119 // must points to the corresponding ScriptLoader's element.
107 CHECK(m_element); 120 CHECK(m_element);
108 return m_element.get(); 121 return m_element.get();
109 } 122 }
110 123
111 void PendingScript::streamingFinished() { 124 void PendingScript::streamingFinished() {
125 checkState();
112 DCHECK(resource()); 126 DCHECK(resource());
113 if (m_client) 127 if (m_client)
114 m_client->pendingScriptFinished(this); 128 m_client->pendingScriptFinished(this);
115 } 129 }
116 130
117 void PendingScript::markParserBlockingLoadStartTime() { 131 void PendingScript::markParserBlockingLoadStartTime() {
118 DCHECK_EQ(m_parserBlockingLoadStartTime, 0.0); 132 DCHECK_EQ(m_parserBlockingLoadStartTime, 0.0);
119 m_parserBlockingLoadStartTime = monotonicallyIncreasingTime(); 133 m_parserBlockingLoadStartTime = monotonicallyIncreasingTime();
120 } 134 }
121 135
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // 192 //
179 // In order to simulate the correct behavior, Blink explicitly does the SRI 193 // In order to simulate the correct behavior, Blink explicitly does the SRI
180 // checks here, when a PendingScript tied to a particular request is 194 // checks here, when a PendingScript tied to a particular request is
181 // finished (and in the case of a StyleSheet, at the point of execution), 195 // finished (and in the case of a StyleSheet, at the point of execution),
182 // while having proper Fetch checks in the fetch module for use in the 196 // while having proper Fetch checks in the fetch module for use in the
183 // fetch JavaScript API. In a future world where the ResourceFetcher uses 197 // fetch JavaScript API. In a future world where the ResourceFetcher uses
184 // the Fetch algorithm, this should be fixed by having separate Response 198 // the Fetch algorithm, this should be fixed by having separate Response
185 // objects (perhaps attached to identical Resource objects) per request. 199 // objects (perhaps attached to identical Resource objects) per request.
186 // 200 //
187 // See https://crbug.com/500701 for more information. 201 // See https://crbug.com/500701 for more information.
188 CHECK(m_isForTesting || m_element); 202 checkState();
189 if (m_element) 203 if (m_element)
190 m_integrityFailure = !checkScriptResourceIntegrity(resource, m_element); 204 m_integrityFailure = !checkScriptResourceIntegrity(resource, m_element);
191 205
192 // If script streaming is in use, the client will be notified in 206 // If script streaming is in use, the client will be notified in
193 // streamingFinished. 207 // streamingFinished.
194 if (m_streamer) 208 if (m_streamer)
195 m_streamer->notifyFinished(resource); 209 m_streamer->notifyFinished(resource);
196 else if (m_client) 210 else if (m_client)
197 m_client->pendingScriptFinished(this); 211 m_client->pendingScriptFinished(this);
198 } 212 }
199 213
200 void PendingScript::notifyAppendData(ScriptResource* resource) { 214 void PendingScript::notifyAppendData(ScriptResource* resource) {
201 if (m_streamer) 215 if (m_streamer)
202 m_streamer->notifyAppendData(resource); 216 m_streamer->notifyAppendData(resource);
203 } 217 }
204 218
205 DEFINE_TRACE(PendingScript) { 219 DEFINE_TRACE(PendingScript) {
206 visitor->trace(m_element); 220 visitor->trace(m_element);
207 visitor->trace(m_streamer); 221 visitor->trace(m_streamer);
208 visitor->trace(m_client); 222 visitor->trace(m_client);
209 ResourceOwner<ScriptResource>::trace(visitor); 223 ResourceOwner<ScriptResource>::trace(visitor);
210 MemoryCoordinatorClient::trace(visitor); 224 MemoryCoordinatorClient::trace(visitor);
211 } 225 }
212 226
213 ScriptSourceCode PendingScript::getSource(const KURL& documentURL, 227 ScriptSourceCode PendingScript::getSource(const KURL& documentURL,
214 bool& errorOccurred) const { 228 bool& errorOccurred) const {
229 checkState();
230
215 if (resource()) { 231 if (resource()) {
216 errorOccurred = resource()->errorOccurred() || m_integrityFailure; 232 errorOccurred = resource()->errorOccurred() || m_integrityFailure;
217 DCHECK(resource()->isLoaded()); 233 DCHECK(resource()->isLoaded());
218 if (m_streamer && !m_streamer->streamingSuppressed()) 234 if (m_streamer && !m_streamer->streamingSuppressed())
219 return ScriptSourceCode(m_streamer, resource()); 235 return ScriptSourceCode(m_streamer, resource());
220 return ScriptSourceCode(resource()); 236 return ScriptSourceCode(resource());
221 } 237 }
238
222 errorOccurred = false; 239 errorOccurred = false;
223 return ScriptSourceCode(m_element->textContent(), documentURL, 240 return ScriptSourceCode(m_element->textContent(), documentURL,
224 startingPosition()); 241 startingPosition());
225 } 242 }
226 243
227 void PendingScript::setStreamer(ScriptStreamer* streamer) { 244 void PendingScript::setStreamer(ScriptStreamer* streamer) {
228 DCHECK(!m_streamer); 245 DCHECK(!m_streamer);
229 DCHECK(!m_watchingForLoad); 246 DCHECK(!m_watchingForLoad);
230 m_streamer = streamer; 247 m_streamer = streamer;
248 checkState();
231 } 249 }
232 250
233 bool PendingScript::isReady() const { 251 bool PendingScript::isReady() const {
234 if (resource() && !resource()->isLoaded()) 252 checkState();
235 return false; 253 if (resource()) {
236 if (m_streamer && !m_streamer->isFinished()) 254 return resource()->isLoaded() && (!m_streamer || m_streamer->isFinished());
237 return false; 255 }
256
238 return true; 257 return true;
239 } 258 }
240 259
241 bool PendingScript::errorOccurred() const { 260 bool PendingScript::errorOccurred() const {
261 checkState();
242 if (resource()) 262 if (resource())
243 return resource()->errorOccurred(); 263 return resource()->errorOccurred();
244 if (m_streamer && m_streamer->resource()) 264
245 return m_streamer->resource()->errorOccurred();
246 return false; 265 return false;
247 } 266 }
248 267
249 void PendingScript::onPurgeMemory() { 268 void PendingScript::onPurgeMemory() {
269 checkState();
250 if (!m_streamer) 270 if (!m_streamer)
251 return; 271 return;
252 m_streamer->cancel(); 272 m_streamer->cancel();
253 m_streamer = nullptr; 273 m_streamer = nullptr;
254 } 274 }
255 275
256 } // namespace blink 276 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/PendingScript.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698