Skip to content

Commit

Permalink
Back out changeset d9a4c7d198f0 (bug 1084009) for b2g emulator chrome…
Browse files Browse the repository at this point in the history
… and debug mochitest bustage

CLOSED TREE
  • Loading branch information
philor committed Sep 10, 2015
1 parent 0209eab commit 8047bfc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 89 deletions.
99 changes: 14 additions & 85 deletions dom/base/nsScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
// loop gets a chance to spin.

// KVKV TODO: Instead of processing immediately, try off-thread-parsing
// it and only schedule a pending ProcessRequest if that fails.
// it and only schedule a ProcessRequest if that fails.
ProcessPendingRequestsAsync();
} else {
mLoadingAsyncRequests.AppendElement(request);
Expand Down Expand Up @@ -714,44 +714,16 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
}
return true;
}
if (request->IsDoneLoading()) {
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.
if (aElement->GetParserCreated() == FROM_PARSER_NETWORK) {
// The request has already been loaded. Attempt to immediately
// start an off-thread compile for it.
nsresult rv = AttemptAsyncScriptCompile(request);
if (rv == NS_OK) {
// Off-thread compile started. Set the script as blocking the parser
// and continue. Script will be executed when ready.
NS_ASSERTION(!mParserBlockingRequest,
"There can be only one parser-blocking script at a time");
NS_ASSERTION(mXSLTRequests.isEmpty(),
"Parser-blocking scripts and XSLT scripts in the same doc!");
mParserBlockingRequest = request;
return true;
}
// If off-thread compile errored, return immediately, without blocking parser.
// Script is discarded.
if (rv != NS_ERROR_FAILURE) {
return false;
}
}
// If we get here, it means the request is fully loaded, and is either
// from a document.write, or a network-loaded script tag that for which
// off-thread compile was rejected.
// If the script comes from the network stream, and document is ready
// to execute scripts, cheat for performance reasons and avoid a trip
// through the event loop.
if (aElement->GetParserCreated() == FROM_PARSER_NETWORK &&
ReadyToExecuteScripts()) {
return ProcessRequest(request) == NS_ERROR_HTMLPARSER_BLOCK;
}
// Document is not ready to execute scripts (style sheet blocking
// execution), or script was introduced by a document.write.
// Otherwise, we've got a document.written script, make a trip through
// the event loop to hide the preload effects from the scripts on the
// Web page.
NS_ASSERTION(!mParserBlockingRequest,
"There can be only one parser-blocking script at a time");
NS_ASSERTION(mXSLTRequests.isEmpty(),
Expand All @@ -760,8 +732,8 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
ProcessPendingRequestsAsync();
return true;
}
// The script hasn't loaded yet, it will be run when it loads.
// The script hasn't loaded yet or there's a style sheet blocking it.
// The script will be run when it loads or the style sheet loads.
NS_ASSERTION(!mParserBlockingRequest,
"There can be only one parser-blocking script at a time");
NS_ASSERTION(mXSLTRequests.isEmpty(),
Expand Down Expand Up @@ -858,23 +830,6 @@ nsScriptLoader::ProcessOffThreadRequest(nsScriptLoadRequest* aRequest)
{
MOZ_ASSERT(aRequest->mProgress == nsScriptLoadRequest::Progress_Compiling);
aRequest->mProgress = nsScriptLoadRequest::Progress_DoneCompiling;
if (aRequest == mParserBlockingRequest) {
if (!ReadyToExecuteScripts()) {
// If not ready to execute scripts, schedule an async call to
// ProcessPendingRequests to handle it.
ProcessPendingRequestsAsync();
return NS_OK;
}
// Same logic as in top of ProcessPendingRequests.
mParserBlockingRequest = nullptr;
UnblockParser(aRequest);
ProcessRequest(aRequest);
mDocument->UnblockOnload(false);
ContinueParserAsync(aRequest);
return NS_OK;
}
nsresult rv = ProcessRequest(aRequest);
mDocument->UnblockOnload(false);
return rv;
Expand Down Expand Up @@ -923,10 +878,9 @@ OffThreadScriptLoaderCallback(void *aToken, void *aCallbackData)
}
nsresult
nsScriptLoader::AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest)
nsScriptLoader::AttemptAsyncScriptParse(nsScriptLoadRequest* aRequest)
{
// Don't off-thread compile inline scripts.
if (aRequest->mIsInline) {
if (!aRequest->mElement->GetScriptAsync() || aRequest->mIsInline) {
return NS_ERROR_FAILURE;
}
Expand Down Expand Up @@ -967,8 +921,7 @@ nsScriptLoader::AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest)
}
nsresult
nsScriptLoader::CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest,
bool* oCompiledOffThread)
nsScriptLoader::CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest)
{
NS_ASSERTION(nsContentUtils::IsSafeToRunScript(),
"Processing requests when running scripts is unsafe.");
Expand All @@ -977,11 +930,8 @@ nsScriptLoader::CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest,
NS_ASSERTION(!aRequest->InCompilingStage(),
"Candidate for off-thread compile is already in compiling stage.");
nsresult rv = AttemptAsyncScriptCompile(aRequest);
nsresult rv = AttemptAsyncScriptParse(aRequest);
if (rv != NS_ERROR_FAILURE) {
if (oCompiledOffThread && rv == NS_OK) {
*oCompiledOffThread = true;
}
return rv;
}
Expand Down Expand Up @@ -1272,12 +1222,8 @@ nsScriptLoader::ProcessPendingRequests()
mParserBlockingRequest->IsReadyToRun() &&
ReadyToExecuteScripts()) {
request.swap(mParserBlockingRequest);
bool offThreadCompiled = request->mProgress == nsScriptLoadRequest::Progress_DoneCompiling;
UnblockParser(request);
ProcessRequest(request);
if (offThreadCompiled) {
mDocument->UnblockOnload(false);
}
ContinueParserAsync(request);
}

Expand Down Expand Up @@ -1681,23 +1627,6 @@ nsScriptLoader::PrepareLoadedRequest(nsScriptLoadRequest* aRequest,
// Mark this as loaded
aRequest->mProgress = nsScriptLoadRequest::Progress_DoneLoading;

// If this is currently blocking the parser, attempt to compile it off-main-thread.
if (aRequest == mParserBlockingRequest) {
nsresult rv = AttemptAsyncScriptCompile(aRequest);
if (rv == NS_OK) {
NS_ASSERTION(aRequest->mProgress == nsScriptLoadRequest::Progress_Compiling,
"Request should be off-thread compiling now.");
return NS_OK;
}

// If off-thread compile errored, return the error.
if (rv != NS_ERROR_FAILURE) {
return rv;
}

// If off-thread compile was rejected, continue with regular processing.
}

// 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
// want to avoid trying to move it if it's not.
Expand Down
5 changes: 2 additions & 3 deletions dom/base/nsScriptLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,9 @@ class nsScriptLoader final : public nsIStreamLoaderObserver
return mEnabled && !mBlockerCount;
}

nsresult AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest);
nsresult AttemptAsyncScriptParse(nsScriptLoadRequest* aRequest);
nsresult ProcessRequest(nsScriptLoadRequest* aRequest);
nsresult CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest,
bool* oCompiledOffThread=nullptr);
nsresult CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest);
void FireScriptAvailable(nsresult aResult,
nsScriptLoadRequest* aRequest);
void FireScriptEvaluated(nsresult aResult,
Expand Down
2 changes: 1 addition & 1 deletion js/src/jsapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4075,7 +4075,7 @@ JS::CompileForNonSyntacticScope(JSContext* cx, const ReadOnlyCompileOptions& opt
JS_PUBLIC_API(bool)
JS::CanCompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, size_t length)
{
static const size_t TINY_LENGTH = 5 * 1000;
static const size_t TINY_LENGTH = 1000;
static const size_t HUGE_LENGTH = 100 * 1000;

// These are heuristics which the caller may choose to ignore (e.g., for
Expand Down

0 comments on commit 8047bfc

Please sign in to comment.