Changeset 208660 in webkit


Ignore:
Timestamp:
Nov 12, 2016 6:43:37 PM (7 years ago)
Author:
rniwa@webkit.org
Message:

document.currentScript should be null when running a script inside a shadow tree
https://bugs.webkit.org/show_bug.cgi?id=164693

Reviewed by Yusuke Suzuki.

LayoutTests/imported/w3c:

Rebaselined the imported test now that there are no errors.

  • web-platform-tests/shadow-dom/Document-prototype-currentScript-expected.txt:

Source/WebCore:

Fixed the bug that we were returning the old or outer script element in document.currentScript
while executing a script element inside a shadow tree. Return null instead.

New behavior matches the latest HTML5 specification:
https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-block
where it says for the classic script type, "if the script element's root is not a shadow root, then set
the script element's node document's currentScript attribute to the script element. Otherwise, set it to null."

No new tests. imported/w3c/web-platform-tests/shadow-dom/Document-prototype-currentScript.html covers it.

  • dom/CurrentScriptIncrementer.h:

(WebCore::CurrentScriptIncrementer::CurrentScriptIncrementer): Push nullptr when the script element
is inside a shadow tree.
(WebCore::CurrentScriptIncrementer::~CurrentScriptIncrementer): Changed to use an early exit.

  • dom/Document.cpp:

(WebCore::Document::pushCurrentScript): Removed the assertion since the argument can now be nullptr.

Location:
trunk
Files:
5 edited

Legend:

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

    r208609 r208660  
     12016-11-12  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        document.currentScript should be null when running a script inside a shadow tree
     4        https://bugs.webkit.org/show_bug.cgi?id=164693
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Rebaselined the imported test now that there are no errors.
     9
     10        * web-platform-tests/shadow-dom/Document-prototype-currentScript-expected.txt:
     11
    1122016-11-11  Brady Eidson  <beidson@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/Document-prototype-currentScript-expected.txt

    r206463 r208660  
    1 CONSOLE MESSAGE: line 2422: Error: assert_equals: expected null but got Element node <script id="outerScriptElement">
    2 
    3 var outerScriptElement ...
    4 CONSOLE MESSAGE: line 2422: Error: assert_equals: expected null but got Element node <script id="outerScriptElement">
    5 
    6 var outerScriptElement ...
    7 
    8 Harness Error (FAIL), message = Error: assert_equals: expected null but got Element node <script id="outerScriptElement">
    9 
    10 var outerScriptElement ...
    111
    122PASS document.currentScript must not to be set to a script element in a shadow tree in open mode
  • trunk/Source/WebCore/ChangeLog

    r208659 r208660  
     12016-11-12  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        document.currentScript should be null when running a script inside a shadow tree
     4        https://bugs.webkit.org/show_bug.cgi?id=164693
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Fixed the bug that we were returning the old or outer script element in document.currentScript
     9        while executing a script element inside a shadow tree. Return null instead.
     10
     11        New behavior matches the latest HTML5 specification:
     12        https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-block
     13        where it says for the classic script type, "if the script element's root is not a shadow root, then set
     14        the script element's node document's currentScript attribute to the script element. Otherwise, set it to null."
     15
     16        No new tests. imported/w3c/web-platform-tests/shadow-dom/Document-prototype-currentScript.html covers it.
     17
     18        * dom/CurrentScriptIncrementer.h:
     19        (WebCore::CurrentScriptIncrementer::CurrentScriptIncrementer): Push nullptr when the script element
     20        is inside a shadow tree.
     21        (WebCore::CurrentScriptIncrementer::~CurrentScriptIncrementer): Changed to use an early exit.
     22        * dom/Document.cpp:
     23        (WebCore::Document::pushCurrentScript): Removed the assertion since the argument can now be nullptr.
     24
    1252016-11-12  Darin Adler  <darin@apple.com>
    226
  • trunk/Source/WebCore/dom/CurrentScriptIncrementer.h

    r208179 r208660  
    3939    CurrentScriptIncrementer(Document& document, Element& element)
    4040        : m_document(document)
    41         , m_isHTMLScriptElementOutsideShadowTree(is<HTMLScriptElement>(element) && !element.isInShadowTree())
     41        , m_isHTMLScriptElement(is<HTMLScriptElement>(element))
    4242    {
    43         if (m_isHTMLScriptElementOutsideShadowTree)
    44             m_document.pushCurrentScript(&downcast<HTMLScriptElement>(element));
     43        if (!m_isHTMLScriptElement)
     44            return;
     45        auto& scriptElement = downcast<HTMLScriptElement>(element);
     46        m_document.pushCurrentScript(scriptElement.isInShadowTree() ? nullptr : &scriptElement);
    4547    }
    4648
    4749    ~CurrentScriptIncrementer()
    4850    {
    49         if (m_isHTMLScriptElementOutsideShadowTree)
    50             m_document.popCurrentScript();
     51        if (!m_isHTMLScriptElement)
     52            return;
     53        m_document.popCurrentScript();
    5154    }
    5255
    5356private:
    5457    Document& m_document;
    55     bool m_isHTMLScriptElementOutsideShadowTree;
     58    bool m_isHTMLScriptElement;
    5659};
    5760
  • trunk/Source/WebCore/dom/Document.cpp

    r208630 r208660  
    47854785void Document::pushCurrentScript(HTMLScriptElement* newCurrentScript)
    47864786{
    4787     ASSERT(newCurrentScript);
    47884787    m_currentScriptStack.append(newCurrentScript);
    47894788}
Note: See TracChangeset for help on using the changeset viewer.