From 57e097750846bf3ffc3e4e2ef9e78be8a82c69de Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 5 Feb 2018 18:52:09 +0000 Subject: Use unique pointer in CFXJS_PerObjectData. Also use the actual type information, not void* and remove casts. Template function not required to wrap virtual dtors. Change-Id: I9397cae136c3c395a368a1ef0ce8162d9b586076 Reviewed-on: https://pdfium-review.googlesource.com/25290 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- fxjs/fxjs_v8.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'fxjs/fxjs_v8.cpp') diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp index f1555b2e96..2161076e36 100644 --- a/fxjs/fxjs_v8.cpp +++ b/fxjs/fxjs_v8.cpp @@ -6,9 +6,12 @@ #include "fxjs/fxjs_v8.h" +#include +#include #include #include "fxjs/cfxjse_runtimedata.h" +#include "fxjs/cjs_object.h" #include "third_party/base/allocator/partition_allocator/partition_alloc.h" // Keep this consistent with the values defined in gin/public/context_holder.h @@ -25,8 +28,9 @@ static wchar_t kPerObjectDataTag[] = L"CFXJS_PerObjectData"; class CFXJS_PerObjectData { public: - explicit CFXJS_PerObjectData(int nObjDefID) - : m_ObjDefID(nObjDefID), m_pPrivate(nullptr) {} + explicit CFXJS_PerObjectData(int nObjDefID) : m_ObjDefID(nObjDefID) {} + + ~CFXJS_PerObjectData() = default; static void SetInObject(CFXJS_PerObjectData* pData, v8::Local pObj) { @@ -48,7 +52,7 @@ class CFXJS_PerObjectData { } const int m_ObjDefID; - void* m_pPrivate; + std::unique_ptr m_pPrivate; }; class CFXJS_ObjDefinition { @@ -540,15 +544,16 @@ void CFXJS_Engine::Error(const WideString& message) { GetIsolate()->ThrowException(NewString(message.AsStringView())); } -void CFXJS_Engine::SetObjectPrivate(v8::Local pObj, void* p) { +void CFXJS_Engine::SetObjectPrivate(v8::Local pObj, + std::unique_ptr p) { CFXJS_PerObjectData* pPerObjectData = CFXJS_PerObjectData::GetFromObject(pObj); if (!pPerObjectData) return; - pPerObjectData->m_pPrivate = p; + pPerObjectData->m_pPrivate = std::move(p); } -void* CFXJS_Engine::GetObjectPrivate(v8::Local pObj) { +CJS_Object* CFXJS_Engine::GetObjectPrivate(v8::Local pObj) { CFXJS_PerObjectData* pData = CFXJS_PerObjectData::GetFromObject(pObj); if (!pData && !pObj.IsEmpty()) { // It could be a global proxy object. @@ -559,7 +564,7 @@ void* CFXJS_Engine::GetObjectPrivate(v8::Local pObj) { v->ToObject(context).ToLocalChecked()); } } - return pData ? pData->m_pPrivate : nullptr; + return pData ? pData->m_pPrivate.get() : nullptr; } v8::Local CFXJS_Engine::GetConstArray(const WideString& name) { -- cgit v1.2.3