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

This commit is contained in:
Ryan VanderMeulen 2013-09-14 21:25:31 -04:00
Родитель 771bfb41ad
Коммит afc0d277a9
2 изменённых файлов: 44 добавлений и 44 удалений

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

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

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

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