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

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

Issue 2536553002: Simplify: remove PendingScript::releaseElementAndClear (Closed)
Patch Set: git cl try 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.
211 // TODO(kouhei): Consider merging this w/ pendingScript->dispose() after the
212 // if block.
213 pendingScript->stopWatchingForLoad(); 213 pendingScript->stopWatchingForLoad();
214 214
215 if (!isExecutingScript()) { 215 if (!isExecutingScript()) {
216 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate()); 216 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate());
217 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { 217 if (pendingScriptType == ScriptStreamer::ParsingBlocking) {
218 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); 218 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady();
219 // The parser cannot be unblocked as a microtask requested another 219 // The parser cannot be unblocked as a microtask requested another
220 // resource 220 // resource
221 if (m_hasScriptsWaitingForResources) 221 if (m_hasScriptsWaitingForResources)
222 return; 222 return;
223 } 223 }
224 } 224 }
225 225
226 TextPosition scriptStartPosition = pendingScript->startingPosition(); 226 TextPosition scriptStartPosition = pendingScript->startingPosition();
227 double scriptParserBlockingTime = 227 double scriptParserBlockingTime =
228 pendingScript->parserBlockingLoadStartTime(); 228 pendingScript->parserBlockingLoadStartTime();
229 // Clear the pending script before possible re-entrancy from executeScript() 229 // Clear the pending script before possible re-entrancy from executeScript()
230 Element* element = pendingScript->releaseElementAndClear(); 230 Element* element = pendingScript->element();
231 pendingScript->dispose();
232
231 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element)) { 233 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element)) {
232 HTMLParserReentryPermit::ScriptNestingLevelIncrementer 234 HTMLParserReentryPermit::ScriptNestingLevelIncrementer
233 nestingLevelIncrementer = 235 nestingLevelIncrementer =
234 m_reentryPermit->incrementScriptNestingLevel(); 236 m_reentryPermit->incrementScriptNestingLevel();
235 IgnoreDestructiveWriteCountIncrementer 237 IgnoreDestructiveWriteCountIncrementer
236 ignoreDestructiveWriteCountIncrementer(m_document); 238 ignoreDestructiveWriteCountIncrementer(m_document);
237 if (errorOccurred) { 239 if (errorOccurred) {
238 TRACE_EVENT_WITH_FLOW1( 240 TRACE_EVENT_WITH_FLOW1(
239 "blink", "HTMLScriptRunner ExecuteScriptFailed", element, 241 "blink", "HTMLScriptRunner ExecuteScriptFailed", element,
240 TRACE_EVENT_FLAG_FLOW_IN, "data", 242 TRACE_EVENT_FLAG_FLOW_IN, "data",
(...skipping 13 matching lines...) Expand all
254 element->dispatchEvent(Event::create(EventTypeNames::load)); 256 element->dispatchEvent(Event::create(EventTypeNames::load));
255 } 257 }
256 } 258 }
257 } 259 }
258 260
259 ASSERT(!isExecutingScript()); 261 ASSERT(!isExecutingScript());
260 } 262 }
261 263
262 void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) { 264 void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) {
263 if (m_parserBlockingScript->resource() == resource) { 265 if (m_parserBlockingScript->resource() == resource) {
264 m_parserBlockingScript->stopWatchingForLoad(); 266 m_parserBlockingScript->dispose();
265 m_parserBlockingScript->releaseElementAndClear();
266 return; 267 return;
267 } 268 }
268 for (auto& script : m_scriptsToExecuteAfterParsing) { 269 for (auto& script : m_scriptsToExecuteAfterParsing) {
269 if (script->resource() == resource) { 270 if (script->resource() == resource) {
270 script->stopWatchingForLoad(); 271 script->dispose();
271 script->releaseElementAndClear();
272 return; 272 return;
273 } 273 }
274 } 274 }
275 } 275 }
276 276
277 void fetchBlockedDocWriteScript(Element* script, 277 void fetchBlockedDocWriteScript(Element* script,
278 bool isParserInserted, 278 bool isParserInserted,
279 const TextPosition& scriptStartPosition) { 279 const TextPosition& scriptStartPosition) {
280 DCHECK(script); 280 DCHECK(script);
281 281
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 return; 508 return;
509 509
510 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { 510 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) {
511 requestDeferredScript(script); 511 requestDeferredScript(script);
512 } else if (scriptLoader->readyToBeParserExecuted()) { 512 } else if (scriptLoader->readyToBeParserExecuted()) {
513 if (m_reentryPermit->scriptNestingLevel() == 1u) { 513 if (m_reentryPermit->scriptNestingLevel() == 1u) {
514 m_parserBlockingScript->setElement(script); 514 m_parserBlockingScript->setElement(script);
515 m_parserBlockingScript->setStartingPosition(scriptStartPosition); 515 m_parserBlockingScript->setStartingPosition(scriptStartPosition);
516 } else { 516 } else {
517 DCHECK_GT(m_reentryPermit->scriptNestingLevel(), 1u); 517 DCHECK_GT(m_reentryPermit->scriptNestingLevel(), 1u);
518 m_parserBlockingScript->releaseElementAndClear(); 518 m_parserBlockingScript->dispose();
yhirano 2016/11/29 01:29:00 Can you tell me why we can call stopWatchingLoad h
kouhei (in TOK) 2016/11/29 01:52:57 This is when we execute inline scripts. We shouldn
519 ScriptSourceCode sourceCode(script->textContent(), 519 ScriptSourceCode sourceCode(script->textContent(),
520 documentURLForScriptExecution(m_document), 520 documentURLForScriptExecution(m_document),
521 scriptStartPosition); 521 scriptStartPosition);
522 doExecuteScript(script, sourceCode, scriptStartPosition); 522 doExecuteScript(script, sourceCode, scriptStartPosition);
523 } 523 }
524 } else { 524 } else {
525 requestParsingBlockingScript(script); 525 requestParsingBlockingScript(script);
526 } 526 }
527 } 527 }
528 } 528 }
529 529
530 DEFINE_TRACE(HTMLScriptRunner) { 530 DEFINE_TRACE(HTMLScriptRunner) {
531 visitor->trace(m_document); 531 visitor->trace(m_document);
532 visitor->trace(m_host); 532 visitor->trace(m_host);
533 visitor->trace(m_parserBlockingScript); 533 visitor->trace(m_parserBlockingScript);
534 visitor->trace(m_scriptsToExecuteAfterParsing); 534 visitor->trace(m_scriptsToExecuteAfterParsing);
535 ScriptResourceClient::trace(visitor); 535 ScriptResourceClient::trace(visitor);
536 } 536 }
537 537
538 } // namespace blink 538 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698