зеркало из https://github.com/mozilla/pjs.git
Bug 602838 part 1 - Execute in insertion order script-inserted external scripts that have the async DOM attribute reporting false. r=jonas, a=blocking2.0-beta8.
--HG-- extra : rebase_source : bfbbf7cf783a1d50a52896e5fe540aa7e84b2e0c
This commit is contained in:
Родитель
e78da5fbc2
Коммит
d3585d7d2d
|
@ -169,6 +169,10 @@ nsScriptLoader::~nsScriptLoader()
|
|||
mAsyncRequests[i]->FireScriptAvailable(NS_ERROR_ABORT);
|
||||
}
|
||||
|
||||
for (PRUint32 i = 0; i < mNonAsyncExternalScriptInsertedRequests.Length(); i++) {
|
||||
mNonAsyncExternalScriptInsertedRequests[i]->FireScriptAvailable(NS_ERROR_ABORT);
|
||||
}
|
||||
|
||||
// Unblock the kids, in case any of them moved to a different document
|
||||
// subtree in the meantime and therefore aren't actually going away.
|
||||
for (PRUint32 j = 0; j < mPendingChildLoaders.Length(); ++j) {
|
||||
|
@ -571,10 +575,30 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
|||
|
||||
request->mJSVersion = version;
|
||||
|
||||
PRBool async = !aElement->GetParserCreated() || aElement->GetScriptAsync();
|
||||
|
||||
// we now have a request that may or may not be still loading
|
||||
if (!async && aElement->GetScriptDeferred()) {
|
||||
if (aElement->GetScriptAsync()) {
|
||||
mAsyncRequests.AppendElement(request);
|
||||
if (!request->mLoading) {
|
||||
// The script is available already. Run it ASAP when the event
|
||||
// loop gets a chance to spin.
|
||||
ProcessPendingRequestsAsync();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
if (!aElement->GetParserCreated()) {
|
||||
// Violate the HTML5 spec in order to make LABjs and the "order" plug-in
|
||||
// for RequireJS work with their Gecko-sniffed code path. See
|
||||
// http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html
|
||||
mNonAsyncExternalScriptInsertedRequests.AppendElement(request);
|
||||
if (!request->mLoading) {
|
||||
// The script is available already. Run it ASAP when the event
|
||||
// loop gets a chance to spin.
|
||||
ProcessPendingRequestsAsync();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
// we now have a parser-inserted request that may or may not be still
|
||||
// loading
|
||||
if (aElement->GetScriptDeferred()) {
|
||||
// We don't want to run this yet.
|
||||
// If we come here, the script is a parser-created script and it has
|
||||
// the defer attribute but not the async attribute. Since a
|
||||
|
@ -587,15 +611,6 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
|||
mDeferRequests.AppendElement(request);
|
||||
return NS_OK;
|
||||
}
|
||||
if (async) {
|
||||
mAsyncRequests.AppendElement(request);
|
||||
if (!request->mLoading) {
|
||||
// The script is available already. Run it ASAP when the event
|
||||
// loop gets a chance to spin.
|
||||
ProcessPendingRequestsAsync();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aElement->GetParserCreated() == FROM_PARSER_XSLT) {
|
||||
// Need to maintain order for XSLT-inserted scripts
|
||||
|
@ -907,6 +922,17 @@ nsScriptLoader::ProcessPendingRequests()
|
|||
++i;
|
||||
}
|
||||
|
||||
while (mEnabled && !mNonAsyncExternalScriptInsertedRequests.IsEmpty() &&
|
||||
!mNonAsyncExternalScriptInsertedRequests[0]->mLoading) {
|
||||
// Violate the HTML5 spec and execute these in the insertion order in
|
||||
// order to make LABjs and the "order" plug-in for RequireJS work with
|
||||
// their Gecko-sniffed code path. See
|
||||
// http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html
|
||||
request.swap(mNonAsyncExternalScriptInsertedRequests[0]);
|
||||
mNonAsyncExternalScriptInsertedRequests.RemoveElementAt(0);
|
||||
ProcessRequest(request);
|
||||
}
|
||||
|
||||
if (mDocumentParsingDone && mXSLTRequests.IsEmpty()) {
|
||||
while (!mDeferRequests.IsEmpty() && !mDeferRequests[0]->mLoading) {
|
||||
request.swap(mDeferRequests[0]);
|
||||
|
@ -923,6 +949,7 @@ nsScriptLoader::ProcessPendingRequests()
|
|||
|
||||
if (mDocumentParsingDone && mDocument &&
|
||||
!mParserBlockingRequest && mAsyncRequests.IsEmpty() &&
|
||||
mNonAsyncExternalScriptInsertedRequests.IsEmpty() &&
|
||||
mXSLTRequests.IsEmpty() && mDeferRequests.IsEmpty()) {
|
||||
// No more pending scripts; time to unblock onload.
|
||||
// OK to unblock onload synchronously here, since callers must be
|
||||
|
@ -1094,6 +1121,7 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
|
|||
if (NS_FAILED(rv)) {
|
||||
if (mDeferRequests.RemoveElement(request) ||
|
||||
mAsyncRequests.RemoveElement(request) ||
|
||||
mNonAsyncExternalScriptInsertedRequests.RemoveElement(request) ||
|
||||
mXSLTRequests.RemoveElement(request)) {
|
||||
FireScriptAvailable(rv, request);
|
||||
} else if (mParserBlockingRequest == request) {
|
||||
|
@ -1172,6 +1200,7 @@ nsScriptLoader::PrepareLoadedRequest(nsScriptLoadRequest* aRequest,
|
|||
// wrong, especially if you see it more than once.
|
||||
NS_ASSERTION(mDeferRequests.IndexOf(aRequest) >= 0 ||
|
||||
mAsyncRequests.IndexOf(aRequest) >= 0 ||
|
||||
mNonAsyncExternalScriptInsertedRequests.IndexOf(aRequest) >= 0 ||
|
||||
mXSLTRequests.IndexOf(aRequest) >= 0 ||
|
||||
mPreloads.Contains(aRequest, PreloadRequestComparator()) ||
|
||||
mParserBlockingRequest,
|
||||
|
@ -1225,6 +1254,7 @@ nsScriptLoader::ParsingComplete(PRBool aTerminated)
|
|||
if (aTerminated) {
|
||||
mDeferRequests.Clear();
|
||||
mAsyncRequests.Clear();
|
||||
mNonAsyncExternalScriptInsertedRequests.Clear();
|
||||
mXSLTRequests.Clear();
|
||||
mParserBlockingRequest = nsnull;
|
||||
}
|
||||
|
|
|
@ -297,6 +297,7 @@ private:
|
|||
|
||||
nsIDocument* mDocument; // [WEAK]
|
||||
nsCOMArray<nsIScriptLoaderObserver> mObservers;
|
||||
nsTArray<nsRefPtr<nsScriptLoadRequest> > mNonAsyncExternalScriptInsertedRequests;
|
||||
nsTArray<nsRefPtr<nsScriptLoadRequest> > mAsyncRequests;
|
||||
nsTArray<nsRefPtr<nsScriptLoadRequest> > mDeferRequests;
|
||||
nsTArray<nsRefPtr<nsScriptLoadRequest> > mXSLTRequests;
|
||||
|
|
|
@ -431,6 +431,8 @@ _TEST_FILES2 = \
|
|||
test_bug601803.html \
|
||||
file_bug601803a.html \
|
||||
file_bug601803b.html \
|
||||
test_bug602838.html \
|
||||
script_bug602838.sjs \
|
||||
test_bug604660.html \
|
||||
file_bug604660-1.xml \
|
||||
file_bug604660-2.xsl \
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
function handleRequest(request, response)
|
||||
{
|
||||
response.setHeader("Cache-Control", "no-cache", false);
|
||||
response.setHeader("Content-Type", "text/javascript", false);
|
||||
response.write("ok(asyncRan, 'Async script should have run first.'); firstRan = true;");
|
||||
response.processAsync();
|
||||
var timer = Components.classes["@mozilla.org/timer;1"]
|
||||
.createInstance(Components.interfaces.nsITimer);
|
||||
timer.initWithCallback(function() {
|
||||
response.finish();
|
||||
}, 200, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=602838
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 602838</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=602838">Mozilla Bug 602838</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for Bug 602838 **/
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
var firstRan = false;
|
||||
var asyncRan = false;
|
||||
|
||||
var s = document.createElement("script");
|
||||
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();";
|
||||
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>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
Загрузка…
Ссылка в новой задаче