| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 value->setString("url", scriptLoader->resource()->url().string()); | 59 value->setString("url", scriptLoader->resource()->url().string()); |
| 60 if (element->ownerDocument() && element->ownerDocument()->frame()) | 60 if (element->ownerDocument() && element->ownerDocument()->frame()) |
| 61 value->setString("frame", String::format("0x%" PRIx64, static_cast<uint6
4_t>(reinterpret_cast<intptr_t>(element->ownerDocument()->frame())))); | 61 value->setString("frame", String::format("0x%" PRIx64, static_cast<uint6
4_t>(reinterpret_cast<intptr_t>(element->ownerDocument()->frame())))); |
| 62 if (textPosition.m_line.zeroBasedInt() > 0 || textPosition.m_column.zeroBase
dInt() > 0) { | 62 if (textPosition.m_line.zeroBasedInt() > 0 || textPosition.m_column.zeroBase
dInt() > 0) { |
| 63 value->setInteger("lineNumber", textPosition.m_line.oneBasedInt()); | 63 value->setInteger("lineNumber", textPosition.m_line.oneBasedInt()); |
| 64 value->setInteger("columnNumber", textPosition.m_column.oneBasedInt()); | 64 value->setInteger("columnNumber", textPosition.m_column.oneBasedInt()); |
| 65 } | 65 } |
| 66 return value.release(); | 66 return value.release(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool doExecuteScript(Element* scriptElement, const ScriptSourceCode& sourceCode,
const TextPosition& textPosition, double* compilationFinishTime = nullptr) | 69 bool doExecuteScript(Element* scriptElement, const ScriptSourceCode& sourceCode,
const TextPosition& textPosition) |
| 70 { | 70 { |
| 71 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(scriptElement); | 71 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(scriptElement); |
| 72 ASSERT(scriptLoader); | 72 ASSERT(scriptLoader); |
| 73 TRACE_EVENT_WITH_FLOW1("blink", "HTMLScriptRunner ExecuteScript", scriptElem
ent, TRACE_EVENT_FLAG_FLOW_IN, | 73 TRACE_EVENT_WITH_FLOW1("blink", "HTMLScriptRunner ExecuteScript", scriptElem
ent, TRACE_EVENT_FLAG_FLOW_IN, |
| 74 "data", getTraceArgsForScriptElement(scriptElement, textPosition)); | 74 "data", getTraceArgsForScriptElement(scriptElement, textPosition)); |
| 75 return scriptLoader->executeScript(sourceCode, compilationFinishTime); | 75 return scriptLoader->executeScript(sourceCode); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void traceParserBlockingScript(const PendingScript* pendingScript, bool waitingF
orResources) | 78 void traceParserBlockingScript(const PendingScript* pendingScript, bool waitingF
orResources) |
| 79 { | 79 { |
| 80 // The HTML parser must yield before executing script in the following | 80 // The HTML parser must yield before executing script in the following |
| 81 // cases: | 81 // cases: |
| 82 // * the script's execution is blocked on the completed load of the script | 82 // * the script's execution is blocked on the completed load of the script |
| 83 // resource | 83 // resource |
| 84 // (https://html.spec.whatwg.org/multipage/scripting.html#pending-parsing-
blocking-script) | 84 // (https://html.spec.whatwg.org/multipage/scripting.html#pending-parsing-
blocking-script) |
| 85 // * the script's execution is blocked on the load of a style sheet or other | 85 // * the script's execution is blocked on the load of a style sheet or other |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } // namespace | 130 } // namespace |
| 131 | 131 |
| 132 using namespace HTMLNames; | 132 using namespace HTMLNames; |
| 133 | 133 |
| 134 HTMLScriptRunner::HTMLScriptRunner(Document* document, HTMLScriptRunnerHost* hos
t) | 134 HTMLScriptRunner::HTMLScriptRunner(Document* document, HTMLScriptRunnerHost* hos
t) |
| 135 : m_document(document) | 135 : m_document(document) |
| 136 , m_host(host) | 136 , m_host(host) |
| 137 , m_parserBlockingScript(PendingScript::create(nullptr, nullptr)) | 137 , m_parserBlockingScript(PendingScript::create(nullptr, nullptr)) |
| 138 , m_scriptNestingLevel(0) | 138 , m_scriptNestingLevel(0) |
| 139 , m_hasScriptsWaitingForResources(false) | 139 , m_hasScriptsWaitingForResources(false) |
| 140 , m_parserBlockingScriptAlreadyLoaded(false) | |
| 141 { | 140 { |
| 142 ASSERT(m_host); | 141 ASSERT(m_host); |
| 143 #if ENABLE(OILPAN) | 142 #if ENABLE(OILPAN) |
| 144 ThreadState::current()->registerPreFinalizer(this); | 143 ThreadState::current()->registerPreFinalizer(this); |
| 145 #endif | 144 #endif |
| 146 } | 145 } |
| 147 | 146 |
| 148 HTMLScriptRunner::~HTMLScriptRunner() | 147 HTMLScriptRunner::~HTMLScriptRunner() |
| 149 { | 148 { |
| 150 // Verify that detach() has been called. | 149 // Verify that detach() has been called. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 ASSERT(m_document->isScriptExecutionReady()); | 181 ASSERT(m_document->isScriptExecutionReady()); |
| 183 ASSERT(isPendingScriptReady(m_parserBlockingScript.get())); | 182 ASSERT(isPendingScriptReady(m_parserBlockingScript.get())); |
| 184 | 183 |
| 185 InsertionPointRecord insertionPointRecord(m_host->inputStream()); | 184 InsertionPointRecord insertionPointRecord(m_host->inputStream()); |
| 186 executePendingScriptAndDispatchEvent(m_parserBlockingScript.get(), ScriptStr
eamer::ParsingBlocking); | 185 executePendingScriptAndDispatchEvent(m_parserBlockingScript.get(), ScriptStr
eamer::ParsingBlocking); |
| 187 } | 186 } |
| 188 | 187 |
| 189 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript* pendi
ngScript, ScriptStreamer::Type pendingScriptType) | 188 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript* pendi
ngScript, ScriptStreamer::Type pendingScriptType) |
| 190 { | 189 { |
| 191 bool errorOccurred = false; | 190 bool errorOccurred = false; |
| 192 double loadFinishTime = pendingScript->resource() && pendingScript->resource
()->url().protocolIsInHTTPFamily() ? pendingScript->resource()->loadFinishTime()
: 0; | |
| 193 ScriptSourceCode sourceCode = pendingScript->getSource(documentURLForScriptE
xecution(m_document), errorOccurred); | 191 ScriptSourceCode sourceCode = pendingScript->getSource(documentURLForScriptE
xecution(m_document), errorOccurred); |
| 194 | 192 |
| 195 // Stop watching loads before executeScript to prevent recursion if the scri
pt reloads itself. | 193 // Stop watching loads before executeScript to prevent recursion if the scri
pt reloads itself. |
| 196 pendingScript->stopWatchingForLoad(); | 194 pendingScript->stopWatchingForLoad(); |
| 197 | 195 |
| 198 if (!isExecutingScript()) { | 196 if (!isExecutingScript()) { |
| 199 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate()); | 197 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate()); |
| 200 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { | 198 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { |
| 201 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead
y(); | 199 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead
y(); |
| 202 // The parser cannot be unblocked as a microtask requested another r
esource | 200 // The parser cannot be unblocked as a microtask requested another r
esource |
| 203 if (m_hasScriptsWaitingForResources) | 201 if (m_hasScriptsWaitingForResources) |
| 204 return; | 202 return; |
| 205 } | 203 } |
| 206 } | 204 } |
| 207 | 205 |
| 208 TextPosition scriptStartPosition = pendingScript->startingPosition(); | 206 TextPosition scriptStartPosition = pendingScript->startingPosition(); |
| 209 // Clear the pending script before possible re-entrancy from executeScript() | 207 // Clear the pending script before possible re-entrancy from executeScript() |
| 210 RefPtrWillBeRawPtr<Element> element = pendingScript->releaseElementAndClear(
); | 208 RefPtrWillBeRawPtr<Element> element = pendingScript->releaseElementAndClear(
); |
| 211 double compilationFinishTime = 0; | |
| 212 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { | 209 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { |
| 213 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 210 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
| 214 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem
enter(m_document); | 211 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem
enter(m_document); |
| 215 if (errorOccurred) { | 212 if (errorOccurred) { |
| 216 TRACE_EVENT_WITH_FLOW1("blink", "HTMLScriptRunner ExecuteScriptFaile
d", element.get(), TRACE_EVENT_FLAG_FLOW_IN, | 213 TRACE_EVENT_WITH_FLOW1("blink", "HTMLScriptRunner ExecuteScriptFaile
d", element.get(), TRACE_EVENT_FLAG_FLOW_IN, |
| 217 "data", getTraceArgsForScriptElement(element.get(), scriptStartP
osition)); | 214 "data", getTraceArgsForScriptElement(element.get(), scriptStartP
osition)); |
| 218 scriptLoader->dispatchErrorEvent(); | 215 scriptLoader->dispatchErrorEvent(); |
| 219 } else { | 216 } else { |
| 220 ASSERT(isExecutingScript()); | 217 ASSERT(isExecutingScript()); |
| 221 if (!doExecuteScript(element.get(), sourceCode, scriptStartPosition,
&compilationFinishTime)) { | 218 if (!doExecuteScript(element.get(), sourceCode, scriptStartPosition)
) { |
| 222 scriptLoader->dispatchErrorEvent(); | 219 scriptLoader->dispatchErrorEvent(); |
| 223 } else { | 220 } else { |
| 224 element->dispatchEvent(Event::create(EventTypeNames::load)); | 221 element->dispatchEvent(Event::create(EventTypeNames::load)); |
| 225 } | 222 } |
| 226 } | 223 } |
| 227 } | 224 } |
| 228 // The exact value doesn't matter; valid time stamps are much bigger than th
is value. | |
| 229 const double epsilon = 1; | |
| 230 if (pendingScriptType == ScriptStreamer::ParsingBlocking && !m_parserBlockin
gScriptAlreadyLoaded && compilationFinishTime > epsilon && loadFinishTime > epsi
lon) { | |
| 231 int duration = (compilationFinishTime - loadFinishTime) * 1000; | |
| 232 DEFINE_STATIC_LOCAL(CustomCountHistogram, loadAndCompileHistogram, ("Web
Core.Scripts.ParsingBlocking.TimeBetweenLoadedAndCompiled", 0, 10000, 50)); | |
| 233 loadAndCompileHistogram.count(duration); | |
| 234 } | |
| 235 | 225 |
| 236 ASSERT(!isExecutingScript()); | 226 ASSERT(!isExecutingScript()); |
| 237 } | 227 } |
| 238 | 228 |
| 239 void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) | 229 void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) |
| 240 { | 230 { |
| 241 if (m_parserBlockingScript->resource() == resource) { | 231 if (m_parserBlockingScript->resource() == resource) { |
| 242 m_parserBlockingScript->stopWatchingForLoad(); | 232 m_parserBlockingScript->stopWatchingForLoad(); |
| 243 m_parserBlockingScript->releaseElementAndClear(); | 233 m_parserBlockingScript->releaseElementAndClear(); |
| 244 return; | 234 return; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 437 |
| 448 DEFINE_TRACE(HTMLScriptRunner) | 438 DEFINE_TRACE(HTMLScriptRunner) |
| 449 { | 439 { |
| 450 visitor->trace(m_document); | 440 visitor->trace(m_document); |
| 451 visitor->trace(m_host); | 441 visitor->trace(m_host); |
| 452 visitor->trace(m_parserBlockingScript); | 442 visitor->trace(m_parserBlockingScript); |
| 453 visitor->trace(m_scriptsToExecuteAfterParsing); | 443 visitor->trace(m_scriptsToExecuteAfterParsing); |
| 454 } | 444 } |
| 455 | 445 |
| 456 } // namespace blink | 446 } // namespace blink |
| OLD | NEW |