Bug 1167409 - 3/5 - Change ScriptLoadRequest::mLoading to ScriptLoadRequest::mProgress. r=smaug

This commit is contained in:
Kannan Vijayan 2015-07-28 17:03:56 -04:00
Родитель 5ca8e26a21
Коммит ad8b91caa9
2 изменённых файлов: 50 добавлений и 18 удалений

Просмотреть файл

@ -609,7 +609,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
request = new nsScriptLoadRequest(aElement, version, ourCORSMode);
request->mURI = scriptURI;
request->mIsInline = false;
request->mLoading = true;
request->mProgress = nsScriptLoadRequest::Progress_Loading;
request->mReferrerPolicy = ourRefPolicy;
// set aScriptFromHead to false so we don't treat non preloaded scripts as
@ -624,14 +624,21 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
}
}
// Should still be in loading stage of script.
NS_ASSERTION(!request->InCompilingStage(),
"Request should noet yet be in compiling stage.");
request->mJSVersion = version;
if (aElement->GetScriptAsync()) {
request->mIsAsync = true;
if (!request->mLoading) {
if (request->IsDoneLoading()) {
mLoadedAsyncRequests.AppendElement(request);
// The script is available already. Run it ASAP when the event
// loop gets a chance to spin.
// KVKV TODO: Instead of processing immediately, try off-thread-parsing
// it and only schedule a ProcessRequest if that fails.
ProcessPendingRequestsAsync();
} else {
mLoadingAsyncRequests.AppendElement(request);
@ -644,7 +651,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
// http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html
request->mIsNonAsyncScriptInserted = true;
mNonAsyncExternalScriptInsertedRequests.AppendElement(request);
if (!request->mLoading) {
if (request->IsDoneLoading()) {
// The script is available already. Run it ASAP when the event
// loop gets a chance to spin.
ProcessPendingRequestsAsync();
@ -673,14 +680,14 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
"Parser-blocking scripts and XSLT scripts in the same doc!");
request->mIsXSLT = true;
mXSLTRequests.AppendElement(request);
if (!request->mLoading) {
if (request->IsDoneLoading()) {
// The script is available already. Run it ASAP when the event
// loop gets a chance to spin.
ProcessPendingRequestsAsync();
}
return true;
}
if (!request->mLoading && ReadyToExecuteScripts()) {
if (request->IsDoneLoading() && ReadyToExecuteScripts()) {
// The request has already been loaded and there are no pending style
// sheets. If the script comes from the network stream, cheat for
// performance reasons and avoid a trip through the event loop.
@ -722,7 +729,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
// Inline scripts ignore ther CORS mode and are always CORS_NONE
request = new nsScriptLoadRequest(aElement, version, CORS_NONE);
request->mJSVersion = version;
request->mLoading = false;
request->mProgress = nsScriptLoadRequest::Progress_DoneLoading;
request->mIsInline = true;
request->mURI = mDocument->GetDocumentURI();
request->mLineNo = aElement->GetScriptLineNumber();
@ -793,6 +800,8 @@ public:
nsresult
nsScriptLoader::ProcessOffThreadRequest(nsScriptLoadRequest* aRequest)
{
MOZ_ASSERT(aRequest->mProgress == nsScriptLoadRequest::Progress_Compiling);
aRequest->mProgress = nsScriptLoadRequest::Progress_DoneCompiling;
nsresult rv = ProcessRequest(aRequest);
mDocument->UnblockOnload(false);
return rv;
@ -877,18 +886,21 @@ nsScriptLoader::AttemptAsyncScriptParse(nsScriptLoadRequest* aRequest)
}
mDocument->BlockOnload();
aRequest->mProgress = nsScriptLoadRequest::Progress_Compiling;
unused << runnable.forget();
return NS_OK;
}
nsresult
nsScriptLoader::ParseOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest)
nsScriptLoader::CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest)
{
NS_ASSERTION(nsContentUtils::IsSafeToRunScript(),
"Processing requests when running scripts is unsafe.");
NS_ASSERTION(!aRequest->mOffThreadToken,
"Candidate for off-thread parsing is already parsed off-thread");
"Candidate for off-thread compile is already parsed off-thread");
NS_ASSERTION(!aRequest->InCompilingStage(),
"Candidate for off-thread compile is already in compiling stage.");
nsresult rv = AttemptAsyncScriptParse(aRequest);
if (rv != NS_ERROR_FAILURE) {
@ -903,6 +915,8 @@ nsScriptLoader::ProcessRequest(nsScriptLoadRequest* aRequest)
{
NS_ASSERTION(nsContentUtils::IsSafeToRunScript(),
"Processing requests when running scripts is unsafe.");
NS_ASSERTION(aRequest->IsReadyToRun(),
"Processing a request that is not ready to run.");
NS_ENSURE_ARG(aRequest);
nsAutoString textData;
@ -1175,8 +1189,9 @@ void
nsScriptLoader::ProcessPendingRequests()
{
nsRefPtr<nsScriptLoadRequest> request;
if (mParserBlockingRequest &&
!mParserBlockingRequest->mLoading &&
mParserBlockingRequest->IsReadyToRun() &&
ReadyToExecuteScripts()) {
request.swap(mParserBlockingRequest);
UnblockParser(request);
@ -1186,18 +1201,18 @@ nsScriptLoader::ProcessPendingRequests()
while (ReadyToExecuteScripts() &&
!mXSLTRequests.isEmpty() &&
!mXSLTRequests.getFirst()->mLoading) {
mXSLTRequests.getFirst()->IsReadyToRun()) {
request = mXSLTRequests.StealFirst();
ProcessRequest(request);
}
while (mEnabled && !mLoadedAsyncRequests.isEmpty()) {
request = mLoadedAsyncRequests.StealFirst();
ParseOffThreadOrProcessRequest(request);
CompileOffThreadOrProcessRequest(request);
}
while (mEnabled && !mNonAsyncExternalScriptInsertedRequests.isEmpty() &&
!mNonAsyncExternalScriptInsertedRequests.getFirst()->mLoading) {
mNonAsyncExternalScriptInsertedRequests.getFirst()->IsReadyToRun()) {
// 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
@ -1207,7 +1222,7 @@ nsScriptLoader::ProcessPendingRequests()
}
if (mDocumentParsingDone && mXSLTRequests.isEmpty()) {
while (!mDeferRequests.isEmpty() && !mDeferRequests.getFirst()->mLoading) {
while (!mDeferRequests.isEmpty() && mDeferRequests.getFirst()->IsReadyToRun()) {
request = mDeferRequests.StealFirst();
ProcessRequest(request);
}
@ -1569,7 +1584,7 @@ nsScriptLoader::PrepareLoadedRequest(nsScriptLoadRequest* aRequest,
"aRequest should be pending!");
// Mark this as loaded
aRequest->mLoading = false;
aRequest->mProgress = nsScriptLoadRequest::Progress_DoneLoading;
// And if it's async, move it to the loaded list. aRequest->mIsAsync really
// _should_ be in a list, but the consequences if it's not are bad enough we
@ -1628,7 +1643,7 @@ nsScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset,
Element::StringToCORSMode(aCrossOrigin));
request->mURI = aURI;
request->mIsInline = false;
request->mLoading = true;
request->mProgress = nsScriptLoadRequest::Progress_Loading;
request->mReferrerPolicy = aReferrerPolicy;
nsresult rv = StartLoad(request, aType, aScriptFromHead);

Просмотреть файл

@ -58,7 +58,7 @@ public:
uint32_t aVersion,
mozilla::CORSMode aCORSMode)
: mElement(aElement),
mLoading(true),
mProgress(Progress_Loading),
mIsInline(true),
mHasSourceMapURL(false),
mIsDefer(false),
@ -107,11 +107,28 @@ public:
return mOffThreadToken ? &mOffThreadToken : nullptr;
}
enum Progress {
Progress_Loading,
Progress_DoneLoading,
Progress_Compiling,
Progress_DoneCompiling
};
bool IsReadyToRun() {
return mProgress == Progress_DoneLoading ||
mProgress == Progress_DoneCompiling;
}
bool IsDoneLoading() {
return mProgress == Progress_DoneLoading;
}
bool InCompilingStage() {
return (mProgress == Progress_Compiling) || (mProgress == Progress_DoneCompiling);
}
using super::getNext;
using super::isInList;
nsCOMPtr<nsIScriptElement> mElement;
bool mLoading; // Are we still waiting for a load to complete?
Progress mProgress; // Are we still waiting for a load to complete?
bool mIsInline; // Is the script inline or loaded?
bool mHasSourceMapURL; // Does the HTTP header have a source map url?
bool mIsDefer; // True if we live in mDeferRequests.
@ -447,7 +464,7 @@ private:
nsresult AttemptAsyncScriptParse(nsScriptLoadRequest* aRequest);
nsresult ProcessRequest(nsScriptLoadRequest* aRequest);
nsresult ParseOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest);
nsresult CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest);
void FireScriptAvailable(nsresult aResult,
nsScriptLoadRequest* aRequest);
void FireScriptEvaluated(nsresult aResult,