Bug 1688585 - Log the reason for nulling out PromiseNativeHandlerShim::mInner. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D145967
This commit is contained in:
Peter Van der Beken 2022-05-10 18:54:52 +00:00
Родитель 6c334e2b06
Коммит 1cc164647d
1 изменённых файлов: 43 добавлений и 1 удалений

Просмотреть файл

@ -396,6 +396,15 @@ namespace {
class PromiseNativeHandlerShim final : public PromiseNativeHandler {
RefPtr<PromiseNativeHandler> mInner;
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
enum InnerState{
NotCleared,
ClearedFromResolve,
ClearedFromReject,
ClearedFromCC,
};
InnerState mState = NotCleared;
#endif
~PromiseNativeHandlerShim() = default;
@ -408,17 +417,41 @@ class PromiseNativeHandlerShim final : public PromiseNativeHandler {
MOZ_CAN_RUN_SCRIPT
void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
ErrorResult& aRv) override {
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
MOZ_DIAGNOSTIC_ASSERT(mState != ClearedFromResolve);
MOZ_DIAGNOSTIC_ASSERT(mState != ClearedFromReject);
MOZ_DIAGNOSTIC_ASSERT(mState != ClearedFromCC);
#else
if (!mInner) {
return;
}
#endif
RefPtr<PromiseNativeHandler> inner = std::move(mInner);
inner->ResolvedCallback(aCx, aValue, aRv);
MOZ_ASSERT(!mInner);
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
mState = ClearedFromResolve;
#endif
}
MOZ_CAN_RUN_SCRIPT
void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
ErrorResult& aRv) override {
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
MOZ_DIAGNOSTIC_ASSERT(mState != ClearedFromResolve);
MOZ_DIAGNOSTIC_ASSERT(mState != ClearedFromReject);
MOZ_DIAGNOSTIC_ASSERT(mState != ClearedFromCC);
#else
if (!mInner) {
return;
}
#endif
RefPtr<PromiseNativeHandler> inner = std::move(mInner);
inner->RejectedCallback(aCx, aValue, aRv);
MOZ_ASSERT(!mInner);
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
mState = ClearedFromReject;
#endif
}
bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
@ -430,7 +463,16 @@ class PromiseNativeHandlerShim final : public PromiseNativeHandler {
NS_DECL_CYCLE_COLLECTION_CLASS(PromiseNativeHandlerShim)
};
NS_IMPL_CYCLE_COLLECTION(PromiseNativeHandlerShim, mInner)
NS_IMPL_CYCLE_COLLECTION_CLASS(PromiseNativeHandlerShim)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(PromiseNativeHandlerShim)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mInner)
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
tmp->mState = ClearedFromCC;
#endif
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(PromiseNativeHandlerShim)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInner)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(PromiseNativeHandlerShim)
NS_IMPL_CYCLE_COLLECTING_RELEASE(PromiseNativeHandlerShim)