Changeset 67163 in webkit


Ignore:
Timestamp:
Sep 9, 2010 9:30:51 PM (14 years ago)
Author:
tonyg@chromium.org
Message:

2010-09-09 Tony Gentilcore <tonyg@chromium.org>

Reviewed by Adam Barth.

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

  • fast/dom/Document/readystate.html: Dynamically inserted scripts now block the load event like in FF4. So move the finishJSTest call to load.
  • fast/dom/Document/readystate-expected.txt: Dynamically inserted script now runs before load during "interactive" phase.
  • fast/dom/HTMLScriptElement/async-inline-script-expected.txt: Added.
  • fast/dom/HTMLScriptElement/async-inline-script.html: Added. The async attribute doesn't apply to inline scripts, so check that they execute in order.
  • fast/dom/HTMLScriptElement/async-onbeforeload-expected.txt: Added.
  • fast/dom/HTMLScriptElement/async-onbeforeload.html: Added. Check that onbeforeload events fire synchronously and that they may be cancelled.
  • fast/dom/HTMLScriptElement/async-write-expected.txt: Added.
  • fast/dom/HTMLScriptElement/async-write.html: Added. Check that writes from async scripts are neutralized.
  • fast/dom/HTMLScriptElement/resources/async.js: Added.
  • http/tests/misc/async-and-defer-script-expected.txt: Added.
  • http/tests/misc/async-and-defer-script.html: Added. The async attributes takes precendence over the defer attribute. Check that a script which has both async and defer acts as async by ensuring it loads after DOMContentLoaded. A deferred scripts would block DCL.
  • http/tests/misc/resources/async-script.js: Added.
  • http/tests/misc/resources/slow-async-script.cgi: Added.
  • http/tests/misc/script-async-expected.txt: Added.
  • http/tests/misc/script-async.html: Added. Test general execution order of deferred scripts. The test checks for multiple valid orders since it is indeterminate.

2010-09-09 Tony Gentilcore <tonyg@chromium.org>

Reviewed by Adam Barth.

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

Tests: fast/dom/HTMLScriptElement/async-inline-script.html

fast/dom/HTMLScriptElement/async-onbeforeload.html
fast/dom/HTMLScriptElement/async-write.html
http/tests/misc/async-and-defer-script.html
http/tests/misc/script-async.html

  • dom/AsyncScriptRunner.cpp: (WebCore::AsyncScriptRunner::AsyncScriptRunner): (WebCore::AsyncScriptRunner::~AsyncScriptRunner): (WebCore::AsyncScriptRunner::executeScriptSoon): Increment the delay count when a task to execute scripts is queued up. (WebCore::AsyncScriptRunner::timerFired): decrementLoadEventDelayCount handles calling checkCompleted().
  • dom/AsyncScriptRunner.h: (WebCore::AsyncScriptRunner::create):
  • dom/Document.cpp: (WebCore::Document::Document):
  • dom/ScriptElement.cpp: (WebCore::ScriptElement::insertedIntoDocument): Treats async scripts just like a dynamically inserted script element rather than a parser inserted one.
  • html/parser/HTMLScriptRunner.cpp: (WebCore::HTMLScriptRunner::runScript):
Location:
trunk
Files:
13 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r67162 r67163  
     12010-09-09  Tony Gentilcore  <tonyg@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Support <script async> as specified by HTML5
     6        https://bugs.webkit.org/show_bug.cgi?id=45310
     7
     8        * fast/dom/Document/readystate.html: Dynamically inserted scripts now block the load event like in FF4. So move the finishJSTest call to load.
     9        * fast/dom/Document/readystate-expected.txt: Dynamically inserted script now runs before load during "interactive" phase.
     10        * fast/dom/HTMLScriptElement/async-inline-script-expected.txt: Added.
     11        * fast/dom/HTMLScriptElement/async-inline-script.html: Added. The async attribute doesn't apply to inline scripts, so check that they execute in order.
     12        * fast/dom/HTMLScriptElement/async-onbeforeload-expected.txt: Added.
     13        * fast/dom/HTMLScriptElement/async-onbeforeload.html: Added. Check that onbeforeload events fire synchronously and that they may be cancelled.
     14        * fast/dom/HTMLScriptElement/async-write-expected.txt: Added.
     15        * fast/dom/HTMLScriptElement/async-write.html: Added. Check that writes from async scripts are neutralized.
     16        * fast/dom/HTMLScriptElement/resources/async.js: Added.
     17        * http/tests/misc/async-and-defer-script-expected.txt: Added.
     18        * http/tests/misc/async-and-defer-script.html: Added. The async attributes takes precendence over the defer attribute.
     19        Check that a script which has both async and defer acts as async by ensuring it loads after DOMContentLoaded.
     20        A deferred scripts would block DCL.
     21        * http/tests/misc/resources/async-script.js: Added.
     22        * http/tests/misc/resources/slow-async-script.cgi: Added.
     23        * http/tests/misc/script-async-expected.txt: Added.
     24        * http/tests/misc/script-async.html: Added. Test general execution order of deferred scripts.
     25        The test checks for multiple valid orders since it is indeterminate.
     26
    1272010-09-09  Dirk Pranke  <dpranke@chromium.org>
    228
  • trunk/LayoutTests/fast/dom/Document/readystate-expected.txt

    r66841 r67163  
    44PASS document.readyState is "interactive"
    55PASS document.readyState is "interactive"
    6 PASS document.readyState is "complete"
     6PASS document.readyState is "interactive"
    77PASS document.readyState is "complete"
    88PASS successfullyParsed is true
  • trunk/LayoutTests/fast/dom/Document/readystate.html

    r66841 r67163  
    55<script src="../../js/resources/js-test-pre.js"></script>
    66</head>
    7 <body onload="shouldBeEqualToString('document.readyState', 'complete');">
     7<body onload="shouldBeEqualToString('document.readyState', 'complete');finishJSTest();">
    88Tests that the document's readyState is set properly at various phases during load.
    99<div id="console"></div>
     
    1919
    2020    var el = document.createElement('script');
    21     el.src = "data:text/javascript,shouldBeEqualToString('document.readyState', 'complete');";
    22     el.onload = function() { finishJSTest(); }
     21    el.src = "data:text/javascript,shouldBeEqualToString('document.readyState', 'interactive');";
    2322    document.getElementsByTagName('head')[0].appendChild(el);
    2423  }, false);
  • trunk/WebCore/ChangeLog

    r67161 r67163  
     12010-09-09  Tony Gentilcore  <tonyg@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Support <script async> as specified by HTML5
     6        https://bugs.webkit.org/show_bug.cgi?id=45310
     7
     8        Tests: fast/dom/HTMLScriptElement/async-inline-script.html
     9               fast/dom/HTMLScriptElement/async-onbeforeload.html
     10               fast/dom/HTMLScriptElement/async-write.html
     11               http/tests/misc/async-and-defer-script.html
     12               http/tests/misc/script-async.html
     13
     14        * dom/AsyncScriptRunner.cpp:
     15        (WebCore::AsyncScriptRunner::AsyncScriptRunner):
     16        (WebCore::AsyncScriptRunner::~AsyncScriptRunner):
     17        (WebCore::AsyncScriptRunner::executeScriptSoon): Increment the delay count when a task to execute scripts is queued up.
     18        (WebCore::AsyncScriptRunner::timerFired): decrementLoadEventDelayCount handles calling checkCompleted().
     19        * dom/AsyncScriptRunner.h:
     20        (WebCore::AsyncScriptRunner::create):
     21        * dom/Document.cpp:
     22        (WebCore::Document::Document):
     23        * dom/ScriptElement.cpp:
     24        (WebCore::ScriptElement::insertedIntoDocument): Treats async scripts just like a dynamically inserted script element rather than a parser inserted one.
     25        * html/parser/HTMLScriptRunner.cpp:
     26        (WebCore::HTMLScriptRunner::runScript):
     27
    1282010-09-09  Alexey Marinichev  <amarinichev@chromium.org>
    229
  • trunk/WebCore/dom/AsyncScriptRunner.cpp

    r64873 r67163  
    2828
    2929#include "CachedScript.h"
     30#include "Document.h"
    3031#include "Element.h"
    3132#include "ScriptElement.h"
     
    3334namespace WebCore {
    3435
    35 AsyncScriptRunner::AsyncScriptRunner()
    36     : m_timer(this, &AsyncScriptRunner::timerFired)
     36AsyncScriptRunner::AsyncScriptRunner(Document* document)
     37    : m_document(document)
     38    , m_timer(this, &AsyncScriptRunner::timerFired)
    3739{
     40    ASSERT(document);
    3841}
    3942
    4043AsyncScriptRunner::~AsyncScriptRunner()
    4144{
    42     for (size_t i = 0; i < m_scriptsToExecuteSoon.size(); ++i)
    43          m_scriptsToExecuteSoon[i].first->element()->deref(); // Balances ref() in executeScriptSoon().
     45    for (size_t i = 0; i < m_scriptsToExecuteSoon.size(); ++i) {
     46        m_scriptsToExecuteSoon[i].first->element()->deref(); // Balances ref() in executeScriptSoon().
     47        m_document->decrementLoadEventDelayCount();
     48    }
    4449}
    4550
     
    5257    ASSERT(element->inDocument());
    5358
     59    m_document->incrementLoadEventDelayCount();
    5460    m_scriptsToExecuteSoon.append(make_pair(data, cachedScript));
    5561    element->ref(); // Balanced by deref()s in timerFired() and dtor.
     
    7985        scripts[i].first->execute(scripts[i].second.get());
    8086        scripts[i].first->element()->deref(); // Balances ref() in executeScriptSoon().
     87        m_document->decrementLoadEventDelayCount();
    8188    }
    8289}
  • trunk/WebCore/dom/AsyncScriptRunner.h

    r64873 r67163  
    3636
    3737class CachedScript;
     38class Document;
    3839class ScriptElementData;
    3940   
    4041class AsyncScriptRunner : public Noncopyable {
    4142public:
    42     static PassOwnPtr<AsyncScriptRunner> create() { return new AsyncScriptRunner(); }
     43    static PassOwnPtr<AsyncScriptRunner> create(Document* document) { return new AsyncScriptRunner(document); }
    4344    ~AsyncScriptRunner();
    4445
     
    4950
    5051private:
    51     AsyncScriptRunner();
     52    AsyncScriptRunner(Document*);
    5253
    5354    void timerFired(Timer<AsyncScriptRunner>*);
    5455
     56    Document* m_document;
    5557    Vector<std::pair<ScriptElementData*, CachedResourceHandle<CachedScript> > > m_scriptsToExecuteSoon;
    5658    Timer<AsyncScriptRunner> m_timer;
  • trunk/WebCore/dom/Document.cpp

    r66963 r67163  
    372372    , m_overMinimumLayoutThreshold(false)
    373373    , m_extraLayoutDelay(0)
    374     , m_asyncScriptRunner(AsyncScriptRunner::create())
     374    , m_asyncScriptRunner(AsyncScriptRunner::create(this))
    375375    , m_xmlVersion("1.0")
    376376    , m_xmlStandalone(false)
  • trunk/WebCore/dom/ScriptElement.cpp

    r66963 r67163  
    5353void ScriptElement::insertedIntoDocument(ScriptElementData& data, const String& sourceUrl)
    5454{
    55     if (data.createdByParser())
     55    if (data.createdByParser() && !data.isAsynchronous())
    5656        return;
    5757
  • trunk/WebCore/html/parser/HTMLScriptRunner.cpp

    r66963 r67163  
    322322
    323323        if (script->hasAttribute(srcAttr)) {
    324             // FIXME: Handle async.
     324            if (script->hasAttribute(asyncAttr)) // Async takes precendence over defer.
     325                return; // Asynchronous scripts handle themselves.
     326
    325327            if (script->hasAttribute(deferAttr))
    326328                requestDeferredScript(script);
Note: See TracChangeset for help on using the changeset viewer.