Backed out changeset 47a8380519cc (bug 916255) for tp timeouts.

This commit is contained in:
Ryan VanderMeulen 2013-09-14 21:25:31 -04:00
parent e757b0b4fb
commit a59f51b8b8
2 changed files with 44 additions and 44 deletions

View File

@ -697,64 +697,62 @@ namespace {
class NotifyOffThreadScriptLoadCompletedRunnable : public nsRunnable
{
nsRefPtr<nsScriptLoadRequest> mRequest;
nsRefPtr<nsScriptLoader> mLoader;
void *mToken;
nsRefPtr<nsScriptLoader> mLoader;
void *mToken;
public:
NotifyOffThreadScriptLoadCompletedRunnable(nsScriptLoadRequest* aRequest,
nsScriptLoader* aLoader)
: mRequest(aRequest), mLoader(aLoader), mToken(NULL)
{}
NotifyOffThreadScriptLoadCompletedRunnable(already_AddRefed<nsScriptLoader> aLoader,
void *aToken)
: mLoader(aLoader), mToken(aToken)
{}
void SetToken(void* aToken) {
MOZ_ASSERT(aToken && !mToken);
mToken = aToken;
}
NS_DECL_NSIRUNNABLE
NS_DECL_NSIRUNNABLE
};
} /* anonymous namespace */
nsresult
nsScriptLoader::ProcessOffThreadRequest(nsScriptLoadRequest* aRequest, void **aOffThreadToken)
nsScriptLoader::ProcessOffThreadRequest(void **aOffThreadToken)
{
nsresult rv = ProcessRequest(aRequest, aOffThreadToken);
mDocument->UnblockOnload(false);
return rv;
nsCOMPtr<nsScriptLoadRequest> request = mOffThreadScriptRequest;
mOffThreadScriptRequest = nullptr;
mDocument->UnblockOnload(false);
return ProcessRequest(request, aOffThreadToken);
}
NS_IMETHODIMP
NotifyOffThreadScriptLoadCompletedRunnable::Run()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(NS_IsMainThread());
nsresult rv = mLoader->ProcessOffThreadRequest(mRequest, &mToken);
nsresult rv = mLoader->ProcessOffThreadRequest(&mToken);
if (mToken) {
// The result of the off thread parse was not actually needed to process
// the request (disappearing window, some other error, ...). Finish the
// request to avoid leaks in the JS engine.
nsCOMPtr<nsIJSRuntimeService> svc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
NS_ENSURE_TRUE(svc, NS_ERROR_FAILURE);
JSRuntime *rt;
svc->GetRuntime(&rt);
NS_ENSURE_TRUE(rt, NS_ERROR_FAILURE);
JS::FinishOffThreadScript(nullptr, rt, mToken);
}
if (mToken) {
// The result of the off thread parse was not actually needed to process
// the request (disappearing window, some other error, ...). Finish the
// request to avoid leaks in the JS engine.
nsCOMPtr<nsIJSRuntimeService> svc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
NS_ENSURE_TRUE(svc, NS_ERROR_FAILURE);
JSRuntime *rt;
svc->GetRuntime(&rt);
NS_ENSURE_TRUE(rt, NS_ERROR_FAILURE);
JS::FinishOffThreadScript(nullptr, rt, mToken);
}
return rv;
return rv;
}
static void
OffThreadScriptLoaderCallback(void *aToken, void *aCallbackData)
{
NotifyOffThreadScriptLoadCompletedRunnable* aRunnable =
static_cast<NotifyOffThreadScriptLoadCompletedRunnable*>(aCallbackData);
aRunnable->SetToken(aToken);
NS_DispatchToMainThread(aRunnable);
NS_RELEASE(aRunnable);
// Be careful not to adjust the refcount on the loader, as this callback
// may be invoked off the main thread.
nsScriptLoader* aLoader = static_cast<nsScriptLoader*>(aCallbackData);
nsRefPtr<NotifyOffThreadScriptLoadCompletedRunnable> notify =
new NotifyOffThreadScriptLoadCompletedRunnable(
already_AddRefed<nsScriptLoader>(aLoader), aToken);
NS_DispatchToMainThread(notify);
}
nsresult
@ -764,6 +762,10 @@ nsScriptLoader::AttemptAsyncScriptParse(nsScriptLoadRequest* aRequest)
return NS_ERROR_FAILURE;
}
if (mOffThreadScriptRequest) {
return NS_ERROR_FAILURE;
}
JSObject *unrootedGlobal;
nsCOMPtr<nsIScriptContext> context = GetScriptContext(&unrootedGlobal);
if (!context) {
@ -779,18 +781,16 @@ nsScriptLoader::AttemptAsyncScriptParse(nsScriptLoadRequest* aRequest)
return NS_ERROR_FAILURE;
}
nsRefPtr<NotifyOffThreadScriptLoadCompletedRunnable> runnable =
new NotifyOffThreadScriptLoadCompletedRunnable(aRequest, this);
mOffThreadScriptRequest = aRequest;
if (!JS::CompileOffThread(cx, global, options,
aRequest->mScriptText.get(), aRequest->mScriptText.Length(),
OffThreadScriptLoaderCallback,
static_cast<void*>(runnable))) {
static_cast<void*>(this))) {
return NS_ERROR_OUT_OF_MEMORY;
}
// This reference will be consumed by OffThreadScriptLoaderCallback.
runnable.forget();
// This reference will be consumed by the NotifyOffThreadScriptLoadCompletedRunnable.
NS_ADDREF(this);
mDocument->BlockOnload();

View File

@ -211,8 +211,7 @@ public:
* Process a request that was deferred so that the script could be compiled
* off thread.
*/
nsresult ProcessOffThreadRequest(nsScriptLoadRequest *aRequest,
void **aOffThreadToken);
nsresult ProcessOffThreadRequest(void **aOffThreadToken);
private:
/**
@ -317,6 +316,7 @@ private:
};
nsTArray<PreloadInfo> mPreloads;
nsCOMPtr<nsScriptLoadRequest> mOffThreadScriptRequest;
nsCOMPtr<nsIScriptElement> mCurrentScript;
nsCOMPtr<nsIScriptElement> mCurrentParserInsertedScript;
// XXXbz do we want to cycle-collect these or something? Not sure.