From 0bb1333a9eff1190ddd68f34c71d6a779c69dfef Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 30 Mar 2017 16:12:02 -0400 Subject: Add some calls to MakeUnique This CL replaces some new's with pdfium::MakeUnique. Change-Id: I50faf3ed55e7730b094c14a7989a9dd51cf33cbb Reviewed-on: https://pdfium-review.googlesource.com/3430 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fxjs/cfxjse_class.cpp | 44 +++++++++++++++++--------------------------- fxjs/cfxjse_context.cpp | 3 ++- 2 files changed, 19 insertions(+), 28 deletions(-) (limited to 'fxjs') diff --git a/fxjs/cfxjse_class.cpp b/fxjs/cfxjse_class.cpp index 3801fb520a..8924a48a47 100644 --- a/fxjs/cfxjse_class.cpp +++ b/fxjs/cfxjse_class.cpp @@ -10,6 +10,7 @@ #include "fxjs/cfxjse_context.h" #include "fxjs/cfxjse_value.h" +#include "third_party/base/ptr_util.h" namespace { @@ -22,10 +23,9 @@ void V8FunctionCallback_Wrapper( return; CFX_ByteStringC szFunctionName(lpFunctionInfo->name); - std::unique_ptr lpThisValue( - new CFXJSE_Value(info.GetIsolate())); + auto lpThisValue = pdfium::MakeUnique(info.GetIsolate()); lpThisValue->ForceSetValue(info.Holder()); - std::unique_ptr lpRetValue(new CFXJSE_Value(info.GetIsolate())); + auto lpRetValue = pdfium::MakeUnique(info.GetIsolate()); CFXJSE_Arguments impl(&info, lpRetValue.get()); lpFunctionInfo->callbackProc(lpThisValue.get(), szFunctionName, impl); if (!lpRetValue->DirectGetValue().IsEmpty()) @@ -41,10 +41,9 @@ void V8ClassGlobalConstructorCallback_Wrapper( return; CFX_ByteStringC szFunctionName(lpClassDefinition->name); - std::unique_ptr lpThisValue( - new CFXJSE_Value(info.GetIsolate())); + auto lpThisValue = pdfium::MakeUnique(info.GetIsolate()); lpThisValue->ForceSetValue(info.Holder()); - std::unique_ptr lpRetValue(new CFXJSE_Value(info.GetIsolate())); + auto lpRetValue = pdfium::MakeUnique(info.GetIsolate()); CFXJSE_Arguments impl(&info, lpRetValue.get()); lpClassDefinition->constructor(lpThisValue.get(), szFunctionName, impl); if (!lpRetValue->DirectGetValue().IsEmpty()) @@ -60,10 +59,8 @@ void V8GetterCallback_Wrapper(v8::Local property, return; CFX_ByteStringC szPropertyName(lpPropertyInfo->name); - std::unique_ptr lpThisValue( - new CFXJSE_Value(info.GetIsolate())); - std::unique_ptr lpPropValue( - new CFXJSE_Value(info.GetIsolate())); + auto lpThisValue = pdfium::MakeUnique(info.GetIsolate()); + auto lpPropValue = pdfium::MakeUnique(info.GetIsolate()); lpThisValue->ForceSetValue(info.Holder()); lpPropertyInfo->getProc(lpThisValue.get(), szPropertyName, lpPropValue.get()); info.GetReturnValue().Set(lpPropValue->DirectGetValue()); @@ -79,10 +76,8 @@ void V8SetterCallback_Wrapper(v8::Local property, return; CFX_ByteStringC szPropertyName(lpPropertyInfo->name); - std::unique_ptr lpThisValue( - new CFXJSE_Value(info.GetIsolate())); - std::unique_ptr lpPropValue( - new CFXJSE_Value(info.GetIsolate())); + auto lpThisValue = pdfium::MakeUnique(info.GetIsolate()); + auto lpPropValue = pdfium::MakeUnique(info.GetIsolate()); lpThisValue->ForceSetValue(info.Holder()); lpPropValue->ForceSetValue(value); lpPropertyInfo->setProc(lpThisValue.get(), szPropertyName, lpPropValue.get()); @@ -135,10 +130,9 @@ void DynPropGetterAdapter_MethodCallback( ASSERT(lpClass && !hPropName.IsEmpty()); v8::String::Utf8Value szPropName(hPropName); CFX_ByteStringC szFxPropName = *szPropName; - std::unique_ptr lpThisValue( - new CFXJSE_Value(info.GetIsolate())); + auto lpThisValue = pdfium::MakeUnique(info.GetIsolate()); lpThisValue->ForceSetValue(info.Holder()); - std::unique_ptr lpRetValue(new CFXJSE_Value(info.GetIsolate())); + auto lpRetValue = pdfium::MakeUnique(info.GetIsolate()); CFXJSE_Arguments impl(&info, lpRetValue.get()); lpClass->dynMethodCall(lpThisValue.get(), szFxPropName, impl); if (!lpRetValue->DirectGetValue().IsEmpty()) @@ -233,8 +227,7 @@ void NamedPropertyQueryCallback( v8::HandleScope scope(pIsolate); v8::String::Utf8Value szPropName(property); CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); - std::unique_ptr lpThisValue( - new CFXJSE_Value(info.GetIsolate())); + auto lpThisValue = pdfium::MakeUnique(info.GetIsolate()); lpThisValue->ForceSetValue(thisObject); if (DynPropQueryAdapter(lpClass, lpThisValue.get(), szFxPropName)) { info.GetReturnValue().Set(v8::DontDelete); @@ -254,8 +247,7 @@ void NamedPropertyDeleterCallback( v8::HandleScope scope(pIsolate); v8::String::Utf8Value szPropName(property); CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); - std::unique_ptr lpThisValue( - new CFXJSE_Value(info.GetIsolate())); + auto lpThisValue = pdfium::MakeUnique(info.GetIsolate()); lpThisValue->ForceSetValue(thisObject); info.GetReturnValue().Set( !!DynPropDeleterAdapter(lpClass, lpThisValue.get(), szFxPropName)); @@ -269,10 +261,9 @@ void NamedPropertyGetterCallback( info.Data().As()->Value()); v8::String::Utf8Value szPropName(property); CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); - std::unique_ptr lpThisValue( - new CFXJSE_Value(info.GetIsolate())); + auto lpThisValue = pdfium::MakeUnique(info.GetIsolate()); lpThisValue->ForceSetValue(thisObject); - std::unique_ptr lpNewValue(new CFXJSE_Value(info.GetIsolate())); + auto lpNewValue = pdfium::MakeUnique(info.GetIsolate()); DynPropGetterAdapter(lpClass, lpThisValue.get(), szFxPropName, lpNewValue.get()); info.GetReturnValue().Set(lpNewValue->DirectGetValue()); @@ -287,11 +278,10 @@ void NamedPropertySetterCallback( info.Data().As()->Value()); v8::String::Utf8Value szPropName(property); CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); - std::unique_ptr lpThisValue( - new CFXJSE_Value(info.GetIsolate())); + auto lpThisValue = pdfium::MakeUnique(info.GetIsolate()); lpThisValue->ForceSetValue(thisObject); - std::unique_ptr lpNewValue(new CFXJSE_Value(info.GetIsolate())); + auto lpNewValue = pdfium::MakeUnique(info.GetIsolate()); lpNewValue->ForceSetValue(value); DynPropSetterAdapter(lpClass, lpThisValue.get(), szFxPropName, lpNewValue.get()); diff --git a/fxjs/cfxjse_context.cpp b/fxjs/cfxjse_context.cpp index 076e6cf2b1..d3b55ff43e 100644 --- a/fxjs/cfxjse_context.cpp +++ b/fxjs/cfxjse_context.cpp @@ -8,6 +8,7 @@ #include "fxjs/cfxjse_class.h" #include "fxjs/cfxjse_value.h" +#include "third_party/base/ptr_util.h" namespace { @@ -187,7 +188,7 @@ CFXJSE_Context::CFXJSE_Context(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {} CFXJSE_Context::~CFXJSE_Context() {} std::unique_ptr CFXJSE_Context::GetGlobalObject() { - std::unique_ptr pValue(new CFXJSE_Value(m_pIsolate)); + auto pValue = pdfium::MakeUnique(m_pIsolate); CFXJSE_ScopeUtil_IsolateHandleContext scope(this); v8::Local hContext = -- cgit v1.2.3