Bug 1947437 - Fix the nullptr assignment on CheckedUnsafePtr. r=dom-worker-reviewers,asuth,smaug
Differential Revision: https://phabricator.services.mozilla.com/D235952
This commit is contained in:
@@ -289,11 +289,17 @@ class CheckedUnsafePtrBase<T, CheckingSupport::Enabled>
|
||||
CheckedUnsafePtrBase& operator=(const CheckedUnsafePtrBase& aOther) {
|
||||
if (StaticPrefs::dom_checkedUnsafePtr_dumpStacks_enabled()) {
|
||||
mLastAssignmentStack.Truncate();
|
||||
MozStackWalk(CheckedUnsafePtrStackCallback, CallerPC(), 0,
|
||||
&mLastAssignmentStack);
|
||||
if (aOther.get()) {
|
||||
MozStackWalk(CheckedUnsafePtrStackCallback, CallerPC(), 0,
|
||||
&mLastAssignmentStack);
|
||||
}
|
||||
}
|
||||
if (&aOther != this) {
|
||||
Replace(aOther.Downcast());
|
||||
if (aOther.get()) {
|
||||
Replace(aOther.Downcast());
|
||||
} else {
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
return Downcast();
|
||||
}
|
||||
|
||||
@@ -56,7 +56,9 @@ class CheckedUnsafePtrTest : public ::testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(CheckedUnsafePtrTest, PointeeWithNoCheckedUnsafePtrs) {
|
||||
{ DerivedPointee pointee{mPassedCheck}; }
|
||||
{
|
||||
DerivedPointee pointee{mPassedCheck};
|
||||
}
|
||||
ASSERT_TRUE(mPassedCheck);
|
||||
}
|
||||
|
||||
@@ -92,6 +94,23 @@ TYPED_TEST_P(TypedCheckedUnsafePtrTest, CheckedUnsafePtrCopyAssigned) {
|
||||
ASSERT_TRUE(this->mPassedCheck);
|
||||
}
|
||||
|
||||
TYPED_TEST_P(TypedCheckedUnsafePtrTest, CheckedUnsafePtrNullptrAssigned) {
|
||||
{
|
||||
CheckedUnsafePtr<TypeParam> ptr = nullptr;
|
||||
}
|
||||
ASSERT_TRUE(this->mPassedCheck);
|
||||
}
|
||||
|
||||
TYPED_TEST_P(TypedCheckedUnsafePtrTest,
|
||||
CheckedUnsafePtrNullCheckedUnsafePtrAssigned) {
|
||||
{
|
||||
CheckedUnsafePtr<TypeParam> ptr1(nullptr);
|
||||
CheckedUnsafePtr<TypeParam> ptr2;
|
||||
ptr2 = ptr1;
|
||||
}
|
||||
ASSERT_TRUE(this->mPassedCheck);
|
||||
}
|
||||
|
||||
TYPED_TEST_P(TypedCheckedUnsafePtrTest,
|
||||
PointeeWithOneDanglingCheckedUnsafePtr) {
|
||||
[this]() -> CheckedUnsafePtr<TypeParam> {
|
||||
@@ -136,6 +155,8 @@ REGISTER_TYPED_TEST_SUITE_P(TypedCheckedUnsafePtrTest,
|
||||
PointeeWithOneCheckedUnsafePtr,
|
||||
CheckedUnsafePtrCopyConstructed,
|
||||
CheckedUnsafePtrCopyAssigned,
|
||||
CheckedUnsafePtrNullptrAssigned,
|
||||
CheckedUnsafePtrNullCheckedUnsafePtrAssigned,
|
||||
PointeeWithOneDanglingCheckedUnsafePtr,
|
||||
PointeeWithOneCopiedDanglingCheckedUnsafePtr,
|
||||
PointeeWithOneCopyAssignedDanglingCheckedUnsafePtr);
|
||||
|
||||
Reference in New Issue
Block a user