Introduce enum class XFA_EventError.

Presently, the code is using int32_t for these status codes,
and is doing so inconsistently, sometimes returning true/false
and sometimes or-ing the bits together. The enum class prevents
these abuses.

Change-Id: Ife1a7296b20fabb6789e35c197cae2018b34e5a2
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/57070
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index 9970f09..5309c49 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -239,13 +239,13 @@
 
       param.m_pTarget = node;
       if (pXFAWidgetHandler->ProcessEvent(node, &param) !=
-          XFA_EVENTERROR_Success) {
+          XFA_EventError::kSuccess) {
         return false;
       }
     }
   }
 
-  int32_t nRet = XFA_EVENTERROR_NotExist;
+  XFA_EventError nRet = XFA_EventError::kNotExist;
   CXFA_Node* node = hWidget->GetNode();
   if (node->IsWidgetReady()) {
     param.m_pTarget = node;
@@ -254,7 +254,7 @@
   if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
     pDocView->UpdateDocView();
 
-  return nRet == XFA_EVENTERROR_Success;
+  return nRet == XFA_EventError::kSuccess;
 }
 
 void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) {
@@ -814,7 +814,7 @@
         param.m_bModifier = data->bModifier;
         param.m_wsPrevText = data->sValue;
 
-        int32_t nRet = XFA_EVENTERROR_NotExist;
+        XFA_EventError nRet = XFA_EventError::kNotExist;
         CXFA_Node* node = hWidget->GetNode();
         if (node->IsWidgetReady()) {
           param.m_pTarget = node;
@@ -824,7 +824,7 @@
         if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
           pDocView->UpdateDocView();
 
-        if (nRet == XFA_EVENTERROR_Success)
+        if (nRet == XFA_EventError::kSuccess)
           return true;
       }
     }
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index dc76841..db3de42 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -638,8 +638,7 @@
   CXFA_Node* pNode = it->MoveToNext();
 
   while (pNode) {
-    int fRet = pNode->ProcessValidate(docView, -1);
-    if (fRet == XFA_EVENTERROR_Error) {
+    if (pNode->ProcessValidate(docView, -1) == XFA_EventError::kError) {
       CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv();
       if (!pFormFillEnv)
         return false;
diff --git a/fxjs/xfa/cjx_exclgroup.cpp b/fxjs/xfa/cjx_exclgroup.cpp
index ae20485..00bf539 100644
--- a/fxjs/xfa/cjx_exclgroup.cpp
+++ b/fxjs/xfa/cjx_exclgroup.cpp
@@ -81,9 +81,10 @@
   if (!notify)
     return CJS_Result::Success(runtime->NewBoolean(false));
 
-  int32_t iRet = notify->ExecEventByDeepFirst(GetXFANode(), XFA_EVENT_Validate,
-                                              false, true);
-  return CJS_Result::Success(runtime->NewBoolean(iRet != XFA_EVENTERROR_Error));
+  XFA_EventError iRet = notify->ExecEventByDeepFirst(
+      GetXFANode(), XFA_EVENT_Validate, false, true);
+  return CJS_Result::Success(
+      runtime->NewBoolean(iRet != XFA_EventError::kError));
 }
 
 CJS_Result CJX_ExclGroup::selectedMember(
diff --git a/fxjs/xfa/cjx_field.cpp b/fxjs/xfa/cjx_field.cpp
index e43acc9..3c0e888 100644
--- a/fxjs/xfa/cjx_field.cpp
+++ b/fxjs/xfa/cjx_field.cpp
@@ -59,12 +59,13 @@
     return CJS_Result::Failure(JSMessage::kParamError);
 
   WideString eventString = runtime->ToWideString(params[0]);
-  int32_t iRet =
+  XFA_EventError iRet =
       execSingleEventByName(eventString.AsStringView(), XFA_Element::Field);
   if (!eventString.EqualsASCII("validate"))
     return CJS_Result::Success();
 
-  return CJS_Result::Success(runtime->NewBoolean(iRet != XFA_EVENTERROR_Error));
+  return CJS_Result::Success(
+      runtime->NewBoolean(iRet != XFA_EventError::kError));
 }
 
 CJS_Result CJX_Field::execInitialize(
@@ -235,9 +236,10 @@
   if (!pNotify)
     return CJS_Result::Success(runtime->NewBoolean(false));
 
-  int32_t iRet = pNotify->ExecEventByDeepFirst(GetXFANode(), XFA_EVENT_Validate,
-                                               false, false);
-  return CJS_Result::Success(runtime->NewBoolean(iRet != XFA_EVENTERROR_Error));
+  XFA_EventError iRet = pNotify->ExecEventByDeepFirst(
+      GetXFANode(), XFA_EVENT_Validate, false, false);
+  return CJS_Result::Success(
+      runtime->NewBoolean(iRet != XFA_EventError::kError));
 }
 
 void CJX_Field::defaultValue(CFXJSE_Value* pValue,
diff --git a/fxjs/xfa/cjx_form.cpp b/fxjs/xfa/cjx_form.cpp
index 32c884b..07e8602 100644
--- a/fxjs/xfa/cjx_form.cpp
+++ b/fxjs/xfa/cjx_form.cpp
@@ -122,9 +122,10 @@
   if (!pNotify)
     return CJS_Result::Success(runtime->NewBoolean(false));
 
-  int32_t iRet = pNotify->ExecEventByDeepFirst(GetXFANode(), XFA_EVENT_Validate,
-                                               false, true);
-  return CJS_Result::Success(runtime->NewBoolean(iRet != XFA_EVENTERROR_Error));
+  XFA_EventError iRet = pNotify->ExecEventByDeepFirst(
+      GetXFANode(), XFA_EVENT_Validate, false, true);
+  return CJS_Result::Success(
+      runtime->NewBoolean(iRet != XFA_EventError::kError));
 }
 
 void CJX_Form::checksumS(CFXJSE_Value* pValue,
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp
index 0cfd135..d143095 100644
--- a/fxjs/xfa/cjx_node.cpp
+++ b/fxjs/xfa/cjx_node.cpp
@@ -509,20 +509,20 @@
   }
 }
 
-int32_t CJX_Node::execSingleEventByName(WideStringView wsEventName,
-                                        XFA_Element eType) {
+XFA_EventError CJX_Node::execSingleEventByName(WideStringView wsEventName,
+                                               XFA_Element eType) {
   CXFA_FFNotify* pNotify = GetDocument()->GetNotify();
   if (!pNotify)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   const XFA_ExecEventParaInfo* eventParaInfo =
       GetEventParaInfoByName(wsEventName);
   if (!eventParaInfo)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   switch (eventParaInfo->m_validFlags) {
     case EventAppliesToo::kNone:
-      return XFA_EVENTERROR_NotExist;
+      return XFA_EventError::kNotExist;
     case EventAppliesToo::kAll:
     case EventAppliesToo::kAllNonRecursive:
       return pNotify->ExecEventByDeepFirst(
@@ -530,13 +530,13 @@
           eventParaInfo->m_validFlags == EventAppliesToo::kAll);
     case EventAppliesToo::kSubform:
       if (eType != XFA_Element::Subform)
-        return XFA_EVENTERROR_NotExist;
+        return XFA_EventError::kNotExist;
 
       return pNotify->ExecEventByDeepFirst(
           GetXFANode(), eventParaInfo->m_eventType, false, false);
     case EventAppliesToo::kFieldOrExclusion: {
       if (eType != XFA_Element::ExclGroup && eType != XFA_Element::Field)
-        return XFA_EVENTERROR_NotExist;
+        return XFA_EventError::kNotExist;
 
       CXFA_Node* pParentNode = GetXFANode()->GetParent();
       if (pParentNode &&
@@ -550,30 +550,30 @@
     }
     case EventAppliesToo::kField:
       if (eType != XFA_Element::Field)
-        return XFA_EVENTERROR_NotExist;
+        return XFA_EventError::kNotExist;
 
       return pNotify->ExecEventByDeepFirst(
           GetXFANode(), eventParaInfo->m_eventType, false, false);
     case EventAppliesToo::kSignature: {
       if (!GetXFANode()->IsWidgetReady())
-        return XFA_EVENTERROR_NotExist;
+        return XFA_EventError::kNotExist;
       if (GetXFANode()->GetUIChildNode()->GetElementType() !=
           XFA_Element::Signature) {
-        return XFA_EVENTERROR_NotExist;
+        return XFA_EventError::kNotExist;
       }
       return pNotify->ExecEventByDeepFirst(
           GetXFANode(), eventParaInfo->m_eventType, false, false);
     }
     case EventAppliesToo::kChoiceList: {
       if (!GetXFANode()->IsWidgetReady())
-        return XFA_EVENTERROR_NotExist;
+        return XFA_EventError::kNotExist;
       if (GetXFANode()->GetUIChildNode()->GetElementType() !=
           XFA_Element::ChoiceList) {
-        return XFA_EVENTERROR_NotExist;
+        return XFA_EventError::kNotExist;
       }
       return pNotify->ExecEventByDeepFirst(
           GetXFANode(), eventParaInfo->m_eventType, false, false);
     }
   }
-  return XFA_EVENTERROR_NotExist;
+  return XFA_EventError::kNotExist;
 }
diff --git a/fxjs/xfa/cjx_node.h b/fxjs/xfa/cjx_node.h
index 29b7c8e..1cbceb6 100644
--- a/fxjs/xfa/cjx_node.h
+++ b/fxjs/xfa/cjx_node.h
@@ -9,6 +9,7 @@
 
 #include "fxjs/xfa/cjx_tree.h"
 #include "fxjs/xfa/jse_define.h"
+#include "xfa/fxfa/fxfa.h"
 #include "xfa/fxfa/fxfa_basic.h"
 
 class CXFA_Node;
@@ -42,7 +43,8 @@
   CXFA_Node* GetXFANode() const;
 
  protected:
-  int32_t execSingleEventByName(WideStringView wsEventName, XFA_Element eType);
+  XFA_EventError execSingleEventByName(WideStringView wsEventName,
+                                       XFA_Element eType);
 
  private:
   using Type__ = CJX_Node;
diff --git a/fxjs/xfa/cjx_subform.cpp b/fxjs/xfa/cjx_subform.cpp
index 18e1508..8dd192a 100644
--- a/fxjs/xfa/cjx_subform.cpp
+++ b/fxjs/xfa/cjx_subform.cpp
@@ -81,9 +81,10 @@
   if (!pNotify)
     return CJS_Result::Success(runtime->NewBoolean(false));
 
-  int32_t iRet = pNotify->ExecEventByDeepFirst(GetXFANode(), XFA_EVENT_Validate,
-                                               false, true);
-  return CJS_Result::Success(runtime->NewBoolean(iRet != XFA_EVENTERROR_Error));
+  XFA_EventError iRet = pNotify->ExecEventByDeepFirst(
+      GetXFANode(), XFA_EVENT_Validate, false, true);
+  return CJS_Result::Success(
+      runtime->NewBoolean(iRet != XFA_EventError::kError));
 }
 
 void CJX_Subform::locale(CFXJSE_Value* pValue,
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index 2c52c9c..59bc5fe 100644
--- a/xfa/fxfa/cxfa_ffdocview.cpp
+++ b/xfa/fxfa/cxfa_ffdocview.cpp
@@ -40,6 +40,7 @@
 #include "xfa/fxfa/parser/cxfa_subform.h"
 #include "xfa/fxfa/parser/cxfa_validate.h"
 #include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
+#include "xfa/fxfa/parser/xfa_utils.h"
 
 const XFA_AttributeValue gs_EventActivity[] = {
     XFA_AttributeValue::Click,      XFA_AttributeValue::Change,
@@ -324,13 +325,13 @@
   m_pFocusWidget = nullptr;
 }
 
-static int32_t XFA_ProcessEvent(CXFA_FFDocView* pDocView,
-                                CXFA_Node* pNode,
-                                CXFA_EventParam* pParam) {
+static XFA_EventError XFA_ProcessEvent(CXFA_FFDocView* pDocView,
+                                       CXFA_Node* pNode,
+                                       CXFA_EventParam* pParam) {
   if (!pParam || pParam->m_eType == XFA_EVENT_Unknown)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
   if (pNode && pNode->GetElementType() == XFA_Element::Draw)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   switch (pParam->m_eType) {
     case XFA_EVENT_Calculate:
@@ -340,13 +341,13 @@
               pDocView->GetDoc())) {
         return pNode->ProcessValidate(pDocView, 0x01);
       }
-      return XFA_EVENTERROR_Disabled;
+      return XFA_EventError::kDisabled;
     case XFA_EVENT_InitCalculate: {
       CXFA_Calculate* calc = pNode->GetCalculateIfExists();
       if (!calc)
-        return XFA_EVENTERROR_NotExist;
+        return XFA_EventError::kNotExist;
       if (pNode->IsUserInteractive())
-        return XFA_EVENTERROR_Disabled;
+        return XFA_EventError::kDisabled;
 
       return pNode->ExecuteScript(pDocView, calc->GetScriptIfExists(), pParam);
     }
@@ -358,20 +359,21 @@
                              pParam);
 }
 
-int32_t CXFA_FFDocView::ExecEventActivityByDeepFirst(CXFA_Node* pFormNode,
-                                                     XFA_EVENTTYPE eEventType,
-                                                     bool bIsFormReady,
-                                                     bool bRecursive) {
+XFA_EventError CXFA_FFDocView::ExecEventActivityByDeepFirst(
+    CXFA_Node* pFormNode,
+    XFA_EVENTTYPE eEventType,
+    bool bIsFormReady,
+    bool bRecursive) {
   if (!pFormNode)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   XFA_Element elementType = pFormNode->GetElementType();
   if (elementType == XFA_Element::Field) {
     if (eEventType == XFA_EVENT_IndexChange)
-      return XFA_EVENTERROR_NotExist;
+      return XFA_EventError::kNotExist;
 
     if (!pFormNode->IsWidgetReady())
-      return XFA_EVENTERROR_NotExist;
+      return XFA_EventError::kNotExist;
 
     CXFA_EventParam eParam;
     eParam.m_eType = eEventType;
@@ -380,15 +382,16 @@
     return XFA_ProcessEvent(this, pFormNode, &eParam);
   }
 
-  int32_t iRet = XFA_EVENTERROR_NotExist;
+  XFA_EventError iRet = XFA_EventError::kNotExist;
   if (bRecursive) {
     for (CXFA_Node* pNode = pFormNode->GetFirstContainerChild(); pNode;
          pNode = pNode->GetNextContainerSibling()) {
       elementType = pNode->GetElementType();
       if (elementType != XFA_Element::Variables &&
           elementType != XFA_Element::Draw) {
-        iRet |= ExecEventActivityByDeepFirst(pNode, eEventType, bIsFormReady,
-                                             bRecursive);
+        XFA_EventErrorAccumulate(
+            &iRet, ExecEventActivityByDeepFirst(pNode, eEventType, bIsFormReady,
+                                                bRecursive));
       }
     }
   }
@@ -399,8 +402,8 @@
   eParam.m_eType = eEventType;
   eParam.m_pTarget = pFormNode;
   eParam.m_bIsFormReady = bIsFormReady;
-  iRet |= XFA_ProcessEvent(this, pFormNode, &eParam);
 
+  XFA_EventErrorAccumulate(&iRet, XFA_ProcessEvent(this, pFormNode, &eParam));
   return iRet;
 }
 
@@ -524,7 +527,7 @@
     node->JSObject()->SetCalcRecursionCount(recurse);
     if (recurse > 11)
       break;
-    if (node->ProcessCalculate(this) == XFA_EVENTERROR_Success &&
+    if (node->ProcessCalculate(this) == XFA_EventError::kSuccess &&
         node->IsWidgetReady()) {
       AddValidateNode(node);
     }
@@ -534,9 +537,10 @@
   return index;
 }
 
-int32_t CXFA_FFDocView::RunCalculateWidgets() {
+XFA_EventError CXFA_FFDocView::RunCalculateWidgets() {
   if (!m_pDoc->GetDocEnvironment()->IsCalculationsEnabled(m_pDoc.Get()))
-    return XFA_EVENTERROR_Disabled;
+    return XFA_EventError::kDisabled;
+
   if (!m_CalculateNodes.empty())
     RunCalculateRecursive(0);
 
@@ -544,7 +548,7 @@
     node->JSObject()->SetCalcRecursionCount(0);
 
   m_CalculateNodes.clear();
-  return XFA_EVENTERROR_Success;
+  return XFA_EventError::kSuccess;
 }
 
 void CXFA_FFDocView::AddValidateNode(CXFA_Node* node) {
diff --git a/xfa/fxfa/cxfa_ffdocview.h b/xfa/fxfa/cxfa_ffdocview.h
index 3752527..e9a094f 100644
--- a/xfa/fxfa/cxfa_ffdocview.h
+++ b/xfa/fxfa/cxfa_ffdocview.h
@@ -14,6 +14,7 @@
 #include "core/fxcrt/unowned_ptr.h"
 #include "xfa/fxfa/cxfa_eventparam.h"
 #include "xfa/fxfa/cxfa_ffdoc.h"
+#include "xfa/fxfa/fxfa.h"
 
 class CXFA_BindItems;
 class CXFA_FFDoc;
@@ -86,10 +87,10 @@
   CXFA_Node* GetFocusNode() const { return m_pFocusNode.Get(); }
   void SetFocusNode(CXFA_Node* pNode);
   void DeleteLayoutItem(CXFA_FFWidget* pWidget);
-  int32_t ExecEventActivityByDeepFirst(CXFA_Node* pFormNode,
-                                       XFA_EVENTTYPE eEventType,
-                                       bool bIsFormReady,
-                                       bool bRecursive);
+  XFA_EventError ExecEventActivityByDeepFirst(CXFA_Node* pFormNode,
+                                              XFA_EVENTTYPE eEventType,
+                                              bool bIsFormReady,
+                                              bool bRecursive);
 
   void AddBindItem(CXFA_BindItems* item) { m_BindItems.push_back(item); }
 
@@ -112,7 +113,7 @@
   bool IsUpdateLocked() { return m_iLock > 0; }
   bool InitValidate(CXFA_Node* pNode);
   bool RunValidate();
-  int32_t RunCalculateWidgets();
+  XFA_EventError RunCalculateWidgets();
   void RunSubformIndexChange();
 
   UnownedPtr<CXFA_FFDoc> const m_pDoc;
diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp
index 194bf65..18a59c9 100644
--- a/xfa/fxfa/cxfa_ffnotify.cpp
+++ b/xfa/fxfa/cxfa_ffnotify.cpp
@@ -215,19 +215,19 @@
   CXFA_EventParam EventParam;
   EventParam.m_eType = XFA_EVENT_Unknown;
 
-  int32_t iRet;
+  XFA_EventError iRet;
   bool bRet;
   std::tie(iRet, bRet) = item->ExecuteBoolScript(pDocView, script, &EventParam);
-  return iRet == XFA_EVENTERROR_Success && bRet;
+  return iRet == XFA_EventError::kSuccess && bRet;
 }
 
-int32_t CXFA_FFNotify::ExecEventByDeepFirst(CXFA_Node* pFormNode,
-                                            XFA_EVENTTYPE eEventType,
-                                            bool bIsFormReady,
-                                            bool bRecursive) {
+XFA_EventError CXFA_FFNotify::ExecEventByDeepFirst(CXFA_Node* pFormNode,
+                                                   XFA_EVENTTYPE eEventType,
+                                                   bool bIsFormReady,
+                                                   bool bRecursive) {
   CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
   if (!pDocView)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
   return pDocView->ExecEventActivityByDeepFirst(pFormNode, eEventType,
                                                 bIsFormReady, bRecursive);
 }
diff --git a/xfa/fxfa/cxfa_ffnotify.h b/xfa/fxfa/cxfa_ffnotify.h
index ecfbd47..6debca8 100644
--- a/xfa/fxfa/cxfa_ffnotify.h
+++ b/xfa/fxfa/cxfa_ffnotify.h
@@ -10,6 +10,7 @@
 #include <memory>
 
 #include "xfa/fxfa/cxfa_eventparam.h"
+#include "xfa/fxfa/fxfa.h"
 #include "xfa/fxfa/parser/cxfa_document.h"
 
 class CXFA_ContentLayoutItem;
@@ -57,10 +58,10 @@
                             float* pCalcWidth,
                             float* pCalcHeight);
   bool RunScript(CXFA_Script* pScript, CXFA_Node* pFormItem);
-  int32_t ExecEventByDeepFirst(CXFA_Node* pFormNode,
-                               XFA_EVENTTYPE eEventType,
-                               bool bIsFormReady,
-                               bool bRecursive);
+  XFA_EventError ExecEventByDeepFirst(CXFA_Node* pFormNode,
+                                      XFA_EVENTTYPE eEventType,
+                                      bool bIsFormReady,
+                                      bool bRecursive);
   void AddCalcValidate(CXFA_Node* pNode);
   CXFA_FFDoc* GetHDOC() const { return m_pDoc.Get(); }
   IXFA_AppProvider* GetAppProvider();
diff --git a/xfa/fxfa/cxfa_ffwidgethandler.cpp b/xfa/fxfa/cxfa_ffwidgethandler.cpp
index 138b7f0..c2277fc 100644
--- a/xfa/fxfa/cxfa_ffwidgethandler.cpp
+++ b/xfa/fxfa/cxfa_ffwidgethandler.cpp
@@ -226,12 +226,12 @@
               .empty();
 }
 
-int32_t CXFA_FFWidgetHandler::ProcessEvent(CXFA_Node* pNode,
-                                           CXFA_EventParam* pParam) {
+XFA_EventError CXFA_FFWidgetHandler::ProcessEvent(CXFA_Node* pNode,
+                                                  CXFA_EventParam* pParam) {
   if (!pParam || pParam->m_eType == XFA_EVENT_Unknown)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
   if (!pNode || pNode->GetElementType() == XFA_Element::Draw)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   switch (pParam->m_eType) {
     case XFA_EVENT_Calculate:
@@ -241,13 +241,13 @@
               m_pDocView->GetDoc())) {
         return pNode->ProcessValidate(m_pDocView.Get(), 0);
       }
-      return XFA_EVENTERROR_Disabled;
+      return XFA_EventError::kDisabled;
     case XFA_EVENT_InitCalculate: {
       CXFA_Calculate* calc = pNode->GetCalculateIfExists();
       if (!calc)
-        return XFA_EVENTERROR_NotExist;
+        return XFA_EventError::kNotExist;
       if (pNode->IsUserInteractive())
-        return XFA_EVENTERROR_Disabled;
+        return XFA_EventError::kDisabled;
       return pNode->ExecuteScript(m_pDocView.Get(), calc->GetScriptIfExists(),
                                   pParam);
     }
diff --git a/xfa/fxfa/cxfa_ffwidgethandler.h b/xfa/fxfa/cxfa_ffwidgethandler.h
index 1e7c546..2969e8e 100644
--- a/xfa/fxfa/cxfa_ffwidgethandler.h
+++ b/xfa/fxfa/cxfa_ffwidgethandler.h
@@ -72,7 +72,7 @@
                     const CFX_Matrix& matrix,
                     bool bHighlight);
   bool HasEvent(CXFA_Node* pNode, XFA_EVENTTYPE eEventType);
-  int32_t ProcessEvent(CXFA_Node* pNode, CXFA_EventParam* pParam);
+  XFA_EventError ProcessEvent(CXFA_Node* pNode, CXFA_EventParam* pParam);
 
  private:
   CXFA_Node* CreateWidgetFormItem(XFA_WIDGETTYPE eType,
diff --git a/xfa/fxfa/fxfa.h b/xfa/fxfa/fxfa.h
index 7b940ff..b5a6d1a 100644
--- a/xfa/fxfa/fxfa.h
+++ b/xfa/fxfa/fxfa.h
@@ -68,14 +68,16 @@
 #define XFA_PAGEVIEWEVENT_PostRemoved 3
 #define XFA_PAGEVIEWEVENT_StopLayout 4
 
-#define XFA_EVENTERROR_Success 1
-#define XFA_EVENTERROR_Error -1
-#define XFA_EVENTERROR_NotExist 0
-#define XFA_EVENTERROR_Disabled 2
-
 #define XFA_TRAVERSEWAY_Tranvalse 0x0001
 #define XFA_TRAVERSEWAY_Form 0x0002
 
+enum class XFA_EventError {
+  kError = -1,
+  kNotExist = 0,
+  kSuccess = 1,
+  kDisabled = 2,
+};
+
 enum XFA_WidgetStatus {
   XFA_WidgetStatus_None = 0,
 
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index ecd0264..3f13b05 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -2322,31 +2322,32 @@
   return pExcl;
 }
 
-int32_t CXFA_Node::ProcessEvent(CXFA_FFDocView* pDocView,
-                                XFA_AttributeValue iActivity,
-                                CXFA_EventParam* pEventParam) {
+XFA_EventError CXFA_Node::ProcessEvent(CXFA_FFDocView* pDocView,
+                                       XFA_AttributeValue iActivity,
+                                       CXFA_EventParam* pEventParam) {
   if (GetElementType() == XFA_Element::Draw)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   std::vector<CXFA_Event*> eventArray =
       GetEventByActivity(iActivity, pEventParam->m_bIsFormReady);
   bool first = true;
-  int32_t iRet = XFA_EVENTERROR_NotExist;
+  XFA_EventError iRet = XFA_EventError::kNotExist;
   for (CXFA_Event* event : eventArray) {
-    int32_t result = ProcessEvent(pDocView, iActivity, event, pEventParam);
-    if (first || result == XFA_EVENTERROR_Success)
+    XFA_EventError result =
+        ProcessEventInternal(pDocView, iActivity, event, pEventParam);
+    if (first || result == XFA_EventError::kSuccess)
       iRet = result;
     first = false;
   }
   return iRet;
 }
 
-int32_t CXFA_Node::ProcessEvent(CXFA_FFDocView* pDocView,
-                                XFA_AttributeValue iActivity,
-                                CXFA_Event* event,
-                                CXFA_EventParam* pEventParam) {
+XFA_EventError CXFA_Node::ProcessEventInternal(CXFA_FFDocView* pDocView,
+                                               XFA_AttributeValue iActivity,
+                                               CXFA_Event* event,
+                                               CXFA_EventParam* pEventParam) {
   if (!event)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   switch (event->GetEventType()) {
     case XFA_Element::Execute:
@@ -2354,7 +2355,7 @@
     case XFA_Element::Script:
       if (iActivity == XFA_AttributeValue::DocClose) {
         // Too late, scripting engine already gone.
-        return false;
+        return XFA_EventError::kNotExist;
       }
       return ExecuteScript(pDocView, event->GetScriptIfExists(), pEventParam);
     case XFA_Element::SignData:
@@ -2365,49 +2366,49 @@
 #ifdef PDF_XFA_ELEMENT_SUBMIT_ENABLED
       CXFA_Submit* submit = event->GetSubmitIfExists();
       if (!submit)
-        return XFA_EVENTERROR_NotExist;
+        return XFA_EventError::kNotExist;
       return pDocView->GetDoc()->GetDocEnvironment()->Submit(pDocView->GetDoc(),
                                                              submit);
 #else
-      return XFA_EVENTERROR_Disabled;
+      return XFA_EventError::kDisabled;
 #endif  // PDF_XFA_ELEMENT_SUBMIT_ENABLED
     }
     default:
       break;
   }
-  return XFA_EVENTERROR_NotExist;
+  return XFA_EventError::kNotExist;
 }
 
-int32_t CXFA_Node::ProcessCalculate(CXFA_FFDocView* pDocView) {
+XFA_EventError CXFA_Node::ProcessCalculate(CXFA_FFDocView* pDocView) {
   if (GetElementType() == XFA_Element::Draw)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   CXFA_Calculate* calc = GetCalculateIfExists();
   if (!calc)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
   if (IsUserInteractive())
-    return XFA_EVENTERROR_Disabled;
+    return XFA_EventError::kDisabled;
 
   CXFA_EventParam EventParam;
   EventParam.m_eType = XFA_EVENT_Calculate;
-  int32_t iRet =
+  XFA_EventError iRet =
       ExecuteScript(pDocView, calc->GetScriptIfExists(), &EventParam);
-  if (iRet != XFA_EVENTERROR_Success)
+  if (iRet != XFA_EventError::kSuccess)
     return iRet;
 
   if (GetRawValue() != EventParam.m_wsResult) {
     SetValue(XFA_VALUEPICTURE_Raw, EventParam.m_wsResult);
     UpdateUIDisplay(pDocView, nullptr);
   }
-  return XFA_EVENTERROR_Success;
+  return XFA_EventError::kSuccess;
 }
 
 void CXFA_Node::ProcessScriptTestValidate(CXFA_FFDocView* pDocView,
                                           CXFA_Validate* validate,
-                                          int32_t iRet,
+                                          XFA_EventError iRet,
                                           bool bRetValue,
                                           bool bVersionFlag) {
-  if (iRet != XFA_EVENTERROR_Success)
+  if (iRet != XFA_EventError::kSuccess)
     return;
   if (bRetValue)
     return;
@@ -2447,29 +2448,29 @@
                        static_cast<uint32_t>(AlertButton::kOK));
 }
 
-int32_t CXFA_Node::ProcessFormatTestValidate(CXFA_FFDocView* pDocView,
-                                             CXFA_Validate* validate,
-                                             bool bVersionFlag) {
+XFA_EventError CXFA_Node::ProcessFormatTestValidate(CXFA_FFDocView* pDocView,
+                                                    CXFA_Validate* validate,
+                                                    bool bVersionFlag) {
   WideString wsPicture = validate->GetPicture();
   if (wsPicture.IsEmpty())
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   WideString wsRawValue = GetRawValue();
   if (wsRawValue.IsEmpty())
-    return XFA_EVENTERROR_Error;
+    return XFA_EventError::kError;
 
   LocaleIface* pLocale = GetLocale();
   if (!pLocale)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   CXFA_LocaleValue lcValue = XFA_GetLocaleValue(this);
   if (lcValue.ValidateValue(lcValue.GetValue(), wsPicture, pLocale, nullptr))
-    return XFA_EVENTERROR_Success;
+    return XFA_EventError::kSuccess;
 
   IXFA_AppProvider* pAppProvider =
       pDocView->GetDoc()->GetApp()->GetAppProvider();
   if (!pAppProvider)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   WideString wsFormatMsg = validate->GetFormatMessageText();
   WideString wsTitle = pAppProvider->GetAppTitle();
@@ -2479,7 +2480,7 @@
     pAppProvider->MsgBox(wsFormatMsg, wsTitle,
                          static_cast<uint32_t>(AlertIcon::kError),
                          static_cast<uint32_t>(AlertButton::kOK));
-    return XFA_EVENTERROR_Error;
+    return XFA_EventError::kError;
   }
 
   if (wsFormatMsg.IsEmpty())
@@ -2489,7 +2490,7 @@
     pAppProvider->MsgBox(wsFormatMsg, wsTitle,
                          static_cast<uint32_t>(AlertIcon::kWarning),
                          static_cast<uint32_t>(AlertButton::kOK));
-    return XFA_EVENTERROR_Error;
+    return XFA_EventError::kError;
   }
 
   if (pAppProvider->MsgBox(wsFormatMsg, wsTitle,
@@ -2499,42 +2500,42 @@
     SetFlag(XFA_NodeFlag_UserInteractive);
   }
 
-  return XFA_EVENTERROR_Error;
+  return XFA_EventError::kError;
 }
 
-int32_t CXFA_Node::ProcessNullTestValidate(CXFA_FFDocView* pDocView,
-                                           CXFA_Validate* validate,
-                                           int32_t iFlags,
-                                           bool bVersionFlag) {
+XFA_EventError CXFA_Node::ProcessNullTestValidate(CXFA_FFDocView* pDocView,
+                                                  CXFA_Validate* validate,
+                                                  int32_t iFlags,
+                                                  bool bVersionFlag) {
   if (!GetValue(XFA_VALUEPICTURE_Raw).IsEmpty())
-    return XFA_EVENTERROR_Success;
+    return XFA_EventError::kSuccess;
   if (m_bIsNull && m_bPreNull)
-    return XFA_EVENTERROR_Success;
+    return XFA_EventError::kSuccess;
 
   XFA_AttributeValue eNullTest = validate->GetNullTest();
   WideString wsNullMsg = validate->GetNullMessageText();
   if (iFlags & 0x01) {
-    int32_t iRet = XFA_EVENTERROR_Success;
+    XFA_EventError iRet = XFA_EventError::kSuccess;
     if (eNullTest != XFA_AttributeValue::Disabled)
-      iRet = XFA_EVENTERROR_Error;
+      iRet = XFA_EventError::kError;
 
     if (wsNullMsg.IsEmpty())
       return iRet;
 
     if (eNullTest != XFA_AttributeValue::Disabled) {
       pDocView->m_arrNullTestMsg.push_back(wsNullMsg);
-      return XFA_EVENTERROR_Error;
+      return XFA_EventError::kError;
     }
-    return XFA_EVENTERROR_Success;
+    return XFA_EventError::kSuccess;
   }
   if (wsNullMsg.IsEmpty() && bVersionFlag &&
       eNullTest != XFA_AttributeValue::Disabled) {
-    return XFA_EVENTERROR_Error;
+    return XFA_EventError::kError;
   }
   IXFA_AppProvider* pAppProvider =
       pDocView->GetDoc()->GetApp()->GetAppProvider();
   if (!pAppProvider)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   WideString wsCaptionName;
   WideString wsTitle = pAppProvider->GetAppTitle();
@@ -2547,11 +2548,11 @@
       pAppProvider->MsgBox(wsNullMsg, wsTitle,
                            static_cast<uint32_t>(AlertIcon::kStatus),
                            static_cast<uint32_t>(AlertButton::kOK));
-      return XFA_EVENTERROR_Error;
+      return XFA_EventError::kError;
     }
     case XFA_AttributeValue::Warning: {
       if (IsUserInteractive())
-        return true;
+        return XFA_EventError::kSuccess;
 
       if (wsNullMsg.IsEmpty()) {
         wsCaptionName = GetValidateCaptionName(bVersionFlag);
@@ -2565,27 +2566,28 @@
           static_cast<uint32_t>(AlertReturn::kYes)) {
         SetFlag(XFA_NodeFlag_UserInteractive);
       }
-      return XFA_EVENTERROR_Error;
+      return XFA_EventError::kError;
     }
     case XFA_AttributeValue::Disabled:
     default:
       break;
   }
-  return XFA_EVENTERROR_Success;
+  return XFA_EventError::kSuccess;
 }
 
-int32_t CXFA_Node::ProcessValidate(CXFA_FFDocView* pDocView, int32_t iFlags) {
+XFA_EventError CXFA_Node::ProcessValidate(CXFA_FFDocView* pDocView,
+                                          int32_t iFlags) {
   if (GetElementType() == XFA_Element::Draw)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   CXFA_Validate* validate = GetValidateIfExists();
   if (!validate)
-    return XFA_EVENTERROR_NotExist;
+    return XFA_EventError::kNotExist;
 
   bool bInitDoc = validate->NeedsInitApp();
   bool bStatus = pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End;
-  int32_t iFormat = 0;
-  int32_t iRet = XFA_EVENTERROR_NotExist;
+  XFA_EventError iFormat = XFA_EventError::kNotExist;
+  XFA_EventError iRet = XFA_EventError::kNotExist;
   CXFA_Script* script = validate->GetScriptIfExists();
   bool bRet = false;
   bool hasBoolResult = (bInitDoc || bStatus) && GetRawValue().IsEmpty();
@@ -2609,14 +2611,15 @@
       bVersionFlag =
           pDocView->GetDoc()->GetXFADoc()->HasFlag(XFA_DOCFLAG_Scripting);
     }
-
-    iRet |= ProcessNullTestValidate(pDocView, validate, iFlags, bVersionFlag);
+    XFA_EventErrorAccumulate(
+        &iRet,
+        ProcessNullTestValidate(pDocView, validate, iFlags, bVersionFlag));
   }
-
-  if (iFormat != XFA_EVENTERROR_Success && hasBoolResult)
+  if (iFormat != XFA_EventError::kSuccess && hasBoolResult)
     ProcessScriptTestValidate(pDocView, validate, iRet, bRet, bVersionFlag);
 
-  return iRet | iFormat;
+  XFA_EventErrorAccumulate(&iRet, iFormat);
+  return iRet;
 }
 
 WideString CXFA_Node::GetValidateCaptionName(bool bVersionFlag) {
@@ -2651,35 +2654,32 @@
   return result;
 }
 
-int32_t CXFA_Node::ExecuteScript(CXFA_FFDocView* pDocView,
-                                 CXFA_Script* script,
-                                 CXFA_EventParam* pEventParam) {
-  bool bRet;
-  int32_t iRet;
-  std::tie(iRet, bRet) = ExecuteBoolScript(pDocView, script, pEventParam);
-  return iRet;
+XFA_EventError CXFA_Node::ExecuteScript(CXFA_FFDocView* pDocView,
+                                        CXFA_Script* script,
+                                        CXFA_EventParam* pEventParam) {
+  return ExecuteBoolScript(pDocView, script, pEventParam).first;
 }
 
-std::pair<int32_t, bool> CXFA_Node::ExecuteBoolScript(
+std::pair<XFA_EventError, bool> CXFA_Node::ExecuteBoolScript(
     CXFA_FFDocView* pDocView,
     CXFA_Script* script,
     CXFA_EventParam* pEventParam) {
   if (m_ExecuteRecursionDepth > kMaxExecuteRecursion)
-    return {XFA_EVENTERROR_Success, false};
+    return {XFA_EventError::kSuccess, false};
 
   ASSERT(pEventParam);
   if (!script)
-    return {XFA_EVENTERROR_NotExist, false};
+    return {XFA_EventError::kNotExist, false};
   if (script->GetRunAt() == XFA_AttributeValue::Server)
-    return {XFA_EVENTERROR_Disabled, false};
+    return {XFA_EventError::kDisabled, false};
 
   WideString wsExpression = script->GetExpression();
   if (wsExpression.IsEmpty())
-    return {XFA_EVENTERROR_NotExist, false};
+    return {XFA_EventError::kNotExist, false};
 
   CXFA_Script::Type eScriptType = script->GetContentType();
   if (eScriptType == CXFA_Script::Type::Unknown)
-    return {XFA_EVENTERROR_Success, false};
+    return {XFA_EventError::kSuccess, false};
 
   CXFA_FFDoc* pDoc = pDocView->GetDoc();
   CFXJSE_Engine* pContext = pDoc->GetXFADoc()->GetScriptContext();
@@ -2701,21 +2701,21 @@
                                pTmpRetValue.get(), this);
   }
 
-  int32_t iRet = XFA_EVENTERROR_Error;
+  XFA_EventError iRet = XFA_EventError::kError;
   if (bRet) {
-    iRet = XFA_EVENTERROR_Success;
+    iRet = XFA_EventError::kSuccess;
     if (pEventParam->m_eType == XFA_EVENT_Calculate ||
         pEventParam->m_eType == XFA_EVENT_InitCalculate) {
       if (!pTmpRetValue->IsUndefined()) {
         if (!pTmpRetValue->IsNull())
           pEventParam->m_wsResult = pTmpRetValue->ToWideString();
 
-        iRet = XFA_EVENTERROR_Success;
+        iRet = XFA_EventError::kSuccess;
       } else {
-        iRet = XFA_EVENTERROR_Error;
+        iRet = XFA_EventError::kError;
       }
       if (pEventParam->m_eType == XFA_EVENT_InitCalculate) {
-        if ((iRet == XFA_EVENTERROR_Success) &&
+        if ((iRet == XFA_EventError::kSuccess) &&
             (GetRawValue() != pEventParam->m_wsResult)) {
           SetValue(XFA_VALUEPICTURE_Raw, pEventParam->m_wsResult);
           pDocView->AddValidateNode(this);
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index b4466db..0bb2e33 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -17,6 +17,7 @@
 #include "third_party/base/optional.h"
 #include "third_party/base/span.h"
 #include "xfa/fxfa/cxfa_ffwidget_type.h"
+#include "xfa/fxfa/fxfa.h"
 #include "xfa/fxfa/parser/cxfa_object.h"
 
 class CFGAS_GEFont;
@@ -250,17 +251,18 @@
 
   CXFA_Node* GetExclGroupIfExists();
 
-  int32_t ProcessEvent(CXFA_FFDocView* pDocView,
-                       XFA_AttributeValue iActivity,
-                       CXFA_EventParam* pEventParam);
-  int32_t ProcessCalculate(CXFA_FFDocView* pDocView);
-  int32_t ProcessValidate(CXFA_FFDocView* pDocView, int32_t iFlags);
-  int32_t ExecuteScript(CXFA_FFDocView* pDocView,
-                        CXFA_Script* script,
-                        CXFA_EventParam* pEventParam);
-  std::pair<int32_t, bool> ExecuteBoolScript(CXFA_FFDocView* pDocView,
-                                             CXFA_Script* script,
-                                             CXFA_EventParam* pEventParam);
+  XFA_EventError ProcessEvent(CXFA_FFDocView* pDocView,
+                              XFA_AttributeValue iActivity,
+                              CXFA_EventParam* pEventParam);
+  XFA_EventError ProcessCalculate(CXFA_FFDocView* pDocView);
+  XFA_EventError ProcessValidate(CXFA_FFDocView* pDocView, int32_t iFlags);
+  XFA_EventError ExecuteScript(CXFA_FFDocView* pDocView,
+                               CXFA_Script* script,
+                               CXFA_EventParam* pEventParam);
+  std::pair<XFA_EventError, bool> ExecuteBoolScript(
+      CXFA_FFDocView* pDocView,
+      CXFA_Script* script,
+      CXFA_EventParam* pEventParam);
 
   CXFA_Node* GetUIChildNode();
   XFA_FFWidgetType GetFFWidgetType();
@@ -393,16 +395,16 @@
  private:
   void ProcessScriptTestValidate(CXFA_FFDocView* pDocView,
                                  CXFA_Validate* validate,
-                                 int32_t iRet,
+                                 XFA_EventError iRet,
                                  bool pRetValue,
                                  bool bVersionFlag);
-  int32_t ProcessFormatTestValidate(CXFA_FFDocView* pDocView,
-                                    CXFA_Validate* validate,
-                                    bool bVersionFlag);
-  int32_t ProcessNullTestValidate(CXFA_FFDocView* pDocView,
-                                  CXFA_Validate* validate,
-                                  int32_t iFlags,
-                                  bool bVersionFlag);
+  XFA_EventError ProcessFormatTestValidate(CXFA_FFDocView* pDocView,
+                                           CXFA_Validate* validate,
+                                           bool bVersionFlag);
+  XFA_EventError ProcessNullTestValidate(CXFA_FFDocView* pDocView,
+                                         CXFA_Validate* validate,
+                                         int32_t iFlags,
+                                         bool bVersionFlag);
   WideString GetValidateCaptionName(bool bVersionFlag);
   WideString GetValidateMessage(bool bError, bool bVersionFlag);
 
@@ -471,10 +473,10 @@
   Optional<float> TryMinHeight();
   Optional<float> TryMaxWidth();
   Optional<float> TryMaxHeight();
-  int32_t ProcessEvent(CXFA_FFDocView* pDocView,
-                       XFA_AttributeValue iActivity,
-                       CXFA_Event* event,
-                       CXFA_EventParam* pEventParam);
+  XFA_EventError ProcessEventInternal(CXFA_FFDocView* pDocView,
+                                      XFA_AttributeValue iActivity,
+                                      CXFA_Event* event,
+                                      CXFA_EventParam* pEventParam);
 
   CFX_XMLDocument* GetXMLDocument() const;
 
diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp
index 4ce9b23..3dddbd9 100644
--- a/xfa/fxfa/parser/xfa_utils.cpp
+++ b/xfa/fxfa/parser/xfa_utils.cpp
@@ -532,3 +532,8 @@
   nRotation = nRotation < 0 ? nRotation + 360 : nRotation;
   return nRotation;
 }
+
+void XFA_EventErrorAccumulate(XFA_EventError* pAcc, XFA_EventError eNew) {
+  if (*pAcc == XFA_EventError::kNotExist || eNew == XFA_EventError::kError)
+    *pAcc = eNew;
+}
diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h
index f602f19..89c30c3 100644
--- a/xfa/fxfa/parser/xfa_utils.h
+++ b/xfa/fxfa/parser/xfa_utils.h
@@ -8,6 +8,7 @@
 #define XFA_FXFA_PARSER_XFA_UTILS_H_
 
 #include "core/fxcrt/fx_stream.h"
+#include "xfa/fxfa/fxfa.h"
 #include "xfa/fxfa/fxfa_basic.h"
 
 class CFX_XMLElement;
@@ -31,4 +32,6 @@
     const RetainPtr<IFX_SeekableStream>& pStream,
     bool bSaveXML);
 
+void XFA_EventErrorAccumulate(XFA_EventError* pAcc, XFA_EventError eNew);
+
 #endif  // XFA_FXFA_PARSER_XFA_UTILS_H_