Commit c42809bb authored by bugsnash's avatar bugsnash Committed by Commit bot

Added move constructor to PassRefPtr.

This is the first step in making PassRefPtr move only,
in preparation for removal of PassRefPtr.

BUG=640449

Review-Url: https://codereview.chromium.org/2274793002
Cr-Commit-Position: refs/heads/master@{#415123}
parent 76e9521d
......@@ -69,6 +69,7 @@ public:
// PassRefPtr temporaries, and we don't have a need to use real const
// PassRefPtrs anyway.
PassRefPtr(const PassRefPtr& o) : m_ptr(o.leakRef()) {}
PassRefPtr(PassRefPtr&& o) : m_ptr(o.leakRef()) {}
template <typename U> PassRefPtr(const PassRefPtr<U>& o, EnsurePtrConvertibleArgDecl(U, T)) : m_ptr(o.leakRef()) {}
ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull(m_ptr); }
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "wtf/PassRefPtr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/RefCounted.h"
namespace WTF {
class RefCountedClass : public RefCounted<RefCountedClass> {
};
TEST(PassRefPtrTest, MoveConstructor)
{
PassRefPtr<RefCountedClass> oldPassRefPtr = adoptRef(new RefCountedClass());
RefCountedClass* rawPtr = oldPassRefPtr.get();
EXPECT_EQ(rawPtr->refCount(), 1);
PassRefPtr<RefCountedClass> newPassRefPtr(std::move(oldPassRefPtr));
EXPECT_EQ(oldPassRefPtr.get(), nullptr);
EXPECT_EQ(newPassRefPtr.get(), rawPtr);
EXPECT_EQ(rawPtr->refCount(), 1);
}
} // namespace WTF
......@@ -216,6 +216,7 @@
'MakeCancellableTest.cpp',
'MathExtrasTest.cpp',
'OptionalTest.cpp',
'PassRefPtrTest.cpp',
'RefPtrTest.cpp',
'SaturatedArithmeticTest.cpp',
'StringExtrasTest.cpp',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment