2010-11-10 Ryosuke Niwa <rniwa@webkit.org>
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Nov 2010 07:37:47 +0000 (07:37 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Nov 2010 07:37:47 +0000 (07:37 +0000)
        Reviewed by Adam Barth.

        [HTML5] 10.2.8.4 Scripts that modify the page as it is being parsed
        https://bugs.webkit.org/show_bug.cgi?id=49364

        Fixed HTMLScriptRunner's executeScript to use the ScriptController of the frame to which script element belongs
        as supposed to that of the frame associated with the HTMLScriptRunner.

        See also: http://www.whatwg.org/specs/web-apps/current-work/#scripts-that-modify-the-page-as-it-is-being-parsed

        Test: fast/parser/script-modify-page-outer.html

        * html/parser/HTMLScriptRunner.cpp:
        (WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent): Calls executeScript.
        (WebCore::HTMLScriptRunner::executeScript): Uses the correct ScriptController instance.
        (WebCore::HTMLScriptRunner::runScript): Call executeScript.
        * html/parser/HTMLScriptRunner.h:
2010-11-10  Ryosuke Niwa  <rniwa@webkit.org>

        Reviewed by Adam Barth.

        [HTML5] 10.2.8.4 Scripts that modify the page as it is being parsed
        https://bugs.webkit.org/show_bug.cgi?id=49364

        Added a test to ensure moving the script element to the parent document as it is being parsed
        changes the script's global object to the parent document's window object.

        See also: http://www.whatwg.org/specs/web-apps/current-work/#scripts-that-modify-the-page-as-it-is-being-parsed

        * fast/parser/move-during-parsing-expected.txt:
        * fast/parser/resources/script-modify-page-inner.html: Added.
        * fast/parser/script-modify-page-outer-expected.txt: Added.
        * fast/parser/script-modify-page-outer.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@71797 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/parser/move-during-parsing-expected.txt
LayoutTests/fast/parser/resources/script-modify-page-inner.html [new file with mode: 0644]
LayoutTests/fast/parser/script-modify-page-outer-expected.txt [new file with mode: 0644]
LayoutTests/fast/parser/script-modify-page-outer.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/parser/HTMLScriptRunner.cpp
WebCore/html/parser/HTMLScriptRunner.h

index efc40aa..911d512 100644 (file)
@@ -1,3 +1,20 @@
+2010-11-10  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Reviewed by Adam Barth.
+
+        [HTML5] 10.2.8.4 Scripts that modify the page as it is being parsed
+        https://bugs.webkit.org/show_bug.cgi?id=49364
+
+        Added a test to ensure moving the script element to the parent document as it is being parsed
+        changes the script's global object to the parent document's window object.
+
+        See also: http://www.whatwg.org/specs/web-apps/current-work/#scripts-that-modify-the-page-as-it-is-being-parsed
+
+        * fast/parser/move-during-parsing-expected.txt:
+        * fast/parser/resources/script-modify-page-inner.html: Added.
+        * fast/parser/script-modify-page-outer-expected.txt: Added.
+        * fast/parser/script-modify-page-outer.html: Added.
+
 2010-11-10  Fumitoshi Ukai  <ukai@chromium.org>
 
         Unreviewed, updating Chromium expectations.
index a7d97d3..4861609 100644 (file)
@@ -1,4 +1,4 @@
-ALERT: parser/resources/move-during-parsing-iframe.html
+ALERT: parser/move-during-parsing.html
 
 This text should not show inside the iframe. It should show inside the parent. Furthermore, there should be text saying "Middle of Page" and then "End of Page" below (also in the parent).
 
diff --git a/LayoutTests/fast/parser/resources/script-modify-page-inner.html b/LayoutTests/fast/parser/resources/script-modify-page-inner.html
new file mode 100644 (file)
index 0000000..991e2e6
--- /dev/null
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div>
+<script>
+if (parent.document.adoptNode)
+  parent.document.body.appendChild(parent.document.adoptNode(document.getElementsByTagName("div")[0]));
+else
+  parent.document.body.appendChild(document.getElementsByTagName("div")[0]);
+</script>
+<script>
+alert('should be outer: ' + document.URL.match(/parser.*/));
+</script>
+</div>
+<script>
+alert('should be inner: ' + document.URL.match(/parser.*/));
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/parser/script-modify-page-outer-expected.txt b/LayoutTests/fast/parser/script-modify-page-outer-expected.txt
new file mode 100644 (file)
index 0000000..79eb31c
--- /dev/null
@@ -0,0 +1,4 @@
+ALERT: should be outer: parser/script-modify-page-outer.html
+ALERT: should be inner: parser/resources/script-modify-page-inner.html
+
+DONE
diff --git a/LayoutTests/fast/parser/script-modify-page-outer.html b/LayoutTests/fast/parser/script-modify-page-outer.html
new file mode 100644 (file)
index 0000000..d85adee
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<script>
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+</script>
+<body onload="document.body.appendChild(document.createTextNode('DONE'));">
+<iframe src="resources/script-modify-page-inner.html"></iframe>
+</body>
+</html>
index d5fa5bf..7b27aae 100644 (file)
@@ -1,3 +1,23 @@
+2010-11-10  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Reviewed by Adam Barth.
+
+        [HTML5] 10.2.8.4 Scripts that modify the page as it is being parsed
+        https://bugs.webkit.org/show_bug.cgi?id=49364
+
+        Fixed HTMLScriptRunner's executeScript to use the ScriptController of the frame to which script element belongs
+        as supposed to that of the frame associated with the HTMLScriptRunner.
+
+        See also: http://www.whatwg.org/specs/web-apps/current-work/#scripts-that-modify-the-page-as-it-is-being-parsed
+
+        Test: fast/parser/script-modify-page-outer.html
+
+        * html/parser/HTMLScriptRunner.cpp:
+        (WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent): Calls executeScript.
+        (WebCore::HTMLScriptRunner::executeScript): Uses the correct ScriptController instance.
+        (WebCore::HTMLScriptRunner::runScript): Call executeScript.
+        * html/parser/HTMLScriptRunner.h:
+
 2010-11-10  Dan Bernstein  <mitz@apple.com>
 
         Style fix I said I’d make then forgot to make.
index 61f673a..d8a96c1 100644 (file)
@@ -140,20 +140,22 @@ void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi
         if (errorOccurred)
             scriptElement->dispatchEvent(createScriptErrorEvent());
         else {
-            executeScript(sourceCode);
+            executeScript(scriptElement.get(), sourceCode);
             scriptElement->dispatchEvent(createScriptLoadEvent());
         }
     }
     ASSERT(!m_scriptNestingLevel);
 }
 
-void HTMLScriptRunner::executeScript(const ScriptSourceCode& sourceCode) const
+void HTMLScriptRunner::executeScript(Element* element, const ScriptSourceCode& sourceCode) const
 {
-    ASSERT(m_document);
+    ASSERT(element);
+    ASSERT(element->document());
     ASSERT(isExecutingScript());
-    if (!m_document->frame())
+    Frame* frame = element->document()->frame();
+    if (!frame)
         return;
-    m_document->frame()->script()->executeScript(sourceCode);
+    frame->script()->executeScript(sourceCode);
 }
 
 void HTMLScriptRunner::watchForLoad(PendingScript& pendingScript)
@@ -318,7 +320,7 @@ void HTMLScriptRunner::runScript(Element* script, const TextPosition1& scriptSta
             // ASSERT(document()->haveStylesheetsLoaded());
             ASSERT(isExecutingScript());
             ScriptSourceCode sourceCode(script->textContent(), documentURLForScriptExecution(m_document), scriptStartPosition);
-            executeScript(sourceCode);
+            executeScript(script, sourceCode);
         }
     }
 }
index 2df295f..df41828 100644 (file)
@@ -69,7 +69,7 @@ private:
 
     void executeParsingBlockingScript();
     void executePendingScriptAndDispatchEvent(PendingScript&);
-    void executeScript(const ScriptSourceCode&) const;
+    void executeScript(Element*, const ScriptSourceCode&) const;
     bool haveParsingBlockingScript() const;
     bool executeParsingBlockingScripts();