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 "nsIURI.h"
#include "nsIURL.h" #include "nsIURL.h"
#include "nsIXPConnect.h" #include "nsIXPConnect.h"
#include "nsIXPCScriptNotify.h"
#include "jsfriendapi.h" #include "jsfriendapi.h"
#include "jsdbgapi.h" #include "jsdbgapi.h"
@ -966,6 +967,13 @@ public:
bool dummy; bool dummy;
return DispatchEventToTarget(aCx, target, event, &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 class NotifyRunnable : public WorkerControlRunnable
@ -1111,6 +1119,13 @@ public:
mErrorNumber, innerWindowId); 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 static bool
ReportError(JSContext* aCx, WorkerPrivate* aWorkerPrivate, ReportError(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
bool aFireAtScope, JSObject* aTarget, const nsString& aMessage, 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 struct WorkerPrivate::TimeoutInfo
{ {
TimeoutInfo() TimeoutInfo()
@ -1881,6 +1908,7 @@ WorkerPrivateParent<Derived>::WorkerPrivateParent(
mWindow.swap(aWindow); mWindow.swap(aWindow);
mScriptContext.swap(aScriptContext); mScriptContext.swap(aScriptContext);
mScriptNotify = do_QueryInterface(mScriptContext);
mBaseURI.swap(aBaseURI); mBaseURI.swap(aBaseURI);
mPrincipal.swap(aPrincipal); mPrincipal.swap(aPrincipal);
mDocument.swap(aDocument); mDocument.swap(aDocument);
@ -2181,10 +2209,11 @@ WorkerPrivateParent<Derived>::ForgetMainThreadObjects(
AssertIsOnParentThread(); AssertIsOnParentThread();
MOZ_ASSERT(!mMainThreadObjectsForgotten); MOZ_ASSERT(!mMainThreadObjectsForgotten);
aDoomed.SetCapacity(6); aDoomed.SetCapacity(7);
SwapToISupportsArray(mWindow, aDoomed); SwapToISupportsArray(mWindow, aDoomed);
SwapToISupportsArray(mScriptContext, aDoomed); SwapToISupportsArray(mScriptContext, aDoomed);
SwapToISupportsArray(mScriptNotify, aDoomed);
SwapToISupportsArray(mBaseURI, aDoomed); SwapToISupportsArray(mBaseURI, aDoomed);
SwapToISupportsArray(mScriptURI, aDoomed); SwapToISupportsArray(mScriptURI, aDoomed);
SwapToISupportsArray(mPrincipal, aDoomed); SwapToISupportsArray(mPrincipal, aDoomed);

View File

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