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/JS_Define.h | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'fxjs/JS_Define.h') diff --git a/fxjs/JS_Define.h b/fxjs/JS_Define.h index f45738e847..1c2410f18f 100644 --- a/fxjs/JS_Define.h +++ b/fxjs/JS_Define.h @@ -7,6 +7,7 @@ #ifndef FXJS_JS_DEFINE_H_ #define FXJS_JS_DEFINE_H_ +#include #include #include "fxjs/cjs_object.h" @@ -49,16 +50,14 @@ std::vector> ExpandKeywordParams( template static void JSConstructor(CFXJS_Engine* pEngine, v8::Local obj) { - CJS_Object* pObj = new T(obj); - pObj->SetEmbedObject(pdfium::MakeUnique(pObj)); - pEngine->SetObjectPrivate(obj, pObj); + auto pObj = pdfium::MakeUnique(obj); + pObj->SetEmbedObject(pdfium::MakeUnique(pObj.get())); pObj->InitInstance(static_cast(pEngine)); + pEngine->SetObjectPrivate(obj, std::move(pObj)); } -template -static void JSDestructor(CFXJS_Engine* pEngine, v8::Local obj) { - delete static_cast(pEngine->GetObjectPrivate(obj)); -} +// CJS_Object has vitual dtor, template not required. +void JSDestructor(CFXJS_Engine* pEngine, v8::Local obj); template void JSPropGetter(const char* prop_name_string, @@ -70,8 +69,7 @@ void JSPropGetter(const char* prop_name_string, if (!pRuntime) return; - CJS_Object* pJSObj = - static_cast(pRuntime->GetObjectPrivate(info.Holder())); + CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder()); if (!pJSObj) return; @@ -98,8 +96,7 @@ void JSPropSetter(const char* prop_name_string, if (!pRuntime) return; - CJS_Object* pJSObj = - static_cast(pRuntime->GetObjectPrivate(info.Holder())); + CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder()); if (!pJSObj) return; @@ -122,8 +119,7 @@ void JSMethod(const char* method_name_string, if (!pRuntime) return; - CJS_Object* pJSObj = - static_cast(pRuntime->GetObjectPrivate(info.Holder())); + CJS_Object* pJSObj = pRuntime->GetObjectPrivate(info.Holder()); if (!pJSObj) return; -- cgit v1.2.3