Chromium Code Reviews| 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 30 matching lines...) Expand all Loading... | |
| 41 #include "public/platform/Platform.h" | 41 #include "public/platform/Platform.h" |
| 42 #include "public/platform/WebFrameScheduler.h" | 42 #include "public/platform/WebFrameScheduler.h" |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 using namespace HTMLNames; | 46 using namespace HTMLNames; |
| 47 | 47 |
| 48 HTMLScriptRunner::HTMLScriptRunner(Document* document, HTMLScriptRunnerHost* hos t) | 48 HTMLScriptRunner::HTMLScriptRunner(Document* document, HTMLScriptRunnerHost* hos t) |
| 49 : m_document(document) | 49 : m_document(document) |
| 50 , m_host(host) | 50 , m_host(host) |
| 51 , m_parserBlockingScript(PendingScript::create(nullptr, nullptr)) | |
| 51 , m_scriptNestingLevel(0) | 52 , m_scriptNestingLevel(0) |
| 52 , m_hasScriptsWaitingForResources(false) | 53 , m_hasScriptsWaitingForResources(false) |
| 53 , m_parserBlockingScriptAlreadyLoaded(false) | 54 , m_parserBlockingScriptAlreadyLoaded(false) |
| 54 { | 55 { |
| 55 ASSERT(m_host); | 56 ASSERT(m_host); |
| 56 } | 57 } |
| 57 | 58 |
| 58 HTMLScriptRunner::~HTMLScriptRunner() | 59 HTMLScriptRunner::~HTMLScriptRunner() |
| 59 { | 60 { |
| 60 #if ENABLE(OILPAN) | 61 #if ENABLE(OILPAN) |
| 61 // If the document is destructed without having explicitly | 62 // If the document is destructed without having explicitly |
| 62 // detached the parser (and this script runner object), perform | 63 // detached the parser (and this script runner object), perform |
| 63 // detach steps now. This will happen if the Document, the parser | 64 // detach steps now. This will happen if the Document, the parser |
| 64 // and this script runner object are swept out in the same GC. | 65 // and this script runner object are swept out in the same GC. |
| 65 detach(); | 66 detach(); |
| 66 #else | 67 #else |
| 67 // Verify that detach() has been called. | 68 // Verify that detach() has been called. |
| 68 ASSERT(!m_document); | 69 ASSERT(!m_document); |
| 69 #endif | 70 #endif |
| 70 } | 71 } |
| 71 | 72 |
| 72 void HTMLScriptRunner::detach() | 73 void HTMLScriptRunner::detach() |
| 73 { | 74 { |
| 74 if (!m_document) | 75 if (!m_document) |
| 75 return; | 76 return; |
| 76 | 77 |
| 77 m_parserBlockingScript.stopWatchingForLoad(this); | 78 m_parserBlockingScript->stopWatchingForLoad(this); |
|
haraken
2016/01/12 00:22:52
You cannot touch m_parserBlockingScript here becau
Nate Chapin
2016/01/13 20:36:33
Done.
| |
| 78 m_parserBlockingScript.releaseElementAndClear(); | 79 m_parserBlockingScript->releaseElementAndClear(); |
| 79 | 80 |
| 80 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { | 81 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { |
| 81 PendingScript pendingScript = m_scriptsToExecuteAfterParsing.takeFirst() ; | 82 OwnPtrWillBeRawPtr<PendingScript> pendingScript = m_scriptsToExecuteAfte rParsing.takeFirst(); |
| 82 pendingScript.stopWatchingForLoad(this); | 83 pendingScript->stopWatchingForLoad(this); |
| 83 pendingScript.releaseElementAndClear(); | 84 pendingScript->releaseElementAndClear(); |
| 84 } | 85 } |
| 85 m_document = nullptr; | 86 m_document = nullptr; |
| 86 } | 87 } |
| 87 | 88 |
| 88 static KURL documentURLForScriptExecution(Document* document) | 89 static KURL documentURLForScriptExecution(Document* document) |
| 89 { | 90 { |
| 90 if (!document) | 91 if (!document) |
| 91 return KURL(); | 92 return KURL(); |
| 92 | 93 |
| 93 if (!document->frame()) { | 94 if (!document->frame()) { |
| 94 if (document->importsController()) | 95 if (document->importsController()) |
| 95 return document->url(); | 96 return document->url(); |
| 96 return KURL(); | 97 return KURL(); |
| 97 } | 98 } |
| 98 | 99 |
| 99 // Use the URL of the currently active document for this frame. | 100 // Use the URL of the currently active document for this frame. |
| 100 return document->frame()->document()->url(); | 101 return document->frame()->document()->url(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 inline PassRefPtrWillBeRawPtr<Event> createScriptLoadEvent() | 104 inline PassRefPtrWillBeRawPtr<Event> createScriptLoadEvent() |
| 104 { | 105 { |
| 105 return Event::create(EventTypeNames::load); | 106 return Event::create(EventTypeNames::load); |
| 106 } | 107 } |
| 107 | 108 |
| 108 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript& script) | 109 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript* script) |
| 109 { | 110 { |
| 110 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); | 111 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); |
| 111 if (m_hasScriptsWaitingForResources) | 112 if (m_hasScriptsWaitingForResources) |
| 112 return false; | 113 return false; |
| 113 return script.isReady(); | 114 return script->isReady(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void HTMLScriptRunner::executeParsingBlockingScript() | 117 void HTMLScriptRunner::executeParsingBlockingScript() |
| 117 { | 118 { |
| 118 ASSERT(m_document); | 119 ASSERT(m_document); |
| 119 ASSERT(!isExecutingScript()); | 120 ASSERT(!isExecutingScript()); |
| 120 ASSERT(m_document->isScriptExecutionReady()); | 121 ASSERT(m_document->isScriptExecutionReady()); |
| 121 ASSERT(isPendingScriptReady(m_parserBlockingScript)); | 122 ASSERT(isPendingScriptReady(m_parserBlockingScript.get())); |
| 122 | 123 |
| 123 InsertionPointRecord insertionPointRecord(m_host->inputStream()); | 124 InsertionPointRecord insertionPointRecord(m_host->inputStream()); |
| 124 executePendingScriptAndDispatchEvent(m_parserBlockingScript, PendingScript:: ParsingBlocking); | 125 executePendingScriptAndDispatchEvent(m_parserBlockingScript.get(), PendingSc ript::ParsingBlocking); |
| 125 } | 126 } |
| 126 | 127 |
| 127 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi ngScript, PendingScript::Type pendingScriptType) | 128 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript* pendi ngScript, PendingScript::Type pendingScriptType) |
| 128 { | 129 { |
| 129 bool errorOccurred = false; | 130 bool errorOccurred = false; |
| 130 double loadFinishTime = pendingScript.resource() && pendingScript.resource() ->url().protocolIsInHTTPFamily() ? pendingScript.resource()->loadFinishTime() : 0; | 131 double loadFinishTime = pendingScript->resource() && pendingScript->resource ()->url().protocolIsInHTTPFamily() ? pendingScript->resource()->loadFinishTime() : 0; |
| 131 ScriptSourceCode sourceCode = pendingScript.getSource(documentURLForScriptEx ecution(m_document), errorOccurred); | 132 ScriptSourceCode sourceCode = pendingScript->getSource(documentURLForScriptE xecution(m_document), errorOccurred); |
| 132 | 133 |
| 133 // Stop watching loads before executeScript to prevent recursion if the scri pt reloads itself. | 134 // Stop watching loads before executeScript to prevent recursion if the scri pt reloads itself. |
| 134 pendingScript.stopWatchingForLoad(this); | 135 pendingScript->stopWatchingForLoad(this); |
| 135 | 136 |
| 136 if (!isExecutingScript()) { | 137 if (!isExecutingScript()) { |
| 137 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate()); | 138 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate()); |
| 138 if (pendingScriptType == PendingScript::ParsingBlocking) { | 139 if (pendingScriptType == PendingScript::ParsingBlocking) { |
| 139 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead y(); | 140 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead y(); |
| 140 // The parser cannot be unblocked as a microtask requested another r esource | 141 // The parser cannot be unblocked as a microtask requested another r esource |
| 141 if (m_hasScriptsWaitingForResources) | 142 if (m_hasScriptsWaitingForResources) |
| 142 return; | 143 return; |
| 143 } | 144 } |
| 144 } | 145 } |
| 145 | 146 |
| 146 // Clear the pending script before possible rentrancy from executeScript() | 147 // Clear the pending script before possible rentrancy from executeScript() |
| 147 RefPtrWillBeRawPtr<Element> element = pendingScript.releaseElementAndClear() ; | 148 RefPtrWillBeRawPtr<Element> element = pendingScript->releaseElementAndClear( ); |
| 148 double compilationFinishTime = 0; | 149 double compilationFinishTime = 0; |
| 149 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { | 150 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { |
| 150 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 151 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
| 151 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem enter(m_document); | 152 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem enter(m_document); |
| 152 if (errorOccurred) | 153 if (errorOccurred) |
| 153 scriptLoader->dispatchErrorEvent(); | 154 scriptLoader->dispatchErrorEvent(); |
| 154 else { | 155 else { |
| 155 ASSERT(isExecutingScript()); | 156 ASSERT(isExecutingScript()); |
| 156 if (!scriptLoader->executeScript(sourceCode, &compilationFinishTime) ) { | 157 if (!scriptLoader->executeScript(sourceCode, &compilationFinishTime) ) { |
| 157 scriptLoader->dispatchErrorEvent(); | 158 scriptLoader->dispatchErrorEvent(); |
| 158 } else { | 159 } else { |
| 159 element->dispatchEvent(createScriptLoadEvent()); | 160 element->dispatchEvent(createScriptLoadEvent()); |
| 160 } | 161 } |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 // The exact value doesn't matter; valid time stamps are much bigger than th is value. | 164 // The exact value doesn't matter; valid time stamps are much bigger than th is value. |
| 164 const double epsilon = 1; | 165 const double epsilon = 1; |
| 165 if (pendingScriptType == PendingScript::ParsingBlocking && !m_parserBlocking ScriptAlreadyLoaded && compilationFinishTime > epsilon && loadFinishTime > epsil on) { | 166 if (pendingScriptType == PendingScript::ParsingBlocking && !m_parserBlocking ScriptAlreadyLoaded && compilationFinishTime > epsilon && loadFinishTime > epsil on) { |
| 166 Platform::current()->histogramCustomCounts("WebCore.Scripts.ParsingBlock ing.TimeBetweenLoadedAndCompiled", (compilationFinishTime - loadFinishTime) * 10 00, 0, 10000, 50); | 167 Platform::current()->histogramCustomCounts("WebCore.Scripts.ParsingBlock ing.TimeBetweenLoadedAndCompiled", (compilationFinishTime - loadFinishTime) * 10 00, 0, 10000, 50); |
| 167 } | 168 } |
| 168 | 169 |
| 169 ASSERT(!isExecutingScript()); | 170 ASSERT(!isExecutingScript()); |
| 170 } | 171 } |
| 171 | 172 |
| 172 void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) | 173 void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) |
| 173 { | 174 { |
| 174 if (m_parserBlockingScript.resource() == resource) { | 175 if (m_parserBlockingScript->resource() == resource) { |
| 175 m_parserBlockingScript.stopWatchingForLoad(this); | 176 m_parserBlockingScript->stopWatchingForLoad(this); |
| 176 m_parserBlockingScript.releaseElementAndClear(); | 177 m_parserBlockingScript->releaseElementAndClear(); |
| 177 return; | 178 return; |
| 178 } | 179 } |
| 179 for (PendingScript& script : m_scriptsToExecuteAfterParsing) { | 180 for (auto& script : m_scriptsToExecuteAfterParsing) { |
| 180 if (script.resource() == resource) { | 181 if (script->resource() == resource) { |
| 181 script.stopWatchingForLoad(this); | 182 script->stopWatchingForLoad(this); |
| 182 script.releaseElementAndClear(); | 183 script->releaseElementAndClear(); |
| 183 return; | 184 return; |
| 184 } | 185 } |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 | 188 |
| 188 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) | 189 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) |
| 189 { | 190 { |
| 190 // Handle cancellations of parser-blocking script loads without | 191 // Handle cancellations of parser-blocking script loads without |
| 191 // notifying the host (i.e., parser) if these were initiated by nested | 192 // notifying the host (i.e., parser) if these were initiated by nested |
| 192 // document.write()s. The cancellation may have been triggered by | 193 // document.write()s. The cancellation may have been triggered by |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 218 return; // Unwind to the outermost HTMLScriptRunner::execute before continuing parsing. | 219 return; // Unwind to the outermost HTMLScriptRunner::execute before continuing parsing. |
| 219 // If preload scanner got created, it is missing the source after the cu rrent insertion point. Append it and scan. | 220 // If preload scanner got created, it is missing the source after the cu rrent insertion point. Append it and scan. |
| 220 if (!hadPreloadScanner && m_host->hasPreloadScanner()) | 221 if (!hadPreloadScanner && m_host->hasPreloadScanner()) |
| 221 m_host->appendCurrentInputStreamToPreloadScannerAndScan(); | 222 m_host->appendCurrentInputStreamToPreloadScannerAndScan(); |
| 222 executeParsingBlockingScripts(); | 223 executeParsingBlockingScripts(); |
| 223 } | 224 } |
| 224 } | 225 } |
| 225 | 226 |
| 226 bool HTMLScriptRunner::hasParserBlockingScript() const | 227 bool HTMLScriptRunner::hasParserBlockingScript() const |
| 227 { | 228 { |
| 228 return !!m_parserBlockingScript.element(); | 229 return !!m_parserBlockingScript->element(); |
| 229 } | 230 } |
| 230 | 231 |
| 231 void HTMLScriptRunner::executeParsingBlockingScripts() | 232 void HTMLScriptRunner::executeParsingBlockingScripts() |
| 232 { | 233 { |
| 233 while (hasParserBlockingScript() && isPendingScriptReady(m_parserBlockingScr ipt)) | 234 while (hasParserBlockingScript() && isPendingScriptReady(m_parserBlockingScr ipt.get())) |
| 234 executeParsingBlockingScript(); | 235 executeParsingBlockingScript(); |
| 235 } | 236 } |
| 236 | 237 |
| 237 void HTMLScriptRunner::executeScriptsWaitingForLoad(Resource* resource) | 238 void HTMLScriptRunner::executeScriptsWaitingForLoad(Resource* resource) |
| 238 { | 239 { |
| 239 ASSERT(!isExecutingScript()); | 240 ASSERT(!isExecutingScript()); |
| 240 ASSERT(hasParserBlockingScript()); | 241 ASSERT(hasParserBlockingScript()); |
| 241 ASSERT_UNUSED(resource, m_parserBlockingScript.resource() == resource); | 242 ASSERT_UNUSED(resource, m_parserBlockingScript->resource() == resource); |
| 242 ASSERT(m_parserBlockingScript.isReady()); | 243 ASSERT(m_parserBlockingScript->isReady()); |
| 243 executeParsingBlockingScripts(); | 244 executeParsingBlockingScripts(); |
| 244 } | 245 } |
| 245 | 246 |
| 246 void HTMLScriptRunner::executeScriptsWaitingForResources() | 247 void HTMLScriptRunner::executeScriptsWaitingForResources() |
| 247 { | 248 { |
| 248 ASSERT(m_document); | 249 ASSERT(m_document); |
| 249 // Callers should check hasScriptsWaitingForResources() before calling | 250 // Callers should check hasScriptsWaitingForResources() before calling |
| 250 // to prevent parser or script re-entry during </style> parsing. | 251 // to prevent parser or script re-entry during </style> parsing. |
| 251 ASSERT(hasScriptsWaitingForResources()); | 252 ASSERT(hasScriptsWaitingForResources()); |
| 252 ASSERT(!isExecutingScript()); | 253 ASSERT(!isExecutingScript()); |
| 253 ASSERT(m_document->isScriptExecutionReady()); | 254 ASSERT(m_document->isScriptExecutionReady()); |
| 254 executeParsingBlockingScripts(); | 255 executeParsingBlockingScripts(); |
| 255 } | 256 } |
| 256 | 257 |
| 257 bool HTMLScriptRunner::executeScriptsWaitingForParsing() | 258 bool HTMLScriptRunner::executeScriptsWaitingForParsing() |
| 258 { | 259 { |
| 259 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { | 260 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { |
| 260 ASSERT(!isExecutingScript()); | 261 ASSERT(!isExecutingScript()); |
| 261 ASSERT(!hasParserBlockingScript()); | 262 ASSERT(!hasParserBlockingScript()); |
| 262 ASSERT(m_scriptsToExecuteAfterParsing.first().resource()); | 263 ASSERT(m_scriptsToExecuteAfterParsing.first()->resource()); |
| 263 if (!m_scriptsToExecuteAfterParsing.first().isReady()) { | 264 if (!m_scriptsToExecuteAfterParsing.first()->isReady()) { |
| 264 m_scriptsToExecuteAfterParsing.first().watchForLoad(this); | 265 m_scriptsToExecuteAfterParsing.first()->watchForLoad(this); |
| 265 return false; | 266 return false; |
| 266 } | 267 } |
| 267 PendingScript first = m_scriptsToExecuteAfterParsing.takeFirst(); | 268 OwnPtrWillBeRawPtr<PendingScript> first = m_scriptsToExecuteAfterParsing .takeFirst(); |
| 268 executePendingScriptAndDispatchEvent(first, PendingScript::Deferred); | 269 executePendingScriptAndDispatchEvent(first.get(), PendingScript::Deferre d); |
| 269 // FIXME: What is this m_document check for? | 270 // FIXME: What is this m_document check for? |
| 270 if (!m_document) | 271 if (!m_document) |
| 271 return false; | 272 return false; |
| 272 } | 273 } |
| 273 return true; | 274 return true; |
| 274 } | 275 } |
| 275 | 276 |
| 276 void HTMLScriptRunner::requestParsingBlockingScript(Element* element) | 277 void HTMLScriptRunner::requestParsingBlockingScript(Element* element) |
| 277 { | 278 { |
| 278 if (!requestPendingScript(m_parserBlockingScript, element)) | 279 if (!requestPendingScript(m_parserBlockingScript.get(), element)) |
| 279 return; | 280 return; |
| 280 | 281 |
| 281 ASSERT(m_parserBlockingScript.resource()); | 282 ASSERT(m_parserBlockingScript->resource()); |
| 282 | 283 |
| 283 // We only care about a load callback if resource is not already | 284 // We only care about a load callback if resource is not already |
| 284 // in the cache. Callers will attempt to run the m_parserBlockingScript | 285 // in the cache. Callers will attempt to run the m_parserBlockingScript |
| 285 // if possible before returning control to the parser. | 286 // if possible before returning control to the parser. |
| 286 if (!m_parserBlockingScript.isReady()) { | 287 if (!m_parserBlockingScript->isReady()) { |
| 287 if (m_document->frame()) { | 288 if (m_document->frame()) { |
| 288 ScriptState* scriptState = ScriptState::forMainWorld(m_document->fra me()); | 289 ScriptState* scriptState = ScriptState::forMainWorld(m_document->fra me()); |
| 289 if (scriptState) | 290 if (scriptState) |
| 290 ScriptStreamer::startStreaming(m_parserBlockingScript, PendingSc ript::ParsingBlocking, m_document->frame()->settings(), scriptState, m_document- >loadingTaskRunner()); | 291 ScriptStreamer::startStreaming(m_parserBlockingScript.get(), Pen dingScript::ParsingBlocking, m_document->frame()->settings(), scriptState, m_doc ument->loadingTaskRunner()); |
| 291 } | 292 } |
| 292 | 293 |
| 293 m_parserBlockingScript.watchForLoad(this); | 294 m_parserBlockingScript->watchForLoad(this); |
| 294 } | 295 } |
| 295 } | 296 } |
| 296 | 297 |
| 297 void HTMLScriptRunner::requestDeferredScript(Element* element) | 298 void HTMLScriptRunner::requestDeferredScript(Element* element) |
| 298 { | 299 { |
| 299 PendingScript pendingScript; | 300 OwnPtrWillBeRawPtr<PendingScript> pendingScript = PendingScript::create(null ptr, nullptr); |
| 300 if (!requestPendingScript(pendingScript, element)) | 301 if (!requestPendingScript(pendingScript.get(), element)) |
| 301 return; | 302 return; |
| 302 | 303 |
| 303 if (m_document->frame() && !pendingScript.isReady()) { | 304 if (m_document->frame() && !pendingScript->isReady()) { |
| 304 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame() ); | 305 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame() ); |
| 305 if (scriptState) | 306 if (scriptState) |
| 306 ScriptStreamer::startStreaming(pendingScript, PendingScript::Deferre d, m_document->frame()->settings(), scriptState, m_document->loadingTaskRunner() ); | 307 ScriptStreamer::startStreaming(pendingScript.get(), PendingScript::D eferred, m_document->frame()->settings(), scriptState, m_document->loadingTaskRu nner()); |
| 307 } | 308 } |
| 308 | 309 |
| 309 ASSERT(pendingScript.resource()); | 310 ASSERT(pendingScript->resource()); |
| 310 m_scriptsToExecuteAfterParsing.append(pendingScript); | 311 m_scriptsToExecuteAfterParsing.append(pendingScript.release()); |
| 311 } | 312 } |
| 312 | 313 |
| 313 bool HTMLScriptRunner::requestPendingScript(PendingScript& pendingScript, Elemen t* script) const | 314 bool HTMLScriptRunner::requestPendingScript(PendingScript* pendingScript, Elemen t* script) const |
| 314 { | 315 { |
| 315 ASSERT(!pendingScript.element()); | 316 ASSERT(!pendingScript->element()); |
| 316 pendingScript.setElement(script); | 317 pendingScript->setElement(script); |
| 317 // This should correctly return 0 for empty or invalid srcValues. | 318 // This should correctly return 0 for empty or invalid srcValues. |
| 318 ScriptResource* resource = toScriptLoaderIfPossible(script)->resource().get( ); | 319 ScriptResource* resource = toScriptLoaderIfPossible(script)->resource().get( ); |
| 319 if (!resource) { | 320 if (!resource) { |
| 320 notImplemented(); // Dispatch error event. | 321 notImplemented(); // Dispatch error event. |
| 321 return false; | 322 return false; |
| 322 } | 323 } |
| 323 pendingScript.setScriptResource(resource); | 324 pendingScript->setScriptResource(resource); |
| 324 return true; | 325 return true; |
| 325 } | 326 } |
| 326 | 327 |
| 327 // Implements the initial steps for 'An end tag whose tag name is "script"' | 328 // Implements the initial steps for 'An end tag whose tag name is "script"' |
| 328 // http://whatwg.org/html#scriptEndTag | 329 // http://whatwg.org/html#scriptEndTag |
| 329 void HTMLScriptRunner::runScript(Element* script, const TextPosition& scriptStar tPosition) | 330 void HTMLScriptRunner::runScript(Element* script, const TextPosition& scriptStar tPosition) |
| 330 { | 331 { |
| 331 ASSERT(m_document); | 332 ASSERT(m_document); |
| 332 ASSERT(!hasParserBlockingScript()); | 333 ASSERT(!hasParserBlockingScript()); |
| 333 { | 334 { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 351 | 352 |
| 352 scriptLoader->prepareScript(scriptStartPosition); | 353 scriptLoader->prepareScript(scriptStartPosition); |
| 353 | 354 |
| 354 if (!scriptLoader->willBeParserExecuted()) | 355 if (!scriptLoader->willBeParserExecuted()) |
| 355 return; | 356 return; |
| 356 | 357 |
| 357 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { | 358 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { |
| 358 requestDeferredScript(script); | 359 requestDeferredScript(script); |
| 359 } else if (scriptLoader->readyToBeParserExecuted()) { | 360 } else if (scriptLoader->readyToBeParserExecuted()) { |
| 360 if (m_scriptNestingLevel == 1) { | 361 if (m_scriptNestingLevel == 1) { |
| 361 m_parserBlockingScript.setElement(script); | 362 m_parserBlockingScript->setElement(script); |
| 362 m_parserBlockingScript.setStartingPosition(scriptStartPosition); | 363 m_parserBlockingScript->setStartingPosition(scriptStartPosition) ; |
| 363 } else { | 364 } else { |
| 364 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); | 365 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); |
| 365 scriptLoader->executeScript(sourceCode); | 366 scriptLoader->executeScript(sourceCode); |
| 366 } | 367 } |
| 367 } else { | 368 } else { |
| 368 requestParsingBlockingScript(script); | 369 requestParsingBlockingScript(script); |
| 369 } | 370 } |
| 370 } | 371 } |
| 371 } | 372 } |
| 372 | 373 |
| 373 DEFINE_TRACE(HTMLScriptRunner) | 374 DEFINE_TRACE(HTMLScriptRunner) |
| 374 { | 375 { |
| 375 visitor->trace(m_document); | 376 visitor->trace(m_document); |
| 376 visitor->trace(m_host); | 377 visitor->trace(m_host); |
| 377 visitor->trace(m_parserBlockingScript); | 378 visitor->trace(m_parserBlockingScript); |
| 378 visitor->trace(m_scriptsToExecuteAfterParsing); | 379 visitor->trace(m_scriptsToExecuteAfterParsing); |
| 379 } | 380 } |
| 380 | 381 |
| 381 } // namespace blink | 382 } // namespace blink |
| OLD | NEW |