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

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptLoader.cpp

Issue 2874343003: Make the clauses of Step 23 of ScriptLoader::PrepareScript() in-order (Closed)
Patch Set: refine Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights
6 * reserved. 6 * reserved.
7 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 7 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 element_->HasSourceAttribute() && parser_inserted_ && 562 element_->HasSourceAttribute() && parser_inserted_ &&
563 !element_->AsyncAttributeValue()) { 563 !element_->AsyncAttributeValue()) {
564 // This clause is implemented by the caller-side of prepareScript(): 564 // This clause is implemented by the caller-side of prepareScript():
565 // - HTMLParserScriptRunner::requestParsingBlockingScript() 565 // - HTMLParserScriptRunner::requestParsingBlockingScript()
566 // - TODO(hiroshige): Investigate XMLDocumentParser::endElementNs() 566 // - TODO(hiroshige): Investigate XMLDocumentParser::endElementNs()
567 will_be_parser_executed_ = true; 567 will_be_parser_executed_ = true;
568 568
569 return true; 569 return true;
570 } 570 }
571 571
572 // 5th Clause:
573 // TODO(hiroshige): Reorder the clauses to match the spec.
574 // - "If the element does not have a src attribute,
575 // and the element has been flagged as "parser-inserted",
576 // and either the parser that created the script is an XML parser
577 // or it's an HTML parser whose script nesting level is not greater than
578 // one,
579 // and the Document of the HTML parser or XML parser that created
580 // the script element has a style sheet that is blocking scripts"
581 // The last part "... has a style sheet that is blocking scripts"
582 // is implemented in Document::isScriptExecutionReady().
583 // Part of the condition check is done in
584 // HTMLParserScriptRunner::processScriptElementInternal().
585 // TODO(hiroshige): Clean up the split condition check.
586 // We check that the type is "classic" here, because according to the spec
587 // a "module" script doesn't reach the 5th Clause because the 4th Clause
588 // catches all "module" scripts.
589 if (GetScriptType() == ScriptType::kClassic &&
590 !element_->HasSourceAttribute() && parser_inserted_ &&
591 !element_document.IsScriptExecutionReady()) {
592 // The former part of this clause is
593 // implemented by the caller-side of prepareScript():
594 // - HTMLParserScriptRunner::requestParsingBlockingScript()
595 // - TODO(hiroshige): Investigate XMLDocumentParser::endElementNs()
596 will_be_parser_executed_ = true;
597 // "Set the element's "ready to be parser-executed" flag."
598 ready_to_be_parser_executed_ = true;
599
600 return true;
601 }
602
603 // 3rd Clause: 572 // 3rd Clause:
604 // - "If the script's type is "classic", 573 // - "If the script's type is "classic",
605 // and the element has a src attribute, 574 // and the element has a src attribute,
606 // and the element does not have an async attribute, 575 // and the element does not have an async attribute,
607 // and the element does not have the "non-blocking" flag set" 576 // and the element does not have the "non-blocking" flag set"
608 // - "If the script's type is "module", 577 // - "If the script's type is "module",
609 // and the element does not have an async attribute, 578 // and the element does not have an async attribute,
610 // and the element does not have the "non-blocking" flag set" 579 // and the element does not have the "non-blocking" flag set"
611 // TODO(hiroshige): Check the script's type and implement "module" case.
612 if ((GetScriptType() == ScriptType::kClassic && 580 if ((GetScriptType() == ScriptType::kClassic &&
613 element_->HasSourceAttribute() && !element_->AsyncAttributeValue() && 581 element_->HasSourceAttribute() && !element_->AsyncAttributeValue() &&
614 !non_blocking_) || 582 !non_blocking_) ||
615 (GetScriptType() == ScriptType::kModule && 583 (GetScriptType() == ScriptType::kModule &&
616 !element_->AsyncAttributeValue() && !non_blocking_)) { 584 !element_->AsyncAttributeValue() && !non_blocking_)) {
617 // "Add the element to the end of the list of scripts that will execute 585 // "Add the element to the end of the list of scripts that will execute
618 // in order as soon as possible associated with the node document of the 586 // in order as soon as possible associated with the node document of the
619 // script element at the time the prepare a script algorithm started." 587 // script element at the time the prepare a script algorithm started."
620 pending_script_ = CreatePendingScript(); 588 pending_script_ = CreatePendingScript();
621 async_exec_type_ = ScriptRunner::kInOrder; 589 async_exec_type_ = ScriptRunner::kInOrder;
(...skipping 29 matching lines...) Expand all
651 this, async_exec_type_); 619 this, async_exec_type_);
652 // Note that watchForLoad can immediately call pendingScriptFinished. 620 // Note that watchForLoad can immediately call pendingScriptFinished.
653 pending_script_->WatchForLoad(this); 621 pending_script_->WatchForLoad(this);
654 // The part "When the script is ready..." is implemented in 622 // The part "When the script is ready..." is implemented in
655 // ScriptRunner::notifyScriptReady(). 623 // ScriptRunner::notifyScriptReady().
656 // TODO(hiroshige): Annotate it. 624 // TODO(hiroshige): Annotate it.
657 625
658 return true; 626 return true;
659 } 627 }
660 628
629 // The following clauses are executed only if the script's type is "classic"
630 // and the element doesn't have a src attribute.
631 DCHECK_EQ(GetScriptType(), ScriptType::kClassic);
632 DCHECK(!is_external_script_);
633
634 // 5th Clause:
635 // - "If the element does not have a src attribute,
636 // and the element has been flagged as "parser-inserted",
637 // and either the parser that created the script is an XML parser
638 // or it's an HTML parser whose script nesting level is not greater than
639 // one,
640 // and the Document of the HTML parser or XML parser that created
641 // the script element has a style sheet that is blocking scripts"
642 // The last part "... has a style sheet that is blocking scripts"
643 // is implemented in Document::isScriptExecutionReady().
644 // Part of the condition check is done in
645 // HTMLParserScriptRunner::processScriptElementInternal().
646 // TODO(hiroshige): Clean up the split condition check.
647 if (!element_->HasSourceAttribute() && parser_inserted_ &&
648 !element_document.IsScriptExecutionReady()) {
649 // The former part of this clause is
650 // implemented by the caller-side of prepareScript():
651 // - HTMLParserScriptRunner::requestParsingBlockingScript()
652 // - TODO(hiroshige): Investigate XMLDocumentParser::endElementNs()
653 will_be_parser_executed_ = true;
654 // "Set the element's "ready to be parser-executed" flag."
655 ready_to_be_parser_executed_ = true;
656
657 return true;
658 }
659
661 // 6th Clause: 660 // 6th Clause:
662 // - "Otherwise" 661 // - "Otherwise"
663 // "Immediately execute the script block, 662 // "Immediately execute the script block,
664 // even if other scripts are already executing." 663 // even if other scripts are already executing."
665 // Note: this block is also duplicated in 664 // Note: this block is also duplicated in
666 // HTMLParserScriptRunner::processScriptElementInternal(). 665 // HTMLParserScriptRunner::processScriptElementInternal().
667 // TODO(hiroshige): Merge the duplicated code. 666 // TODO(hiroshige): Merge the duplicated code.
668 667
669 // This clause is executed only if the script's type is "classic"
670 // and the element doesn't have a src attribute.
671 DCHECK_EQ(GetScriptType(), ScriptType::kClassic);
672 DCHECK(!is_external_script_);
673
674 // Reset line numbering for nested writes. 668 // Reset line numbering for nested writes.
675 TextPosition position = element_document.IsInDocumentWrite() 669 TextPosition position = element_document.IsInDocumentWrite()
676 ? TextPosition() 670 ? TextPosition()
677 : script_start_position; 671 : script_start_position;
678 KURL script_url = (!element_document.IsInDocumentWrite() && parser_inserted_) 672 KURL script_url = (!element_document.IsInDocumentWrite() && parser_inserted_)
679 ? element_document.Url() 673 ? element_document.Url()
680 : KURL(); 674 : KURL();
681 675
682 if (!ExecuteScript(ClassicScript::Create( 676 if (!ExecuteScript(ClassicScript::Create(
683 ScriptSourceCode(ScriptContent(), script_url, position)))) { 677 ScriptSourceCode(ScriptContent(), script_url, position)))) {
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 // then abort these steps at this point. The script is not executed. 981 // then abort these steps at this point. The script is not executed.
988 return DeprecatedEqualIgnoringCase(event_attribute, "onload") || 982 return DeprecatedEqualIgnoringCase(event_attribute, "onload") ||
989 DeprecatedEqualIgnoringCase(event_attribute, "onload()"); 983 DeprecatedEqualIgnoringCase(event_attribute, "onload()");
990 } 984 }
991 985
992 String ScriptLoader::ScriptContent() const { 986 String ScriptLoader::ScriptContent() const {
993 return element_->TextFromChildren(); 987 return element_->TextFromChildren();
994 } 988 }
995 989
996 } // namespace blink 990 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698