summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdfsdk_interform.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-06-05 22:33:31 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-05 22:33:31 +0000
commitc22d671728605bc614dc84ec6a42a5647808b30d (patch)
treece4ec68b844414d1ce1f7275181795677b4ca87e /fpdfsdk/cpdfsdk_interform.cpp
parent7edcf2ce07e87022361a0e00fde27aad738c0621 (diff)
downloadpdfium-c22d671728605bc614dc84ec6a42a5647808b30d.tar.xz
Introduce IJS_Runtime::ScopedEventContext helper class.chromium/3451
This proves that m_EventContextArray is, in fact, a stack. Tidy one function by using AutoRestorer while at it. Change-Id: I319538b4eadcd9ce83319aa73861635dd5eb8c36 Reviewed-on: https://pdfium-review.googlesource.com/33970 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk/cpdfsdk_interform.cpp')
-rw-r--r--fpdfsdk/cpdfsdk_interform.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index 638b4dfc07..1d8002a764 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -19,6 +19,7 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfdoc/cpdf_actionfields.h"
#include "core/fpdfdoc/cpdf_interform.h"
+#include "core/fxcrt/autorestorer.h"
#include "core/fxge/cfx_graphstatedata.h"
#include "core/fxge/cfx_pathdata.h"
#include "fpdfsdk/cpdfsdk_actionhandler.h"
@@ -255,12 +256,11 @@ void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
if (m_bBusy)
return;
+ AutoRestorer<bool> restorer(&m_bBusy);
m_bBusy = true;
- if (!IsCalculateEnabled()) {
- m_bBusy = false;
+ if (!IsCalculateEnabled())
return;
- }
IJS_Runtime* pRuntime = m_pFormFillEnv->GetIJSRuntime();
int nSize = m_pInterForm->CountFieldsInCalculationOrder();
@@ -285,18 +285,16 @@ void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
if (csJS.IsEmpty())
continue;
- IJS_EventContext* pContext = pRuntime->NewEventContext();
WideString sOldValue = pField->GetValue();
WideString sValue = sOldValue;
bool bRC = true;
+ IJS_Runtime::ScopedEventContext pContext(pRuntime);
pContext->OnField_Calculate(pFormField, pField, sValue, bRC);
Optional<IJS_Runtime::JS_Error> err = pContext->RunScript(csJS);
- pRuntime->ReleaseEventContext(pContext);
if (!err && bRC && sValue.Compare(sOldValue) != 0)
pField->SetValue(sValue, true);
}
- m_bBusy = false;
}
WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField,
@@ -325,11 +323,10 @@ WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField,
if (!script.IsEmpty()) {
WideString Value = sValue;
- IJS_EventContext* pContext = pRuntime->NewEventContext();
+ IJS_Runtime::ScopedEventContext pContext(pRuntime);
pContext->OnField_Format(pFormField, Value, true);
Optional<IJS_Runtime::JS_Error> err = pContext->RunScript(script);
- pRuntime->ReleaseEventContext(pContext);
if (!err) {
sValue = Value;
bFormatted = true;