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 13 matching lines...) Expand all Loading... |
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 Loading... |
72 } | 73 } |
73 if (text_position.line_.ZeroBasedInt() > 0 || | 74 if (text_position.line_.ZeroBasedInt() > 0 || |
74 text_position.column_.ZeroBasedInt() > 0) { | 75 text_position.column_.ZeroBasedInt() > 0) { |
75 value->SetInteger("lineNumber", text_position.line_.OneBasedInt()); | 76 value->SetInteger("lineNumber", text_position.line_.OneBasedInt()); |
76 value->SetInteger("columnNumber", text_position.column_.OneBasedInt()); | 77 value->SetInteger("columnNumber", text_position.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& source_code, | 83 const Script* script, |
83 const TextPosition& text_position) { | 84 const TextPosition& text_position) { |
84 ScriptLoader* script_loader = element->Loader(); | 85 ScriptLoader* script_loader = element->Loader(); |
85 DCHECK(script_loader); | 86 DCHECK(script_loader); |
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, text_position)); | 89 GetTraceArgsForScriptElement(element, text_position)); |
89 return script_loader->ExecuteScript(source_code); | 90 return script_loader->ExecuteScript(script); |
90 } | 91 } |
91 | 92 |
92 void TraceParserBlockingScript(const PendingScript* pending_script, | 93 void TraceParserBlockingScript(const PendingScript* pending_script, |
93 bool waiting_for_resources) { | 94 bool waiting_for_resources) { |
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // steps of the "Otherwise" Clause of 'An end tag whose tag name is "script"' | 198 // steps of the "Otherwise" Clause of 'An end tag whose tag name is "script"' |
198 // https://html.spec.whatwg.org/#scriptEndTag | 199 // https://html.spec.whatwg.org/#scriptEndTag |
199 // - When called from executeScriptsWaitingForParsing(), this corresponds | 200 // - When called from executeScriptsWaitingForParsing(), this corresponds |
200 // https://html.spec.whatwg.org/#execute-the-script-block | 201 // https://html.spec.whatwg.org/#execute-the-script-block |
201 // and thus currently this function does more than specced. | 202 // and thus currently this function does more than specced. |
202 // TODO(hiroshige): Make the spec and implementation consistent. | 203 // TODO(hiroshige): Make the spec and implementation consistent. |
203 void HTMLParserScriptRunner::ExecutePendingScriptAndDispatchEvent( | 204 void HTMLParserScriptRunner::ExecutePendingScriptAndDispatchEvent( |
204 PendingScript* pending_script, | 205 PendingScript* pending_script, |
205 ScriptStreamer::Type pending_script_type) { | 206 ScriptStreamer::Type pending_script_type) { |
206 bool error_occurred = false; | 207 bool error_occurred = false; |
207 ScriptSourceCode source_code = pending_script->GetSource( | 208 Script* script = pending_script->GetSource( |
208 DocumentURLForScriptExecution(document_), error_occurred); | 209 DocumentURLForScriptExecution(document_), error_occurred); |
209 | 210 |
210 // Stop watching loads before executeScript to prevent recursion if the script | 211 // Stop watching loads before executeScript to prevent recursion if the script |
211 // reloads itself. | 212 // reloads itself. |
212 // TODO(kouhei): Consider merging this w/ pendingScript->dispose() after the | 213 // TODO(kouhei): Consider merging this w/ pendingScript->dispose() after the |
213 // if block. | 214 // if block. |
214 pending_script->StopWatchingForLoad(); | 215 pending_script->StopWatchingForLoad(); |
215 | 216 |
216 if (!IsExecutingScript()) { | 217 if (!IsExecutingScript()) { |
217 Microtask::PerformCheckpoint(V8PerIsolateData::MainThreadIsolate()); | 218 Microtask::PerformCheckpoint(V8PerIsolateData::MainThreadIsolate()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 GetTraceArgsForScriptElement(element, script_start_position)); | 257 GetTraceArgsForScriptElement(element, script_start_position)); |
257 script_loader->DispatchErrorEvent(); | 258 script_loader->DispatchErrorEvent(); |
258 } else { | 259 } else { |
259 DCHECK(IsExecutingScript()); | 260 DCHECK(IsExecutingScript()); |
260 if (script_parser_blocking_time > 0.0) { | 261 if (script_parser_blocking_time > 0.0) { |
261 DocumentParserTiming::From(*document_) | 262 DocumentParserTiming::From(*document_) |
262 .RecordParserBlockedOnScriptLoadDuration( | 263 .RecordParserBlockedOnScriptLoadDuration( |
263 MonotonicallyIncreasingTime() - script_parser_blocking_time, | 264 MonotonicallyIncreasingTime() - script_parser_blocking_time, |
264 script_loader->WasCreatedDuringDocumentWrite()); | 265 script_loader->WasCreatedDuringDocumentWrite()); |
265 } | 266 } |
266 if (!DoExecuteScript(element, source_code, script_start_position)) { | 267 if (!DoExecuteScript(element, script, script_start_position)) { |
267 script_loader->DispatchErrorEvent(); | 268 script_loader->DispatchErrorEvent(); |
268 } else { | 269 } else { |
269 element->DispatchLoadEvent(); | 270 element->DispatchLoadEvent(); |
270 } | 271 } |
271 } | 272 } |
272 | 273 |
273 // 9. "Decrement the parser's script nesting level by one. | 274 // 9. "Decrement the parser's script nesting level by one. |
274 // If the parser's script nesting level is zero | 275 // If the parser's script nesting level is zero |
275 // (which it always should be at this point), | 276 // (which it always should be at this point), |
276 // then set the parser pause flag to false." | 277 // then set the parser pause flag to false." |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 // "Immediately execute the script block, | 650 // "Immediately execute the script block, |
650 // even if other scripts are already executing." | 651 // even if other scripts are already executing." |
651 // TODO(hiroshige): Merge the block into ScriptLoader::prepareScript(). | 652 // TODO(hiroshige): Merge the block into ScriptLoader::prepareScript(). |
652 DCHECK_GT(reentry_permit_->ScriptNestingLevel(), 1u); | 653 DCHECK_GT(reentry_permit_->ScriptNestingLevel(), 1u); |
653 if (parser_blocking_script_) | 654 if (parser_blocking_script_) |
654 parser_blocking_script_->Dispose(); | 655 parser_blocking_script_->Dispose(); |
655 parser_blocking_script_ = nullptr; | 656 parser_blocking_script_ = nullptr; |
656 ScriptSourceCode source_code(script->textContent(), | 657 ScriptSourceCode source_code(script->textContent(), |
657 DocumentURLForScriptExecution(document_), | 658 DocumentURLForScriptExecution(document_), |
658 script_start_position); | 659 script_start_position); |
659 DoExecuteScript(element, source_code, script_start_position); | 660 DoExecuteScript(element, ClassicScript::Create(source_code), |
| 661 script_start_position); |
660 } | 662 } |
661 } else { | 663 } else { |
662 // 2nd Clause of Step 23. | 664 // 2nd Clause of Step 23. |
663 RequestParsingBlockingScript(script); | 665 RequestParsingBlockingScript(script); |
664 } | 666 } |
665 | 667 |
666 // "Decrement the parser's script nesting level by one. | 668 // "Decrement the parser's script nesting level by one. |
667 // If the parser's script nesting level is zero, then set the parser | 669 // If the parser's script nesting level is zero, then set the parser |
668 // pause flag to false." | 670 // pause flag to false." |
669 // Implemented by ~ScriptNestingLevelIncrementer(). | 671 // Implemented by ~ScriptNestingLevelIncrementer(). |
670 | 672 |
671 // "Let the insertion point have the value of the old insertion point." | 673 // "Let the insertion point have the value of the old insertion point." |
672 // Implemented by ~InsertionPointRecord(). | 674 // Implemented by ~InsertionPointRecord(). |
673 } | 675 } |
674 } | 676 } |
675 | 677 |
676 DEFINE_TRACE(HTMLParserScriptRunner) { | 678 DEFINE_TRACE(HTMLParserScriptRunner) { |
677 visitor->Trace(document_); | 679 visitor->Trace(document_); |
678 visitor->Trace(host_); | 680 visitor->Trace(host_); |
679 visitor->Trace(parser_blocking_script_); | 681 visitor->Trace(parser_blocking_script_); |
680 visitor->Trace(scripts_to_execute_after_parsing_); | 682 visitor->Trace(scripts_to_execute_after_parsing_); |
681 PendingScriptClient::Trace(visitor); | 683 PendingScriptClient::Trace(visitor); |
682 } | 684 } |
683 | 685 |
684 } // namespace blink | 686 } // namespace blink |
OLD | NEW |