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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLScriptRunner.cpp

Issue 2536553002: Simplify: remove PendingScript::releaseElementAndClear (Closed)
Patch Set: Created 4 years 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 /* 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 HTMLScriptRunner::~HTMLScriptRunner() { 163 HTMLScriptRunner::~HTMLScriptRunner() {
164 // Verify that detach() has been called. 164 // Verify that detach() has been called.
165 ASSERT(!m_document); 165 ASSERT(!m_document);
166 } 166 }
167 167
168 void HTMLScriptRunner::detach() { 168 void HTMLScriptRunner::detach() {
169 if (!m_document) 169 if (!m_document)
170 return; 170 return;
171 171
172 m_parserBlockingScript->stopWatchingForLoad(); 172 m_parserBlockingScript->dispose();
173 m_parserBlockingScript->releaseElementAndClear();
174 173
175 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { 174 while (!m_scriptsToExecuteAfterParsing.isEmpty()) {
176 PendingScript* pendingScript = m_scriptsToExecuteAfterParsing.takeFirst(); 175 PendingScript* pendingScript = m_scriptsToExecuteAfterParsing.takeFirst();
177 pendingScript->stopWatchingForLoad(); 176 pendingScript->dispose();
178 pendingScript->releaseElementAndClear();
179 } 177 }
180 m_document = nullptr; 178 m_document = nullptr;
181 // m_reentryPermit is not cleared here, because the script runner 179 // m_reentryPermit is not cleared here, because the script runner
182 // may continue to run pending scripts after the parser has 180 // may continue to run pending scripts after the parser has
183 // detached. 181 // detached.
184 } 182 }
185 183
186 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript* script) { 184 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript* script) {
187 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); 185 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady();
188 if (m_hasScriptsWaitingForResources) 186 if (m_hasScriptsWaitingForResources)
(...skipping 14 matching lines...) Expand all
203 201
204 void HTMLScriptRunner::executePendingScriptAndDispatchEvent( 202 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(
205 PendingScript* pendingScript, 203 PendingScript* pendingScript,
206 ScriptStreamer::Type pendingScriptType) { 204 ScriptStreamer::Type pendingScriptType) {
207 bool errorOccurred = false; 205 bool errorOccurred = false;
208 ScriptSourceCode sourceCode = pendingScript->getSource( 206 ScriptSourceCode sourceCode = pendingScript->getSource(
209 documentURLForScriptExecution(m_document), errorOccurred); 207 documentURLForScriptExecution(m_document), errorOccurred);
210 208
211 // Stop watching loads before executeScript to prevent recursion if the script 209 // Stop watching loads before executeScript to prevent recursion if the script
212 // reloads itself. 210 // reloads itself.
213 pendingScript->stopWatchingForLoad(); 211 pendingScript->stopWatchingForLoad();
sof 2016/11/28 16:17:59 Can this call (effectively) be moved down to where
kouhei (in TOK) 2016/11/29 00:49:05 Good catch. I'd like to separate patch for this as
214 212
215 if (!isExecutingScript()) { 213 if (!isExecutingScript()) {
216 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate()); 214 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate());
217 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { 215 if (pendingScriptType == ScriptStreamer::ParsingBlocking) {
218 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); 216 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady();
219 // The parser cannot be unblocked as a microtask requested another 217 // The parser cannot be unblocked as a microtask requested another
220 // resource 218 // resource
221 if (m_hasScriptsWaitingForResources) 219 if (m_hasScriptsWaitingForResources)
222 return; 220 return;
223 } 221 }
224 } 222 }
225 223
226 TextPosition scriptStartPosition = pendingScript->startingPosition(); 224 TextPosition scriptStartPosition = pendingScript->startingPosition();
227 double scriptParserBlockingTime = 225 double scriptParserBlockingTime =
228 pendingScript->parserBlockingLoadStartTime(); 226 pendingScript->parserBlockingLoadStartTime();
229 // Clear the pending script before possible re-entrancy from executeScript() 227 // Clear the pending script before possible re-entrancy from executeScript()
230 Element* element = pendingScript->releaseElementAndClear(); 228 Element* element = pendingScript->element();
229 pendingScript->dispose();
230
231 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element)) { 231 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element)) {
232 HTMLParserReentryPermit::ScriptNestingLevelIncrementer 232 HTMLParserReentryPermit::ScriptNestingLevelIncrementer
233 nestingLevelIncrementer = 233 nestingLevelIncrementer =
234 m_reentryPermit->incrementScriptNestingLevel(); 234 m_reentryPermit->incrementScriptNestingLevel();
235 IgnoreDestructiveWriteCountIncrementer 235 IgnoreDestructiveWriteCountIncrementer
236 ignoreDestructiveWriteCountIncrementer(m_document); 236 ignoreDestructiveWriteCountIncrementer(m_document);
237 if (errorOccurred) { 237 if (errorOccurred) {
238 TRACE_EVENT_WITH_FLOW1( 238 TRACE_EVENT_WITH_FLOW1(
239 "blink", "HTMLScriptRunner ExecuteScriptFailed", element, 239 "blink", "HTMLScriptRunner ExecuteScriptFailed", element,
240 TRACE_EVENT_FLAG_FLOW_IN, "data", 240 TRACE_EVENT_FLAG_FLOW_IN, "data",
(...skipping 13 matching lines...) Expand all
254 element->dispatchEvent(Event::create(EventTypeNames::load)); 254 element->dispatchEvent(Event::create(EventTypeNames::load));
255 } 255 }
256 } 256 }
257 } 257 }
258 258
259 ASSERT(!isExecutingScript()); 259 ASSERT(!isExecutingScript());
260 } 260 }
261 261
262 void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) { 262 void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) {
263 if (m_parserBlockingScript->resource() == resource) { 263 if (m_parserBlockingScript->resource() == resource) {
264 m_parserBlockingScript->stopWatchingForLoad(); 264 m_parserBlockingScript->dispose();
265 m_parserBlockingScript->releaseElementAndClear();
266 return; 265 return;
267 } 266 }
268 for (auto& script : m_scriptsToExecuteAfterParsing) { 267 for (auto& script : m_scriptsToExecuteAfterParsing) {
269 if (script->resource() == resource) { 268 if (script->resource() == resource) {
270 script->stopWatchingForLoad(); 269 script->dispose();
271 script->releaseElementAndClear();
272 return; 270 return;
273 } 271 }
274 } 272 }
275 } 273 }
276 274
277 void fetchBlockedDocWriteScript(Element* script, 275 void fetchBlockedDocWriteScript(Element* script,
278 bool isParserInserted, 276 bool isParserInserted,
279 const TextPosition& scriptStartPosition) { 277 const TextPosition& scriptStartPosition) {
280 DCHECK(script); 278 DCHECK(script);
281 279
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 return; 506 return;
509 507
510 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { 508 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) {
511 requestDeferredScript(script); 509 requestDeferredScript(script);
512 } else if (scriptLoader->readyToBeParserExecuted()) { 510 } else if (scriptLoader->readyToBeParserExecuted()) {
513 if (m_reentryPermit->scriptNestingLevel() == 1u) { 511 if (m_reentryPermit->scriptNestingLevel() == 1u) {
514 m_parserBlockingScript->setElement(script); 512 m_parserBlockingScript->setElement(script);
515 m_parserBlockingScript->setStartingPosition(scriptStartPosition); 513 m_parserBlockingScript->setStartingPosition(scriptStartPosition);
516 } else { 514 } else {
517 DCHECK_GT(m_reentryPermit->scriptNestingLevel(), 1u); 515 DCHECK_GT(m_reentryPermit->scriptNestingLevel(), 1u);
518 m_parserBlockingScript->releaseElementAndClear(); 516 m_parserBlockingScript->dispose();
519 ScriptSourceCode sourceCode(script->textContent(), 517 ScriptSourceCode sourceCode(script->textContent(),
520 documentURLForScriptExecution(m_document), 518 documentURLForScriptExecution(m_document),
521 scriptStartPosition); 519 scriptStartPosition);
522 doExecuteScript(script, sourceCode, scriptStartPosition); 520 doExecuteScript(script, sourceCode, scriptStartPosition);
523 } 521 }
524 } else { 522 } else {
525 requestParsingBlockingScript(script); 523 requestParsingBlockingScript(script);
526 } 524 }
527 } 525 }
528 } 526 }
529 527
530 DEFINE_TRACE(HTMLScriptRunner) { 528 DEFINE_TRACE(HTMLScriptRunner) {
531 visitor->trace(m_document); 529 visitor->trace(m_document);
532 visitor->trace(m_host); 530 visitor->trace(m_host);
533 visitor->trace(m_parserBlockingScript); 531 visitor->trace(m_parserBlockingScript);
534 visitor->trace(m_scriptsToExecuteAfterParsing); 532 visitor->trace(m_scriptsToExecuteAfterParsing);
535 ScriptResourceClient::trace(visitor); 533 ScriptResourceClient::trace(visitor);
536 } 534 }
537 535
538 } // namespace blink 536 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698