Bug 1248719. Fix things so that taking ownership of error reporting on an AutoJSAPI on a worker is OK even if that AutoJSAPI was initialized without an explicit global. r=bholley

This commit is contained in:
Boris Zbarsky 2016-02-17 22:56:36 -05:00
parent 82f8a5e482
commit 2ad08651e7
4 changed files with 17 additions and 4 deletions

View File

@ -507,8 +507,13 @@ AutoJSAPI::ReportException()
// In this case, we enter the privileged junk scope and don't dispatch any
// error events.
JS::Rooted<JSObject*> errorGlobal(cx(), JS::CurrentGlobalOrNull(cx()));
if (!errorGlobal)
errorGlobal = xpc::PrivilegedJunkScope();
if (!errorGlobal) {
if (mIsMainThread) {
errorGlobal = xpc::PrivilegedJunkScope();
} else {
errorGlobal = workers::GetCurrentThreadWorkerGlobal();
}
}
JSAutoCompartment ac(cx(), errorGlobal);
JS::Rooted<JS::Value> exn(cx());
js::ErrorReport jsReport(cx());

View File

@ -3247,8 +3247,7 @@ UnprivilegedJunkScopeOrWorkerGlobal()
return xpc::UnprivilegedJunkScope();
}
return workers::GetCurrentThreadWorkerPrivate()->
GlobalScope()->GetGlobalJSObject();
return workers::GetCurrentThreadWorkerGlobal();
}
} // namespace binding_detail

View File

@ -1369,6 +1369,12 @@ GetCurrentThreadJSContext()
return GetCurrentThreadWorkerPrivate()->GetJSContext();
}
JSObject*
GetCurrentThreadWorkerGlobal()
{
return GetCurrentThreadWorkerPrivate()->GlobalScope()->GetGlobalJSObject();
}
END_WORKERS_NAMESPACE
struct RuntimeService::IdleThreadInfo

View File

@ -1446,6 +1446,9 @@ IsCurrentThreadRunningChromeWorker();
JSContext*
GetCurrentThreadJSContext();
JSObject*
GetCurrentThreadWorkerGlobal();
class AutoSyncLoopHolder
{
WorkerPrivate* mWorkerPrivate;