Rename UnownedPtr methods to match their raw_ptr counterparts.

-- Release() becomes ExtractAsDangling()
-- Get() becomes get()
-- Reset() is not present, only operator=(), so make private.
-- Call get() in a few soon-to-be ambiguous situations.

Change-Id: Ide0f14ecaaa9a34c9ad95773985f534bdfd97c34
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/103499
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp b/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp
index d0162de..26e8b7f 100644
--- a/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp
+++ b/core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp
@@ -64,7 +64,7 @@
 
 CFX_RenderDevice* CPDF_ScaledRenderBuffer::GetDevice() const {
   return m_pBitmapDevice ? static_cast<CFX_RenderDevice*>(m_pBitmapDevice.get())
-                         : m_pDevice;
+                         : m_pDevice.get();
 }
 
 void CPDF_ScaledRenderBuffer::OutputToDevice() {
diff --git a/core/fxcodec/jpx/cjpx_decoder.cpp b/core/fxcodec/jpx/cjpx_decoder.cpp
index 00f1d11..5f193c7 100644
--- a/core/fxcodec/jpx/cjpx_decoder.cpp
+++ b/core/fxcodec/jpx/cjpx_decoder.cpp
@@ -410,11 +410,11 @@
 
 CJPX_Decoder::~CJPX_Decoder() {
   if (m_Codec)
-    opj_destroy_codec(m_Codec.Release());
+    opj_destroy_codec(m_Codec.ExtractAsDangling());
   if (m_Stream)
-    opj_stream_destroy(m_Stream.Release());
+    opj_stream_destroy(m_Stream.ExtractAsDangling());
   if (m_Image)
-    opj_image_destroy(m_Image.Release());
+    opj_image_destroy(m_Image.ExtractAsDangling());
 }
 
 bool CJPX_Decoder::Init(pdfium::span<const uint8_t> src_data,
@@ -468,12 +468,12 @@
     if (!opj_set_decode_area(m_Codec, m_Image, m_Parameters.DA_x0,
                              m_Parameters.DA_y0, m_Parameters.DA_x1,
                              m_Parameters.DA_y1)) {
-      opj_image_destroy(m_Image.Release());
+      opj_image_destroy(m_Image.ExtractAsDangling());
       return false;
     }
     if (!(opj_decode(m_Codec, m_Stream, m_Image) &&
           opj_end_decompress(m_Codec, m_Stream))) {
-      opj_image_destroy(m_Image.Release());
+      opj_image_destroy(m_Image.ExtractAsDangling());
       return false;
     }
   } else if (!opj_get_decoded_tile(m_Codec, m_Stream, m_Image,
@@ -481,7 +481,7 @@
     return false;
   }
 
-  opj_stream_destroy(m_Stream.Release());
+  opj_stream_destroy(m_Stream.ExtractAsDangling());
   if (m_Image->color_space != OPJ_CLRSPC_SYCC && m_Image->numcomps == 3 &&
       m_Image->comps[0].dx == m_Image->comps[0].dy &&
       m_Image->comps[1].dx != 1) {
diff --git a/core/fxcrt/fx_folder_posix.cpp b/core/fxcrt/fx_folder_posix.cpp
index 156ab1b..b4cf9f9 100644
--- a/core/fxcrt/fx_folder_posix.cpp
+++ b/core/fxcrt/fx_folder_posix.cpp
@@ -47,7 +47,7 @@
     : m_Path(path), m_Dir(dir) {}
 
 FX_PosixFolder::~FX_PosixFolder() {
-  closedir(m_Dir.Release());
+  closedir(m_Dir.ExtractAsDangling());
 }
 
 bool FX_PosixFolder::GetNextFile(ByteString* filename, bool* bFolder) {
diff --git a/core/fxcrt/unowned_ptr.h b/core/fxcrt/unowned_ptr.h
index d8cb498..1a2c9bb 100644
--- a/core/fxcrt/unowned_ptr.h
+++ b/core/fxcrt/unowned_ptr.h
@@ -64,7 +64,8 @@
 
   // Move-construct an UnownedPtr. After construction, |that| will be NULL.
   // Required in addition to move conversion constructor below.
-  constexpr UnownedPtr(UnownedPtr&& that) noexcept : m_pObj(that.Release()) {}
+  constexpr UnownedPtr(UnownedPtr&& that) noexcept
+      : m_pObj(that.ExtractAsDangling()) {}
 
   // Copy-conversion constructor.
   template <class U,
@@ -77,7 +78,7 @@
             typename = typename std::enable_if<
                 std::is_convertible<U*, T*>::value>::type>
   UnownedPtr(UnownedPtr<U>&& that) noexcept {
-    Reset(that.Release());
+    Reset(that.ExtractAsDangling());
   }
 
   // Assign an UnownedPtr from nullptr.
@@ -104,7 +105,7 @@
   // Required in addition to move conversion assignment below.
   UnownedPtr& operator=(UnownedPtr&& that) noexcept {
     if (*this != that)
-      Reset(that.Release());
+      Reset(that.ExtractAsDangling());
     return *this;
   }
 
@@ -124,7 +125,7 @@
                 std::is_convertible<U*, T*>::value>::type>
   UnownedPtr& operator=(UnownedPtr<U>&& that) noexcept {
     if (*this != that)
-      Reset(that.Release());
+      Reset(that.ExtractAsDangling());
     return *this;
   }
 
@@ -133,11 +134,6 @@
     m_pObj = nullptr;
   }
 
-  void Reset(T* obj = nullptr) {
-    ProbeForLowSeverityLifetimeIssue();
-    m_pObj = obj;
-  }
-
   bool operator==(std::nullptr_t ptr) const { return m_pObj == nullptr; }
   bool operator==(const UnownedPtr& that) const {
     return m_pObj == static_cast<T*>(that);
@@ -147,9 +143,9 @@
   }
 
   operator T*() const noexcept { return m_pObj; }
-  T* Get() const noexcept { return m_pObj; }
+  T* get() const noexcept { return m_pObj; }
 
-  T* Release() {
+  T* ExtractAsDangling() {
     ProbeForLowSeverityLifetimeIssue();
     T* pTemp = nullptr;
     std::swap(pTemp, m_pObj);
@@ -163,6 +159,11 @@
  private:
   friend class pdfium::span<T>;
 
+  void Reset(T* obj = nullptr) {
+    ProbeForLowSeverityLifetimeIssue();
+    m_pObj = obj;
+  }
+
   inline void ProbeForLowSeverityLifetimeIssue() {
 #if defined(ADDRESS_SANITIZER)
     if (m_pObj)
diff --git a/core/fxcrt/unowned_ptr_unittest.cpp b/core/fxcrt/unowned_ptr_unittest.cpp
index 7ffa411..f0c10ee 100644
--- a/core/fxcrt/unowned_ptr_unittest.cpp
+++ b/core/fxcrt/unowned_ptr_unittest.cpp
@@ -35,15 +35,6 @@
   }
 }
 
-void ResetDangling() {
-  auto ptr2 = std::make_unique<Clink>();
-  {
-    auto ptr1 = std::make_unique<Clink>();
-    ptr2->next_.Reset(ptr1.get());
-  }
-  ptr2->next_.Reset();
-}
-
 void AssignDangling() {
   auto ptr2 = std::make_unique<Clink>();
   {
@@ -59,7 +50,7 @@
     auto ptr1 = std::make_unique<Clink>();
     ptr2->next_ = ptr1.get();
   }
-  ptr2->next_.Release();
+  ptr2->next_.ExtractAsDangling();
 }
 
 }  // namespace
@@ -178,23 +169,6 @@
 #endif
 }
 
-TEST(UnownedPtr, ResetOk) {
-  auto ptr1 = std::make_unique<Clink>();
-  {
-    auto ptr2 = std::make_unique<Clink>();
-    ptr2->next_.Reset(ptr1.get());
-    ptr2->next_.Reset(nullptr);
-  }
-}
-
-TEST(UnownedPtr, ResetNotOk) {
-#if defined(ADDRESS_SANITIZER)
-  EXPECT_DEATH(ResetDangling(), "");
-#else
-  ResetDangling();
-#endif
-}
-
 TEST(UnownedPtr, AssignOk) {
   auto ptr1 = std::make_unique<Clink>();
   {
@@ -217,7 +191,7 @@
   {
     auto ptr1 = std::make_unique<Clink>();
     ptr2->next_ = ptr1.get();
-    ptr2->next_.Release();
+    ptr2->next_.ExtractAsDangling();
   }
 }
 
diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp
index 4142399..9c38bfa 100644
--- a/fpdfsdk/fpdf_sysfontinfo.cpp
+++ b/fpdfsdk/fpdf_sysfontinfo.cpp
@@ -176,7 +176,7 @@
 
 static void DefaultRelease(struct _FPDF_SYSFONTINFO* pThis) {
   auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
-  delete pDefault->m_pFontInfo.Release();
+  delete pDefault->m_pFontInfo.ExtractAsDangling();
 }
 
 static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper) {
diff --git a/fpdfsdk/pwl/cpwl_combo_box.cpp b/fpdfsdk/pwl/cpwl_combo_box.cpp
index 50c19f4..29d1cea 100644
--- a/fpdfsdk/pwl/cpwl_combo_box.cpp
+++ b/fpdfsdk/pwl/cpwl_combo_box.cpp
@@ -37,9 +37,9 @@
   // subclasses, implement the virtual OnDestroy method that does the
   // cleanup first, then invokes the superclass OnDestroy ... gee,
   // like a dtor would.
-  m_pList.Release();
-  m_pButton.Release();
-  m_pEdit.Release();
+  m_pList.ExtractAsDangling();
+  m_pButton.ExtractAsDangling();
+  m_pEdit.ExtractAsDangling();
   CPWL_Wnd::OnDestroy();
 }
 
diff --git a/fpdfsdk/pwl/cpwl_edit.cpp b/fpdfsdk/pwl/cpwl_edit.cpp
index f0b4d35..e41b339 100644
--- a/fpdfsdk/pwl/cpwl_edit.cpp
+++ b/fpdfsdk/pwl/cpwl_edit.cpp
@@ -467,7 +467,7 @@
 }
 
 void CPWL_Edit::OnDestroy() {
-  m_pCaret.Release();
+  m_pCaret.ExtractAsDangling();
 }
 
 bool CPWL_Edit::IsWndHorV() const {
diff --git a/fpdfsdk/pwl/cpwl_scroll_bar.cpp b/fpdfsdk/pwl/cpwl_scroll_bar.cpp
index 904f404..00a9418 100644
--- a/fpdfsdk/pwl/cpwl_scroll_bar.cpp
+++ b/fpdfsdk/pwl/cpwl_scroll_bar.cpp
@@ -119,9 +119,9 @@
   // subclasses, implement the virtual OnDestroy method that does the
   // cleanup first, then invokes the superclass OnDestroy ... gee,
   // like a dtor would.
-  m_pMinButton.Release();
-  m_pMaxButton.Release();
-  m_pPosButton.Release();
+  m_pMinButton.ExtractAsDangling();
+  m_pMaxButton.ExtractAsDangling();
+  m_pPosButton.ExtractAsDangling();
   CPWL_Wnd::OnDestroy();
 }
 
diff --git a/fxjs/cfx_v8.cpp b/fxjs/cfx_v8.cpp
index 80d28bb..422e28a 100644
--- a/fxjs/cfx_v8.cpp
+++ b/fxjs/cfx_v8.cpp
@@ -34,7 +34,7 @@
 
 void CFX_V8::DisposeIsolate() {
   if (m_pIsolate)
-    m_pIsolate.Release()->Dispose();
+    m_pIsolate.ExtractAsDangling()->Dispose();
 }
 
 v8::Local<v8::Array> CFX_V8::NewArray() {
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index ffbbfcb..101dee2 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -162,7 +162,7 @@
 
 CJS_Global::~CJS_Global() {
   DestroyGlobalPersisitentVariables();
-  m_pGlobalData.Release()->Release();
+  m_pGlobalData.ExtractAsDangling()->Release();
 }
 
 bool CJS_Global::HasProperty(const ByteString& propname) {
diff --git a/fxjs/ijs_runtime.cpp b/fxjs/ijs_runtime.cpp
index 8aeed9a..0308524 100644
--- a/fxjs/ijs_runtime.cpp
+++ b/fxjs/ijs_runtime.cpp
@@ -19,7 +19,7 @@
     : m_pRuntime(pRuntime), m_pContext(pRuntime->NewEventContext()) {}
 
 IJS_Runtime::ScopedEventContext::~ScopedEventContext() {
-  m_pRuntime->ReleaseEventContext(m_pContext.Release());
+  m_pRuntime->ReleaseEventContext(m_pContext.ExtractAsDangling());
 }
 
 // static
diff --git a/fxjs/js_define.h b/fxjs/js_define.h
index 310cdb4..1228c10 100644
--- a/fxjs/js_define.h
+++ b/fxjs/js_define.h
@@ -75,7 +75,7 @@
   if (!pRuntime)
     return;
 
-  CJS_Result result = (pObj->*M)(pRuntime);
+  CJS_Result result = (pObj.get()->*M)(pRuntime);
   if (result.HasError()) {
     pRuntime->Error(JSFormatErrorString(class_name_string, prop_name_string,
                                         result.Error()));
@@ -100,7 +100,7 @@
   if (!pRuntime)
     return;
 
-  CJS_Result result = (pObj->*M)(pRuntime, value);
+  CJS_Result result = (pObj.get()->*M)(pRuntime, value);
   if (result.HasError()) {
     pRuntime->Error(JSFormatErrorString(class_name_string, prop_name_string,
                                         result.Error()));
@@ -125,7 +125,7 @@
   for (unsigned int i = 0; i < (unsigned int)info.Length(); i++)
     parameters.push_back(info[i]);
 
-  CJS_Result result = (pObj->*M)(pRuntime, parameters);
+  CJS_Result result = (pObj.get()->*M)(pRuntime, parameters);
   if (result.HasError()) {
     pRuntime->Error(JSFormatErrorString(class_name_string, method_name_string,
                                         result.Error()));
diff --git a/testing/font_renamer.cpp b/testing/font_renamer.cpp
index 5e8d62a..6a3a81c 100644
--- a/testing/font_renamer.cpp
+++ b/testing/font_renamer.cpp
@@ -87,5 +87,5 @@
 }
 
 FontRenamer::~FontRenamer() {
-  FPDF_FreeDefaultSystemFontInfo(impl_.Release());
+  FPDF_FreeDefaultSystemFontInfo(impl_.ExtractAsDangling());
 }