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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp

Issue 2780463002: Introduce blink::Script (Closed)
Patch Set: style Created 3 years, 8 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
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 13 matching lines...) Expand all
24 */ 24 */
25 25
26 #include "core/html/parser/HTMLParserScriptRunner.h" 26 #include "core/html/parser/HTMLParserScriptRunner.h"
27 27
28 #include <inttypes.h> 28 #include <inttypes.h>
29 #include <memory> 29 #include <memory>
30 #include "bindings/core/v8/Microtask.h" 30 #include "bindings/core/v8/Microtask.h"
31 #include "bindings/core/v8/ScriptSourceCode.h" 31 #include "bindings/core/v8/ScriptSourceCode.h"
32 #include "bindings/core/v8/V8Binding.h" 32 #include "bindings/core/v8/V8Binding.h"
33 #include "bindings/core/v8/V8PerIsolateData.h" 33 #include "bindings/core/v8/V8PerIsolateData.h"
34 #include "core/dom/ClassicScript.h"
34 #include "core/dom/DocumentParserTiming.h" 35 #include "core/dom/DocumentParserTiming.h"
35 #include "core/dom/Element.h" 36 #include "core/dom/Element.h"
36 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" 37 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h"
37 #include "core/dom/ScriptLoader.h" 38 #include "core/dom/ScriptLoader.h"
38 #include "core/dom/TaskRunnerHelper.h" 39 #include "core/dom/TaskRunnerHelper.h"
39 #include "core/events/Event.h" 40 #include "core/events/Event.h"
40 #include "core/frame/LocalFrame.h" 41 #include "core/frame/LocalFrame.h"
41 #include "core/html/parser/HTMLInputStream.h" 42 #include "core/html/parser/HTMLInputStream.h"
42 #include "core/html/parser/HTMLParserScriptRunnerHost.h" 43 #include "core/html/parser/HTMLParserScriptRunnerHost.h"
43 #include "core/html/parser/NestingLevelIncrementer.h" 44 #include "core/html/parser/NestingLevelIncrementer.h"
(...skipping 28 matching lines...) Expand all
72 } 73 }
73 if (textPosition.m_line.zeroBasedInt() > 0 || 74 if (textPosition.m_line.zeroBasedInt() > 0 ||
74 textPosition.m_column.zeroBasedInt() > 0) { 75 textPosition.m_column.zeroBasedInt() > 0) {
75 value->setInteger("lineNumber", textPosition.m_line.oneBasedInt()); 76 value->setInteger("lineNumber", textPosition.m_line.oneBasedInt());
76 value->setInteger("columnNumber", textPosition.m_column.oneBasedInt()); 77 value->setInteger("columnNumber", textPosition.m_column.oneBasedInt());
77 } 78 }
78 return value; 79 return value;
79 } 80 }
80 81
81 bool doExecuteScript(ScriptElementBase* element, 82 bool doExecuteScript(ScriptElementBase* element,
82 const ScriptSourceCode& sourceCode, 83 const Script* script,
83 const TextPosition& textPosition) { 84 const TextPosition& textPosition) {
84 ScriptLoader* scriptLoader = element->loader(); 85 ScriptLoader* scriptLoader = element->loader();
85 DCHECK(scriptLoader); 86 DCHECK(scriptLoader);
86 TRACE_EVENT_WITH_FLOW1("blink", "HTMLParserScriptRunner ExecuteScript", 87 TRACE_EVENT_WITH_FLOW1("blink", "HTMLParserScriptRunner ExecuteScript",
87 element, TRACE_EVENT_FLAG_FLOW_IN, "data", 88 element, TRACE_EVENT_FLAG_FLOW_IN, "data",
88 getTraceArgsForScriptElement(element, textPosition)); 89 getTraceArgsForScriptElement(element, textPosition));
89 return scriptLoader->executeScript(sourceCode); 90 return scriptLoader->executeScript(script);
90 } 91 }
91 92
92 void traceParserBlockingScript(const PendingScript* pendingScript, 93 void traceParserBlockingScript(const PendingScript* pendingScript,
93 bool waitingForResources) { 94 bool waitingForResources) {
94 // The HTML parser must yield before executing script in the following 95 // The HTML parser must yield before executing script in the following
95 // cases: 96 // cases:
96 // * the script's execution is blocked on the completed load of the script 97 // * the script's execution is blocked on the completed load of the script
97 // resource 98 // resource
98 // (https://html.spec.whatwg.org/multipage/scripting.html#pending-parsing-bl ocking-script) 99 // (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 100 // * the script's execution is blocked on the load of a style sheet or other
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // steps of the "Otherwise" Clause of 'An end tag whose tag name is "script"' 197 // steps of the "Otherwise" Clause of 'An end tag whose tag name is "script"'
197 // https://html.spec.whatwg.org/#scriptEndTag 198 // https://html.spec.whatwg.org/#scriptEndTag
198 // - When called from executeScriptsWaitingForParsing(), this corresponds 199 // - When called from executeScriptsWaitingForParsing(), this corresponds
199 // https://html.spec.whatwg.org/#execute-the-script-block 200 // https://html.spec.whatwg.org/#execute-the-script-block
200 // and thus currently this function does more than specced. 201 // and thus currently this function does more than specced.
201 // TODO(hiroshige): Make the spec and implementation consistent. 202 // TODO(hiroshige): Make the spec and implementation consistent.
202 void HTMLParserScriptRunner::executePendingScriptAndDispatchEvent( 203 void HTMLParserScriptRunner::executePendingScriptAndDispatchEvent(
203 PendingScript* pendingScript, 204 PendingScript* pendingScript,
204 ScriptStreamer::Type pendingScriptType) { 205 ScriptStreamer::Type pendingScriptType) {
205 bool errorOccurred = false; 206 bool errorOccurred = false;
206 ScriptSourceCode sourceCode = pendingScript->getSource( 207 Script* script = pendingScript->getSource(
207 documentURLForScriptExecution(m_document), errorOccurred); 208 documentURLForScriptExecution(m_document), errorOccurred);
208 209
209 // Stop watching loads before executeScript to prevent recursion if the script 210 // Stop watching loads before executeScript to prevent recursion if the script
210 // reloads itself. 211 // reloads itself.
211 // TODO(kouhei): Consider merging this w/ pendingScript->dispose() after the 212 // TODO(kouhei): Consider merging this w/ pendingScript->dispose() after the
212 // if block. 213 // if block.
213 pendingScript->stopWatchingForLoad(); 214 pendingScript->stopWatchingForLoad();
214 215
215 if (!isExecutingScript()) { 216 if (!isExecutingScript()) {
216 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate()); 217 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 getTraceArgsForScriptElement(element, scriptStartPosition)); 256 getTraceArgsForScriptElement(element, scriptStartPosition));
256 scriptLoader->dispatchErrorEvent(); 257 scriptLoader->dispatchErrorEvent();
257 } else { 258 } else {
258 DCHECK(isExecutingScript()); 259 DCHECK(isExecutingScript());
259 if (scriptParserBlockingTime > 0.0) { 260 if (scriptParserBlockingTime > 0.0) {
260 DocumentParserTiming::from(*m_document) 261 DocumentParserTiming::from(*m_document)
261 .recordParserBlockedOnScriptLoadDuration( 262 .recordParserBlockedOnScriptLoadDuration(
262 monotonicallyIncreasingTime() - scriptParserBlockingTime, 263 monotonicallyIncreasingTime() - scriptParserBlockingTime,
263 scriptLoader->wasCreatedDuringDocumentWrite()); 264 scriptLoader->wasCreatedDuringDocumentWrite());
264 } 265 }
265 if (!doExecuteScript(element, sourceCode, scriptStartPosition)) { 266 if (!doExecuteScript(element, script, scriptStartPosition)) {
266 scriptLoader->dispatchErrorEvent(); 267 scriptLoader->dispatchErrorEvent();
267 } else { 268 } else {
268 element->dispatchLoadEvent(); 269 element->dispatchLoadEvent();
269 } 270 }
270 } 271 }
271 272
272 // 9. "Decrement the parser's script nesting level by one. 273 // 9. "Decrement the parser's script nesting level by one.
273 // If the parser's script nesting level is zero 274 // If the parser's script nesting level is zero
274 // (which it always should be at this point), 275 // (which it always should be at this point),
275 // then set the parser pause flag to false." 276 // then set the parser pause flag to false."
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 // "Immediately execute the script block, 666 // "Immediately execute the script block,
666 // even if other scripts are already executing." 667 // even if other scripts are already executing."
667 // TODO(hiroshige): Merge the block into ScriptLoader::prepareScript(). 668 // TODO(hiroshige): Merge the block into ScriptLoader::prepareScript().
668 DCHECK_GT(m_reentryPermit->scriptNestingLevel(), 1u); 669 DCHECK_GT(m_reentryPermit->scriptNestingLevel(), 1u);
669 if (m_parserBlockingScript) 670 if (m_parserBlockingScript)
670 m_parserBlockingScript->dispose(); 671 m_parserBlockingScript->dispose();
671 m_parserBlockingScript = nullptr; 672 m_parserBlockingScript = nullptr;
672 ScriptSourceCode sourceCode(script->textContent(), 673 ScriptSourceCode sourceCode(script->textContent(),
673 documentURLForScriptExecution(m_document), 674 documentURLForScriptExecution(m_document),
674 scriptStartPosition); 675 scriptStartPosition);
675 doExecuteScript(element, sourceCode, scriptStartPosition); 676 doExecuteScript(element, ClassicScript::create(sourceCode),
677 scriptStartPosition);
676 } 678 }
677 } else { 679 } else {
678 // 2nd Clause of Step 23. 680 // 2nd Clause of Step 23.
679 requestParsingBlockingScript(script); 681 requestParsingBlockingScript(script);
680 } 682 }
681 683
682 // "Decrement the parser's script nesting level by one. 684 // "Decrement the parser's script nesting level by one.
683 // If the parser's script nesting level is zero, then set the parser 685 // If the parser's script nesting level is zero, then set the parser
684 // pause flag to false." 686 // pause flag to false."
685 // Implemented by ~ScriptNestingLevelIncrementer(). 687 // Implemented by ~ScriptNestingLevelIncrementer().
686 688
687 // "Let the insertion point have the value of the old insertion point." 689 // "Let the insertion point have the value of the old insertion point."
688 // Implemented by ~InsertionPointRecord(). 690 // Implemented by ~InsertionPointRecord().
689 } 691 }
690 } 692 }
691 693
692 DEFINE_TRACE(HTMLParserScriptRunner) { 694 DEFINE_TRACE(HTMLParserScriptRunner) {
693 visitor->trace(m_document); 695 visitor->trace(m_document);
694 visitor->trace(m_host); 696 visitor->trace(m_host);
695 visitor->trace(m_parserBlockingScript); 697 visitor->trace(m_parserBlockingScript);
696 visitor->trace(m_scriptsToExecuteAfterParsing); 698 visitor->trace(m_scriptsToExecuteAfterParsing);
697 PendingScriptClient::trace(visitor); 699 PendingScriptClient::trace(visitor);
698 } 700 }
699 701
700 } // namespace blink 702 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698