зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1256424. Get rid of ThreadsafeAutoSafeJSContext. r=bholley
This commit is contained in:
Родитель
95bb8802ec
Коммит
3ff438ab43
|
@ -9,6 +9,7 @@
|
|||
#include "DOMError.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "DOMCursor.h"
|
||||
#include "mozilla/CycleCollectedJSRuntime.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/Event.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
|
@ -297,11 +298,10 @@ DOMRequestService::FireDetailedError(nsIDOMDOMRequest* aRequest,
|
|||
class FireSuccessAsyncTask : public nsRunnable
|
||||
{
|
||||
|
||||
FireSuccessAsyncTask(JSContext* aCx,
|
||||
DOMRequest* aRequest,
|
||||
FireSuccessAsyncTask(DOMRequest* aRequest,
|
||||
const JS::Value& aResult) :
|
||||
mReq(aRequest),
|
||||
mResult(aCx, aResult)
|
||||
mResult(CycleCollectedJSRuntime::Get()->Runtime(), aResult)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -314,8 +314,8 @@ public:
|
|||
Dispatch(DOMRequest* aRequest,
|
||||
const JS::Value& aResult)
|
||||
{
|
||||
mozilla::ThreadsafeAutoSafeJSContext cx;
|
||||
RefPtr<FireSuccessAsyncTask> asyncTask = new FireSuccessAsyncTask(cx, aRequest, aResult);
|
||||
RefPtr<FireSuccessAsyncTask> asyncTask =
|
||||
new FireSuccessAsyncTask(aRequest, aResult);
|
||||
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToCurrentThread(asyncTask)));
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -825,26 +825,4 @@ AutoSafeJSContext::AutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMP
|
|||
{
|
||||
}
|
||||
|
||||
ThreadsafeAutoSafeJSContext::ThreadsafeAutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
|
||||
{
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
|
||||
if (NS_IsMainThread()) {
|
||||
mCx = nullptr;
|
||||
mAutoSafeJSContext.emplace();
|
||||
} else {
|
||||
mCx = mozilla::dom::workers::GetCurrentThreadJSContext();
|
||||
mRequest.emplace(mCx);
|
||||
}
|
||||
}
|
||||
|
||||
ThreadsafeAutoSafeJSContext::operator JSContext*() const
|
||||
{
|
||||
if (mCx) {
|
||||
return mCx;
|
||||
} else {
|
||||
return *mAutoSafeJSContext;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -468,22 +468,6 @@ private:
|
|||
JSAutoCompartment mAc;
|
||||
};
|
||||
|
||||
/**
|
||||
* Like AutoSafeJSContext but can be used safely on worker threads.
|
||||
*/
|
||||
class MOZ_RAII ThreadsafeAutoSafeJSContext {
|
||||
public:
|
||||
explicit ThreadsafeAutoSafeJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
|
||||
operator JSContext*() const;
|
||||
|
||||
private:
|
||||
JSContext* mCx; // Used on workers. Null means mainthread.
|
||||
Maybe<JSAutoRequest> mRequest; // Used on workers.
|
||||
Maybe<AutoSafeJSContext> mAutoSafeJSContext; // Used on main thread.
|
||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_ScriptSettings_h
|
||||
|
|
|
@ -1762,21 +1762,22 @@ public:
|
|||
{
|
||||
MOZ_ASSERT(mCountdown > 0);
|
||||
|
||||
ThreadsafeAutoSafeJSContext cx;
|
||||
JSAutoCompartment ac(cx, mValues);
|
||||
{
|
||||
AutoJSAPI jsapi;
|
||||
if (!jsapi.Init(mValues)) {
|
||||
// Now what?
|
||||
return;
|
||||
}
|
||||
jsapi.TakeOwnershipOfErrorReporting();
|
||||
JSContext* cx = jsapi.cx();
|
||||
|
||||
AutoDontReportUncaught silenceReporting(cx);
|
||||
JS::Rooted<JS::Value> value(cx, aValue);
|
||||
JS::Rooted<JSObject*> values(cx, mValues);
|
||||
if (!JS_WrapValue(cx, &value) ||
|
||||
!JS_DefineElement(cx, values, index, value, JSPROP_ENUMERATE)) {
|
||||
MOZ_ASSERT(JS_IsExceptionPending(cx));
|
||||
JS::Rooted<JS::Value> exn(cx);
|
||||
JS_GetPendingException(cx, &exn);
|
||||
|
||||
mPromise->MaybeReject(cx, exn);
|
||||
}
|
||||
JS::Rooted<JS::Value> value(cx, aValue);
|
||||
JS::Rooted<JSObject*> values(cx, mValues);
|
||||
if (!JS_WrapValue(cx, &value) ||
|
||||
!JS_DefineElement(cx, values, index, value, JSPROP_ENUMERATE)) {
|
||||
MOZ_ASSERT(JS_IsExceptionPending(cx));
|
||||
JS::Rooted<JS::Value> exn(cx);
|
||||
jsapi.StealException(&exn);
|
||||
mPromise->MaybeReject(cx, exn);
|
||||
}
|
||||
|
||||
--mCountdown;
|
||||
|
|
Загрузка…
Ссылка в новой задаче