From dc5d88bcebbeeb696b405464e901add55d1efaf7 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 17 May 2018 13:53:52 +0000 Subject: Convert JS execute methods to return Optional This CL changes several of the JS execution methods to to return an Optional instead of a bool with a WideString out param. The IJS_Runtime::JS_Error will contain the line, column and exception message if an error occurs during execution. Change-Id: I37785ae6cd133a4c94ad8d25289473600b8a5d19 Reviewed-on: https://pdfium-review.googlesource.com/32614 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fpdfsdk/cpdfsdk_actionhandler.cpp | 5 ++--- fpdfsdk/cpdfsdk_interform.cpp | 11 +++++------ 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/cpdfsdk_actionhandler.cpp b/fpdfsdk/cpdfsdk_actionhandler.cpp index 98c01240b2..660b09c515 100644 --- a/fpdfsdk/cpdfsdk_actionhandler.cpp +++ b/fpdfsdk/cpdfsdk_actionhandler.cpp @@ -544,8 +544,7 @@ void CPDFSDK_ActionHandler::RunScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, cb(pContext); - WideString csInfo; - pContext->RunScript(script, &csInfo); + pContext->RunScript(script); pRuntime->ReleaseEventContext(pContext); - // TODO(dsinclair): Return error if RunScript returns false. + // TODO(dsinclair): Return error if RunScript returns a IJS_Runtime::JS_Error. } diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index 4f11babbbe..b37562ccf2 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -291,10 +291,9 @@ void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) { bool bRC = true; pContext->OnField_Calculate(pFormField, pField, sValue, bRC); - WideString sInfo; - bool bRet = pContext->RunScript(csJS, &sInfo); + Optional err = pContext->RunScript(csJS); pRuntime->ReleaseEventContext(pContext); - if (bRet && bRC && sValue.Compare(sOldValue) != 0) + if (!err && bRC && sValue.Compare(sOldValue) != 0) pField->SetValue(sValue, true); } m_bBusy = false; @@ -328,10 +327,10 @@ WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, IJS_EventContext* pContext = pRuntime->NewEventContext(); pContext->OnField_Format(pFormField, Value, true); - WideString sInfo; - bool bRet = pContext->RunScript(script, &sInfo); + + Optional err = pContext->RunScript(script); pRuntime->ReleaseEventContext(pContext); - if (bRet) { + if (!err) { sValue = Value; bFormatted = true; } -- cgit v1.2.3