Bug 1250291 part 2. Stop pretending to report exceptions in MainThreadWorkerSyncRunnable::PostDispatch. r=khuey

This commit is contained in:
Boris Zbarsky 2016-02-23 15:02:42 -05:00
parent aeed64f72a
commit 307a76a0c0
3 changed files with 46 additions and 9 deletions

View File

@ -469,7 +469,18 @@ MainThreadWorkerSyncRunnable::PostDispatch(JSContext* aCx,
WorkerPrivate* aWorkerPrivate,
bool aDispatchResult)
{
MaybeReportMainThreadException(aCx, aDispatchResult);
// The only way aDispatchResult can be false here is if either PreDispatch or
// DispatchInternal returned false.
//
// Our PreDispatch always returns true and is final. We inherit
// DispatchInternal from WorkerSyncRunnable and don't allow overriding it in
// our subclasses. WorkerSyncRunnable::DispatchInternal only returns false if
// if dispatch to the syncloop target fails or if calling up to
// WorkerRunnable::DispatchInternal fails. WorkerRunnable::DispatchInternal
// only fails if one of its runnable dispatching functions fails, and none of
// those cases can throw a JS exception. So we can never have a JS exception
// here.
MOZ_ASSERT_IF(aCx, !JS_IsExceptionPending(aCx));
}
StopSyncLoopRunnable::StopSyncLoopRunnable(

View File

@ -213,7 +213,6 @@ protected:
virtual ~WorkerSyncRunnable();
private:
virtual bool
DispatchInternal() override;
};
@ -242,14 +241,34 @@ protected:
virtual ~MainThreadWorkerSyncRunnable()
{ }
// Hook for subclasses that want to override our PreDispatch. This override
// must be infallible and must not leave an exception hanging out on the
// JSContext. We pass the JSContext through so callees that expect to be able
// to do something with script have a way to do it. We'd pass an AutoJSAPI,
// but some of our subclasses are dispatched with a null JSContext*, so we
// can't do that sort of thing ourselves.
virtual void InfalliblePreDispatch(JSContext* aCx)
{}
private:
virtual bool
PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override final
{
AssertIsOnMainThread();
InfalliblePreDispatch(aCx);
MOZ_ASSERT_IF(aCx, !JS_IsExceptionPending(aCx));
return true;
}
// We want to be able to assert in PostDispatch that no exceptions were thrown
// on aCx. We can do that if we know no one is subclassing our
// DispatchInternal to do weird things.
virtual bool
DispatchInternal() override final
{
return WorkerSyncRunnable::DispatchInternal();
}
virtual void
PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
bool aDispatchResult) override;

View File

@ -591,8 +591,8 @@ private:
~EventRunnable()
{ }
virtual bool
PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override;
virtual void
InfalliblePreDispatch(JSContext* aCx) override final;
virtual bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override;
@ -1170,10 +1170,19 @@ LoadStartDetectionRunnable::HandleEvent(nsIDOMEvent* aEvent)
return NS_OK;
}
bool
EventRunnable::PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
void
EventRunnable::InfalliblePreDispatch(JSContext* aCx)
{
AssertIsOnMainThread();
MOZ_ASSERT(aCx);
MOZ_ASSERT(JS::CurrentGlobalOrNull(aCx));
AutoJSAPI jsapi;
DebugOnly<bool> ok =
jsapi.Init(xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)), aCx);
MOZ_ASSERT(ok);
MOZ_ASSERT(jsapi.cx() == aCx);
jsapi.TakeOwnershipOfErrorReporting();
RefPtr<nsXMLHttpRequest>& xhr = mProxy->mXHR;
MOZ_ASSERT(xhr);
@ -1244,8 +1253,6 @@ EventRunnable::PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
mReadyState = xhr->ReadyState();
xhr->GetResponseURL(mResponseURL);
return true;
}
bool