Title: [98724] trunk
Revision
98724
Author
pfeld...@chromium.org
Date
2011-10-28 06:27:32 -0700 (Fri, 28 Oct 2011)

Log Message

Reset line numbers for scripts generated with document.write.
https://bugs.webkit.org/show_bug.cgi?id=71099

Reviewed by Yury Semikhatsky.

Source/_javascript_Core:

* wtf/text/TextPosition.h:
(WTF::OrdinalNumber::OrdinalNumber):

Source/WebCore:

Test: http/tests/inspector-enabled/document-write.html

* dom/Document.h:
(WebCore::Document::isInDocumentWrite):
* dom/ScriptElement.cpp:
(WebCore::ScriptElement::prepareScript):

LayoutTests:

* http/tests/inspector-enabled/document-write-expected.txt: Added.
* http/tests/inspector-enabled/document-write.html: Added.
* platform/chromium-win/fast/dom/nested-script-exceptions-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (98723 => 98724)


--- trunk/LayoutTests/ChangeLog	2011-10-28 13:10:36 UTC (rev 98723)
+++ trunk/LayoutTests/ChangeLog	2011-10-28 13:27:32 UTC (rev 98724)
@@ -1,3 +1,14 @@
+2011-10-28  Pavel Feldman  <pfeld...@google.com>
+
+        Reset line numbers for scripts generated with document.write.
+        https://bugs.webkit.org/show_bug.cgi?id=71099
+
+        Reviewed by Yury Semikhatsky.
+
+        * http/tests/inspector-enabled/document-write-expected.txt: Added.
+        * http/tests/inspector-enabled/document-write.html: Added.
+        * platform/chromium-win/fast/dom/nested-script-exceptions-expected.txt:
+
 2011-10-28  Yury Semikhatsky  <yu...@chromium.org>
 
         Unreviewed. Unsupress css3/font-feature-settings-rendering.html as it should

Added: trunk/LayoutTests/http/tests/inspector-enabled/document-write-expected.txt (0 => 98724)


--- trunk/LayoutTests/http/tests/inspector-enabled/document-write-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector-enabled/document-write-expected.txt	2011-10-28 13:27:32 UTC (rev 98724)
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: line 4: Line 4
+CONSOLE MESSAGE: line 5: Line 5
+CONSOLE MESSAGE: line 1: Line 1 in document.write
+CONSOLE MESSAGE: line 4: Line 4 in document.write
+CONSOLE MESSAGE: line 7: Line 7
+CONSOLE MESSAGE: line 25: Line 25
+CONSOLE MESSAGE: line 1: script element
+CONSOLE MESSAGE: line 1: document.write from onload
+
Property changes on: trunk/LayoutTests/http/tests/inspector-enabled/document-write-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/http/tests/inspector-enabled/document-write.html (0 => 98724)


--- trunk/LayoutTests/http/tests/inspector-enabled/document-write.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector-enabled/document-write.html	2011-10-28 13:27:32 UTC (rev 98724)
@@ -0,0 +1,31 @@
+<html>
+<head>
+
+<script>console.log("Line 4");</script>
+<script>console.log("Line 5");</script>
+<script>document.write("<scrip" + "t>console.log(\"Line 1 in document.write\");\n\n\nconsole.log(\"Line 4 in document.write\");</sc" + "ript>");</script>
+<script>console.log("Line 7");</script>
+
+<script>
+
+function onload()
+{
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    var script = document.createElement("script");
+    script.textContent = "console.log(\"script element\")";
+    document.head.appendChild(script);
+    document.write("<scrip" + "t>console.log(\"document.write from onload\");</sc" + "ript>");
+}
+
+</script>
+</head>
+
+<body _onload_="console.log('Line 25'); onload();">
+<p>
+Tests that console reports zero line number for scripts generated with document.write. See https://bugs.webkit.org/show_bug.cgi?id=71099.
+</p>
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/inspector-enabled/document-write.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/platform/chromium-win/fast/dom/nested-script-exceptions-expected.txt (98723 => 98724)


--- trunk/LayoutTests/platform/chromium-win/fast/dom/nested-script-exceptions-expected.txt	2011-10-28 13:10:36 UTC (rev 98723)
+++ trunk/LayoutTests/platform/chromium-win/fast/dom/nested-script-exceptions-expected.txt	2011-10-28 13:27:32 UTC (rev 98724)
@@ -1,2 +1,2 @@
-CONSOLE MESSAGE: line 10: Uncaught Badness 10,000
+CONSOLE MESSAGE: line 1: Uncaught Badness 10,000
 This test checks that exceptions in nested scripts are logged properly. An exception named "Badness 10,000" should be logged properly.

Modified: trunk/Source/_javascript_Core/ChangeLog (98723 => 98724)


--- trunk/Source/_javascript_Core/ChangeLog	2011-10-28 13:10:36 UTC (rev 98723)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-10-28 13:27:32 UTC (rev 98724)
@@ -1,3 +1,13 @@
+2011-10-28  Pavel Feldman  <pfeld...@google.com>
+
+        Reset line numbers for scripts generated with document.write.
+        https://bugs.webkit.org/show_bug.cgi?id=71099
+
+        Reviewed by Yury Semikhatsky.
+
+        * wtf/text/TextPosition.h:
+        (WTF::OrdinalNumber::OrdinalNumber):
+
 2011-10-27  Daniel Bates  <dba...@rim.com>
 
         CMake: Add support to optionally install the built _javascript_ shell

Modified: trunk/Source/_javascript_Core/wtf/text/TextPosition.h (98723 => 98724)


--- trunk/Source/_javascript_Core/wtf/text/TextPosition.h	2011-10-28 13:10:36 UTC (rev 98723)
+++ trunk/Source/_javascript_Core/wtf/text/TextPosition.h	2011-10-28 13:27:32 UTC (rev 98724)
@@ -36,7 +36,7 @@
 public:
     static OrdinalNumber fromZeroBasedInt(int zeroBasedInt) { return OrdinalNumber(zeroBasedInt); }
     static OrdinalNumber fromOneBasedInt(int oneBasedInt) { return OrdinalNumber(oneBasedInt - 1); }
-    OrdinalNumber() { }
+    OrdinalNumber() : m_zeroBasedValue(0) { }
 
     int zeroBasedInt() const { return m_zeroBasedValue; }
     int oneBasedInt() const { return m_zeroBasedValue + 1; }

Modified: trunk/Source/WebCore/ChangeLog (98723 => 98724)


--- trunk/Source/WebCore/ChangeLog	2011-10-28 13:10:36 UTC (rev 98723)
+++ trunk/Source/WebCore/ChangeLog	2011-10-28 13:27:32 UTC (rev 98724)
@@ -1,3 +1,17 @@
+2011-10-28  Pavel Feldman  <pfeld...@google.com>
+
+        Reset line numbers for scripts generated with document.write.
+        https://bugs.webkit.org/show_bug.cgi?id=71099
+
+        Reviewed by Yury Semikhatsky.
+
+        Test: http/tests/inspector-enabled/document-write.html
+
+        * dom/Document.h:
+        (WebCore::Document::isInDocumentWrite):
+        * dom/ScriptElement.cpp:
+        (WebCore::ScriptElement::prepareScript):
+
 2011-10-28  Adam Roben  <aro...@apple.com>
 
         Mac build fix after r98711

Modified: trunk/Source/WebCore/dom/Document.h (98723 => 98724)


--- trunk/Source/WebCore/dom/Document.h	2011-10-28 13:10:36 UTC (rev 98723)
+++ trunk/Source/WebCore/dom/Document.h	2011-10-28 13:27:32 UTC (rev 98724)
@@ -1105,6 +1105,8 @@
     void removeCachedMicroDataItemList(MicroDataItemList*, const String&);
 #endif
     
+    bool isInDocumentWrite() { return m_writeRecursionDepth > 0; }
+
 protected:
     Document(Frame*, const KURL&, bool isXHTML, bool isHTML);
 

Modified: trunk/Source/WebCore/dom/ScriptElement.cpp (98723 => 98724)


--- trunk/Source/WebCore/dom/ScriptElement.cpp	2011-10-28 13:10:36 UTC (rev 98723)
+++ trunk/Source/WebCore/dom/ScriptElement.cpp	2011-10-28 13:27:32 UTC (rev 98724)
@@ -198,14 +198,15 @@
     m_alreadyStarted = true;
 
     // FIXME: If script is parser inserted, verify it's still in the original document.
+    Document* document = m_element->document();
 
     // FIXME: Eventually we'd like to evaluate scripts which are inserted into a
     // viewless document but this'll do for now.
     // See http://bugs.webkit.org/show_bug.cgi?id=5727
-    if (!m_element->document()->frame())
+    if (!document->frame())
         return false;
 
-    if (!m_element->document()->frame()->script()->canExecuteScripts(AboutToExecuteScript))
+    if (!document->frame()->script()->canExecuteScripts(AboutToExecuteScript))
         return false;
 
     Node* ancestor = m_element->parentNode();
@@ -223,7 +224,7 @@
     if (!charsetAttributeValue().isEmpty())
         m_characterEncoding = charsetAttributeValue();
     else
-        m_characterEncoding = m_element->document()->charset();
+        m_characterEncoding = document->charset();
 
     if (hasSourceAttribute())
         if (!requestScript(sourceAttributeValue()))
@@ -234,17 +235,20 @@
         m_willBeParserExecuted = true;
     } else if (hasSourceAttribute() && m_parserInserted && !asyncAttributeValue())
         m_willBeParserExecuted = true;
-    else if (!hasSourceAttribute() && m_parserInserted && !m_element->document()->haveStylesheetsLoaded()) {
+    else if (!hasSourceAttribute() && m_parserInserted && !document->haveStylesheetsLoaded()) {
         m_willBeParserExecuted = true;
         m_readyToBeParserExecuted = true;
     } else if (hasSourceAttribute() && !asyncAttributeValue() && !m_forceAsync) {
         m_willExecuteInOrder = true;
-        m_element->document()->scriptRunner()->queueScriptForExecution(this, m_cachedScript, ScriptRunner::IN_ORDER_EXECUTION);
+        document->scriptRunner()->queueScriptForExecution(this, m_cachedScript, ScriptRunner::IN_ORDER_EXECUTION);
         m_cachedScript->addClient(this);
     } else if (hasSourceAttribute())
         m_cachedScript->addClient(this);
-    else
-        executeScript(ScriptSourceCode(scriptContent(), m_element->document()->url(), scriptStartPosition));
+    else {
+        // Reset line numbering for nested writes.
+        TextPosition position = document->isInDocumentWrite() ? TextPosition() : scriptStartPosition;
+        executeScript(ScriptSourceCode(scriptContent(), document->url(), position));
+    }
 
     return true;
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to