diff --git a/content/base/public/nsIScriptElement.h b/content/base/public/nsIScriptElement.h index 02105ef13f67..5e7e1b99e069 100644 --- a/content/base/public/nsIScriptElement.h +++ b/content/base/public/nsIScriptElement.h @@ -45,6 +45,7 @@ #include "nsIScriptLoaderObserver.h" #include "nsWeakPtr.h" #include "nsIParser.h" +#include "nsContentCreatorFunctions.h" #define NS_ISCRIPTELEMENT_IID \ { 0x6d625b30, 0xfac4, 0x11de, \ @@ -57,14 +58,15 @@ class nsIScriptElement : public nsIScriptLoaderObserver { public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTELEMENT_IID) - nsIScriptElement() + nsIScriptElement(PRUint32 aFromParser) : mLineNumber(0), - mIsEvaluated(PR_FALSE), + mAlreadyStarted(PR_FALSE), mMalformed(PR_FALSE), mDoneAddingChildren(PR_TRUE), mFrozen(PR_FALSE), mDefer(PR_FALSE), mAsync(PR_FALSE), + mParserCreated((PRUint8)aFromParser), mCreatorParser(nsnull) { } @@ -117,6 +119,15 @@ public: return mAsync; } + /** + * Returns a constant defined in nsContentCreatorFunctions.h. Non-zero + * values mean parser-created and zero means not parser-created. + */ + PRUint32 GetParserCreated() + { + return mParserCreated; + } + void SetScriptLineNumber(PRUint32 aLineNumber) { mLineNumber = aLineNumber; @@ -137,7 +148,15 @@ public: void PreventExecution() { - mIsEvaluated = PR_TRUE; + mAlreadyStarted = PR_TRUE; + } + + void LoseParserInsertedness() + { + mFrozen = PR_FALSE; + mUri = nsnull; + mCreatorParser = nsnull; + mParserCreated = NS_NOT_FROM_PARSER; } void SetCreatorParser(nsIParser* aParser) @@ -185,7 +204,7 @@ protected: /** * The "already started" flag per HTML5. */ - PRPackedBool mIsEvaluated; + PRPackedBool mAlreadyStarted; /** * The script didn't have an end tag. @@ -212,6 +231,11 @@ protected: */ PRPackedBool mAsync; + /** + * Whether this element was parser-created. + */ + PRUint8 mParserCreated; + /** * The effective src (or null if no src). */ diff --git a/content/base/src/nsContentSink.cpp b/content/base/src/nsContentSink.cpp index 613a5ef0cb21..ecec06f24669 100644 --- a/content/base/src/nsContentSink.cpp +++ b/content/base/src/nsContentSink.cpp @@ -366,8 +366,8 @@ nsContentSink::ScriptAvailable(nsresult aResult, PRUint32 count = mScriptElements.Count(); // aElement will not be in mScriptElements if a @@ -59,11 +55,6 @@ res += 'B'; - diff --git a/content/base/test/test_bug28293.xhtml b/content/base/test/test_bug28293.xhtml index 1c0385289ce6..7c93b12d9847 100644 --- a/content/base/test/test_bug28293.xhtml +++ b/content/base/test/test_bug28293.xhtml @@ -8,6 +8,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=28293 @@ -58,11 +54,6 @@ res += 'B'; - diff --git a/content/html/content/src/nsHTMLScriptElement.cpp b/content/html/content/src/nsHTMLScriptElement.cpp index 8e0c7c1e1aa1..a250dc17e0c5 100644 --- a/content/html/content/src/nsHTMLScriptElement.cpp +++ b/content/html/content/src/nsHTMLScriptElement.cpp @@ -363,6 +363,7 @@ NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Script) nsHTMLScriptElement::nsHTMLScriptElement(already_AddRefed aNodeInfo, PRUint32 aFromParser) : nsGenericHTMLElement(aNodeInfo) + , nsScriptElement(aFromParser) { mDoneAddingChildren = !aFromParser; AddMutationObserver(this); @@ -428,7 +429,7 @@ nsHTMLScriptElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const NS_ENSURE_SUCCESS(rv, rv); // The clone should be marked evaluated if we are. - it->mIsEvaluated = mIsEvaluated; + it->mAlreadyStarted = mAlreadyStarted; it->mLineNumber = mLineNumber; it->mMalformed = mMalformed; @@ -477,11 +478,10 @@ nsHTMLScriptElement::DoneAddingChildren(PRBool aHaveNotified) { mDoneAddingChildren = PR_TRUE; nsresult rv = MaybeProcessScript(); - if (!mIsEvaluated) { - // Need to thaw the script uri here to allow another script to cause + if (!mAlreadyStarted) { + // Need to lose parser-insertedness here to allow another script to cause // execution later. - mFrozen = PR_FALSE; - mUri = nsnull; + LoseParserInsertedness(); } return rv; } @@ -555,7 +555,7 @@ nsHTMLScriptElement::MaybeProcessScript() // We tried to evaluate the script but realized it was an eventhandler // mEvaluated will already be set at this point - NS_ASSERTION(mIsEvaluated, "should have set mIsEvaluated already"); + NS_ASSERTION(mAlreadyStarted, "should have set mIsEvaluated already"); NS_ASSERTION(!mScriptEventHandler, "how could we have an SEH already?"); mScriptEventHandler = new nsHTMLScriptEventHandler(this); diff --git a/content/html/content/test/test_bug300691-2.html b/content/html/content/test/test_bug300691-2.html index 2d9b7a750604..8ad49540f61e 100644 --- a/content/html/content/test/test_bug300691-2.html +++ b/content/html/content/test/test_bug300691-2.html @@ -9,7 +9,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=300691 - + Mozilla Bug 300691

 
 
 
diff --git a/content/svg/content/src/nsSVGScriptElement.cpp b/content/svg/content/src/nsSVGScriptElement.cpp index 9c7a12e781cf..192eb818ec88 100644 --- a/content/svg/content/src/nsSVGScriptElement.cpp +++ b/content/svg/content/src/nsSVGScriptElement.cpp @@ -135,6 +135,7 @@ NS_INTERFACE_MAP_END_INHERITING(nsSVGScriptElementBase) nsSVGScriptElement::nsSVGScriptElement(already_AddRefed aNodeInfo, PRUint32 aFromParser) : nsSVGScriptElementBase(aNodeInfo) + , nsScriptElement(aFromParser) { mDoneAddingChildren = !aFromParser; AddMutationObserver(this); @@ -160,7 +161,7 @@ nsSVGScriptElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const NS_ENSURE_SUCCESS(rv, rv); // The clone should be marked evaluated if we are. - it->mIsEvaluated = mIsEvaluated; + it->mAlreadyStarted = mAlreadyStarted; it->mLineNumber = mLineNumber; it->mMalformed = mMalformed; @@ -278,11 +279,10 @@ nsSVGScriptElement::DoneAddingChildren(PRBool aHaveNotified) { mDoneAddingChildren = PR_TRUE; nsresult rv = MaybeProcessScript(); - if (!mIsEvaluated) { - // Need to thaw the script uri here to allow another script to cause + if (!mAlreadyStarted) { + // Need to lose parser-insertedness here to allow another script to cause // execution later. - mFrozen = PR_FALSE; - mUri = nsnull; + LoseParserInsertedness(); } return rv; } diff --git a/content/test/reftest/bug591981-1.html b/content/test/reftest/bug591981-1.html new file mode 100644 index 000000000000..5c48ca8123b4 --- /dev/null +++ b/content/test/reftest/bug591981-1.html @@ -0,0 +1,32 @@ + + + +Script-inserted script + + +
+ + + diff --git a/content/test/reftest/bug591981-2.html b/content/test/reftest/bug591981-2.html new file mode 100644 index 000000000000..7d05d5179aa0 --- /dev/null +++ b/content/test/reftest/bug591981-2.html @@ -0,0 +1,32 @@ + + + +Script trying to execute parser-inserted non-executed scripts + + +
+ + + + + diff --git a/content/test/reftest/bug591981-ref.html b/content/test/reftest/bug591981-ref.html new file mode 100644 index 000000000000..8a19a40b9dea --- /dev/null +++ b/content/test/reftest/bug591981-ref.html @@ -0,0 +1,9 @@ + + + +Script-inserted script + + +

internal

external

+ + diff --git a/content/test/reftest/bug591981-script.js b/content/test/reftest/bug591981-script.js new file mode 100644 index 000000000000..818596af3c37 --- /dev/null +++ b/content/test/reftest/bug591981-script.js @@ -0,0 +1 @@ +log("external"); diff --git a/content/test/reftest/reftest.list b/content/test/reftest/reftest.list index ad5d4d839e28..862241297ff4 100644 --- a/content/test/reftest/reftest.list +++ b/content/test/reftest/reftest.list @@ -4,3 +4,5 @@ == bug439965.html bug439965-ref.html == bug427779.xml bug427779-ref.xml == bug559996.html bug559996-ref.html +== bug591981-1.html bug591981-ref.html +== bug591981-2.html bug591981-ref.html diff --git a/dom/tests/mochitest/bugs/child_bug260264.html b/dom/tests/mochitest/bugs/child_bug260264.html index 12cde3eb26f0..a40e1750269b 100644 --- a/dom/tests/mochitest/bugs/child_bug260264.html +++ b/dom/tests/mochitest/bugs/child_bug260264.html @@ -1,5 +1,6 @@ + diff --git a/dom/tests/mochitest/bugs/grandchild_bug260264.html b/dom/tests/mochitest/bugs/grandchild_bug260264.html index 62e0f50ca2a7..22e3d7137400 100644 --- a/dom/tests/mochitest/bugs/grandchild_bug260264.html +++ b/dom/tests/mochitest/bugs/grandchild_bug260264.html @@ -1,5 +1,6 @@ + diff --git a/dom/tests/mochitest/bugs/test_bug260264.html b/dom/tests/mochitest/bugs/test_bug260264.html index 69d2a7e16647..7e353643b74a 100644 --- a/dom/tests/mochitest/bugs/test_bug260264.html +++ b/dom/tests/mochitest/bugs/test_bug260264.html @@ -7,6 +7,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=260264 Test for Bug 260264 + diff --git a/dom/tests/mochitest/bugs/utils_bug260264.js b/dom/tests/mochitest/bugs/utils_bug260264.js index 69a9e11678de..51bbcb1cd4d8 100644 --- a/dom/tests/mochitest/bugs/utils_bug260264.js +++ b/dom/tests/mochitest/bugs/utils_bug260264.js @@ -1,10 +1,3 @@ -(function() { - // For sendMouseEvent: - document.getElementsByTagName("head").item(0) - .appendChild(document.createElement("script")).src = - "/tests/SimpleTest/EventUtils.js"; -})(); - /** * Dispatches |handler| to |element|, as if fired in response to |event|. */