OLD | NEW |
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 if (textPosition.m_line.zeroBasedInt() > 0 || | 72 if (textPosition.m_line.zeroBasedInt() > 0 || |
73 textPosition.m_column.zeroBasedInt() > 0) { | 73 textPosition.m_column.zeroBasedInt() > 0) { |
74 value->setInteger("lineNumber", textPosition.m_line.oneBasedInt()); | 74 value->setInteger("lineNumber", textPosition.m_line.oneBasedInt()); |
75 value->setInteger("columnNumber", textPosition.m_column.oneBasedInt()); | 75 value->setInteger("columnNumber", textPosition.m_column.oneBasedInt()); |
76 } | 76 } |
77 return value; | 77 return value; |
78 } | 78 } |
79 | 79 |
80 bool doExecuteScript(Element* scriptElement, | 80 bool doExecuteScript(Element* scriptElement, |
81 const ScriptSourceCode& sourceCode, | 81 const ScriptSourceCode& sourceCode, |
82 const TextPosition& textPosition) { | 82 const TextPosition& textPosition, |
| 83 CompiledScript* compiledScript = nullptr) { |
83 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(scriptElement); | 84 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(scriptElement); |
84 DCHECK(scriptLoader); | 85 DCHECK(scriptLoader); |
85 TRACE_EVENT_WITH_FLOW1( | 86 TRACE_EVENT_WITH_FLOW2( |
86 "blink", "HTMLParserScriptRunner ExecuteScript", scriptElement, | 87 "blink", "HTMLParserScriptRunner ExecuteScript", scriptElement, |
87 TRACE_EVENT_FLAG_FLOW_IN, "data", | 88 TRACE_EVENT_FLAG_FLOW_IN, "data", |
88 getTraceArgsForScriptElement(scriptElement, textPosition)); | 89 getTraceArgsForScriptElement(scriptElement, textPosition), |
89 return scriptLoader->executeScript(sourceCode); | 90 "compiledScript", compiledScript); |
| 91 return scriptLoader->executeScript(sourceCode, compiledScript); |
90 } | 92 } |
91 | 93 |
92 void traceParserBlockingScript(const PendingScript* pendingScript, | 94 void traceParserBlockingScript(const PendingScript* pendingScript, |
93 bool waitingForResources) { | 95 bool waitingForResources) { |
94 // The HTML parser must yield before executing script in the following | 96 // The HTML parser must yield before executing script in the following |
95 // cases: | 97 // cases: |
96 // * the script's execution is blocked on the completed load of the script | 98 // * the script's execution is blocked on the completed load of the script |
97 // resource | 99 // resource |
98 // (https://html.spec.whatwg.org/multipage/scripting.html#pending-parsing-bl
ocking-script) | 100 // (https://html.spec.whatwg.org/multipage/scripting.html#pending-parsing-bl
ocking-script) |
99 // * the script's execution is blocked on the load of a style sheet or other | 101 // * the script's execution is blocked on the load of a style sheet or other |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // resource | 221 // resource |
220 if (!m_document->isScriptExecutionReady()) | 222 if (!m_document->isScriptExecutionReady()) |
221 return; | 223 return; |
222 } | 224 } |
223 } | 225 } |
224 | 226 |
225 TextPosition scriptStartPosition = pendingScript->startingPosition(); | 227 TextPosition scriptStartPosition = pendingScript->startingPosition(); |
226 double scriptParserBlockingTime = | 228 double scriptParserBlockingTime = |
227 pendingScript->parserBlockingLoadStartTime(); | 229 pendingScript->parserBlockingLoadStartTime(); |
228 Element* element = pendingScript->element(); | 230 Element* element = pendingScript->element(); |
| 231 CompiledScript* compiledScript = pendingScript->getCompiledScript(); |
229 | 232 |
230 // 1. "Let the script be the pending parsing-blocking script. | 233 // 1. "Let the script be the pending parsing-blocking script. |
231 // There is no longer a pending parsing-blocking script." | 234 // There is no longer a pending parsing-blocking script." |
232 // Clear the pending script before possible re-entrancy from executeScript() | 235 // Clear the pending script before possible re-entrancy from executeScript() |
233 pendingScript->dispose(); | 236 pendingScript->dispose(); |
234 pendingScript = nullptr; | 237 pendingScript = nullptr; |
235 | 238 |
236 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { | 239 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { |
237 m_parserBlockingScript = nullptr; | 240 m_parserBlockingScript = nullptr; |
238 } | 241 } |
(...skipping 16 matching lines...) Expand all Loading... |
255 getTraceArgsForScriptElement(element, scriptStartPosition)); | 258 getTraceArgsForScriptElement(element, scriptStartPosition)); |
256 scriptLoader->dispatchErrorEvent(); | 259 scriptLoader->dispatchErrorEvent(); |
257 } else { | 260 } else { |
258 DCHECK(isExecutingScript()); | 261 DCHECK(isExecutingScript()); |
259 if (scriptParserBlockingTime > 0.0) { | 262 if (scriptParserBlockingTime > 0.0) { |
260 DocumentParserTiming::from(*m_document) | 263 DocumentParserTiming::from(*m_document) |
261 .recordParserBlockedOnScriptLoadDuration( | 264 .recordParserBlockedOnScriptLoadDuration( |
262 monotonicallyIncreasingTime() - scriptParserBlockingTime, | 265 monotonicallyIncreasingTime() - scriptParserBlockingTime, |
263 scriptLoader->wasCreatedDuringDocumentWrite()); | 266 scriptLoader->wasCreatedDuringDocumentWrite()); |
264 } | 267 } |
265 if (!doExecuteScript(element, sourceCode, scriptStartPosition)) { | 268 if (!doExecuteScript(element, sourceCode, scriptStartPosition, |
| 269 compiledScript)) { |
266 scriptLoader->dispatchErrorEvent(); | 270 scriptLoader->dispatchErrorEvent(); |
267 } else { | 271 } else { |
268 element->dispatchEvent(Event::create(EventTypeNames::load)); | 272 element->dispatchEvent(Event::create(EventTypeNames::load)); |
269 } | 273 } |
270 } | 274 } |
271 | 275 |
272 // 9. "Decrement the parser's script nesting level by one. | 276 // 9. "Decrement the parser's script nesting level by one. |
273 // If the parser's script nesting level is zero | 277 // If the parser's script nesting level is zero |
274 // (which it always should be at this point), | 278 // (which it always should be at this point), |
275 // then set the parser pause flag to false." | 279 // then set the parser pause flag to false." |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 TextPosition startingPosition = parserBlockingScript()->startingPosition(); | 352 TextPosition startingPosition = parserBlockingScript()->startingPosition(); |
349 bool isParserInserted = scriptLoader->isParserInserted(); | 353 bool isParserInserted = scriptLoader->isParserInserted(); |
350 // Remove this resource entry from memory cache as the new request | 354 // Remove this resource entry from memory cache as the new request |
351 // should not join onto this existing entry. | 355 // should not join onto this existing entry. |
352 memoryCache()->remove(pendingScript->resource()); | 356 memoryCache()->remove(pendingScript->resource()); |
353 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); | 357 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); |
354 } | 358 } |
355 | 359 |
356 void HTMLParserScriptRunner::pendingScriptFinished( | 360 void HTMLParserScriptRunner::pendingScriptFinished( |
357 PendingScript* pendingScript) { | 361 PendingScript* pendingScript) { |
| 362 LOG(ERROR) << "Finished loading pending script of size " |
| 363 << pendingScript->resource()->size(); |
| 364 |
358 // Handle cancellations of parser-blocking script loads without | 365 // Handle cancellations of parser-blocking script loads without |
359 // notifying the host (i.e., parser) if these were initiated by nested | 366 // notifying the host (i.e., parser) if these were initiated by nested |
360 // document.write()s. The cancellation may have been triggered by | 367 // document.write()s. The cancellation may have been triggered by |
361 // script execution to signal an abrupt stop (e.g., window.close().) | 368 // script execution to signal an abrupt stop (e.g., window.close().) |
362 // | 369 // |
363 // The parser is unprepared to be told, and doesn't need to be. | 370 // The parser is unprepared to be told, and doesn't need to be. |
364 if (isExecutingScript() && pendingScript->resource()->wasCanceled()) { | 371 if (isExecutingScript() && pendingScript->resource()->wasCanceled()) { |
365 pendingScript->dispose(); | 372 pendingScript->dispose(); |
366 | 373 |
367 if (pendingScript == parserBlockingScript()) { | 374 if (pendingScript == parserBlockingScript()) { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 // Document of the parser that created the element. | 666 // Document of the parser that created the element. |
660 // (There can only be one such script per Document at a time.)" | 667 // (There can only be one such script per Document at a time.)" |
661 CHECK(!m_parserBlockingScript); | 668 CHECK(!m_parserBlockingScript); |
662 m_parserBlockingScript = | 669 m_parserBlockingScript = |
663 PendingScript::create(script, scriptStartPosition); | 670 PendingScript::create(script, scriptStartPosition); |
664 } else { | 671 } else { |
665 // 6th Clause of Step 23. | 672 // 6th Clause of Step 23. |
666 // "Immediately execute the script block, | 673 // "Immediately execute the script block, |
667 // even if other scripts are already executing." | 674 // even if other scripts are already executing." |
668 // TODO(hiroshige): Merge the block into ScriptLoader::prepareScript(). | 675 // TODO(hiroshige): Merge the block into ScriptLoader::prepareScript(). |
| 676 TRACE_EVENT0("blink", "HTMLParserScriptRunner immediate-execute"); |
669 DCHECK_GT(m_reentryPermit->scriptNestingLevel(), 1u); | 677 DCHECK_GT(m_reentryPermit->scriptNestingLevel(), 1u); |
670 if (m_parserBlockingScript) | 678 if (m_parserBlockingScript) |
671 m_parserBlockingScript->dispose(); | 679 m_parserBlockingScript->dispose(); |
672 m_parserBlockingScript = nullptr; | 680 m_parserBlockingScript = nullptr; |
673 ScriptSourceCode sourceCode(script->textContent(), | 681 ScriptSourceCode sourceCode(script->textContent(), |
674 documentURLForScriptExecution(m_document), | 682 documentURLForScriptExecution(m_document), |
675 scriptStartPosition); | 683 scriptStartPosition); |
676 doExecuteScript(script, sourceCode, scriptStartPosition); | 684 doExecuteScript(script, sourceCode, scriptStartPosition); |
677 } | 685 } |
678 } else { | 686 } else { |
(...skipping 13 matching lines...) Expand all Loading... |
692 | 700 |
693 DEFINE_TRACE(HTMLParserScriptRunner) { | 701 DEFINE_TRACE(HTMLParserScriptRunner) { |
694 visitor->trace(m_document); | 702 visitor->trace(m_document); |
695 visitor->trace(m_host); | 703 visitor->trace(m_host); |
696 visitor->trace(m_parserBlockingScript); | 704 visitor->trace(m_parserBlockingScript); |
697 visitor->trace(m_scriptsToExecuteAfterParsing); | 705 visitor->trace(m_scriptsToExecuteAfterParsing); |
698 PendingScriptClient::trace(visitor); | 706 PendingScriptClient::trace(visitor); |
699 } | 707 } |
700 | 708 |
701 } // namespace blink | 709 } // namespace blink |
OLD | NEW |