diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-05-18 09:51:57 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-18 17:57:26 +0000 |
commit | 7dc9fe5a646b68cf4774a25c67d0aa0cf9c8a453 (patch) | |
tree | 6dc9bd2c2c78ebd2a9bcdf3a943837d754eca53e /fpdfsdk | |
parent | 41066c1ecaafd99904b160211985b56cce195ee8 (diff) | |
download | pdfium-7dc9fe5a646b68cf4774a25c67d0aa0cf9c8a453.tar.xz |
Break linkage from CPDFXA_DocEnvironment to IJS_EventContext.
CPDFXFA_DocEnvionment is part of the heirarchy of objects owned by
the embedder under its FPDF_Document object.
IJS_EventContext is part of the hierarchy of objects owned by the
embedder under its FPDF_FormHandle object.
The FPDF_Document must outlive the FPDF_FormHandle, so there is a
lifetime inversion with the m_pJSEventContext member. No matter,
event contexts are transient and allocated in a stack-based manner
as control bounces from C++ to JS and vice versa, and keeping a
persistent one seems wrong. So make it only as needed.
Bug: 723644
Change-Id: I74dd328ad4b501e4adf57821b44ecc78d945eb0f
Reviewed-on: https://pdfium-review.googlesource.com/5656
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 32 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h | 1 |
2 files changed, 14 insertions, 19 deletions
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 11b001fc7f..4695c64ce1 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -39,16 +39,11 @@ #define FXFA_XFA_ALL 0x01111111 CPDFXFA_DocEnvironment::CPDFXFA_DocEnvironment(CPDFXFA_Context* pContext) - : m_pContext(pContext), m_pJSEventContext(nullptr) { + : m_pContext(pContext) { ASSERT(m_pContext); } -CPDFXFA_DocEnvironment::~CPDFXFA_DocEnvironment() { - if (m_pJSEventContext && m_pContext->GetFormFillEnv()) { - m_pContext->GetFormFillEnv()->GetJSRuntime()->ReleaseEventContext( - m_pJSEventContext.Get()); - } -} +CPDFXFA_DocEnvironment::~CPDFXFA_DocEnvironment() {} void CPDFXFA_DocEnvironment::SetChangeMark(CXFA_FFDoc* hDoc) { if (hDoc == m_pContext->GetXFADoc() && m_pContext->GetFormFillEnv()) @@ -1006,13 +1001,15 @@ bool CPDFXFA_DocEnvironment::SetGlobalProperty( CFXJSE_Value* pValue) { if (hDoc != m_pContext->GetXFADoc()) return false; - - if (m_pContext->GetFormFillEnv() && - m_pContext->GetFormFillEnv()->GetJSRuntime()) { - return m_pContext->GetFormFillEnv()->GetJSRuntime()->SetValueByName( - szPropName, pValue); + if (!m_pContext->GetFormFillEnv() || + !m_pContext->GetFormFillEnv()->GetJSRuntime()) { + return false; } - return false; + CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); + IJS_EventContext* pContext = pFormFillEnv->GetJSRuntime()->NewEventContext(); + bool bRet = pFormFillEnv->GetJSRuntime()->SetValueByName(szPropName, pValue); + pFormFillEnv->GetJSRuntime()->ReleaseEventContext(pContext); + return bRet; } bool CPDFXFA_DocEnvironment::GetGlobalProperty( @@ -1025,10 +1022,9 @@ bool CPDFXFA_DocEnvironment::GetGlobalProperty( !m_pContext->GetFormFillEnv()->GetJSRuntime()) { return false; } - CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); - if (!m_pJSEventContext) - m_pJSEventContext = pFormFillEnv->GetJSRuntime()->NewEventContext(); - - return pFormFillEnv->GetJSRuntime()->GetValueByName(szPropName, pValue); + IJS_EventContext* pContext = pFormFillEnv->GetJSRuntime()->NewEventContext(); + bool bRet = pFormFillEnv->GetJSRuntime()->GetValueByName(szPropName, pValue); + pFormFillEnv->GetJSRuntime()->ReleaseEventContext(pContext); + return bRet; } diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h index ec04e78db9..90bc6dea04 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h @@ -107,7 +107,6 @@ class CPDFXFA_DocEnvironment : public IXFA_DocEnvironment { void ToXFAContentFlags(CFX_WideString csSrcContent, FPDF_DWORD& flag); CFX_UnownedPtr<CPDFXFA_Context> const m_pContext; - CFX_UnownedPtr<IJS_EventContext> m_pJSEventContext; }; #endif // FPDFSDK_FPDFXFA_CPDFXFA_DOCENVIRONMENT_H_ |