Bug 1546506 - Add an assertion to ensure that we won't construct SeekTarget with invalid time. r=bryce

We should only use valid time to construct a `SeekTarget`, because we can't get the value from the invalid time.

This can help us to prevent having a crash when request data value from an invalid time.

Differential Revision: https://phabricator.services.mozilla.com/D28564

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alastor Wu 2019-04-24 17:07:40 +00:00
Родитель 9563f008ce
Коммит f9ae0149f6
1 изменённых файлов: 8 добавлений и 4 удалений

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

@ -28,11 +28,15 @@ struct SeekTarget {
mType(SeekTarget::Invalid),
mVideoOnly(false) {}
SeekTarget(const media::TimeUnit& aTime, Type aType, bool aVideoOnly = false)
: mTime(aTime), mType(aType), mVideoOnly(aVideoOnly) {}
: mTime(aTime), mType(aType), mVideoOnly(aVideoOnly) {
MOZ_ASSERT(mTime.IsValid());
}
SeekTarget(const SeekTarget& aOther)
: mTime(aOther.mTime),
mType(aOther.mType),
mVideoOnly(aOther.mVideoOnly) {}
mVideoOnly(aOther.mVideoOnly) {
MOZ_ASSERT(mTime.IsValid());
}
bool IsValid() const { return mType != SeekTarget::Invalid; }
void Reset() {
mTime = media::TimeUnit::Invalid();
@ -40,11 +44,11 @@ struct SeekTarget {
mVideoOnly = false;
}
media::TimeUnit GetTime() const {
NS_ASSERTION(mTime.IsValid(), "Invalid SeekTarget");
MOZ_ASSERT(mTime.IsValid(), "Invalid SeekTarget");
return mTime;
}
void SetTime(const media::TimeUnit& aTime) {
NS_ASSERTION(aTime.IsValid(), "Invalid SeekTarget destination");
MOZ_ASSERT(aTime.IsValid(), "Invalid SeekTarget destination");
mTime = aTime;
}
void SetType(Type aType) { mType = aType; }