Title: [256808] trunk
Revision
256808
Author
[email protected]
Date
2020-02-17 19:12:43 -0800 (Mon, 17 Feb 2020)

Log 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]):

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (256807 => 256808)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-02-18 03:12:43 UTC (rev 256808)
@@ -1,3 +1,22 @@
+2020-02-17  Chris Dumez  <[email protected]>
+
+        Defer execution of async scripts until until the document is loaded
+        https://bugs.webkit.org/show_bug.cgi?id=207698
+        <rdar://problem/57625747>
+
+        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:
+
 2020-02-17  Rob Buis  <[email protected]>
 
         Main implementation for lazy image loading

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scripthash-changed-1-expected.txt (256807 => 256808)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scripthash-changed-1-expected.txt	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scripthash-changed-1-expected.txt	2020-02-18 03:12:43 UTC (rev 256808)
@@ -1,3 +1,3 @@
 
-FAIL scr1.innerText before modification should not be blocked assert_equals: expected "scr1 at #prepare-a-script" but got ""
+PASS scr1.innerText before modification should not be blocked 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scripthash-changed-2-expected.txt (256807 => 256808)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scripthash-changed-2-expected.txt	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scripthash-changed-2-expected.txt	2020-02-18 03:12:43 UTC (rev 256808)
@@ -1,3 +1,3 @@
 
-FAIL scr2.innerText before modification should be blocked assert_equals: expected "" but got "scr2 at #execute-the-script-block"
+PASS scr2.innerText before modification should be blocked 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scriptnonce-changed-1-expected.txt (256807 => 256808)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scriptnonce-changed-1-expected.txt	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scriptnonce-changed-1-expected.txt	2020-02-18 03:12:43 UTC (rev 256808)
@@ -1,3 +1,3 @@
 
-FAIL scr1 nonce before modification should not be blocked assert_equals: expected "scr1 executed" but got ""
+PASS scr1 nonce before modification should not be blocked 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scriptnonce-changed-2-expected.txt (256807 => 256808)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scriptnonce-changed-2-expected.txt	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/scriptnonce-changed-2-expected.txt	2020-02-18 03:12:43 UTC (rev 256808)
@@ -1,3 +1,3 @@
 
-FAIL scr2 nonce before modification should be blocked assert_equals: expected "" but got "scr2 executed"
+PASS scr2 nonce before modification should be blocked 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/async_005-expected.txt (256807 => 256808)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/async_005-expected.txt	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/async_005-expected.txt	2020-02-18 03:12:43 UTC (rev 256808)
@@ -1,3 +1,3 @@
 
-PASS A script element with both async and defer set should execute asynchronously 
-2134
+FAIL A script element with both async and defer set should execute asynchronously assert_equals: expected "2134" but got "2341"
+2341

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/085-expected.txt (256807 => 256808)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/085-expected.txt	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/085-expected.txt	2020-02-18 03:12:43 UTC (rev 256808)
@@ -1,4 +1,4 @@
 FAILED (This TC requires _javascript_ enabled)
 
-PASS  scheduler: async script and slow-loading defer script 
+FAIL  scheduler: async script and slow-loading defer script assert_array_equals: property 0, expected "external script #2" but got "external script #1"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-modifications-expected.txt (256807 => 256808)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-modifications-expected.txt	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-modifications-expected.txt	2020-02-18 03:12:43 UTC (rev 256808)
@@ -1,3 +1,3 @@
 
-FAIL Modify inline script element's text after prepare-a-script before evaluation assert_unreached: This should not be evaluated Reached unreachable code
+FAIL 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 evalu
 ated\")();',\n                  \"<script>'s text should be already modified\");\n    t.done();\n  });\n"
 

Modified: trunk/Source/WebCore/ChangeLog (256807 => 256808)


--- trunk/Source/WebCore/ChangeLog	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/Source/WebCore/ChangeLog	2020-02-18 03:12:43 UTC (rev 256808)
@@ -1,3 +1,22 @@
+2020-02-17  Chris Dumez  <[email protected]>
+
+        Defer execution of async scripts until until the document is loaded
+        https://bugs.webkit.org/show_bug.cgi?id=207698
+        <rdar://problem/57625747>
+
+        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:
+
 2020-02-17  Youenn Fablet  <[email protected]>
 
         Do not call whenReady callbacks in case of network process crash

Modified: trunk/Source/WebCore/dom/ScriptElement.h (256807 => 256808)


--- trunk/Source/WebCore/dom/ScriptElement.h	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/Source/WebCore/dom/ScriptElement.h	2020-02-18 03:12:43 UTC (rev 256808)
@@ -54,6 +54,8 @@
 
     void executePendingScript(PendingScript&);
 
+    virtual bool hasAsyncAttribute() const = 0;
+
     // XML parser calls these
     virtual void dispatchLoadEvent() = 0;
     virtual void dispatchErrorEvent();
@@ -112,7 +114,6 @@
     virtual String languageAttributeValue() const = 0;
     virtual String forAttributeValue() const = 0;
     virtual String eventAttributeValue() const = 0;
-    virtual bool hasAsyncAttribute() const = 0;
     virtual bool hasDeferAttribute() const = 0;
     virtual bool hasSourceAttribute() const = 0;
     virtual bool hasNoModuleAttribute() const = 0;

Modified: trunk/Source/WebCore/dom/ScriptRunner.cpp (256807 => 256808)


--- trunk/Source/WebCore/dom/ScriptRunner.cpp	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/Source/WebCore/dom/ScriptRunner.cpp	2020-02-18 03:12:43 UTC (rev 256808)
@@ -112,7 +112,17 @@
 
     Vector<RefPtr<PendingScript>> scripts;
 
-    if (!m_document.shouldDeferAsynchronousScriptsUntilParsingFinishes())
+    if (m_document.shouldDeferAsynchronousScriptsUntilParsingFinishes()) {
+        Vector<RefPtr<PendingScript>> scriptsToExecuteSoon;
+        // Scripts not added by the parser are executed asynchronously and yet do not have the 'async' attribute set.
+        // We only want to delay scripts that were explicitly marked as 'async' by the developer.
+        m_scriptsToExecuteSoon.removeAllMatching([&](auto& pendingScript) {
+            if (pendingScript->element().hasAsyncAttribute())
+                return false;
+            scripts.append(WTFMove(pendingScript));
+            return true;
+        });
+    } else
         scripts.swap(m_scriptsToExecuteSoon);
 
     size_t numInOrderScriptsToExecute = 0;

Modified: trunk/Source/WebCore/page/Settings.yaml (256807 => 256808)


--- trunk/Source/WebCore/page/Settings.yaml	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/Source/WebCore/page/Settings.yaml	2020-02-18 03:12:43 UTC (rev 256808)
@@ -856,7 +856,7 @@
   initial: false
 
 shouldDeferAsynchronousScriptsUntilAfterDocumentLoad:
-  initial: false
+  initial: true
 
 shouldIgnoreMetaViewport:
   initial: false

Modified: trunk/Source/WebKit/ChangeLog (256807 => 256808)


--- trunk/Source/WebKit/ChangeLog	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/Source/WebKit/ChangeLog	2020-02-18 03:12:43 UTC (rev 256808)
@@ -1,3 +1,17 @@
+2020-02-17  Chris Dumez  <[email protected]>
+
+        Defer execution of async scripts until until the document is loaded
+        https://bugs.webkit.org/show_bug.cgi?id=207698
+        <rdar://problem/57625747>
+
+        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]):
+
 2020-02-17  Tim Horton  <[email protected]>
 
         Add and adopt HAVE(LOOKUP_GESTURE_RECOGNIZER)

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm (256807 => 256808)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2020-02-18 03:04:58 UTC (rev 256807)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2020-02-18 03:12:43 UTC (rev 256808)
@@ -258,7 +258,7 @@
 
     _colorFilterEnabled = NO;
     _incompleteImageBorderEnabled = NO;
-    _shouldDeferAsynchronousScriptsUntilAfterDocumentLoad = NO;
+    _shouldDeferAsynchronousScriptsUntilAfterDocumentLoad = YES;
     _drawsBackground = YES;
 
     _editableImagesEnabled = NO;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to