From 7f2abcc015583e63cceb52acde757cb2111420bd Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 26 May 2016 09:40:27 -0700 Subject: Replace FXJSE_HCONTEXT with CFXJSE_Context* This Cl removes FXJSE_HCONTEXT and replaces it with the concrete CFXJSE_Context. All varibles have been updated as well to match the new type. Review-Url: https://codereview.chromium.org/2013963005 --- xfa/fxjse/class.cpp | 7 +++---- xfa/fxjse/context.cpp | 32 ++++++++++---------------------- xfa/fxjse/context.h | 1 + xfa/fxjse/include/fxjse.h | 19 +++++++++---------- xfa/fxjse/value.h | 22 ++++++++-------------- 5 files changed, 31 insertions(+), 50 deletions(-) (limited to 'xfa/fxjse') diff --git a/xfa/fxjse/class.cpp b/xfa/fxjse/class.cpp index ff5990aa85..b7637455fd 100644 --- a/xfa/fxjse/class.cpp +++ b/xfa/fxjse/class.cpp @@ -24,12 +24,11 @@ static void FXJSE_V8SetterCallback_Wrapper( v8::Local value, const v8::PropertyCallbackInfo& info); -FXJSE_HCLASS FXJSE_DefineClass(FXJSE_HCONTEXT hContext, +FXJSE_HCLASS FXJSE_DefineClass(CFXJSE_Context* pContext, const FXJSE_CLASS* lpClass) { - CFXJSE_Context* lpContext = reinterpret_cast(hContext); - ASSERT(lpContext); + ASSERT(pContext); return reinterpret_cast( - CFXJSE_Class::Create(lpContext, lpClass, FALSE)); + CFXJSE_Class::Create(pContext, lpClass, FALSE)); } static void FXJSE_V8FunctionCallback_Wrapper( diff --git a/xfa/fxjse/context.cpp b/xfa/fxjse/context.cpp index b125177617..76df5616e5 100644 --- a/xfa/fxjse/context.cpp +++ b/xfa/fxjse/context.cpp @@ -11,28 +11,17 @@ #include "xfa/fxjse/util_inline.h" #include "xfa/fxjse/value.h" -namespace { - -CFXJSE_Context* CFXContextFromHContext(FXJSE_HCONTEXT hContext) { - return reinterpret_cast(hContext); -} - -} // namespace - -FXJSE_HCONTEXT FXJSE_Context_Create(v8::Isolate* pIsolate, - const FXJSE_CLASS* lpGlobalClass, - void* lpGlobalObject) { - CFXJSE_Context* pContext = - CFXJSE_Context::Create(pIsolate, lpGlobalClass, lpGlobalObject); - return reinterpret_cast(pContext); +CFXJSE_Context* FXJSE_Context_Create(v8::Isolate* pIsolate, + const FXJSE_CLASS* lpGlobalClass, + void* lpGlobalObject) { + return CFXJSE_Context::Create(pIsolate, lpGlobalClass, lpGlobalObject); } -void FXJSE_Context_Release(FXJSE_HCONTEXT hContext) { - delete CFXContextFromHContext(hContext); +void FXJSE_Context_Release(CFXJSE_Context* pContext) { + delete pContext; } -FXJSE_HVALUE FXJSE_Context_GetGlobalObject(FXJSE_HCONTEXT hContext) { - CFXJSE_Context* pContext = CFXContextFromHContext(hContext); +FXJSE_HVALUE FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext) { if (!pContext) return nullptr; @@ -68,20 +57,19 @@ static const FX_CHAR* szCompatibleModeScripts[] = { " }\n" " }\n" "}(this, {String: ['substr', 'toUpperCase']}));"}; -void FXJSE_Context_EnableCompatibleMode(FXJSE_HCONTEXT hContext, +void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext, uint32_t dwCompatibleFlags) { for (uint32_t i = 0; i < (uint32_t)FXJSE_COMPATIBLEMODEFLAGCOUNT; i++) { if (dwCompatibleFlags & (1 << i)) { - FXJSE_ExecuteScript(hContext, szCompatibleModeScripts[i], NULL, NULL); + FXJSE_ExecuteScript(pContext, szCompatibleModeScripts[i], NULL, NULL); } } } -FX_BOOL FXJSE_ExecuteScript(FXJSE_HCONTEXT hContext, +FX_BOOL FXJSE_ExecuteScript(CFXJSE_Context* pContext, const FX_CHAR* szScript, FXJSE_HVALUE hRetValue, FXJSE_HVALUE hNewThisObject) { - CFXJSE_Context* pContext = CFXContextFromHContext(hContext); return pContext->ExecuteScript( szScript, reinterpret_cast(hRetValue), reinterpret_cast(hNewThisObject)); diff --git a/xfa/fxjse/context.h b/xfa/fxjse/context.h index 0092aac7f3..38338311e3 100644 --- a/xfa/fxjse/context.h +++ b/xfa/fxjse/context.h @@ -16,6 +16,7 @@ class CFXJSE_Class; class CFXJSE_Value; +struct FXJSE_CLASS; class CFXJSE_Context { public: diff --git a/xfa/fxjse/include/fxjse.h b/xfa/fxjse/include/fxjse.h index d009372c54..207d86e68c 100644 --- a/xfa/fxjse/include/fxjse.h +++ b/xfa/fxjse/include/fxjse.h @@ -11,10 +11,9 @@ #include "core/fxcrt/include/fx_system.h" #include "v8/include/v8.h" -struct FXJSE_CLASS; class CFXJSE_Arguments; +class CFXJSE_Context; -typedef struct FXJSE_HCONTEXT_ { void* pData; } * FXJSE_HCONTEXT; typedef struct FXJSE_HCLASS_ { void* pData; } * FXJSE_HCLASS; typedef struct FXJSE_HVALUE_ { void* pData; } * FXJSE_HVALUE; // NOLINTNEXTLINE @@ -74,16 +73,16 @@ void FXJSE_Finalize(); v8::Isolate* FXJSE_Runtime_Create(); void FXJSE_Runtime_Release(v8::Isolate* pIsolate, bool bOwnedRuntime); -FXJSE_HCONTEXT FXJSE_Context_Create(v8::Isolate* pIsolate, - const FXJSE_CLASS* lpGlobalClass = nullptr, - void* lpGlobalObject = nullptr); -void FXJSE_Context_Release(FXJSE_HCONTEXT hContext); -FXJSE_HVALUE FXJSE_Context_GetGlobalObject(FXJSE_HCONTEXT hContext); +CFXJSE_Context* FXJSE_Context_Create(v8::Isolate* pIsolate, + const FXJSE_CLASS* lpGlobalClass = nullptr, + void* lpGlobalObject = nullptr); +void FXJSE_Context_Release(CFXJSE_Context* pContext); +FXJSE_HVALUE FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext); -void FXJSE_Context_EnableCompatibleMode(FXJSE_HCONTEXT hContext, +void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext, uint32_t dwCompatibleFlags); -FXJSE_HCLASS FXJSE_DefineClass(FXJSE_HCONTEXT hContext, +FXJSE_HCLASS FXJSE_DefineClass(CFXJSE_Context* pContext, const FXJSE_CLASS* lpClass); FXJSE_HVALUE FXJSE_Value_Create(v8::Isolate* pIsolate); @@ -143,7 +142,7 @@ FX_BOOL FXJSE_Value_SetFunctionBind(FXJSE_HVALUE hValue, FXJSE_HVALUE hOldFunction, FXJSE_HVALUE hNewThis); -FX_BOOL FXJSE_ExecuteScript(FXJSE_HCONTEXT hContext, +FX_BOOL FXJSE_ExecuteScript(CFXJSE_Context* pContext, const FX_CHAR* szScript, FXJSE_HVALUE hRetValue, FXJSE_HVALUE hNewThisObject = nullptr); diff --git a/xfa/fxjse/value.h b/xfa/fxjse/value.h index 2939ac34f7..576d092bce 100644 --- a/xfa/fxjse/value.h +++ b/xfa/fxjse/value.h @@ -13,12 +13,6 @@ class CFXJSE_Value { public: CFXJSE_Value(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {} - protected: - CFXJSE_Value(); - CFXJSE_Value(const CFXJSE_Value&); - CFXJSE_Value& operator=(const CFXJSE_Value&); - - public: V8_INLINE FX_BOOL IsUndefined() const { if (m_hValue.IsEmpty()) { return FALSE; @@ -110,7 +104,6 @@ class CFXJSE_Value { return hValue->IsDate(); } - public: V8_INLINE FX_BOOL ToBoolean() const { ASSERT(!m_hValue.IsEmpty()); CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); @@ -150,7 +143,6 @@ class CFXJSE_Value { } void* ToObject(CFXJSE_Class* lpClass) const; - public: V8_INLINE void SetUndefined() { CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); v8::Local hValue = v8::Undefined(m_pIsolate); @@ -194,7 +186,6 @@ class CFXJSE_Value { void SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues); void SetDate(double dDouble); - public: FX_BOOL GetObjectProperty(const CFX_ByteStringC& szPropName, CFXJSE_Value* lpPropValue); FX_BOOL SetObjectProperty(const CFX_ByteStringC& szPropName, @@ -212,7 +203,6 @@ class CFXJSE_Value { uint32_t nArgCount, FXJSE_HVALUE* lpArgs); - public: V8_INLINE v8::Isolate* GetIsolate() const { return m_pIsolate; } V8_INLINE const v8::Global& DirectGetValue() const { return m_hValue; @@ -228,14 +218,18 @@ class CFXJSE_Value { } } - public: static CFXJSE_Value* Create(v8::Isolate* pIsolate); - protected: + private: + friend class CFXJSE_Class; + friend class CFXJSE_Context; + + CFXJSE_Value(); + CFXJSE_Value(const CFXJSE_Value&); + CFXJSE_Value& operator=(const CFXJSE_Value&); + v8::Isolate* m_pIsolate; v8::Global m_hValue; - friend class CFXJSE_Context; - friend class CFXJSE_Class; }; #endif // XFA_FXJSE_VALUE_H_ -- cgit v1.2.3