Changeset 64674 in webkit


Ignore:
Timestamp:
Aug 4, 2010 1:39:24 PM (14 years ago)
Author:
tonyg@chromium.org
Message:

2010-08-04 Tony Gentilcore <tonyg@chromium.org>

Reviewed by Eric Seidel.

LayoutTests for <script defer> as specified by HTML5
https://bugs.webkit.org/show_bug.cgi?id=40934

  • fast/dom/HTMLScriptElement/defer-double-defer-write-expected.txt: Added.
  • fast/dom/HTMLScriptElement/defer-double-defer-write.html: Added. Tests for tricky ordering and reentrancy by doing a double write of defered scripts.
  • fast/dom/HTMLScriptElement/defer-double-write-expected.txt: Copied from LayoutTests/fast/tokenizer/write-before-load-expected.txt.
  • fast/dom/HTMLScriptElement/defer-double-write.html: Added. Tests for tricky ordering and reentrancy by doing a double write of inline scripts.
  • fast/dom/HTMLScriptElement/defer-inline-script-expected.txt: Added.
  • fast/dom/HTMLScriptElement/defer-inline-script.html: Added. Tests that the defer attribute is ignored on inline script blocks.
  • fast/dom/HTMLScriptElement/defer-onbeforeload-expected.txt: Added.
  • fast/dom/HTMLScriptElement/defer-onbeforeload.html: Added. Tests that onbeforeload fires immediately when a deferred script is encounted. Also tests that it can be cancelled.
  • fast/dom/HTMLScriptElement/defer-script-invalid-url-expected.txt: Added.
  • fast/dom/HTMLScriptElement/defer-script-invalid-url.html: Added. Tests that invalid URLs are ignored and subsequent scripts are still executed.
  • fast/dom/HTMLScriptElement/resources/defer.js: Added.
  • fast/dom/HTMLScriptElement/resources/external.js: Added.
  • fast/dom/HTMLScriptElement/resources/shouldnotexecute.js: Added.
  • http/tests/misc/resources/defer-script.js: Added.
  • http/tests/misc/resources/external-script.js: Added.
  • http/tests/misc/resources/script-debug-body-background.js: Added.
  • http/tests/misc/resources/script-write-slow-stylesheet.js: Added.
  • http/tests/misc/resources/slow-defer-script.cgi: Added.
  • http/tests/misc/resources/slow-stylesheet.cgi: Added.
  • http/tests/misc/script-defer-after-slow-stylesheet-expected.txt: Added.
  • http/tests/misc/script-defer-after-slow-stylesheet.html: Added. Tests stylesheet blocking behavior.
  • http/tests/misc/script-defer-expected.txt: Added.
  • http/tests/misc/script-defer-write-slow-stylesheet-expected.txt: Added.
  • http/tests/misc/script-defer-write-slow-stylesheet.html: Added. Tests stylesheet blocking behavior with a slow stylesheet.
  • http/tests/misc/script-defer.html: Added. Tests basic functionality and ordering.

2010-08-04 Tony Gentilcore <tonyg@chromium.org>

Reviewed by Eric Seidel.

Support <script defer> as specified by HTML5
https://bugs.webkit.org/show_bug.cgi?id=40934

See: http://dev.w3.org/html5/spec/Overview.html#the-end

Tests: fast/dom/HTMLScriptElement/defer-double-defer-write.html

fast/dom/HTMLScriptElement/defer-double-write.html
fast/dom/HTMLScriptElement/defer-inline-script.html
fast/dom/HTMLScriptElement/defer-onbeforeload.html
fast/dom/HTMLScriptElement/defer-script-invalid-url.html
http/tests/misc/script-defer-after-slow-stylesheet.html
http/tests/misc/script-defer-write-slow-stylesheet.html
http/tests/misc/script-defer.html

  • html/HTMLDocumentParser.cpp: (WebCore::HTMLDocumentParser::attemptToEnd): (WebCore::HTMLDocumentParser::endIfDelayed): (WebCore::HTMLDocumentParser::executeScriptsWaitingForParsingAndEnd):
  • html/HTMLDocumentParser.h:
  • html/HTMLScriptRunner.cpp: (WebCore::HTMLScriptRunner::executeScriptsWaitingForParsing): (WebCore::HTMLScriptRunner::requestScript): (WebCore::HTMLScriptRunner::requestParsingBlockingScript): (WebCore::HTMLScriptRunner::requestDeferredScript): (WebCore::HTMLScriptRunner::runScript):
  • html/HTMLScriptRunner.h: (WebCore::HTMLScriptRunner::PendingScript::PendingScript): (WebCore::HTMLScriptRunner::PendingScript::operator=):
Location:
trunk
Files:
25 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r64668 r64674  
     12010-08-04  Tony Gentilcore  <tonyg@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        LayoutTests for <script defer> as specified by HTML5
     6        https://bugs.webkit.org/show_bug.cgi?id=40934
     7
     8        * fast/dom/HTMLScriptElement/defer-double-defer-write-expected.txt: Added.
     9        * fast/dom/HTMLScriptElement/defer-double-defer-write.html: Added. Tests for tricky ordering and reentrancy by doing a double write of defered scripts.
     10        * fast/dom/HTMLScriptElement/defer-double-write-expected.txt: Copied from LayoutTests/fast/tokenizer/write-before-load-expected.txt.
     11        * fast/dom/HTMLScriptElement/defer-double-write.html: Added. Tests for tricky ordering and reentrancy by doing a double write of inline scripts.
     12        * fast/dom/HTMLScriptElement/defer-inline-script-expected.txt: Added.
     13        * fast/dom/HTMLScriptElement/defer-inline-script.html: Added. Tests that the defer attribute is ignored on inline script blocks.
     14        * fast/dom/HTMLScriptElement/defer-onbeforeload-expected.txt: Added.
     15        * fast/dom/HTMLScriptElement/defer-onbeforeload.html: Added. Tests that onbeforeload fires immediately when a deferred script is encounted. Also tests that it can be cancelled.
     16        * fast/dom/HTMLScriptElement/defer-script-invalid-url-expected.txt: Added.
     17        * fast/dom/HTMLScriptElement/defer-script-invalid-url.html: Added. Tests that invalid URLs are ignored and subsequent scripts are still executed.
     18        * fast/dom/HTMLScriptElement/resources/defer.js: Added.
     19        * fast/dom/HTMLScriptElement/resources/external.js: Added.
     20        * fast/dom/HTMLScriptElement/resources/shouldnotexecute.js: Added.
     21        * http/tests/misc/resources/defer-script.js: Added.
     22        * http/tests/misc/resources/external-script.js: Added.
     23        * http/tests/misc/resources/script-debug-body-background.js: Added.
     24        * http/tests/misc/resources/script-write-slow-stylesheet.js: Added.
     25        * http/tests/misc/resources/slow-defer-script.cgi: Added.
     26        * http/tests/misc/resources/slow-stylesheet.cgi: Added.
     27        * http/tests/misc/script-defer-after-slow-stylesheet-expected.txt: Added.
     28        * http/tests/misc/script-defer-after-slow-stylesheet.html: Added. Tests stylesheet blocking behavior.
     29        * http/tests/misc/script-defer-expected.txt: Added.
     30        * http/tests/misc/script-defer-write-slow-stylesheet-expected.txt: Added.
     31        * http/tests/misc/script-defer-write-slow-stylesheet.html: Added. Tests stylesheet blocking behavior with a slow stylesheet.
     32        * http/tests/misc/script-defer.html: Added. Tests basic functionality and ordering.
     33
    1342010-08-04  François Sausset  <sausset@gmail.com>
    235
  • trunk/WebCore/ChangeLog

    r64672 r64674  
     12010-08-04  Tony Gentilcore  <tonyg@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Support <script defer> as specified by HTML5
     6        https://bugs.webkit.org/show_bug.cgi?id=40934
     7
     8        See: http://dev.w3.org/html5/spec/Overview.html#the-end
     9
     10        Tests: fast/dom/HTMLScriptElement/defer-double-defer-write.html
     11               fast/dom/HTMLScriptElement/defer-double-write.html
     12               fast/dom/HTMLScriptElement/defer-inline-script.html
     13               fast/dom/HTMLScriptElement/defer-onbeforeload.html
     14               fast/dom/HTMLScriptElement/defer-script-invalid-url.html
     15               http/tests/misc/script-defer-after-slow-stylesheet.html
     16               http/tests/misc/script-defer-write-slow-stylesheet.html
     17               http/tests/misc/script-defer.html
     18
     19        * html/HTMLDocumentParser.cpp:
     20        (WebCore::HTMLDocumentParser::attemptToEnd):
     21        (WebCore::HTMLDocumentParser::endIfDelayed):
     22        (WebCore::HTMLDocumentParser::executeScriptsWaitingForParsingAndEnd):
     23        * html/HTMLDocumentParser.h:
     24        * html/HTMLScriptRunner.cpp:
     25        (WebCore::HTMLScriptRunner::executeScriptsWaitingForParsing):
     26        (WebCore::HTMLScriptRunner::requestScript):
     27        (WebCore::HTMLScriptRunner::requestParsingBlockingScript):
     28        (WebCore::HTMLScriptRunner::requestDeferredScript):
     29        (WebCore::HTMLScriptRunner::runScript):
     30        * html/HTMLScriptRunner.h:
     31        (WebCore::HTMLScriptRunner::PendingScript::PendingScript):
     32        (WebCore::HTMLScriptRunner::PendingScript::operator=):
     33
    1342010-08-04  Kevin Ollivier  <kevino@theolliviers.com>
    235
  • trunk/WebCore/html/HTMLDocumentParser.cpp

    r64638 r64674  
    282282        return;
    283283    }
    284     end();
     284    executeScriptsWaitingForParsingAndEnd();
    285285}
    286286
     
    291291
    292292    m_endWasDelayed = false;
     293    executeScriptsWaitingForParsingAndEnd();
     294}
     295
     296void HTMLDocumentParser::executeScriptsWaitingForParsingAndEnd()
     297{
     298    if (m_scriptRunner) {
     299        bool continueParsing = m_scriptRunner->executeScriptsWaitingForParsing();
     300        if (!continueParsing) {
     301            m_treeBuilder->setPaused(true);
     302            m_endWasDelayed = true;
     303            return;
     304        }
     305    }
    293306    end();
    294307}
  • trunk/WebCore/html/HTMLDocumentParser.h

    r63998 r64674  
    106106    void attemptToEnd();
    107107    void endIfDelayed();
     108    void executeScriptsWaitingForParsingAndEnd();
    108109    void end();
    109110
  • trunk/WebCore/html/HTMLScriptRunner.cpp

    r63998 r64674  
    229229}
    230230
    231 void HTMLScriptRunner::requestScript(Element* script)
    232 {
    233     ASSERT(!m_parsingBlockingScript.element);
    234     AtomicString srcValue = script->getAttribute(srcAttr);
    235     // Allow the host to disllow script loads (using the XSSAuditor, etc.)
     231bool HTMLScriptRunner::executeScriptsWaitingForParsing()
     232{
     233    while (!m_scriptsToExecuteAfterParsing.isEmpty()) {
     234        ASSERT(!haveParsingBlockingScript());
     235        m_parsingBlockingScript = m_scriptsToExecuteAfterParsing.takeFirst();
     236        ASSERT(m_parsingBlockingScript.cachedScript());
     237        if (!m_parsingBlockingScript.cachedScript()->isLoaded()) {
     238            watchForLoad(m_parsingBlockingScript);
     239            return false;
     240        }
     241        if (!executeParsingBlockingScripts())
     242            return false;
     243    }
     244
     245    return m_scriptsToExecuteAfterParsing.isEmpty();
     246}
     247
     248bool HTMLScriptRunner::requestScript(PendingScript& pendingScript, Element* scriptElement)
     249{
     250    ASSERT(!pendingScript.element);
     251    const AtomicString& srcValue = scriptElement->getAttribute(srcAttr);
    236252    if (!m_host->shouldLoadExternalScriptFromSrc(srcValue))
    237         return;
     253        return false;
    238254    // FIXME: We need to resolve the url relative to the element.
    239     if (!script->dispatchBeforeLoadEvent(srcValue))
    240         return;
    241     m_parsingBlockingScript.element = script;
     255    if (!scriptElement->dispatchBeforeLoadEvent(srcValue))
     256        return false;
     257    pendingScript.element = scriptElement;
    242258    // This should correctly return 0 for empty or invalid srcValues.
    243     CachedScript* cachedScript = m_document->docLoader()->requestScript(srcValue, toScriptElement(script)->scriptCharset());
     259    CachedScript* cachedScript = m_document->docLoader()->requestScript(srcValue, toScriptElement(scriptElement)->scriptCharset());
    244260    if (!cachedScript) {
    245261        notImplemented(); // Dispatch error event.
    246         return;
    247     }
    248 
    249     m_parsingBlockingScript.setCachedScript(cachedScript);
     262        return false;
     263    }
     264
     265    pendingScript.setCachedScript(cachedScript);
     266    return true;
     267}
     268
     269void HTMLScriptRunner::requestParsingBlockingScript(Element* scriptElement)
     270{
     271    if (!requestScript(m_parsingBlockingScript, scriptElement))
     272        return;
     273
     274    ASSERT(m_parsingBlockingScript.cachedScript());
    250275
    251276    // We only care about a load callback if cachedScript is not already
     
    256281}
    257282
     283void HTMLScriptRunner::requestDeferredScript(Element* scriptElement)
     284{
     285    PendingScript pendingScript;
     286    if (!requestScript(pendingScript, scriptElement))
     287        return;
     288
     289    ASSERT(pendingScript.cachedScript());
     290    m_scriptsToExecuteAfterParsing.append(pendingScript);
     291}
     292
    258293// This method is meant to match the HTML5 definition of "running a script"
    259294// http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#running-a-script
     
    268303
    269304        if (script->hasAttribute(srcAttr)) {
    270             // FIXME: Handle defer and async
    271             requestScript(script);
     305            // FIXME: Handle async
     306            if (script->hasAttribute(deferAttr))
     307                requestDeferredScript(script);
     308            else
     309                requestParsingBlockingScript(script);
    272310        } else {
    273311            // FIXME: We do not block inline <script> tags on stylesheets to match the
  • trunk/WebCore/html/HTMLScriptRunner.h

    r63998 r64674  
    2929#include "CachedResourceClient.h"
    3030#include "CachedResourceHandle.h"
     31#include <wtf/Deque.h>
    3132#include <wtf/Noncopyable.h>
    3233#include <wtf/PassRefPtr.h>
     
    5354    bool hasScriptsWaitingForStylesheets() const { return m_hasScriptsWaitingForStylesheets; }
    5455    bool executeScriptsWaitingForStylesheets();
     56    bool executeScriptsWaitingForParsing();
    5557
    5658    bool isExecutingScript() { return !!m_scriptNestingLevel; }
     
    6466    //
    6567    // FIXME: Finish turning this into a proper class.
    66     class PendingScript : public CachedResourceClient, Noncopyable {
     68    class PendingScript : public CachedResourceClient {
    6769    public:
    6870        PendingScript()
     
    7072            , m_watchingForLoad(false)
    7173        {
     74        }
     75
     76        PendingScript(const PendingScript& other)
     77            : CachedResourceClient(other)
     78            , element(other.element)
     79            , startingLineNumber(other.startingLineNumber)
     80            , m_watchingForLoad(other.m_watchingForLoad)
     81        {
     82            setCachedScript(other.cachedScript());
     83        }
     84
     85        PendingScript& operator=(const PendingScript& other)
     86        {
     87            if (this == &other)
     88                return *this;
     89
     90            element = other.element;
     91            startingLineNumber = other.startingLineNumber;
     92            m_watchingForLoad = other.m_watchingForLoad;
     93            setCachedScript(other.cachedScript());
     94
     95            return *this;
    7296        }
    7397
     
    102126    void executePendingScript();
    103127
    104     void requestScript(Element*);
     128    bool requestScript(PendingScript&, Element*);
     129    void requestParsingBlockingScript(Element*);
     130    void requestDeferredScript(Element*);
    105131    void runScript(Element*, int startingLineNumber);
    106132
     
    116142    HTMLScriptRunnerHost* m_host;
    117143    PendingScript m_parsingBlockingScript;
     144    Deque<PendingScript> m_scriptsToExecuteAfterParsing;
    118145    unsigned m_scriptNestingLevel;
    119146
Note: See TracChangeset for help on using the changeset viewer.