diff options
author | dsinclair <dsinclair@chromium.org> | 2016-05-31 11:34:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-31 11:34:04 -0700 |
commit | 86fad999ba59b1f8780582cc683b008880aab42e (patch) | |
tree | bc63f57e472a4aca6c2316eea4707d0aa415c122 /xfa/fxjse | |
parent | 4dce6d4689d464c3a8825a5d6aa790adfc9228ee (diff) | |
download | pdfium-86fad999ba59b1f8780582cc683b008880aab42e.tar.xz |
Replace CFXJSE_Value create/destroy with new and delete.
In most cases, the destroy calls were removed and the object wrapped in a
unique_ptr.
Review-Url: https://codereview.chromium.org/2014323003
Diffstat (limited to 'xfa/fxjse')
-rw-r--r-- | xfa/fxjse/cfxjse_arguments.h | 2 | ||||
-rw-r--r-- | xfa/fxjse/class.cpp | 56 | ||||
-rw-r--r-- | xfa/fxjse/context.cpp | 3 | ||||
-rw-r--r-- | xfa/fxjse/dynprop.cpp | 48 | ||||
-rw-r--r-- | xfa/fxjse/include/fxjse.h | 3 | ||||
-rw-r--r-- | xfa/fxjse/value.cpp | 12 | ||||
-rw-r--r-- | xfa/fxjse/value.h | 2 |
7 files changed, 47 insertions, 79 deletions
diff --git a/xfa/fxjse/cfxjse_arguments.h b/xfa/fxjse/cfxjse_arguments.h index 9a20c7c4a3..48a3bfff8f 100644 --- a/xfa/fxjse/cfxjse_arguments.h +++ b/xfa/fxjse/cfxjse_arguments.h @@ -13,7 +13,7 @@ class CFXJSE_Arguments { public: v8::Isolate* GetRuntime() const; int32_t GetLength() const; - CFXJSE_Value* GetValue(int32_t index) const; + std::unique_ptr<CFXJSE_Value> GetValue(int32_t index) const; FX_BOOL GetBoolean(int32_t index) const; int32_t GetInt32(int32_t index) const; FX_FLOAT GetFloat(int32_t index) const; diff --git a/xfa/fxjse/class.cpp b/xfa/fxjse/class.cpp index d49bafb986..bb6f0e1fe4 100644 --- a/xfa/fxjse/class.cpp +++ b/xfa/fxjse/class.cpp @@ -38,19 +38,16 @@ static void FXJSE_V8FunctionCallback_Wrapper( return; } CFX_ByteStringC szFunctionName(lpFunctionInfo->name); - CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); + std::unique_ptr<CFXJSE_Value> lpThisValue( + new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(info.This()); - CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); - CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; - lpFunctionInfo->callbackProc(lpThisValue, szFunctionName, + std::unique_ptr<CFXJSE_Value> lpRetValue(new CFXJSE_Value(info.GetIsolate())); + CFXJSE_ArgumentsImpl impl = {&info, lpRetValue.get()}; + lpFunctionInfo->callbackProc(lpThisValue.get(), szFunctionName, reinterpret_cast<CFXJSE_Arguments&>(impl)); if (!lpRetValue->DirectGetValue().IsEmpty()) { info.GetReturnValue().Set(lpRetValue->DirectGetValue()); } - delete lpRetValue; - lpRetValue = NULL; - delete lpThisValue; - lpThisValue = NULL; } static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper( @@ -62,19 +59,16 @@ static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper( return; } CFX_ByteStringC szFunctionName(lpClassDefinition->name); - CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); + std::unique_ptr<CFXJSE_Value> lpThisValue( + new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(info.This()); - CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); - CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; - lpClassDefinition->constructor(lpThisValue, szFunctionName, + std::unique_ptr<CFXJSE_Value> lpRetValue(new CFXJSE_Value(info.GetIsolate())); + CFXJSE_ArgumentsImpl impl = {&info, lpRetValue.get()}; + lpClassDefinition->constructor(lpThisValue.get(), szFunctionName, reinterpret_cast<CFXJSE_Arguments&>(impl)); if (!lpRetValue->DirectGetValue().IsEmpty()) { info.GetReturnValue().Set(lpRetValue->DirectGetValue()); } - delete lpRetValue; - lpRetValue = NULL; - delete lpThisValue; - lpThisValue = NULL; } static void FXJSE_V8GetterCallback_Wrapper( @@ -87,15 +81,13 @@ static void FXJSE_V8GetterCallback_Wrapper( return; } CFX_ByteStringC szPropertyName(lpPropertyInfo->name); - CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); - CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate()); + std::unique_ptr<CFXJSE_Value> lpThisValue( + new CFXJSE_Value(info.GetIsolate())); + std::unique_ptr<CFXJSE_Value> lpPropValue( + new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(info.This()); - lpPropertyInfo->getProc(lpThisValue, szPropertyName, lpPropValue); + lpPropertyInfo->getProc(lpThisValue.get(), szPropertyName, lpPropValue.get()); info.GetReturnValue().Set(lpPropValue->DirectGetValue()); - delete lpThisValue; - lpThisValue = NULL; - delete lpPropValue; - lpPropValue = NULL; } static void FXJSE_V8SetterCallback_Wrapper( @@ -109,15 +101,13 @@ static void FXJSE_V8SetterCallback_Wrapper( return; } CFX_ByteStringC szPropertyName(lpPropertyInfo->name); - CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); - CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate()); + std::unique_ptr<CFXJSE_Value> lpThisValue( + new CFXJSE_Value(info.GetIsolate())); + std::unique_ptr<CFXJSE_Value> lpPropValue( + new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(info.This()); lpPropValue->ForceSetValue(value); - lpPropertyInfo->setProc(lpThisValue, szPropertyName, lpPropValue); - delete lpThisValue; - lpThisValue = NULL; - delete lpPropValue; - lpPropValue = NULL; + lpPropertyInfo->setProc(lpThisValue.get(), szPropertyName, lpPropValue.get()); } static void FXJSE_V8ConstructorCallback_Wrapper( @@ -144,11 +134,11 @@ int32_t CFXJSE_Arguments::GetLength() const { return lpArguments->m_pInfo->Length(); } -CFXJSE_Value* CFXJSE_Arguments::GetValue(int32_t index) const { +std::unique_ptr<CFXJSE_Value> CFXJSE_Arguments::GetValue(int32_t index) const { const CFXJSE_ArgumentsImpl* lpArguments = reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); - CFXJSE_Value* lpArgValue = CFXJSE_Value::Create(v8::Isolate::GetCurrent()); - ASSERT(lpArgValue); + std::unique_ptr<CFXJSE_Value> lpArgValue( + new CFXJSE_Value(v8::Isolate::GetCurrent())); lpArgValue->ForceSetValue((*lpArguments->m_pInfo)[index]); return lpArgValue; } diff --git a/xfa/fxjse/context.cpp b/xfa/fxjse/context.cpp index 49d0b44338..d40e2af223 100644 --- a/xfa/fxjse/context.cpp +++ b/xfa/fxjse/context.cpp @@ -65,8 +65,7 @@ CFXJSE_Value* FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext) { if (!pContext) return nullptr; - CFXJSE_Value* lpValue = CFXJSE_Value::Create(pContext->GetRuntime()); - ASSERT(lpValue); + CFXJSE_Value* lpValue = new CFXJSE_Value(pContext->GetRuntime()); pContext->GetGlobalObject(lpValue); return lpValue; } diff --git a/xfa/fxjse/dynprop.cpp b/xfa/fxjse/dynprop.cpp index 8a2c67126a..6e98d824e3 100644 --- a/xfa/fxjse/dynprop.cpp +++ b/xfa/fxjse/dynprop.cpp @@ -18,19 +18,16 @@ static void FXJSE_DynPropGetterAdapter_MethodCallback( ASSERT(lpClass && !hPropName.IsEmpty()); v8::String::Utf8Value szPropName(hPropName); CFX_ByteStringC szFxPropName = *szPropName; - CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); + std::unique_ptr<CFXJSE_Value> lpThisValue( + new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(info.This()); - CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); - CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; - lpClass->dynMethodCall(lpThisValue, szFxPropName, + std::unique_ptr<CFXJSE_Value> lpRetValue(new CFXJSE_Value(info.GetIsolate())); + CFXJSE_ArgumentsImpl impl = {&info, lpRetValue.get()}; + lpClass->dynMethodCall(lpThisValue.get(), szFxPropName, reinterpret_cast<CFXJSE_Arguments&>(impl)); if (!lpRetValue->DirectGetValue().IsEmpty()) { info.GetReturnValue().Set(lpRetValue->DirectGetValue()); } - delete lpRetValue; - lpRetValue = nullptr; - delete lpThisValue; - lpThisValue = nullptr; } static void FXJSE_DynPropGetterAdapter(const FXJSE_CLASS_DESCRIPTOR* lpClass, @@ -124,16 +121,15 @@ static void FXJSE_V8_GenericNamedPropertyQueryCallback( v8::HandleScope scope(pIsolate); v8::String::Utf8Value szPropName(property); CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); - CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); + std::unique_ptr<CFXJSE_Value> lpThisValue( + new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(thisObject); - if (FXJSE_DynPropQueryAdapter(lpClass, lpThisValue, szFxPropName)) { + if (FXJSE_DynPropQueryAdapter(lpClass, lpThisValue.get(), szFxPropName)) { info.GetReturnValue().Set(v8::DontDelete); } else { const int32_t iV8Absent = 64; info.GetReturnValue().Set(iV8Absent); } - delete lpThisValue; - lpThisValue = nullptr; } static void FXJSE_V8_GenericNamedPropertyDeleterCallback( @@ -146,12 +142,11 @@ static void FXJSE_V8_GenericNamedPropertyDeleterCallback( v8::HandleScope scope(pIsolate); v8::String::Utf8Value szPropName(property); CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); - CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); + std::unique_ptr<CFXJSE_Value> lpThisValue( + new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(thisObject); info.GetReturnValue().Set( - !!FXJSE_DynPropDeleterAdapter(lpClass, lpThisValue, szFxPropName)); - delete lpThisValue; - lpThisValue = nullptr; + !!FXJSE_DynPropDeleterAdapter(lpClass, lpThisValue.get(), szFxPropName)); } static void FXJSE_V8_GenericNamedPropertyGetterCallback( @@ -162,13 +157,13 @@ static void FXJSE_V8_GenericNamedPropertyGetterCallback( info.Data().As<v8::External>()->Value()); v8::String::Utf8Value szPropName(property); CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); - CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); + std::unique_ptr<CFXJSE_Value> lpThisValue( + new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(thisObject); - CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate()); - FXJSE_DynPropGetterAdapter(lpClass, lpThisValue, szFxPropName, lpNewValue); + std::unique_ptr<CFXJSE_Value> lpNewValue(new CFXJSE_Value(info.GetIsolate())); + FXJSE_DynPropGetterAdapter(lpClass, lpThisValue.get(), szFxPropName, + lpNewValue.get()); info.GetReturnValue().Set(lpNewValue->DirectGetValue()); - delete lpThisValue; - lpThisValue = nullptr; } static void FXJSE_V8_GenericNamedPropertySetterCallback( @@ -180,14 +175,15 @@ static void FXJSE_V8_GenericNamedPropertySetterCallback( info.Data().As<v8::External>()->Value()); v8::String::Utf8Value szPropName(property); CFX_ByteStringC szFxPropName(*szPropName, szPropName.length()); - CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); + std::unique_ptr<CFXJSE_Value> lpThisValue( + new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(thisObject); - CFXJSE_Value* lpNewValue = CFXJSE_Value::Create(info.GetIsolate()); + + CFXJSE_Value* lpNewValue = new CFXJSE_Value(info.GetIsolate()); lpNewValue->ForceSetValue(value); - FXJSE_DynPropSetterAdapter(lpClass, lpThisValue, szFxPropName, lpNewValue); + FXJSE_DynPropSetterAdapter(lpClass, lpThisValue.get(), szFxPropName, + lpNewValue); info.GetReturnValue().Set(value); - delete lpThisValue; - lpThisValue = nullptr; } static void FXJSE_V8_GenericNamedPropertyEnumeratorCallback( diff --git a/xfa/fxjse/include/fxjse.h b/xfa/fxjse/include/fxjse.h index e278935657..e432858603 100644 --- a/xfa/fxjse/include/fxjse.h +++ b/xfa/fxjse/include/fxjse.h @@ -83,9 +83,6 @@ void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext, CFXJSE_Class* FXJSE_DefineClass(CFXJSE_Context* pContext, const FXJSE_CLASS_DESCRIPTOR* lpClass); -CFXJSE_Value* FXJSE_Value_Create(v8::Isolate* pIsolate); -void FXJSE_Value_Release(CFXJSE_Value* pValue); - FX_BOOL FXJSE_Value_IsUndefined(CFXJSE_Value* pValue); FX_BOOL FXJSE_Value_IsNull(CFXJSE_Value* pValue); FX_BOOL FXJSE_Value_IsBoolean(CFXJSE_Value* pValue); diff --git a/xfa/fxjse/value.cpp b/xfa/fxjse/value.cpp index ecd88b078d..6cdbb14aa3 100644 --- a/xfa/fxjse/value.cpp +++ b/xfa/fxjse/value.cpp @@ -165,14 +165,6 @@ FX_BOOL FXJSE_Value_SetFunctionBind(CFXJSE_Value* pValue, return pValue->SetFunctionBind(pOldFunction, pNewThis); } -CFXJSE_Value* FXJSE_Value_Create(v8::Isolate* pIsolate) { - return CFXJSE_Value::Create(pIsolate); -} - -void FXJSE_Value_Release(CFXJSE_Value* pValue) { - delete pValue; -} - void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name, const CFX_ByteStringC& utf8Message) { v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); @@ -205,10 +197,6 @@ void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name, pIsolate->ThrowException(hError); } -CFXJSE_Value* CFXJSE_Value::Create(v8::Isolate* pIsolate) { - return new CFXJSE_Value(pIsolate); -} - void* CFXJSE_Value::ToObject(CFXJSE_Class* lpClass) const { ASSERT(!m_hValue.IsEmpty()); diff --git a/xfa/fxjse/value.h b/xfa/fxjse/value.h index 65b5fa8e3d..2dec5824b3 100644 --- a/xfa/fxjse/value.h +++ b/xfa/fxjse/value.h @@ -218,8 +218,6 @@ class CFXJSE_Value { } } - static CFXJSE_Value* Create(v8::Isolate* pIsolate); - private: friend class CFXJSE_Class; friend class CFXJSE_Context; |