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

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

Issue 368283002: Stream scripts to V8 as they load - Blink side. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: removed untrue assert Created 6 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/html/parser/HTMLScriptRunner.h ('k') | Source/core/xml/parser/XMLDocumentParser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return Event::create(EventTypeNames::load); 102 return Event::create(EventTypeNames::load);
103 } 103 }
104 104
105 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript& script) 105 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript& script)
106 { 106 {
107 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); 107 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady();
108 if (m_hasScriptsWaitingForResources) 108 if (m_hasScriptsWaitingForResources)
109 return false; 109 return false;
110 if (script.resource() && !script.resource()->isLoaded()) 110 if (script.resource() && !script.resource()->isLoaded())
111 return false; 111 return false;
112 if (script.isStreaming())
113 return false;
112 return true; 114 return true;
113 } 115 }
114 116
115 void HTMLScriptRunner::executeParsingBlockingScript() 117 void HTMLScriptRunner::executeParsingBlockingScript()
116 { 118 {
117 ASSERT(m_document); 119 ASSERT(m_document);
118 ASSERT(!isExecutingScript()); 120 ASSERT(!isExecutingScript());
119 ASSERT(m_document->isScriptExecutionReady()); 121 ASSERT(m_document->isScriptExecutionReady());
120 ASSERT(isPendingScriptReady(m_parserBlockingScript)); 122 ASSERT(isPendingScriptReady(m_parserBlockingScript));
121 123
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 const double epsilon = 1; 162 const double epsilon = 1;
161 if (pendingScriptType == PendingScriptBlockingParser && !m_parserBlockingScr iptAlreadyLoaded && compilationFinishTime > epsilon && loadFinishTime > epsilon) { 163 if (pendingScriptType == PendingScriptBlockingParser && !m_parserBlockingScr iptAlreadyLoaded && compilationFinishTime > epsilon && loadFinishTime > epsilon) {
162 blink::Platform::current()->histogramCustomCounts("WebCore.Scripts.Parsi ngBlocking.TimeBetweenLoadedAndCompiled", (compilationFinishTime - loadFinishTim e) * 1000, 0, 10000, 50); 164 blink::Platform::current()->histogramCustomCounts("WebCore.Scripts.Parsi ngBlocking.TimeBetweenLoadedAndCompiled", (compilationFinishTime - loadFinishTim e) * 1000, 0, 10000, 50);
163 } 165 }
164 166
165 ASSERT(!isExecutingScript()); 167 ASSERT(!isExecutingScript());
166 } 168 }
167 169
168 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) 170 void HTMLScriptRunner::notifyFinished(Resource* cachedResource)
169 { 171 {
172 // For a parser-blocking script, this function should be called only when
173 // the streaming is complete.
174 ASSERT(!(m_parserBlockingScript.resource() == cachedResource
175 && m_parserBlockingScript.isStreaming()));
170 m_host->notifyScriptLoaded(cachedResource); 176 m_host->notifyScriptLoaded(cachedResource);
171 } 177 }
172 178
173 // Implements the steps for 'An end tag whose tag name is "script"' 179 // Implements the steps for 'An end tag whose tag name is "script"'
174 // http://whatwg.org/html#scriptEndTag 180 // http://whatwg.org/html#scriptEndTag
175 // Script handling lives outside the tree builder to keep each class simple. 181 // Script handling lives outside the tree builder to keep each class simple.
176 void HTMLScriptRunner::execute(PassRefPtrWillBeRawPtr<Element> scriptElement, co nst TextPosition& scriptStartPosition) 182 void HTMLScriptRunner::execute(PassRefPtrWillBeRawPtr<Element> scriptElement, co nst TextPosition& scriptStartPosition)
177 { 183 {
178 ASSERT(scriptElement); 184 ASSERT(scriptElement);
179 // FIXME: If scripting is disabled, always just return. 185 // FIXME: If scripting is disabled, always just return.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // Exclude already loaded resources (from memory cache) and reloads from the 259 // Exclude already loaded resources (from memory cache) and reloads from the
254 // computation of 260 // computation of
255 // WebCore.Scripts.ParsingBlocking.TimeBetweenLoadedAndCompiled (done after 261 // WebCore.Scripts.ParsingBlocking.TimeBetweenLoadedAndCompiled (done after
256 // the script is compiled). 262 // the script is compiled).
257 m_parserBlockingScriptAlreadyLoaded = m_parserBlockingScript.resource()->isL oaded() || m_parserBlockingScript.resource()->resourceToRevalidate(); 263 m_parserBlockingScriptAlreadyLoaded = m_parserBlockingScript.resource()->isL oaded() || m_parserBlockingScript.resource()->resourceToRevalidate();
258 blink::Platform::current()->histogramEnumeration("WebCore.Scripts.ParsingBlo cking.AlreadyLoaded", m_parserBlockingScriptAlreadyLoaded ? 1 : 0, 2); 264 blink::Platform::current()->histogramEnumeration("WebCore.Scripts.ParsingBlo cking.AlreadyLoaded", m_parserBlockingScriptAlreadyLoaded ? 1 : 0, 2);
259 265
260 // We only care about a load callback if resource is not already 266 // We only care about a load callback if resource is not already
261 // in the cache. Callers will attempt to run the m_parserBlockingScript 267 // in the cache. Callers will attempt to run the m_parserBlockingScript
262 // if possible before returning control to the parser. 268 // if possible before returning control to the parser.
263 if (!m_parserBlockingScript.resource()->isLoaded()) 269 if (!m_parserBlockingScript.resource()->isLoaded()) {
270 bool startedStreaming = false;
271 if (m_document->frame())
272 startedStreaming = ScriptStreamer::startStreaming(m_parserBlockingSc ript, m_document->frame()->settings(), ScriptState::forMainWorld(m_document->fra me()));
273 blink::Platform::current()->histogramEnumeration("WebCore.Scripts.Parsin gBlocking.StartedStreaming", startedStreaming ? 1 : 0, 2);
264 m_parserBlockingScript.watchForLoad(this); 274 m_parserBlockingScript.watchForLoad(this);
275 }
265 } 276 }
266 277
267 void HTMLScriptRunner::requestDeferredScript(Element* element) 278 void HTMLScriptRunner::requestDeferredScript(Element* element)
268 { 279 {
269 PendingScript pendingScript; 280 PendingScript pendingScript;
270 if (!requestPendingScript(pendingScript, element)) 281 if (!requestPendingScript(pendingScript, element))
271 return; 282 return;
272 283
273 ASSERT(pendingScript.resource()); 284 ASSERT(pendingScript.resource());
274 m_scriptsToExecuteAfterParsing.append(pendingScript); 285 m_scriptsToExecuteAfterParsing.append(pendingScript);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 323
313 InsertionPointRecord insertionPointRecord(m_host->inputStream()); 324 InsertionPointRecord insertionPointRecord(m_host->inputStream());
314 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); 325 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
315 326
316 scriptLoader->prepareScript(scriptStartPosition); 327 scriptLoader->prepareScript(scriptStartPosition);
317 328
318 if (!scriptLoader->willBeParserExecuted()) 329 if (!scriptLoader->willBeParserExecuted())
319 return; 330 return;
320 331
321 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { 332 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) {
333 // FIXME: in addition to parser blocking scripts, stream also
334 // scripts which are not parser blocking.
322 requestDeferredScript(script); 335 requestDeferredScript(script);
323 } else if (scriptLoader->readyToBeParserExecuted()) { 336 } else if (scriptLoader->readyToBeParserExecuted()) {
324 if (m_scriptNestingLevel == 1) { 337 if (m_scriptNestingLevel == 1) {
325 m_parserBlockingScript.setElement(script); 338 m_parserBlockingScript.setElement(script);
326 m_parserBlockingScript.setStartingPosition(scriptStartPosition); 339 m_parserBlockingScript.setStartingPosition(scriptStartPosition);
327 } else { 340 } else {
328 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); 341 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition);
329 scriptLoader->executeScript(sourceCode); 342 scriptLoader->executeScript(sourceCode);
330 } 343 }
331 } else { 344 } else {
332 requestParsingBlockingScript(script); 345 requestParsingBlockingScript(script);
333 } 346 }
334 } 347 }
335 } 348 }
336 349
337 void HTMLScriptRunner::trace(Visitor* visitor) 350 void HTMLScriptRunner::trace(Visitor* visitor)
338 { 351 {
339 visitor->trace(m_document); 352 visitor->trace(m_document);
340 visitor->trace(m_host); 353 visitor->trace(m_host);
341 visitor->trace(m_parserBlockingScript); 354 visitor->trace(m_parserBlockingScript);
342 visitor->trace(m_scriptsToExecuteAfterParsing); 355 visitor->trace(m_scriptsToExecuteAfterParsing);
343 } 356 }
344 357
345 } 358 }
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLScriptRunner.h ('k') | Source/core/xml/parser/XMLDocumentParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698