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

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: Do not checkState() when dispose() -- it might be already disposed(). Created 3 years, 9 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);
sof 2017/02/23 07:26:23 This method would be a good place to elucidate the
71 CHECK(resource() || !m_streamer);
72 CHECK(!m_streamer || m_streamer->resource() == resource());
73 }
74
68 void PendingScript::dispose() { 75 void PendingScript::dispose() {
69 stopWatchingForLoad(); 76 stopWatchingForLoad();
70 DCHECK(!m_client); 77 DCHECK(!m_client);
71 DCHECK(!m_watchingForLoad); 78 DCHECK(!m_watchingForLoad);
72 79
73 setResource(nullptr); 80 setResource(nullptr);
74 m_startingPosition = TextPosition::belowRangePosition(); 81 m_startingPosition = TextPosition::belowRangePosition();
75 m_integrityFailure = false; 82 m_integrityFailure = false;
76 m_parserBlockingLoadStartTime = 0; 83 m_parserBlockingLoadStartTime = 0;
77 if (m_streamer) 84 if (m_streamer)
78 m_streamer->cancel(); 85 m_streamer->cancel();
79 m_streamer = nullptr; 86 m_streamer = nullptr;
80 m_element = nullptr; 87 m_element = nullptr;
81 } 88 }
82 89
83 void PendingScript::watchForLoad(PendingScriptClient* client) { 90 void PendingScript::watchForLoad(PendingScriptClient* client) {
91 checkState();
92
84 DCHECK(!m_watchingForLoad); 93 DCHECK(!m_watchingForLoad);
85 // addClient() will call streamingFinished() if the load is complete. Callers 94 // 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 95 // 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 96 // watchForLoad for a PendingScript which isReady. We also need to set
88 // m_watchingForLoad early, since addClient() can result in calling 97 // m_watchingForLoad early, since addClient() can result in calling
89 // notifyFinished and further stopWatchingForLoad(). 98 // notifyFinished and further stopWatchingForLoad().
90 m_watchingForLoad = true; 99 m_watchingForLoad = true;
91 m_client = client; 100 m_client = client;
92 if (isReady()) 101 if (isReady())
93 m_client->pendingScriptFinished(this); 102 m_client->pendingScriptFinished(this);
94 } 103 }
95 104
96 void PendingScript::stopWatchingForLoad() { 105 void PendingScript::stopWatchingForLoad() {
97 if (!m_watchingForLoad) 106 if (!m_watchingForLoad)
98 return; 107 return;
108 checkState();
99 DCHECK(resource()); 109 DCHECK(resource());
100 m_client = nullptr; 110 m_client = nullptr;
101 m_watchingForLoad = false; 111 m_watchingForLoad = false;
102 } 112 }
103 113
104 Element* PendingScript::element() const { 114 Element* PendingScript::element() const {
105 // As mentioned in the comment at |m_element| declaration, |m_element| 115 // As mentioned in the comment at |m_element| declaration, |m_element|
106 // must points to the corresponding ScriptLoader's element. 116 // must points to the corresponding ScriptLoader's element.
107 CHECK(m_element); 117 CHECK(m_element);
108 return m_element.get(); 118 return m_element.get();
109 } 119 }
110 120
111 void PendingScript::streamingFinished() { 121 void PendingScript::streamingFinished() {
122 checkState();
112 DCHECK(resource()); 123 DCHECK(resource());
113 if (m_client) 124 if (m_client)
114 m_client->pendingScriptFinished(this); 125 m_client->pendingScriptFinished(this);
115 } 126 }
116 127
117 void PendingScript::markParserBlockingLoadStartTime() { 128 void PendingScript::markParserBlockingLoadStartTime() {
118 DCHECK_EQ(m_parserBlockingLoadStartTime, 0.0); 129 DCHECK_EQ(m_parserBlockingLoadStartTime, 0.0);
119 m_parserBlockingLoadStartTime = monotonicallyIncreasingTime(); 130 m_parserBlockingLoadStartTime = monotonicallyIncreasingTime();
120 } 131 }
121 132
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // 189 //
179 // In order to simulate the correct behavior, Blink explicitly does the SRI 190 // In order to simulate the correct behavior, Blink explicitly does the SRI
180 // checks here, when a PendingScript tied to a particular request is 191 // 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), 192 // 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 193 // 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 194 // fetch JavaScript API. In a future world where the ResourceFetcher uses
184 // the Fetch algorithm, this should be fixed by having separate Response 195 // the Fetch algorithm, this should be fixed by having separate Response
185 // objects (perhaps attached to identical Resource objects) per request. 196 // objects (perhaps attached to identical Resource objects) per request.
186 // 197 //
187 // See https://crbug.com/500701 for more information. 198 // See https://crbug.com/500701 for more information.
188 CHECK(m_isForTesting || m_element); 199 checkState();
189 if (m_element) 200 if (m_element)
190 m_integrityFailure = !checkScriptResourceIntegrity(resource, m_element); 201 m_integrityFailure = !checkScriptResourceIntegrity(resource, m_element);
191 202
192 // If script streaming is in use, the client will be notified in 203 // If script streaming is in use, the client will be notified in
193 // streamingFinished. 204 // streamingFinished.
194 if (m_streamer) 205 if (m_streamer)
195 m_streamer->notifyFinished(resource); 206 m_streamer->notifyFinished(resource);
196 else if (m_client) 207 else if (m_client)
197 m_client->pendingScriptFinished(this); 208 m_client->pendingScriptFinished(this);
198 } 209 }
199 210
200 void PendingScript::notifyAppendData(ScriptResource* resource) { 211 void PendingScript::notifyAppendData(ScriptResource* resource) {
201 if (m_streamer) 212 if (m_streamer)
202 m_streamer->notifyAppendData(resource); 213 m_streamer->notifyAppendData(resource);
203 } 214 }
204 215
205 DEFINE_TRACE(PendingScript) { 216 DEFINE_TRACE(PendingScript) {
206 visitor->trace(m_element); 217 visitor->trace(m_element);
207 visitor->trace(m_streamer); 218 visitor->trace(m_streamer);
208 visitor->trace(m_client); 219 visitor->trace(m_client);
209 ResourceOwner<ScriptResource>::trace(visitor); 220 ResourceOwner<ScriptResource>::trace(visitor);
210 MemoryCoordinatorClient::trace(visitor); 221 MemoryCoordinatorClient::trace(visitor);
211 } 222 }
212 223
213 ScriptSourceCode PendingScript::getSource(const KURL& documentURL, 224 ScriptSourceCode PendingScript::getSource(const KURL& documentURL,
214 bool& errorOccurred) const { 225 bool& errorOccurred) const {
226 checkState();
227
215 if (resource()) { 228 if (resource()) {
216 errorOccurred = resource()->errorOccurred() || m_integrityFailure; 229 errorOccurred = resource()->errorOccurred() || m_integrityFailure;
217 DCHECK(resource()->isLoaded()); 230 DCHECK(resource()->isLoaded());
218 if (m_streamer && !m_streamer->streamingSuppressed()) 231 if (m_streamer && !m_streamer->streamingSuppressed())
219 return ScriptSourceCode(m_streamer, resource()); 232 return ScriptSourceCode(m_streamer, resource());
220 return ScriptSourceCode(resource()); 233 return ScriptSourceCode(resource());
221 } 234 }
235
222 errorOccurred = false; 236 errorOccurred = false;
223 return ScriptSourceCode(m_element->textContent(), documentURL, 237 return ScriptSourceCode(m_element->textContent(), documentURL,
224 startingPosition()); 238 startingPosition());
225 } 239 }
226 240
227 void PendingScript::setStreamer(ScriptStreamer* streamer) { 241 void PendingScript::setStreamer(ScriptStreamer* streamer) {
228 DCHECK(!m_streamer); 242 DCHECK(!m_streamer);
229 DCHECK(!m_watchingForLoad); 243 DCHECK(!m_watchingForLoad);
230 m_streamer = streamer; 244 m_streamer = streamer;
245 checkState();
231 } 246 }
232 247
233 bool PendingScript::isReady() const { 248 bool PendingScript::isReady() const {
234 if (resource() && !resource()->isLoaded()) 249 checkState();
235 return false; 250 if (resource()) {
236 if (m_streamer && !m_streamer->isFinished()) 251 return resource()->isLoaded() && (!m_streamer || m_streamer->isFinished());
237 return false; 252 }
253
238 return true; 254 return true;
239 } 255 }
240 256
241 bool PendingScript::errorOccurred() const { 257 bool PendingScript::errorOccurred() const {
258 checkState();
242 if (resource()) 259 if (resource())
243 return resource()->errorOccurred(); 260 return resource()->errorOccurred();
244 if (m_streamer && m_streamer->resource()) 261
245 return m_streamer->resource()->errorOccurred();
246 return false; 262 return false;
247 } 263 }
248 264
249 void PendingScript::onPurgeMemory() { 265 void PendingScript::onPurgeMemory() {
266 checkState();
250 if (!m_streamer) 267 if (!m_streamer)
251 return; 268 return;
252 m_streamer->cancel(); 269 m_streamer->cancel();
253 m_streamer = nullptr; 270 m_streamer = nullptr;
254 } 271 }
255 272
256 } // namespace blink 273 } // 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