Changeset 139790 in webkit


Ignore:
Timestamp:
Jan 15, 2013, 2:17:06 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

HTML parser should queue MutationRecords for its operations
https://bugs.webkit.org/show_bug.cgi?id=89351

Patch by Elliott Sprehn <Elliott Sprehn> on 2013-01-15
Reviewed by Eric Seidel.

Source/WebCore:

Generate mutation records inside the parser. This is done by using a
ChildListMutationScope in the ContainerNode::parser* methods and then
adding delivery before each <script> element would be processed by
the parser.

Test: fast/dom/MutationObserver/parser-mutations.html

  • dom/ContainerNode.cpp:

(WebCore::ContainerNode::parserInsertBefore):
(WebCore::ContainerNode::parserRemoveChild):
(WebCore::ContainerNode::parserAppendChild):

  • html/parser/HTMLScriptRunner.cpp:

(WebCore::HTMLScriptRunner::executeParsingBlockingScript):
(WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent):
(WebCore::HTMLScriptRunner::execute):
(WebCore::HTMLScriptRunner::executeScriptsWaitingForLoad):
(WebCore::HTMLScriptRunner::executeScriptsWaitingForStylesheets):
(WebCore::HTMLScriptRunner::executeScriptsWaitingForParsing):
(WebCore::HTMLScriptRunner::runScript):

LayoutTests:

Add tests for parser generated mutations.

XXX: This needs a bunch more tests observing the adoption
agency algorithm to catch parserInsertBefore and parserRemoveChild
mutations.

  • fast/dom/MutationObserver/parser-mutations-expected.txt: Added.
  • fast/dom/MutationObserver/parser-mutations.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r139789 r139790  
     12013-01-15  Elliott Sprehn  <esprehn@gmail.com>
     2
     3        HTML parser should queue MutationRecords for its operations
     4        https://bugs.webkit.org/show_bug.cgi?id=89351
     5
     6        Reviewed by Eric Seidel.
     7
     8        Add tests for parser generated mutations.
     9
     10        XXX: This needs a bunch more tests observing the adoption
     11        agency algorithm to catch parserInsertBefore and parserRemoveChild
     12        mutations.
     13
     14        * fast/dom/MutationObserver/parser-mutations-expected.txt: Added.
     15        * fast/dom/MutationObserver/parser-mutations.html: Added.
     16
    1172013-01-15  Ojan Vafai  <ojan@chromium.org>
    218
  • trunk/Source/WebCore/ChangeLog

    r139789 r139790  
     12013-01-15  Elliott Sprehn  <esprehn@gmail.com>
     2
     3        HTML parser should queue MutationRecords for its operations
     4        https://bugs.webkit.org/show_bug.cgi?id=89351
     5
     6        Reviewed by Eric Seidel.
     7
     8        Generate mutation records inside the parser. This is done by using a
     9        ChildListMutationScope in the ContainerNode::parser* methods and then
     10        adding delivery before each <script> element would be processed by
     11        the parser.
     12
     13        Test: fast/dom/MutationObserver/parser-mutations.html
     14
     15        * dom/ContainerNode.cpp:
     16        (WebCore::ContainerNode::parserInsertBefore):
     17        (WebCore::ContainerNode::parserRemoveChild):
     18        (WebCore::ContainerNode::parserAppendChild):
     19        * html/parser/HTMLScriptRunner.cpp:
     20        (WebCore::HTMLScriptRunner::executeParsingBlockingScript):
     21        (WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent):
     22        (WebCore::HTMLScriptRunner::execute):
     23        (WebCore::HTMLScriptRunner::executeScriptsWaitingForLoad):
     24        (WebCore::HTMLScriptRunner::executeScriptsWaitingForStylesheets):
     25        (WebCore::HTMLScriptRunner::executeScriptsWaitingForParsing):
     26        (WebCore::HTMLScriptRunner::runScript):
     27
    1282013-01-15  Ojan Vafai  <ojan@chromium.org>
    229
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r139132 r139790  
    332332    insertBeforeCommon(nextChild, newChild.get());
    333333
     334#if ENABLE(MUTATION_OBSERVERS)
     335    ChildListMutationScope(this).childAdded(newChild.get());
     336#endif
     337
    334338    childrenChanged(true, newChild->previousSibling(), nextChild, 1);
    335339    ChildNodeInsertionNotifier(this).notify(newChild.get());
     
    552556    Node* prev = oldChild->previousSibling();
    553557    Node* next = oldChild->nextSibling();
     558
     559#if ENABLE(MUTATION_OBSERVERS)
     560    ChildListMutationScope(this).willRemoveChild(oldChild);
     561    oldChild->notifyMutationObserversNodeWillDetach();
     562#endif
    554563
    555564    removeBetween(prev, next, oldChild);
     
    697706        treeScope()->adoptIfNeeded(newChild.get());
    698707    }
     708
     709#if ENABLE(MUTATION_OBSERVERS)
     710    ChildListMutationScope(this).childAdded(newChild.get());
     711#endif
    699712
    700713    childrenChanged(true, last, 0, 1);
  • trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp

    r122226 r139790  
    3737#include "HTMLScriptRunnerHost.h"
    3838#include "IgnoreDestructiveWriteCountIncrementer.h"
     39#include "MutationObserver.h"
    3940#include "NestingLevelIncrementer.h"
    4041#include "NotImplemented.h"
     
    111112{
    112113    ASSERT(m_document);
    113     ASSERT(!m_scriptNestingLevel);
     114    ASSERT(!isExecutingScript());
    114115    ASSERT(m_document->haveStylesheetsLoaded());
    115116    ASSERT(isPendingScriptReady(m_parserBlockingScript));
     
    127128    if (pendingScript.cachedScript() && pendingScript.watchingForLoad())
    128129        stopWatchingForLoad(pendingScript);
     130
     131#if ENABLE(MUTATION_OBSERVERS)
     132    if (!isExecutingScript())
     133        MutationObserver::deliverAllMutations();
     134#endif
    129135
    130136    // Clear the pending script before possible rentrancy from executeScript()
     
    141147        }
    142148    }
    143     ASSERT(!m_scriptNestingLevel);
     149    ASSERT(!isExecutingScript());
    144150}
    145151
     
    171177
    172178    if (hasParserBlockingScript()) {
    173         if (m_scriptNestingLevel)
     179        if (isExecutingScript())
    174180            return; // Unwind to the outermost HTMLScriptRunner::execute before continuing parsing.
    175181        // If preload scanner got created, it is missing the source after the current insertion point. Append it and scan.
     
    193199void HTMLScriptRunner::executeScriptsWaitingForLoad(CachedResource* cachedScript)
    194200{
    195     ASSERT(!m_scriptNestingLevel);
     201    ASSERT(!isExecutingScript());
    196202    ASSERT(hasParserBlockingScript());
    197203    ASSERT_UNUSED(cachedScript, m_parserBlockingScript.cachedScript() == cachedScript);
     
    206212    // to prevent parser or script re-entry during </style> parsing.
    207213    ASSERT(hasScriptsWaitingForStylesheets());
    208     ASSERT(!m_scriptNestingLevel);
     214    ASSERT(!isExecutingScript());
    209215    ASSERT(m_document->haveStylesheetsLoaded());
    210216    executeParsingBlockingScripts();
     
    214220{
    215221    while (!m_scriptsToExecuteAfterParsing.isEmpty()) {
    216         ASSERT(!m_scriptNestingLevel);
     222        ASSERT(!isExecutingScript());
    217223        ASSERT(!hasParserBlockingScript());
    218224        ASSERT(m_scriptsToExecuteAfterParsing.first().cachedScript());
     
    275281    ASSERT(!hasParserBlockingScript());
    276282    {
    277         InsertionPointRecord insertionPointRecord(m_host->inputStream());
    278         NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
    279 
    280283        ScriptElement* scriptElement = toScriptElement(script);
    281284
     
    287290        if (!scriptElement)
    288291            return;
     292
     293#if ENABLE(MUTATION_OBSERVERS)
     294        // FIXME: This may be too agressive as we always deliver mutations at
     295        // every script element, even if it's not ready to execute yet. There's
     296        // unfortuantely no obvious way to tell if prepareScript is going to
     297        // execute the script from out here.
     298        if (!isExecutingScript())
     299            MutationObserver::deliverAllMutations();
     300#endif
     301
     302        InsertionPointRecord insertionPointRecord(m_host->inputStream());
     303        NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
    289304
    290305        scriptElement->prepareScript(scriptStartPosition);
Note: See TracChangeset for help on using the changeset viewer.