From 4ee98cd67354a2ab26134c0688768d4aa92350a2 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 1 Jun 2016 16:58:24 -0700 Subject: Stop casting struct CFXJSE_ArgumentsImpl to unrelated class CFXJSE_Arguments Remove the 'Impl entirely, and put the details into the class itself. Review-Url: https://codereview.chromium.org/2036513002 --- xfa/fxjse/cfxjse_arguments.h | 8 +++++++ xfa/fxjse/class.cpp | 52 ++++++++++++++------------------------------ xfa/fxjse/class.h | 18 +++++---------- xfa/fxjse/dynprop.cpp | 5 ++--- 4 files changed, 32 insertions(+), 51 deletions(-) (limited to 'xfa/fxjse') diff --git a/xfa/fxjse/cfxjse_arguments.h b/xfa/fxjse/cfxjse_arguments.h index 48a3bfff8f..3028d39def 100644 --- a/xfa/fxjse/cfxjse_arguments.h +++ b/xfa/fxjse/cfxjse_arguments.h @@ -11,6 +11,10 @@ class CFXJSE_Arguments { public: + CFXJSE_Arguments(const v8::FunctionCallbackInfo* pInfo, + CFXJSE_Value* pRetValue) + : m_pInfo(pInfo), m_pRetValue(pRetValue) {} + v8::Isolate* GetRuntime() const; int32_t GetLength() const; std::unique_ptr GetValue(int32_t index) const; @@ -20,6 +24,10 @@ class CFXJSE_Arguments { CFX_ByteString GetUTF8String(int32_t index) const; void* GetObject(int32_t index, CFXJSE_Class* pClass = nullptr) const; CFXJSE_Value* GetReturnValue(); + + private: + const v8::FunctionCallbackInfo* m_pInfo; + CFXJSE_Value* m_pRetValue; }; #endif // XFA_FXJSE_CFXJSE_ARGUMENTS_H_ diff --git a/xfa/fxjse/class.cpp b/xfa/fxjse/class.cpp index bb6f0e1fe4..e7e061b5a3 100644 --- a/xfa/fxjse/class.cpp +++ b/xfa/fxjse/class.cpp @@ -42,9 +42,8 @@ static void FXJSE_V8FunctionCallback_Wrapper( new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(info.This()); std::unique_ptr lpRetValue(new CFXJSE_Value(info.GetIsolate())); - CFXJSE_ArgumentsImpl impl = {&info, lpRetValue.get()}; - lpFunctionInfo->callbackProc(lpThisValue.get(), szFunctionName, - reinterpret_cast(impl)); + CFXJSE_Arguments impl(&info, lpRetValue.get()); + lpFunctionInfo->callbackProc(lpThisValue.get(), szFunctionName, impl); if (!lpRetValue->DirectGetValue().IsEmpty()) { info.GetReturnValue().Set(lpRetValue->DirectGetValue()); } @@ -63,9 +62,8 @@ static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper( new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(info.This()); std::unique_ptr lpRetValue(new CFXJSE_Value(info.GetIsolate())); - CFXJSE_ArgumentsImpl impl = {&info, lpRetValue.get()}; - lpClassDefinition->constructor(lpThisValue.get(), szFunctionName, - reinterpret_cast(impl)); + CFXJSE_Arguments impl(&info, lpRetValue.get()); + lpClassDefinition->constructor(lpThisValue.get(), szFunctionName, impl); if (!lpRetValue->DirectGetValue().IsEmpty()) { info.GetReturnValue().Set(lpRetValue->DirectGetValue()); } @@ -123,68 +121,50 @@ static void FXJSE_V8ConstructorCallback_Wrapper( } v8::Isolate* CFXJSE_Arguments::GetRuntime() const { - const CFXJSE_ArgumentsImpl* lpArguments = - reinterpret_cast(this); - return lpArguments->m_pRetValue->GetIsolate(); + return m_pRetValue->GetIsolate(); } int32_t CFXJSE_Arguments::GetLength() const { - const CFXJSE_ArgumentsImpl* lpArguments = - reinterpret_cast(this); - return lpArguments->m_pInfo->Length(); + return m_pInfo->Length(); } std::unique_ptr CFXJSE_Arguments::GetValue(int32_t index) const { - const CFXJSE_ArgumentsImpl* lpArguments = - reinterpret_cast(this); std::unique_ptr lpArgValue( new CFXJSE_Value(v8::Isolate::GetCurrent())); - lpArgValue->ForceSetValue((*lpArguments->m_pInfo)[index]); + lpArgValue->ForceSetValue((*m_pInfo)[index]); return lpArgValue; } FX_BOOL CFXJSE_Arguments::GetBoolean(int32_t index) const { - const CFXJSE_ArgumentsImpl* lpArguments = - reinterpret_cast(this); - return (*lpArguments->m_pInfo)[index]->BooleanValue(); + return (*m_pInfo)[index]->BooleanValue(); } int32_t CFXJSE_Arguments::GetInt32(int32_t index) const { - const CFXJSE_ArgumentsImpl* lpArguments = - reinterpret_cast(this); - return static_cast((*lpArguments->m_pInfo)[index]->NumberValue()); + return static_cast((*m_pInfo)[index]->NumberValue()); } FX_FLOAT CFXJSE_Arguments::GetFloat(int32_t index) const { - const CFXJSE_ArgumentsImpl* lpArguments = - reinterpret_cast(this); - return static_cast((*lpArguments->m_pInfo)[index]->NumberValue()); + return static_cast((*m_pInfo)[index]->NumberValue()); } CFX_ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const { - const CFXJSE_ArgumentsImpl* lpArguments = - reinterpret_cast(this); - v8::Local hString = (*lpArguments->m_pInfo)[index]->ToString(); + v8::Local hString = (*m_pInfo)[index]->ToString(); v8::String::Utf8Value szStringVal(hString); return CFX_ByteString(*szStringVal); } void* CFXJSE_Arguments::GetObject(int32_t index, CFXJSE_Class* pClass) const { - const CFXJSE_ArgumentsImpl* lpArguments = - reinterpret_cast(this); - v8::Local hValue = (*lpArguments->m_pInfo)[index]; + v8::Local hValue = (*m_pInfo)[index]; ASSERT(!hValue.IsEmpty()); - if (!hValue->IsObject()) { - return NULL; - } + if (!hValue->IsObject()) + return nullptr; return FXJSE_RetrieveObjectBinding(hValue.As(), pClass); } CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() { - const CFXJSE_ArgumentsImpl* lpArguments = - reinterpret_cast(this); - return lpArguments->m_pRetValue; + return m_pRetValue; } + static void FXJSE_Context_GlobalObjToString( const v8::FunctionCallbackInfo& info) { const FXJSE_CLASS_DESCRIPTOR* lpClass = static_cast( diff --git a/xfa/fxjse/class.h b/xfa/fxjse/class.h index 344adf4a47..a28d36801e 100644 --- a/xfa/fxjse/class.h +++ b/xfa/fxjse/class.h @@ -15,14 +15,6 @@ class CFXJSE_Context; class CFXJSE_Value; class CFXJSE_Class { - protected: - CFXJSE_Class(CFXJSE_Context* lpContext) - : m_lpClassDefinition(nullptr), m_pContext(lpContext) {} - - public: - inline CFXJSE_Context* GetContext() { return m_pContext; } - inline v8::Global& GetTemplate() { return m_hTemplate; } - public: static CFXJSE_Class* Create(CFXJSE_Context* pContext, const FXJSE_CLASS_DESCRIPTOR* lpClassDefintion, @@ -34,7 +26,13 @@ class CFXJSE_Class { v8::Local& hObjectTemplate, const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition); + CFXJSE_Context* GetContext() { return m_pContext; } + v8::Global& GetTemplate() { return m_hTemplate; } + protected: + explicit CFXJSE_Class(CFXJSE_Context* lpContext) + : m_lpClassDefinition(nullptr), m_pContext(lpContext) {} + CFX_ByteString m_szClassName; const FXJSE_CLASS_DESCRIPTOR* m_lpClassDefinition; CFXJSE_Context* m_pContext; @@ -42,9 +40,5 @@ class CFXJSE_Class { friend class CFXJSE_Context; friend class CFXJSE_Value; }; -struct CFXJSE_ArgumentsImpl { - const v8::FunctionCallbackInfo* m_pInfo; - CFXJSE_Value* m_pRetValue; -}; #endif // XFA_FXJSE_CLASS_H_ diff --git a/xfa/fxjse/dynprop.cpp b/xfa/fxjse/dynprop.cpp index 6e98d824e3..946fe42c1b 100644 --- a/xfa/fxjse/dynprop.cpp +++ b/xfa/fxjse/dynprop.cpp @@ -22,9 +22,8 @@ static void FXJSE_DynPropGetterAdapter_MethodCallback( new CFXJSE_Value(info.GetIsolate())); lpThisValue->ForceSetValue(info.This()); std::unique_ptr lpRetValue(new CFXJSE_Value(info.GetIsolate())); - CFXJSE_ArgumentsImpl impl = {&info, lpRetValue.get()}; - lpClass->dynMethodCall(lpThisValue.get(), szFxPropName, - reinterpret_cast(impl)); + CFXJSE_Arguments impl(&info, lpRetValue.get()); + lpClass->dynMethodCall(lpThisValue.get(), szFxPropName, impl); if (!lpRetValue->DirectGetValue().IsEmpty()) { info.GetReturnValue().Set(lpRetValue->DirectGetValue()); } -- cgit v1.2.3