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

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

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: rebased 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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 // 2nd Clause, Step 23 of https://html.spec.whatwg.org/#prepare-a-script 540 // 2nd Clause, Step 23 of https://html.spec.whatwg.org/#prepare-a-script
541 void HTMLParserScriptRunner::requestParsingBlockingScript(Element* element) { 541 void HTMLParserScriptRunner::requestParsingBlockingScript(Element* element) {
542 // "The element is the pending parsing-blocking script of the Document of 542 // "The element is the pending parsing-blocking script of the Document of
543 // the parser that created the element. 543 // the parser that created the element.
544 // (There can only be one such script per Document at a time.)" 544 // (There can only be one such script per Document at a time.)"
545 CHECK(!parserBlockingScript()); 545 CHECK(!parserBlockingScript());
546 m_parserBlockingScript = requestPendingScript(element); 546 m_parserBlockingScript = requestPendingScript(element);
547 if (!parserBlockingScript()) 547 if (!parserBlockingScript())
548 return; 548 return;
549 549
550 DCHECK(parserBlockingScript()->resource()); 550 // DCHECK(parserBlockingScript()->resource());
551 551
552 // We only care about a load callback if resource is not already in the cache. 552 // We only care about a load callback if resource is not already in the cache.
553 // Callers will attempt to run the m_parserBlockingScript if possible before 553 // Callers will attempt to run the m_parserBlockingScript if possible before
554 // returning control to the parser. 554 // returning control to the parser.
555 if (!parserBlockingScript()->isReady()) { 555 if (!parserBlockingScript()->isReady()) {
556 if (m_document->frame()) { 556 if (m_document->frame()) {
557 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame()); 557 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame());
558 if (scriptState) { 558 if (scriptState) {
559 ScriptStreamer::startStreaming( 559 ScriptStreamer::startStreaming(
560 m_parserBlockingScript, ScriptStreamer::ParsingBlocking, 560 m_parserBlockingScript, ScriptStreamer::ParsingBlocking,
(...skipping 15 matching lines...) Expand all
576 if (m_document->frame() && !pendingScript->isReady()) { 576 if (m_document->frame() && !pendingScript->isReady()) {
577 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame()); 577 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame());
578 if (scriptState) { 578 if (scriptState) {
579 ScriptStreamer::startStreaming( 579 ScriptStreamer::startStreaming(
580 pendingScript, ScriptStreamer::Deferred, 580 pendingScript, ScriptStreamer::Deferred,
581 m_document->frame()->settings(), scriptState, 581 m_document->frame()->settings(), scriptState,
582 TaskRunnerHelper::get(TaskType::Networking, m_document)); 582 TaskRunnerHelper::get(TaskType::Networking, m_document));
583 } 583 }
584 } 584 }
585 585
586 DCHECK(pendingScript->resource()); 586 // DCHECK(pendingScript->resource());
587 587
588 // "Add the element to the end of the list of scripts that will execute 588 // "Add the element to the end of the list of scripts that will execute
589 // when the document has finished parsing associated with the Document 589 // when the document has finished parsing associated with the Document
590 // of the parser that created the element." 590 // of the parser that created the element."
591 m_scriptsToExecuteAfterParsing.push_back(pendingScript); 591 m_scriptsToExecuteAfterParsing.push_back(pendingScript);
592 } 592 }
593 593
594 PendingScript* HTMLParserScriptRunner::requestPendingScript( 594 PendingScript* HTMLParserScriptRunner::requestPendingScript(
595 Element* element) const { 595 Element* element) const {
596 ScriptElementBase* scriptElement = 596 ScriptElementBase* scriptElement =
597 ScriptElementBase::fromElementIfPossible(element); 597 ScriptElementBase::fromElementIfPossible(element);
598 ScriptResource* resource = scriptElement->loader()->resource(); 598 ScriptResource* resource = scriptElement->loader()->resource();
599 // Here |resource| should be non-null. If it were nullptr, 599 // Here |resource| should be non-null. If it were nullptr,
600 // ScriptLoader::fetchScript() should have returned false and 600 // ScriptLoader::fetchScript() should have returned false and
601 // thus the control shouldn't have reached here. 601 // thus the control shouldn't have reached here.
602 CHECK(resource); 602 // CHECK(resource);
603 return PendingScript::create(scriptElement, resource); 603 return PendingScript::create(scriptElement, resource);
604 } 604 }
605 605
606 // The initial steps for 'An end tag whose tag name is "script"' 606 // The initial steps for 'An end tag whose tag name is "script"'
607 // https://html.spec.whatwg.org/#scriptEndTag 607 // https://html.spec.whatwg.org/#scriptEndTag
608 void HTMLParserScriptRunner::processScriptElementInternal( 608 void HTMLParserScriptRunner::processScriptElementInternal(
609 Element* script, 609 Element* script,
610 const TextPosition& scriptStartPosition) { 610 const TextPosition& scriptStartPosition) {
611 DCHECK(m_document); 611 DCHECK(m_document);
612 DCHECK(!hasParserBlockingScript()); 612 DCHECK(!hasParserBlockingScript());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 690
691 DEFINE_TRACE(HTMLParserScriptRunner) { 691 DEFINE_TRACE(HTMLParserScriptRunner) {
692 visitor->trace(m_document); 692 visitor->trace(m_document);
693 visitor->trace(m_host); 693 visitor->trace(m_host);
694 visitor->trace(m_parserBlockingScript); 694 visitor->trace(m_parserBlockingScript);
695 visitor->trace(m_scriptsToExecuteAfterParsing); 695 visitor->trace(m_scriptsToExecuteAfterParsing);
696 PendingScriptClient::trace(visitor); 696 PendingScriptClient::trace(visitor);
697 } 697 }
698 698
699 } // namespace blink 699 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698