Title: [208660] trunk
Revision
208660
Author
[email protected]
Date
2016-11-12 18:43:37 -0800 (Sat, 12 Nov 2016)

Log 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.

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (208659 => 208660)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-11-12 22:31:17 UTC (rev 208659)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-11-13 02:43:37 UTC (rev 208660)
@@ -1,3 +1,14 @@
+2016-11-12  Ryosuke Niwa  <[email protected]>
+
+        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.
+
+        Rebaselined the imported test now that there are no errors.
+
+        * web-platform-tests/shadow-dom/Document-prototype-currentScript-expected.txt:
+
 2016-11-11  Brady Eidson  <[email protected]>
 
         IndexedDB 2.0: "close pending flag" and firing blocked events all need fixing.

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/Document-prototype-currentScript-expected.txt (208659 => 208660)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/Document-prototype-currentScript-expected.txt	2016-11-12 22:31:17 UTC (rev 208659)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/Document-prototype-currentScript-expected.txt	2016-11-13 02:43:37 UTC (rev 208660)
@@ -1,14 +1,4 @@
-CONSOLE MESSAGE: line 2422: Error: assert_equals: expected null but got Element node <script id="outerScriptElement">
 
-var outerScriptElement ...
-CONSOLE MESSAGE: line 2422: Error: assert_equals: expected null but got Element node <script id="outerScriptElement">
-
-var outerScriptElement ...
-
-Harness Error (FAIL), message = Error: assert_equals: expected null but got Element node <script id="outerScriptElement">
-
-var outerScriptElement ...
-
 PASS document.currentScript must not to be set to a script element in a shadow tree in open mode 
 PASS document.currentScript must not to be set to a script element in a shadow tree in closed mode 
 PASS document.currentScript must be set to a script element that loads an external script in a document tree 

Modified: trunk/Source/WebCore/ChangeLog (208659 => 208660)


--- trunk/Source/WebCore/ChangeLog	2016-11-12 22:31:17 UTC (rev 208659)
+++ trunk/Source/WebCore/ChangeLog	2016-11-13 02:43:37 UTC (rev 208660)
@@ -1,3 +1,27 @@
+2016-11-12  Ryosuke Niwa  <[email protected]>
+
+        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.
+
+        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.
+
 2016-11-12  Darin Adler  <[email protected]>
 
         Remove a few assorted uses of ExceptionCode

Modified: trunk/Source/WebCore/dom/CurrentScriptIncrementer.h (208659 => 208660)


--- trunk/Source/WebCore/dom/CurrentScriptIncrementer.h	2016-11-12 22:31:17 UTC (rev 208659)
+++ trunk/Source/WebCore/dom/CurrentScriptIncrementer.h	2016-11-13 02:43:37 UTC (rev 208660)
@@ -38,21 +38,24 @@
 public:
     CurrentScriptIncrementer(Document& document, Element& element)
         : m_document(document)
-        , m_isHTMLScriptElementOutsideShadowTree(is<HTMLScriptElement>(element) && !element.isInShadowTree())
+        , m_isHTMLScriptElement(is<HTMLScriptElement>(element))
     {
-        if (m_isHTMLScriptElementOutsideShadowTree)
-            m_document.pushCurrentScript(&downcast<HTMLScriptElement>(element));
+        if (!m_isHTMLScriptElement)
+            return;
+        auto& scriptElement = downcast<HTMLScriptElement>(element);
+        m_document.pushCurrentScript(scriptElement.isInShadowTree() ? nullptr : &scriptElement);
     }
 
     ~CurrentScriptIncrementer()
     {
-        if (m_isHTMLScriptElementOutsideShadowTree)
-            m_document.popCurrentScript();
+        if (!m_isHTMLScriptElement)
+            return;
+        m_document.popCurrentScript();
     }
 
 private:
     Document& m_document;
-    bool m_isHTMLScriptElementOutsideShadowTree;
+    bool m_isHTMLScriptElement;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/Document.cpp (208659 => 208660)


--- trunk/Source/WebCore/dom/Document.cpp	2016-11-12 22:31:17 UTC (rev 208659)
+++ trunk/Source/WebCore/dom/Document.cpp	2016-11-13 02:43:37 UTC (rev 208660)
@@ -4784,7 +4784,6 @@
 
 void Document::pushCurrentScript(HTMLScriptElement* newCurrentScript)
 {
-    ASSERT(newCurrentScript);
     m_currentScriptStack.append(newCurrentScript);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to