[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

rniwa at webkit.org rniwa at webkit.org
Wed Dec 22 15:47:06 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 6efc52e957af049b957883a48e792681c6c1c720
Author: rniwa at webkit.org <rniwa at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Nov 12 07:21:41 2010 +0000

    2010-11-11  Ryosuke Niwa  <rniwa at webkit.org>
    
            Reviewed by Darin Adler.
    
            Script runs more than once after a clone
            https://bugs.webkit.org/show_bug.cgi?id=48966
    
            The bug was caused by cloneElementWithoutChildren's not propagating isEvaluated flag,
            which indicates whether or not the script has already started, and the fact
            neither HTMLScriptRunner nor XMLDocumentParser was setting isEvaluated flag to true.
    
            Fixed the bug by making cloneElementWithoutChildren call a virtual cloneElementWithoutAttributesAndChildren,
            and override it in HTMLScriptElement and SVGScriptElement to propagate isEvaluated flag,
            and replacing direct access to ScriptController by a call to new ScriptElementData::executeScript,
            which updates the isEvaluated flag properly.
    
            See also: http://www.whatwg.org/specs/web-apps/current-work/#already-started
    
            Tests: fast/dom/script-clone-rerun-self.html
                   fast/dom/script-clone-rerun.html
                   svg/dom/SVGScriptElement/script-clone-rerun-self.svg
                   svg/dom/SVGScriptElement/script-clone-rerun.svg
    
            * dom/Element.cpp:
            (WebCore::Element::cloneElementWithoutChildren): Calls cloneElementWithoutChildren.
            (WebCore::Element::cloneElementWithoutAttributesAndChildren): Extracted from cloneElementWithoutChildren.
            * dom/Element.h:
            * dom/ScriptElement.cpp:
            (WebCore::ScriptElementData::ScriptElementData): Added isEvaluated flag to the argument list.
            (WebCore::ScriptElementData::evaluateScript): Extracted from HTMLScriptRunner::executeScript.
            (WebCore::ScriptElementData::executeScript): Renamed evaluated to isEvaluated.
            (WebCore::ScriptElementData::ignoresLoadRequest): Renamed evaluated to isEvaluated.
            * dom/ScriptElement.h: Renamed evaluated to isEvaluated.
            (WebCore::ScriptElementData::isEvaluated): Added.
            * dom/XMLDocumentParserLibxml2.cpp:
            (WebCore::XMLDocumentParser::endElementNs): Calls ScriptElement::executeScript.
            * html/HTMLScriptElement.cpp:
            (WebCore::HTMLScriptElement::HTMLScriptElement): Added isEvaluated flag to the argument list.
            (WebCore::HTMLScriptElement::create): Calls the constructor with the isEvaluated flag set to false.
            (WebCore::HTMLScriptElement::cloneElementWithoutAttributesAndChildren): Propagates isEvaluated.
            (WebCore::HTMLScriptElement::executeScript): Added; calls ScriptElementData::executeScript.
            * html/HTMLScriptElement.h:
            * html/parser/HTMLScriptRunner.cpp:
            (WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent): Added an assertion that was lost
            in extracting ScriptElementData::executeScript.
            (WebCore::HTMLScriptRunner::runScript): Calls ScriptElementData::executeScript.
            * html/parser/HTMLScriptRunner.h:
            * svg/SVGScriptElement.cpp:
            (WebCore::SVGScriptElement::SVGScriptElement): Added isEvaluated flag to the argument list.
            (WebCore::SVGScriptElement::create): Calls the constructor with the isEvaluated flag set to false.
            (WebCore::SVGScriptElement::cloneElementWithoutAttributesAndChildren): Propagates isEvaluated.
            (WebCore::SVGScriptElement::executeScript): Added; calls ScriptElementData::executeScript.
            * svg/SVGScriptElement.h:
    2010-11-11  Ryosuke Niwa  <rniwa at webkit.org>
    
            Reviewed by Darin Adler.
    
            Script runs more than once after a clone
            https://bugs.webkit.org/show_bug.cgi?id=48966
    
            Added tests to ensure WebKit does not evaluate the script of a clone of
            a script element that has already been evaluated (has already started).
    
            See also: http://www.whatwg.org/specs/web-apps/current-work/#already-started
    
            * fast/dom/script-clone-rerun-expected.txt: Added.
            * fast/dom/script-clone-rerun-self-expected.txt: Added.
            * fast/dom/script-clone-rerun-self.html: Added.
            * fast/dom/script-clone-rerun.html: Added.
            * svg/dom/SVGScriptElement/script-clone-rerun-expected.txt: Added.
            * svg/dom/SVGScriptElement/script-clone-rerun-self-expected.txt: Added.
            * svg/dom/SVGScriptElement/script-clone-rerun-self.svg: Added.
            * svg/dom/SVGScriptElement/script-clone-rerun.svg: Added.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@71895 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index f57bbd6..d687bc6 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,24 @@
+2010-11-11  Ryosuke Niwa  <rniwa at webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Script runs more than once after a clone
+        https://bugs.webkit.org/show_bug.cgi?id=48966
+
+        Added tests to ensure WebKit does not evaluate the script of a clone of
+        a script element that has already been evaluated (has already started).
+
+        See also: http://www.whatwg.org/specs/web-apps/current-work/#already-started
+
+        * fast/dom/script-clone-rerun-expected.txt: Added.
+        * fast/dom/script-clone-rerun-self-expected.txt: Added.
+        * fast/dom/script-clone-rerun-self.html: Added.
+        * fast/dom/script-clone-rerun.html: Added.
+        * svg/dom/SVGScriptElement/script-clone-rerun-expected.txt: Added.
+        * svg/dom/SVGScriptElement/script-clone-rerun-self-expected.txt: Added.
+        * svg/dom/SVGScriptElement/script-clone-rerun-self.svg: Added.
+        * svg/dom/SVGScriptElement/script-clone-rerun.svg: Added.
+
 2010-11-11  Mihai Parparita  <mihaip at chromium.org>
 
         Unreviewed Chromium rebaseline.
diff --git a/LayoutTests/fast/dom/script-clone-rerun-expected.txt b/LayoutTests/fast/dom/script-clone-rerun-expected.txt
new file mode 100644
index 0000000..dd051bb
--- /dev/null
+++ b/LayoutTests/fast/dom/script-clone-rerun-expected.txt
@@ -0,0 +1,3 @@
+This tests cloning a script element that has already started and inserting it into the document does not re-run the script. You should see PASS:
+
+PASS
diff --git a/LayoutTests/fast/dom/script-clone-rerun-self-expected.txt b/LayoutTests/fast/dom/script-clone-rerun-self-expected.txt
new file mode 100644
index 0000000..f0eb844
--- /dev/null
+++ b/LayoutTests/fast/dom/script-clone-rerun-self-expected.txt
@@ -0,0 +1,3 @@
+This test runs a script that clones and inserts its script element. The script should run exactly once and print PASS:
+
+PASS
diff --git a/LayoutTests/fast/dom/script-clone-rerun-self.html b/LayoutTests/fast/dom/script-clone-rerun-self.html
new file mode 100644
index 0000000..7eb227c
--- /dev/null
+++ b/LayoutTests/fast/dom/script-clone-rerun-self.html
@@ -0,0 +1,33 @@
+<!DOCTYPE>
+<html>
+<head>
+<script>
+var i = 0;
+</script>
+</head>
+<body>
+<p>This test runs a script that clones and inserts its script element. The script should run exactly once and print PASS:</p>
+<div><script>
+i++;
+
+var script = document.getElementsByTagName('script')[1];
+var div = script.parentNode;
+div.removeChild(script);
+div.appendChild(script.cloneNode(true));
+
+</script></div>
+<script>
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+result = 'PASS';
+if (i == 2)
+  result = 'FAIL: script ran twice';
+else if (i > 2)
+  result = 'FAIL: script ran ' + i + ' times';
+document.body.appendChild(document.createTextNode(result));
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/script-clone-rerun.html b/LayoutTests/fast/dom/script-clone-rerun.html
new file mode 100644
index 0000000..3c956e2
--- /dev/null
+++ b/LayoutTests/fast/dom/script-clone-rerun.html
@@ -0,0 +1,30 @@
+<!DOCTYPE>
+<html>
+<head>
+<script>
+var i = 0;
+</script>
+</head>
+<body>
+<p>This tests cloning a script element that has already started and inserting it into the document does not re-run the script. You should see PASS:</p>
+<div><script> i++ </script></div>
+<script>
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+var script = document.getElementsByTagName('script')[1];
+var div = script.parentNode;
+div.removeChild(script);
+div.appendChild(script.cloneNode(true));
+
+result = 'PASS';
+if (i == 2)
+  result = 'FAIL: script ran twice';
+else if (i > 2)
+  result = 'FAIL: script ran ' + i + ' times';
+document.body.appendChild(document.createTextNode(result));
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun-expected.txt b/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun-expected.txt
new file mode 100644
index 0000000..78b9b7e
--- /dev/null
+++ b/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun-expected.txt
@@ -0,0 +1,2 @@
+This tests cloning a script element that has already started and inserting it into the document does not re-run the script. You should see PASS:
+PASS
diff --git a/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun-self-expected.txt b/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun-self-expected.txt
new file mode 100644
index 0000000..ab9b748
--- /dev/null
+++ b/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun-self-expected.txt
@@ -0,0 +1,2 @@
+This test runs a script that clones and inserts its script element. The script should run exactly once and print PASS:
+PASS
diff --git a/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun-self.svg b/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun-self.svg
new file mode 100644
index 0000000..1fcbf96
--- /dev/null
+++ b/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun-self.svg
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xhtml="http://www.w3.org/1999/xhtml">
+<defs>
+<script>
+var i = 0;
+</script>
+</defs>
+<text x="15" y="30" font-size="15">This test runs a script that clones and inserts its script element. The script should run exactly once and print PASS:</text>
+<defs>
+<script type="text/javascript">
+i++;
+
+var script = document.getElementsByTagName('script')[1];
+var defs = script.parentNode;
+defs.removeChild(script);
+defs.appendChild(script.cloneNode(true));
+
+</script></defs>
+<defs><script>
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+result = 'PASS';
+if (i == 2)
+  result = 'FAIL: script ran twice';
+else if (i > 2)
+  result = 'FAIL: script ran ' + i + ' times';
+  
+var textElement = document.createElementNS("http://www.w3.org/2000/svg", "text");
+textElement.textContent = result;
+textElement.setAttribute('x', 15);
+textElement.setAttribute('y', 45+10);
+textElement.setAttribute('font-size', 15);
+document.getElementsByTagName('svg')[0].appendChild(textElement);
+
+</script></defs>
+</svg>
diff --git a/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun.svg b/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun.svg
new file mode 100644
index 0000000..b012114
--- /dev/null
+++ b/LayoutTests/svg/dom/SVGScriptElement/script-clone-rerun.svg
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xhtml="http://www.w3.org/1999/xhtml">
+<defs>
+<script>
+var i = 0;
+</script>
+</defs>
+<text x="15" y="30" font-size="15">This tests cloning a script element that has already started and inserting it into the document does not re-run the script. You should see PASS:</text>
+<defs><script> i++; </script></defs>
+<defs>
+<script type="text/javascript">
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+var script = document.getElementsByTagName('script')[1];
+var defs = script.parentNode;
+defs.removeChild(script);
+defs.appendChild(script.cloneNode(true));
+
+result = 'PASS';
+if (i == 2)
+  result = 'FAIL: script ran twice';
+else if (i > 2)
+  result = 'FAIL: script ran ' + i + ' times';
+
+var textElement = document.createElementNS("http://www.w3.org/2000/svg", "text");
+textElement.textContent = result;
+textElement.setAttribute('x', 15);
+textElement.setAttribute('y', 45+10);
+textElement.setAttribute('font-size', 15);
+document.getElementsByTagName('svg')[0].appendChild(textElement);
+
+</script>
+</defs>
+</svg>
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index c303c31..5aec9b6 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,57 @@
+2010-11-11  Ryosuke Niwa  <rniwa at webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Script runs more than once after a clone
+        https://bugs.webkit.org/show_bug.cgi?id=48966
+
+        The bug was caused by cloneElementWithoutChildren's not propagating isEvaluated flag,
+        which indicates whether or not the script has already started, and the fact
+        neither HTMLScriptRunner nor XMLDocumentParser was setting isEvaluated flag to true.
+
+        Fixed the bug by making cloneElementWithoutChildren call a virtual cloneElementWithoutAttributesAndChildren,
+        and override it in HTMLScriptElement and SVGScriptElement to propagate isEvaluated flag,
+        and replacing direct access to ScriptController by a call to new ScriptElementData::executeScript,
+        which updates the isEvaluated flag properly.
+
+        See also: http://www.whatwg.org/specs/web-apps/current-work/#already-started
+
+        Tests: fast/dom/script-clone-rerun-self.html
+               fast/dom/script-clone-rerun.html
+               svg/dom/SVGScriptElement/script-clone-rerun-self.svg
+               svg/dom/SVGScriptElement/script-clone-rerun.svg
+
+        * dom/Element.cpp:
+        (WebCore::Element::cloneElementWithoutChildren): Calls cloneElementWithoutChildren.
+        (WebCore::Element::cloneElementWithoutAttributesAndChildren): Extracted from cloneElementWithoutChildren.
+        * dom/Element.h:
+        * dom/ScriptElement.cpp:
+        (WebCore::ScriptElementData::ScriptElementData): Added isEvaluated flag to the argument list.
+        (WebCore::ScriptElementData::evaluateScript): Extracted from HTMLScriptRunner::executeScript.
+        (WebCore::ScriptElementData::executeScript): Renamed evaluated to isEvaluated.
+        (WebCore::ScriptElementData::ignoresLoadRequest): Renamed evaluated to isEvaluated.
+        * dom/ScriptElement.h: Renamed evaluated to isEvaluated.
+        (WebCore::ScriptElementData::isEvaluated): Added.
+        * dom/XMLDocumentParserLibxml2.cpp:
+        (WebCore::XMLDocumentParser::endElementNs): Calls ScriptElement::executeScript.
+        * html/HTMLScriptElement.cpp:
+        (WebCore::HTMLScriptElement::HTMLScriptElement): Added isEvaluated flag to the argument list.
+        (WebCore::HTMLScriptElement::create): Calls the constructor with the isEvaluated flag set to false.
+        (WebCore::HTMLScriptElement::cloneElementWithoutAttributesAndChildren): Propagates isEvaluated.
+        (WebCore::HTMLScriptElement::executeScript): Added; calls ScriptElementData::executeScript.
+        * html/HTMLScriptElement.h:
+        * html/parser/HTMLScriptRunner.cpp:
+        (WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent): Added an assertion that was lost
+        in extracting ScriptElementData::executeScript.
+        (WebCore::HTMLScriptRunner::runScript): Calls ScriptElementData::executeScript.
+        * html/parser/HTMLScriptRunner.h:
+        * svg/SVGScriptElement.cpp:
+        (WebCore::SVGScriptElement::SVGScriptElement): Added isEvaluated flag to the argument list.
+        (WebCore::SVGScriptElement::create): Calls the constructor with the isEvaluated flag set to false.
+        (WebCore::SVGScriptElement::cloneElementWithoutAttributesAndChildren): Propagates isEvaluated.
+        (WebCore::SVGScriptElement::executeScript): Added; calls ScriptElementData::executeScript.
+        * svg/SVGScriptElement.h:
+
 2010-11-11  Shinichiro Hamaji  <hamaji at chromium.org>
 
         Reviewed by Darin Adler.
diff --git a/WebCore/dom/Element.cpp b/WebCore/dom/Element.cpp
index 4138a16..f635300 100644
--- a/WebCore/dom/Element.cpp
+++ b/WebCore/dom/Element.cpp
@@ -159,7 +159,7 @@ PassRefPtr<Element> Element::cloneElementWithChildren()
 
 PassRefPtr<Element> Element::cloneElementWithoutChildren()
 {
-    RefPtr<Element> clone = document()->createElement(tagQName(), false);
+    RefPtr<Element> clone = cloneElementWithoutAttributesAndChildren();
     // This will catch HTML elements in the wrong namespace that are not correctly copied.
     // This is a sanity check as HTML overloads some of the DOM methods.
     ASSERT(isHTMLElement() == clone->isHTMLElement());
@@ -173,6 +173,11 @@ PassRefPtr<Element> Element::cloneElementWithoutChildren()
     return clone.release();
 }
 
+PassRefPtr<Element> Element::cloneElementWithoutAttributesAndChildren() const
+{
+    return document()->createElement(tagQName(), false);
+}
+
 void Element::removeAttribute(const QualifiedName& name, ExceptionCode& ec)
 {
     if (m_attributeMap) {
diff --git a/WebCore/dom/Element.h b/WebCore/dom/Element.h
index 1a85650..7d4b94c 100644
--- a/WebCore/dom/Element.h
+++ b/WebCore/dom/Element.h
@@ -377,6 +377,7 @@ private:
     // cloneNode is private so that non-virtual cloneElementWithChildren and cloneElementWithoutChildren
     // are used instead.
     virtual PassRefPtr<Node> cloneNode(bool deep);
+    virtual PassRefPtr<Element> cloneElementWithoutAttributesAndChildren() const;
 
     QualifiedName m_tagName;
     virtual NodeRareData* createRareData();
diff --git a/WebCore/dom/ScriptElement.cpp b/WebCore/dom/ScriptElement.cpp
index 28c7594..d7520cd 100644
--- a/WebCore/dom/ScriptElement.cpp
+++ b/WebCore/dom/ScriptElement.cpp
@@ -130,13 +130,13 @@ static bool isSupportedJavaScriptLanguage(const String& language)
 }
 
 // ScriptElementData
-ScriptElementData::ScriptElementData(ScriptElement* scriptElement, Element* element)
+ScriptElementData::ScriptElementData(ScriptElement* scriptElement, Element* element, bool isEvaluated)
     : m_scriptElement(scriptElement)
     , m_element(element)
     , m_cachedScript(0)
     , m_createdByParser(false)
     , m_requested(false)
-    , m_evaluated(false)
+    , m_isEvaluated(isEvaluated)
     , m_firedLoad(false)
 {
     ASSERT(m_scriptElement);
@@ -180,7 +180,7 @@ void ScriptElementData::requestScript(const String& sourceUrl)
 
 void ScriptElementData::evaluateScript(const ScriptSourceCode& sourceCode)
 {
-    if (m_evaluated || sourceCode.isEmpty() || !shouldExecuteAsJavaScript())
+    if (m_isEvaluated || sourceCode.isEmpty() || !shouldExecuteAsJavaScript())
         return;
 
     RefPtr<Document> document = m_element->document();
@@ -189,7 +189,7 @@ void ScriptElementData::evaluateScript(const ScriptSourceCode& sourceCode)
         if (!frame->script()->canExecuteScripts(AboutToExecuteScript))
             return;
 
-        m_evaluated = true;
+        m_isEvaluated = true;
 
         // http://www.whatwg.org/specs/web-apps/current-work/#script
 
@@ -205,6 +205,21 @@ void ScriptElementData::evaluateScript(const ScriptSourceCode& sourceCode)
     }
 }
 
+void ScriptElementData::executeScript(const ScriptSourceCode& sourceCode)
+{
+    if (m_isEvaluated || sourceCode.isEmpty())
+        return;
+    RefPtr<Document> document = m_element->document();
+    ASSERT(document);
+    Frame* frame = document->frame();
+    if (!frame)
+        return;
+
+    m_isEvaluated = true;
+
+    frame->script()->executeScript(sourceCode);
+}
+
 void ScriptElementData::stopLoadRequest()
 {
     if (m_cachedScript) {
@@ -234,7 +249,7 @@ void ScriptElementData::notifyFinished(CachedResource* o)
 
 bool ScriptElementData::ignoresLoadRequest() const
 {
-    return m_evaluated || m_requested || m_createdByParser || !m_element->inDocument();
+    return m_isEvaluated || m_requested || m_createdByParser || !m_element->inDocument();
 }
 
 bool ScriptElementData::shouldExecuteAsJavaScript() const
diff --git a/WebCore/dom/ScriptElement.h b/WebCore/dom/ScriptElement.h
index c663e43..b576468 100644
--- a/WebCore/dom/ScriptElement.h
+++ b/WebCore/dom/ScriptElement.h
@@ -54,6 +54,7 @@ public:
     virtual String scriptCharset() const = 0;
 
     virtual bool shouldExecuteAsJavaScript() const = 0;
+    virtual void executeScript(const ScriptSourceCode&) = 0;
 
 protected:
     // Helper functions used by our parent classes.
@@ -68,7 +69,7 @@ protected:
 // and pass it to the static helper functions in ScriptElement
 class ScriptElementData : private CachedResourceClient {
 public:
-    ScriptElementData(ScriptElement*, Element*);
+    ScriptElementData(ScriptElement*, Element*, bool isEvaluated);
     virtual ~ScriptElementData();
 
     bool ignoresLoadRequest() const;
@@ -78,6 +79,7 @@ public:
     String scriptCharset() const;
     bool isAsynchronous() const;
     bool isDeferred() const;
+    bool isEvaluated() const { return m_isEvaluated; }
 
     Element* element() const { return m_element; }
     bool createdByParser() const { return m_createdByParser; }
@@ -87,6 +89,7 @@ public:
 
     void requestScript(const String& sourceUrl);
     void evaluateScript(const ScriptSourceCode&);
+    void executeScript(const ScriptSourceCode&);
     void stopLoadRequest();
 
     void execute(CachedScript*);
@@ -100,7 +103,7 @@ private:
     CachedResourceHandle<CachedScript> m_cachedScript;
     bool m_createdByParser; // HTML5: "parser-inserted"
     bool m_requested;
-    bool m_evaluated; // HTML5: "already started"
+    bool m_isEvaluated; // HTML5: "already started"
     bool m_firedLoad;
 };
 
diff --git a/WebCore/dom/XMLDocumentParserLibxml2.cpp b/WebCore/dom/XMLDocumentParserLibxml2.cpp
index ef5f3e4..7a3285f 100644
--- a/WebCore/dom/XMLDocumentParserLibxml2.cpp
+++ b/WebCore/dom/XMLDocumentParserLibxml2.cpp
@@ -910,7 +910,7 @@ void XMLDocumentParser::endElementNs()
             } else
                 m_scriptElement = 0;
         } else
-            m_view->frame()->script()->executeScript(ScriptSourceCode(scriptElement->scriptContent(), document()->url(), m_scriptStartPosition));
+            scriptElement->executeScript(ScriptSourceCode(scriptElement->scriptContent(), document()->url(), m_scriptStartPosition));
 
         // JavaScript may have detached the parser
         if (isDetached())
diff --git a/WebCore/html/HTMLScriptElement.cpp b/WebCore/html/HTMLScriptElement.cpp
index 9e776e6..25c535d 100644
--- a/WebCore/html/HTMLScriptElement.cpp
+++ b/WebCore/html/HTMLScriptElement.cpp
@@ -35,9 +35,9 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-inline HTMLScriptElement::HTMLScriptElement(const QualifiedName& tagName, Document* document, bool createdByParser)
+inline HTMLScriptElement::HTMLScriptElement(const QualifiedName& tagName, Document* document, bool createdByParser, bool isEvaluated)
     : HTMLElement(tagName, document)
-    , m_data(this, this)
+    , m_data(this, this, isEvaluated)
 {
     ASSERT(hasTagName(scriptTag));
     m_data.setCreatedByParser(createdByParser);
@@ -45,7 +45,7 @@ inline HTMLScriptElement::HTMLScriptElement(const QualifiedName& tagName, Docume
 
 PassRefPtr<HTMLScriptElement> HTMLScriptElement::create(const QualifiedName& tagName, Document* document, bool createdByParser)
 {
-    return adoptRef(new HTMLScriptElement(tagName, document, createdByParser));
+    return adoptRef(new HTMLScriptElement(tagName, document, createdByParser, false));
 }
 
 bool HTMLScriptElement::isURLAttribute(Attribute* attr) const
@@ -194,4 +194,14 @@ void HTMLScriptElement::dispatchErrorEvent()
     dispatchEvent(Event::create(eventNames().errorEvent, true, false));
 }
 
+PassRefPtr<Element> HTMLScriptElement::cloneElementWithoutAttributesAndChildren() const
+{
+    return adoptRef(new HTMLScriptElement(tagQName(), document(), false, m_data.isEvaluated()));
+}
+
+void HTMLScriptElement::executeScript(const ScriptSourceCode& sourceCode)
+{
+    return m_data.executeScript(sourceCode);
+}
+
 }
diff --git a/WebCore/html/HTMLScriptElement.h b/WebCore/html/HTMLScriptElement.h
index a5629ee..fcf85a7 100644
--- a/WebCore/html/HTMLScriptElement.h
+++ b/WebCore/html/HTMLScriptElement.h
@@ -45,7 +45,7 @@ public:
     bool haveFiredLoadEvent() const { return m_data.haveFiredLoadEvent(); }
 
 private:
-    HTMLScriptElement(const QualifiedName&, Document*, bool createdByParser);
+    HTMLScriptElement(const QualifiedName&, Document*, bool createdByParser, bool isEvaluated);
 
     virtual String scriptContent() const;
 
@@ -71,6 +71,9 @@ private:
     virtual void dispatchLoadEvent();
     virtual void dispatchErrorEvent();
 
+    PassRefPtr<Element> cloneElementWithoutAttributesAndChildren() const;
+    void executeScript(const ScriptSourceCode&);
+
     ScriptElementData m_data;
 };
 
diff --git a/WebCore/html/parser/HTMLScriptRunner.cpp b/WebCore/html/parser/HTMLScriptRunner.cpp
index d8a96c1..7978a0f 100644
--- a/WebCore/html/parser/HTMLScriptRunner.cpp
+++ b/WebCore/html/parser/HTMLScriptRunner.cpp
@@ -32,9 +32,9 @@
 #include "Element.h"
 #include "Event.h"
 #include "Frame.h"
-#include "HTMLScriptRunnerHost.h"
 #include "HTMLInputStream.h"
 #include "HTMLNames.h"
+#include "HTMLScriptRunnerHost.h"
 #include "IgnoreDestructiveWriteCountIncrementer.h"
 #include "NestingLevelIncrementer.h"
 #include "NotImplemented.h"
@@ -133,31 +133,21 @@ void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi
         stopWatchingForLoad(pendingScript);
 
     // Clear the pending script before possible rentrancy from executeScript()
-    RefPtr<Element> scriptElement = pendingScript.releaseElementAndClear();
-    {
+    RefPtr<Element> element = pendingScript.releaseElementAndClear();
+    if (ScriptElement* scriptElement = toScriptElement(element.get())) {
         NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
         IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrementer(m_document);
         if (errorOccurred)
-            scriptElement->dispatchEvent(createScriptErrorEvent());
+            element->dispatchEvent(createScriptErrorEvent());
         else {
-            executeScript(scriptElement.get(), sourceCode);
-            scriptElement->dispatchEvent(createScriptLoadEvent());
+            ASSERT(isExecutingScript());
+            scriptElement->executeScript(sourceCode);
+            element->dispatchEvent(createScriptLoadEvent());
         }
     }
     ASSERT(!m_scriptNestingLevel);
 }
 
-void HTMLScriptRunner::executeScript(Element* element, const ScriptSourceCode& sourceCode) const
-{
-    ASSERT(element);
-    ASSERT(element->document());
-    ASSERT(isExecutingScript());
-    Frame* frame = element->document()->frame();
-    if (!frame)
-        return;
-    frame->script()->executeScript(sourceCode);
-}
-
 void HTMLScriptRunner::watchForLoad(PendingScript& pendingScript)
 {
     ASSERT(!pendingScript.watchingForLoad());
@@ -320,7 +310,7 @@ void HTMLScriptRunner::runScript(Element* script, const TextPosition1& scriptSta
             // ASSERT(document()->haveStylesheetsLoaded());
             ASSERT(isExecutingScript());
             ScriptSourceCode sourceCode(script->textContent(), documentURLForScriptExecution(m_document), scriptStartPosition);
-            executeScript(script, sourceCode);
+            scriptElement->executeScript(sourceCode);
         }
     }
 }
diff --git a/WebCore/html/parser/HTMLScriptRunner.h b/WebCore/html/parser/HTMLScriptRunner.h
index df41828..6cf74d8 100644
--- a/WebCore/html/parser/HTMLScriptRunner.h
+++ b/WebCore/html/parser/HTMLScriptRunner.h
@@ -69,7 +69,6 @@ private:
 
     void executeParsingBlockingScript();
     void executePendingScriptAndDispatchEvent(PendingScript&);
-    void executeScript(Element*, const ScriptSourceCode&) const;
     bool haveParsingBlockingScript() const;
     bool executeParsingBlockingScripts();
 
diff --git a/WebCore/svg/SVGScriptElement.cpp b/WebCore/svg/SVGScriptElement.cpp
index 6532ac2..737cb3a 100644
--- a/WebCore/svg/SVGScriptElement.cpp
+++ b/WebCore/svg/SVGScriptElement.cpp
@@ -31,16 +31,16 @@
 
 namespace WebCore {
 
-inline SVGScriptElement::SVGScriptElement(const QualifiedName& tagName, Document* document, bool createdByParser)
+inline SVGScriptElement::SVGScriptElement(const QualifiedName& tagName, Document* document, bool createdByParser, bool isEvaluated)
     : SVGElement(tagName, document)
-    , m_data(this, this)
+    , m_data(this, this, isEvaluated)
 {
     m_data.setCreatedByParser(createdByParser);
 }
 
 PassRefPtr<SVGScriptElement> SVGScriptElement::create(const QualifiedName& tagName, Document* document, bool createdByParser)
 {
-    return adoptRef(new SVGScriptElement(tagName, document, createdByParser));
+    return adoptRef(new SVGScriptElement(tagName, document, createdByParser, false));
 }
 
 String SVGScriptElement::scriptContent() const
@@ -246,6 +246,16 @@ bool SVGScriptElement::shouldExecuteAsJavaScript() const
     return m_data.shouldExecuteAsJavaScript();
 }
 
+PassRefPtr<Element> SVGScriptElement::cloneElementWithoutAttributesAndChildren() const
+{
+    return adoptRef(new SVGScriptElement(tagQName(), document(), false, m_data.isEvaluated()));
+}
+
+void SVGScriptElement::executeScript(const ScriptSourceCode& sourceCode)
+{
+    m_data.executeScript(sourceCode);
+}
+
 }
 
 #endif // ENABLE(SVG)
diff --git a/WebCore/svg/SVGScriptElement.h b/WebCore/svg/SVGScriptElement.h
index e8695fb..1cca0f6 100644
--- a/WebCore/svg/SVGScriptElement.h
+++ b/WebCore/svg/SVGScriptElement.h
@@ -41,7 +41,7 @@ namespace WebCore {
         void setType(const String&);
 
     private:
-        SVGScriptElement(const QualifiedName&, Document*, bool createdByParser);
+        SVGScriptElement(const QualifiedName&, Document*, bool createdByParser, bool isEvaluated);
 
         virtual String scriptContent() const;
 
@@ -75,6 +75,9 @@ namespace WebCore {
         virtual void dispatchLoadEvent();
         virtual void dispatchErrorEvent();
 
+        PassRefPtr<Element> cloneElementWithoutAttributesAndChildren() const;
+        void executeScript(const ScriptSourceCode& sourceCode);
+
         // SVGURIReference
         DECLARE_ANIMATED_STATIC_PROPERTY_NEW(SVGScriptElement, XLinkNames::hrefAttr, String, Href, href)
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list