зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1841466 - Make `ContentCacheInChild` assert invalid cases with better message r=m_kato
The assertion reason "MOZ_DIAGNOSTIC_ASSERT(IsValid())" does not help us to debug. Make it assert with the minimum data of `ContentCache` instead. Depends on D182652 Differential Revision: https://phabricator.services.mozilla.com/D182653
This commit is contained in:
Родитель
d111bd326e
Коммит
3c8d46af25
|
@ -76,6 +76,41 @@ bool ContentCache::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void ContentCache::AssertIfInvalid() const {
|
||||
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
||||
if (IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// This text will appear in the crash reports without any permissions.
|
||||
// Do not use `ToString` here to avoid to expose unexpected data with
|
||||
// changing the type or `operator<<()`.
|
||||
nsPrintfCString info(
|
||||
"ContentCache={ mText=%s, mSelection=%s, mCaret=%s, mTextRectArray=%s, "
|
||||
"mCompositionStart=%s }\n",
|
||||
// Don't expose mText.ref() value for protecting the user's privacy.
|
||||
mText.isNothing()
|
||||
? "Nothing"
|
||||
: nsPrintfCString("{ Length()=%zu }", mText->Length()).get(),
|
||||
mSelection.isNothing()
|
||||
? "Nothing"
|
||||
: nsPrintfCString("{ mAnchor=%u, mFocus=%u }", mSelection->mAnchor,
|
||||
mSelection->mFocus)
|
||||
.get(),
|
||||
mCaret.isNothing()
|
||||
? "Nothing"
|
||||
: nsPrintfCString("{ mOffset=%u }", mCaret->mOffset).get(),
|
||||
mTextRectArray.isNothing()
|
||||
? "Nothing"
|
||||
: nsPrintfCString("{ Length()=%u }", mTextRectArray->Length()).get(),
|
||||
mCompositionStart.isNothing()
|
||||
? "Nothing"
|
||||
: nsPrintfCString("%u", mCompositionStart.value()).get());
|
||||
CrashReporter::AppendAppNotesToCrashReport(info);
|
||||
MOZ_DIAGNOSTIC_ASSERT(false, "Invalid ContentCache data");
|
||||
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* mozilla::ContentCacheInChild
|
||||
*****************************************************************************/
|
||||
|
@ -148,7 +183,7 @@ bool ContentCacheInChild::CacheAll(nsIWidget* aWidget,
|
|||
|
||||
const bool textCached = CacheText(aWidget, aNotification);
|
||||
const bool editorRectCached = CacheEditorRect(aWidget, aNotification);
|
||||
MOZ_DIAGNOSTIC_ASSERT(IsValid());
|
||||
AssertIfInvalid();
|
||||
return (textCached || editorRectCached) && IsValid();
|
||||
}
|
||||
|
||||
|
@ -190,7 +225,7 @@ bool ContentCacheInChild::CacheSelection(nsIWidget* aWidget,
|
|||
("0x%p CacheSelection(), FAILED, editable content had already been "
|
||||
"blurred",
|
||||
this));
|
||||
MOZ_DIAGNOSTIC_ASSERT(IsValid());
|
||||
AssertIfInvalid();
|
||||
return false;
|
||||
} else {
|
||||
mSelection.emplace(querySelectedTextEvent);
|
||||
|
@ -233,7 +268,7 @@ bool ContentCacheInChild::CacheCaret(nsIWidget* aWidget,
|
|||
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
||||
("0x%p CacheCaret(), Succeeded, mSelection=%s, mCaret=%s", this,
|
||||
ToString(mSelection).c_str(), ToString(mCaret).c_str()));
|
||||
MOZ_DIAGNOSTIC_ASSERT(IsValid());
|
||||
AssertIfInvalid();
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
|
@ -278,7 +313,7 @@ bool ContentCacheInChild::CacheCaretAndTextRects(
|
|||
|
||||
const bool caretCached = CacheCaret(aWidget, aNotification);
|
||||
const bool textRectsCached = CacheTextRects(aWidget, aNotification);
|
||||
MOZ_DIAGNOSTIC_ASSERT(IsValid());
|
||||
AssertIfInvalid();
|
||||
return (caretCached || textRectsCached) && IsValid();
|
||||
}
|
||||
|
||||
|
@ -340,7 +375,7 @@ bool ContentCacheInChild::CacheText(nsIWidget* aWidget,
|
|||
mSelection.reset();
|
||||
mCaret.reset();
|
||||
mTextRectArray.reset();
|
||||
MOZ_DIAGNOSTIC_ASSERT(IsValid());
|
||||
AssertIfInvalid();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -615,7 +650,7 @@ bool ContentCacheInChild::CacheTextRects(nsIWidget* aWidget,
|
|||
ToString(mTextRectArray).c_str(), ToString(mSelection).c_str(),
|
||||
ToString(mFirstCharRect).c_str(),
|
||||
ToString(mLastCommitStringTextRectArray).c_str()));
|
||||
MOZ_DIAGNOSTIC_ASSERT(IsValid());
|
||||
AssertIfInvalid();
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,8 @@ class ContentCache {
|
|||
[[nodiscard]] bool IsValid() const;
|
||||
|
||||
protected:
|
||||
void AssertIfInvalid() const;
|
||||
|
||||
// Whole text in the target
|
||||
Maybe<nsString> mText;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче