| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 ScriptStreamer::ParsingBlocking); | 201 ScriptStreamer::ParsingBlocking); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void HTMLScriptRunner::executePendingScriptAndDispatchEvent( | 204 void HTMLScriptRunner::executePendingScriptAndDispatchEvent( |
| 205 PendingScript* pendingScript, | 205 PendingScript* pendingScript, |
| 206 ScriptStreamer::Type pendingScriptType) { | 206 ScriptStreamer::Type pendingScriptType) { |
| 207 bool errorOccurred = false; | 207 bool errorOccurred = false; |
| 208 ScriptSourceCode sourceCode = pendingScript->getSource( | 208 ScriptSourceCode sourceCode = pendingScript->getSource( |
| 209 documentURLForScriptExecution(m_document), errorOccurred); | 209 documentURLForScriptExecution(m_document), errorOccurred); |
| 210 | 210 |
| 211 // Stop watching loads before executeScript to prevent recursion if the script
reloads itself. | 211 // Stop watching loads before executeScript to prevent recursion if the script |
| 212 // reloads itself. |
| 212 pendingScript->stopWatchingForLoad(); | 213 pendingScript->stopWatchingForLoad(); |
| 213 | 214 |
| 214 if (!isExecutingScript()) { | 215 if (!isExecutingScript()) { |
| 215 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate()); | 216 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate()); |
| 216 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { | 217 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { |
| 217 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); | 218 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); |
| 218 // The parser cannot be unblocked as a microtask requested another resourc
e | 219 // The parser cannot be unblocked as a microtask requested another |
| 220 // resource |
| 219 if (m_hasScriptsWaitingForResources) | 221 if (m_hasScriptsWaitingForResources) |
| 220 return; | 222 return; |
| 221 } | 223 } |
| 222 } | 224 } |
| 223 | 225 |
| 224 TextPosition scriptStartPosition = pendingScript->startingPosition(); | 226 TextPosition scriptStartPosition = pendingScript->startingPosition(); |
| 225 double scriptParserBlockingTime = | 227 double scriptParserBlockingTime = |
| 226 pendingScript->parserBlockingLoadStartTime(); | 228 pendingScript->parserBlockingLoadStartTime(); |
| 227 // Clear the pending script before possible re-entrancy from executeScript() | 229 // Clear the pending script before possible re-entrancy from executeScript() |
| 228 Element* element = pendingScript->releaseElementAndClear(); | 230 Element* element = pendingScript->releaseElementAndClear(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 "blink", "HTMLScriptRunner::execute", "data", | 343 "blink", "HTMLScriptRunner::execute", "data", |
| 342 getTraceArgsForScriptElement(scriptElement, scriptStartPosition)); | 344 getTraceArgsForScriptElement(scriptElement, scriptStartPosition)); |
| 343 // FIXME: If scripting is disabled, always just return. | 345 // FIXME: If scripting is disabled, always just return. |
| 344 | 346 |
| 345 bool hadPreloadScanner = m_host->hasPreloadScanner(); | 347 bool hadPreloadScanner = m_host->hasPreloadScanner(); |
| 346 | 348 |
| 347 // Try to execute the script given to us. | 349 // Try to execute the script given to us. |
| 348 runScript(scriptElement, scriptStartPosition); | 350 runScript(scriptElement, scriptStartPosition); |
| 349 | 351 |
| 350 if (hasParserBlockingScript()) { | 352 if (hasParserBlockingScript()) { |
| 351 if (isExecutingScript()) | 353 if (isExecutingScript()) { |
| 352 return; // Unwind to the outermost HTMLScriptRunner::execute before conti
nuing parsing. | 354 // Unwind to the outermost HTMLScriptRunner::execute before continuing |
| 355 // parsing. |
| 356 return; |
| 357 } |
| 353 | 358 |
| 354 traceParserBlockingScript(m_parserBlockingScript.get(), | 359 traceParserBlockingScript(m_parserBlockingScript.get(), |
| 355 !m_document->isScriptExecutionReady()); | 360 !m_document->isScriptExecutionReady()); |
| 356 m_parserBlockingScript->markParserBlockingLoadStartTime(); | 361 m_parserBlockingScript->markParserBlockingLoadStartTime(); |
| 357 | 362 |
| 358 // If preload scanner got created, it is missing the source after the curren
t insertion point. Append it and scan. | 363 // If preload scanner got created, it is missing the source after the |
| 364 // current insertion point. Append it and scan. |
| 359 if (!hadPreloadScanner && m_host->hasPreloadScanner()) | 365 if (!hadPreloadScanner && m_host->hasPreloadScanner()) |
| 360 m_host->appendCurrentInputStreamToPreloadScannerAndScan(); | 366 m_host->appendCurrentInputStreamToPreloadScannerAndScan(); |
| 361 executeParsingBlockingScripts(); | 367 executeParsingBlockingScripts(); |
| 362 } | 368 } |
| 363 } | 369 } |
| 364 | 370 |
| 365 bool HTMLScriptRunner::hasParserBlockingScript() const { | 371 bool HTMLScriptRunner::hasParserBlockingScript() const { |
| 366 return !!m_parserBlockingScript->element(); | 372 return !!m_parserBlockingScript->element(); |
| 367 } | 373 } |
| 368 | 374 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 419 } |
| 414 return true; | 420 return true; |
| 415 } | 421 } |
| 416 | 422 |
| 417 void HTMLScriptRunner::requestParsingBlockingScript(Element* element) { | 423 void HTMLScriptRunner::requestParsingBlockingScript(Element* element) { |
| 418 if (!requestPendingScript(m_parserBlockingScript.get(), element)) | 424 if (!requestPendingScript(m_parserBlockingScript.get(), element)) |
| 419 return; | 425 return; |
| 420 | 426 |
| 421 ASSERT(m_parserBlockingScript->resource()); | 427 ASSERT(m_parserBlockingScript->resource()); |
| 422 | 428 |
| 423 // We only care about a load callback if resource is not already | 429 // We only care about a load callback if resource is not already in the cache. |
| 424 // in the cache. Callers will attempt to run the m_parserBlockingScript | 430 // Callers will attempt to run the m_parserBlockingScript if possible before |
| 425 // if possible before returning control to the parser. | 431 // returning control to the parser. |
| 426 if (!m_parserBlockingScript->isReady()) { | 432 if (!m_parserBlockingScript->isReady()) { |
| 427 if (m_document->frame()) { | 433 if (m_document->frame()) { |
| 428 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame()); | 434 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame()); |
| 429 if (scriptState) | 435 if (scriptState) |
| 430 ScriptStreamer::startStreaming( | 436 ScriptStreamer::startStreaming( |
| 431 m_parserBlockingScript.get(), ScriptStreamer::ParsingBlocking, | 437 m_parserBlockingScript.get(), ScriptStreamer::ParsingBlocking, |
| 432 m_document->frame()->settings(), scriptState, | 438 m_document->frame()->settings(), scriptState, |
| 433 TaskRunnerHelper::get(TaskType::Networking, m_document)); | 439 TaskRunnerHelper::get(TaskType::Networking, m_document)); |
| 434 } | 440 } |
| 435 | 441 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 529 |
| 524 DEFINE_TRACE(HTMLScriptRunner) { | 530 DEFINE_TRACE(HTMLScriptRunner) { |
| 525 visitor->trace(m_document); | 531 visitor->trace(m_document); |
| 526 visitor->trace(m_host); | 532 visitor->trace(m_host); |
| 527 visitor->trace(m_parserBlockingScript); | 533 visitor->trace(m_parserBlockingScript); |
| 528 visitor->trace(m_scriptsToExecuteAfterParsing); | 534 visitor->trace(m_scriptsToExecuteAfterParsing); |
| 529 ScriptResourceClient::trace(visitor); | 535 ScriptResourceClient::trace(visitor); |
| 530 } | 536 } |
| 531 | 537 |
| 532 } // namespace blink | 538 } // namespace blink |
| OLD | NEW |