Bug 751458. Don't let DOM workers confuse the slow-script time accounting and trigger slow script dialogs. r=bent

This commit is contained in:
Boris Zbarsky 2012-05-04 03:22:18 -04:00
parent 313b018885
commit 6dbb365bb0
2 changed files with 41 additions and 1 deletions

View File

@ -55,6 +55,7 @@
#include "nsIURI.h"
#include "nsIURL.h"
#include "nsIXPConnect.h"
#include "nsIXPCScriptNotify.h"
#include "jsfriendapi.h"
#include "jsdbgapi.h"
@ -966,6 +967,13 @@ public:
bool dummy;
return DispatchEventToTarget(aCx, target, event, &dummy);
}
void PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate, bool aRunResult)
{
// Notify before WorkerRunnable::PostRun, since that can kill aWorkerPrivate
NotifyScriptExecutedIfNeeded();
WorkerRunnable::PostRun(aCx, aWorkerPrivate, aRunResult);
}
};
class NotifyRunnable : public WorkerControlRunnable
@ -1111,6 +1119,13 @@ public:
mErrorNumber, innerWindowId);
}
void PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate, bool aRunResult)
{
// Notify before WorkerRunnable::PostRun, since that can kill aWorkerPrivate
NotifyScriptExecutedIfNeeded();
WorkerRunnable::PostRun(aCx, aWorkerPrivate, aRunResult);
}
static bool
ReportError(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
bool aFireAtScope, JSObject* aTarget, const nsString& aMessage,
@ -1816,6 +1831,18 @@ WorkerRunnable::PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
}
}
void
WorkerRunnable::NotifyScriptExecutedIfNeeded() const
{
// if we're on the main thread notify about the end of our script execution.
if (mTarget == ParentThread && !mWorkerPrivate->GetParent()) {
AssertIsOnMainThread();
if (mWorkerPrivate->GetScriptNotify()) {
mWorkerPrivate->GetScriptNotify()->ScriptExecuted();
}
}
}
struct WorkerPrivate::TimeoutInfo
{
TimeoutInfo()
@ -1881,6 +1908,7 @@ WorkerPrivateParent<Derived>::WorkerPrivateParent(
mWindow.swap(aWindow);
mScriptContext.swap(aScriptContext);
mScriptNotify = do_QueryInterface(mScriptContext);
mBaseURI.swap(aBaseURI);
mPrincipal.swap(aPrincipal);
mDocument.swap(aDocument);
@ -2181,10 +2209,11 @@ WorkerPrivateParent<Derived>::ForgetMainThreadObjects(
AssertIsOnParentThread();
MOZ_ASSERT(!mMainThreadObjectsForgotten);
aDoomed.SetCapacity(6);
aDoomed.SetCapacity(7);
SwapToISupportsArray(mWindow, aDoomed);
SwapToISupportsArray(mScriptContext, aDoomed);
SwapToISupportsArray(mScriptNotify, aDoomed);
SwapToISupportsArray(mBaseURI, aDoomed);
SwapToISupportsArray(mScriptURI, aDoomed);
SwapToISupportsArray(mPrincipal, aDoomed);

View File

@ -69,6 +69,7 @@ class nsIScriptContext;
class nsIURI;
class nsPIDOMWindow;
class nsITimer;
class nsIXPCScriptNotify;
BEGIN_WORKERS_NAMESPACE
@ -133,6 +134,8 @@ protected:
virtual void
PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate, bool aRunResult);
void NotifyScriptExecutedIfNeeded() const;
private:
NS_DECL_NSIRUNNABLE
};
@ -207,6 +210,7 @@ private:
// Main-thread things.
nsCOMPtr<nsPIDOMWindow> mWindow;
nsCOMPtr<nsIScriptContext> mScriptContext;
nsCOMPtr<nsIXPCScriptNotify> mScriptNotify;
nsCOMPtr<nsIURI> mBaseURI;
nsCOMPtr<nsIURI> mScriptURI;
nsCOMPtr<nsIPrincipal> mPrincipal;
@ -386,6 +390,13 @@ public:
return mScriptContext;
}
nsIXPCScriptNotify*
GetScriptNotify() const
{
AssertIsOnMainThread();
return mScriptNotify;
}
JSObject*
GetJSObject() const
{