Changeset 256808 in webkit


Ignore:
Timestamp:
Feb 17, 2020 7:12:43 PM (4 years ago)
Author:
Chris Dumez
Message:

Defer execution of async scripts until until the document is loaded
https://bugs.webkit.org/show_bug.cgi?id=207698
<rdar://problem/57625747>

LayoutTests/imported/w3c:

Reviewed by Antti Koivisto.

Rebaseline WPT test to reflect behavior change. Some tests start passing and some other are now failing because
they rely on specific ordering at network level.

  • web-platform-tests/content-security-policy/script-src/scripthash-changed-1-expected.txt:
  • web-platform-tests/content-security-policy/script-src/scripthash-changed-2-expected.txt:
  • web-platform-tests/content-security-policy/script-src/scriptnonce-changed-1-expected.txt:
  • web-platform-tests/content-security-policy/script-src/scriptnonce-changed-2-expected.txt:
  • web-platform-tests/html/semantics/scripting-1/the-script-element/async_005-expected.txt:
  • web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/085-expected.txt:
  • web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-modifications-expected.txt:

Source/WebCore:

Reviewed Antti Koivisto.

Defer execution of async scripts until until the document is loaded by default to reduce time
to first paint.

  • dom/ScriptElement.h:
  • dom/ScriptRunner.cpp:

(WebCore::ScriptRunner::timerFired):
Make sure we do not defer scripts that were not added by the parser and that do not have the
'async' attribute set.

  • page/Settings.yaml:

Source/WebKit:

Reviewed by Antti Koivisto.

Defer execution of async scripts until until the document is loaded by default to reduce time
to first paint.

  • UIProcess/API/Cocoa/WKWebViewConfiguration.mm:

(-[WKWebViewConfiguration init]):

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r256786 r256808  
     12020-02-17  Chris Dumez  <cdumez@apple.com>
     2
     3        Defer execution of async scripts until until the document is loaded
     4        https://bugs.webkit.org/show_bug.cgi?id=207698
     5        <rdar://problem/57625747>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Rebaseline WPT test to reflect behavior change. Some tests start passing and some other are now failing because
     10        they rely on specific ordering at network level.
     11
     12        * web-platform-tests/content-security-policy/script-src/scripthash-changed-1-expected.txt:
     13        * web-platform-tests/content-security-policy/script-src/scripthash-changed-2-expected.txt:
     14        * web-platform-tests/content-security-policy/script-src/scriptnonce-changed-1-expected.txt:
     15        * web-platform-tests/content-security-policy/script-src/scriptnonce-changed-2-expected.txt:
     16        * web-platform-tests/html/semantics/scripting-1/the-script-element/async_005-expected.txt:
     17        * web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/085-expected.txt:
     18        * web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-modifications-expected.txt:
     19
    1202020-02-17  Rob Buis  <rbuis@igalia.com>
    221
  • trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scripthash-changed-1-expected.txt

    r254133 r256808  
    11
    2 FAIL scr1.innerText before modification should not be blocked assert_equals: expected "scr1 at #prepare-a-script" but got ""
     2PASS scr1.innerText before modification should not be blocked
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scripthash-changed-2-expected.txt

    r254133 r256808  
    11
    2 FAIL scr2.innerText before modification should be blocked assert_equals: expected "" but got "scr2 at #execute-the-script-block"
     2PASS scr2.innerText before modification should be blocked
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scriptnonce-changed-1-expected.txt

    r254133 r256808  
    11
    2 FAIL scr1 nonce before modification should not be blocked assert_equals: expected "scr1 executed" but got ""
     2PASS scr1 nonce before modification should not be blocked
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scriptnonce-changed-2-expected.txt

    r254133 r256808  
    11
    2 FAIL scr2 nonce before modification should be blocked assert_equals: expected "" but got "scr2 executed"
     2PASS scr2 nonce before modification should be blocked
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/async_005-expected.txt

    r204090 r256808  
    11
    2 PASS A script element with both async and defer set should execute asynchronously
    3 2134
     2FAIL A script element with both async and defer set should execute asynchronously assert_equals: expected "2134" but got "2341"
     32341
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/085-expected.txt

    r249886 r256808  
    11FAILED (This TC requires JavaScript enabled)
    22
    3 PASS  scheduler: async script and slow-loading defer script
     3FAIL  scheduler: async script and slow-loading defer script assert_array_equals: property 0, expected "external script #2" but got "external script #1"
    44
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-modifications-expected.txt

    r249886 r256808  
    11
    2 FAIL Modify inline script element's text after prepare-a-script before evaluation assert_unreached: This should not be evaluated Reached unreachable code
     2FAIL Modify inline script element's text after prepare-a-script before evaluation assert_equals: <script>'s innerText should be already modified expected "t.unreached_func(\"This should not be evaluated\")();" but got "\nt.step(() => {\n    // When this is evaluated after the stylesheet is loaded,\n    // script0's innerText is modified by the async script above,\n    // but the evaluated script is still the original script here,\n    // not what is overwritten, because \"child text content\" is taken in\n    // #prepare-a-script and passed to \"creating a classic script\".\n    var s = document.getElementById('script0');\n    assert_equals(s.innerText,\n                  't.unreached_func(\"This should not be evaluated\")();',\n                  \"<script>'s innerText should be already modified\");\n    assert_equals(s.text,\n                  't.unreached_func(\"This should not be evaluated\")();',\n                  \"<script>'s text should be already modified\");\n    t.done();\n  });\n"
    33
  • trunk/Source/WebCore/ChangeLog

    r256805 r256808  
     12020-02-17  Chris Dumez  <cdumez@apple.com>
     2
     3        Defer execution of async scripts until until the document is loaded
     4        https://bugs.webkit.org/show_bug.cgi?id=207698
     5        <rdar://problem/57625747>
     6
     7        Reviewed Antti Koivisto.
     8
     9        Defer execution of async scripts until until the document is loaded by default to reduce time
     10        to first paint.
     11
     12        * dom/ScriptElement.h:
     13        * dom/ScriptRunner.cpp:
     14        (WebCore::ScriptRunner::timerFired):
     15        Make sure we do not defer scripts that were not added by the parser and that do not have the
     16        'async' attribute set.
     17
     18        * page/Settings.yaml:
     19
    1202020-02-17  Youenn Fablet  <youenn@apple.com>
    221
  • trunk/Source/WebCore/dom/ScriptElement.h

    r251290 r256808  
    5454
    5555    void executePendingScript(PendingScript&);
     56
     57    virtual bool hasAsyncAttribute() const = 0;
    5658
    5759    // XML parser calls these
     
    113115    virtual String forAttributeValue() const = 0;
    114116    virtual String eventAttributeValue() const = 0;
    115     virtual bool hasAsyncAttribute() const = 0;
    116117    virtual bool hasDeferAttribute() const = 0;
    117118    virtual bool hasSourceAttribute() const = 0;
  • trunk/Source/WebCore/dom/ScriptRunner.cpp

    r233915 r256808  
    113113    Vector<RefPtr<PendingScript>> scripts;
    114114
    115     if (!m_document.shouldDeferAsynchronousScriptsUntilParsingFinishes())
     115    if (m_document.shouldDeferAsynchronousScriptsUntilParsingFinishes()) {
     116        Vector<RefPtr<PendingScript>> scriptsToExecuteSoon;
     117        // Scripts not added by the parser are executed asynchronously and yet do not have the 'async' attribute set.
     118        // We only want to delay scripts that were explicitly marked as 'async' by the developer.
     119        m_scriptsToExecuteSoon.removeAllMatching([&](auto& pendingScript) {
     120            if (pendingScript->element().hasAsyncAttribute())
     121                return false;
     122            scripts.append(WTFMove(pendingScript));
     123            return true;
     124        });
     125    } else
    116126        scripts.swap(m_scriptsToExecuteSoon);
    117127
  • trunk/Source/WebCore/page/Settings.yaml

    r256715 r256808  
    857857
    858858shouldDeferAsynchronousScriptsUntilAfterDocumentLoad:
    859   initial: false
     859  initial: true
    860860
    861861shouldIgnoreMetaViewport:
  • trunk/Source/WebKit/ChangeLog

    r256806 r256808  
     12020-02-17  Chris Dumez  <cdumez@apple.com>
     2
     3        Defer execution of async scripts until until the document is loaded
     4        https://bugs.webkit.org/show_bug.cgi?id=207698
     5        <rdar://problem/57625747>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Defer execution of async scripts until until the document is loaded by default to reduce time
     10        to first paint.
     11
     12        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
     13        (-[WKWebViewConfiguration init]):
     14
    1152020-02-17  Tim Horton  <timothy_horton@apple.com>
    216
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm

    r256571 r256808  
    259259    _colorFilterEnabled = NO;
    260260    _incompleteImageBorderEnabled = NO;
    261     _shouldDeferAsynchronousScriptsUntilAfterDocumentLoad = NO;
     261    _shouldDeferAsynchronousScriptsUntilAfterDocumentLoad = YES;
    262262    _drawsBackground = YES;
    263263
Note: See TracChangeset for help on using the changeset viewer.