Changeset 234944 in webkit


Ignore:
Timestamp:
Aug 16, 2018 11:25:02 AM (6 years ago)
Author:
rniwa@webkit.org
Message:

Perform a microtask checkpoint before creating a custom element
https://bugs.webkit.org/show_bug.cgi?id=188189
<rdar://problem/42843022>

Reviewed by Geoffrey Garen.

Source/WebCore:

Fixed the bug that the HTML parser was not performing a microtask checkpoint prior to synchronously constructing
a custom element in the concept to create an element for a token:
https://html.spec.whatwg.org/multipage/parsing.html#creating-and-inserting-nodes:perform-a-microtask-checkpoint

Also added a microtask checkpoint before dispatching DOMContentLoaded to work around webkit.org/b/82931 since
scheduling a task to fire a DOMContentLoaded event in Document::finishedParsing as the HTML5 spec mandates
is a long standing bug with a lot of implications, which is completely outside the scope of this bug fix:
https://html.spec.whatwg.org/multipage/parsing.html#stop-parsing

Test: fast/custom-elements/perform-microtask-checkpoint-before-construction.html

  • dom/Document.cpp:

(WebCore::Document::finishedParsing): Perform a microtask checkpoint before dispatching DOMContentLoaded here as
a workaround for webkit.org/b/82931.

  • html/parser/HTMLDocumentParser.cpp:

(WebCore::HTMLDocumentParser::runScriptsForPausedTreeBuilder): Perform a microtask checkpoint here to fix the bug.

LayoutTests:

Added a W3C style testharness.js test for perfoming microtask checkpoint before constructing
a custom element synchronously.

  • fast/custom-elements/perform-microtask-checkpoint-before-construction-expected.txt: Added.
  • fast/custom-elements/perform-microtask-checkpoint-before-construction.html: Added.
  • fast/dom/MutationObserver/parser-mutations.html: Fixed the test per new behavior in Document::finishParsing.

Because iframe loads synchronously and fires DOMContentLoaded, mutation records are now delivered twice after
iframe element is encountered in this test and before script element executes. Concatenate the mutation records
arrays to account for this behavioral change. New WebKit behavior matches that of Chrome; namely this test
fails both on Chrome Canary 70 and trunk WebKit with this patch without this fix.

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r234940 r234944  
     12018-08-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Perform a microtask checkpoint before creating a custom element
     4        https://bugs.webkit.org/show_bug.cgi?id=188189
     5        <rdar://problem/42843022>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Added a W3C style testharness.js test for perfoming microtask checkpoint before constructing
     10        a custom element synchronously.
     11
     12        * fast/custom-elements/perform-microtask-checkpoint-before-construction-expected.txt: Added.
     13        * fast/custom-elements/perform-microtask-checkpoint-before-construction.html: Added.
     14        * fast/dom/MutationObserver/parser-mutations.html: Fixed the test per new behavior in Document::finishParsing.
     15        Because iframe loads synchronously and fires DOMContentLoaded, mutation records are now delivered twice after
     16        iframe element is encountered in this test and before script element executes. Concatenate the mutation records
     17        arrays to account for this behavioral change. New WebKit behavior matches that of Chrome; namely this test
     18        fails both on Chrome Canary 70 and trunk WebKit with this patch without this fix.
     19
    1202018-08-15  Jer Noble  <jer.noble@apple.com>
    221
  • trunk/LayoutTests/fast/dom/MutationObserver/parser-mutations.html

    r155265 r234944  
    88        testRunner.dumpAsText();
    99
     10    var mutations = [];
    1011    var observer = new MutationObserver(function(mutations, observer) {
    11         window.mutations = mutations;
     12        window.mutations = window.mutations.concat(mutations);
    1213    });
    1314    observer.observe(document.body, {childList: true, subtree:true});
  • trunk/Source/WebCore/ChangeLog

    r234943 r234944  
     12018-08-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Perform a microtask checkpoint before creating a custom element
     4        https://bugs.webkit.org/show_bug.cgi?id=188189
     5        <rdar://problem/42843022>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Fixed the bug that the HTML parser was not performing a microtask checkpoint prior to synchronously constructing
     10        a custom element in the concept to create an element for a token:
     11        https://html.spec.whatwg.org/multipage/parsing.html#creating-and-inserting-nodes:perform-a-microtask-checkpoint
     12
     13        Also added a microtask checkpoint before dispatching DOMContentLoaded to work around webkit.org/b/82931 since
     14        scheduling a task to fire a DOMContentLoaded event in Document::finishedParsing as the HTML5 spec mandates
     15        is a long standing bug with a lot of implications, which is completely outside the scope of this bug fix:
     16        https://html.spec.whatwg.org/multipage/parsing.html#stop-parsing
     17
     18        Test: fast/custom-elements/perform-microtask-checkpoint-before-construction.html
     19
     20        * dom/Document.cpp:
     21        (WebCore::Document::finishedParsing): Perform a microtask checkpoint before dispatching DOMContentLoaded here as
     22        a workaround for webkit.org/b/82931.
     23        * html/parser/HTMLDocumentParser.cpp:
     24        (WebCore::HTMLDocumentParser::runScriptsForPausedTreeBuilder): Perform a microtask checkpoint here to fix the bug.
     25
    1262018-08-16  Alex Christensen  <achristensen@webkit.org>
    227
  • trunk/Source/WebCore/dom/Document.cpp

    r234808 r234944  
    54285428        m_documentTiming.domContentLoadedEventStart = MonotonicTime::now();
    54295429
     5430    // FIXME: Schdule a task to fire DOMContentLoaded event instead. See webkit.org/b/82931
     5431    MicrotaskQueue::mainThreadQueue().performMicrotaskCheckpoint();
     5432
    54305433    dispatchEvent(Event::create(eventNames().DOMContentLoadedEvent, true, false));
    54315434
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp

    r234680 r234944  
    4040#include "JSCustomElementInterface.h"
    4141#include "LinkLoader.h"
     42#include "Microtasks.h"
    4243#include "NavigationScheduler.h"
    4344#include "ScriptElement.h"
     
    214215            // Prevent document.open/write during reactions by allocating the incrementer before the reactions stack.
    215216            ThrowOnDynamicMarkupInsertionCountIncrementer incrementer(*document());
     217
     218            MicrotaskQueue::mainThreadQueue().performMicrotaskCheckpoint();
     219
    216220            CustomElementReactionStack reactionStack(document()->execState());
    217221            auto& elementInterface = constructionData->elementInterface.get();
Note: See TracChangeset for help on using the changeset viewer.