зеркало из https://github.com/mozilla/pjs.git
Bug 602838 part 2 - Make script-created scripts (incl. scripts that have lost their parser-insertedness) default to .async=true. r=jonas, a=blocking2.0-beta8.
--HG-- extra : rebase_source : 8488bca56232504b1510e92b52f2567fa42eaf99
This commit is contained in:
Родитель
d3585d7d2d
Коммит
024fd7c98a
|
@ -46,6 +46,7 @@
|
|||
#include "nsWeakPtr.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsContentCreatorFunctions.h"
|
||||
#include "nsIDOMHTMLScriptElement.h"
|
||||
|
||||
#define NS_ISCRIPTELEMENT_IID \
|
||||
{ 0x6d625b30, 0xfac4, 0x11de, \
|
||||
|
@ -63,6 +64,8 @@ public:
|
|||
mAlreadyStarted(PR_FALSE),
|
||||
mMalformed(PR_FALSE),
|
||||
mDoneAddingChildren(PR_TRUE),
|
||||
mForceAsync(aFromParser == mozilla::dom::NOT_FROM_PARSER ||
|
||||
aFromParser == mozilla::dom::FROM_PARSER_FRAGMENT),
|
||||
mFrozen(PR_FALSE),
|
||||
mDefer(PR_FALSE),
|
||||
mAsync(PR_FALSE),
|
||||
|
@ -159,6 +162,12 @@ public:
|
|||
mUri = nsnull;
|
||||
mCreatorParser = nsnull;
|
||||
mParserCreated = mozilla::dom::NOT_FROM_PARSER;
|
||||
PRBool async = PR_FALSE;
|
||||
nsCOMPtr<nsIDOMHTMLScriptElement> htmlScript = do_QueryInterface(this);
|
||||
if (htmlScript) {
|
||||
htmlScript->GetAsync(&async);
|
||||
}
|
||||
mForceAsync = !async;
|
||||
}
|
||||
|
||||
void SetCreatorParser(nsIParser* aParser)
|
||||
|
@ -218,6 +227,12 @@ protected:
|
|||
*/
|
||||
PRPackedBool mDoneAddingChildren;
|
||||
|
||||
/**
|
||||
* If true, the .async property returns true instead of reflecting the
|
||||
* content attribute.
|
||||
*/
|
||||
PRPackedBool mForceAsync;
|
||||
|
||||
/**
|
||||
* Whether src, defer and async are frozen.
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=602838
|
|||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script id=withasync async></script>
|
||||
<script id=withoutasync></script>
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for Bug 602838 **/
|
||||
|
@ -23,17 +25,34 @@ SimpleTest.waitForExplicitFinish();
|
|||
var firstRan = false;
|
||||
var asyncRan = false;
|
||||
|
||||
var withoutasync = document.getElementById("withoutasync");
|
||||
ok(withoutasync.async, "When a script loses parser-insertedness, it should become async.");
|
||||
|
||||
var withasync = document.getElementById("withasync");
|
||||
ok(withasync.async, "A script with the async content attribute should have the DOM attribute reporting true.");
|
||||
withasync.removeAttribute("async");
|
||||
ok(!withasync.async, "Should be able to remove asyncness from a script that had the async content attribute when losing parser-insertedness by removing the content attribute.");
|
||||
|
||||
var s = document.createElement("script");
|
||||
ok(s.async, "Script-created scripts should default to .async=true");
|
||||
ok(!s.hasAttribute("async"), "Script-created scripts should not have the async content attribute by default.");
|
||||
s.removeAttribute("async");
|
||||
ok(s.async, "Removing a non-existing content-attribute should not have an effect on the forced async DOM property.");
|
||||
s.setAttribute("async", "");
|
||||
ok(s.async, "The async DOM property should still be true.");
|
||||
s.removeAttribute("async");
|
||||
ok(!s.async, "When a previously present async content attribute is removed, the DOM property should become false.");
|
||||
s.src = "script_bug602838.sjs";
|
||||
document.body.appendChild(s);
|
||||
|
||||
s = document.createElement("script");
|
||||
s.src = "data:text/javascript,ok(firstRan, 'The first script should have run'); SimpleTest.finish();";
|
||||
s.async = false;
|
||||
ok(!s.async, "Setting the async DOM property to false should turned of forcing async to true.");
|
||||
document.body.appendChild(s);
|
||||
|
||||
s = document.createElement("script");
|
||||
s.src = "data:text/javascript,ok(!firstRan, 'Non-async should not have run yet.'); asyncRan = true;";
|
||||
s.async = true;
|
||||
document.body.appendChild(s);
|
||||
|
||||
</script>
|
||||
|
|
|
@ -345,6 +345,10 @@ public:
|
|||
|
||||
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
|
||||
|
||||
// nsGenericElement
|
||||
virtual nsresult AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
|
||||
const nsAString* aValue, PRBool aNotify);
|
||||
|
||||
virtual nsXPCClassInfo* GetClassInfo();
|
||||
protected:
|
||||
PRBool IsOnloadEventForWindow();
|
||||
|
@ -454,12 +458,39 @@ nsHTMLScriptElement::SetText(const nsAString& aValue)
|
|||
|
||||
NS_IMPL_STRING_ATTR(nsHTMLScriptElement, Charset, charset)
|
||||
NS_IMPL_BOOL_ATTR(nsHTMLScriptElement, Defer, defer)
|
||||
NS_IMPL_BOOL_ATTR(nsHTMLScriptElement, Async, async)
|
||||
NS_IMPL_URI_ATTR(nsHTMLScriptElement, Src, src)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLScriptElement, Type, type)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLScriptElement, HtmlFor, _for)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLScriptElement, Event, event)
|
||||
|
||||
nsresult
|
||||
nsHTMLScriptElement::GetAsync(PRBool* aValue)
|
||||
{
|
||||
if (mForceAsync) {
|
||||
*aValue = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
return GetBoolAttr(nsGkAtoms::async, aValue);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLScriptElement::SetAsync(PRBool aValue)
|
||||
{
|
||||
mForceAsync = PR_FALSE;
|
||||
return SetBoolAttr(nsGkAtoms::async, aValue);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLScriptElement::AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
|
||||
const nsAString* aValue, PRBool aNotify)
|
||||
{
|
||||
if (nsGkAtoms::async == aName && kNameSpaceID_None == aNamespaceID) {
|
||||
mForceAsync = PR_FALSE;
|
||||
}
|
||||
return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue,
|
||||
aNotify);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLScriptElement::GetInnerHTML(nsAString& aInnerHTML)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче